Skip to content

Commit

Permalink
Attempt to bring sanity to how ABI and MACHINE_ARCH are set.
Browse files Browse the repository at this point in the history
Previously there were at least 5 different ways MACHINE_ARCH could be set,
some statically and some at run time, and in many cases these settings
differed, leading to issues at pkg_add time where there was conflict
between the setting encoded into the package and that used by pkg_install.

Instead, move to a single source of truth where the correct value based on
the host and the chosen (or default) ABI is determined in the bootstrap
script.  The value can still be overridden in mk.conf if necessary, e.g.
for cross-compiling.

ABI is now set by default and if unset a default is calculated based on
MACHINE_ARCH.  This fixes some OS, e.g. Linux, where the wrong default was
previously chosen.

As a result of the refactoring there is no need for LOWER_ARCH, with
references to it replaced by MACHINE_ARCH.  SPARC_TARGET_ARCH is also
removed.
  • Loading branch information
jperkin committed Jan 24, 2016
1 parent ee349af commit e2b4d2c
Show file tree
Hide file tree
Showing 19 changed files with 110 additions and 212 deletions.
107 changes: 52 additions & 55 deletions bootstrap/bootstrap
@@ -1,6 +1,6 @@
#! /bin/sh

# $NetBSD: bootstrap,v 1.226 2016/01/06 17:59:58 jperkin Exp $
# $NetBSD: bootstrap,v 1.227 2016/01/24 16:14:44 jperkin Exp $
#
# Copyright (c) 2001-2011 Alistair Crooks <agc@NetBSD.org>
# All rights reserved.
Expand Down Expand Up @@ -77,10 +77,6 @@ usage="Usage: $0 "'
[ --workdir <workdir> ]
'

# this replicates some of the logic in bsd.prefs.mk. until
# bootstrap-pkgsrc is merged into pkgsrc, we need to determine the
# right value for OPSYS and MACHINE_ARCH.

# strip / for BSD/OS, strip - for HP-UX
opsys=`uname -s | tr -d /-`

Expand Down Expand Up @@ -183,15 +179,6 @@ get_abi()
fi

case "$abi_opsys" in
Darwin)
if [ -z "$abi" ]; then
case `uname -m` in
x86_64)
abi="64"
;;
esac
fi
;;
IRIX)
if [ `uname -r` -ge 6 ]; then
abi=`sed -e 's/.*\(abi=\)\([on]*[36][24]\).*/\2/' /etc/compiler.defaults`
Expand Down Expand Up @@ -226,6 +213,24 @@ get_machine_arch_aix()
fi
}

get_machine_arch_darwin()
{
case `uname -p` in
i386)
# Returns "i386" or "x86_64" depending on CPU
echo `uname -m`
;;
powerpc)
# sysctl mib exists on 64-bit hardware
if [ `sysctl -n hw.optional.64bitops 2>/dev/null` = "1" ]; then
echo "powerpc64"
else
echo "powerpc"
fi
;;
esac
}

