Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 6 Aug 2015 13:20:27 +1030
From:      Michael Vale <m.vale@live.com.au>
To:        Adrian Chadd <adrian@freebsd.org>, "bapt@freebsd.org" <bapt@freebsd.org>,  "freebsd-mips@freebsd.org" <freebsd-mips@freebsd.org>, "freebsd-arm@freebsd.org" <freebsd-arm@freebsd.org>, "freebsd-embedded@freebsd.org" <freebsd-embedded@freebsd.org>
Subject:   Multi Arch ELF binary/object compiling, linking and more
Message-ID:  <COL130-W1677EAC8CAF590A2C4D068C4740@phx.gbl>

next in thread | raw e-mail | index | archive | help

[-- Attachment #1 --]
You can try and read my lyrics off of this paper before I lay 'emBut you won't take the sting out these words before I say 'emCause ain't no way I'ma let you stop me from causing mayhemWhen I say I'ma do something I do it,I don't give a damn what you think,I'm doing this for me, so fuck the worldFeed it beans, it's gassed up, if it thinks it's stopping mehttps://www.youtube.com/watch?v=j5-yKhDd64s

Hey,
Okay here it is.  It's not complete yet, but I'm throwing it out there while I have the chance.
One can specify the build machine's arch type with ARCH=, the host (and in turn the build machine if one is not set) with X_BUILD_FOR= and also finally the target with TARGET=.  You can choose to set all three to the same arch as the target, or whatever pleases you.  Surely if you're smart and doing some wicked fancy things you can benefit from setting different archs accordingly, if you're accessing these binaries and objects from a central storage and utilising resources over a network.
EDIT: What I forgot to mention is, to utilize "cross-compiling" allows one to run the same binaries and objects on multiple architectures.  So one would think the build variable would have to be one of the machine compiling the binaries and objects but that is not the case, it has other purposes too.  It has been clear in the GNU and FreeBSD way of things that by retaining the build variable as the one you compile the binary on and setting the HOST variable defines what "other" (sic.) architecture the binaries or object execute on when infact by setting HOST, you also tend to automatically adjust TARGET to suit.  The light on this matter is that you can infact set an intermediate HOST architecture to the TARGET that allows building tasks assigned to the BUILD variable, 'hosting' and 'operating' on the HOST architecture and native execution on the TARGET.  Don't think for one moment though that you can't set all three BUILD, HOST and TARGET to the TARGET architecture and use that binary or object as a development utility, host or native on the desired platform/architecture.
The work is rather complete, I've managed to build asterisk, kismet and different X11/Xorg servers and all their dependencies.
I haven't begun on slimming down the stage outfits into something suitable for embedded flashing and packaging.
https://www.youtube.com/watch?v=BE9CXWV1alg
- Michael. 		 	   		  
[-- Attachment #2 --]
--- /home/god/Downloads/bsd.port.mk.vanilla	2015-08-05 22:25:49.008326405 -0400
+++ /usr/ports/Mk/bsd.port.mk	2015-08-05 19:09:31.748150542 -0400
@@ -1,7 +1,7 @@
 #-*- tab-width: 4; -*-
 # ex:ts=4
 #
-# $FreeBSD$
+# $FreeBSD: head/Mk/bsd.port.mk 393054 2015-07-28 07:34:38Z mat $
 #	$NetBSD: $
 #
 #	bsd.port.mk - 940820 Jordan K. Hubbard.
@@ -1058,23 +1058,24 @@
 .if !defined(.PARSEDIR)
 IGNORE=	Cross building can only be done when using bmake(1) as make(1)
 .endif
+ARCH=	${X_BUILD_FOR}
 # Do not define CPP on purpose
 .if !defined(HOSTCC)
 HOSTCC:=	${CC}
 HOSTCXX:=	${CXX}
 .endif
-.if !exists(/usr/${X_BUILD_FOR}/usr/bin/cc)
+.if !exists(/usr/bin/mips-cc)
 X_SYSROOT=	${LOCALBASE}/${X_BUILD_FOR}
 .else
 X_SYSROOT=	/usr/${X_BUILD_FOR}
 .endif
-CC=		${X_SYSROOT}/usr/bin/cc
-CXX=	${X_SYSROOT}/usr/bin/c++
-NM=		${X_BUILD_FOR}-nm
-STRIP_CMD=	${X_BUILD_FOR}-strip
+#CC=		/usr/bin/mips-cc
+#CXX=		/usr/bin/mips-c++
+NM=		${X_BUILD_FOR}-freebsd-nm
+#STRIP_CMD=	${X_BUILD_FOR}-freebsd-strip
 # only bmake support the below
-STRIPBIN=	${STRIP_CMD}
-.export.env STRIPBIN
+#STRIPBIN=	${STRIP_CMD}
+#.export.env STRIPBIN
 .endif
 
 #
@@ -1234,7 +1235,7 @@
 PKGORIGIN?=		${PKGCATEGORY}/${PORTDIRNAME}
 
 # where 'make config' records user configuration options
-PORT_DBDIR?=	/var/db/ports
+PORT_DBDIR?=	${DESTDIR}/var/db/ports
 
 UID_FILES?=	${PORTSDIR}/UIDs
 GID_FILES?=	${PORTSDIR}/GIDs
@@ -1347,7 +1348,7 @@
 LDCONFIG_CMD?=			${LINUXBASE}/sbin/ldconfig -r ${LINUXBASE}
 .endif
 
-PKGCOMPATDIR?=		${LOCALBASE}/lib/compat/pkg
+PKGCOMPATDIR?=		${X_SYSROOT}${LOCALBASE}/lib/compat/pkg
 
 .if defined(USE_LOCAL_MK)
 .include "${PORTSDIR}/Mk/bsd.local.mk"
@@ -1522,10 +1523,28 @@
 				PORTSDIR="${PORTSDIR}"
 
 .if defined(X_BUILD_FOR)
-BUILD_DEPENDS+=	${X_BUILD_FOR}-cc:${PORTSDIR}/devel/${X_BUILD_FOR}-xdev
-PKG_ENV+=		ABI_FILE=${X_SYSROOT}/usr/lib/crt1.o
-MAKE_ENV+=		NM=${NM} \
-				STRIPBIN=${X_BUILD_FOR}-strip \
+
+PLIST_SUB=	TARGETARCH=${X_BUILD_FOR} #${PKGNAMEPREFIX:C/-//g} \
+		OPSYS=${OPSYS:tl} \
+		GCC_TARGET=${GCC_TARGET} \
+		GCC_VERSION=${PORTVERSION}
+
+#BUILD_DEPENDS+=        ${X_BUILD_FOR}-cc:${PORTSDIR}/devel/${X_BUILD_FOR}-gcc
+
+.if empty(GCC_TARGET)
+# We are building for a FreeBSD target
+GCC_TARGET?=    ${X_BUILD_FOR}-${OPSYS:tl} # ${PKGNAMEPREFIX}port
+BU_PREFIX?=     ${X_BUILD_FOR}-${OPSYS:tl} # ${PKGNAMEPREFIX}${OPSYS:tl}
+.else
+BU_PREFIX?=     ${GCC_TARGET}
+.endif
+
+#INCS+=		-I${X_SYSROOT}/usr/include -I${X_SYSROOT}/usr/local/include
+PKG_ENV+=			ABI_FILE=${X_SYSROOT}/usr/lib/crt1.o
+MAKE_ENV+=			NM=${NM} \
+				CFLAGS=${INCS} \
+				CXXFLAGS=${INCS} \
+				STRIPBIN=${X_BUILD_FOR}-freebsd-strip \
 				PKG_CONFIG_SYSROOT_DIR="${X_SYSROOT}"
 CONFIGURE_ENV+=	PKG_CONFIG_SYSROOT_DIR="${X_SYSROOT}"
 .endif
@@ -1608,8 +1627,13 @@
 PLIST_SUB+=	        PORTEXAMPLES=""
 .endif
 
-CONFIGURE_SHELL?=	${SH}
-MAKE_SHELL?=	${SH}
+.if !defined(X_BUILD_FOR)
+CONFIGURE_SHELL?=       ${SH}
+MAKE_SHELL?=    ${SH}
+.else
+CONFIGURE_SHELL?=       /bin/sh
+MAKE_SHELL?=            /bin/sh
+.endif
 
 CONFIGURE_ENV+=	SHELL=${CONFIGURE_SHELL} CONFIG_SHELL=${CONFIGURE_SHELL}
 MAKE_ENV+=		SHELL=${MAKE_SHELL} NO_LINT=YES
@@ -2550,7 +2574,7 @@
 
 CONFIGURE_SCRIPT?=	configure
 CONFIGURE_CMD?=		./${CONFIGURE_SCRIPT}
-CONFIGURE_TARGET?=	${ARCH}-portbld-${OPSYS:tl}${OSREL}
+CONFIGURE_TARGET?=	${ARCH}-${OPSYS:tl}
 CONFIGURE_TARGET:=	${CONFIGURE_TARGET:S/--build=//}
 CONFIGURE_LOG?=		config.log
 
@@ -2567,7 +2591,10 @@
 CONFIG_SITE?=		${PORTSDIR}/Templates/config.site
 CONFIGURE_ARGS+=	--prefix=${GNU_CONFIGURE_PREFIX} $${_LATE_CONFIGURE_ARGS}
 .if defined(X_BUILD_FOR)
-CONFIGURE_ARGS+=	--host=${X_BUILD_FOR}
+CONFIGURE_ARGS+=	--host=${X_BUILD_FOR}-portbld-${OPSYS:tl}${OSREL}
+.endif
+.if defined(TARGET)
+CONFIGURE_ARGS+=        --target=${TARGET}-${OPSYS:tl}
 .endif
 CONFIGURE_ENV+=		CONFIG_SITE=${CONFIG_SITE} lt_cv_sys_max_cmd_len=${CONFIGURE_MAX_CMD_LEN}
 HAS_CONFIGURE=		yes

Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?COL130-W1677EAC8CAF590A2C4D068C4740>