genscripts.sh revision 1.6
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 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# "" 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 22EMULATION_NAME=$9 23shift 9 24# Can't use ${1:-$target_alias} here due to an Ultrix shell bug. 25if [ "x$1" = "x" ] ; then 26 tool_lib=${exec_prefix}/${target_alias}/lib 27else 28 tool_lib=${exec_prefix}/$1/lib 29fi 30 31# Include the emulation-specific parameters: 32. ${srcdir}/emulparams/${EMULATION_NAME}.sh 33 34if test -d ldscripts; then 35 true 36else 37 mkdir ldscripts 38fi 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 47if [ "x${LIB_PATH}" = "x" ] ; then 48 # Cross, or native non-default emulation not requesting LIB_PATH. 49 LIB_PATH= 50 51 if [ "x${host}" = "x${target}" ] ; then 52 case " $EMULATION_LIBPATH " in 53 *" ${EMULATION_NAME} "*) 54 # Native, and default or emulation requesting LIB_PATH. 55 LIB_PATH=/usr/lib 56 if [ -n "${NATIVE_LIB_DIRS}" ]; then 57 LIB_PATH=${LIB_PATH}:${NATIVE_LIB_DIRS} 58 fi 59 if [ "${libdir}" != /usr/lib ]; then 60 LIB_PATH=${LIB_PATH}:${libdir} 61 fi 62 esac 63 fi 64fi 65 66# Always search $(tooldir)/lib, aka /usr/local/TARGET/lib. 67LIB_PATH=${LIB_PATH}:${tool_lib} 68 69LIB_SEARCH_DIRS=`echo ${LIB_PATH} | tr ':' ' ' | sed -e 's/\([^ ][^ ]*\)/SEARCH_DIR(\1);/g'` 70 71# Generate 5 or 6 script files from a master script template in 72# ${srcdir}/scripttempl/${SCRIPT_NAME}.sh. Which one of the 5 or 6 73# script files is actually used depends on command line options given 74# to ld. (SCRIPT_NAME was set in the emulparams_file.) 75# 76# A .x script file is the default script. 77# A .xr script is for linking without relocation (-r flag). 78# A .xu script is like .xr, but *do* create constructors (-Ur flag). 79# A .xn script is for linking with -n flag (mix text and data on same page). 80# A .xbn script is for linking with -N flag (mix text and data on same page). 81# A .xs script is for generating a shared library with the --shared 82# flag; it is only generated if $GENERATE_SHLIB_SCRIPT is set by the 83# emulation parameters. 84 85SEGMENT_SIZE=${SEGMENT_SIZE-${TARGET_PAGE_SIZE}} 86 87# Determine DATA_ALIGNMENT for the 5 variants, using 88# values specified in the emulparams/<emulation>.sh file or default. 89 90DATA_ALIGNMENT_="${DATA_ALIGNMENT_-${DATA_ALIGNMENT-ALIGN(${SEGMENT_SIZE})}}" 91DATA_ALIGNMENT_n="${DATA_ALIGNMENT_n-${DATA_ALIGNMENT_}}" 92DATA_ALIGNMENT_N="${DATA_ALIGNMENT_N-${DATA_ALIGNMENT-.}}" 93DATA_ALIGNMENT_r="${DATA_ALIGNMENT_r-${DATA_ALIGNMENT-}}" 94DATA_ALIGNMENT_u="${DATA_ALIGNMENT_u-${DATA_ALIGNMENT_r}}" 95 96LD_FLAG=r 97DATA_ALIGNMENT=${DATA_ALIGNMENT_r} 98DEFAULT_DATA_ALIGNMENT="ALIGN(${SEGMENT_SIZE})" 99(. ${srcdir}/scripttempl/${SCRIPT_NAME}.sc) | sed -e '/^ *$/d' > \ 100 ldscripts/${EMULATION_NAME}.xr 101 102LD_FLAG=u 103DATA_ALIGNMENT=${DATA_ALIGNMENT_u} 104CONSTRUCTING=" " 105(. ${srcdir}/scripttempl/${SCRIPT_NAME}.sc) | sed -e '/^ *$/d' > \ 106 ldscripts/${EMULATION_NAME}.xu 107 108LD_FLAG= 109DATA_ALIGNMENT=${DATA_ALIGNMENT_} 110RELOCATING=" " 111(. ${srcdir}/scripttempl/${SCRIPT_NAME}.sc) | sed -e '/^ *$/d' > \ 112 ldscripts/${EMULATION_NAME}.x 113 114LD_FLAG=n 115DATA_ALIGNMENT=${DATA_ALIGNMENT_n} 116TEXT_START_ADDR=${NONPAGED_TEXT_START_ADDR-${TEXT_START_ADDR}} 117(. ${srcdir}/scripttempl/${SCRIPT_NAME}.sc) | sed -e '/^ *$/d' > \ 118 ldscripts/${EMULATION_NAME}.xn 119 120LD_FLAG=N 121DATA_ALIGNMENT=${DATA_ALIGNMENT_N} 122(. ${srcdir}/scripttempl/${SCRIPT_NAME}.sc) | sed -e '/^ *$/d' > \ 123 ldscripts/${EMULATION_NAME}.xbn 124 125if test -n "$GENERATE_SHLIB_SCRIPT"; then 126 LD_FLAG=shared 127 DATA_ALIGNMENT=${DATA_ALIGNMENT_s-${DATA_ALIGNMENT_}} 128 CREATE_SHLIB=" " 129 # Note that TEXT_START_ADDR is set to NONPAGED_TEXT_START_ADDR. 130 (. ${srcdir}/scripttempl/${SCRIPT_NAME}.sc) | sed -e '/^ *$/d' > \ 131 ldscripts/${EMULATION_NAME}.xs 132fi 133 134for i in $EMULATION_LIBPATH ; do 135 test "$i" = "$EMULATION_NAME" && COMPILE_IN=true 136done 137 138# Generate e${EMULATION_NAME}.c. 139. ${srcdir}/emultempl/${TEMPLATE_NAME-generic}.em 140