genscripts.sh revision 1.5
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=/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    esac
54  fi
55fi
56
57# Always search $(tooldir)/lib, aka /usr/local/TARGET/lib.
58LIB_PATH=${LIB_PATH}:${tool_lib}
59
60LIB_SEARCH_DIRS=`echo ${LIB_PATH} | tr ':' ' ' | sed -e 's/\([^ ][^ ]*\)/SEARCH_DIR(\1);/g'`
61
62# Generate 5 or 6 script files from a master script template in
63# ${srcdir}/scripttempl/${SCRIPT_NAME}.sh.  Which one of the 5 or 6
64# script files is actually used depends on command line options given
65# to ld.  (SCRIPT_NAME was set in the emulparams_file.)
66#
67# A .x script file is the default script.
68# A .xr script is for linking without relocation (-r flag).
69# A .xu script is like .xr, but *do* create constructors (-Ur flag).
70# A .xn script is for linking with -n flag (mix text and data on same page).
71# A .xbn script is for linking with -N flag (mix text and data on same page).
72# A .xs script is for generating a shared library with the --shared
73#   flag; it is only generated if $GENERATE_SHLIB_SCRIPT is set by the
74#   emulation parameters.
75
76SEGMENT_SIZE=${SEGMENT_SIZE-${TARGET_PAGE_SIZE}}
77
78# Determine DATA_ALIGNMENT for the 5 variants, using
79# values specified in the emulparams/<emulation>.sh file or default.
80
81DATA_ALIGNMENT_="${DATA_ALIGNMENT_-${DATA_ALIGNMENT-ALIGN(${SEGMENT_SIZE})}}"
82DATA_ALIGNMENT_n="${DATA_ALIGNMENT_n-${DATA_ALIGNMENT_}}"
83DATA_ALIGNMENT_N="${DATA_ALIGNMENT_N-${DATA_ALIGNMENT-.}}"
84DATA_ALIGNMENT_r="${DATA_ALIGNMENT_r-${DATA_ALIGNMENT-}}"
85DATA_ALIGNMENT_u="${DATA_ALIGNMENT_u-${DATA_ALIGNMENT_r}}"
86
87LD_FLAG=r
88DATA_ALIGNMENT=${DATA_ALIGNMENT_r}
89DEFAULT_DATA_ALIGNMENT="ALIGN(${SEGMENT_SIZE})"
90(. ${srcdir}/scripttempl/${SCRIPT_NAME}.sc) | sed -e '/^ *$/d' > \
91  ldscripts/${EMULATION_NAME}.xr
92
93LD_FLAG=u
94DATA_ALIGNMENT=${DATA_ALIGNMENT_u}
95CONSTRUCTING=" "
96(. ${srcdir}/scripttempl/${SCRIPT_NAME}.sc) | sed -e '/^ *$/d' > \
97  ldscripts/${EMULATION_NAME}.xu
98
99LD_FLAG=
100DATA_ALIGNMENT=${DATA_ALIGNMENT_}
101RELOCATING=" "
102(. ${srcdir}/scripttempl/${SCRIPT_NAME}.sc) | sed -e '/^ *$/d' > \
103  ldscripts/${EMULATION_NAME}.x
104
105LD_FLAG=n
106DATA_ALIGNMENT=${DATA_ALIGNMENT_n}
107TEXT_START_ADDR=${NONPAGED_TEXT_START_ADDR-${TEXT_START_ADDR}}
108(. ${srcdir}/scripttempl/${SCRIPT_NAME}.sc) | sed -e '/^ *$/d' > \
109  ldscripts/${EMULATION_NAME}.xn
110
111LD_FLAG=N
112DATA_ALIGNMENT=${DATA_ALIGNMENT_N}
113(. ${srcdir}/scripttempl/${SCRIPT_NAME}.sc) | sed -e '/^ *$/d' > \
114  ldscripts/${EMULATION_NAME}.xbn
115
116if test -n "$GENERATE_SHLIB_SCRIPT"; then
117  LD_FLAG=shared
118  DATA_ALIGNMENT=${DATA_ALIGNMENT_s-${DATA_ALIGNMENT_}}
119  CREATE_SHLIB=" "
120  # Note that TEXT_START_ADDR is set to NONPAGED_TEXT_START_ADDR.
121  (. ${srcdir}/scripttempl/${SCRIPT_NAME}.sc) | sed -e '/^ *$/d' > \
122    ldscripts/${EMULATION_NAME}.xs
123fi
124
125for i in $EMULATION_LIBPATH ; do
126  test "$i" = "$EMULATION_NAME" && COMPILE_IN=true
127done
128
129# Generate e${EMULATION_NAME}.c.
130. ${srcdir}/emultempl/${TEMPLATE_NAME-generic}.em
131