Commit | Line | Data |
---|---|---|
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 \ | |
9c8ebd6a | 6 | # native_lib_dirs use_sysroot 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 \ | |
9c8ebd6a | 11 | # "" no sun3 sparc-sun-sunos4.1.3 |
252b5132 RH |
12 | # produces sun3.x sun3.xbn sun3.xn sun3.xr sun3.xu em_sun3.c |
13 | ||
14 | srcdir=$1 | |
15 | libdir=$2 | |
d9fc3714 AM |
16 | exec_prefix=$3 |
17 | host=$4 | |
18 | target=$5 | |
19 | target_alias=$6 | |
20 | EMULATION_LIBPATH=$7 | |
21 | NATIVE_LIB_DIRS=$8 | |
9c8ebd6a | 22 | use_sysroot=$9 |
d9fc3714 | 23 | shift 9 |
9c8ebd6a DJ |
24 | EMULATION_NAME=$1 |
25 | shift | |
d9fc3714 AM |
26 | # Can't use ${1:-$target_alias} here due to an Ultrix shell bug. |
27 | if [ "x$1" = "x" ] ; then | |
28 | tool_lib=${exec_prefix}/${target_alias}/lib | |
29 | else | |
30 | tool_lib=${exec_prefix}/$1/lib | |
31 | fi | |
252b5132 RH |
32 | |
33 | # Include the emulation-specific parameters: | |
34 | . ${srcdir}/emulparams/${EMULATION_NAME}.sh | |
35 | ||
36 | if test -d ldscripts; then | |
37 | true | |
38 | else | |
39 | mkdir ldscripts | |
40 | fi | |
41 | ||
9c8ebd6a DJ |
42 | # Set some flags for the emultempl scripts. USE_LIBPATH will |
43 | # be set for any libpath-using emulation; NATIVE will be set for a | |
44 | # libpath-using emulation where ${host} = ${target}. NATIVE | |
45 | # may already have been set by the emulparams file, but that's OK | |
46 | # (it'll just get set to "yes" twice). | |
47 | ||
48 | case " $EMULATION_LIBPATH " in | |
49 | *" ${EMULATION_NAME} "*) | |
50 | if [ "x${host}" = "x${target}" ] ; then | |
51 | NATIVE=yes | |
52 | USE_LIBPATH=yes | |
53 | elif [ "x${use_sysroot}" = "xyes" ] ; then | |
54 | USE_LIBPATH=yes | |
55 | fi | |
56 | ;; | |
57 | esac | |
58 | ||
59 | # If the emulparams file sets NATIVE, make sure USE_LIBPATH is set also. | |
60 | if test "x$NATIVE" = "xyes" ; then | |
61 | USE_LIBPATH=yes | |
62 | fi | |
63 | ||
252b5132 RH |
64 | # Set the library search path, for libraries named by -lfoo. |
65 | # If LIB_PATH is defined (e.g., by Makefile) and non-empty, it is used. | |
66 | # Otherwise, the default is set here. | |
67 | # | |
68 | # The format is the usual list of colon-separated directories. | |
69 | # To force a logically empty LIB_PATH, do LIBPATH=":". | |
9c8ebd6a DJ |
70 | # |
71 | # If we are using a sysroot, prefix library paths with "=" to indicate this. | |
72 | # | |
73 | # If the emulparams file set LIBPATH_SUFFIX, prepend an extra copy of | |
74 | # the library path with the suffix applied. | |
252b5132 | 75 | |
9c8ebd6a DJ |
76 | if [ "x${LIB_PATH}" = "x" ] && [ "x${USE_LIBPATH}" = xyes ] ; then |
77 | if [ x"$use_sysroot" != xyes ] ; then | |
78 | LIB_PATH=${libdir} | |
79 | fi | |
80 | for lib in ${NATIVE_LIB_DIRS}; do | |
81 | # The "=" is harmless if we aren't using a sysroot, but also needless. | |
82 | if [ "x${use_sysroot}" = "xyes" ] ; then | |
83 | lib="=${lib}" | |
84 | fi | |
85 | case :${LIB_PATH}: in | |
86 | *:${lib}:*) ;; | |
87 | ::) LIB_PATH=${lib} ;; | |
88 | *) LIB_PATH=${LIB_PATH}:${lib} ;; | |
3336653a | 89 | esac |
9c8ebd6a DJ |
90 | done |
91 | if test -n "$LIBPATH_SUFFIX" ; then | |
92 | LIB_PATH=`echo ${LIB_PATH}: | sed -e s,:,${LIBPATH_SUFFIX}:,g`$LIB_PATH | |
252b5132 RH |
93 | fi |
94 | fi | |
95 | ||
9c8ebd6a DJ |
96 | |
97 | # Always search $(tooldir)/lib, aka /usr/local/TARGET/lib, except for | |
98 | # sysrooted configurations. | |
99 | if [ "x${use_sysroot}" != "xyes" ] ; then | |
100 | LIB_PATH=${tool_lib}:${LIB_PATH} | |
101 | fi | |
252b5132 | 102 | |
eb3d6bb8 | 103 | LIB_SEARCH_DIRS=`echo ${LIB_PATH} | sed -e 's/:/ /g' -e 's/\([^ ][^ ]*\)/SEARCH_DIR(\\"\1\\");/g'` |
252b5132 RH |
104 | |
105 | # Generate 5 or 6 script files from a master script template in | |
106 | # ${srcdir}/scripttempl/${SCRIPT_NAME}.sh. Which one of the 5 or 6 | |
107 | # script files is actually used depends on command line options given | |
108 | # to ld. (SCRIPT_NAME was set in the emulparams_file.) | |
109 | # | |
110 | # A .x script file is the default script. | |
111 | # A .xr script is for linking without relocation (-r flag). | |
112 | # A .xu script is like .xr, but *do* create constructors (-Ur flag). | |
113 | # A .xn script is for linking with -n flag (mix text and data on same page). | |
114 | # A .xbn script is for linking with -N flag (mix text and data on same page). | |
115 | # A .xs script is for generating a shared library with the --shared | |
116 | # flag; it is only generated if $GENERATE_SHLIB_SCRIPT is set by the | |
117 | # emulation parameters. | |
db6751f2 JJ |
118 | # A .xc script is for linking with -z combreloc; it is only generated if |
119 | # $GENERATE_COMBRELOC_SCRIPT is set by the emulation parameters or | |
120 | # $SCRIPT_NAME is "elf". | |
121 | # A .xsc script is for linking with --shared -z combreloc; it is generated | |
122 | # if $GENERATE_COMBRELOC_SCRIPT is set by the emulation parameters or | |
123 | # $SCRIPT_NAME is "elf" and $GENERATE_SHLIB_SCRIPT is set by the emulation | |
124 | # parameters too. | |
125 | ||
126 | if [ "x$SCRIPT_NAME" = "xelf" ]; then | |
127 | GENERATE_COMBRELOC_SCRIPT=yes | |
128 | fi | |
252b5132 | 129 | |
1ddd7b13 | 130 | SEGMENT_SIZE=${SEGMENT_SIZE-${MAXPAGESIZE-${TARGET_PAGE_SIZE}}} |
252b5132 RH |
131 | |
132 | # Determine DATA_ALIGNMENT for the 5 variants, using | |
133 | # values specified in the emulparams/<emulation>.sh file or default. | |
134 | ||
135 | DATA_ALIGNMENT_="${DATA_ALIGNMENT_-${DATA_ALIGNMENT-ALIGN(${SEGMENT_SIZE})}}" | |
136 | DATA_ALIGNMENT_n="${DATA_ALIGNMENT_n-${DATA_ALIGNMENT_}}" | |
137 | DATA_ALIGNMENT_N="${DATA_ALIGNMENT_N-${DATA_ALIGNMENT-.}}" | |
138 | DATA_ALIGNMENT_r="${DATA_ALIGNMENT_r-${DATA_ALIGNMENT-}}" | |
139 | DATA_ALIGNMENT_u="${DATA_ALIGNMENT_u-${DATA_ALIGNMENT_r}}" | |
140 | ||
141 | LD_FLAG=r | |
142 | DATA_ALIGNMENT=${DATA_ALIGNMENT_r} | |
143 | DEFAULT_DATA_ALIGNMENT="ALIGN(${SEGMENT_SIZE})" | |
cedd6b0d JB |
144 | ( echo "/* Script for ld -r: link without relocation */" |
145 | . ${srcdir}/emulparams/${EMULATION_NAME}.sh | |
179c732c | 146 | . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc |
db6751f2 | 147 | ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xr |
252b5132 RH |
148 | |
149 | LD_FLAG=u | |
150 | DATA_ALIGNMENT=${DATA_ALIGNMENT_u} | |
151 | CONSTRUCTING=" " | |
cedd6b0d JB |
152 | ( echo "/* Script for ld -Ur: link w/out relocation, do create constructors */" |
153 | . ${srcdir}/emulparams/${EMULATION_NAME}.sh | |
179c732c | 154 | . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc |
db6751f2 | 155 | ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xu |
252b5132 RH |
156 | |
157 | LD_FLAG= | |
158 | DATA_ALIGNMENT=${DATA_ALIGNMENT_} | |
159 | RELOCATING=" " | |
cedd6b0d JB |
160 | ( echo "/* Default linker script, for normal executables */" |
161 | . ${srcdir}/emulparams/${EMULATION_NAME}.sh | |
179c732c | 162 | . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc |
db6751f2 | 163 | ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.x |
252b5132 RH |
164 | |
165 | LD_FLAG=n | |
166 | DATA_ALIGNMENT=${DATA_ALIGNMENT_n} | |
167 | TEXT_START_ADDR=${NONPAGED_TEXT_START_ADDR-${TEXT_START_ADDR}} | |
cedd6b0d JB |
168 | ( echo "/* Script for -n: mix text and data on same page */" |
169 | . ${srcdir}/emulparams/${EMULATION_NAME}.sh | |
179c732c | 170 | . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc |
db6751f2 | 171 | ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xn |
252b5132 RH |
172 | |
173 | LD_FLAG=N | |
174 | DATA_ALIGNMENT=${DATA_ALIGNMENT_N} | |
cedd6b0d JB |
175 | ( echo "/* Script for -N: mix text and data on same page; don't align data */" |
176 | . ${srcdir}/emulparams/${EMULATION_NAME}.sh | |
179c732c | 177 | . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc |
db6751f2 JJ |
178 | ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xbn |
179 | ||
180 | if test -n "$GENERATE_COMBRELOC_SCRIPT"; then | |
181 | DATA_ALIGNMENT=${DATA_ALIGNMENT_c-${DATA_ALIGNMENT_}} | |
182 | LD_FLAG=c | |
183 | COMBRELOC=ldscripts/${EMULATION_NAME}.xc.tmp | |
e24d7c12 | 184 | ( echo "/* Script for -z combreloc: combine and sort reloc sections */" |
cedd6b0d | 185 | . ${srcdir}/emulparams/${EMULATION_NAME}.sh |
db6751f2 JJ |
186 | . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc |
187 | ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xc | |
188 | rm -f ${COMBRELOC} | |
189 | COMBRELOC= | |
190 | fi | |
252b5132 RH |
191 | |
192 | if test -n "$GENERATE_SHLIB_SCRIPT"; then | |
193 | LD_FLAG=shared | |
194 | DATA_ALIGNMENT=${DATA_ALIGNMENT_s-${DATA_ALIGNMENT_}} | |
195 | CREATE_SHLIB=" " | |
196 | # Note that TEXT_START_ADDR is set to NONPAGED_TEXT_START_ADDR. | |
cedd6b0d JB |
197 | ( |
198 | echo "/* Script for ld --shared: link shared library */" | |
199 | . ${srcdir}/emulparams/${EMULATION_NAME}.sh | |
179c732c | 200 | . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc |
db6751f2 JJ |
201 | ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xs |
202 | if test -n "$GENERATE_COMBRELOC_SCRIPT"; then | |
203 | LD_FLAG=cshared | |
204 | DATA_ALIGNMENT=${DATA_ALIGNMENT_sc-${DATA_ALIGNMENT}} | |
205 | COMBRELOC=ldscripts/${EMULATION_NAME}.xc.tmp | |
cedd6b0d JB |
206 | ( echo "/* Script for --shared -z combreloc: shared library, combine & sort relocs */" |
207 | . ${srcdir}/emulparams/${EMULATION_NAME}.sh | |
db6751f2 JJ |
208 | . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc |
209 | ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xsc | |
210 | rm -f ${COMBRELOC} | |
211 | COMBRELOC= | |
212 | fi | |
252b5132 RH |
213 | fi |
214 | ||
eb3d6bb8 AM |
215 | case " $EMULATION_LIBPATH " in |
216 | *" ${EMULATION_NAME} "*) COMPILE_IN=true;; | |
217 | esac | |
252b5132 RH |
218 | |
219 | # Generate e${EMULATION_NAME}.c. | |
220 | . ${srcdir}/emultempl/${TEMPLATE_NAME-generic}.em |