genscripts.sh revision 60777
1331722Seadler#!/bin/sh 21539Srgrimes# genscripts.sh - generate the ld-emulation-target specific files 31539Srgrimes# 41539Srgrimes# Usage: genscripts.sh srcdir libdir host target target_alias \ 51539Srgrimes# default_emulation native_lib_dirs this_emulation 61539Srgrimes# 71539Srgrimes# Sample usage: 81539Srgrimes# genscripts.sh /djm/ld-devo/devo/ld /usr/local/lib sparc-sun-sunos4.1.3 \ 91539Srgrimes# sparc-sun-sunos4.1.3 sparc-sun-sunos4.1.3 sun4 "" sun3 sparc-sun-sunos4.1.3 101539Srgrimes# produces sun3.x sun3.xbn sun3.xn sun3.xr sun3.xu em_sun3.c 111539Srgrimes# 121539Srgrimes# $FreeBSD: head/gnu/usr.bin/binutils/ld/genscripts.sh 60777 2000-05-22 08:09:42Z obrien $ 13203965Simp# 141539Srgrimes# This is a cut-down version of the GNU script. Instead of jumping through 151539Srgrimes# hoops for all possible combinations of paths, just use the libdir 161539Srgrimes# argument in place of LIB_PATH. 171539Srgrimes# 181539Srgrimes# The host, target and target_alias arguments are not used in this version. 191539Srgrimes# 201539Srgrimes 211539Srgrimessrcdir=$1 221539Srgrimeslibdir=$2 231539Srgrimeshost=$3 241539Srgrimestarget=$4 251539Srgrimestarget_alias=$5 261539SrgrimesEMULATION_LIBPATH=$6 271539SrgrimesNATIVE_LIB_DIRS=$7 281539SrgrimesEMULATION_NAME=$8 291539Srgrimes 30203965Simp# Include the emulation-specific parameters: 31203965Simp. ${srcdir}/emulparams/${EMULATION_NAME}.sh 321539Srgrimes 331539Srgrimesif test -d ldscripts; then 342163Spaul true 352163Spaulelse 361539Srgrimes mkdir ldscripts 371539Srgrimesfi 381539Srgrimes 391539Srgrimes# Set the library search path, for libraries named by -lfoo. 401539Srgrimes# If LIB_PATH is defined (e.g., by Makefile) and non-empty, it is used. 411539Srgrimes# Otherwise, the default is set here. 421539Srgrimes# 431539Srgrimes# The format is the usual list of colon-separated directories. 441539Srgrimes# To force a logically empty LIB_PATH, do LIBPATH=":". 451539Srgrimes 461539SrgrimesLIB_SEARCH_DIRS=`echo ${libdir} | tr ':' ' ' | sed -e 's/\([^ ][^ ]*\)/SEARCH_DIR(\1);/g'` 471539Srgrimes 481539Srgrimes# Generate 5 or 6 script files from a master script template in 491539Srgrimes# ${srcdir}/scripttempl/${SCRIPT_NAME}.sh. Which one of the 5 or 6 501539Srgrimes# script files is actually used depends on command line options given 511539Srgrimes# to ld. (SCRIPT_NAME was set in the emulparams_file.) 521539Srgrimes# 531539Srgrimes# A .x script file is the default script. 541539Srgrimes# A .xr script is for linking without relocation (-r flag). 551539Srgrimes# A .xu script is like .xr, but *do* create constructors (-Ur flag). 561539Srgrimes# A .xn script is for linking with -n flag (mix text and data on same page). 571539Srgrimes# A .xbn script is for linking with -N flag (mix text and data on same page). 581539Srgrimes# A .xs script is for generating a shared library with the --shared 591539Srgrimes# flag; it is only generated if $GENERATE_SHLIB_SCRIPT is set by the 601539Srgrimes# emulation parameters. 611539Srgrimes 621539SrgrimesSEGMENT_SIZE=${SEGMENT_SIZE-${TARGET_PAGE_SIZE}} 6340536Sdima 641539Srgrimes# Determine DATA_ALIGNMENT for the 5 variants, using 651539Srgrimes# values specified in the emulparams/<emulation>.sh file or default. 6640536Sdima 671539SrgrimesDATA_ALIGNMENT_="${DATA_ALIGNMENT_-${DATA_ALIGNMENT-ALIGN(${SEGMENT_SIZE})}}" 681539SrgrimesDATA_ALIGNMENT_n="${DATA_ALIGNMENT_n-${DATA_ALIGNMENT_}}" 691539SrgrimesDATA_ALIGNMENT_N="${DATA_ALIGNMENT_N-${DATA_ALIGNMENT-.}}" 701539SrgrimesDATA_ALIGNMENT_r="${DATA_ALIGNMENT_r-${DATA_ALIGNMENT-}}" 711539SrgrimesDATA_ALIGNMENT_u="${DATA_ALIGNMENT_u-${DATA_ALIGNMENT_r}}" 721539Srgrimes 731539SrgrimesLD_FLAG=r 741539SrgrimesDATA_ALIGNMENT=${DATA_ALIGNMENT_r} 751539SrgrimesDEFAULT_DATA_ALIGNMENT="ALIGN(${SEGMENT_SIZE})" 761539Srgrimes(. ${srcdir}/scripttempl/${SCRIPT_NAME}.sc) | sed -e '/^ *$/d' > \ 771539Srgrimes ldscripts/${EMULATION_NAME}.xr 781539Srgrimes 791539SrgrimesLD_FLAG=u 801539SrgrimesDATA_ALIGNMENT=${DATA_ALIGNMENT_u} 811539SrgrimesCONSTRUCTING=" " 8240536Sdima(. ${srcdir}/scripttempl/${SCRIPT_NAME}.sc) | sed -e '/^ *$/d' > \ 831539Srgrimes ldscripts/${EMULATION_NAME}.xu 841539Srgrimes 851539SrgrimesLD_FLAG= 861539SrgrimesDATA_ALIGNMENT=${DATA_ALIGNMENT_} 871539SrgrimesRELOCATING=" " 881539Srgrimes(. ${srcdir}/scripttempl/${SCRIPT_NAME}.sc) | sed -e '/^ *$/d' > \ 891539Srgrimes ldscripts/${EMULATION_NAME}.x 901539Srgrimes 911539SrgrimesLD_FLAG=n 921539SrgrimesDATA_ALIGNMENT=${DATA_ALIGNMENT_n} 931539SrgrimesTEXT_START_ADDR=${NONPAGED_TEXT_START_ADDR-${TEXT_START_ADDR}} 941539Srgrimes(. ${srcdir}/scripttempl/${SCRIPT_NAME}.sc) | sed -e '/^ *$/d' > \ 951539Srgrimes ldscripts/${EMULATION_NAME}.xn 961539Srgrimes 971539SrgrimesLD_FLAG=N 981539SrgrimesDATA_ALIGNMENT=${DATA_ALIGNMENT_N} 991539Srgrimes(. ${srcdir}/scripttempl/${SCRIPT_NAME}.sc) | sed -e '/^ *$/d' > \ 1001539Srgrimes ldscripts/${EMULATION_NAME}.xbn 1011539Srgrimes 1021539Srgrimesif test -n "$GENERATE_SHLIB_SCRIPT"; then 1031539Srgrimes LD_FLAG=shared 1041539Srgrimes DATA_ALIGNMENT=${DATA_ALIGNMENT_s-${DATA_ALIGNMENT_}} 1051539Srgrimes CREATE_SHLIB=" " 1061539Srgrimes # Note that TEXT_START_ADDR is set to NONPAGED_TEXT_START_ADDR. 1071539Srgrimes (. ${srcdir}/scripttempl/${SCRIPT_NAME}.sc) | sed -e '/^ *$/d' > \ 1081539Srgrimes ldscripts/${EMULATION_NAME}.xs 1091539Srgrimesfi 1101539Srgrimes 1111539Srgrimesfor i in $EMULATION_LIBPATH ; do 1121539Srgrimes test "$i" = "$EMULATION_NAME" && COMPILE_IN=true 113done 114# Generate e${EMULATION_NAME}.c. 115. ${srcdir}/emultempl/${TEMPLATE_NAME-generic}.em 116