Merge pull request #136437 from Ericson2314/netbsd-compat-cross

netbsd.compat: Fix cross compilation
This commit is contained in:
John Ericson 2021-09-05 00:46:54 -04:00 committed by GitHub
commit 4ad0a67799
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 262 additions and 32 deletions

View File

@ -0,0 +1,22 @@
commit f2d0ff85e05b49e9d11735ce4810b242c1dbf5af
Author: John Ericson <John.Ericson@Obsidian.Systems>
Date: Wed Sep 1 15:38:56 2021 +0000
Make should not hit configure
diff --git a/Makefile b/Makefile
index b5adb8a5f2e9..1a914ef16739 100644
--- a/Makefile
+++ b/Makefile
@@ -76,11 +76,6 @@ _CURDIR:= ${.CURDIR}
SRCS:= ${SRCS:M*.c}
-config.cache: include/.stamp configure nbtool_config.h.in defs.mk.in
- rm -f ${.TARGET}
- CC=${HOST_CC:Q} CFLAGS=${HOST_CFLAGS:Q} LDFLAGS=${HOST_LDFLAGS:Q} \
- ${HOST_SH} ${.CURDIR}/configure --cache-file=config.cache
-
defs.mk: config.cache
@touch ${.TARGET}

View File

@ -0,0 +1,101 @@
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>
+.include <bsd.own.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

