forked from lafer-unicamp/mbsim-wagons
-
Notifications
You must be signed in to change notification settings - Fork 0
/
default_build.mk
72 lines (58 loc) · 2.67 KB
/
default_build.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
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
# This file builds a "EXECNAME" executable from all sources found under $(SRCDIR).
# SRCDIR must be set .
# PACKAGES must also be set .
# Moreover the LDFLAGS, CPPFLAGS and CXXFLAGS are honored if set externally.
BUILDDIR = $(SRCDIR)/../build/
EXECNAME = teste
# Enable VPATH builds with sources at SRCDIR
VPATH=$(SRCDIR)
# use a sources all *.cc file under SRCDIR
SOURCES:=$(shell (cd $(SRCDIR); find -name "*.cpp"))
# object and dependency files (derived from SOURCES)
OBJECTS=$(SOURCES:.cpp=.o)
# OBJECTS=$(addprefix $(BUILDDIR),$(notdir $(SOURCES:.cpp=.o)))
DEPFILES=$(SOURCES:.cpp=.o.d)
# enable C++17
CXXFLAGS += -std=c++17 -D_USE_MATH_DEFINES -I$(SRCDIR)/../include
# platform specific settings
ifeq ($(PLATFORM),Windows)
SHEXT=.dll
EXEEXT=.exe
PIC=
LDFLAGSRPATH=
WIN=1
else
SHEXT=.so
EXEEXT=
PIC=-fpic
LDFLAGSRPATH=-Wl,--disable-new-dtags
WIN=0
endif
# default target
all: $(EXECNAME)$(EXEEXT)
# FMI export target
fmiexport: mbsimfmi_model$(SHEXT)
# mingw -Wl,-Map generates some dependencies named rtr0*.o which needs to be removed
# link main executable with pkg-config options from PACKAGES (runexamples.py executes always ./main)
$(EXECNAME)$(EXEEXT): $(OBJECTS)
$(CXX) -Wl,[email protected] -o $(BUILDDIR)$@ $(OBJECTS) $(LDFLAGS) $(shell pkg-config --libs $(PACKAGES))
@sed -rne "/^LOAD /s/^LOAD (.*)$$/ \1 \\\/p" [email protected] | grep -Ev rtr[0-9]+\.o > [email protected] || true
@test $(WIN) -eq 0 && (echo "$@: \\" > [email protected] && cat [email protected] >> [email protected] && rm -f [email protected] [email protected]) || (rm -f [email protected])
# FMI export target
mbsimfmi_model$(SHEXT): $(OBJECTS)
$(CXX) -shared $(LDFLAGSRPATH) -Wl,-rpath,\$$ORIGIN,[email protected] -o $@ $(OBJECTS) $(LDFLAGS) $(shell pkg-config --libs $(PACKAGES))
@sed -rne "/^LOAD /s/^LOAD (.*)$$/ \1 \\\/p" [email protected] | grep -Ev rtr[0-9]+\.o > [email protected] || true
@test $(WIN) -eq 0 && (echo "$@: \\" > [email protected] && cat [email protected] >> [email protected] && rm -f [email protected] [email protected]) || (rm -f [email protected])
rpath: $(OBJECTS)
$(CXX) -o $@ $^ $(LDFLAGS) $(shell pkg-config --libs $(PACKAGES)) $(shell pkg-config --libs-only-L $(PACKAGES) | sed 's/-L/-Wl,-rpath,/g')
# compile source with pkg-config options from PACKAGES (and generate dependency file)
%.o: %.cpp
@$(CXX) -MM -MP $(PIC) $(CPPFLAGS) $(CXXFLAGS) $(shell pkg-config --cflags $(PACKAGES)) $< > $(BUILDDIR)[email protected]
$(CXX) -c $(PIC) -o $(BUILDDIR)$@ $(CPPFLAGS) $(CXXFLAGS) $(shell pkg-config --cflags $(PACKAGES)) $<
# clean target: remove all generated files
clean:
rm -f main$(EXEEXT) mbsimfmi_model$(SHEXT) $(OBJECTS) $(DEPFILES) main$(EXEEXT).d mbsimfmi_model$(SHEXT).d
# include the generated make rules (without print a warning about missing include files (at first run))
-include $(DEPFILES)
-include main$(EXEEXT).d
-include mbsimfmi_model$(SHEXT).d