2 # genscripts.sh - generate the ld-emulation-target specific files
4 # Usage: genscripts.sh srcdir libdir host target target_alias \
5 # default_emulation native_lib_dirs this_emulation tool_dir
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
20 tool_lib=`echo ${libdir} | sed -e 's|/lib$||'`/${9-$target_alias}/lib
22 # Include the emulation-specific parameters:
23 . ${srcdir}/emulparams/${EMULATION_NAME}.sh
25 if test -d ldscripts; then
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.
35 # The format is the usual list of colon-separated directories.
36 # To force a logically empty LIB_PATH, do LIBPATH=":".
38 if [ "x${LIB_PATH}" = "x" ] ; then
39 # Cross, or native non-default emulation not requesting LIB_PATH.
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=/lib:/usr/lib
47 if [ -n "${NATIVE_LIB_DIRS}" ]; then
48 LIB_PATH=${LIB_PATH}:${NATIVE_LIB_DIRS}
50 if [ "${libdir}" != /usr/lib ]; then
51 LIB_PATH=${LIB_PATH}:${libdir}
53 if [ "${libdir}" != /usr/local/lib ] ; then
54 LIB_PATH=${LIB_PATH}:/usr/local/lib
60 # Always search $(tooldir)/lib, aka /usr/local/TARGET/lib.
61 LIB_PATH=${LIB_PATH}:${tool_lib}
63 LIB_SEARCH_DIRS=`echo ${LIB_PATH} | tr ':' ' ' | sed -e 's/\([^ ][^ ]*\)/SEARCH_DIR(\1);/g'`
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.)
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.
79 SEGMENT_SIZE=${SEGMENT_SIZE-${TARGET_PAGE_SIZE}}
81 # Determine DATA_ALIGNMENT for the 5 variants, using
82 # values specified in the emulparams/<emulation>.sh file or default.
84 DATA_ALIGNMENT_="${DATA_ALIGNMENT_-${DATA_ALIGNMENT-ALIGN(${SEGMENT_SIZE})}}"
85 DATA_ALIGNMENT_n="${DATA_ALIGNMENT_n-${DATA_ALIGNMENT_}}"
86 DATA_ALIGNMENT_N="${DATA_ALIGNMENT_N-${DATA_ALIGNMENT-.}}"
87 DATA_ALIGNMENT_r="${DATA_ALIGNMENT_r-${DATA_ALIGNMENT-}}"
88 DATA_ALIGNMENT_u="${DATA_ALIGNMENT_u-${DATA_ALIGNMENT_r}}"
91 DATA_ALIGNMENT=${DATA_ALIGNMENT_r}
92 DEFAULT_DATA_ALIGNMENT="ALIGN(${SEGMENT_SIZE})"
93 (. ${srcdir}/scripttempl/${SCRIPT_NAME}.sc) | sed -e '/^ *$/d' > \
94 ldscripts/${EMULATION_NAME}.xr
97 DATA_ALIGNMENT=${DATA_ALIGNMENT_u}
99 (. ${srcdir}/scripttempl/${SCRIPT_NAME}.sc) | sed -e '/^ *$/d' > \
100 ldscripts/${EMULATION_NAME}.xu
103 DATA_ALIGNMENT=${DATA_ALIGNMENT_}
105 (. ${srcdir}/scripttempl/${SCRIPT_NAME}.sc) | sed -e '/^ *$/d' > \
106 ldscripts/${EMULATION_NAME}.x
109 DATA_ALIGNMENT=${DATA_ALIGNMENT_n}
110 TEXT_START_ADDR=${NONPAGED_TEXT_START_ADDR-${TEXT_START_ADDR}}
111 (. ${srcdir}/scripttempl/${SCRIPT_NAME}.sc) | sed -e '/^ *$/d' > \
112 ldscripts/${EMULATION_NAME}.xn
115 DATA_ALIGNMENT=${DATA_ALIGNMENT_N}
116 (. ${srcdir}/scripttempl/${SCRIPT_NAME}.sc) | sed -e '/^ *$/d' > \
117 ldscripts/${EMULATION_NAME}.xbn
119 if test -n "$GENERATE_SHLIB_SCRIPT"; then
121 DATA_ALIGNMENT=${DATA_ALIGNMENT_s-${DATA_ALIGNMENT_}}
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
128 for i in $EMULATION_LIBPATH ; do
129 test "$i" = "$EMULATION_NAME" && COMPILE_IN=true
132 # Generate e${EMULATION_NAME}.c.
133 . ${srcdir}/emultempl/${TEMPLATE_NAME-generic}.em