Consolidated the makefile further. Phew.

git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@3882 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
Cory McWilliams 2022-05-30 17:24:42 +00:00
parent b06c657ef0
commit 2882af1c05

100
Makefile
View File

@ -13,14 +13,12 @@ CFLAGS += \
-fdata-sections -fdata-sections
LDFLAGS += -Wl,-gc-sections LDFLAGS += -Wl,-gc-sections
debug: CFLAGS += -Og -g debug windebug: CFLAGS += -Og -g
release: CFLAGS += -DNDEBUG -O3 -g release winrelease: CFLAGS += -DNDEBUG -O3 -g
windebug winrelease: CC = i686-w64-mingw32-gcc-win32 windebug winrelease: CC = i686-w64-mingw32-gcc-win32
windebug winrelease: AS = $(CC) windebug winrelease: AS = $(CC)
windebug winrelease: CFLAGS += -D_WIN32_WINNT=0x0A00 -DWINVER=0x0A00 -DNTDDI_VERSION=NTDDI_WIN10 windebug winrelease: CFLAGS += -D_WIN32_WINNT=0x0A00 -DWINVER=0x0A00 -DNTDDI_VERSION=NTDDI_WIN10
windebug winrelease: LDFLAGS += -static windebug winrelease: LDFLAGS += -static
windebug: CFLAGS += -Og -g
winrelease: CFLAGS += -DNDEBUG -O3 -g
ifeq ($(UNAME_M),x86_64) ifeq ($(UNAME_M),x86_64)
debug: CFLAGS += -fsanitize=address -fsanitize=undefined debug: CFLAGS += -fsanitize=address -fsanitize=undefined
@ -28,9 +26,9 @@ debug: LDFLAGS += -fsanitize=address -fsanitize=undefined
endif endif
get_objs = \ get_objs = \
$(foreach build_type,$(BUILD_TYPES),$(addprefix out/$(build_type)/,$(addsuffix .o,$(basename $(value $(1)))))) \ $(foreach build_type,$(BUILD_TYPES),$(addprefix $(BUILD_DIR)/$(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,debug release,$(addprefix $(BUILD_DIR)/$(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,windebug winrelease,$(addprefix $(BUILD_DIR)/$(build_type)/,$(addsuffix .o,$(basename $(value $(1)_win)))))
APP_SOURCES := $(wildcard src/*.c) APP_SOURCES := $(wildcard src/*.c)
APP_OBJS := $(call get_objs,APP_SOURCES) APP_OBJS := $(call get_objs,APP_SOURCES)
@ -123,7 +121,6 @@ UV_SOURCES_win := \
deps/libuv/src/win/winapi.c \ deps/libuv/src/win/winapi.c \
deps/libuv/src/win/winsock.c deps/libuv/src/win/winsock.c
UV_OBJS := $(call get_objs,UV_SOURCES) UV_OBJS := $(call get_objs,UV_SOURCES)
$(info $(UV_OBJS))
$(UV_OBJS): CFLAGS += \ $(UV_OBJS): CFLAGS += \
-Ideps/libuv/include \ -Ideps/libuv/include \
-Ideps/libuv/src \ -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/ed25519/ref10/ed25519_ref10.c \
deps/libsodium/src/libsodium/crypto_core/hsalsa20/ref2/core_hsalsa20_ref2.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_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_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/cp/hash_sha256_cp.c \
deps/libsodium/src/libsodium/crypto_hash/sha256/hash_sha256.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/ref10/x25519_ref10.c \
deps/libsodium/src/libsodium/crypto_scalarmult/curve25519/scalarmult_curve25519.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/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/crypto_sign.c \
deps/libsodium/src/libsodium/crypto_sign/ed25519/ref10/keypair.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/open.c \
deps/libsodium/src/libsodium/crypto_sign/ed25519/ref10/sign.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/ref/salsa20_ref.c \
deps/libsodium/src/libsodium/crypto_stream/salsa20/stream_salsa20.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/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/crypto_verify/sodium/verify.c \
deps/libsodium/src/libsodium/randombytes/randombytes.c \ deps/libsodium/src/libsodium/randombytes/randombytes.c \
deps/libsodium/src/libsodium/randombytes/sysrandom/randombytes_sysrandom.c \ deps/libsodium/src/libsodium/randombytes/sysrandom/randombytes_sysrandom.c \
@ -201,7 +198,7 @@ $(SQLITE_OBJS): CFLAGS += \
XOPT_SOURCES := deps/xopt/xopt.c XOPT_SOURCES := deps/xopt/xopt.c
XOPT_OBJS := $(call get_objs,XOPT_SOURCES) XOPT_OBJS := $(call get_objs,XOPT_SOURCES)
$(filter out/win%,$(XOPT_OBJS)): CFLAGS += \ $(filter $(BUILD_DIR)/win%,$(XOPT_OBJS)): CFLAGS += \
-DHAVE_SNPRINTF \ -DHAVE_SNPRINTF \
-DHAVE_VSNPRINTF \ -DHAVE_VSNPRINTF \
-DHAVE_VASNPRINTF \ -DHAVE_VASNPRINTF \
@ -229,35 +226,21 @@ $(QUICKJS_OBJS): CFLAGS += \
LDFLAGS += \ LDFLAGS += \
-pthread \ -pthread \
-lm -lm
debug: LDFLAGS += \ debug release: LDFLAGS += \
-ldl \ -ldl \
-lssl \ -lssl \
-lcrypto -lcrypto
release: LDFLAGS += \ windebug winrelease: LDFLAGS += \
-ldl \
-lssl \
-lcrypto
windebug: LDFLAGS += \
-lwsock32 \
-lws2_32 \
-lkernel32 \
-liphlpapi \
-luserenv
winrelease: LDFLAGS += \
-lwsock32 \ -lwsock32 \
-lws2_32 \ -lws2_32 \
-lkernel32 \ -lkernel32 \
-liphlpapi \ -liphlpapi \
-luserenv -luserenv
debug: $(BUILD_DIR)/debug/$(PROJECT)
release: $(BUILD_DIR)/release/$(PROJECT)
windebug: $(BUILD_DIR)/windebug/$(PROJECT)
winrelease: $(BUILD_DIR)/winrelease/$(PROJECT)
unix: debug release unix: debug release
win: windebug winrelease win: windebug winrelease
all: $(BUILD_TYPES) all: $(BUILD_TYPES)
.PHONY: all $(BUILD_TYPES) win unix .PHONY: all win unix
ALL_APP_OBJS := \ ALL_APP_OBJS := \
$(APP_OBJS) \ $(APP_OBJS) \
@ -272,47 +255,26 @@ ALL_APP_OBJS := \
DEPS = $(ALL_APP_OBJS:.o=.d) DEPS = $(ALL_APP_OBJS:.o=.d)
-include $(DEPS) -include $(DEPS)
$(BUILD_DIR)/debug/$(PROJECT): $(filter out/debug/%,$(ALL_APP_OBJS)) define build_rules
$(CC) -o $@ $^ $(LDFLAGS) $(1): $(BUILD_DIR)/$(1)/$(PROJECT)$(if $(filter win%,$(1)),.exe)
.PHONY: $(1)
$(BUILD_DIR)/release/$(PROJECT): $(filter out/release/%,$(ALL_APP_OBJS)) $(BUILD_DIR)/$(1)/$(PROJECT)$(if $(filter win%,$(1)),.exe): $(filter $(BUILD_DIR)/$(1)/%,$(ALL_APP_OBJS))
$(CC) -o $@ $^ $(LDFLAGS) @echo [link] $$@
@$$(CC) -o $$@ $$^ $$(LDFLAGS)
$(BUILD_DIR)/windebug/$(PROJECT): $(filter out/windebug/%,$(ALL_APP_OBJS)) $(BUILD_DIR)/$(1)/%.o: %.c
$(CC) -o $@ $^ $(LDFLAGS) @mkdir -p $$(dir $$@)
@echo [c] $$@
@$$(CC) $$(CFLAGS) -c $$< -o $$@
$(BUILD_DIR)/winrelease/$(PROJECT): $(filter out/winrelease/%,$(ALL_APP_OBJS)) $(BUILD_DIR)/$(1)/%.o: %.S
$(CC) -o $@ $^ $(LDFLAGS) @mkdir -p $$(dir $$@)
@echo [as] $$@
@$$(AS) -c $$< -o $$@
endef
$(BUILD_DIR)/debug/%.o: %.c $(foreach build_type,$(BUILD_TYPES),$(eval $(call build_rules,$(build_type))))
@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 $@
clean: clean:
rm -rf $(BUILD_DIR) rm -rf $(BUILD_DIR)