summary refs log tree commit diff
path: root/pkgs/os-specific/bsd
diff options
context:
space:
mode:
authorMatthew Bauer <mjbauer95@gmail.com>2018-04-30 19:59:33 -0500
committerMatthew Bauer <mjbauer95@gmail.com>2018-04-30 19:59:33 -0500
commit1c86f0cc4683e055df981cded464464cb48e05aa (patch)
tree04a8a6ed5458d06db098b32ed4993ce73ff99e74 /pkgs/os-specific/bsd
parentf3062702096f42c6a2349693bf776e17fb8dd4d9 (diff)
downloadnixpkgs-1c86f0cc4683e055df981cded464464cb48e05aa.tar
nixpkgs-1c86f0cc4683e055df981cded464464cb48e05aa.tar.gz
nixpkgs-1c86f0cc4683e055df981cded464464cb48e05aa.tar.bz2
nixpkgs-1c86f0cc4683e055df981cded464464cb48e05aa.tar.lz
nixpkgs-1c86f0cc4683e055df981cded464464cb48e05aa.tar.xz
nixpkgs-1c86f0cc4683e055df981cded464464cb48e05aa.tar.zst
nixpkgs-1c86f0cc4683e055df981cded464464cb48e05aa.zip
netbsd: cleanup bootstrapping
Diffstat (limited to 'pkgs/os-specific/bsd')
-rw-r--r--pkgs/os-specific/bsd/netbsd/default.nix242
1 files changed, 133 insertions, 109 deletions
diff --git a/pkgs/os-specific/bsd/netbsd/default.nix b/pkgs/os-specific/bsd/netbsd/default.nix
index 4961ab6080a..aea0ddac302 100644
--- a/pkgs/os-specific/bsd/netbsd/default.nix
+++ b/pkgs/os-specific/bsd/netbsd/default.nix
@@ -10,10 +10,11 @@ let
   };
 
   netBSDDerivation = attrs: stdenv.mkDerivation ((rec {
-    name = "${attrs.pname or (baseNameOf attrs.path)}-netbsd-${attrs.version}";
+    name = "bsd-${attrs.pname or (baseNameOf attrs.path)}-netbsd-${attrs.version}";
     src = attrs.src or fetchNetBSD attrs.path attrs.version attrs.sha256;
 
     extraPaths = [ ];
+    setOutputFlags = false;
 
     nativeBuildInputs = [ makeMinimal mandoc groff install stat
                           yacc flex tsort lorder ];
@@ -25,17 +26,24 @@ let
     DESTDIR = "$(out)";
     TOOLDIR = "$(out)";
     USETOOLS = "never";
-    NOCLANGERROR="yes";
-    NOGCCERROR="yes";
+    NOCLANGERROR = "yes";
+    NOGCCERROR = "yes";
     LEX = "flex";
+    MKUNPRIVED = "yes";
+    INSTPRIV = '' ''${INSTPRIV.unpriv}'';
+    HOST_SH = "${bash}/bin/sh";
+    OBJCOPY = if stdenv.isDarwin then "true" else "objcopy";
+    PRESERVE = "-p";
+    MACHINE_ARCH = hostPlatform.parsed.cpu.name;
+    MACHINE_CPU = hostPlatform.parsed.cpu.name;
 
     # libs will be provided by cc-wrapper
-    LIBCRT0="";
-    LIBCRTI="";
-    LIBCRTEND="";
-    LIBCRTBEGIN="";
-    LIBC="";
-    LIBUTIL="";
+    LIBCRT0 = "";
+    LIBCRTI = "";
+    LIBCRTEND = "";
+    LIBCRTBEGIN = "";
+    LIBC = "";
+    LIBUTIL = "";
     LIBSSL = "";
     LIBCRYPTO = "";
     LIBCRYPT = "";
@@ -43,8 +51,6 @@ let
     LIBTERMINFO = "";
     LIBM = "";
     LIBL = "";
-    "LIBDO.terminfo" = "_external";
-    "LIBDO.curses" = "_external";
     _GCC_CRTBEGIN = "";
     _GCC_CRTBEGINS = "";
     _GCC_CRTEND = "";
@@ -54,10 +60,14 @@ let
     _GCC_CRTDIR = "";
     _GCC_CRTN = "";
 
+    "LIBDO.terminfo" = "_external";
+    "LIBDO.curses" = "_external";
+
     # all dirs will be prefixed with DESTDIR
     BINDIR = "/bin";
     LIBDIR = "/lib";
     SHLIBDIR = "/lib";
+    INCSDIR = "/include";
     MANDIR = "/share/man";
     INFODIR = "/share/info";
     DOCDIR = "/share/doc";
@@ -65,22 +75,12 @@ let
     X11BINDIR = "/bin";
     X11USRLIBDIR = "/lib";
     X11MANDIR = "/share/man";
-    SHLINKDIR = "/usr/libexec";
-
-    HOST_SH = "${bash}/bin/sh";
-
-    SHLIB_WARNTEXTREL = "no";
-    SHLIB_MKMAP = "no";
-    PRESERVE = "-p";
-    OBJCOPY = if stdenv.isDarwin then "true" else "objcopy";
-
-    MACHINE_ARCH = hostPlatform.parsed.cpu.name;
-    MACHINE_CPU = hostPlatform.parsed.cpu.name;
 
     # NetBSD makefiles should be able to detect this
     # but without they end up using gcc on Darwin stdenv
     preConfigure = ''
       export HAVE_${if stdenv.cc.isGNU then "GCC" else "LLVM"}=${lib.head (lib.splitString "." (lib.getVersion stdenv.cc.cc))}
+
       # Parallel building. Needs the space.
       export makeFlags+=" -j $NIX_BUILD_CORES"
     '';
@@ -91,6 +91,7 @@ let
       sourceRoot=$PWD/$sourceRoot
       export NETBSDSRCDIR=$sourceRoot
       export BSDSRCDIR=$NETBSDSRCDIR
+      export _SRC_TOP_=$NETBSDSRCDIR
       chmod -R u+w $sourceRoot
       for path in $extraPaths; do
         cd $path
@@ -109,15 +110,14 @@ let
     # will be removed in the postInstall.
     preInstall = ''
       mkdir -p $out$BINDIR $out$LIBDIR $out$INFODIR \
-               $out$DOCDIR $out$LOCALEDIR
+               $out$DOCDIR $out$LOCALEDIR $out$INCSDIR
       for i in 1 2 3 4 5 6 7 8 9; do
         mkdir -p $out$MANDIR/man$i $out$MANDIR/html$i \
                  $out$DOCDIR/reference/ref$i
       done
-      mkdir -p $out/usr/include
     '';
 
-    postInstall = ''
+    preFixup = ''
       # Remove lingering /usr references
       if [ -d $out/usr ]; then
         cd $out/usr
@@ -125,6 +125,10 @@ let
         find . -type f -exec mv \{} $out/\{} \;
       fi
 
+      if [ -f $out/METALOG ]; then
+        rm $out/METALOG
+      fi
+
       find $out -type d -empty -delete
     '';
 
@@ -135,7 +139,9 @@ let
     };
   }) // attrs);
 
