source: trunk/RuntimeLibrary/Makefiles/Makefile.windows @ 11565

Last change on this file since 11565 was 11565, checked in by Christian Andersson, 15 months ago

Merged pthreads to trunk. Related to ticket:5671

File size: 10.2 KB
Line 
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
61SHELL = cmd.exe
62
63# Name of shared library
64FILE_NAME =
65
66# Extra CFLAGS for specific source files.
67EXTRA_CFLAGS =
68
69# Platform name - controls what sub-directory the binary is placed in
70PLATFORM =
71
72# Platform specific compiler flag
73PLATFORM_FLAG = -m32
74PLATFORM_64 = -m64
75
76# JModelica home
77JMODELICA_HOME =
78
79# SUNDIALS home
80SUNDIALS_HOME =
81
82# Additional library directories
83EXT_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.
92EXT_LIBS =
93EXTERNAL_LIBS = $(EXT_LIBS:%=-l%) -llapack -lblas -l:libgfortran.a -l:libquadmath.a
94
95# Additional include directories
96EXT_INC_DIRS =
97
98# Directory to place binary in
99BINARY_BASE_DIR = binaries
100BINARY_DIR = $(BINARY_BASE_DIR)/$(PLATFORM)
101# And with \ to make the cmd version of mkdir happy
102BINARY_MKDIR = $(BINARY_BASE_DIR)\$(PLATFORM)
103
104SHARED = $(BINARY_DIR)/$(FILE_NAME).dll
105
106EXECUTABLE = $(BINARY_BASE_DIR)/$(FILE_NAME).exe
107
108# Object files to be included in the shared library
109OBJS = $(patsubst sources/%.c, %.o, $(wildcard sources/*.c)) $(patsubst sources/%.cpp, %.o, $(wildcard sources/*.cpp))
110
111# C++ Compiler command
112CXX = g++
113
114# C Compiler command
115CC = gcc
116
117# ar command
118AR = ar
119
120# Command to remove temporary files
121RM = del
122
123# Extra compiler options
124EXT_OPTION =
125
126# C++ Compiler options
127CXXFLAGS = $(PLATFORM_FLAG) $(EXT_OPTION)
128
129# C Compiler options
130CFLAGS = $(PLATFORM_FLAG) $(EXT_OPTION) -std=c89 -pedantic -msse2 -mfpmath=sse
131
132SHARED_LDFLAGS = $(PLATFORM_FLAG) -shared
133
134# Directories with header files
135JMI_INC_DIR = ${JMODELICA_HOME}/include
136RUNTIMELIBRARY_INC_DIR = ${JMODELICA_HOME}/include/RuntimeLibrary
137STANDARD_HEADER_INC_DIR = ${JMODELICA_HOME}/ThirdParty/FMI/2.0
138SUNDIALS_INC_DIR = $(SUNDIALS_HOME)/include
139
140# Directories with libraries
141JMI_LIB_DIR = ${JMODELICA_HOME}/lib
142RUNTIMELIBRARY_LIB_DIR = ${JMODELICA_HOME}/lib/RuntimeLibrary
143RUNTIMELIBRARY_LIB_DIR64 = ${JMODELICA_HOME}/lib/RuntimeLibrary64
144MINPACK_LIB_DIR = ${JMODELICA_HOME}/ThirdParty/Minpack/lib
145MINPACK_LIB_DIR64 = ${JMODELICA_HOME}/ThirdParty/Minpack/lib64
146SUNDIALS_LIB_DIR = $(SUNDIALS_HOME)/lib
147SUNDIALS_LIB_DIR64 = $(SUNDIALS_HOME)/lib64
148WINPTHREADS_LIB_DIR = ${JMODELICA_HOME}/ThirdParty/winpthreads/lib/winpthreads
149WINPTHREADS_LIB_DIR64 = ${JMODELICA_HOME}/ThirdParty/winpthreads/lib/winpthreads64
150
151# Flags needed for specific libs
152LIB_MINPACK  = "-L$(MINPACK_LIB_DIR)" -l:libcminpack.a
153LIB_SUNDIALS = "-L$(SUNDIALS_LIB_DIR)" -l:libsundials_kinsol.a -l:libsundials_nvecserial.a -l:libsundials_cvode.a
154LIB_PTHREADS = "-L$(WINPTHREADS_LIB_DIR)" -l:libwinpthread.a
155
156# Libraries necessary to link with jmi
157LIBS_FMU_STD = -static-libstdc++ -static-libgcc -ljmi "-L$(JMI_LIB_DIR)" $(EXT_LIB_DIRS) $(EXTERNAL_LIBS) -lModelicaExternalC -lzlib -ljmi
158LIBS_FMU_ALL = $(LIBS_FMU_STD) $(LIB_SUNDIALS) $(LIB_MINPACK) $(LIB_PTHREADS)
159LIBS_FMUME10 = -lfmi1_me           $(LIBS_FMU_ALL)
160LIBS_FMUCS10 = -lfmi1_cs -lfmi1_me $(LIBS_FMU_ALL)
161LIBS_FMU20   = -lfmi2              $(LIBS_FMU_ALL)
162LIBS_CEVAL = $(LIBS_FMU_STD)
163
164# Include paths for compilation
165INCL = "-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)
168MAKEFILE = $(lastword $(MAKEFILE_LIST))
169
170ceval:
171ifeq ($(PLATFORM),win32)
172        "$(MAKE)" -f "$(MAKEFILE)" EXT_OPTION=-mincoming-stack-boundary=2 ceval_
173else
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_
175endif
176
177ceval_: $(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
182fmume10:
183ifeq ($(PLATFORM),win32)
184        "$(MAKE)" -f "$(MAKEFILE)" EXT_OPTION=-mincoming-stack-boundary=2 fmume10_
185else
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_
187endif
188
189fmume10_: $(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
194fmucs10:
195ifeq ($(PLATFORM),win32)
196        "$(MAKE)" -f "$(MAKEFILE)" EXT_OPTION=-mincoming-stack-boundary=2 fmucs10_
197else
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_
199endif
200
201fmucs10_: $(OBJS)
202        mkdir "$(BINARY_MKDIR)"
203        "$(CXX)" $(SHARED_LDFLAGS) $(CXXFLAGS) -o "$(SHARED)" $(OBJS) "-L${RUNTIMELIBRARY_LIB_DIR}" $(LIBS_FMUCS10)
204        $(RM) $(OBJS)
205
206fmume20:
207ifeq ($(PLATFORM),win32)
208        "$(MAKE)" -f "$(MAKEFILE)" EXT_OPTION=-mincoming-stack-boundary=2 fmume20_
209else
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_
211endif
212
213fmume20_: $(OBJS)
214        mkdir $(BINARY_MKDIR)
215        "$(CXX)" $(SHARED_LDFLAGS) $(CXXFLAGS) -o "$(SHARED)" $(OBJS) "-L${RUNTIMELIBRARY_LIB_DIR}" $(LIBS_FMU20)
216        $(RM) $(OBJS)
217
218fmucs20:
219ifeq ($(PLATFORM),win32)
220        "$(MAKE)" -f "$(MAKEFILE)" EXT_OPTION=-mincoming-stack-boundary=2 fmucs20_
221else
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_
223endif
224
225fmucs20_: $(OBJS)
226        mkdir $(BINARY_MKDIR)
227        "$(CXX)" $(SHARED_LDFLAGS) $(CXXFLAGS) -o "$(SHARED)" $(OBJS) "-L${RUNTIMELIBRARY_LIB_DIR}" $(LIBS_FMU20)
228        $(RM) $(OBJS)
229
230fmumecs20:
231ifeq ($(PLATFORM),win32)
232        "$(MAKE)" -f "$(MAKEFILE)" EXT_OPTION=-mincoming-stack-boundary=2 fmucs20_
233else
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_
235endif
236
237fmumecs20_: $(OBJS)
238        mkdir $(BINARY_MKDIR)
239        "$(CXX)" $(SHARED_LDFLAGS) $(CXXFLAGS) -o "$(SHARED)" $(OBJS) "-L${RUNTIMELIBRARY_LIB_DIR}" $(LIBS_FMU20)
240        $(RM) $(OBJS)
241
242
243all: $(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"
255define cflagrule
256$(word 1,$(1)).o : CFLAGS = $(CFLAGS) $(wordlist 2,$(words $(1)),$(1))
257endef
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
263clean:
264        $(RM) $(SHARED) $(OBJS)
Note: See TracBrowser for help on using the repository browser.