cross-compile.env: make it MACHINE-agnostic
[opendreambox.git] / cross-compile.env
1 #!/bin/bash
2
3 oe_set_aliases()
4 {
5         local SCRIPT="${BASH_SOURCE[0]}"
6         if [ -z "${SCRIPT}" ]; then
7                 echo "Could not determine script location! Not using bash?"
8                 return
9         fi
10         while [ -h "${SCRIPT}" ]; do
11                 SCRIPT="$(readlink "${SCRIPT}")"
12         done
13
14         local SCRIPTDIR="$(cd -P `dirname "${SCRIPT}"` && pwd)"
15         local MACHINE="$1"
16         local MACHINE_ENV=".cross-compile-${MACHINE}.env"
17         local MAKE=${MAKE:-make}
18
19         ${MAKE} -C "${SCRIPTDIR}" -s MACHINE=${MACHINE} ${MACHINE_ENV} || return
20         . ${SCRIPTDIR}/${MACHINE_ENV} || return
21
22         #
23         # cf. openembedded-core/meta/conf/bitbake.conf
24         #
25
26         # Used by multilib code to change the library paths
27         local baselib="lib"
28
29         # Path prefixes
30         local base_prefix=""
31         local prefix="/usr"
32         local exec_prefix="/usr"
33
34         # Base paths
35         local base_bindir="${base_prefix}/bin"
36         local base_sbindir="${base_prefix}/sbin"
37         local base_libdir="${base_prefix}/${baselib}"
38
39         # Architecture independent paths
40         local datadir="${prefix}/share"
41         local sysconfdir="${base_prefix}/etc"
42         local servicedir="${base_prefix}/srv"
43         local sharedstatedir="${base_prefix}/com"
44         local localstatedir="${base_prefix}/var"
45         local infodir="${datadir}/info"
46         local mandir="${datadir}/man"
47         local docdir="${datadir}/doc"
48
49         # Architecture dependent paths
50         local bindir="${exec_prefix}/bin"
51         local sbindir="${exec_prefix}/sbin"
52         local libexecdir="${exec_prefix}/libexec"
53         local libdir="${exec_prefix}/${baselib}"
54         local includedir="${exec_prefix}/include"
55         local oldincludedir="${exec_prefix}/include"
56
57         # Linkage between native layouts
58         local base_bindir_native="/bin"
59         local base_sbindir_native="/sbin"
60         local sysconfdir_native="/etc"
61         local prefix_native="/usr"
62         local bindir_native="${prefix_native}/bin"
63         local sbindir_native="${prefix_native}/sbin"
64         local includedir_native="${prefix_native}/include"
65         local libdir_native="${prefix_native}/lib"
66         local base_libdir_native="/lib"
67         local datadir_native="${prefix_native}/share"
68
69         # Architecture-dependent build variables.
70         local BUILD_ARCH="$(uname -m)"
71         local BUILD_OS="$(uname -s | tr '[:upper:]' '[:lower:]')"
72         local BUILD_VENDOR=""
73         local BUILD_SYS="${BUILD_ARCH}${BUILD_VENDOR}-${BUILD_OS}"
74         local BUILD_PREFIX=""
75         local BUILD_CC_ARCH=""
76         local BUILD_LD_ARCH=""
77         local BUILD_AS_ARCH=""
78         local BUILD_EXEEXT=""
79
80         local TARGET_ARCH="${TUNE_ARCH}"
81         local TARGET_OS="linux${LIBCEXTENSION}${ABIEXTENSION}"
82         local TARGET_VENDOR="-oe"
83         local TARGET_SYS="${TARGET_ARCH}${TARGET_VENDOR}-${TARGET_OS}"
84         local TARGET_PREFIX="${TARGET_SYS}-"
85         local TARGET_CC_ARCH="${TUNE_CCARGS}"
86         local TARGET_LD_ARCH="${TUNE_LDARGS}"
87         local TARGET_AS_ARCH="${TUNE_ASARGS}"
88
89         local HOST_ARCH="${TARGET_ARCH}"
90         local HOST_OS="${TARGET_OS}"
91         local HOST_VENDOR="${TARGET_VENDOR}"
92         local HOST_SYS="${HOST_ARCH}${HOST_VENDOR}-${HOST_OS}"
93         local HOST_PREFIX="${TARGET_PREFIX}"
94         local HOST_CC_ARCH="${TARGET_CC_ARCH}"
95         local HOST_LD_ARCH="${TARGET_LD_ARCH}"
96         local HOST_AS_ARCH="${TARGET_AS_ARCH}"
97         local HOST_EXEEXT=""
98
99         local PACKAGE_ARCH="${TUNE_PKGARCH}"
100         local MULTIMACH_TARGET_SYS="${PACKAGE_ARCH}${TARGET_VENDOR}-${TARGET_OS}"
101         local MULTIMACH_HOST_SYS="${PACKAGE_ARCH}${HOST_VENDOR}-${HOST_OS}"
102
103         # General work and output directories for the build system.
104         local STAGING_DIR="${TMPDIR}/sysroots"
105
106         local STAGING_DIR_HOST="${STAGING_DIR}/${MACHINE}"
107         local STAGING_BINDIR="${STAGING_DIR_HOST}${bindir}"
108         local STAGING_LIBDIR="${STAGING_DIR_HOST}${libdir}"
109         local STAGING_INCDIR="${STAGING_DIR_HOST}${includedir}"
110         local STAGING_DATADIR="${STAGING_DIR_HOST}${datadir}"
111
112         local STAGING_DIR_NATIVE="${STAGING_DIR}/${BUILD_SYS}"
113         local STAGING_BINDIR_NATIVE="${STAGING_DIR_NATIVE}${bindir_native}"
114         local STAGING_BINDIR_CROSS="${STAGING_BINDIR}/crossscripts"
115         local STAGING_BINDIR_TOOLCHAIN="${STAGING_DIR_NATIVE}${bindir_native}/${TUNE_PKGARCH}${TARGET_VENDOR}-${TARGET_OS}"
116
117         local STAGING_DIR_TARGET="${STAGING_DIR}/${MACHINE}"
118
119         # Toolchain info.
120         local OE_PATH="${STAGING_BINDIR_TOOLCHAIN}:${STAGING_BINDIR_CROSS}:${STAGING_DIR_NATIVE}${sbindir_native}:${STAGING_BINDIR_NATIVE}:${STAGING_DIR_NATIVE}${base_sbindir_native}:${STAGING_DIR_NATIVE}/${base_bindir_native}"
121
122         # Build utility info.
123         local TOOLCHAIN_OPTIONS=" --sysroot=${STAGING_DIR_TARGET}"
124         local CC="${CCACHE}${HOST_PREFIX}gcc ${HOST_CC_ARCH}${TOOLCHAIN_OPTIONS}"
125         local CXX="${CCACHE}${HOST_PREFIX}g++ ${HOST_CC_ARCH}${TOOLCHAIN_OPTIONS}"
126         local F77="${CCACHE}${HOST_PREFIX}g77 ${HOST_CC_ARCH}${TOOLCHAIN_OPTIONS}"
127         local CPP="${HOST_PREFIX}gcc -E${TOOLCHAIN_OPTIONS} ${HOST_CC_ARCH}"
128         local LD="${HOST_PREFIX}ld${TOOLCHAIN_OPTIONS} ${HOST_LD_ARCH}"
129         local CCLD="${CC}"
130         local AR="${HOST_PREFIX}ar"
131         local AS="${HOST_PREFIX}as ${HOST_AS_ARCH}"
132         local RANLIB="${HOST_PREFIX}ranlib"
133         local STRIP="${HOST_PREFIX}strip"
134         local OBJCOPY="${HOST_PREFIX}objcopy"
135         local OBJDUMP="${HOST_PREFIX}objdump"
136         local NM="${HOST_PREFIX}nm"
137
138         local PKG_CONFIG_DIR="${STAGING_DIR_HOST}/${libdir}/pkgconfig"
139         local PKG_CONFIG_PATH="${PKG_CONFIG_DIR}:${STAGING_DATADIR}/pkgconfig"
140         local PKG_CONFIG_LIBDIR="${PKG_CONFIG_DIR}"
141         local PKG_CONFIG_SYSROOT_DIR="${STAGING_DIR_HOST}"
142         local PKG_CONFIG_DISABLE_UNINSTALLED="yes"
143
144         local OE_ENV=" \
145                 BUILD_SYS=\"${BUILD_SYS}\" \
146                 HOST_SYS=\"${HOST_SYS}\" \
147                 STAGING_LIBDIR=\"${STAGING_LIBDIR}\" \
148                 STAGING_INCDIR=\"${STAGING_INCDIR}\" \
149                 PATH=\"${OE_PATH}:${PATH}\" \
150                 CC=\"${CC}\" \
151                 CXX=\"${CXX}\" \
152                 F77=\"${F77}\" \
153                 CPP=\"${CPP}\" \
154                 LD=\"${LD}\" \
155                 CCLD=\"${CCLD}\" \
156                 AR=\"${AR}\" \
157                 AS=\"${AS}\" \
158                 RANLIB=\"${RANLIB}\" \
159                 STRIP=\"${STRIP}\" \
160                 OBJCOPY=\"${OBJCOPY}\" \
161                 OBJDUMP=\"${OBJDUMP}\" \
162                 NM=\"${NM}\" \
163                 PKG_CONFIG_DIR=\"${PKG_CONFIG_DIR}\" \
164                 PKG_CONFIG_PATH=\"${PKG_CONFIG_PATH}\" \
165                 PKG_CONFIG_LIBDIR=\"${PKG_CONFIG_LIBDIR}\" \
166                 PKG_CONFIG_SYSROOT_DIR=\"${PKG_CONFIG_SYSROOT_DIR}\" \
167                 PKG_CONFIG_DISABLE_UNINSTALLED=\"${PKG_CONFIG_DISABLE_UNINSTALLED}\" \
168         "
169
170         echo "Creating shell command aliases:"
171         echo "* oe_autoreconf"
172         alias oe_autoreconf="${OE_ENV} autoreconf -Wcross --verbose --install --force --exclude=autopoint"
173
174         echo "* oe_runconf"
175         alias oe_runconf=" \
176                 ./configure \
177                         --build=${BUILD_SYS} \
178                         --host=${HOST_SYS} \
179                         --target=${TARGET_SYS} \
180                         --prefix=${prefix} \
181                         --exec_prefix=${exec_prefix} \
182                         --bindir=${bindir} \
183                         --sbindir=${sbindir} \
184                         --libexecdir=${libexecdir} \
185                         --datadir=${datadir} \
186                         --sysconfdir=${sysconfdir} \
187                         --sharedstatedir=${sharedstatedir} \
188                         --localstatedir=${localstatedir} \
189                         --libdir=${libdir} \
190                         --includedir=${includedir} \
191                         --oldincludedir=${oldincludedir} \
192                         --infodir=${infodir} \
193                         --mandir=${mandir} \
194                         --with-libtool-sysroot=${STAGING_DIR_HOST} \
195                         ${OE_ENV} \
196         "
197
198         echo "* oe_runmake"
199         alias oe_runmake="${MAKE} ${PARALLEL_MAKE} ${OE_ENV}"
200
201         echo "* oe_env"
202         alias oe_env="${OE_ENV}"
203
204         echo "* oe_setenv"
205         alias oe_setenv="export ${OE_ENV}"
206 }
207
208 oe_set_aliases $1