Fix from Paul Breed:
[deliverable/binutils-gdb.git] / ld / genscripts.sh
CommitLineData
252b5132
RH
1#!/bin/sh
2# genscripts.sh - generate the ld-emulation-target specific files
3#
d9fc3714
AM
4# Usage: genscripts.sh srcdir libdir exec_prefix \
5# host target target_alias default_emulation \
6# native_lib_dirs this_emulation tool_dir
252b5132
RH
7#
8# Sample usage:
d9fc3714
AM
9# genscripts.sh /djm/ld-devo/devo/ld /usr/local/lib /usr/local \
10# sparc-sun-sunos4.1.3 sparc-sun-sunos4.1.3 sparc-sun-sunos4.1.3 sun4 \
11# "" sun3 sparc-sun-sunos4.1.3
252b5132
RH
12# produces sun3.x sun3.xbn sun3.xn sun3.xr sun3.xu em_sun3.c
13
14srcdir=$1
15libdir=$2
d9fc3714
AM
16exec_prefix=$3
17host=$4
18target=$5
19target_alias=$6
20EMULATION_LIBPATH=$7
21NATIVE_LIB_DIRS=$8
22EMULATION_NAME=$9
23shift 9
24# Can't use ${1:-$target_alias} here due to an Ultrix shell bug.
25if [ "x$1" = "x" ] ; then
26 tool_lib=${exec_prefix}/${target_alias}/lib
27else
28 tool_lib=${exec_prefix}/$1/lib
29fi
252b5132
RH
30
31# Include the emulation-specific parameters:
32. ${srcdir}/emulparams/${EMULATION_NAME}.sh
33
34if test -d ldscripts; then
35 true
36else
37 mkdir ldscripts
38fi
39
40# Set the library search path, for libraries named by -lfoo.
41# If LIB_PATH is defined (e.g., by Makefile) and non-empty, it is used.
42# Otherwise, the default is set here.
43#
44# The format is the usual list of colon-separated directories.
45# To force a logically empty LIB_PATH, do LIBPATH=":".
46
47if [ "x${LIB_PATH}" = "x" ] ; then
48 if [ "x${host}" = "x${target}" ] ; then
3336653a
RH
49 case " $EMULATION_LIBPATH " in
50 *" ${EMULATION_NAME} "*)
51 # Native, and default or emulation requesting LIB_PATH.
eb3d6bb8
AM
52 LIB_PATH=${libdir}
53 for lib in ${NATIVE_LIB_DIRS}; do
54 case :${LIB_PATH}: in
55 *:${lib}:*) ;;
56 *) LIB_PATH=${LIB_PATH}:${lib} ;;
57 esac
58 done
3336653a 59 esac
252b5132
RH
60 fi
61fi
62
63# Always search $(tooldir)/lib, aka /usr/local/TARGET/lib.
eb3d6bb8 64LIB_PATH=${tool_lib}:${LIB_PATH}
252b5132 65
eb3d6bb8 66LIB_SEARCH_DIRS=`echo ${LIB_PATH} | sed -e 's/:/ /g' -e 's/\([^ ][^ ]*\)/SEARCH_DIR(\\"\1\\");/g'`
252b5132
RH
67
68# Generate 5 or 6 script files from a master script template in
69# ${srcdir}/scripttempl/${SCRIPT_NAME}.sh. Which one of the 5 or 6
70# script files is actually used depends on command line options given
71# to ld. (SCRIPT_NAME was set in the emulparams_file.)
72#
73# A .x script file is the default script.
74# A .xr script is for linking without relocation (-r flag).
75# A .xu script is like .xr, but *do* create constructors (-Ur flag).
76# A .xn script is for linking with -n flag (mix text and data on same page).
77# A .xbn script is for linking with -N flag (mix text and data on same page).
78# A .xs script is for generating a shared library with the --shared
79# flag; it is only generated if $GENERATE_SHLIB_SCRIPT is set by the
80# emulation parameters.
db6751f2
JJ
81# A .xc script is for linking with -z combreloc; it is only generated if
82# $GENERATE_COMBRELOC_SCRIPT is set by the emulation parameters or
83# $SCRIPT_NAME is "elf".
84# A .xsc script is for linking with --shared -z combreloc; it is generated
85# if $GENERATE_COMBRELOC_SCRIPT is set by the emulation parameters or
86# $SCRIPT_NAME is "elf" and $GENERATE_SHLIB_SCRIPT is set by the emulation
87# parameters too.
88
89if [ "x$SCRIPT_NAME" = "xelf" ]; then
90 GENERATE_COMBRELOC_SCRIPT=yes
91fi
252b5132
RH
92
93SEGMENT_SIZE=${SEGMENT_SIZE-${TARGET_PAGE_SIZE}}
94
95# Determine DATA_ALIGNMENT for the 5 variants, using
96# values specified in the emulparams/<emulation>.sh file or default.
97
98DATA_ALIGNMENT_="${DATA_ALIGNMENT_-${DATA_ALIGNMENT-ALIGN(${SEGMENT_SIZE})}}"
99DATA_ALIGNMENT_n="${DATA_ALIGNMENT_n-${DATA_ALIGNMENT_}}"
100DATA_ALIGNMENT_N="${DATA_ALIGNMENT_N-${DATA_ALIGNMENT-.}}"
101DATA_ALIGNMENT_r="${DATA_ALIGNMENT_r-${DATA_ALIGNMENT-}}"
102DATA_ALIGNMENT_u="${DATA_ALIGNMENT_u-${DATA_ALIGNMENT_r}}"
103
104LD_FLAG=r
105DATA_ALIGNMENT=${DATA_ALIGNMENT_r}
106DEFAULT_DATA_ALIGNMENT="ALIGN(${SEGMENT_SIZE})"
cedd6b0d
JB
107( echo "/* Script for ld -r: link without relocation */"
108 . ${srcdir}/emulparams/${EMULATION_NAME}.sh
179c732c 109 . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
db6751f2 110) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xr
252b5132
RH
111
112LD_FLAG=u
113DATA_ALIGNMENT=${DATA_ALIGNMENT_u}
114CONSTRUCTING=" "
cedd6b0d
JB
115( echo "/* Script for ld -Ur: link w/out relocation, do create constructors */"
116 . ${srcdir}/emulparams/${EMULATION_NAME}.sh
179c732c 117 . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
db6751f2 118) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xu
252b5132
RH
119
120LD_FLAG=
121DATA_ALIGNMENT=${DATA_ALIGNMENT_}
122RELOCATING=" "
cedd6b0d
JB
123( echo "/* Default linker script, for normal executables */"
124 . ${srcdir}/emulparams/${EMULATION_NAME}.sh
179c732c 125 . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
db6751f2 126) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.x
252b5132
RH
127
128LD_FLAG=n
129DATA_ALIGNMENT=${DATA_ALIGNMENT_n}
130TEXT_START_ADDR=${NONPAGED_TEXT_START_ADDR-${TEXT_START_ADDR}}
cedd6b0d
JB
131( echo "/* Script for -n: mix text and data on same page */"
132 . ${srcdir}/emulparams/${EMULATION_NAME}.sh
179c732c 133 . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
db6751f2 134) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xn
252b5132
RH
135
136LD_FLAG=N
137DATA_ALIGNMENT=${DATA_ALIGNMENT_N}
cedd6b0d
JB
138( echo "/* Script for -N: mix text and data on same page; don't align data */"
139 . ${srcdir}/emulparams/${EMULATION_NAME}.sh
179c732c 140 . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
db6751f2
JJ
141) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xbn
142
143if test -n "$GENERATE_COMBRELOC_SCRIPT"; then
144 DATA_ALIGNMENT=${DATA_ALIGNMENT_c-${DATA_ALIGNMENT_}}
145 LD_FLAG=c
146 COMBRELOC=ldscripts/${EMULATION_NAME}.xc.tmp
e24d7c12 147 ( echo "/* Script for -z combreloc: combine and sort reloc sections */"
cedd6b0d 148 . ${srcdir}/emulparams/${EMULATION_NAME}.sh
db6751f2
JJ
149 . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
150 ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xc
151 rm -f ${COMBRELOC}
152 COMBRELOC=
153fi
252b5132
RH
154
155if test -n "$GENERATE_SHLIB_SCRIPT"; then
156 LD_FLAG=shared
157 DATA_ALIGNMENT=${DATA_ALIGNMENT_s-${DATA_ALIGNMENT_}}
158 CREATE_SHLIB=" "
159 # Note that TEXT_START_ADDR is set to NONPAGED_TEXT_START_ADDR.
cedd6b0d
JB
160 (
161 echo "/* Script for ld --shared: link shared library */"
162 . ${srcdir}/emulparams/${EMULATION_NAME}.sh
179c732c 163 . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
db6751f2
JJ
164 ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xs
165 if test -n "$GENERATE_COMBRELOC_SCRIPT"; then
166 LD_FLAG=cshared
167 DATA_ALIGNMENT=${DATA_ALIGNMENT_sc-${DATA_ALIGNMENT}}
168 COMBRELOC=ldscripts/${EMULATION_NAME}.xc.tmp
cedd6b0d
JB
169 ( echo "/* Script for --shared -z combreloc: shared library, combine & sort relocs */"
170 . ${srcdir}/emulparams/${EMULATION_NAME}.sh
db6751f2
JJ
171 . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
172 ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xsc
173 rm -f ${COMBRELOC}
174 COMBRELOC=
175 fi
252b5132
RH
176fi
177
eb3d6bb8
AM
178case " $EMULATION_LIBPATH " in
179 *" ${EMULATION_NAME} "*) COMPILE_IN=true;;
180esac
252b5132
RH
181
182# Generate e${EMULATION_NAME}.c.
183. ${srcdir}/emultempl/${TEMPLATE_NAME-generic}.em
This page took 0.15297 seconds and 4 git commands to generate.