1999-05-28 Martin Dorey <mdorey@madge.com>
[binutils.git] / ld / genscripts.sh
blobeea5401515beba8e8bf3b1a9b0fd928870e41fde
1 #!/bin/sh
2 # genscripts.sh - generate the ld-emulation-target specific files
4 # Usage: genscripts.sh srcdir libdir host target target_alias \
5 # default_emulation native_lib_dirs this_emulation tool_dir
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
12 srcdir=$1
13 libdir=$2
14 host=$3
15 target=$4
16 target_alias=$5
17 DEFAULT_EMULATION=$6
18 NATIVE_LIB_DIRS=$7
19 EMULATION_NAME=$8
20 tool_lib=`echo ${libdir} | sed -e 's|/lib$||'`/${9-$target_alias}/lib
22 # Include the emulation-specific parameters:
23 . ${srcdir}/emulparams/${EMULATION_NAME}.sh
25 if test -d ldscripts; then
26 true
27 else
28 mkdir ldscripts
31 # Set the library search path, for libraries named by -lfoo.
32 # If LIB_PATH is defined (e.g., by Makefile) and non-empty, it is used.
33 # Otherwise, the default is set here.
35 # The format is the usual list of colon-separated directories.
36 # To force a logically empty LIB_PATH, do LIBPATH=":".
38 if [ "x${LIB_PATH}" = "x" ] ; then
39 if [ "x${host}" = "x${target}" ] ; then
40 if [ "x${DEFAULT_EMULATION}" = "x${EMULATION_NAME}" ] ; then
41 # Native.
42 LIB_PATH=/lib:/usr/lib
43 if [ -n "${NATIVE_LIB_DIRS}" ]; then
44 LIB_PATH=${LIB_PATH}:${NATIVE_LIB_DIRS}
46 if [ "${libdir}" != /usr/lib ]; then
47 LIB_PATH=${LIB_PATH}:${libdir}
49 if [ "${libdir}" != /usr/local/lib ] ; then
50 LIB_PATH=${LIB_PATH}:/usr/local/lib
52 else
53 # Native, but not default emulation.
54 LIB_PATH=
56 else
57 # Cross.
58 LIB_PATH=
62 # Always search $(tooldir)/lib, aka /usr/local/TARGET/lib.
63 LIB_PATH=${LIB_PATH}:${tool_lib}
65 LIB_SEARCH_DIRS=`echo ${LIB_PATH} | tr ':' ' ' | sed -e 's/\([^ ][^ ]*\)/SEARCH_DIR(\1);/g'`
67 # Generate 5 or 6 script files from a master script template in
68 # ${srcdir}/scripttempl/${SCRIPT_NAME}.sh. Which one of the 5 or 6
69 # script files is actually used depends on command line options given
70 # to ld. (SCRIPT_NAME was set in the emulparams_file.)
72 # A .x script file is the default script.
73 # A .xr script is for linking without relocation (-r flag).
74 # A .xu script is like .xr, but *do* create constructors (-Ur flag).
75 # A .xn script is for linking with -n flag (mix text and data on same page).
76 # A .xbn script is for linking with -N flag (mix text and data on same page).
77 # A .xs script is for generating a shared library with the --shared
78 # flag; it is only generated if $GENERATE_SHLIB_SCRIPT is set by the
79 # emulation parameters.
81 SEGMENT_SIZE=${SEGMENT_SIZE-${TARGET_PAGE_SIZE}}
83 # Determine DATA_ALIGNMENT for the 5 variants, using
84 # values specified in the emulparams/<emulation>.sh file or default.
86 DATA_ALIGNMENT_="${DATA_ALIGNMENT_-${DATA_ALIGNMENT-ALIGN(${SEGMENT_SIZE})}}"
87 DATA_ALIGNMENT_n="${DATA_ALIGNMENT_n-${DATA_ALIGNMENT_}}"
88 DATA_ALIGNMENT_N="${DATA_ALIGNMENT_N-${DATA_ALIGNMENT-.}}"
89 DATA_ALIGNMENT_r="${DATA_ALIGNMENT_r-${DATA_ALIGNMENT-}}"
90 DATA_ALIGNMENT_u="${DATA_ALIGNMENT_u-${DATA_ALIGNMENT_r}}"
92 LD_FLAG=r
93 DATA_ALIGNMENT=${DATA_ALIGNMENT_r}
94 DEFAULT_DATA_ALIGNMENT="ALIGN(${SEGMENT_SIZE})"
95 (. ${srcdir}/scripttempl/${SCRIPT_NAME}.sc) | sed -e '/^ *$/d' > \
96 ldscripts/${EMULATION_NAME}.xr
98 LD_FLAG=u
99 DATA_ALIGNMENT=${DATA_ALIGNMENT_u}
100 CONSTRUCTING=" "
101 (. ${srcdir}/scripttempl/${SCRIPT_NAME}.sc) | sed -e '/^ *$/d' > \
102 ldscripts/${EMULATION_NAME}.xu
104 LD_FLAG=
105 DATA_ALIGNMENT=${DATA_ALIGNMENT_}
106 RELOCATING=" "
107 (. ${srcdir}/scripttempl/${SCRIPT_NAME}.sc) | sed -e '/^ *$/d' > \
108 ldscripts/${EMULATION_NAME}.x
110 LD_FLAG=n
111 DATA_ALIGNMENT=${DATA_ALIGNMENT_n}
112 TEXT_START_ADDR=${NONPAGED_TEXT_START_ADDR-${TEXT_START_ADDR}}
113 (. ${srcdir}/scripttempl/${SCRIPT_NAME}.sc) | sed -e '/^ *$/d' > \
114 ldscripts/${EMULATION_NAME}.xn
116 LD_FLAG=N
117 DATA_ALIGNMENT=${DATA_ALIGNMENT_N}
118 (. ${srcdir}/scripttempl/${SCRIPT_NAME}.sc) | sed -e '/^ *$/d' > \
119 ldscripts/${EMULATION_NAME}.xbn
121 if test -n "$GENERATE_SHLIB_SCRIPT"; then
122 LD_FLAG=shared
123 DATA_ALIGNMENT=${DATA_ALIGNMENT_s-${DATA_ALIGNMENT_}}
124 CREATE_SHLIB=" "
125 # Note that TEXT_START_ADDR is set to NONPAGED_TEXT_START_ADDR.
126 (. ${srcdir}/scripttempl/${SCRIPT_NAME}.sc) | sed -e '/^ *$/d' > \
127 ldscripts/${EMULATION_NAME}.xs
130 test "$DEFAULT_EMULATION" = "$EMULATION_NAME" && COMPILE_IN=true
132 # Generate e${EMULATION_NAME}.c.
133 . ${srcdir}/emultempl/${TEMPLATE_NAME-generic}.em