1 | |
---|
2 | # Copyright (C) 2009 Modelon AB |
---|
3 | # |
---|
4 | # This program is free software: you can redistribute it and/or modify |
---|
5 | # it under the terms of the GNU General Public License version 3 as published |
---|
6 | # by the Free Software Foundation, or optionally, under the terms of the |
---|
7 | # Common Public License version 1.0 as published by IBM. |
---|
8 | # |
---|
9 | # This program is distributed in the hope that it will be useful, |
---|
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
12 | # GNU General Public License, or the Common Public License, for more details. |
---|
13 | # |
---|
14 | # You should have received copies of the GNU General Public License |
---|
15 | # and the Common Public License along with this program. If not, |
---|
16 | # see <http://www.gnu.org/licenses/> or |
---|
17 | # <http://www.ibm.com/developerworks/library/os-cpl.html/> respectively. |
---|
18 | |
---|
19 | # |
---|
20 | # NOTICE: This make file is intended to be run from the standard Windows |
---|
21 | # command prompt cmd.exe. Also, the MinGW bin directory needs to be in PATH. |
---|
22 | # |
---|
23 | # Usage: |
---|
24 | # This makefile is intended to be used by the code generated by the |
---|
25 | # JModelica compilers. The following arguments are supported: |
---|
26 | # |
---|
27 | # FILE_NAME (mandatory) The name of the C file. |
---|
28 | # PLATFORM (mandatory) The platform we are compiling for, |
---|
29 | # currently only used to decide where to place binary. |
---|
30 | # Should be win32 or win64. |
---|
31 | # JMODELICA_HOME (mandatory) The directory where JModelica has been built, |
---|
32 | # or equivalently, the directory of a binary JModelica |
---|
33 | # distribution. |
---|
34 | # SUNDIALS_HOME (mandatory) The directory of Sundials. |
---|
35 | # EXT_LIB_DIRS List of external library directories. |
---|
36 | # EXT_LIBS List of external libraries. |
---|
37 | # EXT_INC_DIRS List of external include directories. |
---|
38 | # EXTRA_CFLAGS Extra CFLAGS for specific files |
---|
39 | # Format is (with e1.c and e2.c) "e1:O2:pedantic e2:O1" |
---|
40 | # |
---|
41 | # The following targets are supported: |
---|
42 | # fmume10 Build a shared object file containing the generated code and the |
---|
43 | # Model Exchange for API FMI 1.0. |
---|
44 | # fmucs10 Build a shared object file containing the generated code and the |
---|
45 | # co-simulation API for FMI 1.0. |
---|
46 | # fmume20 Build a shared object file containing the generated code and the |
---|
47 | # Model Exchange for API FMI 2.0. |
---|
48 | # fmucs20 Build a shared object file containing the generated code and the |
---|
49 | # co-simulation API for FMI 2.0. |
---|
50 | # fmumecs20 Build a shared object file containing the generated code and the |
---|
51 | # Model Exchange API and co-simulation API for FMI 2.0. |
---|
52 | # |
---|
53 | # Example: |
---|
54 | # make -f Makefile.windows win32 |
---|
55 | # FILE_NAME=CCodeGenTests.CCodeGenTest2 \ |
---|
56 | # JMODELICA_HOME=/c/jmodelica_install \ |
---|
57 | # |
---|
58 | # |
---|
59 | # |
---|
60 | # Make sure that cmd.exe is used, even if cygwin or mingw-sh are on the path |
---|
61 | SHELL = cmd.exe |
---|
62 | |
---|
63 | # Name of shared library |
---|
64 | FILE_NAME = |
---|
65 | |
---|
66 | # Extra CFLAGS for specific source files. |
---|
67 | EXTRA_CFLAGS = |
---|
68 | |
---|
69 | # Platform name - controls what sub-directory the binary is placed in |
---|
70 | PLATFORM = |
---|
71 | |
---|
72 | # Platform specific compiler flag |
---|
73 | PLATFORM_FLAG = -m32 |
---|
74 | PLATFORM_64 = -m64 |
---|
75 | |
---|
76 | # JModelica home |
---|
77 | JMODELICA_HOME = |
---|
78 | |
---|
79 | # SUNDIALS home |
---|
80 | SUNDIALS_HOME = |
---|
81 | |
---|
82 | # Additional library directories |
---|
83 | EXT_LIB_DIRS = |
---|
84 | |
---|
85 | # Additional libraries |
---|
86 | # The compiler is assumed to always include lapack since some runtime |
---|
87 | # configurations depends on it. Our lapack library is located in the |
---|
88 | # runtime library directory and depends on blas and gfortran. Blas |
---|
89 | # should also be included from the runtime library directory. Gfortran |
---|
90 | # is found in the mingw configuration and we need to specify that we |
---|
91 | # want the static version. |
---|
92 | EXT_LIBS = |
---|
93 | EXTERNAL_LIBS = $(EXT_LIBS:%=-l%) -llapack -lblas -l:libgfortran.a -l:libquadmath.a |
---|
94 | |
---|
95 | # Additional include directories |
---|
96 | EXT_INC_DIRS = |
---|
97 | |
---|
98 | # Directory to place binary in |
---|
99 | BINARY_BASE_DIR = binaries |
---|
100 | BINARY_DIR = $(BINARY_BASE_DIR)/$(PLATFORM) |
---|
101 | # And with \ to make the cmd version of mkdir happy |
---|
102 | BINARY_MKDIR = $(BINARY_BASE_DIR)\$(PLATFORM) |
---|
103 | |
---|
104 | SHARED = $(BINARY_DIR)/$(FILE_NAME).dll |
---|
105 | |
---|
106 | EXECUTABLE = $(BINARY_BASE_DIR)/$(FILE_NAME).exe |
---|
107 | |
---|
108 | # Object files to be included in the shared library |
---|
109 | OBJS = $(patsubst sources/%.c, %.o, $(wildcard sources/*.c)) $(patsubst sources/%.cpp, %.o, $(wildcard sources/*.cpp)) |
---|
110 | |
---|
111 | # C++ Compiler command |
---|
112 | CXX = g++ |
---|
113 | |
---|
114 | # C Compiler command |
---|
115 | CC = gcc |
---|
116 | |
---|
117 | # ar command |
---|
118 | AR = ar |
---|
119 | |
---|
120 | # Command to remove temporary files |
---|
121 | RM = del |
---|
122 | |
---|
123 | # Extra compiler options |
---|
124 | EXT_OPTION = |
---|
125 | |
---|
126 | # C++ Compiler options |
---|
127 | CXXFLAGS = $(PLATFORM_FLAG) $(EXT_OPTION) |
---|
128 | |
---|
129 | # C Compiler options |
---|
130 | CFLAGS = $(PLATFORM_FLAG) $(EXT_OPTION) -std=c89 -pedantic -msse2 -mfpmath=sse |
---|
131 | |
---|
132 | SHARED_LDFLAGS = $(PLATFORM_FLAG) -shared |
---|
133 | |
---|
134 | # Directories with header files |
---|
135 | JMI_INC_DIR = ${JMODELICA_HOME}/include |
---|
136 | RUNTIMELIBRARY_INC_DIR = ${JMODELICA_HOME}/include/RuntimeLibrary |
---|
137 | STANDARD_HEADER_INC_DIR = ${JMODELICA_HOME}/ThirdParty/FMI/2.0 |
---|
138 | SUNDIALS_INC_DIR = $(SUNDIALS_HOME)/include |
---|
139 | |
---|
140 | # Directories with libraries |
---|
141 | JMI_LIB_DIR = ${JMODELICA_HOME}/lib |
---|
142 | RUNTIMELIBRARY_LIB_DIR = ${JMODELICA_HOME}/lib/RuntimeLibrary |
---|
143 | RUNTIMELIBRARY_LIB_DIR64 = ${JMODELICA_HOME}/lib/RuntimeLibrary64 |
---|
144 | MINPACK_LIB_DIR = ${JMODELICA_HOME}/ThirdParty/Minpack/lib |
---|
145 | MINPACK_LIB_DIR64 = ${JMODELICA_HOME}/ThirdParty/Minpack/lib64 |
---|
146 | SUNDIALS_LIB_DIR = $(SUNDIALS_HOME)/lib |
---|
147 | SUNDIALS_LIB_DIR64 = $(SUNDIALS_HOME)/lib64 |
---|
148 | WINPTHREADS_LIB_DIR = ${JMODELICA_HOME}/ThirdParty/winpthreads/lib/winpthreads |
---|
149 | WINPTHREADS_LIB_DIR64 = ${JMODELICA_HOME}/ThirdParty/winpthreads/lib/winpthreads64 |
---|
150 | |
---|
151 | # Flags needed for specific libs |
---|
152 | LIB_MINPACK = "-L$(MINPACK_LIB_DIR)" -l:libcminpack.a |
---|
153 | LIB_SUNDIALS = "-L$(SUNDIALS_LIB_DIR)" -l:libsundials_kinsol.a -l:libsundials_nvecserial.a -l:libsundials_cvode.a |
---|
154 | LIB_PTHREADS = "-L$(WINPTHREADS_LIB_DIR)" -l:libwinpthread.a |
---|
155 | |
---|
156 | # Libraries necessary to link with jmi |
---|
157 | LIBS_FMU_STD = -static-libstdc++ -static-libgcc -ljmi "-L$(JMI_LIB_DIR)" $(EXT_LIB_DIRS) $(EXTERNAL_LIBS) -lModelicaExternalC -lzlib -ljmi |
---|
158 | LIBS_FMU_ALL = $(LIBS_FMU_STD) $(LIB_SUNDIALS) $(LIB_MINPACK) $(LIB_PTHREADS) |
---|
159 | LIBS_FMUME10 = -lfmi1_me $(LIBS_FMU_ALL) |
---|
160 | LIBS_FMUCS10 = -lfmi1_cs -lfmi1_me $(LIBS_FMU_ALL) |
---|
161 | LIBS_FMU20 = -lfmi2 $(LIBS_FMU_ALL) |
---|
162 | LIBS_CEVAL = -ljmi_evaluator_util $(LIBS_FMU_STD) |
---|
163 | |
---|
164 | # Include paths for compilation |
---|
165 | INCL = "-I$(RUNTIMELIBRARY_INC_DIR)" "-I${STANDARD_HEADER_INC_DIR}" $(EXT_INC_DIRS) "-I$(SUNDIALS_INC_DIR)" |
---|
166 | |
---|
167 | # set variable to correct makefile (for recursive call in fmume/fmucs) |
---|
168 | MAKEFILE = $(lastword $(MAKEFILE_LIST)) |
---|
169 | |
---|
170 | ceval: |
---|
171 | ifeq ($(PLATFORM),win32) |
---|
172 | "$(MAKE)" -f "$(MAKEFILE)" EXT_OPTION=-mincoming-stack-boundary=2 ceval_ |
---|
173 | else |
---|
174 | "$(MAKE)" -f "$(MAKEFILE)" PLATFORM_FLAG=$(PLATFORM_64) "RUNTIMELIBRARY_LIB_DIR=$(RUNTIMELIBRARY_LIB_DIR64)" "MINPACK_LIB_DIR=$(MINPACK_LIB_DIR64)" "SUNDIALS_LIB_DIR=$(SUNDIALS_LIB_DIR64)" "WINPTHREADS_LIB_DIR=$(WINPTHREADS_LIB_DIR64)" ceval_ |
---|
175 | endif |
---|
176 | |
---|
177 | ceval_: $(OBJS) |
---|
178 | if not exist "$(BINARY_BASE_DIR)" mkdir "$(BINARY_BASE_DIR)" |
---|
179 | "$(CXX)" $(CXXFLAGS) -o "$(EXECUTABLE)" $(OBJS) "-L${RUNTIMELIBRARY_LIB_DIR}" $(LIBS_CEVAL) |
---|
180 | $(RM) $(OBJS) |
---|
181 | |
---|
182 | fmume10: |
---|
183 | ifeq ($(PLATFORM),win32) |
---|
184 | "$(MAKE)" -f "$(MAKEFILE)" EXT_OPTION=-mincoming-stack-boundary=2 fmume10_ |
---|
185 | else |
---|
186 | "$(MAKE)" -f "$(MAKEFILE)" PLATFORM_FLAG=$(PLATFORM_64) "RUNTIMELIBRARY_LIB_DIR=$(RUNTIMELIBRARY_LIB_DIR64)" "MINPACK_LIB_DIR=$(MINPACK_LIB_DIR64)" "SUNDIALS_LIB_DIR=$(SUNDIALS_LIB_DIR64)" "WINPTHREADS_LIB_DIR=$(WINPTHREADS_LIB_DIR64)" fmume10_ |
---|
187 | endif |
---|
188 | |
---|
189 | fmume10_: $(OBJS) |
---|
190 | if not exist "$(BINARY_MKDIR)" mkdir "$(BINARY_MKDIR)" |
---|
191 | "$(CXX)" $(SHARED_LDFLAGS) $(CXXFLAGS) -o "$(SHARED)" $(OBJS) "-L${RUNTIMELIBRARY_LIB_DIR}" $(LIBS_FMUME10) |
---|
192 | $(RM) $(OBJS) |
---|
193 | |
---|
194 | fmucs10: |
---|
195 | ifeq ($(PLATFORM),win32) |
---|
196 | "$(MAKE)" -f "$(MAKEFILE)" EXT_OPTION=-mincoming-stack-boundary=2 fmucs10_ |
---|
197 | else |
---|
198 | "$(MAKE)" -f "$(MAKEFILE)" PLATFORM_FLAG=$(PLATFORM_64) "RUNTIMELIBRARY_LIB_DIR=$(RUNTIMELIBRARY_LIB_DIR64)" "MINPACK_LIB_DIR=$(MINPACK_LIB_DIR64)" "SUNDIALS_LIB_DIR=$(SUNDIALS_LIB_DIR64)" "WINPTHREADS_LIB_DIR=$(WINPTHREADS_LIB_DIR64)" fmucs10_ |
---|
199 | endif |
---|
200 | |
---|
201 | fmucs10_: $(OBJS) |
---|
202 | mkdir "$(BINARY_MKDIR)" |
---|
203 | "$(CXX)" $(SHARED_LDFLAGS) $(CXXFLAGS) -o "$(SHARED)" $(OBJS) "-L${RUNTIMELIBRARY_LIB_DIR}" $(LIBS_FMUCS10) |
---|
204 | $(RM) $(OBJS) |
---|
205 | |
---|
206 | fmume20: |
---|
207 | ifeq ($(PLATFORM),win32) |
---|
208 | "$(MAKE)" -f "$(MAKEFILE)" EXT_OPTION=-mincoming-stack-boundary=2 fmume20_ |
---|
209 | else |
---|
210 | "$(MAKE)" -f "$(MAKEFILE)" "PLATFORM_FLAG=$(PLATFORM_64)" "RUNTIMELIBRARY_LIB_DIR=$(RUNTIMELIBRARY_LIB_DIR64)" "MINPACK_LIB_DIR=$(MINPACK_LIB_DIR64)" "SUNDIALS_LIB_DIR=$(SUNDIALS_LIB_DIR64)" "WINPTHREADS_LIB_DIR=$(WINPTHREADS_LIB_DIR64)" fmume20_ |
---|
211 | endif |
---|
212 | |
---|
213 | fmume20_: $(OBJS) |
---|
214 | mkdir $(BINARY_MKDIR) |
---|
215 | "$(CXX)" $(SHARED_LDFLAGS) $(CXXFLAGS) -o "$(SHARED)" $(OBJS) "-L${RUNTIMELIBRARY_LIB_DIR}" $(LIBS_FMU20) |
---|
216 | $(RM) $(OBJS) |
---|
217 | |
---|
218 | fmucs20: |
---|
219 | ifeq ($(PLATFORM),win32) |
---|
220 | "$(MAKE)" -f "$(MAKEFILE)" EXT_OPTION=-mincoming-stack-boundary=2 fmucs20_ |
---|
221 | else |
---|
222 | "$(MAKE)" -f "$(MAKEFILE)" "PLATFORM_FLAG=$(PLATFORM_64)" "RUNTIMELIBRARY_LIB_DIR=$(RUNTIMELIBRARY_LIB_DIR64)" "MINPACK_LIB_DIR=$(MINPACK_LIB_DIR64)" "SUNDIALS_LIB_DIR=$(SUNDIALS_LIB_DIR64)" "WINPTHREADS_LIB_DIR=$(WINPTHREADS_LIB_DIR64)" fmucs20_ |
---|
223 | endif |
---|
224 | |
---|
225 | fmucs20_: $(OBJS) |
---|
226 | mkdir $(BINARY_MKDIR) |
---|
227 | "$(CXX)" $(SHARED_LDFLAGS) $(CXXFLAGS) -o "$(SHARED)" $(OBJS) "-L${RUNTIMELIBRARY_LIB_DIR}" $(LIBS_FMU20) |
---|
228 | $(RM) $(OBJS) |
---|
229 | |
---|
230 | fmumecs20: |
---|
231 | ifeq ($(PLATFORM),win32) |
---|
232 | "$(MAKE)" -f "$(MAKEFILE)" EXT_OPTION=-mincoming-stack-boundary=2 fmucs20_ |
---|
233 | else |
---|
234 | "$(MAKE)" -f "$(MAKEFILE)" PLATFORM_FLAG=$(PLATFORM_64) "RUNTIMELIBRARY_LIB_DIR=$(RUNTIMELIBRARY_LIB_DIR64)" "MINPACK_LIB_DIR=$(MINPACK_LIB_DIR64)" "SUNDIALS_LIB_DIR=$(SUNDIALS_LIB_DIR64)" "WINPTHREADS_LIB_DIR=$(WINPTHREADS_LIB_DIR64)" fmucs20_ |
---|
235 | endif |
---|
236 | |
---|
237 | fmumecs20_: $(OBJS) |
---|
238 | mkdir $(BINARY_MKDIR) |
---|
239 | "$(CXX)" $(SHARED_LDFLAGS) $(CXXFLAGS) -o "$(SHARED)" $(OBJS) "-L${RUNTIMELIBRARY_LIB_DIR}" $(LIBS_FMU20) |
---|
240 | $(RM) $(OBJS) |
---|
241 | |
---|
242 | |
---|
243 | all: $(SHARED) |
---|
244 | |
---|
245 | .SUFFIXES: .cpp .c .o .obj |
---|
246 | |
---|
247 | # Compile |
---|
248 | %.o: sources/%.c |
---|
249 | "$(CC)" $(CFLAGS) $(INCL) -c -o "$@" $< |
---|
250 | |
---|
251 | |
---|
252 | # Create a rule which uses the first item in arg as src name and |
---|
253 | # following items as additional CFLAGS. Argument "file:-O2:-d" |
---|
254 | # will expand to the rule "file.o : CFLAGS = $(CFLAGS) -O2 -d" |
---|
255 | define cflagrule |
---|
256 | $(word 1,$(1)).o : CFLAGS = $(CFLAGS) $(wordlist 2,$(words $(1)),$(1)) |
---|
257 | endef |
---|
258 | |
---|
259 | # For each word in variable EXTRA_CFLAGS, create a cflagrule |
---|
260 | # Example "main2 main3:O3 main:O2:pedantic" |
---|
261 | $(foreach src, $(EXTRA_CFLAGS),$(eval $(call cflagrule, $(subst :, -,$(src))))) |
---|
262 | |
---|
263 | clean: |
---|
264 | $(RM) $(SHARED) $(OBJS) |
---|