3
0
Fork 0
forked from mirrors/nixpkgs

netbsd.compat: Fix cross compilation

Not to netbsd, where it isn't needed, but elsewhere.

A few things going on here:

 - Make compat use the "regular" not "host" makefile infra. This,
   however, makes more assumptions that the toolchain is BSD-like, and
   so we need to compensate for them with the likes of:

    - `LORDER=...` and `TSORT=...`

    - Move `export INSTALL_*` to install's setup hook so they don't interfere
      with coreutils install

 - Don't use `DESTDIR` for installing include files, instead set `INCSDIR`.
   This is more proper, but doesn't work when `INCSDIR` is set multiple
   times, unfortunately, as CLI defs override all other assignments. So
   instead set `INCSDIR0` on the CLI, and do some `INCSDIR =
   ${INCSDIR0}/...` in the relevant packages.

    - `INCSDIR` is set just in the NetBSD setup hook because FreeBSD uses
    `INCLUDEDIR`.
This commit is contained in:
John Ericson 2021-09-01 21:44:25 +00:00
parent af58c2cc0c
commit ad609d27b5
6 changed files with 204 additions and 20 deletions

View file

@ -0,0 +1,100 @@
commit 5acf3bdea5140e90135d15d6479f29fbf624f75e
Author: John Ericson <John.Ericson@Obsidian.Systems>
Date: Wed Sep 1 15:38:56 2021 +0000
Don't force building and installing for the build platform
Also remove `compat/` subdir from install directories.
diff --git a/Makefile b/Makefile
index 4bcf227f0e75..9ed1d6eea6ff 100644
--- a/Makefile
+++ b/Makefile
@@ -1,6 +1,6 @@
# $NetBSD: Makefile,v 1.87 2019/05/08 02:25:50 thorpej Exp $
-HOSTLIB= nbcompat
+LIB= nbcompat
.include <bsd.hostinit.mk>
@@ -94,63 +94,37 @@ include/.stamp:
# Install rules
-HOST_LIBDIR= ${TOOLDIR}/lib
-HOST_INCSDIR= ${TOOLDIR}/include
-HOST_SHAREDIR= ${TOOLDIR}/share
-
-install: .PHONY install.lib includes install.defs.mk
-
-# Install lib${HOSTLIB}.a in ${TOOLDIR}/lib
-install.lib: .PHONY ${HOST_LIBDIR}/lib${HOSTLIB}.a
-${HOST_LIBDIR}/lib${HOSTLIB}.a: lib${HOSTLIB}.a
- ${_MKTARGET_INSTALL}
- ${HOST_INSTALL_DIR} ${HOST_LIBDIR}
- ${HOST_INSTALL_FILE} -m ${LIBMODE} ${.ALLSRC} ${.TARGET}
+install: .PHONY includes install.defs.mk
.for _f in ${INCFILES}
-HOST_INCINSTFILES+= ${HOST_INCSDIR}/compat/${_f}
-${HOST_INCSDIR}/compat/${_f}: ${_f}
+INCINSTFILES+= ${INCSDIR}/${_f}
+${INCSDIR}/${_f}: ${_f}
${_MKTARGET_INSTALL}
- ${HOST_INSTALL_FILE} ${.ALLSRC} ${.TARGET}
+ ${INSTALL_FILE} ${.ALLSRC} ${.TARGET}
.endfor
.for _d in ${INCSUBDIRS}
-HOST_INCINSTDIRS+= ${HOST_INCSDIR}/compat/${_d}
-${HOST_INCSDIR}/compat/${_d}:
+INCINSTDIRS+= ${INCSDIR}/${_d}
+${INCSDIR}/${_d}:
${_MKTARGET_INSTALL}
- ${HOST_INSTALL_DIR} ${.TARGET}
+ ${INSTALL_DIR} ${.TARGET}
.endfor
-# Install include files in ${TOOLDIR}/include/compat
-includes: .PHONY ${HOST_INCINSTDIRS} .WAIT ${HOST_INCINSTFILES}
+# Install include files in ${INCSDIR}
+includes: .PHONY ${INCINSTDIRS} .WAIT ${INCINSTFILES}
@(cd include && find . -name '*.h' -print | while read f ; do \
- ${HOST_INSTALL_FILE} $$f ${HOST_INCSDIR}/compat/$$f ; \
+ ${INSTALL_FILE} $$f ${INCSDIR}/$$f ; \
done)
-# Install defs.mk in ${TOOLDIR}/share/compat
-install.defs.mk: .PHONY ${HOST_SHAREDIR}/compat/defs.mk
-${HOST_SHAREDIR}/compat/defs.mk: defs.mk
+# Install defs.mk in ${DATADIR}
+install.defs.mk: .PHONY ${DATADIR}/defs.mk
+${DATADIR}/defs.mk: defs.mk
${_MKTARGET_INSTALL}
- ${HOST_INSTALL_DIR} ${HOST_SHAREDIR}
- ${HOST_INSTALL_DIR} ${HOST_SHAREDIR}/compat
- ${HOST_INSTALL_FILE} ${.ALLSRC} ${.TARGET}
-
-# bsd.hostlib.mk wants HOST_CPPFLAGS, not CPPFLAGS
-
-HOST_CPPFLAGS:= ${CPPFLAGS}
-CPPFLAGS:= # empty
-
-.include <bsd.hostlib.mk>
-
-# Use uninstalled copy of host-mkdep
-HOST_MKDEP_OBJ!= cd ${.CURDIR}/../host-mkdep && ${PRINTOBJDIR}
-HOST_MKDEP= ${HOST_MKDEP_OBJ}/host-mkdep
-MKDEP= ${HOST_MKDEP}
+ ${INSTALL_DIR} ${DATADIR}
+ ${INSTALL_FILE} ${.ALLSRC} ${.TARGET}
-# Use uninstalled copy of the install program
-INSTALL_OBJ!= cd ${NETBSDSRCDIR}/tools/binstall && ${PRINTOBJDIR}
-INSTALL= ${INSTALL_OBJ}/xinstall
+.include <bsd.lib.mk>
# Run "${TOOLDIR}/bin/nbmake-${MACHINE} regen" by hand after editing
# configure.ac. See more detailed instructions in configure.ac.