-  # BOOTSTRAPPING
+  ##
+  ## BOOTSTRAPPING
+  ##
   makeMinimal = netBSDDerivation rec {
     path = "tools/make";
     sha256 = "0l4794zwj2haark3azf9xwcwqlkbrifhb2glaa9iba4dkg2mklsb";
@@ -144,16 +150,26 @@ let
     buildInputs = [];
     nativeBuildInputs = [];
 
-    patchPhase = ''
+    postPatch = ''
       patchShebangs configure
-      ${make.patchPhase}
+      ${make.postPatch}
+    '';
+    buildPhase = ''
+      runHook prePatch
+
+      sh ./buildmake.sh
+
+      runHook postPatch
     '';
-    buildPhase = "sh ./buildmake.sh";
     installPhase = ''
+      runHook preInstall
+
       install -D nbmake $out/bin/nbmake
       ln -s $out/bin/nbmake $out/bin/make
       mkdir -p $out/share
-      cp -r ../../share/mk $out/share/mk
+      cp -r $NETBSDSRCDIR/share/mk $out/share/mk
+
+      runHook postInstall
     '';
     extraPaths = [ make.src ] ++ make.extraPaths;
   };
@@ -171,7 +187,8 @@ let
 
     # temporarily use gnuinstall for bootstrapping
     # bsdinstall will be built later
