source: scripts/funcs/stub_header-funcs.sh@ 0fd3a9e

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

r561@server (orig r559): root | 2005-06-05 02:38:49 -0700
Fixed Directory Structure

  • Property mode set to 100755
File size: 4.5 KB
Line 
1#!/bin/bash
2#
3# Stub Header Functions for cross-lfs build
4# -----------------------------------------
5# $LastChangedBy$
6# $LastChangedDate$
7# $LastChangedRevision$
8# $HeadURL$
9#
10
11set_stub_arch_switch() {
12 # TODO: this needs to be revisited... only handles 2 arches
13 case ${TGT_ARCH} in
14 x86_64 )
15 LIBDIRENV=${LIBDIRENV-32}
16 DEFAULTENV=${DEFAULTENV-64}
17 ARCH_SWITCH=__x86_64__
18 ENV1=64
19 ENV2=32
20 ;;
21 sparc* | ultrasparc* )
22 LIBDIRENV=${LIBDIRENV-32}
23 DEFAULTENV=${DEFAULTENV-64}
24 ARCH_SWITCH=__arch64__
25 ENV1=64
26 ENV2=32
27 ;;
28 ppc* | powerpc* )
29 LIBDIRENV=${LIBDIRENV-32}
30 DEFAULTENV=${DEFAULTENV-64}
31 ARCH_SWITCH=__powerpc64__
32 ENV1=64
33 ENV2=32
34 ;;
35 s390* )
36 LIBDIRENV=${LIBDIRENV-31}
37 DEFAULTENV=${DEFAULTENV-64}
38 ARCH_SWITCH=__s390x__
39 ENV1=64
40 ENV2=31
41 ;;
42 * )
43 echo "set_stub_arch_switch: error, TGT_ARCH=${TGT_ARCH} unknown" 1>&2
44 return 1
45 ;;
46 esac
47}
48
49create_stub_hdrs() {
50 if [ "${#}" = "0" ]; then
51 echo "create_stub_hdrs: error, no headers specified" 1>&2
52 return 1
53 fi
54
55 if [ -z "${BUILDENV}" ]; then
56 echo "create_stub_hdrs: error, BUILDENV not set" 1>&2
57 return 1
58 fi
59
60 set_stub_arch_switch || return 1
61
62 echo " o creating stub headers"
63
64 for file in ${@} ; do
65 hdr=`basename ${file}`
66 hdrdir=`dirname ${file}`
67 barrier="__STUB__$( echo ${hdr} | tr [a-z]. [A-Z]_ )__"
68
69 if [ ! -f ${file} ]; then
70 echo "create_stub_hdrs: error, header ${file} does not exist" 1>&2
71 return 1
72 fi
73
74 # If the header we are making a stub for is a stub header we created earlier,
75 # do not continue as something has gone wrong...
76 head -n 1 ${file} | grep "#ifndef ${barrier}" > /dev/null 2>&1 && {
77 echo "create_stub_hdrs: error, ${file} is a stub header" 1>&2
78 return 1
79 }
80
81 # create the dirctory to house the real header (if it does not already exist)
82 if [ ! -d ${hdrdir}/${BUILDENV} ]; then
83 mkdir ${hdrdir}/${BUILDENV}
84 fi
85
86 # move the real header
87 mv ${file} ${hdrdir}/${BUILDENV} || {
88 echo "create_stub_hdrs: error, unable to move ${file} to ${hdrdir}/${BUILDENV}" 1>&2
89 return 1
90 }
91
92 # Generate the header stub
93
94 # include barrier
95 echo "#ifndef ${barrier}" > ${hdrdir}/${hdr}
96 echo "#define ${barrier}" >> ${hdrdir}/${hdr}
97 echo "" >> ${hdrdir}/${hdr}
98
99 if [ -f ${hdrdir}/${ENV1}/${hdr} ]; then
100 echo "#ifdef ${ARCH_SWITCH}" >> ${hdrdir}/${hdr}
101 echo "#include \"${ENV1}/${hdr}\"" >> ${hdrdir}/${hdr}
102 if [ -f ${hdrdir}/${ENV2}/${hdr} ]; then
103 echo "#else" >> ${hdrdir}/${hdr}
104 echo "#include \"${ENV2}/${hdr}\"" >> ${hdrdir}/${hdr}
105 fi
106 elif [ -f ${hdrdir}/${ENV2}/${hdr} ]; then
107 echo "#ifndef ${ARCH_SWITCH}" >> ${hdrdir}/${hdr}
108 echo "#include \"${ENV2}/${hdr}\"" >> ${hdrdir}/${hdr}
109 else
110 echo "create_stub_hdr: error, something really b0rked here" 1>&2
111 return 1
112 fi
113 echo "#endif /* ${ARCH_SWITCH} */" >> ${hdrdir}/${hdr}
114
115 echo "" >> ${hdrdir}/${hdr}
116 echo "#endif /* ${barrier} */" >> ${hdrdir}/${hdr}
117
118 echo " - ${hdrdir}/${hdr}"
119
120 done
121}
122
123create_stub_hdr() {
124 hdr=`basename ${1}`
125 hdrdir=`dirname ${1}`
126 barrier="__STUB__$( echo ${hdr} | tr [a-z]. [A-Z]_ )__"
127
128 set_stub_arch_switch
129
130 # setup include barrier
131 echo "#ifndef ${barrier}" > ${hdrdir}/${hdr}
132 echo "#define ${barrier}" >> ${hdrdir}/${hdr}
133 echo "" >> ${hdrdir}/${hdr}
134
135 if [ -f ${hdrdir}/${ENV1}/${hdr} ]; then
136 echo "#ifdef ${ARCH_SWITCH}" >> ${hdrdir}/${hdr}
137 echo "#include \"${ENV1}/${hdr}\"" >> ${hdrdir}/${hdr}
138 if [ -f ${hdrdir}/${ENV2}/${hdr} ]; then
139 echo "#else" >> ${hdrdir}/${hdr}
140 echo "#include \"${ENV2}/${hdr}\"" >> ${hdrdir}/${hdr}
141 fi
142 elif [ -f ${hdrdir}/${ENV2}/${hdr} ]; then
143 echo "#ifndef ${ARCH_SWITCH}" >> ${hdrdir}/${hdr}
144 echo "#include \"${ENV2}/${hdr}\"" >> ${hdrdir}/${hdr}
145 else
146 echo "create_stub_hdr: error, something really b0rked here" 1>&2
147 return 1
148 fi
149 echo "#endif /* ${ARCH_SWITCH} */" >> ${hdrdir}/${hdr}
150
151 echo "" >> ${hdrdir}/${hdr}
152 echo "#endif /* ${barrier} */" >> ${hdrdir}/${hdr}
153
154 echo " - ${hdrdir}/${hdr}"
155
156}
157
158
159# Export functions
160export -f set_stub_arch_switch
161export -f create_stub_hdrs
Note: See TracBrowser for help on using the repository browser.