genscripts.sh revision 1.1
1#!/bin/sh 2# genscripts.sh - generate the ld-emulation-target specific files 3# 4# Usage: genscripts.sh srcdir libdir host_alias target_alias \ 5# default_emulation 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 sun4 sun3 10# produces sun3.x sun3.xbn sun3.xn sun3.xr sun3.xu em_sun3.c 11 12srcdir=$1 13libdir=$2 14host_alias=$3 15target_alias=$4 16DEFAULT_EMULATION=$5 17NATIVE_LIB_DIRS=$6 18EMULATION_NAME=$7 19 20# Include the emulation-specific parameters: 21. ${srcdir}/emulparams/${EMULATION_NAME}.sh 22 23if test -d ldscripts; then 24 true 25else 26 mkdir ldscripts 27fi 28 29# Set the library search path, for libraries named by -lfoo. 30# If LIB_PATH is defined (e.g., by Makefile) and non-empty, it is used. 31# Otherwise, the default is set here. 32# 33# The format is the usual list of colon-separated directories. 34# To force a logically empty LIB_PATH, do LIBPATH=":". 35 36if [ "x${LIB_PATH}" = "x" ] ; then 37 if [ "x${host_alias}" = "x${target_alias}" ] ; then 38 if [ "x${DEFAULT_EMULATION}" = "x${EMULATION_NAME}" ] ; then 39 # Native. 40 LIB_PATH=/lib:/usr/lib 41 if [ -n "${NATIVE_LIB_DIRS}" ]; then 42 LIB_PATH=${LIB_PATH}:${NATIVE_LIB_DIRS} 43 fi 44 if [ "${libdir}" != /usr/lib ]; then 45 LIB_PATH=${LIB_PATH}:${libdir} 46 fi 47 if [ "${libdir}" != /usr/local/lib ] ; then 48 LIB_PATH=${LIB_PATH}:/usr/local/lib 49 fi 50 else 51 # Native, but not default emulation. 52 LIB_PATH= 53 fi 54 else 55 # Cross. 56 LIB_PATH= 57 fi 58fi 59 60# Always search $(tooldir)/lib, aka /usr/local/TARGET/lib. 61LIB_PATH=${LIB_PATH}:`echo ${libdir} | sed -e s'|/lib$||'`/${target_alias}/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 128test "$DEFAULT_EMULATION" = "$EMULATION_NAME" && COMPILE_IN=true 129 130# Generate em_${EMULATION_NAME}.c. 131. ${srcdir}/emultempl/${TEMPLATE_NAME-generic}.em 132