diff --git a/pkgs/build-support/mk-epics-package/default.nix b/pkgs/build-support/mk-epics-package/default.nix index 1ae18b6a..44ce18dc 100644 --- a/pkgs/build-support/mk-epics-package/default.nix +++ b/pkgs/build-support/mk-epics-package/default.nix @@ -16,127 +16,43 @@ depsBuildBuild ? [], nativeBuildInputs ? [], buildInputs ? [], - makeFlags ? [], - preBuild ? "", - postFixup ? "", ... -} @ attrs: -with lib; let - inherit (buildPackages) epnixLib; - +} @ attrs: let # remove non standard attributes that cannot be coerced to strings overridable = builtins.removeAttrs attrs ["local_config_site" "local_release"]; - generateConf = (epnixLib.formats.make {}).generate; - - # "build" as in Nix terminology (the build machine) - build_arch = epnixLib.toEpicsArch stdenv.buildPlatform; - # "host" as in Nix terminology (the machine which will run the generated code) - host_arch = epnixLib.toEpicsArch stdenv.hostPlatform; + generateConf = (buildPackages.epnixLib.formats.make {}).generate; in stdenv.mkDerivation (overridable // { strictDeps = true; + # When cross-compiling, + # epics will build every project twice, + # once "build -> build", and once "build -> host", + # so we need a compiler for the "build -> build" compilation. depsBuildBuild = depsBuildBuild ++ [buildPackages.stdenv.cc]; - nativeBuildInputs = nativeBuildInputs ++ [makeWrapper perl readline]; - - # Also add perl into the non-native build inputs so that shebangs gets patched - buildInputs = buildInputs ++ [perl readline] ++ (optional (!isEpicsBase) [epnix.epics-base]); - - makeFlags = - makeFlags + nativeBuildInputs = + nativeBuildInputs ++ [ - "INSTALL_LOCATION=${placeholder "out"}" + makeWrapper + perl + readline + epnix.epicsSetupHook ]; - PERL_HASH_SEED = 0; + # Also add perl into the non-native build inputs + # so that shebangs gets patched + buildInputs = + buildInputs + ++ [perl readline] + ++ (lib.optional (!isEpicsBase) epnix.epics-base); setupHook = ./setup-hook.sh; - # Defaults to true, EPICS' Makefile framework does usually support parallel builds - enableParallelBuilding = attrs.enableParallelBuilding or true; - - dontConfigure = true; - - local_config_site = generateConf ({ - # This variable is used as a default version revision if no VCS is found. - # - # Since fetchgit and related fetchers remove the .git directory for - # reproducibility, EPICS fallsback to either the GENVERSIONDEFAULT variable - # if set (not the default), or the current date/time, which isn't - # reproducible. - GENVERSIONDEFAULT = "EPNix"; - CROSS_COMPILER_TARGET_ARCHS = - if (stdenv.buildPlatform != stdenv.hostPlatform) - then host_arch - else null; - - # This prevents EPICS from detecting installed libraries on the host - # system, for when Nix is compiling without sandbox (e.g.: WSL2) - GNU_DIR = "/var/empty"; - } - // local_config_site); - - # Undefine the SUPPORT variable here, since there is no single "support" - # directory and this variable is a source of conflicts between RELEASE files - local_release = generateConf (local_release // {SUPPORT = null;}); - - preBuild = - '' - echo "$local_config_site" > configure/CONFIG_SITE.local - echo "$local_release" > configure/RELEASE.local - - # set to empty if unset - : "''${EPICS_COMPONENTS=}" - - IFS=: read -ra components <<<$EPICS_COMPONENTS - - for component in "''${components[@]}"; do - echo "$component" - echo "$component" >> configure/RELEASE.local - done - - echo "==============================" - echo "CONFIG_SITE.local" - echo "------------------------------" - cat "configure/CONFIG_SITE.local" - echo "==============================" - echo "RELEASE.local" - echo "------------------------------" - cat "configure/RELEASE.local" - echo "------------------------------" - - '' - + preBuild; - - # Automatically create binaries directly in `bin/` that calls the ones that - # are in `bin/linux-x86_64/` - # TODO: we should probably do the same for libraries - # - # Don't do a manual `make install`, `make` already installs - # everything into `INSTALL_LOCATION`. - installPhase = '' - runHook preInstall - - if [[ -d "$out/bin/${host_arch}" ]]; then - for file in "$out/bin/${host_arch}/"*; do - [[ -x "$file" ]] || continue - - makeWrapper "$file" "$out/bin/$(basename "$file")" - done - fi - - runHook postInstall - ''; + local_config_site = generateConf local_config_site; + local_release = generateConf local_release; doCheck = attrs.doCheck or true; checkTarget = "runtests"; - - stripDebugList = attrs.stripDebugList or ["bin/${host_arch}" "lib/${host_arch}"]; - postFixup = - optionalString (stdenv.buildPlatform != stdenv.hostPlatform) '' - stripDirs strip "bin/${build_arch} lib/${build_arch}" "-S" - '' - + postFixup; }) diff --git a/pkgs/build-support/mk-epics-package/setup-hook.sh b/pkgs/build-support/mk-epics-package/setup-hook.sh index 04a03022..8868f553 100644 --- a/pkgs/build-support/mk-epics-package/setup-hook.sh +++ b/pkgs/build-support/mk-epics-package/setup-hook.sh @@ -1 +1,5 @@ +# Export this package in a EPNix specific "EPICS_COMPONENTS" environment variable, +# so that we are able to list every EPICS-specific packages, +# to add them in the 'configure/RELEASE.local' file +# in dependent packages. export "EPICS_COMPONENTS=${EPICS_COMPONENTS:+${EPICS_COMPONENTS}:}@varname@=@out@"