From: Alberto Leiva Popper Date: Mon, 2 Dec 2024 17:15:39 +0000 (-0300) Subject: Makefile maintenance X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d571a4258ff1baefbe8ef4727cbf421646670ee6;p=thirdparty%2FFORT-validator.git Makefile maintenance Triggered by fixing compilation in MacOS. - Rename extension.h to ext.h; the former collides with Extension.h. - Move _DEFAULT_SOURCE to the source; it's not widespread enough for Makefile.am. - Add _DARWIN_C_SOURCE, needed by MacOS for timegm() and mkdtemp(). - Add -flto to unit test AM_CFLAGS. This minimizes superflous #includes and mocks needed, and will hopefully make them consistent across platforms. - Delete _BSD_SOURCE; it seems orphaned. (Though see below.) Works on Linux and Mac. Might have broken the BSDs; I can't test them ATM. --- diff --git a/src/Makefile.am b/src/Makefile.am index 5f41650b..2ba315a6 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -28,7 +28,7 @@ fort_SOURCES += config/types.h fort_SOURCES += config/uint.c config/uint.h fort_SOURCES += config/work_offline.c config/work_offline.h fort_SOURCES += daemon.h daemon.c -fort_SOURCES += extension.h extension.c +fort_SOURCES += ext.h ext.c fort_SOURCES += file.h file.c fort_SOURCES += hash.h hash.c fort_SOURCES += http.h http.c @@ -100,7 +100,7 @@ fort_SOURCES += $(ASN_MODULE_SRCS) $(ASN_MODULE_HDRS) # -Werror -Wno-unused fort_CFLAGS = -Wall -Wpedantic #fort_CFLAGS += $(GCC_WARNS) -fort_CFLAGS += -std=c99 -D_DEFAULT_SOURCE=1 -D_XOPEN_SOURCE=700 -D_BSD_SOURCE=1 +fort_CFLAGS += -std=c99 -D_XOPEN_SOURCE=700 fort_CFLAGS += -O2 -g $(FORT_FLAGS) ${XML2_CFLAGS} if BACKTRACE_ENABLED fort_CFLAGS += -DBACKTRACE_ENABLED diff --git a/src/asn1/asn1c/CRL.c b/src/asn1/asn1c/CRL.c index fbcc02ec..d3d91c93 100644 --- a/src/asn1/asn1c/CRL.c +++ b/src/asn1/asn1c/CRL.c @@ -2,7 +2,7 @@ #include -#include "extension.h" +#include "ext.h" #include "json_util.h" #include "libcrypto_util.h" diff --git a/src/asn1/asn1c/Certificate.c b/src/asn1/asn1c/Certificate.c index 807b890d..73722e91 100644 --- a/src/asn1/asn1c/Certificate.c +++ b/src/asn1/asn1c/Certificate.c @@ -2,7 +2,7 @@ #include -#include "extension.h" +#include "ext.h" #include "json_util.h" #include "libcrypto_util.h" #include "log.h" diff --git a/src/common.c b/src/common.c index 03a5c762..bdcbe978 100644 --- a/src/common.c +++ b/src/common.c @@ -1,3 +1,6 @@ +#define _DEFAULT_SOURCE 1 /* timegm() on Linux */ +#define _DARWIN_C_SOURCE 1 /* timegm() on MacOS */ + #include "common.h" #include diff --git a/src/extension.c b/src/ext.c similarity index 99% rename from src/extension.c rename to src/ext.c index b9de9f26..8c7c342c 100644 --- a/src/extension.c +++ b/src/ext.c @@ -1,4 +1,4 @@ -#include "extension.h" +#include "ext.h" #include #include diff --git a/src/extension.h b/src/ext.h similarity index 100% rename from src/extension.h rename to src/ext.h diff --git a/src/libcrypto_util.c b/src/libcrypto_util.c index 74437c55..f4e60d28 100644 --- a/src/libcrypto_util.c +++ b/src/libcrypto_util.c @@ -9,7 +9,7 @@ #include "alloc.h" #include "asn1/asn1c/OBJECT_IDENTIFIER.h" -#include "extension.h" +#include "ext.h" #include "json_util.h" #include "log.h" diff --git a/src/log.c b/src/log.c index 0c2bd25d..9e3f6c7f 100644 --- a/src/log.c +++ b/src/log.c @@ -549,7 +549,7 @@ enomem_panic(void) garbage = write(STDERR_FILENO, ENOMEM_MSG, strlen(ENOMEM_MSG)); unlock_mutex(); /* Prevents "set but not used" warning. */ - garbage++; + garbage += garbage; } if (op_config.syslog_enabled) { diff --git a/src/main.c b/src/main.c index ccb789aa..b40d011d 100644 --- a/src/main.c +++ b/src/main.c @@ -2,7 +2,7 @@ #include "cache.h" #include "config.h" -#include "extension.h" +#include "ext.h" #include "hash.h" #include "http.h" #include "log.h" diff --git a/src/object/certificate.c b/src/object/certificate.c index d1d28661..3f59f5ac 100644 --- a/src/object/certificate.c +++ b/src/object/certificate.c @@ -17,7 +17,7 @@ #include "cache.h" #include "common.h" #include "config.h" -#include "extension.h" +#include "ext.h" #include "libcrypto_util.h" #include "log.h" #include "nid.h" diff --git a/src/object/crl.c b/src/object/crl.c index c0316a3a..dd12bdad 100644 --- a/src/object/crl.c +++ b/src/object/crl.c @@ -5,7 +5,7 @@ #include #include "algorithm.h" -#include "extension.h" +#include "ext.h" #include "log.h" #include "thread_var.h" #include "types/name.h" diff --git a/src/print_file.c b/src/print_file.c index c978ea64..ac3ec81f 100644 --- a/src/print_file.c +++ b/src/print_file.c @@ -1,3 +1,10 @@ +/* + * This seems like a MacOS bug. + * mkdtemp() is supposed to be POSIX 2008, + * but Mac considers it a "Darwin extension." + */ +#define _DARWIN_C_SOURCE 1 /* mkdtemp() on MacOS */ + #include "print_file.h" #include diff --git a/test/Makefile.am b/test/Makefile.am index 85f9867c..ca550ac3 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -13,107 +13,115 @@ if USE_TESTS # Otherwise it must be included manually: # mumble_mumble_CFLAGS = ${AM_CFLAGS} flag1 flag2 flag3 ... AM_CFLAGS = -Wall -Wpedantic -AM_CFLAGS += -std=c99 -D_DEFAULT_SOURCE=1 -D_XOPEN_SOURCE=700 -D_BSD_SOURCE=1 -AM_CFLAGS += -I../src -DUNIT_TESTING ${CHECK_CFLAGS} ${XML2_CFLAGS} ${JANSSON_CFLAGS} -# Reminder: As opposed to AM_CFLAGS, "AM_LDADD" is not idiomatic automake, and -# autotools will even reprehend us if we declare it. Therefore, I came up with -# "my" own "ldadd". Unlike AM_CFLAGS, it needs to be manually added to every -# target. -MY_LDADD = ${CHECK_LIBS} ${JANSSON_LIBS} - -check_PROGRAMS = address.test -check_PROGRAMS += base64.test -check_PROGRAMS += cache.test -check_PROGRAMS += common.test -check_PROGRAMS += db_table.test -check_PROGRAMS += deltas_array.test -check_PROGRAMS += hash.test -check_PROGRAMS += mft.test -check_PROGRAMS += pdu_handler.test -check_PROGRAMS += pdu_stream.test -check_PROGRAMS += rrdp.test -check_PROGRAMS += rrdp_update.test -check_PROGRAMS += rsync.test -check_PROGRAMS += serial.test -check_PROGRAMS += tal.test -check_PROGRAMS += task.test -check_PROGRAMS += thread_pool.test -check_PROGRAMS += url.test -check_PROGRAMS += uthash.test -check_PROGRAMS += vcard.test -check_PROGRAMS += vrps.test -check_PROGRAMS += xml.test -TESTS = ${check_PROGRAMS} - -############################################################################### - -address_test_SOURCES = types/address_test.c -address_test_LDADD = ${MY_LDADD} - -base64_test_SOURCES = base64_test.c -base64_test_LDADD = ${MY_LDADD} - -cache_test_SOURCES = cache_test.c -cache_test_LDADD = ${MY_LDADD} ${JANSSON_LIBS} ${XML2_LIBS} - -common_test_SOURCES = common_test.c -common_test_LDADD = ${MY_LDADD} - -db_table_test_SOURCES = rtr/db/db_table_test.c -db_table_test_LDADD = ${MY_LDADD} - -deltas_array_test_SOURCES = rtr/db/deltas_array_test.c -deltas_array_test_LDADD = ${MY_LDADD} - -hash_test_SOURCES = hash_test.c -hash_test_LDADD = ${MY_LDADD} - -mft_test_SOURCES = object/manifest_test.c -mft_test_LDADD = ${MY_LDADD} - -pdu_handler_test_SOURCES = rtr/pdu_handler_test.c -pdu_handler_test_LDADD = ${MY_LDADD} ${JANSSON_LIBS} - -pdu_stream_test_SOURCES = rtr/pdu_stream_test.c -pdu_stream_test_LDADD = ${MY_LDADD} ${JANSSON_LIBS} +# The extra info provided by this flag allows the linker to strip unused +# symbols, which reduces required superfluous #includes and mocks. +# It's supported by gcc and clang, not sure about others. +AM_CFLAGS += -flto +AM_CFLAGS += -std=c99 -D_XOPEN_SOURCE=700 +# Most (if not all) tests need common.c, which needs timegm() +AM_CFLAGS += -D_DEFAULT_SOURCE=1 -D_DARWIN_C_SOURCE=1 +AM_CFLAGS += -I../src -DUNIT_TESTING +AM_CFLAGS += ${CHECK_CFLAGS} ${XML2_CFLAGS} ${JANSSON_CFLAGS} +# AM_LDFLAGS isn't working on Linux, and "AM_LDADD" is not idiomatic +# automake. (autotools will reprehend us if we declare it.) + + +check_PROGRAMS = address.test +address_test_SOURCES = types/address_test.c +address_test_LDADD = ${CHECK_LIBS} + +check_PROGRAMS += base64.test +base64_test_SOURCES = base64_test.c +base64_test_LDADD = ${CHECK_LIBS} + +check_PROGRAMS += cache.test +cache_test_SOURCES = cache_test.c +cache_test_LDADD = ${CHECK_LIBS} +cache_test_LDADD += ${XML2_LIBS} +cache_test_LDADD += ${JANSSON_LIBS} + +check_PROGRAMS += common.test +common_test_SOURCES = common_test.c +common_test_LDADD = ${CHECK_LIBS} + +check_PROGRAMS += db_table.test +db_table_test_SOURCES = rtr/db/db_table_test.c +db_table_test_LDADD = ${CHECK_LIBS} + +check_PROGRAMS += deltas_array.test +deltas_array_test_SOURCES = rtr/db/deltas_array_test.c +deltas_array_test_LDADD = ${CHECK_LIBS} + +check_PROGRAMS += hash.test +hash_test_SOURCES = hash_test.c +hash_test_LDADD = ${CHECK_LIBS} + +check_PROGRAMS += mft.test +mft_test_SOURCES = object/manifest_test.c +mft_test_LDADD = ${CHECK_LIBS} + +check_PROGRAMS += pdu_handler.test +pdu_handler_test_SOURCES = rtr/pdu_handler_test.c +pdu_handler_test_LDADD = ${CHECK_LIBS} + +check_PROGRAMS += pdu_stream.test +pdu_stream_test_SOURCES = rtr/pdu_stream_test.c +pdu_stream_test_LDADD = ${CHECK_LIBS} + +check_PROGRAMS += rrdp.test +rrdp_test_SOURCES = rrdp_test.c +rrdp_test_LDADD = ${CHECK_LIBS} +rrdp_test_LDADD += ${XML2_LIBS} +rrdp_test_LDADD += ${JANSSON_LIBS} + +check_PROGRAMS += rrdp_update.test +rrdp_update_test_SOURCES = rrdp_update_test.c +rrdp_update_test_LDADD = ${CHECK_LIBS} +rrdp_update_test_LDADD += ${XML2_LIBS} + +check_PROGRAMS += rsync.test +rsync_test_SOURCES = rsync_test.c +rsync_test_LDADD = ${CHECK_LIBS} + +check_PROGRAMS += serial.test +serial_test_SOURCES = types/serial_test.c +serial_test_LDADD = ${CHECK_LIBS} + +check_PROGRAMS += tal.test +tal_test_SOURCES = object/tal_test.c +tal_test_LDADD = ${CHECK_LIBS} + +check_PROGRAMS += task.test +task_test_SOURCES = task_test.c +task_test_LDADD = ${CHECK_LIBS} + +check_PROGRAMS += thread_pool.test +thread_pool_test_SOURCES = thread_pool_test.c +thread_pool_test_LDADD = ${CHECK_LIBS} + +check_PROGRAMS += url.test +url_test_SOURCES = types/url_test.c +url_test_LDADD = ${CHECK_LIBS} + +check_PROGRAMS += uthash.test +uthash_test_SOURCES = types/uthash_test.c +uthash_test_LDADD = ${CHECK_LIBS} + +check_PROGRAMS += vcard.test +vcard_test_SOURCES = vcard_test.c +vcard_test_LDADD = ${CHECK_LIBS} + +check_PROGRAMS += vrps.test +vrps_test_SOURCES = rtr/db/vrps_test.c +vrps_test_LDADD = ${CHECK_LIBS} + +check_PROGRAMS += xml.test +xml_test_SOURCES = xml_test.c +xml_test_LDADD = ${CHECK_LIBS} +xml_test_LDADD += ${XML2_LIBS} -rrdp_test_SOURCES = rrdp_test.c -rrdp_test_LDADD = ${MY_LDADD} ${JANSSON_LIBS} ${XML2_LIBS} - -rrdp_update_test_SOURCES = rrdp_update_test.c -rrdp_update_test_LDADD = ${MY_LDADD} ${JANSSON_LIBS} ${XML2_LIBS} - -rsync_test_SOURCES = rsync_test.c -rsync_test_LDADD = ${MY_LDADD} - -serial_test_SOURCES = types/serial_test.c -serial_test_LDADD = ${MY_LDADD} - -tal_test_SOURCES = object/tal_test.c -tal_test_LDADD = ${MY_LDADD} - -task_test_SOURCES = task_test.c -task_test_LDADD = ${MY_LDADD} - -thread_pool_test_SOURCES = thread_pool_test.c -thread_pool_test_LDADD = ${MY_LDADD} - -url_test_SOURCES = types/url_test.c -url_test_LDADD = ${MY_LDADD} ${JANSSON_LIBS} - -uthash_test_SOURCES = types/uthash_test.c -uthash_test_LDADD = ${MY_LDADD} - -vcard_test_SOURCES = vcard_test.c -vcard_test_LDADD = ${MY_LDADD} - -vrps_test_SOURCES = rtr/db/vrps_test.c -vrps_test_LDADD = ${MY_LDADD} ${JANSSON_LIBS} - -xml_test_SOURCES = xml_test.c -xml_test_LDADD = ${MY_LDADD} ${XML2_LIBS} +TESTS = ${check_PROGRAMS} -############################################################################### EXTRA_DIST = mock.c mock.h EXTRA_DIST += resources/lorem-ipsum.txt diff --git a/test/cache_test.c b/test/cache_test.c index 841a5a10..89e699a2 100644 --- a/test/cache_test.c +++ b/test/cache_test.c @@ -18,7 +18,6 @@ #include "rrdp.c" #include "types/map.c" #include "types/path.c" -#include "types/str.c" #include "types/url.c" /* Mocks */ diff --git a/test/hash_test.c b/test/hash_test.c index 0e4e6020..79dc9054 100644 --- a/test/hash_test.c +++ b/test/hash_test.c @@ -6,7 +6,6 @@ #include "file.c" #include "hash.c" #include "mock.c" -#include "types/path.c" /* Actually mostly tests libcrypto's sanity, not Fort's. */ START_TEST(test_hash) diff --git a/test/object/manifest_test.c b/test/object/manifest_test.c index e19af31f..3168674e 100644 --- a/test/object/manifest_test.c +++ b/test/object/manifest_test.c @@ -5,12 +5,6 @@ #include "common.c" #include "mock.c" #include "object/manifest.c" -#include "types/map.c" -#include "types/path.c" -#include "types/url.c" - -MOCK_ABORT_INT(signed_object_decode, struct signed_object *sobj, char const *path) -MOCK_ABORT_VOID(signed_object_cleanup, struct signed_object *sobj) #define BUFFER_LEN 128 static uint8_t buffer[BUFFER_LEN]; diff --git a/test/object/tal_test.c b/test/object/tal_test.c index a8388915..eca8ab8c 100644 --- a/test/object/tal_test.c +++ b/test/object/tal_test.c @@ -7,27 +7,10 @@ #include "common.c" #include "file.c" #include "mock.c" -#include "types/map.c" #include "types/path.c" #include "types/str.c" #include "types/url.c" -/* Mocks */ - -MOCK_ABORT_INT(cache_prepare, void) -MOCK_ABORT_VOID(cache_commit, void) -MOCK_ABORT_PTR(db_table_create, db_table, void) -MOCK_VOID(db_table_destroy, struct db_table *table) -MOCK_ABORT_INT(db_table_join, struct db_table *dst, struct db_table *src) -MOCK_ABORT_INT(handle_roa_v4, uint32_t as, struct ipv4_prefix const *prefix, - uint8_t max_length, void *arg) -MOCK_ABORT_INT(handle_roa_v6, uint32_t as, struct ipv6_prefix const *prefix, - uint8_t max_length, void *arg) -MOCK_ABORT_INT(handle_router_key, unsigned char const *ski, - struct asn_range const *asns, unsigned char const *spk, void *arg) - -/* Tests */ - static void check_spki(struct tal *tal) { diff --git a/test/rrdp_test.c b/test/rrdp_test.c index d373252a..dd8c6889 100644 --- a/test/rrdp_test.c +++ b/test/rrdp_test.c @@ -4,7 +4,6 @@ #include "alloc.c" #include "base64.c" -#include "cachetmp.c" #include "common.c" #include "file.c" #include "hash.c" @@ -13,16 +12,8 @@ #include "relax_ng.c" #include "rrdp.c" #include "types/map.c" -#include "types/path.c" #include "types/url.c" -/* Mocks */ - -MOCK_ABORT_INT(http_download, char const *url, char const *path, curl_off_t ims, - bool *changed) - -/* Mocks end */ - static void ck_rrdp_session(char const *session, char const *serial, struct rrdp_session *actual) diff --git a/test/rrdp_update_test.c b/test/rrdp_update_test.c index 5f346895..447779db 100644 --- a/test/rrdp_update_test.c +++ b/test/rrdp_update_test.c @@ -6,14 +6,12 @@ #include "common.c" #include "file.c" #include "hash.c" -#include "json_util.c" #include "mock.c" #include "mock_https.c" #include "relax_ng.c" #include "rrdp.c" #include "rrdp_util.h" #include "types/map.c" -#include "types/path.c" #include "types/url.c" /* Utils */ diff --git a/test/rtr/db/db_table_test.c b/test/rtr/db/db_table_test.c index 6dfc2d4f..23ab16b6 100644 --- a/test/rtr/db/db_table_test.c +++ b/test/rtr/db/db_table_test.c @@ -4,11 +4,8 @@ #include "alloc.c" #include "common.c" #include "mock.c" +#include "types/array.h" #include "types/address.c" -#include "types/delta.c" -#include "types/router_key.c" -#include "types/vrp.c" -#include "rtr/db/delta.c" #include "rtr/db/db_table.c" #define ADDR1 htonl(0xC0000201) /* 192.0.2.1 */ diff --git a/test/rtr/db/deltas_array_test.c b/test/rtr/db/deltas_array_test.c index 37246209..6c561b0e 100644 --- a/test/rtr/db/deltas_array_test.c +++ b/test/rtr/db/deltas_array_test.c @@ -3,10 +3,6 @@ #include "alloc.c" #include "mock.c" -#include "types/address.c" -#include "types/delta.c" -#include "types/router_key.c" -#include "types/vrp.c" #include "rtr/db/delta.c" #include "rtr/db/deltas_array.c" diff --git a/test/rtr/db/vrps_test.c b/test/rtr/db/vrps_test.c index d675a679..15d5ad49 100644 --- a/test/rtr/db/vrps_test.c +++ b/test/rtr/db/vrps_test.c @@ -2,12 +2,10 @@ #include #include -#include "algorithm.c" #include "alloc.c" #include "base64.c" #include "common.c" #include "file.c" -#include "json_util.c" #include "mock.c" #include "output_printer.c" #include "rtr/db/db_table.c" @@ -15,12 +13,7 @@ #include "rtr/db/deltas_array.c" #include "rtr/db/rtr_db_mock.c" #include "rtr/db/vrps.c" -#include "slurm/db_slurm.c" #include "slurm/slurm_loader.c" -#include "slurm/slurm_parser.c" -#include "thread_pool.c" -#include "types/delta.c" -#include "types/path.c" #include "types/router_key.c" #include "types/serial.c" #include "types/vrp.c" @@ -71,6 +64,7 @@ static unsigned int deltas_lifetime = 5; MOCK_UINT(config_get_deltas_lifetime, deltas_lifetime, void) MOCK_ABORT_ENUM(config_get_output_format, output_format, void) +MOCK_ABORT_VOID(db_slurm_destroy, struct db_slurm *db) /* Test functions */ diff --git a/test/rtr/pdu_handler_test.c b/test/rtr/pdu_handler_test.c index 910c92d1..2d8c24ad 100644 --- a/test/rtr/pdu_handler_test.c +++ b/test/rtr/pdu_handler_test.c @@ -6,7 +6,6 @@ #include "alloc.c" #include "common.c" #include "mock.c" -#include "types/delta.c" #include "types/router_key.c" #include "types/serial.c" #include "types/vrp.c" @@ -17,7 +16,6 @@ #include "rtr/db/db_table.c" #include "rtr/db/rtr_db_mock.c" #include "rtr/db/vrps.c" -#include "thread_pool.c" /* Mocks */ diff --git a/test/task_test.c b/test/task_test.c index c2e34392..5df2f53b 100644 --- a/test/task_test.c +++ b/test/task_test.c @@ -7,7 +7,6 @@ #include "mock.c" #include "types/array.h" #include "types/map.c" -#include "types/path.c" void rpki_certificate_free(struct rpki_certificate *cert)