forked from mirrors/nixpkgs
5c8561f11a
Co-authored-by: Jaakko Luttinen <jaakko.luttinen@iki.fi> Most of changes are: * separate packages for different openmodelica components, * qt4 -> qt5, * patches to instruct the OMEdit wrapper with stdenv executables location, * adoption of #89731 and #109595, * openblas -> blas, lapack according to #83888, * parallel building, * getting rid of spurious build phases, * correct the license, * cross-compilation, * forcing compiler to clang++ according to OM build recommendations, * drop of pangox_compat according to #75909 and #76412, * better dependencies, and more.
102 lines
3.2 KiB
Nix
102 lines
3.2 KiB
Nix
# mkOpenModelicaDerivation is an mkDerivation function for packages
|
|
# from OpenModelica suite.
|
|
|
|
{ stdenv, lib, fetchgit, autoconf, automake, libtool, cmake, autoreconfHook, symlinkJoin }:
|
|
pkg:
|
|
let
|
|
inherit (builtins) hasAttr getAttr length elemAt;
|
|
inherit (lib) attrByPath concatStringsSep;
|
|
|
|
|
|
# A few helpers functions:
|
|
|
|
# getAttrDef is just a getAttr with default fallback
|
|
getAttrDef = attr: default: x: attrByPath [ attr ] default x;
|
|
|
|
# getAttr-like helper for optional append to string:
|
|
# "Hello" + appendByAttr "a" " " {a = "world";} = "Hello world"
|
|
# "Hello" + appendByAttr "a" " " {} = "Hello"
|
|
appendByAttr = attr: sep: x: if hasAttr attr x then sep + (getAttr attr x) else "";
|
|
|
|
# Are there any OM dependencies at all?
|
|
ifDeps = length pkg.omdeps != 0;
|
|
|
|
# Dependencies of current OpenModelica-target joined in one file tree.
|
|
# Return the dep itself in case it is a single one.
|
|
joinedDeps =
|
|
if length pkg.omdeps == 1
|
|
then elemAt pkg.omdeps 0
|
|
else
|
|
symlinkJoin {
|
|
name = pkg.pname + "-omhome";
|
|
paths = pkg.omdeps;
|
|
};
|
|
|
|
# Should we run ./configure for the target pkg?
|
|
omautoconf = getAttrDef "omautoconf" false pkg;
|
|
|
|
# Name of the make target
|
|
omtarget = getAttrDef "omtarget" pkg.pname pkg;
|
|
|
|
# Directory of target sources
|
|
omdir = getAttrDef "omdir" pkg.pname pkg;
|
|
|
|
# Simple to to m4 configuration scripts
|
|
postPatch = lib.optionalString ifDeps ''
|
|
sed -i ''$(find -name omhome.m4) -e 's|if test ! -z "$USINGPRESETBUILDDIR"|if test ! -z "$USINGPRESETBUILDDIR" -a -z "$OMHOME"|'
|
|
'' +
|
|
appendByAttr "postPatch" "\n" pkg;
|
|
|
|
# Update shebangs in the scripts before running configuration.
|
|
preAutoreconf = "patchShebangs --build common" +
|
|
appendByAttr "preAutoreconf" "\n" pkg;
|
|
|
|
# Tell OpenModelica where built dependencies are located.
|
|
configureFlags = lib.optional ifDeps "--with-openmodelicahome=${joinedDeps}" ++
|
|
getAttrDef "configureFlags" [ ] pkg;
|
|
|
|
# Our own configurePhase that accounts for omautoconf
|
|
configurePhase = ''
|
|
runHook preConfigure
|
|
export configureFlags="''${configureFlags} --with-ombuilddir=$PWD/build --prefix=$prefix"
|
|
./configure --no-recursion $configureFlags
|
|
${lib.optionalString omautoconf "(cd ${omdir}; ./configure $configureFlags)"}
|
|
runHook postConfigure
|
|
'';
|
|
|
|
# Targets that we want to build ourselves:
|
|
deptargets = lib.forEach pkg.omdeps (dep: dep.omtarget);
|
|
|
|
# ... so we ask openmodelica makefile to skip those targets.
|
|
preBuild = ''
|
|
for target in ${concatStringsSep " " deptargets}; do
|
|
touch ''${target}.skip;
|
|
done
|
|
'' +
|
|
appendByAttr "preBuild" "\n" pkg;
|
|
|
|
makeFlags = "${omtarget}" +
|
|
appendByAttr "makeFlags" " " pkg;
|
|
|
|
installFlags = "-i " +
|
|
appendByAttr "installFlags" " " pkg;
|
|
|
|
|
|
in
|
|
stdenv.mkDerivation (pkg // {
|
|
inherit omtarget postPatch preAutoreconf configureFlags configurePhase preBuild makeFlags installFlags;
|
|
|
|
src = fetchgit (import ./src-main.nix);
|
|
version = "1.17.0";
|
|
|
|
nativeBuildInputs = getAttrDef "nativeBuildInputs" [ ] pkg
|
|
++ [ autoconf automake libtool cmake autoreconfHook ];
|
|
|
|
buildInputs = getAttrDef "buildInputs" [ ] pkg
|
|
++ lib.optional ifDeps joinedDeps;
|
|
|
|
dontUseCmakeConfigure = true;
|
|
|
|
hardeningDisable = [ "format" ];
|
|
})
|