-    makeFlags = "INSTALL=${coreutils}/bin/install";
+    makeFlags = [ "INSTALL=${coreutils}/bin/install" ];
+    installFlags = [];
     RENAME = "-D";
 
     postInstall = ''
@@ -219,7 +236,17 @@ let
     extraPaths = [ mtree.src make.src ];
     nativeBuildInputs = [ makeMinimal mandoc groff ];
     buildInputs = [ compat fts ];
-    RENAME = "-D";
+    installPhase = ''
+      runHook preInstall
+
+      install -D install.1 $out/share/man/man1/install.1
+      install -D xinstall $out/bin/install
+      ln -s $out/bin/install $out/bin/xinstall
+      ln -s $out/bin/install $out/bin/binstall
+
+      runHook postInstall
+    '';
+    # INSTALL_FILE = "install -D";
   };
 
   fts = netBSDDerivation {
@@ -240,10 +267,14 @@ let
       ar -rsc libfts.a lib/libc/gen/fts.o
     '';
     installPhase = ''
+      runHook preInstall
+
       install -D lib/libc/gen/fts.3 $out/share/man/man3/fts.3
       install -D include/fts.h $out/include/fts.h
       install -D lib/libc/include/namespace.h $out/include/namespace.h
       install -D libfts.a $out/lib/libfts.a
+
+      runHook postInstall
     '';
     setupHook = ./fts-setup-hook.sh;
   };
@@ -268,7 +299,9 @@ let
     sha256 = "0rjf9blihhm0n699vr2bg88m4yjhkbxh6fxliaay3wxkgnydjwn2";
     nativeBuildInputs = [ makeMinimal mandoc groff install ];
   };
