forked from lwtnn/lwtnn
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmakefile
118 lines (93 loc) · 3 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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# makefile for generic c++ project
# generated with `makeproject` on Tue Sep 22 08:07:33 PDT 2015
# Author: Dan Guest <[email protected]>
# _______________________________________________________________
# Basic Setup
# --- set dirs
BUILD := build
SRC := src
INC := include
DICT := dict
OUTPUT := bin
LIBDIR := $(CURDIR)/lib
LIBNAME := liblwtnn.so
# set search path
vpath %.cxx $(SRC)
vpath %.hh $(INC)
vpath %.h $(INC)
vpath %Dict.h $(DICT)
vpath %Dict.cxx $(DICT)
# --- set compiler and flags (roll c options and include paths together)
CXX ?= g++
CXXFLAGS := -O2 -Wall -fPIC -I$(INC) -g -std=c++11 -pedantic
# add user flags
CXXFLAGS += $(LWTNN_CXX_FLAGS)
LIBS := $(LWTNN_LIBS)
LDFLAGS := $(LWTNN_LDFLAGS)
# add eigen
ifeq ($(shell pkg-config eigen3; echo $$?),0)
CXXFLAGS += $(shell pkg-config eigen3 --cflags)
endif
# ---- define objects from files in the SRC directory
GEN_OBJ_SRC := $(wildcard $(SRC)/*.cxx)
GEN_OBJ := $(notdir $(GEN_OBJ_SRC:%.cxx=%.o))
# this list may be manipulated in other segments further down
GEN_OBJ_PATHS := $(GEN_OBJ:%=$(BUILD)/%)
# --- all top level (added further down)
ALL_TOP_LEVEL := # blank, more will be added below
# _______________________________________________________________
# Add Top Level Objects
# --- stuff used for the c++ executable
# everything with this prefix will be built as an executable
EXE_PREFIX := lwtnn-
ALL_EXE_SRC := $(wildcard $(SRC)/$(EXE_PREFIX)*.cxx)
ALL_EXE := $(notdir $(ALL_EXE_SRC:%.cxx=%))
ALL_EXE_PATHS := $(ALL_EXE:%=$(OUTPUT)/%)
# filter out the general objects
GEN_OBJ_PATHS := $(filter-out $(BUILD)/$(EXE_PREFIX)%.o,$(GEN_OBJ_PATHS))
# add to all top level
ALL_TOP_LEVEL += $(ALL_EXE_PATHS)
# add the library
ALL_TOP_LEVEL += $(LIBDIR)/$(LIBNAME)
# _______________________________________________________________
# Add Libraries
# --- first call here
all: $(ALL_TOP_LEVEL)
# _______________________________________________________________
# Add Build Rules
# build exe
$(OUTPUT)/$(EXE_PREFIX)%: $(GEN_OBJ_PATHS) $(BUILD)/$(EXE_PREFIX)%.o
@mkdir -p $(OUTPUT)
@echo "linking $^ --> $@"
@$(CXX) -o $@ $^ $(LIBS) $(LDFLAGS)
# build lib
$(LIBDIR)/$(LIBNAME): $(GEN_OBJ_PATHS)
@mkdir -p $(LIBDIR)
@echo "linking $^ --> $@"
@$(CXX) -o $@ $^ $(LIBS) $(LDFLAGS) -shared
# compile rule
$(BUILD)/%.o: %.cxx
@echo compiling $<
@mkdir -p $(BUILD)
@$(CXX) -c $(CXXFLAGS) $< -o $@
# use auto dependency generation
ALLOBJ := $(GEN_OBJ)
DEP := $(BUILD)
ifneq ($(MAKECMDGOALS),clean)
ifneq ($(MAKECMDGOALS),rmdep)
include $(ALLOBJ:%.o=$(DEP)/%.d)
endif
endif
DEPTARGSTR = -MT $(BUILD)/$*.o -MT $(DEP)/$*.d
$(DEP)/%.d: %.cxx
@echo making dependencies for $<
@mkdir -p $(DEP)
@$(CXX) -MM -MP $(DEPTARGSTR) $(CXXFLAGS) $(PY_FLAGS) $< -o $@
# clean
.PHONY : clean rmdep all
CLEANLIST = *~ *.o *.o~ *.d core
clean:
rm -fr $(CLEANLIST) $(CLEANLIST:%=$(BUILD)/%) $(CLEANLIST:%=$(DEP)/%)
rm -fr $(BUILD) $(DICT) $(OUTPUT) $(LIBDIR)
rmdep:
rm -f $(DEP)/*.d