-
Notifications
You must be signed in to change notification settings - Fork 297
/
Makefile.common
216 lines (176 loc) · 9.65 KB
/
Makefile.common
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
ifeq ($(wildcard $(OMC))$(WSL_OMC),)
all:
$(MAKE) -f $(defaultMakefileTarget) bootstrap-from-tarball
else
all: runtime-depends
$(MAKE) -f $(defaultMakefileTarget) --no-print-directory generate-files-in-steps
$(MAKE) -f $(defaultMakefileTarget) --no-print-directory install INCLUDESOURCES=1
endif
generate-files-in-steps:
$(MAKE) -f $(defaultMakefileTarget) templates scripting
$(MAKE) -f $(defaultMakefileTarget) Makefile.sources
$(MAKE) -f $(defaultMakefileTarget) interfaces INCLUDESOURCES=1
$(MAKE) -f $(defaultMakefileTarget) Makefile.depends INCLUDESOURCES=1
$(MAKE) -f $(defaultMakefileTarget) generate-files INCLUDESOURCES=1 INCLUDEDEPENDS=1
.PHONY: interfaces generate-files runtime-depends parser compilerruntime patch-files bootstrap-from-tarball bootstrap-from-tarball2
GEN_DIR=build/
PATCH_SOURCES=true
PATCHES := $(patsubst %.patch.xz,%.patch,$(wildcard patches/*.patch.xz))
detected_OS ?= $(shell uname -s)
# Darwin doesn't like our static libffi, use the system one
# we get dyld: Symbol not found: _ffi_type_double, basically
# no ffi symbols are put in libOpenModelicaCompiler.dylib
ifeq ($(detected_OS),Darwin)
LIBFFI=-lffi
else # sane systems
LIBFFI=$(TOP_DIR)/3rdParty/libffi/install/lib*/libffi.a
endif
LIBOMCBACKENDRUNTIMEAR=$(TOP_DIR)/Compiler/runtime/libomcbackendruntime.a
ifeq ($(BOOTSTRAP_STAGE_1),1)
OMCRUNTIMEAR=$(OMCRUNTIMEAR1)
OMPARSEAR=../../Parser/libomparse-boot.a
LOMPARSE=$(OMPARSEAR)
LCOMPILERRUNTIME= $(LIBOMCBACKENDRUNTIMEAR) $(abspath $(OMCRUNTIMEAR)) $(LIBFFI) $(RPATH_BOOT_STAGE_1)
FMILIB_OR_BOOT=
else
OMCRUNTIMEAR=$(OMCRUNTIMEAR2)
OMPARSEAR=$(OMHOME)/$(LIB_OMC)/libomparse.a
LOMPARSE=-lomparse
LCOMPILERRUNTIME=$(LIBOMCBACKENDRUNTIMEAR) -lomcruntime $(LIBFFI)
FMILIB_OR_BOOT=$(FMILIB) -lexpat
endif
%.patch: %.patch.xz
xz --keep --decompress --force $<
patch-files: $(PATCHES)
bootstrap-from-tarball:
OPENMODELICAHOME="$(OMBUILDDIR)" $(MAKE) -f $(defaultMakefileTarget) bootstrap-from-tarball2
bootstrap-from-tarball2:
$(MAKE) -f $(defaultMakefileTarget) clean OMC=.omc
rm -rf $(GEN_DIR)
mkdir -p $(GEN_DIR)
cp -r bootstrap-sources/* .
# Patch _main.c to avoid a new tarball
#$(MAKE) -f $(defaultMakefileTarget) patch-files
#$(PATCH_SOURCES)
# We have not compiled OpenModelicaScriptingAPI.mo yet
touch build/OpenModelicaScriptingAPI.h
$(MAKE) -f $(defaultMakefileTarget) install INCLUDESOURCES=1 OMC=.omc BOOTSTRAP_STAGE_1=1 CPPFLAGS="$(CPPFLAGS) -DOMC_BOOTSTRAPPING_STAGE_1"
@echo "Bootstrapping phase 1/3 completed"
$(MAKE) -f $(defaultMakefileTarget) --no-print-directory clean OMC="$(BOOTSTRAP_OMC)"
$(MAKE) -f $(defaultMakefileTarget) --no-print-directory runtime-depends OMBUILDDIR=$(OMBUILDDIR) OMC="$(BOOTSTRAP_OMC)"
OPENMODELICA_BACKEND_STUBS=1 $(MAKE) -f $(defaultMakefileTarget) generate-files-in-steps OMC="$(BOOTSTRAP_OMC)" OMC_EXTRA_FLAGS= TEMPLATES_TARGET=templates-bootstrap
cp bootstrap-sources/build/_main.c build/
# We have not compiled OpenModelicaScriptingAPI.mo yet
touch build/OpenModelicaScriptingAPI.h
$(MAKE) -f $(defaultMakefileTarget) install INCLUDESOURCES=1 OMC="$(BOOTSTRAP_OMC)" CPPFLAGS="$(CPPFLAGS) -DOMC_BOOTSTRAPPING_STAGE_2"
@echo "Bootstrapping phase 2/3 completed"
$(MAKE) -f $(defaultMakefileTarget) clean OMC="$(BOOTSTRAP_OMC)"
$(MAKE) -f $(defaultMakefileTarget) --no-print-directory -C $(TOP_DIR)/Compiler/Template OMC="$(BOOTSTRAP_OMC)" clean
$(MAKE) -f $(defaultMakefileTarget) --no-print-directory -C $(TOP_DIR)/Compiler/Script OMC="$(BOOTSTRAP_OMC)" clean
$(MAKE) -f $(defaultMakefileTarget) generate-files-in-steps OMC="$(BOOTSTRAP_OMC)" "OMC_EXTRA_FLAGS=$(OMC_EXTRA_FLAGS)"
$(MAKE) -f $(defaultMakefileTarget) install INCLUDESOURCES=1 OMC="$(BOOTSTRAP_OMC)" CPPFLAGS="$(CPPFLAGS)"
@echo "Bootstrapping phase 3/3 completed"
runtime-depends:
@# NOTE: OpenModelicaBootstrappingHeader.h has to be regenerated without any other process writing to so/etc or you get bus errors
$(MAKE) -f $(defaultMakefileTarget) -C .. OpenModelicaBootstrappingHeader.h OMBUILDDIR=$(OMBUILDDIR) OMC="$(OMC)"
$(MAKE) -f $(defaultMakefileTarget) parser compilerruntime
parser:
$(MAKE) -f $(defaultMakefileTarget) -C ../../Parser install OMBUILDDIR=$(OMBUILDDIR) OM_ENABLE_ENCRYPTION=$(OM_ENABLE_ENCRYPTION)
compilerruntime:
$(MAKE) -f $(defaultMakefileTarget) -C ../runtime install OMBUILDDIR=$(OMBUILDDIR)
bootstrap-from-compiled: make-separate
make-bootstrap-tarball: clean
test `uname` = "Linux" # Linux produces more compact sources since Windows disables some features of the MetaModelica compilation stages
test ! -f Makefile.sources || rm Makefile.sources
test ! -f Makefile.depends || rm Makefile.depends
OPENMODELICA_BACKEND_STUBS=1 $(MAKE) -f $(defaultMakefileTarget) generate-files-in-steps
rm -rf $(GEN_DIR)/*.mo $(GEN_DIR)/tmp $(GEN_DIR)/*.deps $(GEN_DIR)/*.mos $(GEN_DIR)/*.stamp
sed -i.bak -e "s/^ *//" -e "/^[/][/]/d" -e "/^#line /d" -e "s/ *[/][*].*[*][/]\([;)]\?\) *$$/\1/" -e "s/^ *[/][*].*[*][/]\(;\?\) */\1/" -e "/^ *$$/d" $(GEN_DIR)/*.c $(GEN_DIR)/*.h
rm -f $(GEN_DIR)/*.bak
rm -rf bootstrap-sources patches/ bootstrap-sources.tar
mkdir -p bootstrap-sources
mv $(GEN_DIR) Makefile.sources bootstrap-sources/
git add bootstrap-sources/
templates:
$(MAKE) -f $(defaultMakefileTarget) --no-print-directory -C $(TOP_DIR)/Compiler/Template OMBUILDDIR=$(OMBUILDDIR) $(TEMPLATES_TARGET)
scripting:
$(MAKE) -f $(defaultMakefileTarget) --no-print-directory -C $(TOP_DIR)/Compiler/Script OMBUILDDIR=$(OMBUILDDIR)
clean:
rm -rf "$(GEN_DIR)"
rm -f Makefile.sources LoadCompilerInterface.mos Makefile.depends
rm -f patches/*.patch
ifeq ($(INCLUDESOURCES),1)
include Makefile.sources
endif
ifeq ($(INCLUDEDEPENDS),1)
include Makefile.depends
endif
generate-files: $(ALL_INTERFACES:%.stamp.mo=%.stamp) $(GEN_DIR)_main.c
@test ! -z "$^" || (echo "*** Empty dependencies for $@"; false)
ALL_OBJECTS=$(ALL_INTERFACES:%.stamp.mo=%.o) $(ALL_INTERFACES:%.stamp.mo=%_records.o)
compile-files: $(ALL_OBJECTS) $(GEN_DIR)_main.o
@test ! -z "$^" || (echo "*** Empty dependencies for $@"; false)
interfaces: $(ALL_INTERFACES) $(ALL_SOURCES)
%.stamp.mo:
@mkdir -p build
@echo 'echo(false);inFile := "$<";outFile := "$@.tmp"; className := $$TypeName($(@:$(GEN_DIR)%.stamp.mo=%)); runScript("GenerateInterface.mos"); print(getErrorString()); print("Something went horribly wrong for $@\\n"); exit(1);' > "$@.mos"
$(OMC) -g=MetaModelica -n=1 $@.mos
@touch $@
%.interface.mo: %.stamp.mo
ifeq ($(wildcard $(OMC))$(WSL_OMC),)
else
Makefile.sources: LoadCompilerSources.mos MakeSources.mos ../Util/Autoconf.mo
$(OMC) -g=MetaModelica -n=1 MakeSources.mos
mv Makefile.sources.tmp Makefile.sources
mv LoadCompilerInterface.mos.tmp LoadCompilerInterface.mos
LoadCompilerInterface.mos: Makefile.sources
@test -f $@ || (rm -f $< && $(MAKE) -f $(defaultMakefileTarget) $<)
Makefile.depends: MakeDepends.mos LoadCompilerInterface.mos Makefile.sources $(ALL_INTERFACES:%.stamp.mo=%.interface.mo) ../Util/Autoconf.mo
@rm -f $@
$(OMC) -g=MetaModelica -n=1 $<
endif
$(GEN_DIR)%.stamp:
@test ! -z "$^" || (echo Empty dependencies for $@ ; false)
@echo 'echo(false);files:={"'`echo $^ | sed 's/ /","/g'`'"};mainClass:=$$TypeName('`basename $@ | sed "s/[.]stamp//"`');runScript("CompileFile.mos");print("Something went horribly wrong for '$@'\\n");exit(1);' > $@.mos
$(OMC) -g=MetaModelica -n=1 $(OMC_EXTRA_FLAGS) $@.mos
@touch $@
$(GEN_DIR)_main.c:
$(OMC) -g=MetaModelica GenerateEntryPoint.mos
$(GEN_DIR)_main.o: $(GEN_DIR)_main.c
$(CC) -DOMC_ENTRYPOINT_STATIC= -c $(GEN_DIR)_main.c -o $(GEN_DIR)_main.o $(CFLAGS) $(CPPFLAGS)
$(GEN_DIR)_main_omc.c: $(GEN_DIR)_main.c
cp -a $^ $@
$(GEN_DIR)_main_static_omc.c: $(GEN_DIR)_main.c
sed -e s/DLLImport// -e s/DLLExport// $^ > $@.tmp
mv $@.tmp $@
$(GEN_DIR)_main_static.c: $(GEN_DIR)_main_static_omc.c
cp -a $^ $@
$(GEN_DIR)_main_omc.o: $(GEN_DIR)_main_omc.c
$(CC) -c $(GEN_DIR)_main_omc.c -o $(GEN_DIR)_main_omc.o $(CFLAGS) $(CPPFLAGS)
$(GEN_DIR)_main_static_omc.o: $(GEN_DIR)_main_static_omc.c
$(CC) -c $(GEN_DIR)_main_static_omc.c -o $(GEN_DIR)_main_static_omc.o $(CFLAGS) $(CPPFLAGS)
$(GEN_DIR)_main_static.o: $(GEN_DIR)_main_static.c
$(CC) -DOMC_ENTRYPOINT_STATIC -c $(GEN_DIR)_main_static.c -o $(GEN_DIR)_main_static.o $(CFLAGS) $(CPPFLAGS)
$(OMHOME)/$(LIB_OMC)/libOpenModelicaCompiler$(SHREXT): $(ALL_OBJECTS) $(OMCRUNTIMEAR) $(OMPARSEAR) $(GEN_DIR)_main_omc.o
@test ! -z "`echo $(ALL_OBJECTS)`" || (echo Empty dependencies for $@ ; false)
$(CC) -shared $(RPATH) $(INSTALL_NAME) -o $@ $(ALL_OBJECTS) $(GEN_DIR)_main_omc.o $(LDFLAGS)
test ! "$(SHREXT)" = ".dylib" || install_name_tool -id @rpath/libOpenModelicaCompiler.dylib $@
test ! "$(SHREXT)" = ".dylib" || install_name_tool -change libcolamd.dylib @rpath/libcolamd.dylib $@
test ! "$(SHREXT)" = ".dylib" || install_name_tool -change libsuitesparseconfig.dylib @rpath/libsuitesparseconfig.dylib $@
ifeq (${STATIC},)
#shared
$(GEN_DIR)omc$(EXE_SUFFIX)$(EXE_EXT): $(OMHOME)/$(LIB_OMC)/libOpenModelicaCompiler$(SHREXT) $(GEN_DIR)_main_omc.o $(GEN_DIR)_main.o
$(CC) $(GEN_DIR)_main.o $(RPATH) $(CFLAGS) $(CPPFLAGS) -o $@ $(LDFLAGS_SHARED_MAIN) -lOpenModelicaCompiler
install: $(GEN_DIR)omc$(EXE_SUFFIX)$(EXE_EXT) install-interface
cp -a $< $(OMHOME)/bin/
test ! "$(SHREXT)" = ".dll" || cp -a $(OMHOME)/$(LIB_OMC)/libOpenModelicaCompiler$(SHREXT) $(OMHOME)/bin/
else
#static
$(GEN_DIR)omc$(EXE_SUFFIX)$(EXE_EXT): $(ALL_OBJECTS) $(GEN_DIR)_main_static.o $(GEN_DIR)_main_static_omc.o $(OMCRUNTIMEAR) $(OMPARSEAR)
@test ! -z "`echo $(ALL_OBJECTS)`" || (echo Empty dependencies for $@ ; false)
$(CC) $(GEN_DIR)_main_static.o $(RPATH) $(CFLAGS) $(CPPFLAGS) -o $@ $(GEN_DIR)_main_static_omc.o $(ALL_OBJECTS) $(LDFLAGS)
install: $(GEN_DIR)omc$(EXE_SUFFIX)$(EXE_EXT) install-interface
cp -a $< $(OMHOME)/bin/
endif
install-interface:
cp -a $(GEN_DIR)OpenModelicaScriptingAPI.h $(OMHOME)/include/omc/scripting-API