-  # END BOOTSTRAPPING
+  ##
+  ## END BOOTSTRAPPING
+  ##
 
   libutil = netBSDDerivation {
     path = "lib/libutil";
@@ -292,44 +325,31 @@ let
     path = "usr.bin/make";
     sha256 = "0srkkg6qdzqlccfi4xh19gl766ks6hpss76bnfvwmd0zg4q4zdar";
     version = "7.1.2";
-    patchPhase = ''
+    postPatch = ''
       # make needs this to pick up our sys make files
       export NIX_CFLAGS_COMPILE+=" -D_PATH_DEFSYSPATH=\"$out/share/mk\""
 
-      # can't set owner or group in Nix build
-      # maybe there is a better way to trick it?
       substituteInPlace $NETBSDSRCDIR/share/mk/bsd.prog.mk \
-        --replace '-o ''${SCRIPTSOWN_''${.ALLSRC:T}:U''${SCRIPTSOWN}}' "" \
-        --replace '-g ''${SCRIPTSGRP_''${.ALLSRC:T}:U''${SCRIPTSGRP}}' "" \
-        --replace '-o ''${RUMPBINOWN} -g ''${RUMPBINGRP}' "" \
-        --replace '-o ''${BINOWN} -g ''${BINGRP}' "" \
-        --replace '-o ''${RUMPBINOWN} -g ''${RUMPBINGRP}' "" \
-        --replace '-o ''${DEBUGOWN} -g ''${DEBUGGRP}' ""
-      substituteInPlace $NETBSDSRCDIR/share/mk/bsd.doc.mk \
-        --replace '-o ''${DOCOWN} -g ''${DOCGRP}' ""
-      substituteInPlace $NETBSDSRCDIR/share/mk/bsd.links.mk \
-        --replace '-o ''${LINKSOWN_''${.ALLSRC:T}:U''${LINKSOWN}}' "" \
-        --replace '-g ''${LINKSGRP_''${.ALLSRC:T}:U''${LINKSGRP}}' ""
-      substituteInPlace $NETBSDSRCDIR/share/mk/bsd.man.mk \
-        --replace '-o ''${MANOWN} -g ''${MANGRP}' ""
-      substituteInPlace $NETBSDSRCDIR/share/mk/bsd.files.mk \
-        --replace '-o ''${FILESOWN_''${.ALLSRC:T}:U''${FILESOWN}}' "" \
-        --replace '-g ''${FILESGRP_''${.ALLSRC:T}:U''${FILESGRP}}' ""
-      substituteInPlace $NETBSDSRCDIR/share/mk/bsd.inc.mk \
-        --replace '-o ''${BINOWN} -g ''${BINGRP}' ""
-      substituteInPlace $NETBSDSRCDIR/share/mk/bsd.lib.mk \
-        --replace '-o ''${DEBUGOWN} -g ''${DEBUGGRP}' "" \
-        --replace '-o ''${LIBOWN} -g ''${LIBGRP}' ""
+        --replace '-Wl,-dynamic-linker=''${_SHLINKER}' "" \
+        --replace '-Wl,-rpath,''${SHLIBDIR}' ""
     '' + lib.optionalString stdenv.isDarwin ''
       substituteInPlace $NETBSDSRCDIR/share/mk/bsd.sys.mk \
-        --replace '-Wl,--fatal-warnings' ""
+        --replace '-Wl,--fatal-warnings' "" \
+        --replace '-Wl,--warn-shared-textrel' ""
       substituteInPlace $NETBSDSRCDIR/share/mk/bsd.lib.mk \
         --replace '-Wl,-soname,''${_LIB}.so.''${SHLIB_SOVERSION}' "" \
         --replace '-Wl,--whole-archive' "" \
-        --replace '-Wl,--no-whole-archive' ""
+        --replace '-Wl,--no-whole-archive' "" \
+        --replace '-Wl,--warn-shared-textrel' "" \
+        --replace '-Wl,-Map=''${_LIB}.so.''${SHLIB_SOVERSION}.map' "" \
+        --replace '-Wl,-rpath,''${SHLIBDIR}' ""
+    '';
+    preInstall = ''
+      mkdir -p $out$BINDIR $out$DOCDIR/reference/ref1/make \
+               $out$MANDIR/man1 $out$MANDIR/html1 $out/share/mk
     '';
     postInstall = ''
-      (cd $NETBSDSRCDIR/share/mk && make install)
+      (cd $NETBSDSRCDIR/share/mk && make FILESDIR=/share/mk install)
     '';
     extraPaths = [
       (fetchNetBSD "share/mk" "7.1.2" "0570v0siv0wygn8ygs1yy9pgk9xjw9x1axr5qg4xrddv3lskf9xa")
@@ -346,17 +366,23 @@ let
     path = "usr.bin/who";
     version = "7.1.2";
     sha256 = "17ffwww957m3qw0b6fkgjpp12pd5ydg2hs9dxkkw0qpv11j00d88";
-    patchPhase = ''
+    postPatch = lib.optionalString stdenv.isLinux ''
       substituteInPlace $NETBSDSRCDIR/usr.bin/who/utmpentry.c \
-        --replace "strncpy(e->name, up->ut_name, sizeof(up->ut_name))" "strncpy(e->name, up->ut_user, sizeof(up->ut_user))" \
         --replace "utmptime = st.st_mtimespec" "utmptime = st.st_mtim" \
-        --replace "timespeccmp(&st.st_mtimespec, &utmptime, >)" "st.st_mtim.tv_sec == utmptime.tv_sec ? st.st_mtim.tv_nsec > utmptime.tv_nsec : st.st_mtim.tv_sec > utmptime.tv_sec" \
-        --replace "timespecclear(&utmptime)" "utmptime.tv_sec = utmptime.tv_nsec = 0"
+        --replace "timespeccmp(&st.st_mtimespec, &utmptime, >)" "st.st_mtim.tv_sec == utmptime.tv_sec ? st.st_mtim.tv_nsec > utmptime.tv_nsec : st.st_mtim.tv_sec > utmptime.tv_sec"
+   '' + lib.optionalString stdenv.isDarwin ''
+      substituteInPlace $NETBSDSRCDIR/usr.bin/who/utmpentry.c \
+        --replace "timespeccmp(&st.st_mtimespec, &utmpxtime, >)" "st.st_mtimespec.tv_sec == utmpxtime.tv_sec ? st.st_mtimespec.tv_nsec > utmpxtime.tv_nsec : st.st_mtimespec.tv_sec > utmpxtime.tv_sec"
+   '' + ''
+      substituteInPlace $NETBSDSRCDIR/usr.bin/who/utmpentry.c \
+        --replace "strncpy(e->name, up->ut_name, sizeof(up->ut_name))" "strncpy(e->name, up->ut_user, sizeof(up->ut_user))" \
+        --replace "timespecclear(&utmptime)" "utmptime.tv_sec = utmptime.tv_nsec = 0" \
+        --replace "timespecclear(&utmpxtime)" "utmpxtime.tv_sec = utmpxtime.tv_nsec = 0"
     '';
   };
 
 in rec {
-  inherit compat install netBSDDerivation fts;
+  inherit compat install netBSDDerivation fts make;
 
   getent = netBSDDerivation {
     path = "usr.bin/getent";
@@ -375,23 +401,26 @@ in rec {
     path = "share/dict";
     version = "7.1.2";
     sha256 = "0nickhsjwgnr2h9nvwflvgfz93kqms5hzdnpyq02crpj35w98bh4";
-    preBuild = "mkdir -p $out/share/dict";
     makeFlags = [ "BINDIR=/share" ];
+    preInstall = "mkdir -p $out/share/dict";
   };
 
   games = netBSDDerivation {
     path = "games";
     sha256 = "04wjsang8f8kxsifiayklbxaaxmm3vx9rfr91hfbxj4hk8gkqzy1";
     version = "7.1.2";
-    patchPhase = ''
+    makeFlags = [ "BINDIR=/bin"
+                  "SCRIPTSDIR=/bin"
+                  "FILESDIR=/share/games" ];
+    postPatch = ''
       sed -i '1i #include <time.h>' adventure/save.c
 
       for f in $(find . -name pathnames.h); do
         substituteInPlace $f \
+          --replace /usr/share/games/fortune $out/share/games \
           --replace /usr/share/games $out/share/games \
           --replace /usr/games $out/bin \
           --replace /usr/libexec $out/libexec \
-          --replace /var/games $out/var/games \
           --replace /usr/bin/more ${more}/bin/more \
           --replace /usr/share/dict ${dict}/share/dict
       done
@@ -424,13 +453,11 @@ in rec {
         --replace 2550 550
     '';
 
-    # HACK strfile needs to be installed first & in the path
+    # HACK strfile needs to be installed first & in the path. The
+    # Makefile should do this for us but haven't gotten it to work
     preBuild = ''
-      pushd fortune/strfile
       mkdir -p $out/bin $out/share/man/man8 $out/share/man/html8
-      make
-      make BINDIR=/bin install
-      popd
+      (cd fortune/strfile && make && make BINDIR=/bin install)
       export PATH=$out/bin:$PATH
     '';
 
@@ -447,38 +474,37 @@ in rec {
       "-D__c99inline=__inline"
     ];
 
-    postBuild = ''
-      mkdir -p $out/usr/games $out/usr/share/games/ching \
-               $out/usr/share/games/fortune \
-               $out/usr/share/games/quiz.db \
-               $out/usr/share/games/boggle \
-               $out/usr/libexec/ching $out/var/games/hackdir
+    preInstall = ''
+      mkdir -p $out/var/games/hackdir \
+               $out/share/games \
+               $out$DOCDIR/reference/ref6/rogue \
+               $out$MANDIR/man6 $out$MANDIR/html6
       touch $out/var/games/hackdir/perm
     '';
 
-    preFixup = ''
-      mkdir -p $out/bin
-      mv $out/games/* $out/bin
-      rmdir $out/games
-    '';
-
     buildInputs = [ compat libcurses libterminfo libressl ];
     extraPaths = [ dict.src who.src ];
   };
 
-  # finger = netBSDDerivation {
-  #   path = "usr.bin/finger";
-  #   sha256 = "0jl672z50f2yf7ikp682b3xrarm6bnrrx9vi94xnp2fav8m8zfyi";
-  #   version = "7.1.2";
-  #   extraPaths = [ who.src ];
-  #   NIX_CFLAGS_COMPILE = [
-  #     "-DSUPPORT_UTMP"
-  #     "-USUPPORT_UTMPX"
-  #   ];
-  #   patchPhase = ''
-  #     ${who.patchPhase}
-  #   '';
-  # };
+  finger = netBSDDerivation {
+    path = "usr.bin/finger";
+    sha256 = "0jl672z50f2yf7ikp682b3xrarm6bnrrx9vi94xnp2fav8m8zfyi";
+    version = "7.1.2";
+    NIX_CFLAGS_COMPILE = [
+      (if stdenv.isLinux then "-DSUPPORT_UTMP" else "-USUPPORT_UTMP")
+      (if stdenv.isDarwin then "-DSUPPORT_UTMPX" else "-USUPPORT_UTMPX")
+    ];
+    postPatch = ''
+      NIX_CFLAGS_COMPILE+=" -I$NETBSDSRCDIR/include"
+
+      substituteInPlace extern.h \
+        --replace psort _psort
+
+      ${who.postPatch}
+    '';
+    extraPaths = [ who.src ]
+              ++ lib.optional stdenv.isDarwin (fetchNetBSD "include/utmp.h" "7.1.2" "05690fzz0825p2bq0sfyb00mxwd0wa06qryqgqkwpqk9y2xzc7px");
+  };
 
   fingerd = netBSDDerivation {
     path = "libexec/fingerd";
@@ -490,8 +516,8 @@ in rec {
     path = "lib/libedit";
     buildInputs = [ libterminfo libcurses ];
     propagatedBuildInputs = [ compat ];
-    postBuild = "mkdir -p $out/usr/include/readline";
-    patchPhase = ''
+    makeFlags = [ "INCSDIR=/include" ];
+    postPatch = ''
       sed -i '1i #undef bool_t' el.h
       substituteInPlace config.h \
         --replace "#define HAVE_STRUCT_DIRENT_D_NAMLEN 1" ""
@@ -511,16 +537,13 @@ in rec {
     sha256 = "06plg0bjqgbb0aghpb9qlk8wkp1l2izdlr64vbr5laqyw8jg84zq";
     buildInputs = [ compat tic nbperf ];
     MKPIC = if stdenv.isDarwin then "no" else "yes";
-    patchPhase = ''
-      substituteInPlace term.c \
-        --replace /usr/share $out/share
+    makeFlags = [ "INCSDIR=/include" ];
+    postPatch = ''
+      substituteInPlace term.c --replace /usr/share $out/share
     '';
-    postBuild = ''
-      pushd $NETBSDSRCDIR/share/terminfo
+    postInstall = ''
       mkdir -p $out/share/misc
-      make
-      make BINDIR=/share install
-      popd
+      (cd $NETBSDSRCDIR/share/terminfo && make && make BINDIR=/share install)
     '';
     extraPaths = [
       (fetchNetBSD "share/terminfo" "7.1.2" "1z5vzq8cw24j05r6df4vd6r57cvdbv7vbm4h962kplp14xrbg2h3")
@@ -532,6 +555,7 @@ in rec {
     version = "7.1.2";
     sha256 = "04djah9dadzw74nswn0xydkxn900kav8xdvxlxdl50nbrynxg9yf";
     buildInputs = [ libterminfo ];
+    makeFlags = [ "INCSDIR=/include" ];
     NIX_CFLAGS_COMPILE = [
       "-D__scanflike(a,b)="
       "-D__va_list=va_list"
@@ -540,7 +564,7 @@ in rec {
     propagatedBuildInputs = [ compat ];
     MKDOC = "no"; # missing vfontedpr
     MKPIC = if stdenv.isDarwin then "no" else "yes";
-    patchPhase = lib.optionalString (!stdenv.isDarwin) ''
+    postPatch = lib.optionalString (!stdenv.isDarwin) ''
       substituteInPlace printw.c \
         --replace "funopen(win, NULL, __winwrite, NULL, NULL)" NULL \
         --replace "__strong_alias(vwprintw, vw_printw)" 'extern int vwprintw(WINDOW*, const char*, va_list) __attribute__ ((alias ("vw_printw")));'