Skip to content

Commit c0ef774

Browse files
committed
Improve makefile
1 parent 84e6b26 commit c0ef774

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

Makefile

+13-10
Original file line numberDiff line numberDiff line change
@@ -11,33 +11,36 @@ SRCS := $(shell find $(SRC_DIRS) -not -name 'main.c' -name '*.c')
1111
INC_DIRS := $(shell find $(SRC_DIRS) -type d)
1212
INC_FLAGS := $(addprefix -I,$(INC_DIRS))
1313
LIBS := -lpthread -lm
14+
1415
WARNING_FLAGS := -pedantic -Wall -Wextra -Wno-missing-declarations -Wstrict-prototypes -Wpointer-arith -Wwrite-strings -Wbad-function-cast -Wformat-security -Wno-discarded-qualifiers -Wno-implicit-fallthrough -Wformat-nonliteral -Wmissing-format-attribute -Wno-unused-variable -Wno-unused-parameter -Wno-unused-function -Wno-ignored-qualifiers -Wno-strict-prototypes -Wno-bad-function-cast -Wno-pointer-sign
1516
HARDENING_FLAGS := -fno-builtin -fvisibility=hidden -fstack-protector -fno-omit-frame-pointer -fno-asynchronous-unwind-tables -fno-unwind-tables -fno-common -ffunction-sections -fdata-sections
1617
PERFORMANCE_FLAGS := -fPIC -fPIE -ffast-math -fassociative-math -fno-signed-zeros -fno-trapping-math -fno-exceptions
1718

18-
# Flags
19-
# Debug
20-
# CFLAGS := $(INC_FLAGS) -g3 -O0 -ggdb $(WARNING_FLAGS)
19+
# Build type (debug or release)
20+
BUILD_TYPE ?= release
2121

22-
# Release
23-
CFLAGS := $(INC_FLAGS) -g0 -O2 $(WARNING_FLAGS) $(HARDENING_FLAGS) $(PERFORMANCE_FLAGS)
22+
ifeq ($(BUILD_TYPE),debug)
23+
CFLAGS := $(INC_FLAGS) -g3 -O0 -ggdb $(WARNING_FLAGS)
24+
else
25+
CFLAGS := $(INC_FLAGS) -g0 -O2 $(WARNING_FLAGS) $(HARDENING_FLAGS) $(PERFORMANCE_FLAGS)
26+
endif
2427

2528
# Rules
2629
all: $(DEPLOY_DIR)/$(TARGET_EXEC)
2730

2831
$(DEPLOY_DIR)/$(TARGET_EXEC): $(SRCS) $(SRC_DIRS)/main.c | $(DEPLOY_DIR)
2932
$(CC) $(SRCS) $(SRC_DIRS)/main.c $(CFLAGS) $(LIBS) -o $@
30-
$(STRIP) -R .comment -R *.note* -s -x -X -v $@
33+
$(STRIP) --strip-all -v $@
3134

3235
$(DEPLOY_DIR):
3336
mkdir -p $(DEPLOY_DIR)
3437

3538
clean:
36-
rm -f $(DEPLOY_DIR)/$(TARGET_EXEC) $(DEPLOY_DIR)/stats_*.log $(DEPLOY_DIR)/stats_*.raw wdt.log
39+
$(RM) -f $(DEPLOY_DIR)/$(TARGET_EXEC) $(DEPLOY_DIR)/stats_*.log $(DEPLOY_DIR)/stats_*.raw wdt.log
3740

3841
install: $(DEPLOY_DIR)/$(TARGET_EXEC)
39-
cp $(DEPLOY_DIR)/$(TARGET_EXEC) ~/
40-
cp run.sh ~/
41-
chmod +x ~$(TARGET_EXEC) run.sh
42+
$(CP) $(DEPLOY_DIR)/$(TARGET_EXEC) ~/
43+
$(CP) run.sh ~/
44+
chmod +x ~/$(TARGET_EXEC) ~/run.sh
4245

4346
.PHONY: all clean install

0 commit comments

Comments
 (0)