-
Notifications
You must be signed in to change notification settings - Fork 1
/
Make.common
61 lines (49 loc) · 1.71 KB
/
Make.common
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
SRCROOT := $(realpath $(dir $(lastword $(MAKEFILE_LIST))))
HOST_ARCH = $(shell uname -m | sed s,i[3456789]86,ia32,)
TARGET_ARCH := $(shell uname -m | sed s,i[3456789]86,ia32,)
HOST_OS = $(shell uname -s)
# Dependencies
DEPS_PREFIX := $(SRCROOT)/deps
# Build target type
ifeq ($(strip $(DEBUG)),1)
BUILD_TARGET_TYPE = debug
else
BUILD_TARGET_TYPE = release
endif
# Build directories
BASE_BUILD_PREFIX := $(SRCROOT)/build
BUILD_PREFIX := $(BASE_BUILD_PREFIX)/$(BUILD_TARGET_TYPE)
TESTS_BUILD_PREFIX := $(BASE_BUILD_PREFIX)/test
INCLUDE_BUILD_PREFIX := $(BUILD_PREFIX)/include
LIB_BUILD_PREFIX := $(BUILD_PREFIX)/lib
BIN_BUILD_PREFIX := $(BUILD_PREFIX)/bin
DEBUG_BUILD_PREFIX := $(BUILD_PREFIX)/debug
OBJECT_DIR := $(BUILD_PREFIX)/.objs
# Tools
CC = clang
CXXC = clang++
LD = clang
AR = ar
# $(call UpperCase,foo_bar) -> FOO_BAR
UpperCase = $(shell echo $(1) | tr a-z A-Z)
# Compiler and Linker flags for all targets
CFLAGS += -Wall -g -std=c99 -I$(INCLUDE_BUILD_PREFIX) \
-arch $(TARGET_ARCH)
CXXFLAGS += -std=c++11 -fno-rtti
LDFLAGS += -arch $(TARGET_ARCH)
XXLDFLAGS += -lc++ -lstdc++
# Compiler and Linker flags for release and debug targets (e.g. make DEBUG=1)
ifeq ($(strip $(DEBUG)),1)
CFLAGS += -O0 -DS_DEBUG=1
#LDFLAGS +=
else
CFLAGS += -O3 -DS_DEBUG=0 -DNDEBUG
#LDFLAGS +=
endif
# Functions
# $(call PubHeaderNames,<header_pub_dir>,<list of header files>) -> <list of pub header files>
PubHeaderNames = $(patsubst %,$(1)/%,$(2))
# $(call FileDirs,<list of files>) -> <unique list of dirs>
FileDirs = $(sort $(foreach fn,$(1),$(dir $(fn))))
# $(call SrcToObjects,<objdir>,<list of source files>) -> <list of objects>
SrcToObjects = $(patsubst %,$(1)/%,$(2))