Skip to content

Commit

Permalink
build: Move common files for handling ASN.1 to common
Browse files Browse the repository at this point in the history
Signed-off-by: Daiki Ueno <[email protected]>
  • Loading branch information
ueno authored and ZoltanFridrich committed Sep 26, 2023
1 parent e8872bf commit d8cc241
Show file tree
Hide file tree
Showing 15 changed files with 119 additions and 55 deletions.
1 change: 1 addition & 0 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ NULL =
AM_CPPFLAGS = \
-I$(top_srcdir) \
-I$(top_srcdir)/common \
-I$(top_builddir)/common \
-DBINDIR=\"$(bindir)\" \
-DBUILDDIR=\"$(abs_builddir)\" \
-DDATA_DIR=\"$(datadir)\" \
Expand Down
47 changes: 47 additions & 0 deletions common/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -141,4 +141,51 @@ common_frob_getprogname_SOURCES = common/frob-getprogname.c
common_frob_getprogname_LDADD = $(common_LIBS)
endif

if WITH_ASN1
SUFFIXES += .asn .asn.h
.asn.asn.h:
$(AM_V_GEN)$(ASN1PARSER) -o $@ $<

asn_h = \
common/basic.asn.h \
common/openssl.asn.h \
common/pkix.asn.h \
$(NULL)

BUILT_SOURCES += $(asn_h)

EXTRA_DIST += \
common/basic.asn \
common/openssl.asn \
common/pkix.asn \
$(NULL)

noinst_LTLIBRARIES += libp11-asn1.la

libp11_asn1_la_SOURCES = \
common/asn1.c common/asn1.h \
common/oid.c common/oid.h \
$(asn_h) \
$(NULL)

asn1_LIBS = \
libp11-asn1.la \
$(LIBTASN1_LIBS) \
$(common_LIBS) \
$(NULL)

test_asn1_SOURCES = common/test-asn1.c
test_asn1_LDADD = $(asn1_LIBS)
test_asn1_CFLAGS = $(LIBTASN1_CFLAGS)

test_oid_SOURCES = common/test-oid.c
test_oid_LDADD = $(asn1_LIBS)
test_oid_CFLAGS = $(LIBTASN1_CFLAGS)

c_tests += \
test-asn1 \
test-oid \
$(NULL)
endif