check_prog()
{
_var="$1"; _name="$2"
Expand Down Expand Up @@ -503,7 +508,6 @@ overpath=""
root_user=root
bmakexargs=
need_extras=no
set_machine_arch=no
use_bsdinstall=
case "$opsys" in
AIX)
Expand All @@ -523,10 +527,6 @@ Bitrig)
need_sed=no
set_opsys=no
machine_arch=`arch -s`
if [ "$machine_arch" = "amd64" ]; then
machine_arch=x86_64
bmakexargs="MACHINE_ARCH=$machine_arch"
fi
check_compiler=yes
;;
CYGWIN_*)
Expand Down Expand Up @@ -554,11 +554,7 @@ Darwin)
need_awk=no
need_sed=no
set_opsys=no
get_abi "Darwin"
machine_arch=`uname -p`
if [ "$machine_arch" = "i386" -a "$abi" = "64" ]; then
machine_arch=x86_64
fi
machine_arch=`get_machine_arch_darwin`
CC=${CC:-"cc -isystem /usr/include"}; export CC
check_compiler=yes
osrev=`uname -r`
Expand Down Expand Up @@ -590,10 +586,6 @@ DragonFly)
set_opsys=no
check_prog tarprog tar
machine_arch=`uname -p`
if [ "$machine_arch" = "amd64" ]; then
machine_arch=x86_64
bmakexargs="MACHINE_ARCH=$machine_arch"
fi
;;
FreeBSD)
root_group=wheel
Expand All @@ -602,10 +594,6 @@ FreeBSD)
need_sed=no
set_opsys=no
machine_arch=`uname -p`
if [ "$machine_arch" = "amd64" ]; then
machine_arch=x86_64
bmakexargs="MACHINE_ARCH=$machine_arch"
fi
check_compiler=yes
;;
FreeMiNT)
Expand Down Expand Up @@ -705,7 +693,6 @@ IRIX*)
need_sed=yes
set_opsys=yes
machine_arch=mipseb
bmakexargs="MACHINE_ARCH=$machine_arch"
check_compiler=yes
if [ `uname -r` -lt 6 ]; then
# IRIX 5's mkdir bails out with an error when trying to create with the -p
Expand All @@ -730,12 +717,6 @@ Linux)
need_sed=no
set_opsys=no
machine_arch=`uname -m | sed -e 's/i.86/i386/'`
# Support multiarch systems.
if [ "$machine_arch" = "x86_64" -a "$abi" = "32" ]; then
machine_arch=i386
set_machine_arch=yes
bmakexargs="MACHINE_ARCH=$machine_arch"
fi
;;
Minix)
root_group=operator
Expand Down Expand Up @@ -789,10 +770,6 @@ OpenBSD)
need_sed=no
set_opsys=no
machine_arch=`arch -s`
if [ "$machine_arch" = "amd64" ]; then
machine_arch=x86_64
bmakexargs="MACHINE_ARCH=$machine_arch"
fi
;;
OSF1)
root_group=system
Expand Down Expand Up @@ -871,6 +848,34 @@ UnixWare)
;;
esac

# Fixup MACHINE_ARCH to use canonical pkgsrc variants, and support multiarch
# systems via --abi, setting a default $abi based on MACHINE_ARCH if not set.
#
case "$machine_arch/$abi" in
# "amd64" translates to "x86_64", defaults to 64-bit
amd64/32) abi=32 machine_arch=i386 ;;
amd64/*) abi=64 machine_arch=x86_64 ;;
# XXX: hppa untested
hppa/64) abi=64 machine_arch=hppa64 ;;
hppa/*) abi=32 machine_arch=hppa ;;
hppa64/32) abi=32 machine_arch=hppa ;;
hppa64/*) abi=64 machine_arch=hppa64 ;;
# "i386" can support 64-bit, e.g. SunOS, defaults to 32-bit.
i386/64) abi=64 machine_arch=x86_64 ;;
i386/*) abi=32 machine_arch=i386 ;;
# XXX: powerpc untested
powerpc/64) abi=64 machine_arch=powerpc64 ;;
powerpc/*) abi=32 machine_arch=powerpc ;;
powerpc64/32) abi=32 machine_arch=powerpc ;;
powerpc64/*) abi=64 machine_arch=powerpc64 ;;
# "sparc" can support 64-bit, e.g. SunOS, defaults to 32-bit.
sparc/64) abi=64 machine_arch=sparc64 ;;
sparc/*) abi=32 machine_arch=sparc ;;
# x86_64 supports 32-bit/64-bit, defaults to 64-bit.
x86_64/32) abi=32 machine_arch=i386 ;;
x86_64/*) abi=64 machine_arch=x86_64 ;;
esac

# If "--full" is specified, then install all of the platform-independent
# bootstrap software.
#
Expand Down Expand Up @@ -898,14 +903,9 @@ if [ $? -ne 0 ]; then
die "ERROR: --make-jobs must be a positive integer argument"
fi

# export OPSYS and MACHINE_ARCH for pkg_install. we only set
# MACHINE_ARCH on platforms where we override bmake's value.
OPSYS=${opsys}
export OPSYS
if [ "${machine_arch}" != "" ]; then
MACHINE_ARCH=${machine_arch}
export MACHINE_ARCH
fi
# export MACHINE_ARCH and OPSYS for bmake and pkg_install.
MACHINE_ARCH=${machine_arch}; export MACHINE_ARCH
OPSYS=${opsys}; export OPSYS

if [ "x$preserve_path" != "xyes" ]; then
PATH="$overpath:$PATH"
Expand Down Expand Up @@ -1021,9 +1021,6 @@ fi
if [ -n "$abi" ]; then
echo "ABI= $abi" >> ${TARGET_MKCONF}
fi
if [ "$set_machine_arch" = "yes" ]; then
echo "MACHINE_ARCH= $machine_arch" >> ${TARGET_MKCONF}
fi
if [ "$compiler" != "" ]; then
echo "PKGSRC_COMPILER= $compiler" >> ${TARGET_MKCONF}
fi
Expand Down Expand Up @@ -1140,7 +1137,7 @@ $shprog ./bootstrap.sh)"
bootstrap_bmake() {
echo_msg "Bootstrapping bmake"
copy_src $pkgsrcdir/devel/bmake/files bmake
run_cmd "(cd $wrkdir/bmake && $shprog configure $configure_quiet_flags --with-default-sys-path=$wrkdir/share/mk --prefix=$wrkdir $bmakexargs)"
run_cmd "(cd $wrkdir/bmake && $shprog configure $configure_quiet_flags --prefix=$wrkdir --with-default-sys-path=$wrkdir/share/mk --with-machine-arch=${machine_arch} $bmakexargs)"
run_cmd "(cd $wrkdir/bmake && $shprog make-bootstrap.sh)"
run_cmd "$install_sh -c -o $user -g $group -m 755 $wrkdir/bmake/bmake $wrkdir/bin/bmake"
}
Expand Down
6 changes: 2 additions & 4 deletions devel/bmake/Makefile
@@ -1,4 +1,4 @@
# $NetBSD: Makefile,v 1.71 2015/06/17 17:37:50 tron Exp $
# $NetBSD: Makefile,v 1.72 2016/01/24 16:14:44 jperkin Exp $

DISTNAME= bmake-20150505
CATEGORIES= devel
Expand Down Expand Up @@ -28,6 +28,7 @@ INSTALLATION_DIRS= bin ${PKGMANDIR}/cat1 ${PKGMANDIR}/man1
GNU_CONFIGURE= yes
CONFIGURE_ARGS+= --prefix=${PREFIX}
CONFIGURE_ARGS+= --with-default-sys-path=${makesyspath}
CONFIGURE_ARGS+= --with-machine_arch=${MACHINE_ARCH}
CONFIGURE_ARGS+= --sysconfdir=${PKG_SYSCONFDIR}

.include "../../mk/bsd.prefs.mk"
Expand All @@ -41,9 +42,6 @@ CONFIGURE_ARGS+= --with-defshell=${PREFIX}/bin/pdksh
.if ${OPSYS} == "Interix"
MAKE_ENV+= XDEFS=-DUSE_SELECT
.endif
.if ${OPSYS} == "IRIX"
CONFIGURE_ARGS+= --with-machine_arch=${MACHINE_ARCH}
.endif

do-extract:
${CP} -R ${FILESDIR} ${WRKSRC}
Expand Down
14 changes: 11 additions & 3 deletions devel/bmake/files/main.c
@@ -1,4 +1,4 @@
/* $NetBSD: main.c,v 1.13 2015/05/19 22:01:19 joerg Exp $ */
/* $NetBSD: main.c,v 1.14 2016/01/24 16:14:44 jperkin Exp $ */

