Skip to content

Commit

Permalink
Build SEMLA
Browse files Browse the repository at this point in the history
Checkout the SEMLA repository inside the OM super project i.e., at the same level where OMCompiler is.
Run the makefile with `OMENCRYPTION=ON` i.e., `make -f Makefile.omdev.mingw OMENCRYPTION=ON`.

Belonging to [master]:
  - OpenModelica/OMCompiler#2197
  • Loading branch information
adeas31 authored and OpenModelica-Hudson committed Feb 15, 2018
1 parent 0a2708a commit 081af3b
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 0 deletions.
8 changes: 8 additions & 0 deletions Compiler/FrontEnd/ModelicaBuiltin.mo
Expand Up @@ -2451,6 +2451,14 @@ external "builtin";
annotation(preferredView="text");
end buildModelFMU;

function buildEncryptedPackage
input TypeName className "the class that should encrypted";
output Boolean success;
output String commandOutput "Output of the packagetool execuable";
external "builtin";
annotation(preferredView="text");
end buildEncryptedPackage;

function simulate "simulates a modelica model by generating c code, build it and run the simulation executable.
The only required argument is the className, while all others have some default values.
simulate(className, [startTime], [stopTime], [numberOfIntervals], [tolerance], [method], [fileNamePrefix], [options], [outputFormat], [variableFilter], [cflags], [simflags])
Expand Down
57 changes: 57 additions & 0 deletions Compiler/Script/CevalScriptBackend.mo
Expand Up @@ -1314,6 +1314,15 @@ algorithm
case (cache,_,"buildModelFMU", _,_)
then (cache,Values.STRING(""));

case (cache,env,"buildEncryptedPackage", {Values.CODE(Absyn.C_TYPENAME(className))},_)
algorithm
p := SymbolTable.getAbsyn();
(b, str) := buildEncryptedPackage(className, p);
then (cache,Values.TUPLE({Values.BOOL(b),Values.STRING(str)}));

case (cache,_,"buildEncryptedPackage",_,_)
then (cache,Values.TUPLE({Values.BOOL(false),Values.STRING("")}));

case (cache,env,"translateModelXML",{Values.CODE(Absyn.C_TYPENAME(className)),Values.STRING(filenameprefix)},_)
equation
filenameprefix = Util.stringReplaceChar(filenameprefix,".","_");
Expand Down Expand Up @@ -3445,6 +3454,54 @@ algorithm
System.removeDirectory(fmutmp);
end buildModelFMU;

protected function buildEncryptedPackage
input Absyn.Path className "path for the model";
input Absyn.Program inProgram;
output Boolean success;
output String commandOutput;
protected
Absyn.Class cls;
String fileName, omhome, pd, str1, str2, str3, call, logFile;
algorithm
cls := Interactive.getPathedClassInProgram(className, inProgram);
fileName := Absyn.classFilename(cls);
if (System.regularFileExists(fileName)) then
// get OPENMODELICAHOME
omhome := Settings.getInstallationDirectoryPath();
pd := System.pathDelimiter();
str1 := if System.os() == "Windows_NT" then ".exe" else "";
// create the path till packagetool
str2 := stringAppendList({omhome,pd,"bin",pd,"packagetool",str1});
if System.regularFileExists(str2) then
// create the list of arguments for packagetool
str3 := "-librarypath \"" + System.dirname(fileName) + "\" -version \"1.0\" -language \"3.2\" -encrypt \"true\"";
call := stringAppendList({str2," ",str3});
logFile := "packagetool.log";
// remove the logFile if it already exists.
if System.regularFileExists(logFile) then
System.removeFile(logFile);
end if;
// run the packagetool command
if 0 == System.systemCall(call, logFile) then
success := true;
else
success := false;
end if;
// read the logFile
if System.regularFileExists(logFile) then
commandOutput := System.readFile(logFile);
end if;
else
Error.addMessage(Error.FILE_NOT_FOUND_ERROR, {str2});
commandOutput := "";
success := false;
end if;
else
Error.addMessage(Error.FILE_NOT_FOUND_ERROR, {fileName});
commandOutput := "";
success := false;
end if;
end buildEncryptedPackage;

protected function translateModelXML " author: Alachew
translates a model into XML code "
Expand Down
15 changes: 15 additions & 0 deletions Makefile.common
Expand Up @@ -27,6 +27,21 @@ INSTALL_LOCALEDIR = ${DESTDIR}${datadir}/locale

.PHONY : interactive omc release all mkbuilddirs fmi test install-dirs susan susan_all susgen sustst install-openturns runtimeCPPinstall CMinpack metis Cdaskr boehm-gc libzmq $(MINGW_EXTRA_LIBS)

ifeq ($(OMENCRYPTION),ON)
.PHONY : semla
CPPFLAGS=-DOMENCRYPTION

semla: mkbuilddirs
mkdir -p ../SEMLA/build
(cd ../SEMLA/build && test -f Makefile || $(CMAKE) -DCMAKE_COLOR_MAKEFILE:Bool=OFF -DCMAKE_INSTALL_PREFIX:String=../install ../src -G $(CMAKE_TARGET))
(cd ../SEMLA/build && $(CMAKE) --build .)
(cd ../SEMLA/build && $(CMAKE) --build . --target install)
cp -pPR ../SEMLA/install/bin/* $(builddir_bin)
cp -pPR ../SEMLA/install/lib/* $(builddir_lib_omc)
mkdir -p $(builddir_bin)/LVE
mv $(builddir_bin)/lve.exe $(builddir_bin)/LVE/lve_win64.exe
endif # end of OMENCRYPTION

mkbuilddirs:
echo Making build directories under $(OMBUILDDIR)
if [ "$(APP)" = ".app" ]; then mkdir -p $(builddir_app); fi
Expand Down
4 changes: 4 additions & 0 deletions Makefile.omdev.mingw
Expand Up @@ -262,7 +262,11 @@ copycppmsvcheader: getMSVCversion
(cp -puf $(BOOST_PATH_MSVC)/boost/*.hpp $(OMBUILDDIR)/include/omc/cpp/3rdParty/boost/msvc/boost)
(cp -pufr $(BOOST_PATH_MSVC)/boost/* $(OMBUILDDIR)/include/omc/cpp/3rdParty/boost/msvc/boost)

ifeq ($(OMENCRYPTION),ON)
omc: mkbuilddirs interactive fmil omdev_extra_dlls breakprocess opencl_rt CMinpack metis Cdaskr $(IPOPT_TARGET) graphstream
else
omc: mkbuilddirs interactive fmil omdev_extra_dlls breakprocess opencl_rt CMinpack metis Cdaskr $(IPOPT_TARGET) graphstream semla
endif
(time $(MAKE) -f $(defaultMakefileTarget) CFLAGS="$(CFLAGS)" omc-bootstrapped OMBUILDDIR=$(OMBUILDDIR))

boehm-gc-lib: $(OMBUILDDIR)/lib/omc/libomcgc.a
Expand Down

0 comments on commit 081af3b

Please sign in to comment.