-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
110 lines (82 loc) · 2.83 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
.SUFFIXES:
# Sources and defines
TARGET := $(notdir $(CURDIR))
BUILD := build
INCLUDES := include
SOURCES := source
DEFINES := -D_FORTIFY_SOURCE=2
# Compiler settings
ARCH :=
CFLAGS := $(ARCH) -std=c17 -O2 -g -fPIE -fstrict-aliasing \
-ffunction-sections -fdata-sections -fstack-protector-strong \
-Wall -Wextra -Wstrict-aliasing=2
CXXFLAGS := $(ARCH) -std=c++20 -O2 -g -fPIE -fstrict-aliasing \
-ffunction-sections -fdata-sections -fstack-protector-strong \
-Wall -Wextra -Wstrict-aliasing=2
ASFLAGS := $(ARCH) -O2 -g -fPIE -x assembler-with-cpp
ARFLAGS := -rcs
LDFLAGS := $(ARCH) -O2 -s -pie -fPIE -Wl,--gc-sections,-z,relro,-z,now,-z,noexecstack
PREFIX :=
ifneq ($(strip $(USE_CLANG)),)
CC := $(PREFIX)clang
CXX := $(PREFIX)clang++
AS := $(PREFIX)clang
AR := $(PREFIX)gcc-ar
else
CC := $(PREFIX)gcc
CXX := $(PREFIX)g++
AS := $(PREFIX)gcc
AR := $(PREFIX)gcc-ar
endif
# Do not change anything after this
ifneq ($(BUILD),$(notdir $(CURDIR)))
export OUTPUT := $(CURDIR)/$(TARGET)
export VPATH := $(foreach dir,$(DATA),$(CURDIR)/$(dir)) \
$(foreach dir,$(SOURCES),$(CURDIR)/$(dir))
CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp)))
CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c)))
SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s)))
ifeq ($(strip $(CPPFILES)),)
export LD := $(CC)
else
export LD := $(CXX)
endif
export OFILES := $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o)
export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) -I$(CURDIR)/$(BUILD)
.PHONY: $(BUILD) clean release
$(BUILD):
@[ -d $@ ] || mkdir -p $@
@$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile
clean:
@echo clean ...
@rm -rf $(BUILD) $(TARGET)
release:
@[ -d $(BUILD) ] || mkdir -p $(BUILD)
@$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile NO_DEBUG=1
else
ifneq ($(strip $(NO_DEBUG)),)
DEFINES += -DNDEBUG
endif
#VERS_STRING := $(shell git describe --tags --match v[0-9]* --abbrev=8 | sed 's/-[0-9]*-g/-/i')
#VERS_MAJOR := $(shell echo "$(VERS_STRING)" | sed 's/v\([0-9]*\)\..*/\1/i')
#VERS_MINOR := $(shell echo "$(VERS_STRING)" | sed 's/.*\.\([0-9]*\).*/\1/')
#DEFINES += -DVERS_STRING=\"$(VERS_STRING)\"
#DEFINES += -DVERS_MAJOR=$(shell echo "$(VERS_STRING)" | sed 's/v\([0-9]*\)\..*/\1/i')
#DEFINES += -DVERS_MINOR=$(shell echo "$(VERS_STRING)" | sed 's/.*\.\([0-9]*\).*/\1/')
# Main target
$(OUTPUT): $(OFILES)
$(LD) $(LDFLAGS) $(OFILES) $(LIBPATHS) $(LIBS) -o $@
@echo built ... $(notdir $@)
%.o: %.cpp
@echo $(notdir $<)
$(CXX) $(CXXFLAGS) $(DEFINES) $(INCLUDE) -c $< -o $@
%.o: %.c
@echo $(notdir $<)
$(CC) $(CFLAGS) $(DEFINES) $(INCLUDE) -c $< -o $@
%.o: %.s
@echo $(notdir $<)
$(AS) $(ASFLAGS) $(DEFINES) $(INCLUDE) -c $< -o $@
%.a:
@echo $(notdir $@)
$(AR) $(ARFLAGS) $@ $^
endif