-
Notifications
You must be signed in to change notification settings - Fork 17
/
Makefile
67 lines (50 loc) · 1.43 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
CXXFLAGS=-std=c++11 -Wall
OPTFLAGS=-O3
ifdef DEBUG
ifeq ($(DEBUG), 1)
OPTFLAGS= -O0 -g -DNO_OUTPUT
endif
endif
CXXFLAGS+=$(OPTFLAGS)
STATIC_LIB_NAME := libdramsim.a
LIB_NAME=libdramsim.so
LIB_NAME_MACOS=libdramsim.dylib
UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S),Darwin)
LDFLAGS=-g -shared -Wl
else
LDFLAGS=-g -shared -Wl,-soname,$(LIB_NAME)
endif
SRC = $(wildcard *.cpp)
OBJ = $(addsuffix .o, $(basename $(SRC)))
LIB_SRC := $(filter-out TraceBasedSim.cpp,$(SRC))
LIB_OBJ := $(addsuffix .o, $(basename $(LIB_SRC)))
#build portable objects (i.e. with -fPIC)
POBJ = $(addsuffix .po, $(basename $(LIB_SRC)))
REBUILDABLES=$(OBJ) ${POBJ} $(LIB_NAME) $(STATIC_LIB_NAME)
all: ${LIB_NAME}
# $@ target name, $^ target deps, $< matched pattern
$(LIB_NAME): $(POBJ)
g++ $(LDFLAGS) -o $@ $^
@echo "Built $@ successfully"
$(STATIC_LIB_NAME): $(LIB_OBJ)
$(AR) crs $@ $^
$(LIB_NAME_MACOS): $(POBJ)
g++ -dynamiclib -o $@ $^
@echo "Built $@ successfully"
#include the autogenerated dependency files for each .o file
-include $(OBJ:.o=.dep)
-include $(POBJ:.po=.deppo)
# build dependency list via gcc -M and save to a .dep file
%.dep : %.cpp
@$(CXX) -M $(CXXFLAGS) $< > $@
%.deppo : %.cpp
@$(CXX) -M $(CXXFLAGS) -MT"$*.po" $< > $@
# build all .cpp files to .o files
%.o : %.cpp
g++ $(CXXFLAGS) -o $@ -c $<
#po = portable object .. for lack of a better term
%.po : %.cpp
g++ $(CXXFLAGS) -fPIC -o $@ -c $<
clean:
-rm -f $(REBUILDABLES) *.dep *.deppo