Rearrange the makefile so that debug and release can be built together. There are probably easy ways to make this more concise that I am missing.

git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@3664 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
Cory McWilliams 2021-10-03 22:14:06 +00:00
parent 059392df8e
commit 6d2b560c3d

105
Makefile
View File

@ -1,7 +1,9 @@
PROJECT = tildefriends
BUILD_DIR ?= out
BUILD_DIR_DBG := $(BUILD_DIR)/debug
BUILD_DIR_REL := $(BUILD_DIR)/release
COMMON_CFLAGS = \
CFLAGS += \
-Wall \
-Wextra \
-Wno-unused-parameter \
@ -9,24 +11,16 @@ COMMON_CFLAGS = \
-MMD \
-ffunction-sections \
-fdata-sections
COMMON_LDFLAGS += -Wl,-gc-sections
LDFLAGS += -Wl,-gc-sections
ifneq ($(UNUSED),)
COMMON_LDFLAGS += -Wl,-print-gc-sections
endif
debug: CFLAGS += -Og -g -fsanitize=address -fsanitize=undefined
debug: LDFLAGS += -fsanitize=address -fsanitize=undefined
release: CFLAGS += -DNDEBUG -O3
ifneq ($(DEBUG),)
COMMON_CFLAGS += -g -fsanitize=address -fsanitize=undefined
COMMON_LDFLAGS += -fsanitize=address -fsanitize=undefined
BUILD_DIR := $(BUILD_DIR)/debug
else
COMMON_CFLAGS += -DNDEBUG -O3
BUILD_DIR := $(BUILD_DIR)/release
endif
APP_BIN = $(BUILD_DIR)/$(PROJECT)
APP_SOURCES = $(wildcard src/*.c)
APP_OBJS = $(patsubst %.c,$(BUILD_DIR)/%.o,$(APP_SOURCES))
APP_OBJS_DBG = $(patsubst %.c,$(BUILD_DIR_DBG)/%.o,$(APP_SOURCES))
APP_OBJS_REL = $(patsubst %.c,$(BUILD_DIR_REL)/%.o,$(APP_SOURCES))
APP_OBJS := $(APP_OBJS_DBG) $(APP_OBJS_REL)
$(APP_OBJS): CFLAGS += \
-Ideps/base64c/include \
-Ideps/crypt_blowfish \
@ -37,7 +31,9 @@ $(APP_OBJS): CFLAGS += \
-Werror
BASE64C_SOURCES = deps/base64c/src/base64c.c
BASE64C_OBJS = $(patsubst %.c,$(BUILD_DIR)/%.o,$(BASE64C_SOURCES))
BASE64C_OBJS_DBG = $(patsubst %.c,$(BUILD_DIR_DBG)/%.o,$(BASE64C_SOURCES))
BASE64C_OBJS_REL = $(patsubst %.c,$(BUILD_DIR_REL)/%.o,$(BASE64C_SOURCES))
BASE64C_OBJS := $(BASE64C_OBJS_DBG) $(BASE64C_OBJS_REL)
$(BASE64C_OBJS): CFLAGS += \
-Wno-sign-compare
@ -45,7 +41,9 @@ BLOWFISH_SOURCES = \
deps/crypt_blowfish/crypt_blowfish.c \
deps/crypt_blowfish/crypt_gensalt.c \
deps/crypt_blowfish/wrapper.c
BLOWFISH_OBJS = $(patsubst %.c,$(BUILD_DIR)/%.o,$(BLOWFISH_SOURCES))
BLOWFISH_OBJS_DBG = $(patsubst %.c,$(BUILD_DIR_DBG)/%.o,$(BLOWFISH_SOURCES))
BLOWFISH_OBJS_REL = $(patsubst %.c,$(BUILD_DIR_REL)/%.o,$(BLOWFISH_SOURCES))
BLOWFISH_OBJS := $(BLOWFISH_OBJS_DBG) $(BLOWFISH_OBJS_REL)
UV_SOURCES = \
deps/libuv/src/fs-poll.c \
@ -84,7 +82,9 @@ UV_SOURCES = \
deps/libuv/src/uv-common.c \
deps/libuv/src/uv-data-getter-setters.c \
deps/libuv/src/version.c
UV_OBJS = $(patsubst %.c,$(BUILD_DIR)/%.o,$(UV_SOURCES))
UV_OBJS_DBG = $(patsubst %.c,$(BUILD_DIR_DBG)/%.o,$(UV_SOURCES))
UV_OBJS_REL = $(patsubst %.c,$(BUILD_DIR_REL)/%.o,$(UV_SOURCES))
UV_OBJS := $(UV_OBJS_DBG) $(UV_OBJS_REL)
$(UV_OBJS): CFLAGS += \
-Ideps/libuv/include \
-Ideps/libuv/src \
@ -94,7 +94,9 @@ $(UV_OBJS): CFLAGS += \
-D_GNU_SOURCE \
SQLITE_SOURCES = deps/sqlite/sqlite3.c
SQLITE_OBJS = $(patsubst %.c,$(BUILD_DIR)/%.o,$(SQLITE_SOURCES))
SQLITE_OBJS_DBG = $(patsubst %.c,$(BUILD_DIR_DBG)/%.o,$(SQLITE_SOURCES))
SQLITE_OBJS_REL = $(patsubst %.c,$(BUILD_DIR_REL)/%.o,$(SQLITE_SOURCES))
SQLITE_OBJS := $(SQLITE_OBJS_DBG) $(SQLITE_OBJS_REL)
$(SQLITE_OBJS): CFLAGS += \
-DSQLITE_DBCONFIG_DEFAULT_DEFENSIVE \
-DSQLITE_ENABLE_JSON1 \
@ -113,7 +115,9 @@ $(SQLITE_OBJS): CFLAGS += \
-Wno-implicit-fallthrough
XOPT_SOURCES = deps/xopt/xopt.c
XOPT_OBJS = $(patsubst %.c,$(BUILD_DIR)/%.o,$(XOPT_SOURCES))
XOPT_OBJS_DBG = $(patsubst %.c,$(BUILD_DIR_DBG)/%.o,$(XOPT_SOURCES))
XOPT_OBJS_REL = $(patsubst %.c,$(BUILD_DIR_REL)/%.o,$(XOPT_SOURCES))
XOPT_OBJS := $(XOPT_OBJS_DBG) $(XOPT_OBJS_REL)
QUICKJS_SOURCES = \
deps/quickjs/cutils.c \
@ -122,7 +126,9 @@ QUICKJS_SOURCES = \
deps/quickjs/libunicode.c \
deps/quickjs/quickjs-libc.c \
deps/quickjs/quickjs.c
QUICKJS_OBJS = $(patsubst %.c,$(BUILD_DIR)/%.o,$(QUICKJS_SOURCES))
QUICKJS_OBJS_DBG = $(patsubst %.c,$(BUILD_DIR_DBG)/%.o,$(QUICKJS_SOURCES))
QUICKJS_OBJS_REL = $(patsubst %.c,$(BUILD_DIR_REL)/%.o,$(QUICKJS_SOURCES))
QUICKJS_OBJS := $(QUICKJS_OBJS_DBG) $(QUICKJS_OBJS_REL)
$(QUICKJS_OBJS): CFLAGS += \
-DCONFIG_VERSION=\"$(shell cat deps/quickjs/VERSION)\" \
-DDUMP_LEAKS \
@ -130,11 +136,10 @@ $(QUICKJS_OBJS): CFLAGS += \
-Wno-sign-compare \
-Wno-implicit-fallthrough \
-Wno-unused-variable \
-Wno-unused-but-set-variable
-Wno-unused-but-set-variable \
-Wno-enum-conversion
APP_LDFLAGS = \
$(COMMON_LDFLAGS) \
$(LDFLAGS) \
LDFLAGS += \
-pthread \
-ldl \
-lm \
@ -142,29 +147,47 @@ APP_LDFLAGS = \
-lcrypto \
-lsodium
DEFAULT_TARGET = $(APP_BIN)
all: $(DEFAULT_TARGET)
.PHONY: all
debug: $(BUILD_DIR_DBG)/$(PROJECT)
release: $(BUILD_DIR_REL)/$(PROJECT)
all: debug release
.PHONY: all debug release
ALL_APP_OBJS = \
$(APP_OBJS) \
$(BASE64C_OBJS) \
$(BLOWFISH_OBJS) \
$(UV_OBJS) \
$(SQLITE_OBJS) \
$(QUICKJS_OBJS) \
$(XOPT_OBJS)
ALL_APP_OBJS_DBG = \
$(APP_OBJS_DBG) \
$(BASE64C_OBJS_DBG) \
$(BLOWFISH_OBJS_DBG) \
$(UV_OBJS_DBG) \
$(SQLITE_OBJS_DBG) \
$(QUICKJS_OBJS_DBG) \
$(XOPT_OBJS_DBG)
ALL_APP_OBJS_REL = \
$(APP_OBJS_REL) \
$(BASE64C_OBJS_REL) \
$(BLOWFISH_OBJS_REL) \
$(UV_OBJS_REL) \
$(SQLITE_OBJS_REL) \
$(QUICKJS_OBJS_REL) \
$(XOPT_OBJS_REL)
ALL_APP_OBJS := $(ALL_APP_OBJS_DBG) $(ALL_APP_OBJS_REL)
DEPS = $(ALL_APP_OBJS:.o=.d)
-include $(DEPS)
$(APP_BIN): $(ALL_APP_OBJS)
$(CC) -o $@ $^ $(APP_LDFLAGS)
$(BUILD_DIR_DBG)/$(PROJECT): $(ALL_APP_OBJS_DBG)
$(CC) -o $@ $^ $(LDFLAGS)
$(BUILD_DIR)/%.o: %.c
$(BUILD_DIR_REL)/$(PROJECT): $(ALL_APP_OBJS_REL)
$(CC) -o $@ $^ $(LDFLAGS)
$(BUILD_DIR_DBG)/%.o: %.c
@mkdir -p $(dir $@)
@echo [c] $@
@$(CC) $(COMMON_CFLAGS) $(CFLAGS) -c $< -o $@
$(CC) $(CFLAGS) -c $< -o $@
$(BUILD_DIR_REL)/%.o: %.c
@mkdir -p $(dir $@)
@echo [c] $@
$(CC) $(CFLAGS) -c $< -o $@
clean:
rm -rf $(BUILD_DIR)