@ -28,6 +28,12 @@ let
selfTargetTarget = pkgsTargetTarget.netbsd or {}; # might be missing
};
defaultMakeFlags = [
"MKSOFTFLOAT=${if stdenv.hostPlatform.gcc.float or (stdenv.hostPlatform.parsed.abi.float or "hard") == "soft"
then "yes"
else "no"}"
];
in lib.makeScopeWithSplicing
splicePackages
newScope
@ -90,6 +96,8 @@ in lib.makeScopeWithSplicing
BSD_PATH = attrs.path;
makeFlags = defaultMakeFlags;
strictDeps = true;
meta = with lib; {
@ -97,6 +105,7 @@ in lib.makeScopeWithSplicing
platforms = platforms.unix;
license = licenses.bsd2;
};
} // lib.optionalAttrs stdenv'.hasCC {
# TODO should CC wrapper set this?
CPP = "${stdenv'.cc.targetPrefix}cpp";
@ -166,10 +175,14 @@ in lib.makeScopeWithSplicing
./compat-setup-hook.sh
];
# 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";
preConfigure = ''
make include/.stamp configure nbtool_config.h.in defs.mk.in
'';
configurePlatforms = [ "build" "host" ];
configureFlags = [
"--cache-file=config.cache"
];
nativeBuildInputs = with buildPackages.netbsd; commonDeps ++ [
bsdSetupHook netbsdSetupHook
@ -181,18 +194,30 @@ in lib.makeScopeWithSplicing
# temporarily use gnuinstall for bootstrapping
# bsdinstall will be built later
makeFlags = [
makeFlags = defaultMakeFlags ++ [
"INSTALL=${buildPackages.coreutils}/bin/install"
"TOOLDIR=$(out)"
"DATADIR=$(out)/share"
# Can't sort object files yet
"LORDER=echo"
"TSORT=cat"
# Can't process man pages yet
"MKSHARE=no"
];
RENAME = "-D";
patches = [ ./compat.patch ];
patches = [
./compat-cxx-safe-header.patch
./compat-dont-configure-twice.patch
./compat-no-force-native.patch
];
preInstall = ''
makeFlagsArray+=('INSTALL_FILE=''${INSTALL} ''${COPY} ''${PRESERVE} ''${RENAME}')
makeFlagsArray+=('INSTALL_DIR=''${INSTALL} -d')
makeFlagsArray+=('INSTALL_SYMLINK=''${INSTALL} ''${SYMLINK} ''${RENAME}')
'';
postInstall = ''
mv $out/include/compat/* $out/include
rmdir $out/include/compat
# 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
@ -261,6 +286,7 @@ in lib.makeScopeWithSplicing
runHook postInstall
'';
setupHook = ./install-setup-hook.sh;
};
fts = mkDerivation {
@ -354,7 +380,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\""
@ -444,7 +504,7 @@ in lib.makeScopeWithSplicing
makeMinimal
install mandoc groff nbperf
];
makeFlags = [ "TOOLDIR=$(out)" ];
makeFlags = defaultMakeFlags ++ [ "TOOLDIR=$(out)" ];
extraPaths = with self; [
libterminfo.src
(fetchNetBSD "usr.bin/tic" "9.2" "1mwdfg7yx1g43ss378qsgl5rqhsxskqvsd2mqvrn38qw54i8v5i1")
@ -494,11 +554,27 @@ 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;
meta.platforms = lib.platforms.netbsd;
makeFlags = [ "RPCGEN_CPP=${buildPackages.stdenv.cc.cc}/bin/cpp" ];
makeFlags = defaultMakeFlags ++ [ "RPCGEN_CPP=${buildPackages.stdenv.cc.cc}/bin/cpp" ];
};
common = fetchNetBSD "common" "9.2" "1pfylz9r3ap5wnwwbwczbfjb1m5qdyspzbnmxmcdkpzz2zgj64b9";
@ -509,9 +585,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";
@ -525,9 +609,11 @@ in lib.makeScopeWithSplicing
pushd arch/$MACHINE/conf
config $CONFIG
popd
'';
''
# multiple header dirs, see above
+ self.include.postConfigure;
makeFlags = [ "FIRMWAREDIR=$(out)/libdata/firmware" ];
makeFlags = defaultMakeFlags ++ [ "FIRMWAREDIR=$(out)/libdata/firmware" ];
hardeningDisable = [ "pic" ];
MKKMOD = "no";
NIX_CFLAGS_COMPILE = [ "-Wa,--no-warn" ];
@ -595,7 +681,7 @@ in lib.makeScopeWithSplicing
buildInputs = with self; [ libterminfo libcurses ];
propagatedBuildInputs = with self; compatIfNeeded;
SHLIBINSTALLDIR = "$(out)/lib";
makeFlags = [ "LIBDO.terminfo=${self.libterminfo}/lib" ];
makeFlags = defaultMakeFlags ++ [ "LIBDO.terminfo=${self.libterminfo}/lib" ];
postPatch = ''
sed -i '1i #undef bool_t' el.h
substituteInPlace config.h \
@ -647,7 +733,7 @@ in lib.makeScopeWithSplicing
] ++ lib.optional stdenv.isDarwin "-D__strong_alias(a,b)=";
propagatedBuildInputs = with self; compatIfNeeded;
MKDOC = "no"; # missing vfontedpr
makeFlags = [ "LIBDO.terminfo=${self.libterminfo}/lib" ];
makeFlags = defaultMakeFlags ++ [ "LIBDO.terminfo=${self.libterminfo}/lib" ];
postPatch = lib.optionalString (!stdenv.isDarwin) ''
substituteInPlace printw.c \
--replace "funopen(win, NULL, __winwrite, NULL, NULL)" NULL \
@ -674,7 +760,7 @@ in lib.makeScopeWithSplicing
path = "lib/librpcsvc";
version = "9.2";
sha256 = "1q34pfiyjbrgrdqm46jwrsqms49ly6z3b0xh1wg331zga900vq5n";
makeFlags = [ "INCSDIR=$(out)/include/rpcsvc" ];
makeFlags = defaultMakeFlags ++ [ "INCSDIR=$(out)/include/rpcsvc" ];
meta.platforms = lib.platforms.netbsd;
nativeBuildInputs = with buildPackages.netbsd; [
bsdSetupHook netbsdSetupHook
@ -773,7 +859,7 @@ in lib.makeScopeWithSplicing
# Hack to prevent a symlink being installed here for compatibility.
SHLINKINSTALLDIR = "/usr/libexec";
USE_FORT = "yes";
makeFlags = [ "BINDIR=$(out)/libexec" "CLIBOBJ=${self.libc}/lib" ];
makeFlags = defaultMakeFlags ++ [ "BINDIR=$(out)/libexec" "CLIBOBJ=${self.libc}/lib" ];
extraPaths = with self; [ libc.src ] ++ libc.extraPaths;
};
@ -804,7 +890,7 @@ in lib.makeScopeWithSplicing
SHLIBINSTALLDIR = "$(out)/lib";
MKPICINSTALL = "yes";
NLSDIR = "$(out)/share/nls";
makeFlags = [ "FILESDIR=$(out)/var/db"];
makeFlags = defaultMakeFlags ++ [ "FILESDIR=$(out)/var/db"];
postInstall = ''
pushd ${self.headers}
find . -type d -exec mkdir -p $out/\{} \;
@ -858,7 +944,7 @@ in lib.makeScopeWithSplicing
noCC = true;
version = "9.2";
sha256 = "0svfc0byk59ri37pyjslv4c4rc7zw396r73mr593i78d39q5g3ad";
makeFlags = [ "BINDIR=$(out)/share" ];
makeFlags = defaultMakeFlags ++ [ "BINDIR=$(out)/share" ];
};
misc = mkDerivation {
@ -866,7 +952,7 @@ in lib.makeScopeWithSplicing
noCC = true;
version = "9.2";
sha256 = "1j2cdssdx6nncv8ffj7f7ybl7m9hadjj8vm8611skqdvxnjg6nbc";
makeFlags = [ "BINDIR=$(out)/share" ];
makeFlags = defaultMakeFlags ++ [ "BINDIR=$(out)/share" ];
};
man = mkDerivation {
@ -874,7 +960,7 @@ in lib.makeScopeWithSplicing
noCC = true;
version = "9.2";
sha256 = "1l4lmj4kmg8dl86x94sr45w0xdnkz8dn4zjx0ipgr9bnq98663zl";
makeFlags = [ "FILESDIR=$(out)/share" ];
makeFlags = defaultMakeFlags ++ [ "FILESDIR=$(out)/share" ];
};
#
# END MISCELLANEOUS

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[@]}"