git.iko.soy/typeable/nixpkgs
on master help sign in
Merge pull request #66404 from eraserhd/pr/master/plan9port-mac-compiler-fixes

plan9port: use C compiler from Nix

commit868bf106f1d55da39d6960de9602382b8e80854f authorAnderson Torres <torres.anderson.85@protonmail.com> dateTue 10 Sep 2019, 07:45 (7 years ago) parenta69a6c151faa42
5 files changed+185−30
pkgs/tools/system/plan9port/builder.sh+51−8 pkgs/tools/system/plan9port/darwin-cfframework.patch+24 pkgs/tools/system/plan9port/darwin-sw_vers.patch+47 pkgs/tools/system/plan9port/default.nix+22−22 pkgs/tools/system/plan9port/tmpdir.patch+41
pkgs/tools/system/plan9port/builder.sh+51−8
@@ -3,11 +3,40 @@ source $stdenv/setup
33export PLAN9=$out/plan9
44export PLAN9_TARGET=$PLAN9
55
6+plan9portLinkFlags()
7+{
8+ local -a linkFlags=()
9+ eval set -- "$NIX_LDFLAGS"
10+ while (( $# > 0 )); do
11+ if [[ $1 = -rpath ]]; then
12+ linkFlags+=( "-Wl,-rpath,$2" )
13+ shift 2
14+ else
15+ linkFlags+=( "$1" )
16+ shift
17+ fi
18+ done
19+ echo "${linkFlags[*]}"
20+}
21+
622configurePhase()
723{
8− echo CFLAGS=\"-I${fontconfig_dev}/include -I${xorgproto_exp}/include -I${libX11_dev}/include -I${libXt_dev}/include -I${libXext_dev}/include -I${freetype_dev}/include -I${zlib_dev}/include\" > LOCAL.config
9− echo LDFLAGS=\"-L${fontconfig_lib}/lib -L${xorgproto_exp}/lib -L${libX11_exp}/lib -L${libXt_exp}/lib -L${libXext_exp}/lib -L${freetype_exp}/lib -L${zlib_exp}/lib\" >> LOCAL.config
10− echo X11=\"${libXt_dev}/include\" >> LOCAL.config
24+ (
25+ echo CC9=\"$(which $CC)\"
26+ echo CFLAGS=\"$NIX_CFLAGS_COMPILE\"
27+ echo LDFLAGS=\"$(plan9portLinkFlags)\"
28+ echo X11=\"${libXt_dev}/include\"
29+ case "$system" in
30+ x86_64-*) echo OBJTYPE=x86_64;;
31+ i?86-*) echo OBJTYPE=386;;
32+ *power*) echo OBJTYPE=power;;
33+ *sparc*) echo OBJTYPE=sparc;;
34+ *) exit 12
35+ esac
36+ if [[ $system =~ .*linux.* ]]; then
37+ echo SYSVERSION=2.6.x
38+ fi
39+ ) >config
1140
1241 for f in `grep -l -r /usr/local/plan9`; do
1342 sed "s,/usr/local/plan9,${PLAN9},g" -i $f
@@ -17,15 +46,29 @@ configurePhase()
1746buildPhase()
1847{
1948 mkdir -p $PLAN9
20− ./INSTALL -b
49+
50+ # Copy sources, some necessary bin scripts
51+ cp -R * $PLAN9
52+
53+ local originalPath="$PATH"
54+ export PATH="$PLAN9/bin:$PATH"
55+ export NPROC=$NIX_BUILD_CORES
56+ pushd src
57+ ../dist/buildmk
58+ mk clean
59+ mk libs-nuke
60+ mk all
61+ mk -k install
62+ if [[ -f $PLAN9/bin/quote1 ]]; then
63+ cp $PLAN9/bin/quote1 $PLAN9/bin/'"'
64+ cp $PLAN9/bin/quote2 $PLAN9/bin/'""'
65+ fi
66+ popd
67+ export PATH="$originalPath"
2168}
2269
2370installPhase()
2471{
25− ./INSTALL -c
26− # Copy sources
27− cp -R * $PLAN9
28−
2972 # Copy the `9' utility. This way you can use
3073 # $ 9 awk
3174 # to use the plan 9 awk
pkgs/tools/system/plan9port/darwin-cfframework.patchnew file+24
@@ -0,0 +1,24 @@
1+From d1f0bd3de7d3d54523aeefd9731ea850d20eaab4 Mon Sep 17 00:00:00 2001
2+From: Jason Felice <jason.m.felice@gmail.com>
3+Date: Tue, 2 Jul 2019 13:19:23 -0400
4+Subject: [PATCH] Need CoreFoundation
5+
6+---
7+ src/cmd/devdraw/cocoa-screen.m | 1 +
8+ 1 file changed, 1 insertion(+)
9+
10+diff --git a/src/cmd/devdraw/cocoa-screen.m b/src/cmd/devdraw/cocoa-screen.m
11+index 97128da2..0e380dd3 100644
12+--- a/src/cmd/devdraw/cocoa-screen.m
13++++ b/src/cmd/devdraw/cocoa-screen.m
14+@@ -56,6 +56,7 @@
15+ #endif
16+
17+ AUTOFRAMEWORK(Cocoa)
18++AUTOFRAMEWORK(CoreFoundation)
19+
20+ #define LOG if(0)NSLog
21+ #define panic sysfatal
22+--
23+2.21.0
24+
pkgs/tools/system/plan9port/darwin-sw_vers.patchnew file+47
@@ -0,0 +1,47 @@
1+From d21d082275f04f88eabcc8ecdb03ee932c71ebf1 Mon Sep 17 00:00:00 2001
2+From: Jason Felice <jason.m.felice@gmail.com>
3+Date: Mon, 1 Jul 2019 15:23:19 -0400
4+Subject: [PATCH 2/3] Build for 10.12
5+
6+---
7+ bin/osxvers | 3 +--
8+ src/cmd/devdraw/mkwsysrules.sh | 4 ++--
9+ 2 files changed, 3 insertions(+), 4 deletions(-)
10+
11+diff --git a/bin/osxvers b/bin/osxvers
12+index 4af44da2..3be7e6e9 100755
13+--- a/bin/osxvers
14++++ b/bin/osxvers
15+@@ -2,6 +2,5 @@
16+
17+ u=`uname`
18+ case "$u" in
19+-Darwin)
20+- sw_vers | awk '$1 == "ProductVersion:" {print $2}' | awk -F. '{printf("CFLAGS=$CFLAGS -DOSX_VERSION=%d%02d%02d\n", $1, $2, $3)}'
21++Darwin) printf 'CFLAGS=$CFLAGS -DOSX_VERSION=101200\n';;
22+ esac
23+diff --git a/src/cmd/devdraw/mkwsysrules.sh b/src/cmd/devdraw/mkwsysrules.sh
24+index e94afbd3..40e632db 100644
25+--- a/src/cmd/devdraw/mkwsysrules.sh
26++++ b/src/cmd/devdraw/mkwsysrules.sh
27+@@ -22,7 +22,7 @@ fi
28+
29+ if [ "x$WSYSTYPE" = "x" ]; then
30+ if [ "x`uname`" = "xDarwin" ]; then
31+- if sw_vers | grep 'ProductVersion: 10\.[0-5]\.' >/dev/null; then
32++ if false; then
33+ echo 1>&2 'OS X 10.5 and older are not supported'
34+ exit 1
35+ else
36+@@ -54,7 +54,7 @@ if [ $WSYSTYPE = x11 ]; then
37+ XO=`ls x11-*.c 2>/dev/null | sed 's/\.c$/.o/'`
38+ echo 'WSYSOFILES=$WSYSOFILES '$XO
39+ elif [ $WSYSTYPE = osx-cocoa ]; then
40+- if sw_vers|awk '/ProductVersion/{split($2,a,".");exit(a[2]<14)}' >/dev/null; then # 0 is true in sh.
41++ if false; then
42+ echo 'OBJCFLAGS=$OBJCFLAGS -fobjc-arc'
43+ echo 'WSYSOFILES=$WSYSOFILES osx-draw.o cocoa-screen-metal-objc.o cocoa-srv.o cocoa-thread.o'
44+ else
45+--
46+2.21.0
47+
pkgs/tools/system/plan9port/default.nix+22−22
@@ -1,7 +1,11 @@
1−{ stdenv, fetchFromGitHub, which, libX11, libXt, fontconfig, freetype
1+{ stdenv, fetchFromGitHub, which
2+, darwin ? null
23, xorgproto ? null
4+, libX11
35, libXext ? null
4−, zlib ? null
6+, libXt ? null
7+, fontconfig ? null
8+, freetype ? null
59, perl ? null # For building web manuals
610}:
711
@@ -16,14 +20,24 @@ stdenv.mkDerivation {
1620 sha256 = "1lp17948q7vpl8rc2bf5a45bc8jqyj0s3zffmks9r25ai42vgb43";
1721 };
1822
23+ patches = [
24+ ./tmpdir.patch
25+ ./darwin-sw_vers.patch
26+ ./darwin-cfframework.patch
27+ ];
28+
1929 postPatch = ''
2030 #hardcoded path
2131 substituteInPlace src/cmd/acme/acme.c \
2232 --replace /lib/font/bit $out/plan9/font
33+
2334 #deprecated flags
2435 find . -type f \
2536 -exec sed -i -e 's/_SVID_SOURCE/_DEFAULT_SOURCE/g' {} \; \
2637 -exec sed -i -e 's/_BSD_SOURCE/_DEFAULT_SOURCE/g' {} \;
38+
39+ substituteInPlace bin/9c \
40+ --replace 'which uniq' '${which}/bin/which uniq'
2741 '' + stdenv.lib.optionalString (!stdenv.isDarwin) ''
2842 #add missing ctrl+c\z\x\v keybind for non-Darwin
2943 substituteInPlace src/cmd/acme/text.c \
@@ -34,30 +48,16 @@ stdenv.mkDerivation {
3448 '';
3549
3650 buildInputs = [
37− which perl libX11 fontconfig xorgproto libXt libXext
51+ perl
52+ ] ++ stdenv.lib.optionals (!stdenv.isDarwin) [
53+ xorgproto libX11 libXext libXt fontconfig
3854 freetype # fontsrv wants ft2build.h provides system fonts for acme and sam.
39− ];
55+ ] ++ stdenv.lib.optionals stdenv.isDarwin (with darwin.apple_sdk.frameworks; [
56+ darwin.cf-private Carbon Cocoa IOKit Metal QuartzCore
57+ ]);
4058
4159 builder = ./builder.sh;
42−
43− libX11_dev = libX11.dev;
4460 libXt_dev = libXt.dev;
45− libXext_dev = libXext.dev;
46− fontconfig_dev = fontconfig.dev;
47− freetype_dev = freetype.dev;
48− zlib_dev = zlib.dev;
49−
50− xorgproto_exp = xorgproto;
51− libX11_exp = libX11;
52− libXt_exp = libXt;
53− libXext_exp = libXext;
54− freetype_exp = freetype;
55− zlib_exp = zlib;
56−
57− fontconfig_lib = fontconfig.lib;
58−
59− NIX_LDFLAGS="-lgcc_s";
60− enableParallelBuilding = true;
6161
6262 doInstallCheck = true;
6363 installCheckPhase = ''
pkgs/tools/system/plan9port/tmpdir.patchnew file+41
@@ -0,0 +1,41 @@
1+From c762625549ff367b54bcd8281d1ce248a69b4401 Mon Sep 17 00:00:00 2001
2+From: Jason Felice <jason.m.felice@gmail.com>
3+Date: Mon, 1 Jul 2019 15:01:21 -0400
4+Subject: [PATCH] Use $TMPDIR if available
5+
6+NixOS sandboxed builds (at least on Mac) don't have access to /tmp,
7+and this should be better POSIX.
8+---
9+ bin/9c | 2 +-
10+ bin/9l | 2 +-
11+ 2 files changed, 2 insertions(+), 2 deletions(-)
12+
13+diff --git a/bin/9c b/bin/9c
14+index 3ffb716c..88c47887 100755
15+--- a/bin/9c
16++++ b/bin/9c
17+@@ -133,7 +133,7 @@ case "$tag" in
18+ esac
19+
20+ # N.B. Must use temp file to avoid pipe; pipe loses status.
21+-xtmp=/tmp/9c.$$.$USER.out
22++xtmp=${TMPDIR-/tmp}/9c.$$.$USER.out
23+ $cc -DPLAN9PORT -I$PLAN9/include $cflags "$@" 2>$xtmp
24+ status=$?
25+ quiet $xtmp
26+diff --git a/bin/9l b/bin/9l
27+index 6195815f..717a540a 100755
28+--- a/bin/9l
29++++ b/bin/9l
30+@@ -346,7 +346,7 @@ then
31+ echo $ld -L$PLAN9/lib "$@" $libsl $extralibs $frameworks
32+ fi
33+
34+-xtmp=/tmp/9l.$$.$USER.out
35++xtmp="${TMPDIR-/tmp}/9l.$$.$USER.out"
36+ xxout() {
37+ sed 's/.*: In function `[^:]*: *//' $xtmp | egrep . |
38+ egrep -v 'is (often|almost always) misused|is dangerous, better use|text-based stub'
39+--
40+2.21.0
41+