Skip to content
This repository was archived by the owner on May 18, 2019. It is now read-only.

Commit 4a2a554

Browse files
sjoelundOpenModelica-Hudson
authored andcommitted
Use -Wl,-Bstatic for user libraries in FMUs
FMUs should be statically compiled. This enforces it, but might cause some FMUs to no longer compile if no static library is available or dependencies are missing in the Library annotation. Also added a new file Compiler/Util/Autoconf.mo which is generated by autoconf and contains constants previously in external C functions. Belonging to [master]: - #3015
1 parent c84e407 commit 4a2a554

File tree

15 files changed

+69
-15
lines changed

15 files changed

+69
-15
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,3 +164,5 @@ tags
164164

165165
*.plist
166166
*clang_output*
167+
168+
Compiler/Util/Autoconf.mo

Compiler/Script/CevalScript.mo

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ import SimCode;
6161

6262
// protected imports
6363
protected
64+
import Autoconf;
6465
import BaseHashSet;
6566
import CevalScriptBackend;
6667
import CevalFunction;
@@ -1711,7 +1712,7 @@ algorithm
17111712
gcc_res = 0 == System.systemCall(gcc + " --version", touch_file);
17121713
gccVersion = System.readFile(touch_file);
17131714
System.systemCall("rm -f " + touch_file, "");
1714-
confcmd = System.configureCommandLine();
1715+
confcmd = Autoconf.configureCommandLine;
17151716
vals = {Values.STRING(omhome),
17161717
Values.STRING(omlib),
17171718
Values.STRING(omcpath),

Compiler/Script/CevalScriptBackend.mo

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ import UnitAbsyn;
5151

5252
// protected imports
5353
protected
54+
import Autoconf;
5455
import BackendDump;
5556
import BackendDAECreate;
5657
import BackendDAEUtil;
@@ -3385,6 +3386,8 @@ algorithm
33853386
makefileStr := System.stringReplace(makefileStr, "@FMIPLATFORM@", System.modelicaPlatform());
33863387
makefileStr := System.stringReplace(makefileStr, "@CPPFLAGS@", includeDefaultFmi);
33873388
makefileStr := System.stringReplace(makefileStr, "@LIBTYPE_DYNAMIC@", "1");
3389+
makefileStr := System.stringReplace(makefileStr, "@BSTATIC@", Autoconf.bstatic);
3390+
makefileStr := System.stringReplace(makefileStr, "@BDYNAMIC@", Autoconf.bdynamic);
33883391
makefileStr := System.stringReplace(makefileStr, "\r\n", "\n");
33893392
System.writeFile(dir + "Makefile", makefileStr);
33903393
System.writeFile(dir + "config.log", "Using cached values for dynamic platform");
@@ -3404,6 +3407,8 @@ algorithm
34043407
makefileStr := System.stringReplace(makefileStr, "@FMIPLATFORM@", System.modelicaPlatform());
34053408
makefileStr := System.stringReplace(makefileStr, "@CPPFLAGS@", "-DOMC_MINIMAL_RUNTIME=1 -DCMINPACK_NO_DLL=1 " + includeDefaultFmi);
34063409
makefileStr := System.stringReplace(makefileStr, "@LIBTYPE_DYNAMIC@", "1");
3410+
makefileStr := System.stringReplace(makefileStr, "@BSTATIC@", Autoconf.bstatic);
3411+
makefileStr := System.stringReplace(makefileStr, "@BDYNAMIC@", Autoconf.bdynamic);
34073412
makefileStr := System.stringReplace(makefileStr, "\r\n", "\n");
34083413
System.writeFile(dir + "Makefile", makefileStr);
34093414
System.writeFile(dir + "config.log", "Using cached values for static platform");

Compiler/Template/CodegenFMU.tpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1163,7 +1163,7 @@ match platform
11631163
nozip: <%fileNamePrefix%>_functions.h <%fileNamePrefix%>_literals.h $(OFILES) $(RUNTIMEFILES)
11641164
<%\t%>mkdir -p ../binaries/$(FMIPLATFORM)
11651165
ifeq (@LIBTYPE_DYNAMIC@,1)
1166-
<%\t%>$(LD) -o <%modelNamePrefix%>$(DLLEXT) $(OFILES) $(RUNTIMEFILES) <%dirExtra%> <%libsPos1%> <%libsPos2%> $(LDFLAGS)
1166+
<%\t%>$(LD) -o <%modelNamePrefix%>$(DLLEXT) $(OFILES) $(RUNTIMEFILES) <%dirExtra%> <%libsPos1%> @BSTATIC@ <%libsPos2%> @BDYNAMIC@ $(LDFLAGS)
11671167
<%\t%>cp <%fileNamePrefix%>$(DLLEXT) <%fileNamePrefix%>_FMU.libs ../binaries/$(FMIPLATFORM)/
11681168
endif
11691169
<%\t%>head -n20 Makefile > ../resources/$(FMIPLATFORM).summary

Compiler/Util/Autoconf.mo.in

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
encapsulated package Autoconf
2+
3+
constant Boolean haveBStatic = @BSTATIC@;
4+
constant String bstatic = if haveBStatic then "-Wl,-Bstatic" else "";
5+
constant String bdynamic = if haveBStatic then "-Wl,-Bdynamic" else "";
6+
constant String configureCommandLine = "Configured @date@ using arguments: @CONFIGURE_ARGS@";
7+
8+
annotation(__OpenModelica_Interface="util");
9+
end Autoconf;
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
encapsulated package Autoconf
2+
3+
constant String bstatic = "-Wl,-Bstatic";
4+
constant String bdynamic = "-Wl,-Bdynamic";
5+
constant String configureCommandLine = "Manually created Makefiles for OMDev";
6+
7+
annotation(__OpenModelica_Interface="util");
8+
end Autoconf;

Compiler/Util/System.mo

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -779,14 +779,6 @@ public function getuid
779779
external "C" uid=System_getuid() annotation(Library = "omcruntime");
780780
end getuid;
781781

782-
public function configureCommandLine
783-
"Returns the date and command used to configure OpenModelica.
784-
On the platforms that don't configure options, like OMDev, the returned string
785-
is more generic and does not contain a date."
786-
output String cmdLine;
787-
external "C" cmdLine=System_configureCommandLine() annotation(Library = "omcruntime");
788-
end configureCommandLine;
789-
790782
public function realtimeTick
791783
"Tock returns the time since the last tock; undefined if tick was never called.
792784
The clock index is 0-31. The function fails if the number is out of range."

Compiler/boot/LoadCompilerSources.mos

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ if true then /* Suppress output */
133133

134134
// "Util";
135135
"../Util/Array.mo",
136+
"../Util/Autoconf.mo",
136137
"../Util/AvlSetCR.mo",
137138
"../Util/AvlSetPath.mo",
138139
"../Util/AvlSetString.mo",

Compiler/boot/Makefile.in

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,5 +43,8 @@ default: all
4343

4444
include Makefile.common
4545

46+
../Util/Autoconf.mo: ../Util/Autoconf.mo.in
47+
(cd "$(TOP_DIR)" && ./config.status)
48+
4649
Makefile: Makefile.in
4750
(cd @top_builddir@ && ./config.status)

Compiler/boot/Makefile.omdev.mingw

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,7 @@ LDFLAGS_SHARED_MAIN=-L"$(OMHOME)/$(LIB_OMC)" $(EXTRA_LD_FLAGS)
5252

5353
default: all
5454

55+
../Util/Autoconf.mo: ../Util/Autoconf.mo.omdev.mingw
56+
cp -p "$<" "$@"
57+
5558
include Makefile.common

0 commit comments

Comments
 (0)