jam: set target-specific macros correctly

Jam embeds some information about the target platform, namely the OS and
architecture, directly into the binary. We need to re-evaluate the
macros for the target platform when Jam is being used to cross compile.

+58 -31
+58 -31
pkgs/development/tools/build-managers/jam/default.nix
··· 1 - { lib, stdenv, fetchurl, bison, buildPackages }: 1 + { lib, stdenv, fetchurl, bison, buildPackages, pkgsBuildTarget }: 2 2 3 3 let 4 - mkJam = { meta ? { }, ... } @ args: stdenv.mkDerivation (args // { 4 + mkJam = { pname, version, src, meta ? { } }: stdenv.mkDerivation { 5 + inherit pname version src; 6 + 5 7 depsBuildBuild = [ buildPackages.stdenv.cc ]; 6 8 nativeBuildInputs = [ bison ]; 7 9 8 10 # Jambase expects ar to have flags. 9 11 preConfigure = '' 10 12 export AR="$AR rc" 13 + ''; 14 + 15 + # When cross-compiling, we need to set the preprocessor macros 16 + # OSMAJOR/OSMINOR/OSPLAT to the values from the target platform, not the 17 + # host platform. This looks a little ridiculous because the vast majority of 18 + # build tools don't embed target-specific information into their binary, but 19 + # in this case we behave more like a compiler than a make(1)-alike. 20 + postPatch = lib.optionalString (stdenv.hostPlatform != stdenv.targetPlatform) '' 21 + cat >>jam.h <<EOF 22 + #undef OSMAJOR 23 + #undef OSMINOR 24 + #undef OSPLAT 25 + $( 26 + ${pkgsBuildTarget.targetPackages.stdenv.cc}/bin/${pkgsBuildTarget.targetPackages.stdenv.cc.targetPrefix}cc -E -dM jam.h \ 27 + | grep -E '^#define (OSMAJOR|OSMINOR|OSPLAT) ' 28 + ) 29 + EOF 11 30 ''; 12 31 13 32 LOCATE_TARGET = "bin.unix"; ··· 30 49 31 50 enableParallelBuilding = true; 32 51 33 - meta = with lib; meta // { 52 + meta = with lib; { 34 53 license = licenses.free; 35 54 mainProgram = "jam"; 36 55 platforms = platforms.unix; 37 - }; 38 - }); 56 + } // meta; 57 + }; 39 58 in 40 59 { 41 60 jam = let 42 61 pname = "jam"; 43 62 version = "2.6.1"; 44 - in mkJam { 45 - inherit pname version; 46 63 47 - src = fetchurl { 48 - url = "https://swarm.workshop.perforce.com/projects/perforce_software-jam/download/main/${pname}-${version}.tar"; 49 - sha256 = "19xkvkpycxfsncxvin6yqrql3x3z9ypc1j8kzls5k659q4kv5rmc"; 50 - }; 64 + base = mkJam { 65 + inherit pname version; 66 + 67 + src = fetchurl { 68 + url = "https://swarm.workshop.perforce.com/projects/perforce_software-jam/download/main/${pname}-${version}.tar"; 69 + sha256 = "19xkvkpycxfsncxvin6yqrql3x3z9ypc1j8kzls5k659q4kv5rmc"; 70 + }; 51 71 52 - meta = with lib; { 53 - description = "Just Another Make"; 54 - homepage = "https://www.perforce.com/resources/documentation/jam"; 55 - maintainers = with maintainers; [ impl orivej ]; 72 + meta = with lib; { 73 + description = "Just Another Make"; 74 + homepage = "https://www.perforce.com/resources/documentation/jam"; 75 + maintainers = with maintainers; [ impl orivej ]; 76 + }; 56 77 }; 57 - }; 78 + in base.overrideAttrs (oldAttrs: { 79 + makeFlags = (oldAttrs.makeFlags or []) ++ [ 80 + "CC=${buildPackages.stdenv.cc.targetPrefix}cc" 81 + ]; 82 + }); 58 83 59 84 ftjam = let 60 85 pname = "ftjam"; 61 86 version = "2.5.2"; 62 - in mkJam { 63 - inherit pname version; 64 87 65 - src = fetchurl { 66 - url = "https://downloads.sourceforge.net/project/freetype/${pname}/${version}/${pname}-${version}.tar.bz2"; 67 - hash = "sha256-6JdzUAqSkS3pGOn+v/q+S2vOedaa8ZRDX04DK4ptZqM="; 68 - }; 88 + base = mkJam { 89 + inherit pname version; 69 90 70 - postPatch = '' 91 + src = fetchurl { 92 + url = "https://downloads.sourceforge.net/project/freetype/${pname}/${version}/${pname}-${version}.tar.bz2"; 93 + hash = "sha256-6JdzUAqSkS3pGOn+v/q+S2vOedaa8ZRDX04DK4ptZqM="; 94 + }; 95 + 96 + meta = with lib; { 97 + description = "FreeType's enhanced, backwards-compatible Jam clone"; 98 + homepage = "https://freetype.org/jam/"; 99 + maintainers = with maintainers; [ AndersonTorres impl ]; 100 + }; 101 + }; 102 + in base.overrideAttrs (oldAttrs: { 103 + postPatch = (oldAttrs.postPatch or "") + '' 71 104 substituteInPlace Jamfile --replace strip ${stdenv.cc.targetPrefix}strip 72 105 ''; 73 106 74 107 # Doesn't understand how to cross compile once bootstrapped, so we'll just 75 108 # use the Makefile for the bootstrapping portion. 76 109 configurePlatforms = [ "build" "target" ]; 77 - configureFlags = [ 110 + configureFlags = (oldAttrs.configureFlags or []) ++ [ 78 111 "CC=${buildPackages.stdenv.cc.targetPrefix}cc" 79 112 "--host=${stdenv.buildPlatform.config}" 80 113 ]; 81 - 82 - meta = with lib; { 83 - description = "FreeType's enhanced, backwards-compatible Jam clone"; 84 - homepage = "https://freetype.org/jam/"; 85 - maintainers = with maintainers; [ AndersonTorres impl ]; 86 - }; 87 - }; 114 + }); 88 115 }