View file

@ -175,11 +175,6 @@ in lib.makeScopeWithSplicing
"--cache-file=config.cache"
];
# the build system re-runs `./configure` with `HOST_CC` (which is their
# name for Build CC) as a compiler to make `defs.mk`, which is installed
depsBuildBuild = [ buildPackages.stdenv.cc ] ++ commonDeps;
HOST_CC = "${buildPackages.stdenv.cc.targetPrefix}cc";
nativeBuildInputs = with buildPackages.netbsd; commonDeps ++ [
bsdSetupHook netbsdSetupHook
makeMinimal
@ -192,19 +187,26 @@ in lib.makeScopeWithSplicing
# bsdinstall will be built later
makeFlags = [
"INSTALL=${buildPackages.coreutils}/bin/install"
"TOOLDIR=$(out)"
"DATADIR=$(out)/share"
# Can't sort object files yet
"LORDER=echo"
"TSORT=cat"
];
RENAME = "-D";
patches = [
./compat-cxx-safe-header.patch
./compat-dont-configure-twice.patch
./compat-no-force-native.patch
];
postInstall = ''
mv $out/include/compat/* $out/include
rmdir $out/include/compat
preInstall = ''
makeFlagsArray+=('INSTALL_FILE=''${INSTALL} ''${COPY} ''${PRESERVE} ''${RENAME}')
makeFlagsArray+=('INSTALL_DIR=''${INSTALL} -d')
makeFlagsArray+=('INSTALL_SYMLINK=''${INSTALL} ''${SYMLINK} ''${RENAME}')
'';
postInstall = ''
# why aren't these installed by netbsd?
install -D compat_defs.h $out/include/compat_defs.h
install -D $BSDSRCDIR/include/cdbw.h $out/include/cdbw.h
@ -273,6 +275,7 @@ in lib.makeScopeWithSplicing
runHook postInstall
'';
setupHook = ./install-setup-hook.sh;
};
fts = mkDerivation {
@ -366,7 +369,41 @@ in lib.makeScopeWithSplicing
path = "usr.bin/make";
sha256 = "0vi73yicbmbp522qzqvd979cx6zm5jakhy77xh73c1kygf8klccs";
version = "9.2";
postPatch = ''
postPatch = ''
substituteInPlace $BSDSRCDIR/share/mk/bsd.doc.mk \
--replace '-o ''${DOCOWN}' "" \
--replace '-g ''${DOCGRP}' ""
for mk in $BSDSRCDIR/share/mk/bsd.inc.mk $BSDSRCDIR/share/mk/bsd.kinc.mk; do
substituteInPlace $mk \
--replace '-o ''${BINOWN}' "" \
--replace '-g ''${BINGRP}' ""
done
substituteInPlace $BSDSRCDIR/share/mk/bsd.kmodule.mk \
--replace '-o ''${KMODULEOWN}' "" \
--replace '-g ''${KMODULEGRP}' ""
substituteInPlace $BSDSRCDIR/share/mk/bsd.lib.mk \
--replace '-o ''${LIBOWN}' "" \
--replace '-g ''${LIBGRP}' "" \
--replace '-o ''${DEBUGOWN}' "" \
--replace '-g ''${DEBUGGRP}' ""
substituteInPlace $BSDSRCDIR/share/mk/bsd.lua.mk \
--replace '-o ''${LIBOWN}' "" \
--replace '-g ''${LIBGRP}' ""
substituteInPlace $BSDSRCDIR/share/mk/bsd.man.mk \
--replace '-o ''${MANOWN}' "" \
--replace '-g ''${MANGRP}' ""
substituteInPlace $BSDSRCDIR/share/mk/bsd.nls.mk \
--replace '-o ''${NLSOWN}' "" \
--replace '-g ''${NLSGRP}' ""
substituteInPlace $BSDSRCDIR/share/mk/bsd.prog.mk \
--replace '-o ''${BINOWN}' "" \
--replace '-g ''${BINGRP}' "" \
--replace '-o ''${RUMPBINOWN}' "" \
--replace '-g ''${RUMPBINGRP}' "" \
--replace '-o ''${DEBUGOWN}' "" \
--replace '-g ''${DEBUGGRP}' ""
# make needs this to pick up our sys make files
export NIX_CFLAGS_COMPILE+=" -D_PATH_DEFSYSPATH=\"$out/share/mk\""
@ -506,6 +543,22 @@ in lib.makeScopeWithSplicing
makeMinimal
install mandoc groff rsync nbperf rpcgen
];
# The makefiles define INCSDIR per subdirectory, so we have to set
# something else on the command line so those definitions aren't
# overridden.
postPatch = ''
find "$BSDSRCDIR" -name Makefile -exec \
sed -i -E \
-e 's_/usr/include_''${INCSDIR0}_' \
{} \;
'';
# multiple header dirs, see above
postConfigure = ''
makeFlags=''${makeFlags/INCSDIR/INCSDIR0}
'';
extraPaths = with self; [ common ];
headersOnly = true;
noCC = true;
@ -521,9 +574,17 @@ in lib.makeScopeWithSplicing
version = "9.2";
sha256 = "03s18q8d9giipf05bx199fajc2qwikji0djz7hw63d2lya6bfnpj";
# Fix this error when building bootia32.efi and bootx64.efi:
# error: PHDR segment not covered by LOAD segment
patches = [ ./no-dynamic-linker.patch ];
patches = [
# Fix this error when building bootia32.efi and bootx64.efi:
# error: PHDR segment not covered by LOAD segment
./no-dynamic-linker.patch
# multiple header dirs, see above
./sys-headers-incsdir.patch
];
# multiple header dirs, see above
inherit (self.include) postPatch;
CONFIG = "GENERIC";
@ -537,7 +598,9 @@ in lib.makeScopeWithSplicing
pushd arch/$MACHINE/conf
config $CONFIG
popd
'';
''
# multiple header dirs, see above
+ self.include.postConfigure;
makeFlags = [ "FIRMWAREDIR=$(out)/libdata/firmware" ];
hardeningDisable = [ "pic" ];

View file

@ -0,0 +1,8 @@
addNetBSDInstallMakeFlags() {
export INSTALL_FILE="install -U -c"
export INSTALL_DIR="install -U -d"
export INSTALL_LINK="install -U -l h"
export INSTALL_SYMLINK="install -U -l s"
}
preConfigureHooks+=(addNetBSDInstallMakeFlags)

View file

@ -7,4 +7,9 @@ mergeNetBSDSourceDir() {
done
}
addNetBSDMakeFlags() {
makeFlags="INCSDIR=${!outputDev}/include $makeFlags"
}
postUnpackHooks+=(mergeNetBSDSourceDir)
preConfigureHooks+=(addNetBSDMakeFlags)

View file

@ -0,0 +1,13 @@
diff --git a/Makefile b/Makefile
index 3f1e18dc659d..163362b82f94 100644
--- a/Makefile
+++ b/Makefile
@@ -2,6 +2,8 @@
.include <bsd.own.mk>
+INCSDIR= ${INCSDIR0}
+
SUBDIR= altq arch compat dev fs miscfs \
net net80211 netatalk netbt netcan netipsec netinet netinet6 \
netmpls netsmb \

View file

@ -36,11 +36,6 @@ addMakeFlags() {
export MKUNPRIVED=yes
export EXTERNAL_TOOLCHAIN=yes
export INSTALL_FILE="install -U -c"
export INSTALL_DIR="xinstall -U -d"
export INSTALL_LINK="install -U -l h"
export INSTALL_SYMLINK="install -U -l s"
makeFlags="MACHINE=$MACHINE $makeFlags"
makeFlags="MACHINE_ARCH=$MACHINE_ARCH $makeFlags"
makeFlags="AR=$AR $makeFlags"
@ -79,7 +74,7 @@ includesPhase() {
local flagsArray=(
$makeFlags ${makeFlagsArray+"${makeFlagsArray[@]}"}
DESTDIR=${!outputInclude} includes
includes
)
echoCmd 'includes flags' "${flagsArray[@]}"