forked from styluslabs/nanovgXC
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile.unix
87 lines (68 loc) · 2.01 KB
/
Makefile.unix
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
# (mostly) project-independent Makefile fragment for Linux
CFLAGS = -MMD -Wall -Wshadow -Wno-unused-function
CXX = g++
CXXFLAGS = --std=c++14 -fno-rtti -fno-exceptions -Werror=return-type
CC = gcc
CCFLAGS = --std=c99 -Werror=implicit-function-declaration -Werror=int-conversion
# use gcc instead of g++ to link C-only project
LD = gcc
LDFLAGS =
DEBUG ?= 0
ifneq ($(DEBUG), 0)
CFLAGS += -g
BUILDDIR = Debug
else
CFLAGS += -O2 -march=native -DNDEBUG
BUILDDIR = Release
endif
SANITIZE ?= 0
ifneq ($(SANITIZE), 0)
CFLAGS += -fsanitize=address -fsanitize=undefined -fsanitize=float-divide-by-zero
LDFLAGS += -lasan -lubsan
endif
# disable optimizations which make profiling difficult, esp. inlining; frame pointer needed for sampling
PROFILE ?= 0
ifneq ($(PROFILE), 0)
CFLAGS += -fno-omit-frame-pointer -g
LDFLAGS += -rdynamic
endif
# project independent stuff
# pkg-config headers and libraries
ifneq ($(PKGS),)
CFLAGS += $(shell pkg-config --cflags $(PKGS))
LIBS += $(shell pkg-config --libs $(PKGS))
endif
ifneq ($(TOPDIR),)
OBJDIR=$(BUILDDIR)/$(TOPDIR)
else
OBJDIR=$(BUILDDIR)
endif
# include files
INCFLAGS = $(INC:%=-I%) $(INCSYS:%=-isystem%)
# defines
CFLAGS += $(DEFS:%=-D%)
SRCBASE=$(basename $(SOURCES))
OBJ=$(SRCBASE:%=$(OBJDIR)/%.o)
DEPS=$(SRCBASE:%=$(OBJDIR)/%.d)
TGT=$(BUILDDIR)/$(TARGET)
# gcc will not create directories, so depend on existence of all directories in output folder
# sort removes duplicates (which cause make error)
BUILDDIRS=$(sort $(dir $(OBJ)))
.PHONY: all clean distclean
all: $(TGT)
$(OBJDIR)/%.o: %.cpp
$(CXX) -c $(CFLAGS) $(CXXFLAGS) $(INCFLAGS) -o $@ $<
$(OBJDIR)/%.o: %.c
$(CC) -c $(CFLAGS) $(CCFLAGS) $(INCFLAGS) -o $@ $<
$(TGT): $(OBJ)
$(LD) -o $@ $^ $(LDFLAGS) $(LIBS)
# | (pipe) operator causes make to just check for existence instead of timestamp
$(OBJ): | $(BUILDDIRS)
$(BUILDDIRS):
mkdir -p $(BUILDDIRS)
clean:
rm -f $(TGT) $(OBJ) $(DEPS)
distclean:
rm -rf ./Debug ./Release
# dependency files generated by gcc (-MMD switch) ("-include" ignores file if missing)
-include $(DEPS)