Skip to content

Commit

Permalink
build: add support for meson
Browse files Browse the repository at this point in the history
Co-authored-by: Frank Morgner <frankmorgner@gmail.com>
Co-authored-by: Jussi Pakkanen <jpakkane@gmail.com>
  • Loading branch information
3 people committed Apr 28, 2024
1 parent fe2c1c8 commit 9c30919
Show file tree
Hide file tree
Showing 23 changed files with 1,416 additions and 8 deletions.
76 changes: 76 additions & 0 deletions doc/files/meson.build
@@ -0,0 +1,76 @@
if progxsltproc.found() and stylesheets_path != ''
xml1 = configure_file(
configuration: {
'sysconfdir': absolute_sysconfdir,
'docdir': absolute_docdir,
'libdir': absolute_libdir / '',
'DYN_LIB_EXT': '.' + extension_of_libraries,
'DEFAULT_PCSC_PROVIDER': conf.get_unquoted('DEFAULT_PCSC_PROVIDER'),
'PROFILE_DIR_DEFAULT': (host_machine.system() == 'windows' or host_machine.system() == 'cygwin')?
'obtained from windows registers' : absolute_pkgdir,
'DEFAULT_SM_MODULE': conf.get_unquoted('DEFAULT_SM_MODULE')
},
input: 'opensc.conf.5.xml.in',
output: 'opensc.conf.5.xml'
)

custom_target(
command: [progxsltproc,
'--nonet',
'--path', meson.project_source_root() / 'doc' + ':' + stylesheets_path / 'manpages',
'--xinclude',
'-o', '@OUTPUT@',
'man.xsl',
'@INPUT@'
],
input: xml1,
output: modfs.stem(xml1),
build_by_default: get_option('man'),
install: get_option('man'),
install_dir: get_option('mandir') / 'man5'
)

xml2 = configure_file(
configuration: {'pkgdatadir': absolute_pkgdir},
input: 'pkcs15-profile.5.xml',
output: 'pkcs15-profile.5.xml'
)

custom_target(
command: [progxsltproc,
'--nonet',
'--path', meson.project_source_root() / 'doc' + ':' + stylesheets_path / 'manpages',
'--xinclude',
'-o', '@OUTPUT@',
'man.xsl',
'@INPUT@'
],
input: xml2,
output: modfs.stem(xml2),
build_by_default: get_option('man'),
install: get_option('man'),
install_dir: get_option('mandir') / 'man5'
)

custom_target(
command: [progxsltproc,
'--nonet',
'--path', meson.project_build_root() / 'doc' / 'files' + ':' +
meson.project_source_root() / 'doc' + ':' +
stylesheets_path / 'html',
'--xinclude',
'-o', '@OUTPUT@',
'html.xsl',
'@INPUT@'
],
input: 'files.xml',
output: 'files.html',
depend_files: [xml1, xml2],
build_by_default: get_option('doc'),
install: get_option('doc'),
install_dir: absolute_docdir
)

