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