genscripts.sh revision 1.8
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 use_sysroot 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# "" no sun3 sparc-sun-sunos4.1.3 12# produces sun3.x sun3.xbn sun3.xn sun3.xr sun3.xu em_sun3.c 13 14srcdir=$1 15libdir=$2 16exec_prefix=$3 17host=$4 18target=$5 19target_alias=$6 20EMULATION_LIBPATH=$7 21NATIVE_LIB_DIRS=$8 22use_sysroot=$9 23shift 9 24EMULATION_NAME=$1 25shift 26# Can't use ${1:-$target_alias} here due to an Ultrix shell bug. 27if [ "x$1" = "x" ] ; then 28 tool_lib=${exec_prefix}/${target_alias}/lib 29else 30 tool_lib=${exec_prefix}/$1/lib 31fi 32 33# Include the emulation-specific parameters: 34. ${srcdir}/emulparams/${EMULATION_NAME}.sh 35 36if test -d ldscripts; then 37 true 38else 39 mkdir ldscripts 40fi 41 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 48case " $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 ;; 57esac 58 59# If the emulparams file sets NATIVE, make sure USE_LIBPATH is set also. 60if test "x$NATIVE" = "xyes" ; then 61 USE_LIBPATH=yes 62fi 63 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=":". 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. 75 76if [ "x${LIB_PATH}" = "x" ] && [ "x${USE_LIBPATH}" = xyes ] ; then 77 if [ x"$use_sysroot" != xyes ] ; then 78 LIB_PATH=${libdir} 79 fi 80 LIB_PATH2="" 81 for lib in ${NATIVE_LIB_DIRS}; do 82 # The "=" is harmless if we aren't using a sysroot, but also needless. 83 if [ "x${use_sysroot}" = "xyes" ] ; then 84 lib="=${lib}" 85 fi 86 addsuffix= 87 case "${LIBPATH_SUFFIX}:${lib}" in 88 :*) ;; 89 *:*${LIBPATH_SUFFIX}) ;; 90 *) addsuffix=yes ;; 91 esac 92 if test -n "$addsuffix"; then 93 case :${LIB_PATH}: in 94 *:${lib}${LIBPATH_SUFFIX}:*) ;; 95 ::) LIB_PATH=${lib}${LIBPATH_SUFFIX} ;; 96 *) LIB_PATH=${LIB_PATH}:${lib}${LIBPATH_SUFFIX} ;; 97 esac 98 case :${LIB_PATH}${LIB_PATH2}: in 99 *:${lib}:*) ;; 100 *) LIB_PATH2=${LIB_PATH2}:${lib} ;; 101 esac 102 else 103 case :${LIB_PATH}: in 104 *:${lib}:*) ;; 105 ::) LIB_PATH=${lib} ;; 106 *) LIB_PATH=${LIB_PATH}:${lib} ;; 107 esac 108 fi 109 done 110 LIB_PATH=${LIB_PATH}${LIB_PATH2} 111fi 112 113LIB_SEARCH_DIRS=`echo ${LIB_PATH} | sed -e 's/:/ /g' -e 's/\([^ ][^ ]*\)/SEARCH_DIR(\\"\1\\");/g'` 114 115# Generate 5 or 6 script files from a master script template in 116# ${srcdir}/scripttempl/${SCRIPT_NAME}.sh. Which one of the 5 or 6 117# script files is actually used depends on command line options given 118# to ld. (SCRIPT_NAME was set in the emulparams_file.) 119# 120# A .x script file is the default script. 121# A .xr script is for linking without relocation (-r flag). 122# A .xu script is like .xr, but *do* create constructors (-Ur flag). 123# A .xn script is for linking with -n flag (mix text and data on same page). 124# A .xbn script is for linking with -N flag (mix text and data on same page). 125# A .xs script is for generating a shared library with the --shared 126# flag; it is only generated if $GENERATE_SHLIB_SCRIPT is set by the 127# emulation parameters. 128# A .xc script is for linking with -z combreloc; it is only generated if 129# $GENERATE_COMBRELOC_SCRIPT is set by the emulation parameters or 130# $SCRIPT_NAME is "elf". 131# A .xsc script is for linking with --shared -z combreloc; it is generated 132# if $GENERATE_COMBRELOC_SCRIPT is set by the emulation parameters or 133# $SCRIPT_NAME is "elf" and $GENERATE_SHLIB_SCRIPT is set by the emulation 134# parameters too. 135 136if [ "x$SCRIPT_NAME" = "xelf" ]; then 137 GENERATE_COMBRELOC_SCRIPT=yes 138fi 139 140SEGMENT_SIZE=${SEGMENT_SIZE-${MAXPAGESIZE-${TARGET_PAGE_SIZE}}} 141 142# Determine DATA_ALIGNMENT for the 5 variants, using 143# values specified in the emulparams/<emulation>.sh file or default. 144 145DATA_ALIGNMENT_="${DATA_ALIGNMENT_-${DATA_ALIGNMENT-ALIGN(${SEGMENT_SIZE})}}" 146DATA_ALIGNMENT_n="${DATA_ALIGNMENT_n-${DATA_ALIGNMENT_}}" 147DATA_ALIGNMENT_N="${DATA_ALIGNMENT_N-${DATA_ALIGNMENT-.}}" 148DATA_ALIGNMENT_r="${DATA_ALIGNMENT_r-${DATA_ALIGNMENT-}}" 149DATA_ALIGNMENT_u="${DATA_ALIGNMENT_u-${DATA_ALIGNMENT_r}}" 150 151LD_FLAG=r 152DATA_ALIGNMENT=${DATA_ALIGNMENT_r} 153DEFAULT_DATA_ALIGNMENT="ALIGN(${SEGMENT_SIZE})" 154( echo "/* Script for ld -r: link without relocation */" 155 . ${srcdir}/emulparams/${EMULATION_NAME}.sh 156 . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc 157) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xr 158 159LD_FLAG=u 160DATA_ALIGNMENT=${DATA_ALIGNMENT_u} 161CONSTRUCTING=" " 162( echo "/* Script for ld -Ur: link w/out relocation, do create constructors */" 163 . ${srcdir}/emulparams/${EMULATION_NAME}.sh 164 . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc 165) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xu 166 167LD_FLAG= 168DATA_ALIGNMENT=${DATA_ALIGNMENT_} 169RELOCATING=" " 170( echo "/* Default linker script, for normal executables */" 171 . ${srcdir}/emulparams/${EMULATION_NAME}.sh 172 . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc 173) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.x 174 175LD_FLAG=n 176DATA_ALIGNMENT=${DATA_ALIGNMENT_n} 177TEXT_START_ADDR=${NONPAGED_TEXT_START_ADDR-${TEXT_START_ADDR}} 178( echo "/* Script for -n: mix text and data on same page */" 179 . ${srcdir}/emulparams/${EMULATION_NAME}.sh 180 . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc 181) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xn 182 183LD_FLAG=N 184DATA_ALIGNMENT=${DATA_ALIGNMENT_N} 185( echo "/* Script for -N: mix text and data on same page; don't align data */" 186 . ${srcdir}/emulparams/${EMULATION_NAME}.sh 187 . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc 188) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xbn 189 190if test -n "$GENERATE_COMBRELOC_SCRIPT"; then 191 DATA_ALIGNMENT=${DATA_ALIGNMENT_c-${DATA_ALIGNMENT_}} 192 LD_FLAG=c 193 COMBRELOC=ldscripts/${EMULATION_NAME}.xc.tmp 194 ( echo "/* Script for -z combreloc: combine and sort reloc sections */" 195 . ${srcdir}/emulparams/${EMULATION_NAME}.sh 196 . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc 197 ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xc 198 rm -f ${COMBRELOC} 199 COMBRELOC= 200fi 201 202if test -n "$GENERATE_SHLIB_SCRIPT"; then 203 LD_FLAG=shared 204 DATA_ALIGNMENT=${DATA_ALIGNMENT_s-${DATA_ALIGNMENT_}} 205 CREATE_SHLIB=" " 206 # Note that TEXT_START_ADDR is set to NONPAGED_TEXT_START_ADDR. 207 ( 208 echo "/* Script for ld --shared: link shared library */" 209 . ${srcdir}/emulparams/${EMULATION_NAME}.sh 210 . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc 211 ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xs 212 if test -n "$GENERATE_COMBRELOC_SCRIPT"; then 213 LD_FLAG=cshared 214 DATA_ALIGNMENT=${DATA_ALIGNMENT_sc-${DATA_ALIGNMENT}} 215 COMBRELOC=ldscripts/${EMULATION_NAME}.xc.tmp 216 ( echo "/* Script for --shared -z combreloc: shared library, combine & sort relocs */" 217 . ${srcdir}/emulparams/${EMULATION_NAME}.sh 218 . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc 219 ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xsc 220 rm -f ${COMBRELOC} 221 COMBRELOC= 222 fi 223fi 224 225LD_FLAG=Z 226DATA_ALIGNMENT=${DATA_ALIGNMENT_} 227RELOCATING=" " 228(. ${srcdir}/scripttempl/${SCRIPT_NAME}.sc) | sed -e '/^ *$/d' > \ 229 ldscripts/${EMULATION_NAME}.xz 230 231case " $EMULATION_LIBPATH " in 232 *" ${EMULATION_NAME} "*) COMPILE_IN=true;; 233esac 234 235# Generate e${EMULATION_NAME}.c. 236. ${srcdir}/emultempl/${TEMPLATE_NAME-generic}.em 237