Add the DragonFly cvs id and perform general cleanups on cvs/rcs/sccs ids. Most
[dragonfly.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 # $DragonFly: src/gnu/usr.bin/binutils/ld/Attic/genscripts.sh,v 1.2 2003/06/17 04:25:44 dillon Exp $
14 #
15 # This is a cut-down version of the GNU script. Instead of jumping through
16 # hoops for all possible combinations of paths, just use the libdir
17 # argument in place of LIB_PATH.
18 #
19 # The host, target and target_alias arguments are not used in this version.
20 #
21
22 srcdir=$1
23 libdir=$2
24 host=$3
25 target=$4
26 target_alias=$5
27 EMULATION_LIBPATH=$6
28 NATIVE_LIB_DIRS=$7
29 EMULATION_NAME=$8
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 LIB_SEARCH_DIRS=`echo ${libdir} | tr ':' ' ' | sed -e 's/\([^ ][^ ]*\)/SEARCH_DIR(\1);/g'`
48
49 # Generate 5 or 6 script files from a master script template in
50 # ${srcdir}/scripttempl/${SCRIPT_NAME}.sh.  Which one of the 5 or 6
51 # script files is actually used depends on command line options given
52 # to ld.  (SCRIPT_NAME was set in the emulparams_file.)
53 #
54 # A .x script file is the default script.
55 # A .xr script is for linking without relocation (-r flag).
56 # A .xu script is like .xr, but *do* create constructors (-Ur flag).
57 # A .xn script is for linking with -n flag (mix text and data on same page).
58 # A .xbn script is for linking with -N flag (mix text and data on same page).
59 # A .xs script is for generating a shared library with the --shared
60 #   flag; it is only generated if $GENERATE_SHLIB_SCRIPT is set by the
61 #   emulation parameters.
62 # A .xc script is for linking with -z combreloc; it is only generated if
63 #   $GENERATE_COMBRELOC_SCRIPT is set by the emulation parameters or
64 #   $SCRIPT_NAME is "elf".
65 # A .xsc script is for linking with --shared -z combreloc; it is generated
66 #   if $GENERATE_COMBRELOC_SCRIPT is set by the emulation parameters or
67 #   $SCRIPT_NAME is "elf" and $GENERATE_SHLIB_SCRIPT is set by the emulation
68 #   parameters too.
69
70 if [ "x$SCRIPT_NAME" = "xelf" ]; then
71   GENERATE_COMBRELOC_SCRIPT=yes
72 fi
73
74 SEGMENT_SIZE=${SEGMENT_SIZE-${TARGET_PAGE_SIZE}}
75
76 # Determine DATA_ALIGNMENT for the 5 variants, using
77 # values specified in the emulparams/<emulation>.sh file or default.
78
79 DATA_ALIGNMENT_="${DATA_ALIGNMENT_-${DATA_ALIGNMENT-ALIGN(${SEGMENT_SIZE})}}"
80 DATA_ALIGNMENT_n="${DATA_ALIGNMENT_n-${DATA_ALIGNMENT_}}"
81 DATA_ALIGNMENT_N="${DATA_ALIGNMENT_N-${DATA_ALIGNMENT-.}}"
82 DATA_ALIGNMENT_r="${DATA_ALIGNMENT_r-${DATA_ALIGNMENT-}}"
83 DATA_ALIGNMENT_u="${DATA_ALIGNMENT_u-${DATA_ALIGNMENT_r}}"
84
85 LD_FLAG=r
86 DATA_ALIGNMENT=${DATA_ALIGNMENT_r}
87 DEFAULT_DATA_ALIGNMENT="ALIGN(${SEGMENT_SIZE})"
88 ( echo "/* Script for ld -r: link without relocation */"
89   . ${srcdir}/emulparams/${EMULATION_NAME}.sh
90   . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
91 ) | sed -e '/^ *$/d;s/[         ]*$//' > ldscripts/${EMULATION_NAME}.xr
92
93 LD_FLAG=u
94 DATA_ALIGNMENT=${DATA_ALIGNMENT_u}
95 CONSTRUCTING=" "
96 ( echo "/* Script for ld -Ur: link w/out relocation, do create constructors */"
97   . ${srcdir}/emulparams/${EMULATION_NAME}.sh
98   . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
99 ) | sed -e '/^ *$/d;s/[         ]*$//' > ldscripts/${EMULATION_NAME}.xu
100
101 LD_FLAG=
102 DATA_ALIGNMENT=${DATA_ALIGNMENT_}
103 RELOCATING=" "
104 ( echo "/* Default linker script, for normal executables */"
105   . ${srcdir}/emulparams/${EMULATION_NAME}.sh
106   . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
107 ) | sed -e '/^ *$/d;s/[         ]*$//' > ldscripts/${EMULATION_NAME}.x
108
109 LD_FLAG=n
110 DATA_ALIGNMENT=${DATA_ALIGNMENT_n}
111 TEXT_START_ADDR=${NONPAGED_TEXT_START_ADDR-${TEXT_START_ADDR}}
112 ( echo "/* Script for -n: mix text and data on same page */"
113   . ${srcdir}/emulparams/${EMULATION_NAME}.sh
114   . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
115 ) | sed -e '/^ *$/d;s/[         ]*$//' > ldscripts/${EMULATION_NAME}.xn
116
117 LD_FLAG=N
118 DATA_ALIGNMENT=${DATA_ALIGNMENT_N}
119 ( echo "/* Script for -N: mix text and data on same page; don't align data */"
120   . ${srcdir}/emulparams/${EMULATION_NAME}.sh
121   . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
122 ) | sed -e '/^ *$/d;s/[         ]*$//' > ldscripts/${EMULATION_NAME}.xbn
123
124 if test -n "$GENERATE_COMBRELOC_SCRIPT"; then
125   DATA_ALIGNMENT=${DATA_ALIGNMENT_c-${DATA_ALIGNMENT_}}
126   LD_FLAG=c
127   COMBRELOC=ldscripts/${EMULATION_NAME}.xc.tmp
128   ( echo "/* Script for -z combreloc: combine and sort reloc sections */"
129     . ${srcdir}/emulparams/${EMULATION_NAME}.sh
130     . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
131   ) | sed -e '/^ *$/d;s/[       ]*$//' > ldscripts/${EMULATION_NAME}.xc
132   rm -f ${COMBRELOC}
133   COMBRELOC=
134 fi
135
136 if test -n "$GENERATE_SHLIB_SCRIPT"; then
137   LD_FLAG=shared
138   DATA_ALIGNMENT=${DATA_ALIGNMENT_s-${DATA_ALIGNMENT_}}
139   CREATE_SHLIB=" "
140   # Note that TEXT_START_ADDR is set to NONPAGED_TEXT_START_ADDR.
141   (
142     echo "/* Script for ld --shared: link shared library */"
143     . ${srcdir}/emulparams/${EMULATION_NAME}.sh
144     . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
145   ) | sed -e '/^ *$/d;s/[       ]*$//' > ldscripts/${EMULATION_NAME}.xs
146   if test -n "$GENERATE_COMBRELOC_SCRIPT"; then
147     LD_FLAG=cshared
148     DATA_ALIGNMENT=${DATA_ALIGNMENT_sc-${DATA_ALIGNMENT}}
149     COMBRELOC=ldscripts/${EMULATION_NAME}.xc.tmp
150     ( echo "/* Script for --shared -z combreloc: shared library, combine & sort relocs */"
151       . ${srcdir}/emulparams/${EMULATION_NAME}.sh
152       . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
153     ) | sed -e '/^ *$/d;s/[     ]*$//' > ldscripts/${EMULATION_NAME}.xsc
154     rm -f ${COMBRELOC}
155     COMBRELOC=
156   fi
157 fi
158
159 for i in $EMULATION_LIBPATH ; do
160   test "$i" = "$EMULATION_NAME" && COMPILE_IN=true
161 done
162 # Generate e${EMULATION_NAME}.c.
163 . ${srcdir}/emultempl/${TEMPLATE_NAME-generic}.em