EXTRA_DIST += common/meson.build
File renamed without changes.
File renamed without changes.
File renamed without changes.
64 changes: 64 additions & 0 deletions common/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,54 @@ libp11_tool = static_library('p11-tool', libp11_tool_sources,
libp11_tool_dep = declare_dependency(link_with: libp11_tool,
dependencies: [libp11_common_dep])

libp11_asn1_deps = []

if with_asn1
libp11_asn1_sources = [
'asn1.c',
'oid.c',
]

basic_asn_h = custom_target(
'basic.asn.h',
output: 'basic.asn.h',
input: 'basic.asn',
command: [asn1Parser, '-o', '@OUTPUT@', '@INPUT@'],
)

pkix_asn_h = custom_target(
'pkix.asn.h',
output: 'pkix.asn.h',
input: 'pkix.asn',
command: [asn1Parser, '-o', '@OUTPUT@', '@INPUT@'],
)

openssl_asn_h = custom_target(
'openssl.asn.h',
output: 'openssl.asn.h',
input: 'openssl.asn',
command: [asn1Parser, '-o', '@OUTPUT@', '@INPUT@'],
)

asn_h_dep = declare_dependency(
sources: [basic_asn_h, pkix_asn_h, openssl_asn_h],
)

libp11_asn1 = static_library(
'p11-asn1', libp11_asn1_sources,
gnu_symbol_visibility: 'hidden',
include_directories: configinc,
)

libp11_asn1_dep = declare_dependency(
include_directories: [configinc, commoninc],
link_with: libp11_asn1,
dependencies: [asn_h_dep] + libtasn1_deps,
)

libp11_asn1_deps += libp11_asn1_dep
endif

# Tests ----------------------------------------------------------------

if get_option('test')
Expand Down Expand Up @@ -111,6 +159,22 @@ if get_option('test')
test(name, t)
endforeach

if with_asn1
asn1_tests = [
'test-asn1',
'test-oid',
]

foreach name : asn1_tests
t = executable(name, '@[email protected]'.format(name),
c_args: tests_c_args,
include_directories: configinc,
dependencies: libp11_asn1_deps + dlopen_deps,
link_with: [libp11_test, libp11_common])
test(name, t)
endforeach
endif

common_progs = [
'frob-getauxval',
'frob-getenv'
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
1 change: 0 additions & 1 deletion trust/test-asn1.c → common/test-asn1.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
#include "asn1.h"
#include "debug.h"
#include "oid.h"
#include "x509.h"

#include <stdlib.h>
#include <stdio.h>
Expand Down
File renamed without changes.
2 changes: 2 additions & 0 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,7 @@ endif
# --------------------------------------------------------------------
# Trust Module

with_asn1 = false
with_trust_module = false
libtasn1_deps = []
libtasn1 = dependency('libtasn1', version: '>= 2.3',
Expand All @@ -407,6 +408,7 @@ if libtasn1.found()
if asn1Parser.found()
conf.set('WITH_ASN1', 1)
libtasn1_deps += libtasn1
with_asn1 = true
with_trust_module = true
endif
endif
Expand Down
32 changes: 3 additions & 29 deletions trust/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,8 @@ check_LTLIBRARIES += \
$(NULL)

libtrust_data_la_SOURCES = \
trust/asn1.c trust/asn1.h \
trust/oid.c trust/oid.h \
trust/utf8.c trust/utf8.h \
trust/x509.c trust/x509.h \
$(asn_h) \
$(NULL)

libtrust_data_la_CFLAGS = \
Expand Down Expand Up @@ -52,6 +49,7 @@ p11_kit_trust_la_LIBADD = \
libtrust-data.la \
libp11-library.la \
libp11-common.la \
libp11-asn1.la \
$(LIBTASN1_LIBS) \
$(HASH_LIBS) \
$(NULL)
Expand Down Expand Up @@ -85,6 +83,7 @@ trust_trust_LDADD = \
libp11-kit.la \
libp11-common.la \
libp11-tool.la \
libp11-asn1.la \
$(LTLIBINTL) \
$(LIBTASN1_LIBS) \
$(HASH_LIBS) \
Expand Down Expand Up @@ -113,7 +112,6 @@ trust_trust_SOURCES = \
trust/save.c trust/save.h \
trust/check-format.c trust/check-format.h \
trust/trust.c \
$(asn_h) \
$(NULL)

externaldir = $(privatedir)
Expand All @@ -129,22 +127,6 @@ EXTRA_DIST += \
trust/p11-kit-trust.module \
trust/meson.build

SUFFIXES += .asn .asn.h
.asn.asn.h:
$(AM_V_GEN)$(ASN1PARSER) -o $@ $<

asn_h = \
trust/basic.asn.h \
trust/openssl.asn.h \
trust/pkix.asn.h

BUILT_SOURCES += $(asn_h)

EXTRA_DIST += \
trust/basic.asn \
trust/openssl.asn \
trust/pkix.asn

# Tests ----------------------------------------------------------------

trust_CFLAGS = \
Expand All @@ -159,6 +141,7 @@ trust_LIBS = \
libp11-library.la \
libp11-test.la \
libp11-common.la \
libp11-asn1.la \
$(LIBTASN1_LIBS) \
$(HASH_LIBS) \
$(NULL)
Expand All @@ -173,7 +156,6 @@ libtrust_test_la_SOURCES = \

c_tests += \
test-digest \
test-asn1 \
test-base64 \
test-pem \
test-oid \
Expand All @@ -194,10 +176,6 @@ c_tests += \
test-jks \
$(NULL)

test_asn1_SOURCES = trust/test-asn1.c
test_asn1_LDADD = $(trust_LIBS)
test_asn1_CFLAGS = $(trust_CFLAGS)

test_base64_SOURCES = trust/test-base64.c
test_base64_LDADD = $(trust_LIBS)
test_base64_CFLAGS = $(trust_CFLAGS)
Expand Down Expand Up @@ -230,10 +208,6 @@ test_module_SOURCES = trust/test-module.c
test_module_LDADD = $(trust_LIBS)
test_module_CFLAGS = $(trust_CFLAGS)

test_oid_SOURCES = trust/test-oid.c
test_oid_LDADD = $(trust_LIBS)
test_oid_CFLAGS = $(trust_CFLAGS)

test_openssl_SOURCES = trust/test-openssl.c
test_openssl_LDADD = $(trust_LIBS)
test_openssl_CFLAGS = $(trust_CFLAGS)
Expand Down
27 changes: 2 additions & 25 deletions trust/meson.build
Original file line number Diff line number Diff line change
@@ -1,33 +1,12 @@
libtrust_data_sources = [
'asn1.c',
'oid.c',
'utf8.c',
'x509.c'
]

basic_asn_h = custom_target('basic.asn.h',
output: 'basic.asn.h',
input: 'basic.asn',
command: [asn1Parser, '-o', '@OUTPUT@', '@INPUT@'])

pkix_asn_h = custom_target('pkix.asn.h',
output: 'pkix.asn.h',
input: 'pkix.asn',
command: [asn1Parser, '-o', '@OUTPUT@', '@INPUT@'])

openssl_asn_h = custom_target('openssl.asn.h',
output: 'openssl.asn.h',
input: 'openssl.asn',
command: [asn1Parser, '-o', '@OUTPUT@', '@INPUT@'])

asn_h_dep = declare_dependency(
sources: [basic_asn_h, pkix_asn_h, openssl_asn_h]
)

libtrust_data = static_library('libtrust-data',
libtrust_data_sources,
include_directories: [configinc, commoninc],
dependencies: [asn_h_dep] + libtasn1_deps)
dependencies: libp11_asn1_deps)

libtrust_sources = [
'builder.c',
Expand All @@ -54,7 +33,7 @@ shared_module('p11-kit-trust',
'module-init.c',
name_prefix: '',
c_args: p11_kit_trust_c_args,
dependencies: [asn_h_dep, libp11_library_dep] + dlopen_deps + libtasn1_deps,
dependencies: [libp11_library_dep] + libp11_asn1_deps + dlopen_deps,
link_args: p11_module_ldflags,
link_depends: [p11_module_symbol_map],
link_with: libtrust_data,
Expand Down Expand Up @@ -119,10 +98,8 @@ if get_option('test')

trust_tests = [
'test-digest',
'test-asn1',
'test-base64',
'test-pem',
'test-oid',
'test-utf8',
'test-x509',
'test-persist',
Expand Down

0 comments on commit d8cc241

Please sign in to comment.