source: trunk/RuntimeLibrary/Makefiles/Makefile.linux @ 13703

Last change on this file since 13703 was 13703, checked in by Christian Andersson, 2 months ago

Reverted changeset:13700. Related to ticket:5837

File size: 6.9 KB
Line 
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
58FILE_NAME =
59
60# Extra CFLAGS for specific source files.
61EXTRA_CFLAGS =
62
63# Platform name - controls what sub-directory the binary is placed in
64PLATFORM =
65
66# JModelica home
67JMODELICA_HOME =
68
69# SUNDIALS home
70SUNDIALS_HOME =
71
72# Additional library directories
73EXT_LIB_DIRS =
74
75# Additional libraries
76EXT_LIBS =
77EXTERNAL_LIBS = $(EXT_LIBS:%=-l%) -llapack -lblas -lgfortran
78
79# Additional include directories
80EXT_INC_DIRS =
81
82# Directory to place binary in
83BINARY_BASE_DIR = binaries
84BINARY_DIR = $(BINARY_BASE_DIR)/$(PLATFORM)
85
86SHARED = $(BINARY_DIR)/$(FILE_NAME).so
87EXECUTABLE = $(BINARY_BASE_DIR)/$(FILE_NAME)
88
89# Object files to be included in the shared library
90OBJS = $(patsubst sources/%.c, %.o, $(wildcard sources/*.c)) $(patsubst sources/%.cpp, %.o, $(wildcard sources/*.cpp))
91
92# C++ Compiler command
93CXX = g++
94
95# C Compiler command
96CC = gcc
97
98
99# C Compiler options
100CFLAGS = -std=c89 -pedantic -fPIC -msse2 -mfpmath=sse
101
102SHARED_LDFLAGS = -shared -Wl,-rpath,'$$ORIGIN',--no-undefined -pthread
103
104# Directories with header files
105JMI_INC_DIR = ${JMODELICA_HOME}/include
106RUNTIMELIBRARY_INC_DIR = ${JMODELICA_HOME}/include/RuntimeLibrary
107STANDARD_HEADER_INC_DIR = ${JMODELICA_HOME}/ThirdParty/FMI/2.0
108SUNDIALS_INC_DIR = $(SUNDIALS_HOME)/include
109
110# Directories with libraries
111JMI_LIB_DIR = ${JMODELICA_HOME}/lib
112RUNTIMELIBRARY_LIB_DIR = ${JMODELICA_HOME}/lib/RuntimeLibrary
113SUNDIALS_LIB_DIR = $(SUNDIALS_HOME)/lib
114MINPACK_LIB_DIR = ${JMODELICA_HOME}/ThirdParty/Minpack/lib
115
116# Libraries necessary to link with jmi
117# Reused parts
118LIBS_FMU_STD = -ljmi -ldl "-L$(JMI_LIB_DIR)" $(EXT_LIB_DIRS) $(EXTERNAL_LIBS) -lModelicaExternalC -lzlib -ljmi
119LIB_SUNDIALS = -L$(SUNDIALS_LIB_DIR) -l:libsundials_kinsol.a -l:libsundials_nvecserial.a
120LIB_MINPACK  = -L$(MINPACK_LIB_DIR) -l:libcminpack.a
121LIB_STD      = -lstdc++ -lm
122LIB_COMMON   = $(LIB_SUNDIALS) $(LIB_MINPACK) $(LIB_STD)
123
124# For different targets
125LIBS_FMUME10 = -lfmi1_me $(LIBS_FMU_STD) $(LIB_COMMON)
126LIBS_FMUCS10 = -lfmi1_cs -lfmi1_me $(LIBS_FMU_STD) $(LIB_COMMON) -l:libsundials_cvode.a
127LIBS_FMU20   = -lfmi2 $(LIBS_FMU_STD) $(LIB_COMMON) -l:libsundials_cvode.a
128LIBS_CEVAL   = $(LIBS_FMU_STD)
129
130# Include paths for compilation
131INCL = -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)
134MAKEFILE = $(lastword $(MAKEFILE_LIST))
135
136
137ceval:
138        $(MAKE) -f $(MAKEFILE) ceval_
139
140ceval_: $(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
146fmume10:
147        $(MAKE) -f $(MAKEFILE) fmume10_
148
149fmume10_: $(OBJS)
150        mkdir -p $(BINARY_DIR)
151        $(CXX) $(SHARED_LDFLAGS) $(CFLAGS) -o $(SHARED) $(OBJS) -L$(RUNTIMELIBRARY_LIB_DIR) $(LIBS_FMUME10)
152        $(RM) $(OBJS)
153
154fmucs10:
155        $(MAKE) -f $(MAKEFILE) fmucs10_
156
157fmucs10_: $(OBJS)
158        mkdir -p $(BINARY_DIR)
159        $(CXX) $(SHARED_LDFLAGS) $(CFLAGS) -o $(SHARED) $(OBJS) -L$(RUNTIMELIBRARY_LIB_DIR) $(LIBS_FMUCS10)
160        $(RM) $(OBJS)
161
162fmume20:
163        $(MAKE) -f $(MAKEFILE) fmume20_
164
165fmume20_: $(OBJS)
166        mkdir -p $(BINARY_DIR)
167        $(CXX) $(SHARED_LDFLAGS) $(CFLAGS) -o $(SHARED) $(OBJS) -L${RUNTIMELIBRARY_LIB_DIR} $(LIBS_FMU20)
168        $(RM) $(OBJS)
169       
170fmucs20:
171        $(MAKE) -f $(MAKEFILE) fmucs20_
172       
173fmucs20_: $(OBJS)
174        mkdir -p $(BINARY_DIR)
175        $(CXX) $(SHARED_LDFLAGS) $(CFLAGS) -o $(SHARED) $(OBJS) -L${RUNTIMELIBRARY_LIB_DIR} $(LIBS_FMU20)
176        $(RM) $(OBJS)
177       
178fmumecs20:
179        $(MAKE) -f $(MAKEFILE) fmucs20_
180       
181fmumecs20_: $(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"
195define cflagrule
196$(word 1,$(1)).o : CFLAGS = $(CFLAGS) $(wordlist 2,$(words $(1)),$(1))
197endef
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
203clean:
204        $(RM) $(SHARED) $(OBJS)
Note: See TracBrowser for help on using the repository browser.