genscripts.sh revision 77571
1137284Scognet#!/bin/sh
2137284Scognet# genscripts.sh - generate the ld-emulation-target specific files
3137284Scognet#
4137284Scognet# Usage: genscripts.sh srcdir libdir host target target_alias \
5137284Scognet# default_emulation native_lib_dirs this_emulation
6137284Scognet#
7137284Scognet# Sample usage:
8137284Scognet# genscripts.sh /djm/ld-devo/devo/ld /usr/local/lib sparc-sun-sunos4.1.3 \
9140279Sdas# sparc-sun-sunos4.1.3 sparc-sun-sunos4.1.3 sun4 "" sun3 sparc-sun-sunos4.1.3
10143858Scognet# produces sun3.x sun3.xbn sun3.xn sun3.xr sun3.xu em_sun3.c
11143858Scognet#
12# $FreeBSD: head/gnu/usr.bin/binutils/ld/genscripts.sh 77571 2001-06-01 05:31:02Z obrien $
13#
14# This is a cut-down version of the GNU script. Instead of jumping through
15# hoops for all possible combinations of paths, just use the libdir
16# argument in place of LIB_PATH.
17#
18# The host, target and target_alias arguments are not used in this version.
19#
20
21srcdir=$1
22libdir=$2
23host=$3
24target=$4
25target_alias=$5
26EMULATION_LIBPATH=$6
27NATIVE_LIB_DIRS=$7
28EMULATION_NAME=$8
29
30# Include the emulation-specific parameters:
31. ${srcdir}/emulparams/${EMULATION_NAME}.sh
32
33if test -d ldscripts; then
34  true
35else
36  mkdir ldscripts
37fi
38
39# Set the library search path, for libraries named by -lfoo.
40# If LIB_PATH is defined (e.g., by Makefile) and non-empty, it is used.
41# Otherwise, the default is set here.
42#
43# The format is the usual list of colon-separated directories.
44# To force a logically empty LIB_PATH, do LIBPATH=":".
45
46LIB_SEARCH_DIRS=`echo ${libdir} | tr ':' ' ' | sed -e 's/\([^ ][^ ]*\)/SEARCH_DIR(\1);/g'`
47
48# Generate 5 or 6 script files from a master script template in
49# ${srcdir}/scripttempl/${SCRIPT_NAME}.sh.  Which one of the 5 or 6
50# script files is actually used depends on command line options given
51# to ld.  (SCRIPT_NAME was set in the emulparams_file.)
52#
53# A .x script file is the default script.
54# A .xr script is for linking without relocation (-r flag).
55# A .xu script is like .xr, but *do* create constructors (-Ur flag).
56# A .xn script is for linking with -n flag (mix text and data on same page).
57# A .xbn script is for linking with -N flag (mix text and data on same page).
58# A .xs script is for generating a shared library with the --shared
59#   flag; it is only generated if $GENERATE_SHLIB_SCRIPT is set by the
60#   emulation parameters.
61
62SEGMENT_SIZE=${SEGMENT_SIZE-${TARGET_PAGE_SIZE}}
63
64# Determine DATA_ALIGNMENT for the 5 variants, using
65# values specified in the emulparams/<emulation>.sh file or default.
66
67DATA_ALIGNMENT_="${DATA_ALIGNMENT_-${DATA_ALIGNMENT-ALIGN(${SEGMENT_SIZE})}}"
68DATA_ALIGNMENT_n="${DATA_ALIGNMENT_n-${DATA_ALIGNMENT_}}"
69DATA_ALIGNMENT_N="${DATA_ALIGNMENT_N-${DATA_ALIGNMENT-.}}"
70DATA_ALIGNMENT_r="${DATA_ALIGNMENT_r-${DATA_ALIGNMENT-}}"
71DATA_ALIGNMENT_u="${DATA_ALIGNMENT_u-${DATA_ALIGNMENT_r}}"
72
73LD_FLAG=r
74DATA_ALIGNMENT=${DATA_ALIGNMENT_r}
75DEFAULT_DATA_ALIGNMENT="ALIGN(${SEGMENT_SIZE})"
76(. ${srcdir}/scripttempl/${SCRIPT_NAME}.sc) | sed -e '/^ *$/d' \
77  > ldscripts/${EMULATION_NAME}.xr
78
79LD_FLAG=u
80DATA_ALIGNMENT=${DATA_ALIGNMENT_u}
81CONSTRUCTING=" "
82(. ${srcdir}/scripttempl/${SCRIPT_NAME}.sc) | sed -e '/^ *$/d' \
83  > ldscripts/${EMULATION_NAME}.xu
84
85LD_FLAG=
86DATA_ALIGNMENT=${DATA_ALIGNMENT_}
87RELOCATING=" "
88(. ${srcdir}/scripttempl/${SCRIPT_NAME}.sc) | sed -e '/^ *$/d' \
89  > ldscripts/${EMULATION_NAME}.x
90
91LD_FLAG=n
92DATA_ALIGNMENT=${DATA_ALIGNMENT_n}
93TEXT_START_ADDR=${NONPAGED_TEXT_START_ADDR-${TEXT_START_ADDR}}
94(. ${srcdir}/scripttempl/${SCRIPT_NAME}.sc) | sed -e '/^ *$/d' \
95  > ldscripts/${EMULATION_NAME}.xn
96
97LD_FLAG=N
98DATA_ALIGNMENT=${DATA_ALIGNMENT_N}
99(. ${srcdir}/scripttempl/${SCRIPT_NAME}.sc) | sed -e '/^ *$/d' \
100  > ldscripts/${EMULATION_NAME}.xbn
101
102if test -n "$GENERATE_SHLIB_SCRIPT"; then
103  LD_FLAG=shared
104  DATA_ALIGNMENT=${DATA_ALIGNMENT_s-${DATA_ALIGNMENT_}}
105  CREATE_SHLIB=" "
106  # Note that TEXT_START_ADDR is set to NONPAGED_TEXT_START_ADDR.
107  (. ${srcdir}/scripttempl/${SCRIPT_NAME}.sc) | sed -e '/^ *$/d' \
108    > ldscripts/${EMULATION_NAME}.xs
109fi
110
111for i in $EMULATION_LIBPATH ; do
112  test "$i" = "$EMULATION_NAME" && COMPILE_IN=true
113done
114# Generate e${EMULATION_NAME}.c.
115. ${srcdir}/emultempl/${TEMPLATE_NAME-generic}.em
116