/
Makefile.common
201 lines (164 loc) · 8.56 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
ifeq ($(OS),Windows_NT)
SED = sed
else
UNAME := $(shell uname)
ifeq ($(UNAME),Darwin)
SED = gsed
else
SED = sed
endif
endif
ifeq ($(wildcard $(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
GEN_DIR=build/
PATCH_SOURCES=$(SED) -i 's/ = omc_assert_function/__attribute__((noreturn)) = omc_assert_function/' build/_main.c
PATCHES := $(patsubst %.patch.xz,%.patch,$(wildcard patches/*.patch.xz))
ifeq ($(BOOTSTRAP_STAGE_1),1)
OMCRUNTIMEAR=../runtime/libomcruntime-boot$(SHREXT)
OMPARSEAR=../../Parser/libomparse-boot.a
LOMPARSE=$(OMPARSEAR)
LCOMPILERRUNTIME=$(abspath $(OMCRUNTIMEAR))
else
OMCRUNTIMEAR=$(OMHOME)/$(LIB_OMC)/libomcruntime$(SHREXT)
OMPARSEAR=$(OMHOME)/$(LIB_OMC)/libomparse.a
LOMPARSE=-lomparse
LCOMPILERRUNTIME=-lomcruntime
endif
%.patch: %.patch.xz
xz --keep --decompress --force $<
bootstrap-from-tarball: $(PATCHES)
$(MAKE) -f $(defaultMakefileTarget) clean OMC=.omc
tar xJf bootstrap-sources.tar.xz
# Patch _main.c to avoid a new tarball
$(PATCH_SOURCES)
# cd build && for x in ../patches/*.patch; do patch -i "$$x" "`basename $$x | $(SED) 's/\([.][0-9]*\)\?[.]patch/.c/'`" || exit 1; done
# 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=
# Patch _main.c to avoid a new tarball
$(PATCH_SOURCES)
echo '#include "Patternm.h"' >> build/SimCodeFunctionUtil_includes.h
# We have not compiled OpenModelicaScriptingAPI.mo yet
touch build/OpenModelicaScriptingAPI.h
$(MAKE) -f $(defaultMakefileTarget) install INCLUDESOURCES=1 OMC="$(BOOTSTRAP_OMC)"
@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) -DOMC_BOOTSTRAPPING_STAGE_1"
@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)
compilerruntime:
$(MAKE) -f $(defaultMakefileTarget) -C ../runtime install OMBUILDDIR=$(OMBUILDDIR)
bootstrap-from-compiled: make-separate
make-bootstrap-tarball: clean
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 -e "s/^ *//" -e "/^[/][/]/d" -e "/^#line /d" -e "s/ *[/][*].*[*][/]\([;)]\?\) *$$/\1/" -e "s/^ *[/][*].*[*][/]\(;\?\) */\1/" -e "/^ *$$/d" $(GEN_DIR)/*.c $(GEN_DIR)/*.h
tar cf bootstrap-sources.tar $(GEN_DIR) Makefile.sources
xz --best --force bootstrap-sources.tar
templates:
$(MAKE) -f $(defaultMakefileTarget) --no-print-directory -C $(TOP_DIR)/Compiler/Template
scripting:
$(MAKE) -f $(defaultMakefileTarget) --no-print-directory -C $(TOP_DIR)/Compiler/Script
clean:
rm -rf $(GEN_DIR)
rm -f Makefile.sources LoadCompilerInterface.mos Makefile.depends
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) -n=1 $@.mos
@touch $@
%.interface.mo: %.stamp.mo
ifeq ($(wildcard $(OMC)),)
else
Makefile.sources: LoadCompilerSources.mos MakeSources.mos
$(OMC) -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)
@rm -f $@
$(OMC) -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) -n=1 $(OMC_EXTRA_FLAGS) $@.mos
@touch $@
$(GEN_DIR)_main.c:
$(OMC) 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 $@
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