source: scripts/funcs/multiarch-funcs.sh@ 0ee931e

clfs-1.2 clfs-2.1 clfs-3.0.0-systemd clfs-3.0.0-sysvinit systemd sysvinit
Last change on this file since 0ee931e was 23b6afb, checked in by Jim Gifford <clfs@…>, 19 years ago

r564@server (orig r562): jim | 2005-06-07 20:12:28 -0700
Mirrored from jg555.com on Tue Jun 7 20:12:17 PDT 2005
----------------------------------------------------------------------


  • Property mode set to 100755
File size: 6.3 KB
Line 
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
14set_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
27set_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}
54
55which_func() {
56 type ${1} | \
57 sed -e 's@.* \(.*\)$@\1@g' \
58 -e 's@[()]@@g'
59}
60
61
62# Following function sets compiler options
63setup_multiarch() {
64 if [ "Y" = "${MULTIARCH}" ]; then
65 vendor_os=`echo ${TARGET} | sed 's@\([^-]*\)-\(.*\)@\2@'`
66 TGT_ARCH=`echo ${TARGET} | sed 's@\([^-]*\).*@\1@'`
67
68 ARCH_CFLAGS=""
69 ALT_TGT=""
70
71 case ${BUILDENV} in
72 64 )
73 case ${TGT_ARCH} in
74 x86_64 ) ARCH_CFLAGS="-m${BUILDENV}"
75 ARCH_LDFLAGS="-m elf_x86_64" ;;
76 powerpc* | ppc* | s390* )
77 ARCH_CFLAGS="-m${BUILDENV}" ;;
78 sparc* ) ARCH_CFLAGS="-m${BUILDENV}"
79 ALT_TGT=sparc64-${vendor_os} ;;
80 mips*el* ) ARCH_CFLAGS="-mabi=${BUILDENV}"
81 ALT_TGT="mips64el-${vendor_os}" ;;
82 * )
83 echo "### Unknown: ${TGT_ARCH} - ${BUILDENV} ###" 1>&2
84 return 1
85 ;;
86 esac
87 ;;
88 32 )
89 case ${TGT_ARCH} in
90 x86_64 | x86-64 ) ARCH_CFLAGS="-m${BUILDENV}"
91 ARCH_LDFLAGS="-m elf_i386"
92 ALT_TGT="i686-${vendor_os}" ;;
93 powerpc* | ppc* ) ARCH_CFLAGS="-m${BUILDENV}"
94 ALT_TGT="ppc-${vendor_os}" ;;
95 sparc* ) ARCH_CFLAGS="-m${BUILDENV}"
96 ALT_TGT="sparcv9-${vendor_os}" ;;
97 mips*el* ) ARCH_CFLAGS="-mabi=${BUILDENV}"
98 ALT_TGT="mipsel-${vendor_os}" ;;
99 * )
100 echo "### Unknown: ${TGT_ARCH} - ${BUILDENV} ###" 1>&2
101 return 1
102 ;;
103 esac
104 ;;
105 n32 )
106 case ${TGT_ARCH} in
107 mips*el* ) ARCH_CFLAGS="-mabi=${BUILDENV}" ;;
108 * )
109 echo "### Unknown: ${TGT_ARCH} - ${BUILDENV} ###" 1>&2
110 return 1
111 ;;
112 esac
113 ;;
114 31 )
115 case ${TGT_ARCH} in
116 s390* ) ARCH_CFLAGS="-m${BUILDENV}"
117 ALT_TGT="s390-${vender_os}" ;;
118 * )
119 echo "### Unknown: ${TGT_ARCH} - ${BUILDENV} ###" 1>&2
120 return 1
121 ;;
122 esac
123 ;;
124 * )
125 echo "### Unknown biarch system ###" 1>&2
126 return 1
127 ;;
128 esac
129
130 suffix="-${BUILDENV}"
131 fi
132}
133
134create_wrapper() {
135 # want one arg only, the name of the wrapper file to create
136 if [ ! "${#}" = "1" ]; then
137 echo "create_wrapper: error, use create_wrapper /path/to/wrapper" 1>&2
138 return 1
139 fi
140 wrapper=${1}
141
142 if [ -z "${DEFAULTENV}" ]; then
143 echo "create_wrapper: error, DEFAULTENV not set" 1>&2
144 return 1
145 fi
146
147 wrapperdir=`dirname ${wrapper}`
148 if [ ! -d ${wrapperdir} ]; then mkdir -p ${wrapperdir} ; fi
149
150 cat > wrapper.c <<"EOF"
151/*
152
153 wrapper.c - c wrapper for cross-lfs multiarch handling
154 ------------------------------------------------------
155 Created By: Ryan Oliver <ryan.oliver@pha.com.au> 20050606
156
157 $LastChangedBy$
158 $LastChangedDate$
159 $LastChangedRevision$
160 $HeadURL$
161
162 */
163
164#include <unistd.h>
165#include <stdlib.h>
166#include <errno.h>
167
168/* TODO: should check for __x86_64__ , __powerpc64__ etc and set accordingly */
169#ifndef DEFAULTENV
170#define DEFAULTENV "64"
171#endif
172
173int main(int argc, char **argv) {
174
175 char *filename;
176 char *buildenv;
177
178 if(!(buildenv = getenv("BUILDENV")))
179 buildenv = DEFAULTENV;
180
181 filename = (char *) malloc(strlen(argv[0]) + strlen(buildenv) + 2);
182 strcpy(filename, argv[0]);
183 strcat(filename, "-");
184 strcat(filename, buildenv);
185
186 execvp(filename, argv);
187 perror(argv[0]);
188 free(filename);
189
190}
191EOF
192
193 OLD_BUILDENV="${BUILDENV}"
194 BUILDENV="${DEFAULTENV}"
195 setup_multiarch
196
197 ${CC-gcc} ${ARCH_CFLAGS} -DDEFAULTENV=\"${DEFAULTENV}\" \
198 wrapper.c -o ${wrapper}
199 chmod 755 ${wrapper}
200
201 BUILDENV="${OLD_BUILDENV}"
202
203}
204
205use_wrapper() {
206 # Use full path
207 wrapper=/usr/bin/multilib_wrapper
208
209 if [ "${#}" = "0" ]; then
210 echo "use_wrapper: error, no files specified" 1>&2
211 return 1
212 fi
213 if [ -z "${BUILDENV}" ]; then
214 echo "use_wrapper: error, BUILDENV not set" 1>&2
215 return 1
216 fi
217
218 echo " o set files to use multi-arch wrapper ( ${wrapper} )"
219 if [ ! -f ${wrapper} ]; then create_wrapper ${wrapper} || return 1 ; fi
220
221 for file in ${@} ; do
222 if [ ! -f ${file} ]; then
223 echo "use_wrapper: error, ${file} is not a regular file" 1>&2
224 return 1
225 fi
226
227 # do the work
228 mv ${file} ${file}-${BUILDENV} &&
229 ln -sf ${wrapper} ${file} &&
230 echo " - ${file}" || {
231 echo "use_wrapper: error creating ${file}" 1>&2
232 return 1
233 }
234
235 done
236}
237
238export -f set_buildenv
239export -f set_libdirname
240export -f setup_multiarch
241export -f create_wrapper
242export -f use_wrapper
243export -f which_func
Note: See TracBrowser for help on using the repository browser.