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