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:
parent
059392df8e
commit
6d2b560c3d
105
Makefile
105
Makefile
@ -1,7 +1,9 @@
|
|||||||
PROJECT = tildefriends
|
PROJECT = tildefriends
|
||||||
BUILD_DIR ?= out
|
BUILD_DIR ?= out
|
||||||
|
BUILD_DIR_DBG := $(BUILD_DIR)/debug
|
||||||
|
BUILD_DIR_REL := $(BUILD_DIR)/release
|
||||||
|
|
||||||
COMMON_CFLAGS = \
|
CFLAGS += \
|
||||||
-Wall \
|
-Wall \
|
||||||
-Wextra \
|
-Wextra \
|
||||||
-Wno-unused-parameter \
|
-Wno-unused-parameter \
|
||||||
@ -9,24 +11,16 @@ COMMON_CFLAGS = \
|
|||||||
-MMD \
|
-MMD \
|
||||||
-ffunction-sections \
|
-ffunction-sections \
|
||||||
-fdata-sections
|
-fdata-sections
|
||||||
COMMON_LDFLAGS += -Wl,-gc-sections
|
LDFLAGS += -Wl,-gc-sections
|
||||||
|
|
||||||
ifneq ($(UNUSED),)
|
debug: CFLAGS += -Og -g -fsanitize=address -fsanitize=undefined
|
||||||
COMMON_LDFLAGS += -Wl,-print-gc-sections
|
debug: LDFLAGS += -fsanitize=address -fsanitize=undefined
|
||||||
endif
|
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_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 += \
|
$(APP_OBJS): CFLAGS += \
|
||||||
-Ideps/base64c/include \
|
-Ideps/base64c/include \
|
||||||
-Ideps/crypt_blowfish \
|
-Ideps/crypt_blowfish \
|
||||||
@ -37,7 +31,9 @@ $(APP_OBJS): CFLAGS += \
|
|||||||
-Werror
|
-Werror
|
||||||
|
|
||||||
BASE64C_SOURCES = deps/base64c/src/base64c.c
|
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 += \
|
$(BASE64C_OBJS): CFLAGS += \
|
||||||
-Wno-sign-compare
|
-Wno-sign-compare
|
||||||
|
|
||||||
@ -45,7 +41,9 @@ 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_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 = \
|
UV_SOURCES = \
|
||||||
deps/libuv/src/fs-poll.c \
|
deps/libuv/src/fs-poll.c \
|
||||||
@ -84,7 +82,9 @@ 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_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 += \
|
$(UV_OBJS): CFLAGS += \
|
||||||
-Ideps/libuv/include \
|
-Ideps/libuv/include \
|
||||||
-Ideps/libuv/src \
|
-Ideps/libuv/src \
|
||||||
@ -94,7 +94,9 @@ $(UV_OBJS): CFLAGS += \
|
|||||||
-D_GNU_SOURCE \
|
-D_GNU_SOURCE \
|
||||||
|
|
||||||
SQLITE_SOURCES = deps/sqlite/sqlite3.c
|
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 += \
|
$(SQLITE_OBJS): CFLAGS += \
|
||||||
-DSQLITE_DBCONFIG_DEFAULT_DEFENSIVE \
|
-DSQLITE_DBCONFIG_DEFAULT_DEFENSIVE \
|
||||||
-DSQLITE_ENABLE_JSON1 \
|
-DSQLITE_ENABLE_JSON1 \
|
||||||
@ -113,7 +115,9 @@ $(SQLITE_OBJS): CFLAGS += \
|
|||||||
-Wno-implicit-fallthrough
|
-Wno-implicit-fallthrough
|
||||||
|
|
||||||
XOPT_SOURCES = deps/xopt/xopt.c
|
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 = \
|
QUICKJS_SOURCES = \
|
||||||
deps/quickjs/cutils.c \
|
deps/quickjs/cutils.c \
|
||||||
@ -122,7 +126,9 @@ QUICKJS_SOURCES = \
|
|||||||
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 = $(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 += \
|
$(QUICKJS_OBJS): CFLAGS += \
|
||||||
-DCONFIG_VERSION=\"$(shell cat deps/quickjs/VERSION)\" \
|
-DCONFIG_VERSION=\"$(shell cat deps/quickjs/VERSION)\" \
|
||||||
-DDUMP_LEAKS \
|
-DDUMP_LEAKS \
|
||||||
@ -130,11 +136,10 @@ $(QUICKJS_OBJS): CFLAGS += \
|
|||||||
-Wno-sign-compare \
|
-Wno-sign-compare \
|
||||||
-Wno-implicit-fallthrough \
|
-Wno-implicit-fallthrough \
|
||||||
-Wno-unused-variable \
|
-Wno-unused-variable \
|
||||||
-Wno-unused-but-set-variable
|
-Wno-unused-but-set-variable \
|
||||||
|
-Wno-enum-conversion
|
||||||
|
|
||||||
APP_LDFLAGS = \
|
LDFLAGS += \
|
||||||
$(COMMON_LDFLAGS) \
|
|
||||||
$(LDFLAGS) \
|
|
||||||
-pthread \
|
-pthread \
|
||||||
-ldl \
|
-ldl \
|
||||||
-lm \
|
-lm \
|
||||||
@ -142,29 +147,47 @@ APP_LDFLAGS = \
|
|||||||
-lcrypto \
|
-lcrypto \
|
||||||
-lsodium
|
-lsodium
|
||||||
|
|
||||||
DEFAULT_TARGET = $(APP_BIN)
|
debug: $(BUILD_DIR_DBG)/$(PROJECT)
|
||||||
all: $(DEFAULT_TARGET)
|
release: $(BUILD_DIR_REL)/$(PROJECT)
|
||||||
.PHONY: all
|
all: debug release
|
||||||
|
.PHONY: all debug release
|
||||||
|
|
||||||
ALL_APP_OBJS = \
|
ALL_APP_OBJS_DBG = \
|
||||||
$(APP_OBJS) \
|
$(APP_OBJS_DBG) \
|
||||||
$(BASE64C_OBJS) \
|
$(BASE64C_OBJS_DBG) \
|
||||||
$(BLOWFISH_OBJS) \
|
$(BLOWFISH_OBJS_DBG) \
|
||||||
$(UV_OBJS) \
|
$(UV_OBJS_DBG) \
|
||||||
$(SQLITE_OBJS) \
|
$(SQLITE_OBJS_DBG) \
|
||||||
$(QUICKJS_OBJS) \
|
$(QUICKJS_OBJS_DBG) \
|
||||||
$(XOPT_OBJS)
|
$(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)
|
DEPS = $(ALL_APP_OBJS:.o=.d)
|
||||||
-include $(DEPS)
|
-include $(DEPS)
|
||||||
|
|
||||||
$(APP_BIN): $(ALL_APP_OBJS)
|
$(BUILD_DIR_DBG)/$(PROJECT): $(ALL_APP_OBJS_DBG)
|
||||||
$(CC) -o $@ $^ $(APP_LDFLAGS)
|
$(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 $@)
|
@mkdir -p $(dir $@)
|
||||||
@echo [c] $@
|
@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:
|
clean:
|
||||||
rm -rf $(BUILD_DIR)
|
rm -rf $(BUILD_DIR)
|
||||||
|
Loading…
Reference in New Issue
Block a user