1 | #!/bin/bash
|
---|
2 | #
|
---|
3 | # Multi-arch handling functions for cross-lfs build
|
---|
4 | # -------------------------------------------------
|
---|
5 | # $LastChangedBy$
|
---|
6 | # $LastChangedDate$
|
---|
7 | # $LastChangedRevision$
|
---|
8 | # $HeadURL$
|
---|
9 | #
|
---|
10 |
|
---|
11 | # TODO: should really check if DEFAULTENV and LIBDIRENV have been set
|
---|
12 | # in plfs-config and bail out if they have not...
|
---|
13 |
|
---|
14 | set_buildenv() {
|
---|
15 | case ${SELF} in
|
---|
16 | *-64.sh ) BUILDENV=64 ;;
|
---|
17 | *-32.sh ) BUILDENV=32 ;;
|
---|
18 | *-n32.sh ) BUILDENV=n32 ;;
|
---|
19 | *-o32.sh ) BUILDENV=o32 ;;
|
---|
20 | *-o64.sh ) BUILDENV=o64 ;;
|
---|
21 | * ) BUILDENV=${DEFAULTENV} ;;
|
---|
22 | esac
|
---|
23 |
|
---|
24 | export BUILDENV
|
---|
25 | }
|
---|
26 |
|
---|
27 | set_libdirname() {
|
---|
28 | # TODO: this will barf on mips if setting 64bit libs to go to */lib
|
---|
29 | # but will work if setting
|
---|
30 | if [ -z "${BUILDENV}" ]; then
|
---|
31 | BUILDENV=${DEFAULTENV}
|
---|
32 | export BUILDENV
|
---|
33 | fi
|
---|
34 | if [ ! "${BUILDENV}" = "${LIBDIRENV}" ]; then
|
---|
35 | case ${BUILDENV} in
|
---|
36 | 32 | o32 | n32 ) libdirname=lib32 ;;
|
---|
37 | 64 | o64 ) libdirname=lib64 ;;
|
---|
38 | * ) echo "unknown buildenv ${BUILDENV}"; return 1
|
---|
39 | esac
|
---|
40 | LOG=`echo ${LOG} | sed "s@\.log@-${BUILDENV}&@"`
|
---|
41 | else
|
---|
42 | libdirname=lib
|
---|
43 | fi
|
---|
44 |
|
---|
45 | # Adjust PKG_CONFIG_PATH
|
---|
46 | PKG_CONFIG_PATH=`echo "${PKG_CONFIG_PATH}" | \
|
---|
47 | sed -e "s@lib[36][124]@lib@g" -e "s@lib@${libdirname}@g" `
|
---|
48 |
|
---|
49 | # Adjust GNOME_LIBCONF_PATH
|
---|
50 | GNOME_LIBCONF_PATH=`echo "${GNOME_LIBCONF_PATH}" | \
|
---|
51 | sed -e "s@lib[36][124]@lib@g" -e "s@lib@${libdirname}@g" `
|
---|
52 |
|
---|
53 | # JAVA handling ... see java-setup.sh
|
---|
54 | #------------------------------------
|
---|
55 | # TODO: This needs to be done a WHOLE lot better...
|
---|
56 | TMP_JAVA_HOME="${JAVA_INSTALLDIR}/jdk${JAVA_VER}"
|
---|
57 | if [ "${MULTIARCH}" = "Y" ]; then
|
---|
58 | TMP_JAVA_HOME="${TMP_JAVA_HOME}-${BUILDENV}"
|
---|
59 | fi
|
---|
60 | if [ -d "${TMP_JAVA_HOME}" ]; then
|
---|
61 | export JAVA_HOME="${TMP_JAVA_HOME}"
|
---|
62 |
|
---|
63 | # Alter PATH
|
---|
64 | echo "${PATH}" | grep "${JAVA_INSTALLDIR}/jdk${JAVA_VER}" \
|
---|
65 | > /dev/null 2>&1 &&
|
---|
66 | {
|
---|
67 | PATH=`echo "${PATH}" | sed -e "s@${JAVA_INSTALLDIR}/jdk${JAVA_VER}\(\|-[36][124]\)@${JAVA_HOME}@g" `
|
---|
68 | } || {
|
---|
69 | PATH="${PATH}:${JAVA_HOME}/bin"
|
---|
70 | }
|
---|
71 | fi
|
---|
72 |
|
---|
73 | }
|
---|
74 |
|
---|
75 | # Following function sets compiler options
|
---|
76 | setup_multiarch() {
|
---|
77 | if [ "Y" = "${MULTIARCH}" ]; then
|
---|
78 | vendor_os=`echo ${TARGET} | sed 's@\([^-]*\)-\(.*\)@\2@'`
|
---|
79 | TGT_ARCH=`echo ${TARGET} | sed 's@\([^-]*\).*@\1@'`
|
---|
80 |
|
---|
81 | ARCH_CFLAGS=""
|
---|
82 | ALT_TGT=""
|
---|
83 |
|
---|
84 | case ${BUILDENV} in
|
---|
85 | 64 )
|
---|
86 | case ${TGT_ARCH} in
|
---|
87 | x86_64 ) ARCH_CFLAGS="-m${BUILDENV}"
|
---|
88 | ARCH_LDFLAGS="-m elf_x86_64" ;;
|
---|
89 | powerpc* | ppc* | s390* )
|
---|
90 | ARCH_CFLAGS="-m${BUILDENV}" ;;
|
---|
91 | sparc* ) ARCH_CFLAGS="-m${BUILDENV}"
|
---|
92 | ALT_TGT=sparc64-${vendor_os} ;;
|
---|
93 | mips*el* ) ARCH_CFLAGS="-mabi=${BUILDENV}"
|
---|
94 | ALT_TGT="mips64el-${vendor_os}" ;;
|
---|
95 | * )
|
---|
96 | echo "### Unknown: ${TGT_ARCH} - ${BUILDENV} ###" 1>&2
|
---|
97 | return 1
|
---|
98 | ;;
|
---|
99 | esac
|
---|
100 | ;;
|
---|
101 | 32 )
|
---|
102 | case ${TGT_ARCH} in
|
---|
103 | x86_64 | x86-64 ) ARCH_CFLAGS="-m${BUILDENV}"
|
---|
104 | ARCH_LDFLAGS="-m elf_i386"
|
---|
105 | ALT_TGT="i686-${vendor_os}" ;;
|
---|
106 | powerpc* | ppc* ) ARCH_CFLAGS="-m${BUILDENV}"
|
---|
107 | ALT_TGT="ppc-${vendor_os}" ;;
|
---|
108 | sparc* ) ARCH_CFLAGS="-m${BUILDENV}"
|
---|
109 | ALT_TGT="sparcv9-${vendor_os}" ;;
|
---|
110 | mips*el* ) ARCH_CFLAGS="-mabi=${BUILDENV}"
|
---|
111 | ALT_TGT="mipsel-${vendor_os}" ;;
|
---|
112 | * )
|
---|
113 | echo "### Unknown: ${TGT_ARCH} - ${BUILDENV} ###" 1>&2
|
---|
114 | return 1
|
---|
115 | ;;
|
---|
116 | esac
|
---|
117 | ;;
|
---|
118 | n32 )
|
---|
119 | case ${TGT_ARCH} in
|
---|
120 | mips*el* ) ARCH_CFLAGS="-mabi=${BUILDENV}" ;;
|
---|
121 | * )
|
---|
122 | echo "### Unknown: ${TGT_ARCH} - ${BUILDENV} ###" 1>&2
|
---|
123 | return 1
|
---|
124 | ;;
|
---|
125 | esac
|
---|
126 | ;;
|
---|
127 | 31 )
|
---|
128 | case ${TGT_ARCH} in
|
---|
129 | s390* ) ARCH_CFLAGS="-m${BUILDENV}"
|
---|
130 | ALT_TGT="s390-${vender_os}" ;;
|
---|
131 | * )
|
---|
132 | echo "### Unknown: ${TGT_ARCH} - ${BUILDENV} ###" 1>&2
|
---|
133 | return 1
|
---|
134 | ;;
|
---|
135 | esac
|
---|
136 | ;;
|
---|
137 | * )
|
---|
138 | echo "### Unknown biarch system ###" 1>&2
|
---|
139 | return 1
|
---|
140 | ;;
|
---|
141 | esac
|
---|
142 |
|
---|
143 | suffix="-${BUILDENV}"
|
---|
144 | fi
|
---|
145 | }
|
---|
146 |
|
---|
147 | create_wrapper() {
|
---|
148 | # want one arg only, the name of the wrapper file to create
|
---|
149 | if [ ! "${#}" = "1" ]; then
|
---|
150 | echo "create_wrapper: error, use create_wrapper /path/to/wrapper" 1>&2
|
---|
151 | return 1
|
---|
152 | fi
|
---|
153 | wrapper=${1}
|
---|
154 |
|
---|
155 | if [ -z "${DEFAULTENV}" ]; then
|
---|
156 | echo "create_wrapper: error, DEFAULTENV not set" 1>&2
|
---|
157 | return 1
|
---|
158 | fi
|
---|
159 |
|
---|
160 | wrapperdir=`dirname ${wrapper}`
|
---|
161 | if [ ! -d ${wrapperdir} ]; then mkdir -p ${wrapperdir} ; fi
|
---|
162 |
|
---|
163 | cat > wrapper.c <<"EOF"
|
---|
164 | /*
|
---|
165 |
|
---|
166 | wrapper.c - c wrapper for cross-lfs multiarch handling
|
---|
167 | ------------------------------------------------------
|
---|
168 | Created By: Ryan Oliver <ryan.oliver@pha.com.au> 20050606
|
---|
169 |
|
---|
170 | $LastChangedBy$
|
---|
171 | $LastChangedDate$
|
---|
172 | $LastChangedRevision$
|
---|
173 | $HeadURL$
|
---|
174 |
|
---|
175 | */
|
---|
176 |
|
---|
177 | #include <unistd.h>
|
---|
178 | #include <stdlib.h>
|
---|
179 | #include <errno.h>
|
---|
180 |
|
---|
181 | /* TODO: should check for __x86_64__ , __powerpc64__ etc and set accordingly */
|
---|
182 | #ifndef DEFAULTENV
|
---|
183 | #define DEFAULTENV "64"
|
---|
184 | #endif
|
---|
185 |
|
---|
186 | int main(int argc, char **argv) {
|
---|
187 |
|
---|
188 | char *filename;
|
---|
189 | char *buildenv;
|
---|
190 |
|
---|
191 | if(!(buildenv = getenv("BUILDENV")))
|
---|
192 | buildenv = DEFAULTENV;
|
---|
193 |
|
---|
194 | filename = (char *) malloc(strlen(argv[0]) + strlen(buildenv) + 2);
|
---|
195 | strcpy(filename, argv[0]);
|
---|
196 | strcat(filename, "-");
|
---|
197 | strcat(filename, buildenv);
|
---|
198 |
|
---|
199 | execvp(filename, argv);
|
---|
200 | perror(argv[0]);
|
---|
201 | free(filename);
|
---|
202 |
|
---|
203 | }
|
---|
204 | EOF
|
---|
205 |
|
---|
206 | OLD_BUILDENV="${BUILDENV}"
|
---|
207 | BUILDENV="${DEFAULTENV}"
|
---|
208 | setup_multiarch
|
---|
209 |
|
---|
210 | ${CC-gcc} ${ARCH_CFLAGS} -DDEFAULTENV=\"${DEFAULTENV}\" \
|
---|
211 | wrapper.c -o ${wrapper}
|
---|
212 | chmod 755 ${wrapper}
|
---|
213 |
|
---|
214 | BUILDENV="${OLD_BUILDENV}"
|
---|
215 |
|
---|
216 | }
|
---|
217 |
|
---|
218 | use_wrapper() {
|
---|
219 | set -x
|
---|
220 | # Use full path
|
---|
221 | wrapper=/usr/bin/multilib_wrapper
|
---|
222 |
|
---|
223 | if [ "${#}" = "0" ]; then
|
---|
224 | echo "use_wrapper: error, no files specified" 1>&2
|
---|
225 | return 1
|
---|
226 | fi
|
---|
227 | if [ -z "${BUILDENV}" ]; then
|
---|
228 | echo "use_wrapper: error, BUILDENV not set" 1>&2
|
---|
229 | return 1
|
---|
230 | fi
|
---|
231 |
|
---|
232 | echo " o set files to use multi-arch wrapper ( ${wrapper} )"
|
---|
233 | if [ ! -f ${wrapper} ]; then create_wrapper ${wrapper} || return 1 ; fi
|
---|
234 |
|
---|
235 | for file in ${@} ; do
|
---|
236 | if [ ! -f ${file} ]; then
|
---|
237 | echo "use_wrapper: error, ${file} is not a regular file" 1>&2
|
---|
238 | return 1
|
---|
239 | fi
|
---|
240 |
|
---|
241 | if [ -L ${file} ]; then
|
---|
242 | # eek, old wrapper symlink wasn't replaced...
|
---|
243 | echo "use_wrapper: error, ${file} is a symlink" 1>&2
|
---|
244 | return 1
|
---|
245 | fi
|
---|
246 |
|
---|
247 |
|
---|
248 | # do the work
|
---|
249 | mv ${file} ${file}-${BUILDENV} &&
|
---|
250 | ln -sfnv ${wrapper} ${file} &&
|
---|
251 | echo " - ${file}" || {
|
---|
252 | echo "use_wrapper: error creating ${file}" 1>&2
|
---|
253 | return 1
|
---|
254 | }
|
---|
255 |
|
---|
256 | done
|
---|
257 | set +x
|
---|
258 | }
|
---|
259 |
|
---|
260 | export -f set_buildenv
|
---|
261 | export -f set_libdirname
|
---|
262 | export -f setup_multiarch
|
---|
263 | export -f create_wrapper
|
---|
264 | export -f use_wrapper
|
---|