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