source: scripts/funcs/multiarch-funcs.sh@ f5aa871

clfs-1.2 clfs-2.1 clfs-3.0.0-systemd clfs-3.0.0-sysvinit systemd sysvinit
Last change on this file since f5aa871 was 9b5d6cdc, checked in by Jim Gifford <clfs@…>, 19 years ago

r569@server (orig r567): ryan | 2005-06-09 08:37:18 -0700
Remove export of now non-existent which_func



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