Skip to content

Commit

Permalink
Use Autoconf.mo instead of external C functions
Browse files Browse the repository at this point in the history
This starts using Autoconf.mo for constants such as the dll extension.

Belonging to [master]:
  - OpenModelica/OMCompiler#3016
  - OpenModelica/OpenModelica-testsuite#1154
  • Loading branch information
sjoelund authored and OpenModelica-Hudson committed Mar 29, 2019
1 parent c97542d commit 5db7684
Show file tree
Hide file tree
Showing 17 changed files with 130 additions and 161 deletions.
3 changes: 2 additions & 1 deletion Compiler/BackEnd/OpenTURNS.mo
Expand Up @@ -46,6 +46,7 @@ import DAE;

protected
import Array;
import Autoconf;
import BackendDAEOptimize;
import BackendDAEUtil;
import BackendEquation;
Expand Down Expand Up @@ -221,7 +222,7 @@ algorithm
// varLst := listReverse(varLst);
inputs := stringDelimitList(generateXMLLibraryInputs(varLst),"\n");
outputs := stringDelimitList(generateXMLLibraryOutputs(varLst),"\n");
dllStr := " <path>" + className + cStrWrapperSuffix + System.getDllExt() + "</path>";
dllStr := " <path>" + className + cStrWrapperSuffix + Autoconf.dllExt + "</path>";
funcStr := " <function provided=\"yes\">" + className + cStrWrapperSuffix + "</function>";

