]>
Commit | Line | Data |
---|---|---|
a6152e39 DM |
1 | #!/bin/sh |
2 | # genscripts.sh - generate the ld-emulation-target specific files | |
3 | # | |
4 | # Usage: genscripts.sh srcdir libdir host_alias target_alias \ | |
5 | # default_emulation this_emulation | |
6 | # | |
173a0c3d | 7 | # Sample usage: |
a6152e39 DM |
8 | # genscripts.sh /djm/ld-devo/devo/ld /usr/local/lib sparc-sun-sunos4.1.3 \ |
9 | # sparc-sun-sunos4.1.3 sun4 sun3 | |
173a0c3d | 10 | # produces sun3.x sun3.xbn sun3.xn sun3.xr sun3.xu em_sun3.c |
de566389 PB |
11 | |
12 | srcdir=$1 | |
ff76a7db DM |
13 | libdir=$2 |
14 | host_alias=$3 | |
15 | target_alias=$4 | |
a6152e39 DM |
16 | DEFAULT_EMULATION=$5 |
17 | EMULATION_NAME=$6 | |
de566389 | 18 | |
173a0c3d | 19 | # Include the emulation-specific parameters: |
a6152e39 | 20 | . ${srcdir}/emulparams/${EMULATION_NAME}.sh |
de566389 | 21 | |
173a0c3d DM |
22 | # Set the library search path, for libraries named by -lfoo. |
23 | # If LIB_PATH is defined (e.g., by Makefile) and non-empty, it is used. | |
24 | # Otherwise, the default is set here. | |
25 | # | |
26 | # The format is the usual list of colon-separated directories. | |
27 | # To force a logically empty LIB_PATH, do LIBPATH=":". | |
de566389 | 28 | |
173a0c3d DM |
29 | if [ "x${LIB_PATH}" = "x" ] ; then |
30 | if [ "x${host_alias}" = "x${target_alias}" ] ; then | |
31 | # Native. | |
ff76a7db | 32 | LIB_PATH=/lib:/usr/lib:${libdir} |
173a0c3d DM |
33 | if [ "${libdir}" != /usr/local/lib ] ; then |
34 | LIB_PATH=${LIB_PATH}:/usr/local/lib | |
35 | fi | |
36 | else | |
37 | # Cross. | |
a6152e39 | 38 | LIB_PATH=: |
173a0c3d | 39 | fi |
de566389 PB |
40 | fi |
41 | LIB_SEARCH_DIRS=`echo ${LIB_PATH} | tr ':' ' ' | sed -e 's/\([^ ][^ ]*\)/SEARCH_DIR(\1);/g'` | |
42 | ||
173a0c3d DM |
43 | # Generate 5 script files from a master script template in |
44 | # ${srcdir}/scripttempl/${SCRIPT_NAME}.sh. Which one of the 5 script files | |
45 | # is actually used depends on command line options given to ld. | |
a6152e39 | 46 | # (SCRIPT_NAME was set in the emulparams_file.) |
de566389 PB |
47 | # |
48 | # A .x script file is the default script. | |
49 | # A .xr script is for linking without relocation (-r flag). | |
50 | # A .xu script is like .xr, but *do* create constructors (-Ur flag). | |
51 | # A .xn script is for linking with -n flag (mix text and data on same page). | |
173a0c3d | 52 | # A .xbn script is for linking with -N flag (mix text and data on same page). |
de566389 | 53 | |
de566389 PB |
54 | SEGMENT_SIZE=${SEGMENT_SIZE-${PAGE_SIZE}} |
55 | ||
173a0c3d DM |
56 | # Determine DATA_ALIGNMENT for the 5 variants, using |
57 | # values specified in the emulparams/<emulation>.sh file or default. | |
58 | ||
59 | DATA_ALIGNMENT_="${DATA_ALIGNMENT_-${DATA_ALIGNMENT-ALIGN(${SEGMENT_SIZE})}}" | |
60 | DATA_ALIGNMENT_n="${DATA_ALIGNMENT_n-${DATA_ALIGNMENT_}}" | |
61 | DATA_ALIGNMENT_N="${DATA_ALIGNMENT_N-${DATA_ALIGNMENT-.}}" | |
62 | DATA_ALIGNMENT_r="${DATA_ALIGNMENT_r-${DATA_ALIGNMENT-}}" | |
63 | DATA_ALIGNMENT_u="${DATA_ALIGNMENT_u-${DATA_ALIGNMENT_r}}" | |
64 | ||
65 | LD_FLAG=r | |
66 | DATA_ALIGNMENT=${DATA_ALIGNMENT_r} | |
67 | DEFAULT_DATA_ALIGNMENT="ALIGN(${SEGMENT_SIZE})" | |
68 | (. ${srcdir}/scripttempl/${SCRIPT_NAME}.sc) | sed -e '/^ *$/d' > \ | |
69 | ldscripts/${EMULATION_NAME}.xr | |
70 | ||
71 | LD_FLAG=u | |
72 | DATA_ALIGNMENT=${DATA_ALIGNMENT_u} | |
de566389 | 73 | CONSTRUCTING= |
173a0c3d DM |
74 | (. ${srcdir}/scripttempl/${SCRIPT_NAME}.sc) | sed -e '/^ *$/d' > \ |
75 | ldscripts/${EMULATION_NAME}.xu | |
76 | ||
77 | LD_FLAG= | |
78 | DATA_ALIGNMENT=${DATA_ALIGNMENT_} | |
de566389 | 79 | RELOCATING= |
173a0c3d DM |
80 | (. ${srcdir}/scripttempl/${SCRIPT_NAME}.sc) | sed -e '/^ *$/d' > \ |
81 | ldscripts/${EMULATION_NAME}.x | |
82 | ||
83 | LD_FLAG=n | |
84 | DATA_ALIGNMENT=${DATA_ALIGNMENT_n} | |
85 | TEXT_START_ADDR=${NONPAGED_TEXT_START_ADDR-${TEXT_START_ADDR}} | |
86 | (. ${srcdir}/scripttempl/${SCRIPT_NAME}.sc) | sed -e '/^ *$/d' > \ | |
87 | ldscripts/${EMULATION_NAME}.xn | |
88 | ||
89 | LD_FLAG=N | |
90 | DATA_ALIGNMENT=${DATA_ALIGNMENT_N} | |
91 | (. ${srcdir}/scripttempl/${SCRIPT_NAME}.sc) | sed -e '/^ *$/d' > \ | |
92 | ldscripts/${EMULATION_NAME}.xbn | |
de566389 | 93 | |
173a0c3d DM |
94 | # Generate em_${EMULATION_NAME}.c. |
95 | . ${srcdir}/emultempl/${TEMPLATE_NAME-generic}.em |