unset_variable('xml1')
unset_variable('xml2')
endif
38 changes: 38 additions & 0 deletions doc/tools/generate_completion.sh
@@ -0,0 +1,38 @@
if [ ! $# -eq 3 ]; then
echo "Usage: template description.1.xml generated_completion"
exit 1
fi
if [ ! -r "$1" ]; then
echo "The file \"$1\" does not exist or is not readable"
exit 2
fi
if [ ! -r "$2" ]; then
echo "The file \"$2\" does not exist or is not readable"
exit 3
fi

ALLOPTS=$(sed -n 's,.*<option>\([^<]*\)</option>.*,\1,pg' "$2" | sort -u | grep '^-' | tr '\n' ' ')

OPTSWITHARGS=$(sed -n 's,.*<option>\([^<]*\)</option>.*<replaceable>.*,\1,pg' "$2" | sort -u | grep '^-' | tr '\n' '|' | sed 's,|$$,,' | grep ^ || echo "!*")

FILEOPTS=$(sed -n 's,.*<option>\([^<]*\)</option>.*<replaceable>.*filename.*,\1,pg' "$2" | sort -u | grep '^-' | tr '\n' '|' | sed 's,|$$,,' | grep ^ || echo "!*")

PINOPTS=$(sed -En 's,.*<option>([^<]*)</option>.*<replaceable>\s*(newpin|pin|puk|sopin|sopuk)\s*<.*,\1,pg' "$2" | sort -u | grep '^-' | tr '\n' '|' | sed 's,|$$,,' | grep ^ || echo "!*")

MODULEOPTS=$(sed -n 's,.*<option>\([^<]*\)</option>.*<replaceable>.*mod.*,\1,pg' "$2" | sort -u | grep '^-' | tr '\n' '|' | sed 's,|$$,,' | grep ^ || echo "!*")

FUNCTION_NAME=$(basename "$3" | sed s,-,_,g)

PROGRAM_NAME=$(basename "$3")

cat "$1" \
| sed "s,ALLOPTS,${ALLOPTS}," \
| sed "s,OPTSWITHARGS,${OPTSWITHARGS}," \
| sed "s,FILEOPTS,${FILEOPTS}," \
| sed "s,PINOPTS,${PINOPTS}," \
| sed "s,MODULEOPTS,${MODULEOPTS}," \
| sed "s,FUNCTION_NAME,${FUNCTION_NAME}," \
| sed "s,PROGRAM_NAME,${PROGRAM_NAME}," \
> "$3"

exit 0
98 changes: 98 additions & 0 deletions doc/tools/meson.build
@@ -0,0 +1,98 @@
sources = [
'cardos-tool.1.xml',
'dnie-tool.1.xml',
'dtrust-tool.1.xml',
'egk-tool.1.xml',
'eidenv.1.xml',
'goid-tool.1.xml',
'iasecc-tool.1.xml',
'openpgp-tool.1.xml',
'opensc-asn1.1.xml',
'opensc-explorer.1.xml',
'opensc-tool.1.xml',
'pkcs11-register.1.xml',
'pkcs15-crypt.1.xml',
'pkcs15-tool.1.xml'
]

if get_option('components').contains('pkcs11')
sources += [
'pkcs11-tool.1.xml'
]
endif

if conf.get('ENABLE_OPENSSL')
sources += [
'cryptoflex-tool.1.xml',
'gids-tool.1.xml',
'netkey-tool.1.xml',
'piv-tool.1.xml',
'pkcs15-init.1.xml',
'sc-hsm-tool.1.xml',
'westcos-tool.1.xml'
]
endif

if conf.get('ENABLE_OPENSSL') and conf.get('ENABLE_OPENPACE')
sources += [
'npa-tool.1.xml'
]
endif

if conf.get('ENABLE_NOTIFY')
sources += [
'opensc-notify.1.xml'
]
endif

if progxsltproc.found() and stylesheets_path != ''
foreach xml : sources
custom_target(
command: [progxsltproc,
'--nonet',
'--path', meson.project_source_root() / 'doc' + ':' + stylesheets_path / 'manpages',
'--xinclude',
'-o', '@OUTPUT@',
'man.xsl',
'@INPUT@'
],
input: xml,
output: modfs.replace_suffix(xml, ''),
build_by_default: get_option('man'),
install: get_option('man'),
install_dir: get_option('mandir') / 'man1'
)
endforeach

custom_target(
command: [progxsltproc,
'--nonet',
'--path', meson.project_source_root() / 'doc' + ':' + stylesheets_path / 'html',
'--xinclude',
'-o', '@OUTPUT@',
'html.xsl',
'@INPUT@'
],
input: 'tools.xml',
output: 'tools.html',
depend_files: sources,
build_by_default: get_option('doc'),
install: get_option('doc'),
install_dir: absolute_docdir
)
endif

if bash_completion_path != ''
foreach xml : sources
custom_target(
command: ['generate_completion.sh', '@INPUT0@', '@INPUT1@', '@OUTPUT@'],
input: ['completion-template', xml],
output: modfs.replace_suffix(modfs.replace_suffix(xml, ''), ''),
build_by_default: true,
install: true,
install_dir: bash_completion_path
)
endforeach
endif

unset_variable('sources')
40 changes: 40 additions & 0 deletions etc/meson.build
@@ -0,0 +1,40 @@
install_data(
'opensc.conf',
install_dir: get_option('sysconfdir')
)

if conf.get('ENABLE_OPENPACE')
install_data(
'DESRCACC100001',
'DESCHSMCVCA00001',
install_dir: cv_certificates_path
)
endif

if get_option('doc')
conf_etc = configuration_data()
conf_etc.set('LIBDIR', absolute_libdir / '')
conf_etc.set('DEFAULT_PCSC_PROVIDER', conf.get_unquoted('DEFAULT_PCSC_PROVIDER'))
conf_etc.set('DEFAULT_SM_MODULE', conf.get_unquoted('DEFAULT_SM_MODULE'))
conf_etc.set('DEFAULT_SM_MODULE_PATH', conf.get_unquoted('DEFAULT_SM_MODULE_PATH'))
conf_etc.set('DYN_LIB_EXT', '.' + extension_of_libraries)
conf_etc.set('LIB_PRE', prefix_of_libraries)

if host_machine.system() == 'windows' or host_machine.system() == 'cygwin'
conf_etc.set('DEBUG_FILE', '%TEMP%\\opensc-debug.log')
conf_etc.set('PROFILE_DIR_DEFAULT', 'obtained from windows registers')
conf_etc.set('PROFILE_DIR', '')
else
conf_etc.set('DEBUG_FILE', '/tmp/opensc-debug.log')
conf_etc.set('PROFILE_DIR_DEFAULT', absolute_pkgdir)
conf_etc.set('PROFILE_DIR', absolute_pkgdir)
endif

configure_file(
configuration: conf_etc,
input: 'opensc.conf.example.in',
output: 'opensc.conf',
install: true,
install_dir: absolute_docdir
)
endif

0 comments on commit 9c30919

Please sign in to comment.