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