-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
96 lines (75 loc) · 2.69 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
# QUICKSTART:
# * `make static` (default): build a statically-linked library in bin/
# * `make shared`: build a dynamically-linked library in bin/i
# * `make all`: builds the static and static-example targets
# * `make debug`: same as `make all` but with debugging flags set
# * `make example`, `make static-example`: build all example programs and link them
# statically.
# * `make dynamic-example`: build all example programs and link them dynamically.
# Be sure to run `make dynamic` first (for the same reason as above).
# Project root (Fix for Windows compilation)
PROJ_ROOT = $(dir $(abspath $(lastword $(MAKEFILE_LIST))))
# Where to find the sources
LIB_SRCS = $(wildcard *.cpp) $(wildcard tools/*.cpp)
BUILTIN_COMMANDS = $(wildcard cmd/*.cpp)
EXAMPLE_SRCS = $(wildcard examples/*.cpp)
EXAMPLE_FILES = $(notdir $(EXAMPLE_SRCS))
# Output directories
BIN_ROOT = bin
BIN_OBJ = $(BIN_ROOT)/obj
BIN_TOOLS = $(BIN_OBJ)/tools
BIN_CMD = $(BIN_OBJ)/cmd
BIN_LIB = $(BIN_ROOT)
BIN_EXAMPLE = $(BIN_ROOT)/example
# Output objects
LIB_OBJS = $(addprefix $(BIN_OBJ)/, $(LIB_SRCS:%.cpp=%.o))
BUILTIN_OBJS = $(addprefix $(BIN_OBJ)/, $(BUILTIN_COMMANDS:%.cpp=%.o))
STATIC_LIB = $(BIN_LIB)/libiash.a
DYNAMIC_LIB = $(BIN_LIB)/libiash.so
EXAMPLES = $(addprefix $(BIN_EXAMPLE)/, $(EXAMPLE_FILES:%.cpp=%))
EXAMPLE_PREREQ =
# Executables and flags
CXX = g++
CXXFLAGS = -Wall -Werror -pedantic --std=c++11
OPTIMIZATION = -O2
LIBFLAGS =
EXAMPLE_LINKFLAGS = -L$(abspath $(BIN_LIB)) -liash
AR = ar
MKDIR = mkdir -p
RM = rm -vrf
.PHONY: clean all static dynamic example static-example dynamic-example dirs
ifeq ($(OS),Windows_NT)
MKDIR = md
RM = rmdir /s /q
BIN_OBJ = $(BIN_ROOT)\obj
BIN_TOOLS = $(BIN_OBJ)\tools
BIN_CMD = $(BIN_OBJ)\cmd
BIN_EXAMPLE = $(BIN_ROOT)\example
endif
static: $(STATIC_LIB)
dynamic: LIBFLAGS += -fpic
dynamic: $(DYNAMIC_LIB)
debug: OPTIMIZATION = -g
debug: all
all: static static-example
$(STATIC_LIB): $(LIB_OBJS) $(BUILTIN_OBJS)
$(AR) rcs "$@" $(LIB_OBJS) $(BUILTIN_OBJS)
$(DYNAMIC_LIB): $(LIB_OBJS) $(BUILTIN_OBJS)
$(CXX) $(LIB_OBJS) $(BUILTIN_OBJS) -shared -o "$@"
$(BIN_OBJ)/%.o: %.cpp | dirs
$(CXX) $(CXXFLAGS) $(LIBFLAGS) $(OPTIMIZATION) -c $< -o $@
example: static-example
static-example: $(addsuffix .static, $(EXAMPLES))
dynamic-example: $(addsuffix .dynamic, $(EXAMPLES))
$(BIN_EXAMPLE)/%.static: examples/%.cpp static | dirs
$(CXX) $(CXXFLAGS) $(OPTIMIZATION) -I $(PROJ_ROOT) $< $(STATIC_LIB) -o $@
$(BIN_EXAMPLE)/%.dynamic: examples/%.cpp dynamic | dirs
$(CXX) $(CXXFLAGS) $(OPTIMIZATION) -I $(PROJ_ROOT) $< -o $@ $(EXAMPLE_LINKFLAGS)
dirs:
@$(MKDIR) $(BIN_ROOT)
@$(MKDIR) $(BIN_OBJ)
@$(MKDIR) $(BIN_TOOLS)
@$(MKDIR) $(BIN_CMD)
@$(MKDIR) $(BIN_EXAMPLE)
clean:
$(RM) $(BIN_ROOT)