/*
* Copyright (c) 1988, 1989, 1990, 1993
Expand Down Expand Up @@ -69,7 +69,7 @@
*/

#ifndef MAKE_NATIVE
static char rcsid[] = "$NetBSD: main.c,v 1.13 2015/05/19 22:01:19 joerg Exp $";
static char rcsid[] = "$NetBSD: main.c,v 1.14 2016/01/24 16:14:44 jperkin Exp $";
#else
#include <sys/cdefs.h>
#ifndef lint
Expand All @@ -81,7 +81,7 @@ __COPYRIGHT("@(#) Copyright (c) 1988, 1989, 1990, 1993\
#if 0
static char sccsid[] = "@(#)main.c 8.3 (Berkeley) 3/19/94";
#else
__RCSID("$NetBSD: main.c,v 1.13 2015/05/19 22:01:19 joerg Exp $");
__RCSID("$NetBSD: main.c,v 1.14 2016/01/24 16:14:44 jperkin Exp $");
#endif
#endif /* not lint */
#endif
Expand Down Expand Up @@ -916,6 +916,14 @@ main(int argc, char **argv)
#endif
}

/*
* Hardcode default pkgsrc MACHINE_ARCH. There is only one legitimate
* way to override the variable, and that is through the environment,
* handled above. We need to use PKGSRC_MACHINE_ARCH as some OS define
* MACHINE_ARCH in their system headers.
*/
machine_arch = PKGSRC_MACHINE_ARCH;

