genscripts.sh revision 52939
152939Sjb#!/bin/sh
252939Sjb# genscripts.sh - generate the ld-emulation-target specific files
352939Sjb#
452939Sjb# Usage: genscripts.sh srcdir libdir host target target_alias \
552939Sjb# default_emulation native_lib_dirs this_emulation
652939Sjb#
752939Sjb# Sample usage:
852939Sjb# genscripts.sh /djm/ld-devo/devo/ld /usr/local/lib sparc-sun-sunos4.1.3 \
952939Sjb# sparc-sun-sunos4.1.3 sparc-sun-sunos4.1.3 sun4 "" sun3 sparc-sun-sunos4.1.3
1052939Sjb# produces sun3.x sun3.xbn sun3.xn sun3.xr sun3.xu em_sun3.c
1152939Sjb#
1252939Sjb# $FreeBSD: head/gnu/usr.bin/binutils/ld/genscripts.sh 52939 1999-11-06 22:40:15Z jb $
1352939Sjb#
1452939Sjb# This is a cut-down version of the GNU script. Instead of jumping through
1552939Sjb# hoops for all possible combinations of paths, just use the libdir
1652939Sjb# argument in place of LIB_PATH.
1752939Sjb#
1852939Sjb# The host, target and target_alias arguments are not used in this version.
1952939Sjb#
2052939Sjb
2152939Sjbsrcdir=$1
2252939Sjblibdir=$2
2352939Sjbhost=$3
2452939Sjbtarget=$4
2552939Sjbtarget_alias=$5
2652939SjbDEFAULT_EMULATION=$6
2752939SjbNATIVE_LIB_DIRS=$7
2852939SjbEMULATION_NAME=$8
2952939Sjb
3052939Sjb# Include the emulation-specific parameters:
3152939Sjb. ${srcdir}/emulparams/${EMULATION_NAME}.sh
3252939Sjb
3352939Sjbif test -d ldscripts; then
3452939Sjb  true
3552939Sjbelse
3652939Sjb  mkdir ldscripts
3752939Sjbfi
3852939Sjb
3952939SjbLIB_SEARCH_DIRS=`echo ${libdir} | tr ':' ' ' | sed -e 's/\([^ ][^ ]*\)/SEARCH_DIR(\1);/g'`
4052939Sjb
4152939Sjb# Generate 5 or 6 script files from a master script template in
4252939Sjb# ${srcdir}/scripttempl/${SCRIPT_NAME}.sh.  Which one of the 5 or 6
4352939Sjb# script files is actually used depends on command line options given
4452939Sjb# to ld.  (SCRIPT_NAME was set in the emulparams_file.)
4552939Sjb#
4652939Sjb# A .x script file is the default script.
4752939Sjb# A .xr script is for linking without relocation (-r flag).
4852939Sjb# A .xu script is like .xr, but *do* create constructors (-Ur flag).
4952939Sjb# A .xn script is for linking with -n flag (mix text and data on same page).
5052939Sjb# A .xbn script is for linking with -N flag (mix text and data on same page).
5152939Sjb# A .xs script is for generating a shared library with the --shared
5252939Sjb#   flag; it is only generated if $GENERATE_SHLIB_SCRIPT is set by the
5352939Sjb#   emulation parameters.
5452939Sjb
5552939SjbSEGMENT_SIZE=${SEGMENT_SIZE-${TARGET_PAGE_SIZE}}
5652939Sjb
5752939Sjb# Determine DATA_ALIGNMENT for the 5 variants, using
5852939Sjb# values specified in the emulparams/<emulation>.sh file or default.
5952939Sjb
6052939SjbDATA_ALIGNMENT_="${DATA_ALIGNMENT_-${DATA_ALIGNMENT-ALIGN(${SEGMENT_SIZE})}}"
6152939SjbDATA_ALIGNMENT_n="${DATA_ALIGNMENT_n-${DATA_ALIGNMENT_}}"
6252939SjbDATA_ALIGNMENT_N="${DATA_ALIGNMENT_N-${DATA_ALIGNMENT-.}}"
6352939SjbDATA_ALIGNMENT_r="${DATA_ALIGNMENT_r-${DATA_ALIGNMENT-}}"
6452939SjbDATA_ALIGNMENT_u="${DATA_ALIGNMENT_u-${DATA_ALIGNMENT_r}}"
6552939Sjb
6652939SjbLD_FLAG=r
6752939SjbDATA_ALIGNMENT=${DATA_ALIGNMENT_r}
6852939SjbDEFAULT_DATA_ALIGNMENT="ALIGN(${SEGMENT_SIZE})"
6952939Sjb(. ${srcdir}/scripttempl/${SCRIPT_NAME}.sc) | sed -e '/^ *$/d' > \
7052939Sjb  ldscripts/${EMULATION_NAME}.xr
7152939Sjb
7252939SjbLD_FLAG=u
7352939SjbDATA_ALIGNMENT=${DATA_ALIGNMENT_u}
7452939SjbCONSTRUCTING=" "
7552939Sjb(. ${srcdir}/scripttempl/${SCRIPT_NAME}.sc) | sed -e '/^ *$/d' > \
7652939Sjb  ldscripts/${EMULATION_NAME}.xu
7752939Sjb
7852939SjbLD_FLAG=
7952939SjbDATA_ALIGNMENT=${DATA_ALIGNMENT_}
8052939SjbRELOCATING=" "
8152939Sjb(. ${srcdir}/scripttempl/${SCRIPT_NAME}.sc) | sed -e '/^ *$/d' > \
8252939Sjb  ldscripts/${EMULATION_NAME}.x
8352939Sjb
8452939SjbLD_FLAG=n
8552939SjbDATA_ALIGNMENT=${DATA_ALIGNMENT_n}
8652939SjbTEXT_START_ADDR=${NONPAGED_TEXT_START_ADDR-${TEXT_START_ADDR}}
8752939Sjb(. ${srcdir}/scripttempl/${SCRIPT_NAME}.sc) | sed -e '/^ *$/d' > \
8852939Sjb  ldscripts/${EMULATION_NAME}.xn
8952939Sjb
9052939SjbLD_FLAG=N
9152939SjbDATA_ALIGNMENT=${DATA_ALIGNMENT_N}
9252939Sjb(. ${srcdir}/scripttempl/${SCRIPT_NAME}.sc) | sed -e '/^ *$/d' > \
9352939Sjb  ldscripts/${EMULATION_NAME}.xbn
9452939Sjb
9552939Sjbif test -n "$GENERATE_SHLIB_SCRIPT"; then
9652939Sjb  LD_FLAG=shared
9752939Sjb  DATA_ALIGNMENT=${DATA_ALIGNMENT_s-${DATA_ALIGNMENT_}}
9852939Sjb  CREATE_SHLIB=" "
9952939Sjb  # Note that TEXT_START_ADDR is set to NONPAGED_TEXT_START_ADDR.
10052939Sjb  (. ${srcdir}/scripttempl/${SCRIPT_NAME}.sc) | sed -e '/^ *$/d' > \
10152939Sjb    ldscripts/${EMULATION_NAME}.xs
10252939Sjbfi
10352939Sjb
10452939Sjbtest "$DEFAULT_EMULATION" = "$EMULATION_NAME" && COMPILE_IN=true
10552939Sjb
10652939Sjb# Generate e${EMULATION_NAME}.c.
10752939Sjb. ${srcdir}/emultempl/${TEMPLATE_NAME-generic}.em
108