-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmakefile
86 lines (68 loc) · 1.67 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
ifeq ($(OS),Windows_NT)
MAKE_OS = WINDOWS
else
UNAME_S = $(shell uname -s)
ifeq ($(UNAME_S),Linux)
MAKE_OS = LINUX
endif
ifeq ($(UNAME_S),Darwin)
MAKE_OS = MACOSX
endif
endif
# Path
INCLUDE_PATH = .
SOURCE_PATH = ./src/
LIB_PATH =
BUILD_PATH = ./build/
# Tools
CC = g++
LD = g++
RM = rm -f
ECHO = echo
MKDIR = mkdir -p
RMDIR = rm -f -r
# global defines
GLOBAL_DEFINES = $(MAKE_OS)
# C/C++ Flags
CFLAGS = $(addprefix -I,$(INCLUDE_PATH))
CFLAGS += $(addprefix -D,$(GLOBAL_DEFINES))
CFLAGS += -MD -MP -MF $@.d
CPPFLAGS = $(CFLAGS)
LDFLAGS = -static $(addprefix -L,$(LIB_PATH))
LIBS =
ifeq ("$(MAKE_OS)","WINDOWS")
LIBS += -lws2_32
endif
ifeq ("$(MAKE_OS)","MACOSX")
LDFLAGS := $(filter-out -static,$(LDFLAGS))
endif
# Verbose
ifneq ("1","$(verbose)")
silent = @
endif
# Source files
SOURCE_FILES = $(wildcard $(SOURCE_PATH)*.c)
OBJECT_FILES = $(addprefix $(BUILD_PATH),$(SOURCE_FILES:.c=.o))
DEPS_FILES = $(OBJECT_FILES:.o=.o.d)
DEPS_MAKEFILE = ./makefile
# targets
all: $(BUILD_PATH)DuoSetupCLI
$(BUILD_PATH)DuoSetupCLI: $(OBJECT_FILES) $(DEPS_MAKEFILE)
$(silent)$(ECHO) Building $@ ...
$(silent)$(MKDIR) $(dir $@)
$(silent)$(LD) $(OBJECT_FILES) $(LDFLAGS) $(LIBS) -o $@
$(BUILD_PATH)%.o: %.c $(DEPS_MAKEFILE)
$(silent)$(ECHO) Compiling $< ...
$(silent)$(MKDIR) $(dir $@)
$(silent)$(CC) -c $(CFLAGS) -o $@ $<
$(BUILD_PATH)%.cpp.o: %.cpp $(DEPS_MAKEFILE)
$(silent)$(ECHO) Compiling $< ...
$(silent)$(MKDIR) $(dir $@)
$(silent)$(CC) -c $(CPPFLAGS) -o $@ $<
clean:
$(silent)$(ECHO) Cleaning targets ...
$(silent)$(RM) DuoSetupCLI $(OBJECT_FILES)
$(silent)$(RMDIR) $(BUILD_PATH)
ifneq ("MAKECMDGOALS","clean")
-include $(DEPS_FILES)
endif