content :=stringDelimitList({
Expand Down
7 changes: 4 additions & 3 deletions Compiler/Main/Main.mo
Expand Up @@ -42,6 +42,7 @@ encapsulated package Main

protected
import Absyn;
import Autoconf;
import BackendDAE;
import BackendDAECreate;
import BackendDAEUtil;
Expand Down Expand Up @@ -764,9 +765,9 @@ algorithm
// 150M for Windows, 300M for others makes the GC try to unmap less and so it crashes less.
// Disabling unmap is another alternative that seems to work well (but could cause the memory consumption to not be released, and requires manually calling collect and unmap
if true then
GC.setForceUnmapOnGcollect(if System.os() == "Windows_NT" then true else false);
GC.setForceUnmapOnGcollect(if Autoconf.os == "Windows_NT" then true else false);
else
GC.expandHeap(if System.os() == "Windows_NT"
GC.expandHeap(if Autoconf.os == "Windows_NT"
then 1024*1024*150
else 1024*1024*300);
end if;
Expand Down Expand Up @@ -844,7 +845,7 @@ algorithm
// Setup mingw path only once
// adrpo: NEVER MOVE THIS CASE FROM HERE OR PUT ANY OTHER CASES BEFORE IT
// without asking Adrian.Pop@liu.se
if System.os() == "Windows_NT" then
if Autoconf.os == "Windows_NT" then
setWindowsPaths(Settings.getInstallationDirectoryPath());
end if;

Expand Down
14 changes: 7 additions & 7 deletions Compiler/Script/CevalScript.mo
Expand Up @@ -224,11 +224,11 @@ protected
String omhome = Settings.getInstallationDirectoryPath(),omhome_1 = System.stringReplace(omhome, "\"", "");
String pd = System.pathDelimiter();
String cdWorkingDir,setMakeVars,libsfilename,libs_str,s_call,filename,winCompileMode,workDir = (if stringEq(workingDir, "") then "" else workingDir + pd);
String fileDLL = workDir + fileprefix + System.getDllExt(),
fileEXE = workDir + fileprefix + System.getExeExt(),
String fileDLL = workDir + fileprefix + Autoconf.dllExt,
fileEXE = workDir + fileprefix + Autoconf.exeExt,
fileLOG = workDir + fileprefix + ".log";
Integer numParallel,res;
Boolean isWindows = System.os() == "Windows_NT";
Boolean isWindows = Autoconf.os == "Windows_NT";
list<String> makeVarsNoBinding;
algorithm
libsfilename := fileprefix + ".libs";
Expand All @@ -252,7 +252,7 @@ algorithm
numParallel := if Config.getRunningTestsuite() then 1 else Config.noProc();
cdWorkingDir := if stringEmpty(workingDir) then "" else (" -C \"" + workingDir + "\"");
setMakeVars := sum(" "+var for var in makeVarsNoBinding);
s_call := stringAppendList({System.getMakeCommand()," -j",intString(numParallel),cdWorkingDir," -f ",fileprefix,".makefile",setMakeVars});
s_call := stringAppendList({Autoconf.make," -j",intString(numParallel),cdWorkingDir," -f ",fileprefix,".makefile",setMakeVars});
end if;
if Flags.isSet(Flags.DYN_LOAD) then
Debug.traceln("compileModel: running " + s_call);
Expand Down Expand Up @@ -1692,11 +1692,11 @@ algorithm
"CONFIGURE_CMDLINE"};
omhome = Settings.getInstallationDirectoryPath();
omlib = Settings.getModelicaPath(Config.getRunningTestsuite());
omcpath = omhome + "/bin/omc" + System.getExeExt();
omcpath = omhome + "/bin/omc" + Autoconf.exeExt;
systemPath = Util.makeValueOrDefault(System.readEnv,"PATH","");
omdev = Util.makeValueOrDefault(System.readEnv,"OMDEV","");
omcfound = System.regularFileExists(omcpath);
os = System.os();
os = Autoconf.os;
touch_file = "omc.checksettings.create_file_test";
usercflags = Util.makeValueOrDefault(System.readEnv,"MODELICAUSERCFLAGS","");
workdir = System.pwd();
Expand All @@ -1705,7 +1705,7 @@ algorithm
uname = System.readFile(touch_file);
rm_res = 0 == System.systemCall("rm " + touch_file, "");
// _ = System.platform();
senddata = System.getRTLibs();
senddata = Autoconf.ldflags_runtime;
gcc = System.getCCompiler();
have_corba = Corba.haveCorba();
System.systemCall("rm -f " + touch_file, "");
Expand Down
24 changes: 12 additions & 12 deletions Compiler/Script/CevalScriptBackend.mo
Expand Up @@ -1608,7 +1608,7 @@ algorithm
(b,cache,compileDir,executable,_,outputFormat_str,_,simflags,resultValues,vals) = buildModel(cache,env,vals,msg);
if b then
Values.REAL(linearizeTime) = getListNthShowError(vals,"try to get stop time",0,2);
executableSuffixedExe = stringAppend(executable, System.getExeExt());
executableSuffixedExe = stringAppend(executable, Autoconf.exeExt);
logFile = stringAppend(executable,".log");
if System.regularFileExists(logFile) then
0 = System.removeFile(logFile);
Expand Down Expand Up @@ -2412,7 +2412,7 @@ algorithm
pd = System.pathDelimiter();
// create absolute path of simulation result file
str1 = System.pwd() + pd + filename;
s1 = if System.os() == "Windows_NT" then ".exe" else "";
s1 = if Autoconf.os == "Windows_NT" then ".exe" else "";
filename = if System.regularFileExists(str1) then str1 else filename;
// check if plot callback is defined
b = System.plotCallBackDefined();
Expand Down Expand Up @@ -2473,7 +2473,7 @@ algorithm
pd = System.pathDelimiter();
// create absolute path of simulation result file
str1 = System.pwd() + pd + filename;
s1 = if System.os() == "Windows_NT" then ".exe" else "";
s1 = if Autoconf.os == "Windows_NT" then ".exe" else "";
filename = if System.regularFileExists(str1) then str1 else filename;
// check if plot callback is defined
b = System.plotCallBackDefined();
Expand Down Expand Up @@ -2853,7 +2853,7 @@ algorithm
pd = System.pathDelimiter();
// create absolute path of simulation result file
str1 = System.pwd() + pd + filename;
s1 = if System.os() == "Windows_NT" then ".exe" else "";
s1 = if Autoconf.os == "Windows_NT" then ".exe" else "";
filename = if System.regularFileExists(str1) then str1 else filename;
// check if plot callback is defined
b = System.plotCallBackDefined();
Expand Down Expand Up @@ -2955,7 +2955,7 @@ algorithm
then ".bat";
case ("Cpp","WIN64")
then ".bat";
else System.getExeExt();
else Autoconf.exeExt;
end match;
end getSimulationExtension;

Expand Down Expand Up @@ -3369,7 +3369,7 @@ algorithm
if System.regularFileExists(logfile) then
System.removeFile(logfile);
end if;
nozip := System.getMakeCommand()+" -j"+intString(Config.noProc()) + " nozip";
nozip := Autoconf.make+" -j"+intString(Config.noProc()) + " nozip";
includeDefaultFmi := "-I" + Settings.getInstallationDirectoryPath() + "/include/omc/c/fmi";
finishedBuild := match Util.stringSplitAtChar(platform, " ")
case {"dynamic"}
Expand All @@ -3378,9 +3378,9 @@ algorithm
// replace @XX@ variables in the Makefile
makefileStr := System.stringReplace(makefileStr, "@CC@", CC);
makefileStr := System.stringReplace(makefileStr, "@CFLAGS@", CFLAGS);
makefileStr := System.stringReplace(makefileStr, "@LDFLAGS@", LDFLAGS+System.getRTLibsSim());
makefileStr := System.stringReplace(makefileStr, "@LDFLAGS@", LDFLAGS+Autoconf.ldflags_runtime_sim);
makefileStr := System.stringReplace(makefileStr, "@LIBS@", "");
makefileStr := System.stringReplace(makefileStr, "@DLLEXT@", System.getDllExt());
makefileStr := System.stringReplace(makefileStr, "@DLLEXT@", Autoconf.dllExt);
makefileStr := System.stringReplace(makefileStr, "@NEED_RUNTIME@", "");
makefileStr := System.stringReplace(makefileStr, "@NEED_DGESV@", "");
makefileStr := System.stringReplace(makefileStr, "@FMIPLATFORM@", System.modelicaPlatform());
Expand All @@ -3399,9 +3399,9 @@ algorithm
// replace @XX@ variables in the Makefile
makefileStr := System.stringReplace(makefileStr, "@CC@", CC);
makefileStr := System.stringReplace(makefileStr, "@CFLAGS@", CFLAGS);
makefileStr := System.stringReplace(makefileStr, "@LDFLAGS@", LDFLAGS+" -lSimulationRuntimeFMI "+System.getRTLibsFMU());
makefileStr := System.stringReplace(makefileStr, "@LDFLAGS@", LDFLAGS+" -lSimulationRuntimeFMI "+Autoconf.ldflags_runtime_fmu);
makefileStr := System.stringReplace(makefileStr, "@LIBS@", "");
makefileStr := System.stringReplace(makefileStr, "@DLLEXT@", System.getDllExt());
makefileStr := System.stringReplace(makefileStr, "@DLLEXT@", Autoconf.dllExt);
makefileStr := System.stringReplace(makefileStr, "@NEED_RUNTIME@", "");
makefileStr := System.stringReplace(makefileStr, "@NEED_DGESV@", "");
makefileStr := System.stringReplace(makefileStr, "@FMIPLATFORM@", System.modelicaPlatform());
Expand Down Expand Up @@ -3518,7 +3518,7 @@ algorithm

System.realtimeTick(ClockIndexes.RT_CLOCK_BUILD_MODEL);

isWindows := System.os() == "Windows_NT";
isWindows := Autoconf.os == "Windows_NT";

fmutmp := filenameprefix + ".fmutmp";
logfile := filenameprefix + ".log";
Expand Down Expand Up @@ -3583,7 +3583,7 @@ algorithm
// get OPENMODELICAHOME
omhome := Settings.getInstallationDirectoryPath();
pd := System.pathDelimiter();
ext := if System.os() == "Windows_NT" then ".exe" else "";
ext := if Autoconf.os == "Windows_NT" then ".exe" else "";
if encrypt then
// create the path till packagetool
packageTool := stringAppendList({omhome,pd,"lib",pd,"omc",pd,"SEMLA",pd,"packagetool",ext});
Expand Down
16 changes: 9 additions & 7 deletions Compiler/Script/Figaro.mo
@@ -1,12 +1,14 @@
encapsulated package Figaro "Figaro support."

// Imports
public import Absyn;
public import Error;
public import SCode;
public import System;
import Absyn;
import Error;
import SCode;
import SCodeUtil;
protected

protected import SCodeUtil;
import Autoconf;
import System;

// Aliases
public type Ident = Absyn.Ident;
Expand Down Expand Up @@ -55,7 +57,7 @@ algorithm

// Temporary (or maybe permanent) fix because the Figaro processor works in an asynchronous way.

if System.os() == "Windows_NT" then
if Autoconf.os == "Windows_NT" then
System.systemCall("timeout 5");
else
System.systemCall("sleep 5");
Expand Down Expand Up @@ -1204,4 +1206,4 @@ algorithm
end printToken;

annotation(__OpenModelica_Interface="frontend");
end Figaro;
end Figaro;
39 changes: 20 additions & 19 deletions Compiler/SimCode/SimCodeFunctionUtil.mo
Expand Up @@ -39,6 +39,7 @@ import SimCodeVar;
protected

import Array;
import Autoconf;
import BaseHashTable;
import CevalScript;
import ComponentReference;
Expand Down Expand Up @@ -1773,10 +1774,10 @@ algorithm
includes := generateExtFunctionIncludesIncludestr(mod);
(libs, dirs, resources) := generateExtFunctionLibraryDirectoryFlags(program, path, mod, libs);
for name in if Flags.isSet(Flags.CHECK_EXT_LIBS) then libNames else {} loop
if getGerneralTarget(target)=="msvc" or System.os()=="Windows_NT" then
fullLibNames := {name + System.getDllExt(), "lib" + name + ".a", "lib" + name + ".lib"};
if getGerneralTarget(target)=="msvc" or Autoconf.os=="Windows_NT" then
fullLibNames := {name + Autoconf.dllExt, "lib" + name + ".a", "lib" + name + ".lib"};
else
fullLibNames := {"lib" + name + ".a", "lib" + name + System.getDllExt()};
fullLibNames := {"lib" + name + ".a", "lib" + name + Autoconf.dllExt};
end if;
lookForExtFunctionLibrary(fullLibNames, dirs, name, resources, path, info);
end for;
Expand Down Expand Up @@ -1898,7 +1899,7 @@ algorithm
libPaths := matchcontinue(uri,path,inLibs)
local
String str, platform1, platform2;
case(_, _,{"-lWinmm"}) guard System.os()=="Windows_NT"
case(_, _,{"-lWinmm"}) guard Autoconf.os=="Windows_NT"
//Winmm has to be linked from the windows system but not from the resource directories.
//This is a fix for M_DD since otherwise the dummy pthread.dll that breaks the built will be linked
then {(Settings.getInstallationDirectoryPath() + "/lib/" + System.getTriple() + "/omc")};
Expand Down Expand Up @@ -1938,7 +1939,7 @@ algorithm
end matchcontinue;
str := CevalScript.getFullPathFromUri(program, str, false);
resourcesStr := CevalScript.getFullPathFromUri(program, "modelica://" + Absyn.pathFirstIdent(path) + "/Resources", false);
isLinux := stringEq("linux",System.os());
isLinux := stringEq("linux",Autoconf.os);
target := Flags.getConfigString(Flags.TARGET);
// please, take care about ordering these libraries, the most specific should have the highest priority
libs2 := getLinkerLibraryPaths(str, path, inLibs);
Expand Down Expand Up @@ -1997,7 +1998,7 @@ algorithm
str = CevalScript.getFullPathFromUri(program, str, false);
platform1 = System.openModelicaPlatform();
platform2 = System.modelicaPlatform();
isLinux = stringEq("linux",System.os());
isLinux = stringEq("linux",Autoconf.os);
// please, take care about ordering these libraries, the most specific should go first (in reverse here)
libs = generateExtFunctionLibraryDirectoryPaths2(true, str, isLinux, {} );
libs = generateExtFunctionLibraryDirectoryPaths2(not stringEq(platform2,""), str + "/" + platform2, isLinux, libs);
Expand All @@ -2009,7 +2010,7 @@ algorithm
str = CevalScript.getFullPathFromUri(program, str, false);
platform1 = System.openModelicaPlatform();
platform2 = System.modelicaPlatform();
isLinux = stringEq("linux",System.os());
isLinux = stringEq("linux",Autoconf.os);
// please, take care about ordering these libraries, the most specific should go first (in reverse here)
libs = generateExtFunctionLibraryDirectoryPaths2(true, str, isLinux, {} );
libs = generateExtFunctionLibraryDirectoryPaths2(not stringEq(platform2,""), str + "/" + platform2, isLinux, libs);
Expand Down Expand Up @@ -2060,7 +2061,7 @@ algorithm
// omcruntime on windows needs linking with mico2313 and wsock and then some :)
case Absyn.STRING("omcruntime")
equation
true = "Windows_NT" == System.os();
true = "Windows_NT" == Autoconf.os;
strs = {"f2c.lib", "initialization.lib", "libexpat.lib", "math-support.lib", "meta.lib", "ModelicaExternalC.lib", "results.lib", "simulation.lib", "solver.lib", "sundials_kinsol.lib", "sundials_nvecserial.lib", "util.lib", "lapack_win32_MT.lib"};
then
(strs, {});
Expand Down Expand Up @@ -2112,45 +2113,45 @@ algorithm
case Absyn.STRING("Lapack") then ({},{});

//pthreads is already linked under windows
case Absyn.STRING("pthread") guard System.os()=="Windows_NT"
case Absyn.STRING("pthread") guard Autoconf.os=="Windows_NT"
equation
Error.addCompilerNotification("pthreads library is already available. It is not linked from the external library resource directory.\n");
then ({},{});

//do not link rt.dll for Modelica Device Drivers as it is not needed under windows
case Absyn.STRING("rt") guard System.os()=="Windows_NT"
case Absyn.STRING("rt") guard Autoconf.os=="Windows_NT"
equation
Error.addCompilerNotification("rt library is not needed under Windows. It is not linked from the external library resource directory.\n");
then ({},{});

//do not link Ws2_32.dll for Modelica Device Drivers as it is not needed under windows
case Absyn.STRING("Ws2_32") guard System.os()=="Windows_NT"
case Absyn.STRING("Ws2_32") guard Autoconf.os=="Windows_NT"
equation
Error.addCompilerNotification("Ws2_32 library is not needed under Windows. It is not linked from the external library resource directory.\n");
then ({},{});

//user32 is already linked under windows
case Absyn.STRING("User32") guard System.os()=="Windows_NT"
case Absyn.STRING("User32") guard Autoconf.os=="Windows_NT"
equation
Error.addCompilerNotification("User32 library is already available. It is not linked from the external library resource directory.\n");
then ({},{});

//winmm is a windows system lib
case Absyn.STRING(str as "Winmm") guard System.os()=="Windows_NT"
case Absyn.STRING(str as "Winmm") guard Autoconf.os=="Windows_NT"
equation
str = "-l" + str;
Error.addCompilerNotification("Winmm library is a windows system library. It is not linked from the external library resource directory.\n");
then ({str},{});

//do not link X11.dll for Modelica Device Drivers as it is not needed under windows
case Absyn.STRING("X11") guard System.os()=="Windows_NT"
case Absyn.STRING("X11") guard Autoconf.os=="Windows_NT"
equation
Error.addCompilerNotification("X11 library is not needed under Windows. It is not linked from the external library resource directory.\n");
then ({},{});

case Absyn.STRING(str as "omcruntime")
equation
if "Windows_NT" == System.os() then
if "Windows_NT" == Autoconf.os then
// omcruntime on windows needs linking with mico2313 and wsock and then some :)
str = "-l" + str;
strs = str :: "-lintl" :: "-liconv" :: "-lexpat" :: "-lsqlite3" :: "-llpsolve55" :: "-ltre" :: "-lomniORB420_rt" :: "-lomnithread40_rt" :: "-lws2_32" :: "-lRpcrt4" :: "-lregex" :: {};
Expand All @@ -2168,7 +2169,7 @@ algorithm
then ({str},{});

case Absyn.STRING("fmilib")
then (if System.os()=="Windows_NT" then {"-lfmilib","-lshlwapi"} else {"-lfmilib"},{});
then (if Autoconf.os=="Windows_NT" then {"-lfmilib","-lshlwapi"} else {"-lfmilib"},{});

case Absyn.STRING(str)
algorithm
Expand Down Expand Up @@ -2520,15 +2521,15 @@ algorithm
(if Flags.isSet(Flags.HPCOM) then System.getOMPCCompiler() else System.getCCompiler());
cxxcompiler := if stringEq(Config.simCodeTarget(),"JavaScript") then "emcc" else System.getCXXCompiler();
linker := if stringEq(Config.simCodeTarget(),"JavaScript") then "emcc" else System.getLinker();
exeext := if stringEq(Config.simCodeTarget(),"JavaScript") then ".js" else System.getExeExt();
dllext := System.getDllExt();
exeext := if stringEq(Config.simCodeTarget(),"JavaScript") then ".js" else Autoconf.exeExt;
dllext := Autoconf.dllExt;
omhome := Settings.getInstallationDirectoryPath();
omhome := System.trim(omhome, "\""); // Remove any quotation marks from omhome.
cflags := System.getCFlags() + " " +
(if Flags.isSet(Flags.HPCOM) then "-fopenmp" else "");
cflags := if stringEq(Config.simCodeTarget(),"JavaScript") then "-Os -Wno-warn-absolute-paths" else cflags;
ldflags := System.getLDFlags();
rtlibs := if isFunction then System.getRTLibs() else (if isFMU then System.getRTLibsFMU() else System.getRTLibsSim());
rtlibs := if isFunction then Autoconf.ldflags_runtime else (if isFMU then Autoconf.ldflags_runtime_fmu else Autoconf.ldflags_runtime_sim);
platform := System.modelicaPlatform();
compileDir := System.pwd() + System.pathDelimiter();
makefileParams := SimCodeFunction.MAKEFILE_PARAMS(ccompiler, cxxcompiler, linker, exeext, dllext,
Expand Down
3 changes: 2 additions & 1 deletion Compiler/SimCode/SimCodeMain.mo
Expand Up @@ -54,6 +54,7 @@ import SimCode;

// protected imports
protected
import Autoconf;
import AvlSetString;
import BackendDAECreate;
import BackendDAEOptimize;
Expand Down Expand Up @@ -696,7 +697,7 @@ algorithm
for path in simCode.modelInfo.resourcePaths loop
dirname := System.dirname(path);
// on windows, remove ":" from the path!
if System.os() == "Windows_NT" then
if Autoconf.os == "Windows_NT" then
dirname := System.stringReplace(dirname, ":", "");
end if;
newdir := resourcesDir + dirname;
Expand Down
1 change: 1 addition & 0 deletions Compiler/SimCode/SimCodeUtil.mo
Expand Up @@ -60,6 +60,7 @@ import Values;
// protected imports
protected
import Array;
import Autoconf;
import AvlSetString;
import BackendDAEOptimize;
import BackendDAETransform;
Expand Down

0 comments on commit 5db7684

Please sign in to comment.