From 2882af1c054772193d4c7ecf343e8ac4b723f98e Mon Sep 17 00:00:00 2001 From: Cory McWilliams Date: Mon, 30 May 2022 17:24:42 +0000 Subject: [PATCH] Consolidated the makefile further. Phew. git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@3882 ed5197a5-7fde-0310-b194-c3ffbd925b24 --- Makefile | 100 +++++++++++++++++-------------------------------------- 1 file changed, 31 insertions(+), 69 deletions(-) diff --git a/Makefile b/Makefile index 73ecf41f..e21fad1c 100644 --- a/Makefile +++ b/Makefile @@ -13,14 +13,12 @@ CFLAGS += \ -fdata-sections LDFLAGS += -Wl,-gc-sections -debug: CFLAGS += -Og -g -release: CFLAGS += -DNDEBUG -O3 -g +debug windebug: CFLAGS += -Og -g +release winrelease: CFLAGS += -DNDEBUG -O3 -g windebug winrelease: CC = i686-w64-mingw32-gcc-win32 windebug winrelease: AS = $(CC) windebug winrelease: CFLAGS += -D_WIN32_WINNT=0x0A00 -DWINVER=0x0A00 -DNTDDI_VERSION=NTDDI_WIN10 windebug winrelease: LDFLAGS += -static -windebug: CFLAGS += -Og -g -winrelease: CFLAGS += -DNDEBUG -O3 -g ifeq ($(UNAME_M),x86_64) debug: CFLAGS += -fsanitize=address -fsanitize=undefined @@ -28,9 +26,9 @@ debug: LDFLAGS += -fsanitize=address -fsanitize=undefined endif get_objs = \ - $(foreach build_type,$(BUILD_TYPES),$(addprefix out/$(build_type)/,$(addsuffix .o,$(basename $(value $(1)))))) \ - $(foreach build_type,debug release,$(addprefix out/$(build_type)/,$(addsuffix .o,$(basename $(value $(1)_unix))))) \ - $(foreach build_type,windebug winrelease,$(addprefix out/$(build_type)/,$(addsuffix .o,$(basename $(value $(1)_win))))) + $(foreach build_type,$(BUILD_TYPES),$(addprefix $(BUILD_DIR)/$(build_type)/,$(addsuffix .o,$(basename $(value $(1)))))) \ + $(foreach build_type,debug release,$(addprefix $(BUILD_DIR)/$(build_type)/,$(addsuffix .o,$(basename $(value $(1)_unix))))) \ + $(foreach build_type,windebug winrelease,$(addprefix $(BUILD_DIR)/$(build_type)/,$(addsuffix .o,$(basename $(value $(1)_win))))) APP_SOURCES := $(wildcard src/*.c) APP_OBJS := $(call get_objs,APP_SOURCES) @@ -123,7 +121,6 @@ UV_SOURCES_win := \ deps/libuv/src/win/winapi.c \ deps/libuv/src/win/winsock.c UV_OBJS := $(call get_objs,UV_SOURCES) -$(info $(UV_OBJS)) $(UV_OBJS): CFLAGS += \ -Ideps/libuv/include \ -Ideps/libuv/src \ @@ -140,6 +137,8 @@ SODIUM_SOURCES := \ deps/libsodium/src/libsodium/crypto_core/ed25519/ref10/ed25519_ref10.c \ deps/libsodium/src/libsodium/crypto_core/hsalsa20/ref2/core_hsalsa20_ref2.c \ deps/libsodium/src/libsodium/crypto_core/salsa/ref/core_salsa_ref.c \ + deps/libsodium/src/libsodium/crypto_generichash/blake2b/ref/blake2b-compress-ref.c \ + deps/libsodium/src/libsodium/crypto_generichash/blake2b/ref/blake2b-ref.c \ deps/libsodium/src/libsodium/crypto_generichash/blake2b/ref/generichash_blake2b.c \ deps/libsodium/src/libsodium/crypto_hash/sha256/cp/hash_sha256_cp.c \ deps/libsodium/src/libsodium/crypto_hash/sha256/hash_sha256.c \ @@ -153,19 +152,17 @@ SODIUM_SOURCES := \ deps/libsodium/src/libsodium/crypto_scalarmult/curve25519/ref10/x25519_ref10.c \ deps/libsodium/src/libsodium/crypto_scalarmult/curve25519/scalarmult_curve25519.c \ deps/libsodium/src/libsodium/crypto_secretbox/crypto_secretbox_easy.c \ + deps/libsodium/src/libsodium/crypto_secretbox/xsalsa20poly1305/secretbox_xsalsa20poly1305.c \ deps/libsodium/src/libsodium/crypto_sign/crypto_sign.c \ deps/libsodium/src/libsodium/crypto_sign/ed25519/ref10/keypair.c \ deps/libsodium/src/libsodium/crypto_sign/ed25519/ref10/open.c \ deps/libsodium/src/libsodium/crypto_sign/ed25519/ref10/sign.c \ + deps/libsodium/src/libsodium/crypto_sign/ed25519/sign_ed25519.c \ + deps/libsodium/src/libsodium/crypto_stream/chacha20/ref/chacha20_ref.c \ + deps/libsodium/src/libsodium/crypto_stream/chacha20/stream_chacha20.c \ deps/libsodium/src/libsodium/crypto_stream/salsa20/ref/salsa20_ref.c \ deps/libsodium/src/libsodium/crypto_stream/salsa20/stream_salsa20.c \ deps/libsodium/src/libsodium/crypto_stream/xsalsa20/stream_xsalsa20.c \ - deps/libsodium/src/libsodium/crypto_stream/chacha20/stream_chacha20.c \ - deps/libsodium/src/libsodium/crypto_generichash/blake2b/ref/blake2b-ref.c \ - deps/libsodium/src/libsodium/crypto_stream/chacha20/ref/chacha20_ref.c \ - deps/libsodium/src/libsodium/crypto_generichash/blake2b/ref/blake2b-compress-ref.c \ - deps/libsodium/src/libsodium/crypto_secretbox/xsalsa20poly1305/secretbox_xsalsa20poly1305.c \ - deps/libsodium/src/libsodium/crypto_sign/ed25519/sign_ed25519.c \ deps/libsodium/src/libsodium/crypto_verify/sodium/verify.c \ deps/libsodium/src/libsodium/randombytes/randombytes.c \ deps/libsodium/src/libsodium/randombytes/sysrandom/randombytes_sysrandom.c \ @@ -201,7 +198,7 @@ $(SQLITE_OBJS): CFLAGS += \ XOPT_SOURCES := deps/xopt/xopt.c XOPT_OBJS := $(call get_objs,XOPT_SOURCES) -$(filter out/win%,$(XOPT_OBJS)): CFLAGS += \ +$(filter $(BUILD_DIR)/win%,$(XOPT_OBJS)): CFLAGS += \ -DHAVE_SNPRINTF \ -DHAVE_VSNPRINTF \ -DHAVE_VASNPRINTF \ @@ -229,35 +226,21 @@ $(QUICKJS_OBJS): CFLAGS += \ LDFLAGS += \ -pthread \ -lm -debug: LDFLAGS += \ +debug release: LDFLAGS += \ -ldl \ -lssl \ -lcrypto -release: LDFLAGS += \ - -ldl \ - -lssl \ - -lcrypto -windebug: LDFLAGS += \ - -lwsock32 \ - -lws2_32 \ - -lkernel32 \ - -liphlpapi \ - -luserenv -winrelease: LDFLAGS += \ +windebug winrelease: LDFLAGS += \ -lwsock32 \ -lws2_32 \ -lkernel32 \ -liphlpapi \ -luserenv -debug: $(BUILD_DIR)/debug/$(PROJECT) -release: $(BUILD_DIR)/release/$(PROJECT) -windebug: $(BUILD_DIR)/windebug/$(PROJECT) -winrelease: $(BUILD_DIR)/winrelease/$(PROJECT) unix: debug release win: windebug winrelease all: $(BUILD_TYPES) -.PHONY: all $(BUILD_TYPES) win unix +.PHONY: all win unix ALL_APP_OBJS := \ $(APP_OBJS) \ @@ -272,47 +255,26 @@ ALL_APP_OBJS := \ DEPS = $(ALL_APP_OBJS:.o=.d) -include $(DEPS) -$(BUILD_DIR)/debug/$(PROJECT): $(filter out/debug/%,$(ALL_APP_OBJS)) - $(CC) -o $@ $^ $(LDFLAGS) +define build_rules +$(1): $(BUILD_DIR)/$(1)/$(PROJECT)$(if $(filter win%,$(1)),.exe) +.PHONY: $(1) -$(BUILD_DIR)/release/$(PROJECT): $(filter out/release/%,$(ALL_APP_OBJS)) - $(CC) -o $@ $^ $(LDFLAGS) +$(BUILD_DIR)/$(1)/$(PROJECT)$(if $(filter win%,$(1)),.exe): $(filter $(BUILD_DIR)/$(1)/%,$(ALL_APP_OBJS)) + @echo [link] $$@ + @$$(CC) -o $$@ $$^ $$(LDFLAGS) -$(BUILD_DIR)/windebug/$(PROJECT): $(filter out/windebug/%,$(ALL_APP_OBJS)) - $(CC) -o $@ $^ $(LDFLAGS) +$(BUILD_DIR)/$(1)/%.o: %.c + @mkdir -p $$(dir $$@) + @echo [c] $$@ + @$$(CC) $$(CFLAGS) -c $$< -o $$@ -$(BUILD_DIR)/winrelease/$(PROJECT): $(filter out/winrelease/%,$(ALL_APP_OBJS)) - $(CC) -o $@ $^ $(LDFLAGS) +$(BUILD_DIR)/$(1)/%.o: %.S + @mkdir -p $$(dir $$@) + @echo [as] $$@ + @$$(AS) -c $$< -o $$@ +endef -$(BUILD_DIR)/debug/%.o: %.c - @mkdir -p $(dir $@) - @echo [c] $@ - @$(CC) $(CFLAGS) -c $< -o $@ - -$(BUILD_DIR)/release/%.o: %.c - @mkdir -p $(dir $@) - @echo [c] $@ - @$(CC) $(CFLAGS) -c $< -o $@ - -$(BUILD_DIR)/windebug/%.o: %.c - @mkdir -p $(dir $@) - @echo [c] $@ - @$(CC) $(CFLAGS) -c $< -o $@ - -$(BUILD_DIR)/windebug/%.o: %.S - @mkdir -p $(dir $@) - @echo [as] $@ - @$(AS) -c $< -o $@ - -$(BUILD_DIR)/winrelease/%.o: %.c - @mkdir -p $(dir $@) - @echo [c] $@ - @$(CC) $(CFLAGS) -c $< -o $@ - -$(BUILD_DIR)/winrelease/%.o: %.S - @mkdir -p $(dir $@) - @echo [as] $@ - @$(AS) -c $< -o $@ +$(foreach build_type,$(BUILD_TYPES),$(eval $(call build_rules,$(build_type)))) clean: rm -rf $(BUILD_DIR)