Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
1# mkOpenModelicaDerivation is an mkDerivation function for packages 2# from OpenModelica suite. 3 4{ 5 stdenv, 6 lib, 7 fetchgit, 8 autoconf, 9 automake, 10 libtool, 11 cmake, 12 autoreconfHook, 13 symlinkJoin, 14}: 15pkg: 16let 17 inherit (builtins) 18 hasAttr 19 getAttr 20 length 21 elemAt 22 ; 23 inherit (lib) attrByPath concatStringsSep; 24 25 # A few helpers functions: 26 27 # getAttrDef is just a getAttr with default fallback 28 getAttrDef = 29 attr: default: x: 30 attrByPath [ attr ] default x; 31 32 # getAttr-like helper for optional append to string: 33 # "Hello" + appendByAttr "a" " " {a = "world";} = "Hello world" 34 # "Hello" + appendByAttr "a" " " {} = "Hello" 35 appendByAttr = 36 attr: sep: x: 37 lib.optionalString (hasAttr attr x) (sep + (getAttr attr x)); 38 39 # Are there any OM dependencies at all? 40 ifDeps = length pkg.omdeps != 0; 41 42 # Dependencies of current OpenModelica-target joined in one file tree. 43 # Return the dep itself in case it is a single one. 44 joinedDeps = 45 if length pkg.omdeps == 1 then 46 elemAt pkg.omdeps 0 47 else 48 symlinkJoin { 49 name = pkg.pname + "-omhome"; 50 paths = pkg.omdeps; 51 }; 52 53 # Should we run ./configure for the target pkg? 54 omautoconf = getAttrDef "omautoconf" false pkg; 55 56 # Name of the make target 57 omtarget = getAttrDef "omtarget" pkg.pname pkg; 58 59 # Directory of target sources 60 omdir = getAttrDef "omdir" pkg.pname pkg; 61 62 # Simple to to m4 configuration scripts 63 postPatch = 64 lib.optionalString ifDeps '' 65 sed -i ''$(find -name omhome.m4) -e 's|if test ! -z "$USINGPRESETBUILDDIR"|if test ! -z "$USINGPRESETBUILDDIR" -a -z "$OMHOME"|' 66 '' 67 + appendByAttr "postPatch" "\n" pkg; 68 69 # Update shebangs in the scripts before running configuration. 70 preAutoreconf = "patchShebangs --build common" + appendByAttr "preAutoreconf" "\n" pkg; 71 72 # Tell OpenModelica where built dependencies are located. 73 configureFlags = 74 lib.optional ifDeps "--with-openmodelicahome=${joinedDeps}" ++ getAttrDef "configureFlags" [ ] pkg; 75 76 # Our own configurePhase that accounts for omautoconf 77 configurePhase = '' 78 runHook preConfigure 79 export configureFlags="''${configureFlags} --with-ombuilddir=$PWD/build --prefix=$prefix" 80 ./configure --no-recursion $configureFlags 81 ${lib.optionalString omautoconf "(cd ${omdir}; ./configure $configureFlags)"} 82 runHook postConfigure 83 ''; 84 85 # Targets that we want to build ourselves: 86 deptargets = lib.forEach pkg.omdeps (dep: dep.omtarget); 87 88 # ... so we ask openmodelica makefile to skip those targets. 89 preBuild = '' 90 for target in ${concatStringsSep " " deptargets}; do 91 touch ''${target}.skip; 92 done 93 '' 94 + appendByAttr "preBuild" "\n" pkg; 95 96 makeFlags = "${omtarget}" + appendByAttr "makeFlags" " " pkg; 97 98 installFlags = "-i " + appendByAttr "installFlags" " " pkg; 99 100in 101stdenv.mkDerivation ( 102 pkg 103 // { 104 inherit 105 omtarget 106 postPatch 107 preAutoreconf 108 configureFlags 109 configurePhase 110 preBuild 111 makeFlags 112 installFlags 113 ; 114 115 src = fetchgit (import ./src-main.nix); 116 version = "1.18.0"; 117 118 nativeBuildInputs = getAttrDef "nativeBuildInputs" [ ] pkg ++ [ 119 autoconf 120 automake 121 libtool 122 cmake 123 autoreconfHook 124 ]; 125 126 buildInputs = getAttrDef "buildInputs" [ ] pkg ++ lib.optional ifDeps joinedDeps; 127 128 dontUseCmakeConfigure = true; 129 130 hardeningDisable = [ "format" ]; 131 } 132)