lol

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 }: 2 3 let 4 - mkJam = { meta ? { }, ... } @ args: stdenv.mkDerivation (args // { 5 depsBuildBuild = [ buildPackages.stdenv.cc ]; 6 nativeBuildInputs = [ bison ]; 7 8 # Jambase expects ar to have flags. 9 preConfigure = '' 10 export AR="$AR rc" 11 ''; 12 13 LOCATE_TARGET = "bin.unix"; ··· 30 31 enableParallelBuilding = true; 32 33 - meta = with lib; meta // { 34 license = licenses.free; 35 mainProgram = "jam"; 36 platforms = platforms.unix; 37 - }; 38 - }); 39 in 40 { 41 jam = let 42 pname = "jam"; 43 version = "2.6.1"; 44 - in mkJam { 45 - inherit pname version; 46 47 - src = fetchurl { 48 - url = "https://swarm.workshop.perforce.com/projects/perforce_software-jam/download/main/${pname}-${version}.tar"; 49 - sha256 = "19xkvkpycxfsncxvin6yqrql3x3z9ypc1j8kzls5k659q4kv5rmc"; 50 - }; 51 52 - meta = with lib; { 53 - description = "Just Another Make"; 54 - homepage = "https://www.perforce.com/resources/documentation/jam"; 55 - maintainers = with maintainers; [ impl orivej ]; 56 }; 57 - }; 58 59 ftjam = let 60 pname = "ftjam"; 61 version = "2.5.2"; 62 - in mkJam { 63 - inherit pname version; 64 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 - }; 69 70 - postPatch = '' 71 substituteInPlace Jamfile --replace strip ${stdenv.cc.targetPrefix}strip 72 ''; 73 74 # Doesn't understand how to cross compile once bootstrapped, so we'll just 75 # use the Makefile for the bootstrapping portion. 76 configurePlatforms = [ "build" "target" ]; 77 - configureFlags = [ 78 "CC=${buildPackages.stdenv.cc.targetPrefix}cc" 79 "--host=${stdenv.buildPlatform.config}" 80 ]; 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 - }; 88 }
··· 1 + { lib, stdenv, fetchurl, bison, buildPackages, pkgsBuildTarget }: 2 3 let 4 + mkJam = { pname, version, src, meta ? { } }: stdenv.mkDerivation { 5 + inherit pname version src; 6 + 7 depsBuildBuild = [ buildPackages.stdenv.cc ]; 8 nativeBuildInputs = [ bison ]; 9 10 # Jambase expects ar to have flags. 11 preConfigure = '' 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 30 ''; 31 32 LOCATE_TARGET = "bin.unix"; ··· 49 50 enableParallelBuilding = true; 51 52 + meta = with lib; { 53 license = licenses.free; 54 mainProgram = "jam"; 55 platforms = platforms.unix; 56 + } // meta; 57 + }; 58 in 59 { 60 jam = let 61 pname = "jam"; 62 version = "2.6.1"; 63 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 + }; 71 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 + }; 77 }; 78 + in base.overrideAttrs (oldAttrs: { 79 + makeFlags = (oldAttrs.makeFlags or []) ++ [ 80 + "CC=${buildPackages.stdenv.cc.targetPrefix}cc" 81 + ]; 82 + }); 83 84 ftjam = let 85 pname = "ftjam"; 86 version = "2.5.2"; 87 88 + base = mkJam { 89 + inherit pname version; 90 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 "") + '' 104 substituteInPlace Jamfile --replace strip ${stdenv.cc.targetPrefix}strip 105 ''; 106 107 # Doesn't understand how to cross compile once bootstrapped, so we'll just 108 # use the Makefile for the bootstrapping portion. 109 configurePlatforms = [ "build" "target" ]; 110 + configureFlags = (oldAttrs.configureFlags or []) ++ [ 111 "CC=${buildPackages.stdenv.cc.targetPrefix}cc" 112 "--host=${stdenv.buildPlatform.config}" 113 ]; 114 + }); 115 }