1 | # Copyright (C) 2009 Modelon AB |
---|
2 | # |
---|
3 | # This program is free software: you can redistribute it and/or modify |
---|
4 | # it under the terms of the GNU General Public License version 3 as published |
---|
5 | # by the Free Software Foundation, or optionally, under the terms of the |
---|
6 | # Common Public License version 1.0 as published by IBM. |
---|
7 | # |
---|
8 | # This program is distributed in the hope that it will be useful, |
---|
9 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
10 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
11 | # GNU General Public License, or the Common Public License, for more details. |
---|
12 | # |
---|
13 | # You should have received copies of the GNU General Public License |
---|
14 | # and the Common Public License along with this program. If not, |
---|
15 | # see <http://www.gnu.org/licenses/> or |
---|
16 | # <http://www.ibm.com/developerworks/library/os-cpl.html/> respectively. |
---|
17 | |
---|
18 | # |
---|
19 | # NOTICE: This make file is intended to be run in a Linux shell. |
---|
20 | # |
---|
21 | # Usage: |
---|
22 | # This makefile is intended to be used by the code generated by the |
---|
23 | # JModelica compilers. The following arguments are supported: |
---|
24 | # |
---|
25 | # FILE_NAME (mandatory) The name of the C file. |
---|
26 | # PLATFORM (mandatory) The platform we are compiling for, |
---|
27 | # currently only used to decide where to place binary. |
---|
28 | # Should be linux32 or linux64. |
---|
29 | # JMODELICA_HOME (mandatory) The directory where JModelica has been built, |
---|
30 | # or equivalently, the directory of a binary JModelica |
---|
31 | # distribution. |
---|
32 | # SUNDIALS_HOME (mandatory) The directory of Sundials. |
---|
33 | # EXT_LIB_DIRS List of external library directories. |
---|
34 | # EXT_LIBS List of external libraries. |
---|
35 | # EXT_INC_DIRS List of external include directories. |
---|
36 | # EXTRA_CFLAGS Extra CFLAGS for specific files |
---|
37 | # Format is (with e1.c and e2.c) "e1:O2:pedantic e2:O1" |
---|
38 | # |
---|
39 | # The following targets are supported: |
---|
40 | # fmume10 Build a shared object file containing the generated code and the |
---|
41 | # Model Exchange for API FMI 1.0. |
---|
42 | # fmucs10 Build a shared object file containing the generated code and the |
---|
43 | # co-simulation API for FMI 1.0. |
---|
44 | # fmume20 Build a shared object file containing the generated code and the |
---|
45 | # Model Exchange for API FMI 2.0. |
---|
46 | # fmucs20 Build a shared object file containing the generated code and the |
---|
47 | # co-simulation API for FMI 2.0. |
---|
48 | # fmumecs20 Build a shared object file containing the generated code and the |
---|
49 | # Model Exchange API and co-simulation API for FMI 2.0. |
---|
50 | # |
---|
51 | # Example: |
---|
52 | # make -f Makefile.linux linux32 \ |
---|
53 | # FILE_NAME=CCodeGenTests.CCodeGenTest1 \ |
---|
54 | # JMODELICA_HOME=/home/jakesson/projects/JModelica/build \ |
---|
55 | # |
---|
56 | |
---|
57 | # Name of shared library |
---|
58 | FILE_NAME = |
---|
59 | |
---|
60 | # Extra CFLAGS for specific source files. |
---|
61 | EXTRA_CFLAGS = |
---|
62 | |
---|
63 | # Platform name - controls what sub-directory the binary is placed in |
---|
64 | PLATFORM = |
---|
65 | |
---|
66 | # JModelica home |
---|
67 | JMODELICA_HOME = |
---|
68 | |
---|
69 | # SUNDIALS home |
---|
70 | SUNDIALS_HOME = |
---|
71 | |
---|
72 | # Additional library directories |
---|
73 | EXT_LIB_DIRS = |
---|
74 | |
---|
75 | # Additional libraries |
---|
76 | EXT_LIBS = |
---|
77 | EXTERNAL_LIBS = $(EXT_LIBS:%=-l%) -llapack -lblas -lgfortran |
---|
78 | |
---|
79 | # Additional include directories |
---|
80 | EXT_INC_DIRS = |
---|
81 | |
---|
82 | # Directory to place binary in |
---|
83 | BINARY_BASE_DIR = binaries |
---|
84 | BINARY_DIR = $(BINARY_BASE_DIR)/$(PLATFORM) |
---|
85 | |
---|
86 | SHARED = $(BINARY_DIR)/$(FILE_NAME).so |
---|
87 | EXECUTABLE = $(BINARY_BASE_DIR)/$(FILE_NAME) |
---|
88 | |
---|
89 | # Object files to be included in the shared library |
---|
90 | OBJS = $(patsubst sources/%.c, %.o, $(wildcard sources/*.c)) $(patsubst sources/%.cpp, %.o, $(wildcard sources/*.cpp)) |
---|
91 | |
---|
92 | # C++ Compiler command |
---|
93 | CXX = g++ |
---|
94 | |
---|
95 | # C Compiler command |
---|
96 | CC = gcc |
---|
97 | |
---|
98 | |
---|
99 | # C Compiler options |
---|
100 | CFLAGS = -std=c89 -pedantic -fPIC -msse2 -mfpmath=sse |
---|
101 | |
---|
102 | SHARED_LDFLAGS = -shared -Wl,-rpath,'$$ORIGIN',--no-undefined -pthread |
---|
103 | |
---|
104 | # Directories with header files |
---|
105 | JMI_INC_DIR = ${JMODELICA_HOME}/include |
---|
106 | RUNTIMELIBRARY_INC_DIR = ${JMODELICA_HOME}/include/RuntimeLibrary |
---|
107 | STANDARD_HEADER_INC_DIR = ${JMODELICA_HOME}/ThirdParty/FMI/2.0 |
---|
108 | SUNDIALS_INC_DIR = $(SUNDIALS_HOME)/include |
---|
109 | |
---|
110 | # Directories with libraries |
---|
111 | JMI_LIB_DIR = ${JMODELICA_HOME}/lib |
---|
112 | RUNTIMELIBRARY_LIB_DIR = ${JMODELICA_HOME}/lib/RuntimeLibrary |
---|
113 | SUNDIALS_LIB_DIR = $(SUNDIALS_HOME)/lib |
---|
114 | MINPACK_LIB_DIR = ${JMODELICA_HOME}/ThirdParty/Minpack/lib |
---|
115 | |
---|
116 | # Libraries necessary to link with jmi |
---|
117 | # Reused parts |
---|
118 | LIBS_FMU_STD = -ljmi -ldl "-L$(JMI_LIB_DIR)" $(EXT_LIB_DIRS) $(EXTERNAL_LIBS) -lModelicaExternalC -lzlib -ljmi |
---|
119 | LIB_SUNDIALS = -L$(SUNDIALS_LIB_DIR) -l:libsundials_kinsol.a -l:libsundials_nvecserial.a |
---|
120 | LIB_MINPACK = -L$(MINPACK_LIB_DIR) -l:libcminpack.a |
---|
121 | LIB_STD = -lstdc++ -lm |
---|
122 | LIB_COMMON = $(LIB_SUNDIALS) $(LIB_MINPACK) $(LIB_STD) |
---|
123 | |
---|
124 | # For different targets |
---|
125 | LIBS_FMUME10 = -lfmi1_me $(LIBS_FMU_STD) $(LIB_COMMON) |
---|
126 | LIBS_FMUCS10 = -lfmi1_cs -lfmi1_me $(LIBS_FMU_STD) $(LIB_COMMON) -l:libsundials_cvode.a |
---|
127 | LIBS_FMU20 = -lfmi2 $(LIBS_FMU_STD) $(LIB_COMMON) -l:libsundials_cvode.a |
---|
128 | LIBS_CEVAL = $(LIBS_FMU_STD) |
---|
129 | |
---|
130 | # Include paths for compilation |
---|
131 | INCL = -I$(RUNTIMELIBRARY_INC_DIR) -I$(STANDARD_HEADER_INC_DIR) $(EXT_INC_DIRS) -I$(SUNDIALS_INC_DIR) |
---|
132 | |
---|
133 | # set variable to correct makefile (for recursive call in fmume/fmucs) |
---|
134 | MAKEFILE = $(lastword $(MAKEFILE_LIST)) |
---|
135 | |
---|
136 | |
---|
137 | ceval: |
---|
138 | $(MAKE) -f $(MAKEFILE) ceval_ |
---|
139 | |
---|
140 | ceval_: $(OBJS) |
---|
141 | mkdir -p $(BINARY_BASE_DIR) |
---|
142 | $(CC) $(CFLAGS) -o $(EXECUTABLE) $(OBJS) -L${RUNTIMELIBRARY_LIB_DIR} $(LIBS_CEVAL) $(LIB_STD) |
---|
143 | $(RM) $(OBJS) |
---|
144 | |
---|
145 | |
---|
146 | fmume10: |
---|
147 | $(MAKE) -f $(MAKEFILE) fmume10_ |
---|
148 | |
---|
149 | fmume10_: $(OBJS) |
---|
150 | mkdir -p $(BINARY_DIR) |
---|
151 | $(CXX) $(SHARED_LDFLAGS) $(CFLAGS) -o $(SHARED) $(OBJS) -L$(RUNTIMELIBRARY_LIB_DIR) $(LIBS_FMUME10) |
---|
152 | $(RM) $(OBJS) |
---|
153 | |
---|
154 | fmucs10: |
---|
155 | $(MAKE) -f $(MAKEFILE) fmucs10_ |
---|
156 | |
---|
157 | fmucs10_: $(OBJS) |
---|
158 | mkdir -p $(BINARY_DIR) |
---|
159 | $(CXX) $(SHARED_LDFLAGS) $(CFLAGS) -o $(SHARED) $(OBJS) -L$(RUNTIMELIBRARY_LIB_DIR) $(LIBS_FMUCS10) |
---|
160 | $(RM) $(OBJS) |
---|
161 | |
---|
162 | fmume20: |
---|
163 | $(MAKE) -f $(MAKEFILE) fmume20_ |
---|
164 | |
---|
165 | fmume20_: $(OBJS) |
---|
166 | mkdir -p $(BINARY_DIR) |
---|
167 | $(CXX) $(SHARED_LDFLAGS) $(CFLAGS) -o $(SHARED) $(OBJS) -L${RUNTIMELIBRARY_LIB_DIR} $(LIBS_FMU20) |
---|
168 | $(RM) $(OBJS) |
---|
169 | |
---|
170 | fmucs20: |
---|
171 | $(MAKE) -f $(MAKEFILE) fmucs20_ |
---|
172 | |
---|
173 | fmucs20_: $(OBJS) |
---|
174 | mkdir -p $(BINARY_DIR) |
---|
175 | $(CXX) $(SHARED_LDFLAGS) $(CFLAGS) -o $(SHARED) $(OBJS) -L${RUNTIMELIBRARY_LIB_DIR} $(LIBS_FMU20) |
---|
176 | $(RM) $(OBJS) |
---|
177 | |
---|
178 | fmumecs20: |
---|
179 | $(MAKE) -f $(MAKEFILE) fmucs20_ |
---|
180 | |
---|
181 | fmumecs20_: $(OBJS) |
---|
182 | mkdir -p $(BINARY_DIR) |
---|
183 | $(CXX) $(SHARED_LDFLAGS) $(CFLAGS) -o $(SHARED) $(OBJS) -L${RUNTIMELIBRARY_LIB_DIR} $(LIBS_FMU20) |
---|
184 | $(RM) $(OBJS) |
---|
185 | |
---|
186 | |
---|
187 | # Compile |
---|
188 | %.o: sources/%.c |
---|
189 | $(CC) $(CFLAGS) $(INCL) -c -o $@ $< |
---|
190 | |
---|
191 | |
---|
192 | # Create a rule which uses the first item in arg as src name and |
---|
193 | # following items as additional CFLAGS. Argument "file:-O2:-d" |
---|
194 | # will expand to the rule "file.o : CFLAGS = $(CFLAGS) -O2 -d" |
---|
195 | define cflagrule |
---|
196 | $(word 1,$(1)).o : CFLAGS = $(CFLAGS) $(wordlist 2,$(words $(1)),$(1)) |
---|
197 | endef |
---|
198 | |
---|
199 | # For each word in variable EXTRA_CFLAGS, create a cflagrule |
---|
200 | # Example "main2 main3:O3 main:O2:pedantic" |
---|
201 | $(foreach src, $(EXTRA_CFLAGS),$(eval $(call cflagrule, $(subst :, -,$(src))))) |
---|
202 | |
---|
203 | clean: |
---|
204 | $(RM) $(SHARED) $(OBJS) |
---|