-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
80 lines (68 loc) · 1.46 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
VPATH ?= .
#
# build target
#
EXECUTABLE = exchange
TARGET = $(EXECUTABLE)
#
# toolchains
#
CC := gcc
LD := ld
CPP := cpp
CXX := g++
AR := ar
AS := as
NM := nm
STRIP := strip
OBJCOPY := objcopy
RM := -rm -rf
#
# files or dirs
#
SRC_FILES :=
SRC_FILES_EXCLUDE :=
SRC_DIRS := src src/modules/merge src/modules/split src/modules/wave
SRC_DIRS_EXCLUDE :=
INCLUDE_DIRS := -Iinclude -Iinclude/modules/merge -Iinclude/modules/split -Iinclude/modules/wave
#
# flags
#
CFLAGS := -Os -std=gnu99 -fvisibility=hidden -D_GNU_SOURCE -fPIC -fPIE
CFLAGS += -Wall -Wno-variadic-macros -Wno-format-zero-length -fstack-protector-all -ffunction-sections -fdata-sections
CFLAGS += $(INCLUDE_DIRS)
CXXFLAGS := $(subst -std=gnu99,,$(CFLAGS))
LDFLAGS := -Wl,--gc-sections -pie
#
# rules
#
%.o : %.c
$(CC) $(CFLAGS) -c $< -o $@
%.o : %.cc
$(CXX) $(CXXFLAGS) -c $< -o $@
%.o : %.cpp
$(CXX) $(CXXFLAGS) -c $< -o $@
#
# objects
#
ifneq ($(SRC_DIRS),)
SRC_FILES += $(shell find $(SRC_DIRS) -name "*.c" -or -name "*.cpp" -or -name "*.cc")
endif
ifneq ($(SRC_DIRS_EXCLUDE),)
SRC_FILES_EXCLUDE += $(shell find $(SRC_DIRS_EXCLUDE) -name "*.c" -or -name "*.cpp" -or -name "*.cc")
endif
SRC_FILES := $(filter-out $(SRC_FILES_EXCLUDE), $(SRC_FILES))
OBJECTS = $(subst .c,.o,$(subst .cpp,.o,$(subst .cc,.o,$(SRC_FILES))))
#
# goal all
#
.PHONY: all
all: $(TARGET)
$(EXECUTABLE) : $(OBJECTS)
$(CXX) $^ $(LDFLAGS) -o $@
#
# goal: clean
#
.PHONY: clean
clean:
$(RM) $(TARGET) $(OBJECTS)