source: trunk/RuntimeLibrary/Makefiles/Makefile.macosx @ 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
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 in a Mac OSX shell.
21#
22# Usage:
23#   This makefile is intended to be used by the code generated by the
24#   JModelica compilers. The following arguments are supported:
25#   
26#   FILE_NAME             (mandatory) The name of the C file.
27#   PLATFORM              (mandatory) The platform we are compiling for,
28#                         currently only used to decide where to place binary.
29#                         Should be darwin32 or darwin64.
30#   JMODELICA_HOME        (mandatory) The directory where JModelica has been built,
31#                         or equivalently, the directory of a binary JModelica
32#                         distribution.
33#   SUNDIALS_HOME         (mandatory) The directory of Sundials.
34#   EXT_LIB_DIRS          List of external library directories.
35#   EXT_LIBS              List of external libraries.
36#   EXT_INC_DIRS          List of external include directories.
37#   EXTRA_CFLAGS          Extra CFLAGS for specific files
38#                         Format is (with e1.c and e2.c) "e1:O2:pedantic e2:O1"
39#           
40# The following targets are supported:
41#    fmume10      Build a shared object file containing the generated code and the
42#                 Model Exchange for API FMI 1.0.
43#    fmucs10      Build a shared object file containing the generated code and the
44#                 co-simulation API for FMI 1.0.
45#    fmume20      Build a shared object file containing the generated code and the
46#                 Model Exchange for API FMI 2.0.
47#    fmucs20      Build a shared object file containing the generated code and the
48#                 co-simulation API for FMI 2.0.
49#    fmumecs20    Build a shared object file containing the generated code and the
50#                 Model Exchange API and co-simulation API for FMI 2.0.
51#
52# Example:
53#  make -f Makefile.macosx darwin32 \
54#    FILE_NAME=CCodeGenTests.CCodeGenTest1 \
55#    JMODELICA_HOME=/Users/jakesson/projects/JModelica/build \
56#
57
58# Name of shared library
59FILE_NAME =
60
61# Extra CFLAGS for specific source files.
62EXTRA_CFLAGS =
63
64# Platform name - controls what sub-directory the binary is placed in
65PLATFORM =
66
67# JModelica home
68JMODELICA_HOME =
69
70# SUNDIALS home
71SUNDIALS_HOME =
72
73# Additional library directories
74EXT_LIB_DIRS =
75
76# Additional libraries
77EXT_LIBS =
78EXTERNAL_LIBS = $(EXT_LIBS:%=-l%) -llapack -lblas -lgfortran
79
80# Additional include directories
81EXT_INC_DIRS =
82
83# Directory to place binary in
84BINARY_BASE_DIR = binaries
85BINARY_DIR = $(BINARY_BASE_DIR)/$(PLATFORM)
86
87SHARED = $(BINARY_DIR)/$(FILE_NAME).dylib
88
89EXECUTABLE = $(BINARY_BASE_DIR)/$(FILE_NAME)
90
91# Object files to be included in the shared library
92OBJS = $(patsubst sources/%.c, %.o, $(wildcard sources/*.c)) $(patsubst sources/%.cpp, %.o, $(wildcard sources/*.cpp))
93
94# C++ Compiler command
95CXX = g++
96
97# C Compiler command
98CC = gcc
99
100# C Compiler options
101CFLAGS = -std=c89 -pedantic -fPIC -msse2 -mfpmath=sse
102
103SHARED_LDFLAGS = -dynamiclib -Wl,-rpath,@loader_path/ -pthread
104
105# Directories with header files
106JMI_INC_DIR = ${JMODELICA_HOME}/include
107RUNTIMELIBRARY_INC_DIR = ${JMODELICA_HOME}/include/RuntimeLibrary
108STANDARD_HEADER_INC_DIR = ${JMODELICA_HOME}/ThirdParty/FMI/2.0
109SUNDIALS_INC_DIR = $(SUNDIALS_HOME)/include
110
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 "-L$(JMI_LIB_DIR)" $(EXT_LIB_DIRS) $(EXTERNAL_LIBS) -lModelicaExternalC -lzlib -static-libstdc++ -ljmi
119LIB_SUNDIALS = -L$(SUNDIALS_LIB_DIR) $(SUNDIALS_HOME)/lib/libsundials_kinsol.a $(SUNDIALS_HOME)/lib/libsundials_nvecserial.a
120LIB_MINPACK  = -L$(MINPACK_LIB_DIR) ${JMODELICA_HOME}/ThirdParty/Minpack/lib/libcminpack.a
121LIB_COMMON   = $(LIB_SUNDIALS) $(LIB_MINPACK)
122
123# For different targets
124LIBS_FMUME10 = -lfmi1_me $(LIBS_FMU_STD) $(LIB_COMMON)
125LIBS_FMUCS10 = -lfmi1_cs -lfmi1_me $(LIBS_FMU_STD) $(LIB_COMMON) $(SUNDIALS_HOME)/lib/libsundials_cvode.a
126LIBS_FMU20   = -lfmi2 $(LIBS_FMU_STD) $(LIB_COMMON) $(SUNDIALS_HOME)/lib/libsundials_cvode.a
127LIBS_CEVAL   = $(LIBS_FMU_STD)
128
129# Include paths for compilation
130INCL = -I$(RUNTIMELIBRARY_INC_DIR) -I$(STANDARD_HEADER_INC_DIR) $(EXT_INC_DIRS) -I$(SUNDIALS_INC_DIR)
131
132# set variable to correct makefile (for recursive call in fmume/fmucs)
133MAKEFILE = $(lastword $(MAKEFILE_LIST))
134
135ceval:
136        $(MAKE) -f $(MAKEFILE) ceval_
137
138ceval_: $(OBJS)
139        mkdir -p $(BINARY_BASE_DIR)
140        $(CC) $(CFLAGS) -o $(EXECUTABLE) $(OBJS) -L${RUNTIMELIBRARY_LIB_DIR} $(LIBS_CEVAL)
141        $(RM) $(OBJS)
142
143fmume10:
144        $(MAKE) -f $(MAKEFILE) fmume10_
145
146fmume10_: $(OBJS)
147        mkdir -p $(BINARY_DIR)
148        $(CXX) $(SHARED_LDFLAGS) $(CFLAGS) -o $(SHARED) $(OBJS) -L$(RUNTIMELIBRARY_LIB_DIR) $(LIBS_FMUME10)
149        $(RM) $(OBJS)
150
151fmucs10:
152        $(MAKE) -f $(MAKEFILE) fmucs10_
153
154fmucs10_: $(OBJS)
155        mkdir -p $(BINARY_DIR)
156        $(CC) $(SHARED_LDFLAGS) $(CFLAGS) -o $(SHARED) $(OBJS) -L$(RUNTIMELIBRARY_LIB_DIR) $(LIBS_FMUCS10)
157        $(RM) $(OBJS)
158
159fmume20:
160        $(MAKE) -f $(MAKEFILE) fmume20_
161
162fmume20_: $(OBJS)
163        mkdir -p $(BINARY_DIR)
164        $(CXX) $(SHARED_LDFLAGS) $(CFLAGS) -o $(SHARED) $(OBJS) -L${RUNTIMELIBRARY_LIB_DIR} $(LIBS_FMU20)
165        $(RM) $(OBJS)
166       
167fmucs20:
168        $(MAKE) -f $(MAKEFILE) fmucs20_
169       
170fmucs20_: $(OBJS)
171        mkdir -p $(BINARY_DIR)
172        $(CC) $(SHARED_LDFLAGS) $(CFLAGS) -o $(SHARED) $(OBJS) -L${RUNTIMELIBRARY_LIB_DIR} $(LIBS_FMU20)
173        $(RM) $(OBJS)
174       
175fmumecs20:
176        $(MAKE) -f $(MAKEFILE) fmucs20_
177       
178fmumecs20_: $(OBJS)
179        mkdir -p $(BINARY_DIR)
180        $(CC) $(SHARED_LDFLAGS) $(CFLAGS) -o $(SHARED) $(OBJS) -L${RUNTIMELIBRARY_LIB_DIR} $(LIBS_FMU20)
181        $(RM) $(OBJS)
182
183
184%.o: sources/%.c
185        $(CC) $(CFLAGS) $(INCL) -c -o $@ $<
186
187# Create a rule which uses the first item in arg as src name and
188# following items as additional CFLAGS. Argument "file:-O2:-d"
189# will expand to the rule "file.o : CFLAGS = $(CFLAGS) -O2 -d"
190define cflagrule
191$(word 1,$(1)).o : CFLAGS = $(CFLAGS) $(wordlist 2,$(words $(1)),$(1))
192endef
193
194# For each word in variable EXTRA_CFLAGS, create a cflagrule
195# Example "main2 main3:O3 main:O2:pedantic"
196$(foreach src, $(EXTRA_CFLAGS),$(eval $(call cflagrule, $(subst :, -,$(src)))))
197
198clean:
199        $(RM) $(SHARED) $(OBJS)
Note: See TracBrowser for help on using the repository browser.