]> git.ipfire.org Git - thirdparty/FORT-validator.git/commitdiff
Makefile maintenance
authorAlberto Leiva Popper <ydahhrk@gmail.com>
Mon, 2 Dec 2024 17:15:39 +0000 (14:15 -0300)
committerAlberto Leiva Popper <ydahhrk@gmail.com>
Mon, 2 Dec 2024 17:15:39 +0000 (14:15 -0300)
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.

24 files changed:
src/Makefile.am
src/asn1/asn1c/CRL.c
src/asn1/asn1c/Certificate.c
src/common.c
src/ext.c [moved from src/extension.c with 99% similarity]
src/ext.h [moved from src/extension.h with 100% similarity]
src/libcrypto_util.c
src/log.c
src/main.c
src/object/certificate.c
src/object/crl.c
src/print_file.c
test/Makefile.am
test/cache_test.c
test/hash_test.c
test/object/manifest_test.c
test/object/tal_test.c
test/rrdp_test.c
test/rrdp_update_test.c
test/rtr/db/db_table_test.c
test/rtr/db/deltas_array_test.c
test/rtr/db/vrps_test.c
test/rtr/pdu_handler_test.c
test/task_test.c

index 5f41650b512ae01f21f1bcc7788605eea36164d6..2ba315a6d6438c7da23155c194e1f3c907706da9 100644 (file)
@@ -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
index fbcc02ecb1c8d978e8dded601916b555553198c4..d3d91c9310309fe19e94940d635ca29dad1f0d5c 100644 (file)
@@ -2,7 +2,7 @@
 
 #include <openssl/objects.h>
 
-#include "extension.h"
+#include "ext.h"
 #include "json_util.h"
 #include "libcrypto_util.h"
 
index 807b890d29a4083a29e7c9e1f47a37a606a9e3b8..73722e913ea01b33867ae1a6f2fa0db2a12c8129 100644 (file)
@@ -2,7 +2,7 @@
 
 #include <openssl/objects.h>
 
-#include "extension.h"
+#include "ext.h"
 #include "json_util.h"
 #include "libcrypto_util.h"
 #include "log.h"
index 03a5c7629032c5e0f35ed2c448795f89f2f0ecb0..bdcbe978b6171cbfe9581d8fc3b084cab9404bf4 100644 (file)
@@ -1,3 +1,6 @@
+#define _DEFAULT_SOURCE  1     /* timegm() on Linux */
+#define _DARWIN_C_SOURCE 1     /* timegm() on MacOS */
+
 #include "common.h"
 
 #include <dirent.h>
similarity index 99%
rename from src/extension.c
rename to src/ext.c
index b9de9f269409849fd8efce26fca9b66f1db0a336..8c7c342cc1b75e4a8cc2021e22514060eb63e3fb 100644 (file)
+++ b/src/ext.c
@@ -1,4 +1,4 @@
-#include "extension.h"
+#include "ext.h"
 
 #include <openssl/asn1t.h>
 #include <openssl/obj_mac.h>
similarity index 100%
rename from src/extension.h
rename to src/ext.h
index 74437c55711aecefbbd8971c349c497507d068da..f4e60d2845faa2340823d0778202c006cc924366 100644 (file)
@@ -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"
 
index 0c2bd25d5b3b4284eb63957e3136346824604136..9e3f6c7fbe04a1e0fe2be5661f6cebb0a5af33f7 100644 (file)
--- 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) {
index ccb789aa8df7187e271d643255c4bc66dd150c3f..b40d011db86e202ff6ee2414255bf525cd46b2c9 100644 (file)
@@ -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"
index d1d28661e678e575e78e32951247b3861879a8c6..3f59f5ac8a18a0be7c07d74981a3dcf1cff012f6 100644 (file)
@@ -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"
index c0316a3a67c093ec1266b50264a99a1bc56187ce..dd12bdadf0751e641006f939579bd2639213e912 100644 (file)
@@ -5,7 +5,7 @@
 #include <syslog.h>
 
 #include "algorithm.h"
-#include "extension.h"
+#include "ext.h"
 #include "log.h"
 #include "thread_var.h"
 #include "types/name.h"
index c978ea64b91f9c75e5bd5cbb6e3f617183d26a19..ac3ec81facff42a4da4866ceb7c8f8b50e6c72ee 100644 (file)
@@ -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 <errno.h>
index 85f9867ce69e575b1f829ad08ec28d5ddc1abee7..ca550ac3d94051b53fa66bcb3969243e92e14185 100644 (file)
@@ -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
index 841a5a1051832de924a4086ea4bd94e462030633..89e699a2522fcc411ef2e55028c2630947a89dfb 100644 (file)
@@ -18,7 +18,6 @@
 #include "rrdp.c"
 #include "types/map.c"
 #include "types/path.c"
-#include "types/str.c"
 #include "types/url.c"
 
 /* Mocks */
index 0e4e6020b0909e602bf9e8ed359ead9b612447b3..79dc905486a0f7cd4fc2c1619e6ef39ea69b070e 100644 (file)
@@ -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)
index e19af31fc192625964ce136782bff84f460f7221..3168674e8c68683440053e46c7ca754709d07d68 100644 (file)
@@ -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];
index a8388915bf2d9a2378a9c5cda828b3e4852bd8c1..eca8ab8cc141c1e8b2b4d29c99d2a6fff886d2a9 100644 (file)
@@ -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)
 {
index d373252ac6cecf7853e4a103e7512f5bc2012ea1..dd8c6889de2df396dc6596b919fd4d188f24a7d2 100644 (file)
@@ -4,7 +4,6 @@
 
 #include "alloc.c"
 #include "base64.c"
-#include "cachetmp.c"
 #include "common.c"
 #include "file.c"
 #include "hash.c"
 #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)
index 5f3468959c6dcc13fe9f47509daa479deb2ca3e5..447779db98016930a153b19dc701ceb6d5713cdc 100644 (file)
@@ -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 */
index 6dfc2d4ffcd72c0a4b5e9635d17f1984a67e62f2..23ab16b640b492d04a5a3a92626a56e3843eb8ee 100644 (file)
@@ -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 */
index 3724620936243f9cc019426cc604cb1ba92bb161..6c561b0e54429f056bbb811142305ae9b5628dd8 100644 (file)
@@ -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"
 
index d675a679270c1dfa7b6dfbee2153c6ff4e8d20a2..15d5ad4924d6150346f57062ee5f0e6572cb5966 100644 (file)
@@ -2,12 +2,10 @@
 #include <stdbool.h>
 #include <stdlib.h>
 
-#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"
 #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 */
 
index 910c92d10421080f8b4962ff2445aaa52108a9b0..2d8c24ad9258df63b8db5f162696f98b1e53d45d 100644 (file)
@@ -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 */
 
index c2e343921fa58002f1362e80cc5395482104b745..5df2f53bcdac7f8c436c5df987ed7a52caa0950e 100644 (file)
@@ -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)