Remove some of the repetition in the Makefile.

git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@3881 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
Cory McWilliams 2022-05-26 00:47:36 +00:00
parent 04ec425c9c
commit b06c657ef0

169
Makefile
View File

@ -1,8 +1,6 @@
PROJECT = tildefriends PROJECT = tildefriends
BUILD_DIR ?= out BUILD_DIR ?= out
BUILD_DIR_DBG := $(BUILD_DIR)/debug BUILD_TYPES := debug release windebug winrelease
BUILD_DIR_REL := $(BUILD_DIR)/release
BUILD_DIR_WIN := $(BUILD_DIR)/win
UNAME_M := $(shell uname -m) UNAME_M := $(shell uname -m)
CFLAGS += \ CFLAGS += \
@ -17,21 +15,25 @@ LDFLAGS += -Wl,-gc-sections
debug: CFLAGS += -Og -g debug: CFLAGS += -Og -g
release: CFLAGS += -DNDEBUG -O3 -g release: CFLAGS += -DNDEBUG -O3 -g
win: CC = i686-w64-mingw32-gcc-win32 windebug winrelease: CC = i686-w64-mingw32-gcc-win32
win: AS = $(CC) windebug winrelease: AS = $(CC)
win: CFLAGS += -D_WIN32_WINNT=0x0A00 -DWINVER=0x0A00 -DNTDDI_VERSION=NTDDI_WIN10 windebug winrelease: CFLAGS += -D_WIN32_WINNT=0x0A00 -DWINVER=0x0A00 -DNTDDI_VERSION=NTDDI_WIN10
win: 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
debug: LDFLAGS += -fsanitize=address -fsanitize=undefined debug: LDFLAGS += -fsanitize=address -fsanitize=undefined
endif endif
APP_SOURCES = $(wildcard src/*.c) get_objs = \
APP_OBJS_DBG = $(patsubst %.c,$(BUILD_DIR_DBG)/%.o,$(APP_SOURCES)) $(foreach build_type,$(BUILD_TYPES),$(addprefix out/$(build_type)/,$(addsuffix .o,$(basename $(value $(1)))))) \
APP_OBJS_REL = $(patsubst %.c,$(BUILD_DIR_REL)/%.o,$(APP_SOURCES)) $(foreach build_type,debug release,$(addprefix out/$(build_type)/,$(addsuffix .o,$(basename $(value $(1)_unix))))) \
APP_OBJS_WIN = $(patsubst %.c,$(BUILD_DIR_WIN)/%.o,$(APP_SOURCES)) $(foreach build_type,windebug winrelease,$(addprefix out/$(build_type)/,$(addsuffix .o,$(basename $(value $(1)_win)))))
APP_OBJS := $(APP_OBJS_DBG) $(APP_OBJS_REL) $(APP_OBJS_WIN)
APP_SOURCES := $(wildcard src/*.c)
APP_OBJS := $(call get_objs,APP_SOURCES)
$(APP_OBJS): CFLAGS += \ $(APP_OBJS): CFLAGS += \
-Ideps/base64c/include \ -Ideps/base64c/include \
-Ideps/crypt_blowfish \ -Ideps/crypt_blowfish \
@ -43,26 +45,20 @@ $(APP_OBJS): CFLAGS += \
-Ideps/libsodium/src/libsodium/include \ -Ideps/libsodium/src/libsodium/include \
-Werror -Werror
BASE64C_SOURCES = deps/base64c/src/base64c.c BASE64C_SOURCES := deps/base64c/src/base64c.c
BASE64C_OBJS_DBG = $(patsubst %.c,$(BUILD_DIR_DBG)/%.o,$(BASE64C_SOURCES)) BASE64C_OBJS := $(call get_objs,BASE64C_SOURCES)
BASE64C_OBJS_REL = $(patsubst %.c,$(BUILD_DIR_REL)/%.o,$(BASE64C_SOURCES))
BASE64C_OBJS_WIN = $(patsubst %.c,$(BUILD_DIR_WIN)/%.o,$(BASE64C_SOURCES))
BASE64C_OBJS := $(BASE64C_OBJS_DBG) $(BASE64C_OBJS_REL) $(BASE64C_OBJS_WIN)
$(BASE64C_OBJS): CFLAGS += \ $(BASE64C_OBJS): CFLAGS += \
-Wno-sign-compare -Wno-sign-compare
BLOWFISH_SOURCES = \ BLOWFISH_SOURCES := \
deps/crypt_blowfish/crypt_blowfish.c \ deps/crypt_blowfish/crypt_blowfish.c \
deps/crypt_blowfish/crypt_gensalt.c \ deps/crypt_blowfish/crypt_gensalt.c \
deps/crypt_blowfish/wrapper.c deps/crypt_blowfish/wrapper.c
BLOWFISH_SOURCES_WIN = \ BLOWFISH_SOURCES_win = \
deps/crypt_blowfish/x86.S deps/crypt_blowfish/x86.S
BLOWFISH_OBJS_DBG = $(patsubst %.c,$(BUILD_DIR_DBG)/%.o,$(BLOWFISH_SOURCES)) BLOWFISH_OBJS := $(call get_objs,BLOWFISH_SOURCES)
BLOWFISH_OBJS_REL = $(patsubst %.c,$(BUILD_DIR_REL)/%.o,$(BLOWFISH_SOURCES))
BLOWFISH_OBJS_WIN = $(patsubst %.S,$(BUILD_DIR_WIN)/%.o,$(patsubst %.c,$(BUILD_DIR_WIN)/%.o,$(BLOWFISH_SOURCES) $(BLOWFISH_SOURCES_WIN)))
BLOWFISH_OBJS := $(BLOWFISH_OBJS_DBG) $(BLOWFISH_OBJS_REL) $(BLOWFISH_OBJS_WIN)
UV_SOURCES = \ UV_SOURCES := \
deps/libuv/src/fs-poll.c \ deps/libuv/src/fs-poll.c \
deps/libuv/src/idna.c \ deps/libuv/src/idna.c \
deps/libuv/src/inet.c \ deps/libuv/src/inet.c \
@ -73,7 +69,7 @@ UV_SOURCES = \
deps/libuv/src/uv-common.c \ deps/libuv/src/uv-common.c \
deps/libuv/src/uv-data-getter-setters.c \ deps/libuv/src/uv-data-getter-setters.c \
deps/libuv/src/version.c deps/libuv/src/version.c
UV_SOURCES_UNIX = \ UV_SOURCES_unix := \
deps/libuv/src/unix/async.c \ deps/libuv/src/unix/async.c \
deps/libuv/src/unix/core.c \ deps/libuv/src/unix/core.c \
deps/libuv/src/unix/dl.c \ deps/libuv/src/unix/dl.c \
@ -100,7 +96,7 @@ UV_SOURCES_UNIX = \
deps/libuv/src/unix/thread.c \ deps/libuv/src/unix/thread.c \
deps/libuv/src/unix/tty.c \ deps/libuv/src/unix/tty.c \
deps/libuv/src/unix/udp.c deps/libuv/src/unix/udp.c
UV_SOURCES_WIN = \ UV_SOURCES_win := \
deps/libuv/src/win/async.c \ deps/libuv/src/win/async.c \
deps/libuv/src/win/core.c \ deps/libuv/src/win/core.c \
deps/libuv/src/win/detect-wakeup.c \ deps/libuv/src/win/detect-wakeup.c \
@ -126,10 +122,8 @@ UV_SOURCES_WIN = \
deps/libuv/src/win/util.c \ deps/libuv/src/win/util.c \
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_DBG = $(patsubst %.c,$(BUILD_DIR_DBG)/%.o,$(UV_SOURCES) $(UV_SOURCES_UNIX)) UV_OBJS := $(call get_objs,UV_SOURCES)
UV_OBJS_REL = $(patsubst %.c,$(BUILD_DIR_REL)/%.o,$(UV_SOURCES) $(UV_SOURCES_UNIX)) $(info $(UV_OBJS))
UV_OBJS_WIN = $(patsubst %.c,$(BUILD_DIR_WIN)/%.o,$(UV_SOURCES) $(UV_SOURCES_WIN))
UV_OBJS := $(UV_OBJS_DBG) $(UV_OBJS_REL) $(UV_OBJS_WIN)
$(UV_OBJS): CFLAGS += \ $(UV_OBJS): CFLAGS += \
-Ideps/libuv/include \ -Ideps/libuv/include \
-Ideps/libuv/src \ -Ideps/libuv/src \
@ -138,7 +132,7 @@ $(UV_OBJS): CFLAGS += \
-Wno-sign-compare \ -Wno-sign-compare \
-D_GNU_SOURCE \ -D_GNU_SOURCE \
SODIUM_SOURCES = \ SODIUM_SOURCES := \
deps/libsodium/src/libsodium/crypto_auth/hmacsha512/auth_hmacsha512.c \ deps/libsodium/src/libsodium/crypto_auth/hmacsha512/auth_hmacsha512.c \
deps/libsodium/src/libsodium/crypto_auth/hmacsha512256/auth_hmacsha512256.c \ deps/libsodium/src/libsodium/crypto_auth/hmacsha512256/auth_hmacsha512256.c \
deps/libsodium/src/libsodium/crypto_box/crypto_box.c \ deps/libsodium/src/libsodium/crypto_box/crypto_box.c \
@ -178,10 +172,7 @@ SODIUM_SOURCES = \
deps/libsodium/src/libsodium/sodium/core.c \ deps/libsodium/src/libsodium/sodium/core.c \
deps/libsodium/src/libsodium/sodium/runtime.c \ deps/libsodium/src/libsodium/sodium/runtime.c \
deps/libsodium/src/libsodium/sodium/utils.c deps/libsodium/src/libsodium/sodium/utils.c
SODIUM_OBJS_DBG = $(patsubst %.c,$(BUILD_DIR_DBG)/%.o,$(SODIUM_SOURCES)) SODIUM_OBJS := $(call get_objs,SODIUM_SOURCES)
SODIUM_OBJS_REL = $(patsubst %.c,$(BUILD_DIR_REL)/%.o,$(SODIUM_SOURCES))
SODIUM_OBJS_WIN = $(patsubst %.c,$(BUILD_DIR_WIN)/%.o,$(SODIUM_SOURCES))
SODIUM_OBJS := $(SODIUM_OBJS_DBG) $(SODIUM_OBJS_REL) $(SODIUM_OBJS_WIN)
$(SODIUM_OBJS): CFLAGS += \ $(SODIUM_OBJS): CFLAGS += \
-DCONFIGURED=1 \ -DCONFIGURED=1 \
-DMINIMAL=1 \ -DMINIMAL=1 \
@ -189,11 +180,8 @@ $(SODIUM_OBJS): CFLAGS += \
-Wno-unused-variable \ -Wno-unused-variable \
-Ideps/libsodium/src/libsodium/include/sodium -Ideps/libsodium/src/libsodium/include/sodium
SQLITE_SOURCES = deps/sqlite/sqlite3.c SQLITE_SOURCES := deps/sqlite/sqlite3.c
SQLITE_OBJS_DBG = $(patsubst %.c,$(BUILD_DIR_DBG)/%.o,$(SQLITE_SOURCES)) SQLITE_OBJS := $(call get_objs,SQLITE_SOURCES)
SQLITE_OBJS_REL = $(patsubst %.c,$(BUILD_DIR_REL)/%.o,$(SQLITE_SOURCES))
SQLITE_OBJS_WIN = $(patsubst %.c,$(BUILD_DIR_WIN)/%.o,$(SQLITE_SOURCES))
SQLITE_OBJS := $(SQLITE_OBJS_DBG) $(SQLITE_OBJS_REL) $(SQLITE_OBJS_WIN)
$(SQLITE_OBJS): CFLAGS += \ $(SQLITE_OBJS): CFLAGS += \
-DSQLITE_DBCONFIG_DEFAULT_DEFENSIVE \ -DSQLITE_DBCONFIG_DEFAULT_DEFENSIVE \
-DSQLITE_ENABLE_JSON1 \ -DSQLITE_ENABLE_JSON1 \
@ -211,29 +199,23 @@ $(SQLITE_OBJS): CFLAGS += \
-DSQLITE_SECURE_DELETE \ -DSQLITE_SECURE_DELETE \
-Wno-implicit-fallthrough -Wno-implicit-fallthrough
XOPT_SOURCES = deps/xopt/xopt.c XOPT_SOURCES := deps/xopt/xopt.c
XOPT_OBJS_DBG = $(patsubst %.c,$(BUILD_DIR_DBG)/%.o,$(XOPT_SOURCES)) XOPT_OBJS := $(call get_objs,XOPT_SOURCES)
XOPT_OBJS_REL = $(patsubst %.c,$(BUILD_DIR_REL)/%.o,$(XOPT_SOURCES)) $(filter out/win%,$(XOPT_OBJS)): CFLAGS += \
XOPT_OBJS_WIN = $(patsubst %.c,$(BUILD_DIR_WIN)/%.o,$(XOPT_SOURCES))
XOPT_OBJS := $(XOPT_OBJS_DBG) $(XOPT_OBJS_REL) $(XOPT_OBJS_WIN)
$(XOPT_OBJS_WIN): CFLAGS += \
-DHAVE_SNPRINTF \ -DHAVE_SNPRINTF \
-DHAVE_VSNPRINTF \ -DHAVE_VSNPRINTF \
-DHAVE_VASNPRINTF \ -DHAVE_VASNPRINTF \
-DHAVE_VASPRINTF \ -DHAVE_VASPRINTF \
-Dvsnprintf=rpl_vsnprintf -Dvsnprintf=rpl_vsnprintf
QUICKJS_SOURCES = \ QUICKJS_SOURCES := \
deps/quickjs/cutils.c \ deps/quickjs/cutils.c \
deps/quickjs/libbf.c \ deps/quickjs/libbf.c \
deps/quickjs/libregexp.c \ deps/quickjs/libregexp.c \
deps/quickjs/libunicode.c \ deps/quickjs/libunicode.c \
deps/quickjs/quickjs-libc.c \ deps/quickjs/quickjs-libc.c \
deps/quickjs/quickjs.c deps/quickjs/quickjs.c
QUICKJS_OBJS_DBG = $(patsubst %.c,$(BUILD_DIR_DBG)/%.o,$(QUICKJS_SOURCES)) QUICKJS_OBJS := $(call get_objs,QUICKJS_SOURCES)
QUICKJS_OBJS_REL = $(patsubst %.c,$(BUILD_DIR_REL)/%.o,$(QUICKJS_SOURCES))
QUICKJS_OBJS_WIN = $(patsubst %.c,$(BUILD_DIR_WIN)/%.o,$(QUICKJS_SOURCES))
QUICKJS_OBJS := $(QUICKJS_OBJS_DBG) $(QUICKJS_OBJS_REL) $(QUICKJS_OBJS_WIN)
$(QUICKJS_OBJS): CFLAGS += \ $(QUICKJS_OBJS): CFLAGS += \
-DCONFIG_VERSION=\"$(shell cat deps/quickjs/VERSION)\" \ -DCONFIG_VERSION=\"$(shell cat deps/quickjs/VERSION)\" \
-DDUMP_LEAKS \ -DDUMP_LEAKS \
@ -255,76 +237,79 @@ release: LDFLAGS += \
-ldl \ -ldl \
-lssl \ -lssl \
-lcrypto -lcrypto
win: LDFLAGS += \ 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_DBG)/$(PROJECT) debug: $(BUILD_DIR)/debug/$(PROJECT)
release: $(BUILD_DIR_REL)/$(PROJECT) release: $(BUILD_DIR)/release/$(PROJECT)
win: $(BUILD_DIR_WIN)/$(PROJECT) windebug: $(BUILD_DIR)/windebug/$(PROJECT)
all: debug release winrelease: $(BUILD_DIR)/winrelease/$(PROJECT)
.PHONY: all debug release win unix: debug release
win: windebug winrelease
all: $(BUILD_TYPES)
.PHONY: all $(BUILD_TYPES) win unix
ALL_APP_OBJS_DBG = \ ALL_APP_OBJS := \
$(APP_OBJS_DBG) \ $(APP_OBJS) \
$(BASE64C_OBJS_DBG) \ $(BASE64C_OBJS) \
$(BLOWFISH_OBJS_DBG) \ $(BLOWFISH_OBJS) \
$(UV_OBJS_DBG) \ $(QUICKJS_OBJS) \
$(SODIUM_OBJS_DBG) \ $(SODIUM_OBJS) \
$(SQLITE_OBJS_DBG) \ $(SQLITE_OBJS) \
$(QUICKJS_OBJS_DBG) \ $(UV_OBJS) \
$(XOPT_OBJS_DBG) $(XOPT_OBJS)
ALL_APP_OBJS_REL = \
$(APP_OBJS_REL) \
$(BASE64C_OBJS_REL) \
$(BLOWFISH_OBJS_REL) \
$(UV_OBJS_REL) \
$(SODIUM_OBJS_REL) \
$(SQLITE_OBJS_REL) \
$(QUICKJS_OBJS_REL) \
$(XOPT_OBJS_REL)
ALL_APP_OBJS_WIN = \
$(APP_OBJS_WIN) \
$(BASE64C_OBJS_WIN) \
$(BLOWFISH_OBJS_WIN) \
$(UV_OBJS_WIN) \
$(SODIUM_OBJS_WIN) \
$(SQLITE_OBJS_WIN) \
$(QUICKJS_OBJS_WIN) \
$(XOPT_OBJS_WIN)
ALL_APP_OBJS := $(ALL_APP_OBJS_DBG) $(ALL_APP_OBJS_REL) $(ALL_APP_OBJS_WIN)
DEPS = $(ALL_APP_OBJS:.o=.d) DEPS = $(ALL_APP_OBJS:.o=.d)
-include $(DEPS) -include $(DEPS)
$(BUILD_DIR_DBG)/$(PROJECT): $(ALL_APP_OBJS_DBG) $(BUILD_DIR)/debug/$(PROJECT): $(filter out/debug/%,$(ALL_APP_OBJS))
$(CC) -o $@ $^ $(LDFLAGS) $(CC) -o $@ $^ $(LDFLAGS)
$(BUILD_DIR_REL)/$(PROJECT): $(ALL_APP_OBJS_REL) $(BUILD_DIR)/release/$(PROJECT): $(filter out/release/%,$(ALL_APP_OBJS))
$(CC) -o $@ $^ $(LDFLAGS) $(CC) -o $@ $^ $(LDFLAGS)
$(BUILD_DIR_WIN)/$(PROJECT): $(ALL_APP_OBJS_WIN) $(BUILD_DIR)/windebug/$(PROJECT): $(filter out/windebug/%,$(ALL_APP_OBJS))
$(CC) -o $@ $^ $(LDFLAGS) $(CC) -o $@ $^ $(LDFLAGS)
$(BUILD_DIR_DBG)/%.o: %.c $(BUILD_DIR)/winrelease/$(PROJECT): $(filter out/winrelease/%,$(ALL_APP_OBJS))
$(CC) -o $@ $^ $(LDFLAGS)
$(BUILD_DIR)/debug/%.o: %.c
@mkdir -p $(dir $@) @mkdir -p $(dir $@)
@echo [c] $@ @echo [c] $@
@$(CC) $(CFLAGS) -c $< -o $@ @$(CC) $(CFLAGS) -c $< -o $@
$(BUILD_DIR_REL)/%.o: %.c $(BUILD_DIR)/release/%.o: %.c
@mkdir -p $(dir $@) @mkdir -p $(dir $@)
@echo [c] $@ @echo [c] $@
@$(CC) $(CFLAGS) -c $< -o $@ @$(CC) $(CFLAGS) -c $< -o $@
$(BUILD_DIR_WIN)/%.o: %.c $(BUILD_DIR)/windebug/%.o: %.c
@mkdir -p $(dir $@) @mkdir -p $(dir $@)
@echo [c] $@ @echo [c] $@
@$(CC) $(CFLAGS) -c $< -o $@ @$(CC) $(CFLAGS) -c $< -o $@
$(BUILD_DIR_WIN)/%.o: %.S $(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 $@) @mkdir -p $(dir $@)
@echo [as] $@ @echo [as] $@
@$(AS) -c $< -o $@ @$(AS) -c $< -o $@