Skip to content

Commit

Permalink
Apply patch (requested by mrg in ticket #1499):
Browse files Browse the repository at this point in the history
src/compat version 2.  this allows building any number of alternate
library / program target ABIs.  rather than duplicating the list of
subdirs and Makefiles to build, it re-traverses the necessary ones.
details:
- add support for MAKEDIRTARGETENV to share/mk
- renames LD32DIR to MLIBDIR
- fixes library builds for some subdirs (more was built than needed)
- fixes /bin & /sbin apps in compat mode
- reduces complexity in src/compat and the rest of the tree
- updates ldd netbsd32 support
  • Loading branch information
riz committed Jan 6, 2011
1 parent 13fe76a commit 65af359
Show file tree
Hide file tree
Showing 198 changed files with 593 additions and 5,540 deletions.
20 changes: 12 additions & 8 deletions Makefile
@@ -1,4 +1,4 @@
# $NetBSD: Makefile,v 1.262.2.3 2009/03/27 14:50:35 msaitoh Exp $
# $NetBSD: Makefile,v 1.262.2.4 2011/01/06 05:19:54 riz Exp $

#
# This is the top-level makefile for building NetBSD. For an outline of
Expand Down Expand Up @@ -397,19 +397,23 @@ BUILD_CC_LIB+= external/bsd/pcc/crtstuff
BUILD_CC_LIB+= external/bsd/pcc/libpcc
.endif

.if ${MKCOMPAT} != "no"
BUILD_COMPAT_LIBS= compat/lib/csu ${BUILD_CC_LIB:S/^/compat\//} compat/lib/libc
.else
BUILD_COMPAT_LIBS=
.endif

.for dir in tools tools/compat lib/csu ${BUILD_CC_LIB} lib/libc lib/libdes lib gnu/lib external/lib sys/rump/fs/lib sys/rump/net/lib ${BUILD_COMPAT_LIBS}
.for dir in tools tools/compat lib/csu ${BUILD_CC_LIB} lib/libc lib/libdes lib gnu/lib external/lib sys/rump/fs/lib sys/rump/net/lib
do-${dir:S/\//-/g}: .PHONY .MAKE
.for targ in dependall install
${MAKEDIRTARGET} ${dir} ${targ}
.endfor
.endfor

.if ${MKCOMPAT} != "no"
COMPAT_SUBDIR_LIST=lib/csu ${BUILD_CC_LIB} lib/libc
.for dir in ${COMPAT_SUBDIR_LIST}
do-compat-${dir:S/\//-/g}: .PHONY .MAKE
.for targ in obj dependall install
${MAKEDIRTARGET} compat ${targ} BOOTSTRAP_SUBDIRS="../../../${dir}"
.endfor
.endfor
.endif

do-top-obj: .PHONY .MAKE
${MAKEDIRTARGET} . obj NOSUBDIR=

Expand Down
26 changes: 8 additions & 18 deletions compat/Makefile
@@ -1,27 +1,17 @@
# $NetBSD: Makefile,v 1.1 2008/10/26 07:38:27 mrg Exp $
# $NetBSD: Makefile,v 1.1.2.1 2011/01/06 05:19:55 riz Exp $

# Build 32-bit compat versions of:
# src/gnu/lib/libgcc4 into ${DESTDIR}/usr/lib/<32arch>
# src/lib/libc into ${DESTDIR}/usr/lib/<32arch>
# src/gnu/lib/ into ${DESTDIR}/usr/lib/<32arch>
# src/lib/ into ${DESTDIR}/usr/lib/<32arch>
# src/libexec/ld.elf_so into ${DESTDIR}/usr/libexec/ld.elf_so-<32arch>
# Build multi-abi libaries

.include <bsd.own.mk>

.if ${MKCOMPAT} != "no" && \
(${MACHINE} == "sparc64" || ${MACHINE} == "amd64")

.if ${MKCOMPAT} != "no"
.if !make(includes)
SUBDIR= gnu/lib/crtstuff4 .WAIT \
lib/csu .WAIT \
gnu/lib/libgcc4 .WAIT \
lib/libc .WAIT \
lib/libutil .WAIT \
lib gnu/lib .WAIT \
libexec/ld.elf_so
.endif

.include "archdirs.mk"

SUBDIR= dirshack .WAIT ${ARCHDIR_SUBDIR}

.endif
.endif

.include <bsd.subdir.mk>
66 changes: 28 additions & 38 deletions compat/Makefile.compat
@@ -1,46 +1,34 @@
# $NetBSD: Makefile.compat,v 1.3 2008/10/28 22:58:23 mrg Exp $

COPTS+= -m32
CPUFLAGS+= -m32
LDADD+= -m32
MKDEPFLAGS+= -m32

# XXX ugly
.if ${MACHINE} == "sparc64"
LD+= -m elf32_sparc
LD32DIR= sparc
.elif ${MACHINE} == "amd64"
LD+= -m elf_i386
LD32DIR= i386
.endif

LIBDIR= /usr/lib/${LD32DIR}
SHLIBDIR= /usr/lib/${LD32DIR}
SHLIBINSTALLDIR= /usr/lib/${LD32DIR}

COMMON_MACHINE_ARCH= ${LD32DIR}
LIBC_MACHINE_ARCH= ${LD32DIR}
BFD_MACHINE_ARCH= ${LD32DIR}
CRYPTO_MACHINE_CPU= ${LD32DIR}
KVM_MACHINE_ARCH= ${LD32DIR}
PTHREAD_MACHINE_ARCH= ${LD32DIR}
LDELFSO_MACHINE_CPU= ${LD32DIR}

_GCC_CRTBEGIN?= ${DESTDIR}/usr/lib/${LD32DIR}/crtbegin.o
_GCC_CRTBEGINS?= ${DESTDIR}/usr/lib/${LD32DIR}/crtbeginS.o
_GCC_CRTEND?= ${DESTDIR}/usr/lib/${LD32DIR}/crtend.o
_GCC_CRTENDS?= ${DESTDIR}/usr/lib/${LD32DIR}/crtendS.o
_GCC_CRTDIR?= ${DESTDIR}/usr/lib/${LD32DIR}
_GCC_LIBGCCDIR?= ${DESTDIR}/usr/lib/${LD32DIR}
# $NetBSD: Makefile.compat,v 1.3.2.1 2011/01/06 05:19:55 riz Exp $

#
# Makefile fragment to help implement a multilib set of libraries
#
# expects MLIBDIR to be set to the extra path component
#

.ifndef _COMPAT_OPTIONS_MK_ # {
_COMPAT_OPTIONS_MK_=1

LIBDIR= /usr/lib/${MLIBDIR}
SHLIBDIR= /usr/lib/${MLIBDIR}
SHLIBINSTALLDIR= /usr/lib/${MLIBDIR}

_GCC_CRTBEGIN= ${DESTDIR}/usr/lib/${MLIBDIR}/crtbegin.o
_GCC_CRTBEGINS= ${DESTDIR}/usr/lib/${MLIBDIR}/crtbeginS.o
_GCC_CRTEND= ${DESTDIR}/usr/lib/${MLIBDIR}/crtend.o
_GCC_CRTENDS= ${DESTDIR}/usr/lib/${MLIBDIR}/crtendS.o
_GCC_CRTDIR= ${DESTDIR}/usr/lib/${MLIBDIR}
_GCC_LIBGCCDIR= ${DESTDIR}/usr/lib/${MLIBDIR}

NOSHARE= # defined
NONLS= # defined
NOLINT= # defined
NONLS= # defined
NOMAN= # defined
NOINFO= # defined
NOCHECKVER= # defined

LIBC_DIR= ${NETBSDSRCDIR}/compat/lib/libc

# ld.elf_so
SHLINKINSTALLDIR= /usr/libexec
SHLINKINSTALLDIR= /libexec

# XXX
EXTRALIBDIRS= ${DESTDIR}${LIBDIR} ${DESTDIR}${LIBDIR}/i18n ${DESTDIR}${LIBDIR}/security
Expand All @@ -56,3 +44,5 @@ ${EXTRALIBDIRS}: .EXEC
fi
# Make sure the base dir is created first.
${DESTDIR}${LIBDIR}/i18n ${DESTDIR}${LIBDIR}/security: ${DESTDIR}${LIBDIR}

.endif # _COMPAT_OPTIONS_MK_ }
93 changes: 61 additions & 32 deletions compat/README
@@ -1,43 +1,72 @@
$NetBSD: README,v 1.2 2008/10/27 07:22:22 mrg Exp $
$NetBSD: README,v 1.2.2.1 2011/01/06 05:19:55 riz Exp $

This directory contains Makefile fragments that will build all of the
NetBSD libraries in 32-bit mode and install them into /usr/lib/<arch>
and also install a /usr/libexec/ld.elf_so-<arch>.

This is current only supported for the amd64 and sparc64 platforms,
where <arch> is "i386" or "sparc" respectively. (It could be used to
build MIPS o32 libraries on n32 system, but not both n32 and o32 on
a n64 system. It only supports one extra target.)
Building multi- ABI libraries for NetBSD platforms.


Most of the makefiles here were built with the "build-makefiles" script.
The expections are lib/csu/Makefile and ld.elf_so/Makefile.
src/compat has a framework to (re)build the libraries shipped with
NetBSD for a different ABI than the default for that platform. This
allows 32-bit libraries for the amd64 and sparc64 ports, and enables
the mips64 port to support all three of old-style 32-bit ("o32"), the
new 32-bit (default, "n32", 64-bit CPU required) or the 64-bit ABI.


The method used is the:
- evaluate some local variables
- switch .CURDIR
- include original Makefile,
- evaluate some variables
- switch .CURDIR back
that is used by crunchgen to build eg, installer media or /rescue.
The basic premise is to re-set $MAKEOBJDIRPREFIX to fresh subdirectory
underneath src/compat and rebuild the libraries with a different set
of options. Each platform wanting support should create their port
subdirectory directly in src/compat, and then one subdirectory in here
for each ABI required. e.g., src/compat/amd64/i386 is where we build
the 32-bit compat libraries for the amd64 port. In each of these
subdirs, a small Makefile and makefile fragment should exist. The
Makefile should set BSD_MK_COMPAT_FILE to equal the fragment, and then
include "../../compatsubdir.mk" Eg, amd64/i386/Makefile has:

BSD_MK_COMPAT_FILE=${.CURDIR}/bsd.i386.mk

.include "../../compatsubdir.mk"

TODO:
- some yacc issue -- libc, libipsec and libpcap need "make" run
to generate headers properly, otherwise it complains about
no way to get to foo.h. this is currently hacked by putting
a rule "foo.h: foo.c" in the (generated) makefiles
- there's an ugly hack to make libpam build correctly again the
right libc. ld.elf_so has a similar (but less ugly hack)
- not sure that /usr/lib/{i386,sparc}{,/i18n} are created
properly yet
In the makefile fragment any changes to ABI flags are passed here
and the MLIBDIR variable must be set to the subdirectory in /usr/lib
where libraries for the ABI will be installed. There are a couple of
helper Makefiles around. amd64/i386/bsd.i386.mk looks like:

Future work
LD+= -m elf_i386
MLIBDIR= i386
LIBC_MACHINE_ARCH= ${MLIBDIR}
COMMON_MACHINE_ARCH= ${MLIBDIR}
KVM_MACHINE_ARCH= ${MLIBDIR}
PTHREAD_MACHINE_ARCH= ${MLIBDIR}
BFD_MACHINE_ARCH= ${MLIBDIR}
CSU_MACHINE_ARCH= ${MLIBDIR}
CRYPTO_MACHINE_CPU= ${MLIBDIR}
LDELFSO_MACHINE_CPU= ${MLIBDIR}

Ideally this should be able to handle any number of compat targets.
Perhaps using a "force MAKEOBJDIR, and run-run make" solution will
work, but my initial attempts got me no where. If not, perhaps
build-makefiles could be expanded to be used at run-time in such
a per-compat target obj-dir.
.include "${NETBSDSRCDIR}/compat/m32.mk"

and the referenced m32.mk looks like:

COPTS+= -m32
CPUFLAGS+= -m32
LDADD+= -m32
LDFLAGS+= -m32
MKDEPFLAGS+= -m32

.include "Makefile.compat"


compatsubdir.mk holds the list of subdirectories (the libraries and
ld.elf_so) to build with this ABI.

archdirs.mk holds the list of subdirectories for each port.

Makefile.compat has the basic framework to force the right paths for
library and ld.elf_so linkage. It contains a hack to create subdirs
in the build that should be fixed.

dirshack/Makefile is a hack to get objdirs created timely, and should
be fixed in a better way.



mrg@eterna.com.au
december 2009
5 changes: 5 additions & 0 deletions compat/amd64/i386/Makefile
@@ -0,0 +1,5 @@
# $NetBSD: Makefile,v 1.1.4.2 2011/01/06 05:19:55 riz Exp $

BSD_MK_COMPAT_FILE=${.CURDIR}/bsd.i386.mk

.include "../../compatsubdir.mk"
14 changes: 14 additions & 0 deletions compat/amd64/i386/bsd.i386.mk
@@ -0,0 +1,14 @@
# $NetBSD: bsd.i386.mk,v 1.2.2.2 2011/01/06 05:19:55 riz Exp $

LD+= -m elf_i386
MLIBDIR= i386
LIBC_MACHINE_ARCH= ${MLIBDIR}
COMMON_MACHINE_ARCH= ${MLIBDIR}
KVM_MACHINE_ARCH= ${MLIBDIR}
PTHREAD_MACHINE_ARCH= ${MLIBDIR}
BFD_MACHINE_ARCH= ${MLIBDIR}
CSU_MACHINE_ARCH= ${MLIBDIR}
CRYPTO_MACHINE_CPU= ${MLIBDIR}
LDELFSO_MACHINE_CPU= ${MLIBDIR}

.include "${.PARSEDIR}/../../m32.mk"
22 changes: 22 additions & 0 deletions compat/archdirs.mk
@@ -0,0 +1,22 @@
# $NetBSD: archdirs.mk,v 1.1.2.2 2011/01/06 05:19:55 riz Exp $

# list of subdirs used per-platform

.if ${MACHINE} == "sparc64"
ARCHDIR_SUBDIR= sparc64/sparc
.endif

.if ${MACHINE} == "amd64"
ARCHDIR_SUBDIR= amd64/i386
.endif
# $NetBSD: archdirs.mk,v 1.1.2.2 2011/01/06 05:19:55 riz Exp $

# list of subdirs used per-platform

.if ${MACHINE} == "sparc64"
ARCHDIR_SUBDIR= sparc64/sparc
.endif

.if ${MACHINE} == "amd64"
ARCHDIR_SUBDIR= amd64/i386
.endif

0 comments on commit 65af359

Please sign in to comment.