forked from chronolaw/cpp_study
-
Notifications
You must be signed in to change notification settings - Fork 0
/
common.mk
40 lines (32 loc) · 797 Bytes
/
common.mk
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
CXX_FLAGS=-Wall
CXX=g++
HAS_CPP14=$(shell \
echo > /tmp/dummy.cpp ; \
if $(CXX) -std=c++14 -c -o /dev/null /tmp/dummy.cpp 2>/dev/null ; then \
echo yes ; \
else \
echo no ; \
fi)
HAS_CPP11=$(shell \
echo > /tmp/dummy.cpp ; \
if $(CXX) -std=c++11 -c -o /dev/null /tmp/dummy.cpp 2>/dev/null ; then \
echo yes ; \
else \
echo no ; \
fi)
ifeq ($(HAS_CPP14), yes)
PREFER_STANDARD:=cpp14
else
ifeq ($(HAS_CPP11), yes)
PREFER_STANDARD:=cpp11
endif
endif
all: examples
example_%_cpp14: %.cpp
$(CXX) -std=c++14 -o $@ $^ $(CXX_FLAGS) $($@_cxx_flags) $($@_ld_flags)
example_%_cpp11: %.cpp
$(CXX) -std=c++11 -o $@ $^ $(CXX_FLAGS) $($@_cxx_flags) $($@_ld_flags)
example_%_cpp98: %.cpp
$(CXX) -std=c++98 -o $@ $^ $(CXX_FLAGS) $($@_cxx_flags) $($@_ld_flags)
clean:
rm -fr example_*