if (!machine_arch) {
#if defined(MAKE_NATIVE) && defined(HAVE_SYSCTL) && defined(CTL_HW) && defined(HW_MACHINE_ARCH)
static char machine_arch_buf[sizeof(utsname.machine)];
Expand Down
2 changes: 1 addition & 1 deletion devel/bmake/files/make-bootstrap.sh.in
Expand Up @@ -16,7 +16,7 @@ CFLAGS="@CFLAGS@ -I. -I${srcdir} @DEFS@ @CPPFLAGS@ -DMAKE_NATIVE ${XDEFS} -DBMAK
MAKE_VERSION=`sed -n '/^MAKE_VERSION=/s,.*=[^0-9]*,,p' $srcdir/Makefile`

MDEFS="-DMAKE_VERSION=\"$MAKE_VERSION\" \
-D@force_machine@MACHINE=\"@machine@\" -DMACHINE_ARCH=\"@machine_arch@\" \
-D@force_machine@MACHINE=\"@machine@\" -DPKGSRC_MACHINE_ARCH=\"@machine_arch@\" \
-D_PATH_DEFSYSPATH=\"${DEFAULT_SYS_PATH}\""


Expand Down
4 changes: 2 additions & 2 deletions graphics/evas/Makefile.common
@@ -1,4 +1,4 @@
# $NetBSD: Makefile.common,v 1.14 2015/03/17 21:30:27 joerg Exp $
# $NetBSD: Makefile.common,v 1.15 2016/01/24 16:14:44 jperkin Exp $

# used by graphics/evas-buffer/Makefile
# used by graphics/evas-edb/Makefile
Expand Down Expand Up @@ -58,7 +58,7 @@ CONFIGURE_ARGS+= --enable-cpu-altivec
.endif

# currently it is like it is
MODULE_ARCH= ${LOWER_OPSYS}-${LOWER_ARCH}-${EVAS_VERSION}
MODULE_ARCH= ${LOWER_OPSYS}-${MACHINE_ARCH}-${EVAS_VERSION}
PLIST_SUBST= MODULE_ARCH=${MODULE_ARCH}
PRINT_PLIST_AWK+= { gsub(/${MODULE_ARCH}/, "$${MODULE_ARCH}") }

Expand Down
8 changes: 4 additions & 4 deletions lang/gcc34/Makefile
@@ -1,4 +1,4 @@
# $NetBSD: Makefile,v 1.56 2013/02/01 22:21:07 wiz Exp $
# $NetBSD: Makefile,v 1.57 2016/01/24 16:14:44 jperkin Exp $
#

DISTNAME= gcc-${GCC_VERSION}
Expand Down Expand Up @@ -89,18 +89,18 @@ CPPFLAGS+= -I${BUILDLINK_DIR}/include
CFLAGS+= -I${BUILDLINK_DIR}/include
.if ${OPSYS} == "NetBSD"
# thread / crtbegin / __cxa_atexit support depend on a "netbsd2" OS name
GCC_PLATFORM= ${LOWER_ARCH}--${LOWER_OPSYS}${APPEND_ELF}${LOWER_OS_VERSION:C/[_a-z].*//}
GCC_PLATFORM= ${MACHINE_ARCH}--${LOWER_OPSYS}${APPEND_ELF}${LOWER_OS_VERSION:C/[_a-z].*//}
CONFIGURE_ARGS+= --host=${GCC_PLATFORM:Q}
ABI_BASELINE_PAIR= ${GCC_PLATFORM:C/--/-/}
MAKE_ENV+= ABI_BASELINE_PAIR=${ABI_BASELINE_PAIR:Q}
.endif # NetBSD

post-patch:
.if ${OPSYS} == "NetBSD"
. if exists(${FILESDIR}/${LOWER_ARCH}-baseline_symbols${LOWER_OS_VERSION:C/\..*//}.txt)
. if exists(${FILESDIR}/${MACHINE_ARCH}-baseline_symbols${LOWER_OS_VERSION:C/\..*//}.txt)
(${TEST} -d ${WRKSRC}/libstdc++-v3/config/abi/${ABI_BASELINE_PAIR} || \
${MKDIR} ${WRKSRC}/libstdc++-v3/config/abi/${ABI_BASELINE_PAIR})
${CP} ${FILESDIR}/${LOWER_ARCH}-baseline_symbols${LOWER_OS_VERSION:C/\..*//}.txt \
${CP} ${FILESDIR}/${MACHINE_ARCH}-baseline_symbols${LOWER_OS_VERSION:C/\..*//}.txt \
${WRKSRC}/libstdc++-v3/config/abi/${ABI_BASELINE_PAIR}/baseline_symbols.txt
. endif
.endif
Expand Down
4 changes: 2 additions & 2 deletions lang/gcc44/Makefile
@@ -1,4 +1,4 @@
# $NetBSD: Makefile,v 1.44 2015/10/20 10:26:40 jperkin Exp $
# $NetBSD: Makefile,v 1.45 2016/01/24 16:14:44 jperkin Exp $

DISTNAME= gcc-${GCC_VERSION}
PKGNAME= gcc44-${GCC_VERSION}
Expand Down Expand Up @@ -92,7 +92,7 @@ CFLAGS+= -I${BUILDLINK_DIR}/include

# Somone should fix this so it will match the NetBSD system compiler
#.if ${OPSYS} == "NetBSD"
#GCC_PLATFORM= ${LOWER_ARCH}--${LOWER_OPSYS}${APPEND_ELF}
#GCC_PLATFORM= ${MACHINE_ARCH}--${LOWER_OPSYS}${APPEND_ELF}
#CONFIGURE_ARGS+= --host=${GCC_PLATFORM:Q}
#MAKE_ENV+= AR=/usr/bin/ar
#.endif # NetBSD
Expand Down
4 changes: 2 additions & 2 deletions lang/gcc45/Makefile
@@ -1,4 +1,4 @@
# $NetBSD: Makefile,v 1.19 2015/10/20 10:30:54 jperkin Exp $
# $NetBSD: Makefile,v 1.20 2016/01/24 16:14:44 jperkin Exp $

DISTNAME= gcc-${GCC_VERSION}
PKGNAME= gcc45-${GCC_VERSION}
Expand Down Expand Up @@ -118,7 +118,7 @@ CFLAGS+= -I${BUILDLINK_DIR}/include

# Somone should fix this so it will match the NetBSD system compiler
#.if ${OPSYS} == "NetBSD"
#GCC_PLATFORM= ${LOWER_ARCH}--${LOWER_OPSYS}${APPEND_ELF}
#GCC_PLATFORM= ${MACHINE_ARCH}--${LOWER_OPSYS}${APPEND_ELF}
#CONFIGURE_ARGS+= --host=${GCC_PLATFORM:Q}
#MAKE_ENV+= AR=/usr/bin/ar
#.endif # NetBSD
Expand Down
4 changes: 2 additions & 2 deletions lang/gcc46/Makefile
@@ -1,4 +1,4 @@
# $NetBSD: Makefile,v 1.28 2015/01/01 01:29:56 ryoon Exp $
# $NetBSD: Makefile,v 1.29 2016/01/24 16:14:44 jperkin Exp $

DISTNAME= gcc-${GCC_VERSION}
PKGNAME= gcc46-${GCC_VERSION}
Expand Down Expand Up @@ -111,7 +111,7 @@ CFLAGS+= -I${BUILDLINK_DIR}/include

# Someone should fix this so it will match the NetBSD system compiler
#.if ${OPSYS} == "NetBSD"
#GCC_PLATFORM= ${LOWER_ARCH}--${LOWER_OPSYS}${APPEND_ELF}
#GCC_PLATFORM= ${MACHINE_ARCH}--${LOWER_OPSYS}${APPEND_ELF}
#CONFIGURE_ARGS+= --host=${GCC_PLATFORM:Q}
#MAKE_ENV+= AR=/usr/bin/ar
#.endif # NetBSD
Expand Down
4 changes: 2 additions & 2 deletions lang/sbcl/Makefile
@@ -1,4 +1,4 @@
# $NetBSD: Makefile,v 1.63 2015/12/09 22:48:10 asau Exp $
# $NetBSD: Makefile,v 1.64 2016/01/24 16:14:44 jperkin Exp $

DISTNAME= ${PKGNAME_NOREV}-source
PKGNAME= sbcl-1.3.1
Expand Down Expand Up @@ -94,7 +94,7 @@ do-test:
# for f in compiler.pure.lisp interface.pure.lisp compiler.impure.lisp debug.impure.lisp interface.impure.lisp; do mv ${WRKSRC}/tests/$$f ${WRKSRC}/tests/$$f.off || :; done
cd ${WRKSRC}/tests && ${SH} ./run-tests.sh

.if $(LOWER_ARCH) == "amd64" || $(LOWER_ARCH) == "x86_64"
.if ${MACHINE_ARCH} == "x86_64"
PLIST_SUBST+= SUFX64=-64
.else
PLIST_SUBST+= SUFX64=
Expand Down

0 comments on commit e2b4d2c

Please sign in to comment.