oops - use correct version of automake to regenerate Makefile.in
[deliverable/binutils-gdb.git] / ld / genscripts.sh
CommitLineData
252b5132
RH
1#!/bin/sh
2# genscripts.sh - generate the ld-emulation-target specific files
3#
8fbdf3ab
AM
4# Usage: genscripts_extra.sh \
5# srcdir \
6# libdir \
7# exec_prefix \
8# host \
9# target \
10# target_alias \
11# default_emulation \
12# native_lib_dirs \
13# use_sysroot \
14# this_emulation \
15# optional:
16# tool_dir \
17# customizer_script
252b5132
RH
18#
19# Sample usage:
8fbdf3ab
AM
20#
21# genscripts_extra.sh \
22# /sources/ld \
23# /usr/local/lib \
24# /usr/local \
25# sparc-sun-sunos4.1.3 \
26# sparc-sun-sunos4.1.3 \
27# sparc-sun-sunos4.1.3 \
28# sun4 \
29# "" \
30# no \
31# sun3 \
32# sparc-sun-sunos4.1.3 \
33# sparc.sh
34#
35# produces the linker scripts:
36#
37# sun3.x [default linker script]
38# sun3.xbn [used when the linker is invoked with "-N"]
39# sun3.xn [used when the linker is invoked with "-n"]
40# sun3.xr [used when the linker is invoked with "-r"]
41# sun3.xu [used when the linker is invoked with "-Ur"]
42# and maybe:
43# sun3.xc [used when the linker is invoked with "-z combreloc"]
44# sun3.xsc [used when the linker is invoked with "--shared"]
45# sun3.xdc [used when the linker is invoked with "-pie"]
46#
47# It also produced the C source file:
48#
49# em_sun3.c
50#
51# which is then compiled into the linker.
52#
53# The linker scripts are created by running the shell script
54# /sources/ld/emulparams/sparc.sh to set the value of ${SCRIPT_NAME}
55# (and any other variables it wants to). ${SCRIPT_NAME} is then
56# invoked with a variable called ${LD_FLAG} to tell it which version
57# of the linker script to create.
58
252b5132
RH
59
60srcdir=$1
61libdir=$2
d9fc3714
AM
62exec_prefix=$3
63host=$4
64target=$5
65target_alias=$6
66EMULATION_LIBPATH=$7
67NATIVE_LIB_DIRS=$8
9c8ebd6a 68use_sysroot=$9
d9fc3714 69shift 9
9c8ebd6a 70EMULATION_NAME=$1
8fbdf3ab
AM
71TOOL_LIB=$2
72CUSTOMIZER_SCRIPT=$3
73
74# Can't use ${TOOL_LIB:-$target_alias} here due to an Ultrix shell bug.
75if [ "x${TOOL_LIB}" = "x" ] ; then
d9fc3714
AM
76 tool_lib=${exec_prefix}/${target_alias}/lib
77else
8fbdf3ab
AM
78 tool_lib=${exec_prefix}/${TOOL_LIB}/lib
79fi
80
81if [ "x${CUSTOMIZER_SCRIPT}" = "x" ] ; then
82 CUSTOMIZER_SCRIPT=${EMULATION_NAME}
d9fc3714 83fi
8fbdf3ab 84CUSTOMIZER_SCRIPT="${srcdir}/emulparams/${CUSTOMIZER_SCRIPT}.sh"
252b5132
RH
85
86# Include the emulation-specific parameters:
8fbdf3ab 87. ${CUSTOMIZER_SCRIPT} ${EMULATION_NAME}
252b5132
RH
88
89if test -d ldscripts; then
90 true
91else
92 mkdir ldscripts
93fi
94
9c8ebd6a
DJ
95# Set some flags for the emultempl scripts. USE_LIBPATH will
96# be set for any libpath-using emulation; NATIVE will be set for a
97# libpath-using emulation where ${host} = ${target}. NATIVE
98# may already have been set by the emulparams file, but that's OK
99# (it'll just get set to "yes" twice).
100
101case " $EMULATION_LIBPATH " in
102 *" ${EMULATION_NAME} "*)
103 if [ "x${host}" = "x${target}" ] ; then
104 NATIVE=yes
105 USE_LIBPATH=yes
106 elif [ "x${use_sysroot}" = "xyes" ] ; then
107 USE_LIBPATH=yes
108 fi
109 ;;
110esac
111
112# If the emulparams file sets NATIVE, make sure USE_LIBPATH is set also.
113if test "x$NATIVE" = "xyes" ; then
114 USE_LIBPATH=yes
115fi
116
252b5132
RH
117# Set the library search path, for libraries named by -lfoo.
118# If LIB_PATH is defined (e.g., by Makefile) and non-empty, it is used.
119# Otherwise, the default is set here.
120#
121# The format is the usual list of colon-separated directories.
122# To force a logically empty LIB_PATH, do LIBPATH=":".
9c8ebd6a
DJ
123#
124# If we are using a sysroot, prefix library paths with "=" to indicate this.
125#
126# If the emulparams file set LIBPATH_SUFFIX, prepend an extra copy of
127# the library path with the suffix applied.
252b5132 128
9c8ebd6a 129if [ "x${LIB_PATH}" = "x" ] && [ "x${USE_LIBPATH}" = xyes ] ; then
f22f5fcd 130 LIB_PATH2=
9c8ebd6a 131 if [ x"$use_sysroot" != xyes ] ; then
f22f5fcd 132 LIB_PATH2=${libdir}
9c8ebd6a
DJ
133 fi
134 for lib in ${NATIVE_LIB_DIRS}; do
135 # The "=" is harmless if we aren't using a sysroot, but also needless.
136 if [ "x${use_sysroot}" = "xyes" ] ; then
137 lib="=${lib}"
138 fi
d460ab58
JJ
139 addsuffix=
140 case "${LIBPATH_SUFFIX}:${lib}" in
141 :*) ;;
142 *:*${LIBPATH_SUFFIX}) ;;
143 *) addsuffix=yes ;;
3336653a 144 esac
d460ab58
JJ
145 if test -n "$addsuffix"; then
146 case :${LIB_PATH}: in
147 *:${lib}${LIBPATH_SUFFIX}:*) ;;
148 ::) LIB_PATH=${lib}${LIBPATH_SUFFIX} ;;
149 *) LIB_PATH=${LIB_PATH}:${lib}${LIBPATH_SUFFIX} ;;
150 esac
f22f5fcd 151 case :${LIB_PATH}:${LIB_PATH2}: in
d460ab58 152 *:${lib}:*) ;;
f22f5fcd
AM
153 *::) LIB_PATH2=${lib} ;;
154 *) LIB_PATH2=${LIB_PATH2}:${lib} ;;
d460ab58
JJ
155 esac
156 else
f22f5fcd
AM
157 case :${LIB_PATH2}: in
158 *:${lib}:*) ;;
159 ::) LIB_PATH2=${lib} ;;
160 *) LIB_PATH2=${LIB_PATH2}:${lib} ;;
d460ab58
JJ
161 esac
162 fi
9c8ebd6a 163 done
f22f5fcd
AM
164 case :${LIB_PATH}:${LIB_PATH2}: in
165 *:: | ::*) LIB_PATH=${LIB_PATH}${LIB_PATH2} ;;
166 *) LIB_PATH=${LIB_PATH}:${LIB_PATH2} ;;
167 esac
252b5132
RH
168fi
169
9c8ebd6a
DJ
170
171# Always search $(tooldir)/lib, aka /usr/local/TARGET/lib, except for
f22f5fcd 172# sysrooted configurations and when LIBPATH=":".
9c8ebd6a 173if [ "x${use_sysroot}" != "xyes" ] ; then
f22f5fcd
AM
174 case :${LIB_PATH}: in
175 ::: | *:${tool_lib}:*) ;;
176 ::) LIB_PATH=${tool_lib} ;;
177 *) LIB_PATH=${tool_lib}:${LIB_PATH} ;;
178 esac
9c8ebd6a 179fi
252b5132 180
eb3d6bb8 181LIB_SEARCH_DIRS=`echo ${LIB_PATH} | sed -e 's/:/ /g' -e 's/\([^ ][^ ]*\)/SEARCH_DIR(\\"\1\\");/g'`
252b5132 182
cdaeef2e
L
183# We need it for testsuite.
184case " $EMULATION_LIBPATH " in
185 *" ${EMULATION_NAME} "*)
186 test -d tmpdir || mkdir tmpdir
f22f5fcd 187 test -f tmpdir/libpath.exp || \
cdaeef2e
L
188 echo "set libpath \"${LIB_PATH}\"" | sed -e 's/:/ /g' > tmpdir/libpath.exp
189 ;;
190esac
191
252b5132
RH
192# Generate 5 or 6 script files from a master script template in
193# ${srcdir}/scripttempl/${SCRIPT_NAME}.sh. Which one of the 5 or 6
194# script files is actually used depends on command line options given
195# to ld. (SCRIPT_NAME was set in the emulparams_file.)
196#
197# A .x script file is the default script.
198# A .xr script is for linking without relocation (-r flag).
199# A .xu script is like .xr, but *do* create constructors (-Ur flag).
200# A .xn script is for linking with -n flag (mix text and data on same page).
201# A .xbn script is for linking with -N flag (mix text and data on same page).
202# A .xs script is for generating a shared library with the --shared
203# flag; it is only generated if $GENERATE_SHLIB_SCRIPT is set by the
204# emulation parameters.
db6751f2
JJ
205# A .xc script is for linking with -z combreloc; it is only generated if
206# $GENERATE_COMBRELOC_SCRIPT is set by the emulation parameters or
207# $SCRIPT_NAME is "elf".
208# A .xsc script is for linking with --shared -z combreloc; it is generated
209# if $GENERATE_COMBRELOC_SCRIPT is set by the emulation parameters or
210# $SCRIPT_NAME is "elf" and $GENERATE_SHLIB_SCRIPT is set by the emulation
211# parameters too.
212
213if [ "x$SCRIPT_NAME" = "xelf" ]; then
214 GENERATE_COMBRELOC_SCRIPT=yes
215fi
252b5132 216
1ddd7b13 217SEGMENT_SIZE=${SEGMENT_SIZE-${MAXPAGESIZE-${TARGET_PAGE_SIZE}}}
252b5132
RH
218
219# Determine DATA_ALIGNMENT for the 5 variants, using
8fbdf3ab 220# values specified in the emulparams/<script_to_run>.sh file or default.
252b5132
RH
221
222DATA_ALIGNMENT_="${DATA_ALIGNMENT_-${DATA_ALIGNMENT-ALIGN(${SEGMENT_SIZE})}}"
223DATA_ALIGNMENT_n="${DATA_ALIGNMENT_n-${DATA_ALIGNMENT_}}"
224DATA_ALIGNMENT_N="${DATA_ALIGNMENT_N-${DATA_ALIGNMENT-.}}"
225DATA_ALIGNMENT_r="${DATA_ALIGNMENT_r-${DATA_ALIGNMENT-}}"
226DATA_ALIGNMENT_u="${DATA_ALIGNMENT_u-${DATA_ALIGNMENT_r}}"
227
228LD_FLAG=r
229DATA_ALIGNMENT=${DATA_ALIGNMENT_r}
230DEFAULT_DATA_ALIGNMENT="ALIGN(${SEGMENT_SIZE})"
cedd6b0d 231( echo "/* Script for ld -r: link without relocation */"
8fbdf3ab 232 . ${CUSTOMIZER_SCRIPT} ${EMULATION_NAME}
179c732c 233 . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
db6751f2 234) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xr
252b5132
RH
235
236LD_FLAG=u
237DATA_ALIGNMENT=${DATA_ALIGNMENT_u}
238CONSTRUCTING=" "
cedd6b0d 239( echo "/* Script for ld -Ur: link w/out relocation, do create constructors */"
8fbdf3ab 240 . ${CUSTOMIZER_SCRIPT} ${EMULATION_NAME}
179c732c 241 . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
db6751f2 242) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xu
252b5132
RH
243
244LD_FLAG=
245DATA_ALIGNMENT=${DATA_ALIGNMENT_}
246RELOCATING=" "
cedd6b0d 247( echo "/* Default linker script, for normal executables */"
8fbdf3ab 248 . ${CUSTOMIZER_SCRIPT} ${EMULATION_NAME}
179c732c 249 . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
db6751f2 250) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.x
252b5132
RH
251
252LD_FLAG=n
253DATA_ALIGNMENT=${DATA_ALIGNMENT_n}
254TEXT_START_ADDR=${NONPAGED_TEXT_START_ADDR-${TEXT_START_ADDR}}
cedd6b0d 255( echo "/* Script for -n: mix text and data on same page */"
8fbdf3ab 256 . ${CUSTOMIZER_SCRIPT} ${EMULATION_NAME}
179c732c 257 . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
db6751f2 258) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xn
252b5132
RH
259
260LD_FLAG=N
261DATA_ALIGNMENT=${DATA_ALIGNMENT_N}
cedd6b0d 262( echo "/* Script for -N: mix text and data on same page; don't align data */"
8fbdf3ab 263 . ${CUSTOMIZER_SCRIPT} ${EMULATION_NAME}
179c732c 264 . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
db6751f2
JJ
265) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xbn
266
267if test -n "$GENERATE_COMBRELOC_SCRIPT"; then
268 DATA_ALIGNMENT=${DATA_ALIGNMENT_c-${DATA_ALIGNMENT_}}
269 LD_FLAG=c
270 COMBRELOC=ldscripts/${EMULATION_NAME}.xc.tmp
e24d7c12 271 ( echo "/* Script for -z combreloc: combine and sort reloc sections */"
8fbdf3ab 272 . ${CUSTOMIZER_SCRIPT} ${EMULATION_NAME}
db6751f2
JJ
273 . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
274 ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xc
275 rm -f ${COMBRELOC}
276 COMBRELOC=
277fi
252b5132
RH
278
279if test -n "$GENERATE_SHLIB_SCRIPT"; then
280 LD_FLAG=shared
281 DATA_ALIGNMENT=${DATA_ALIGNMENT_s-${DATA_ALIGNMENT_}}
282 CREATE_SHLIB=" "
283 # Note that TEXT_START_ADDR is set to NONPAGED_TEXT_START_ADDR.
cedd6b0d
JB
284 (
285 echo "/* Script for ld --shared: link shared library */"
8fbdf3ab 286 . ${CUSTOMIZER_SCRIPT} ${EMULATION_NAME}
179c732c 287 . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
db6751f2
JJ
288 ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xs
289 if test -n "$GENERATE_COMBRELOC_SCRIPT"; then
290 LD_FLAG=cshared
291 DATA_ALIGNMENT=${DATA_ALIGNMENT_sc-${DATA_ALIGNMENT}}
292 COMBRELOC=ldscripts/${EMULATION_NAME}.xc.tmp
cedd6b0d 293 ( echo "/* Script for --shared -z combreloc: shared library, combine & sort relocs */"
8fbdf3ab 294 . ${CUSTOMIZER_SCRIPT} ${EMULATION_NAME}
db6751f2
JJ
295 . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
296 ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xsc
297 rm -f ${COMBRELOC}
298 COMBRELOC=
299 fi
36af4a4e
JJ
300 unset CREATE_SHLIB
301fi
302
303if test -n "$GENERATE_PIE_SCRIPT"; then
304 LD_FLAG=pie
305 DATA_ALIGNMENT=${DATA_ALIGNMENT_s-${DATA_ALIGNMENT_}}
306 CREATE_PIE=" "
307 # Note that TEXT_START_ADDR is set to NONPAGED_TEXT_START_ADDR.
308 (
309 echo "/* Script for ld -pie: link position independent executable */"
8fbdf3ab 310 . ${CUSTOMIZER_SCRIPT} ${EMULATION_NAME}
36af4a4e
JJ
311 . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
312 ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xd
313 if test -n "$GENERATE_COMBRELOC_SCRIPT"; then
314 LD_FLAG=cpie
315 DATA_ALIGNMENT=${DATA_ALIGNMENT_sc-${DATA_ALIGNMENT}}
316 COMBRELOC=ldscripts/${EMULATION_NAME}.xc.tmp
317 ( echo "/* Script for -pie -z combreloc: position independent executable, combine & sort relocs */"
8fbdf3ab 318 . ${CUSTOMIZER_SCRIPT} ${EMULATION_NAME}
36af4a4e
JJ
319 . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
320 ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xdc
321 rm -f ${COMBRELOC}
322 COMBRELOC=
323 fi
324 unset CREATE_PIE
252b5132
RH
325fi
326
eb3d6bb8
AM
327case " $EMULATION_LIBPATH " in
328 *" ${EMULATION_NAME} "*) COMPILE_IN=true;;
329esac
252b5132
RH
330
331# Generate e${EMULATION_NAME}.c.
332. ${srcdir}/emultempl/${TEMPLATE_NAME-generic}.em
This page took 0.273491 seconds and 4 git commands to generate.