-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
40 lines (30 loc) · 856 Bytes
/
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
# compiler and options
CXX ?= g++
CXXFLAGS ?= -std=c++11
# needing and generated files
SRCS = $(wildcard *.cpp)
OBJS = $(SRCS:.cpp=.o)
TARGET = $(patsubst %.cpp, %, $(SRCS))
INC = -I.
# end with .cc
LIB_OBJS = $(patsubst %.cc, %.o, $(wildcard *.cc))
LIB = $(patsubst %.o, lib%.a, $(LIB_OBJS))
LIBPATH = -L.
LIBNAME = $(patsubst %.o, -l%, $(LIB_OBJS))
.PHONY:all clean
all:$(TARGET)
# generate target, sequence is important, if a->b then a before b
$(TARGET):%:%.o $(LIB)
$(CXX) $(CXXFLAGS) -o $@ $< $(LIBPATH) $(LIBNAME)
$(OBJS):%.o:%.cpp
$(CXX) $(CXXFLAGS) $(INC) -o $@ -c $<
# generate static lib
$(LIB):lib%.a:%.o
ar cr $@ $<
$(LIB_OBJS):%.o:%.cc
$(CXX) $(CXXFLAGS) $(INC) -o $@ -c $<
clean:
rm $(TARGET) $(OBJS) $(LIB) $(LIB_OBJS)
# @for name in $(TARGET);do\
# $(CXX) $(INC) $(CXXFLAGS) -o $$name $$name.cpp $(wildcard *.cc);\
#done