home *** CD-ROM | disk | FTP | other *** search
/ Geek Gadgets 1 / ADE-1.bin / ade-dist / binutils-2.7-src.tgz / tar.out / fsf / binutils / ld / genscripts.sh < prev    next >
Linux/UNIX/POSIX Shell Script  |  1996-09-28  |  4KB  |  135 lines

  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.  
  12. srcdir=$1
  13. libdir=$2
  14. host=$3
  15. target=$4
  16. target_alias=$5
  17. DEFAULT_EMULATION=$6
  18. NATIVE_LIB_DIRS=$7
  19. LIB_PATH=$8
  20. EMULATION_NAME=$9
  21. tool_lib=`echo ${libdir} | sed -e 's|/lib$||'`/${10-$target_alias}/lib
  22.  
  23. # Include the emulation-specific parameters:
  24. . ${srcdir}/emulparams/${EMULATION_NAME}.sh
  25.  
  26. if test -d ldscripts; then
  27.   true
  28. else
  29.   mkdir ldscripts
  30. fi
  31.  
  32. # Set the library search path, for libraries named by -lfoo.
  33. # If LIB_PATH is defined (e.g., by Makefile) and non-empty, it is used.
  34. # Otherwise, the default is set here.
  35. #
  36. # The format is the usual list of colon-separated directories.
  37. # To force a logically empty LIB_PATH, do LIBPATH=":".
  38.  
  39. if [ "x${LIB_PATH}" = "x" ] ; then
  40.   if [ "x${host}" = "x${target}" ] ; then
  41.     if [ "x${DEFAULT_EMULATION}" = "x${EMULATION_NAME}" ] ; then
  42.       # Native.
  43.       LIB_PATH=/lib:/usr/lib
  44.       if [ -n "${NATIVE_LIB_DIRS}" ]; then
  45.     LIB_PATH=${LIB_PATH}:${NATIVE_LIB_DIRS}
  46.       fi
  47.       if [ "${libdir}" != /usr/lib ]; then
  48.     LIB_PATH=${LIB_PATH}:${libdir}
  49.       fi
  50.       if [ "${libdir}" != /usr/local/lib ] ; then
  51.     LIB_PATH=${LIB_PATH}:/usr/local/lib
  52.       fi
  53.     else
  54.       # Native, but not default emulation.
  55.       LIB_PATH=
  56.     fi
  57.   else
  58.     # Cross.
  59.     LIB_PATH=
  60.   fi
  61. fi
  62.  
  63. # Always search $(tooldir)/lib, aka /usr/local/TARGET/lib.
  64. LIB_PATH=${LIB_PATH}:${tool_lib}
  65.  
  66. LIB_SEARCH_DIRS=`echo ${LIB_PATH} | tr ':' ' ' | sed -e 's/\([^ ][^ ]*\)/SEARCH_DIR(\1);/g'`
  67.  
  68. # Generate 5 or 6 script files from a master script template in
  69. # ${srcdir}/scripttempl/${SCRIPT_NAME}.sh.  Which one of the 5 or 6
  70. # script files is actually used depends on command line options given
  71. # to ld.  (SCRIPT_NAME was set in the emulparams_file.)
  72. #
  73. # A .x script file is the default script.
  74. # A .xr script is for linking without relocation (-r flag).
  75. # A .xu script is like .xr, but *do* create constructors (-Ur flag).
  76. # A .xn script is for linking with -n flag (mix text and data on same page).
  77. # A .xbn script is for linking with -N flag (mix text and data on same page).
  78. # A .xs script is for generating a shared library with the --shared
  79. #   flag; it is only generated if $GENERATE_SHLIB_SCRIPT is set by the
  80. #   emulation parameters.
  81.  
  82. SEGMENT_SIZE=${SEGMENT_SIZE-${TARGET_PAGE_SIZE}}
  83.  
  84. # Determine DATA_ALIGNMENT for the 5 variants, using
  85. # values specified in the emulparams/<emulation>.sh file or default.
  86.  
  87. DATA_ALIGNMENT_="${DATA_ALIGNMENT_-${DATA_ALIGNMENT-ALIGN(${SEGMENT_SIZE})}}"
  88. DATA_ALIGNMENT_n="${DATA_ALIGNMENT_n-${DATA_ALIGNMENT_}}"
  89. DATA_ALIGNMENT_N="${DATA_ALIGNMENT_N-${DATA_ALIGNMENT-.}}"
  90. DATA_ALIGNMENT_r="${DATA_ALIGNMENT_r-${DATA_ALIGNMENT-}}"
  91. DATA_ALIGNMENT_u="${DATA_ALIGNMENT_u-${DATA_ALIGNMENT_r}}"
  92.  
  93. LD_FLAG=r
  94. DATA_ALIGNMENT=${DATA_ALIGNMENT_r}
  95. DEFAULT_DATA_ALIGNMENT="ALIGN(${SEGMENT_SIZE})"
  96. (. ${srcdir}/scripttempl/${SCRIPT_NAME}.sc) | sed -e '/^ *$/d' > \
  97.   ldscripts/${EMULATION_NAME}.xr
  98.  
  99. LD_FLAG=u
  100. DATA_ALIGNMENT=${DATA_ALIGNMENT_u}
  101. CONSTRUCTING=" "
  102. (. ${srcdir}/scripttempl/${SCRIPT_NAME}.sc) | sed -e '/^ *$/d' > \
  103.   ldscripts/${EMULATION_NAME}.xu
  104.  
  105. LD_FLAG=
  106. DATA_ALIGNMENT=${DATA_ALIGNMENT_}
  107. RELOCATING=" "
  108. (. ${srcdir}/scripttempl/${SCRIPT_NAME}.sc) | sed -e '/^ *$/d' > \
  109.   ldscripts/${EMULATION_NAME}.x
  110.  
  111. LD_FLAG=n
  112. DATA_ALIGNMENT=${DATA_ALIGNMENT_n}
  113. TEXT_START_ADDR=${NONPAGED_TEXT_START_ADDR-${TEXT_START_ADDR}}
  114. (. ${srcdir}/scripttempl/${SCRIPT_NAME}.sc) | sed -e '/^ *$/d' > \
  115.   ldscripts/${EMULATION_NAME}.xn
  116.  
  117. LD_FLAG=N
  118. DATA_ALIGNMENT=${DATA_ALIGNMENT_N}
  119. (. ${srcdir}/scripttempl/${SCRIPT_NAME}.sc) | sed -e '/^ *$/d' > \
  120.   ldscripts/${EMULATION_NAME}.xbn
  121.  
  122. if test -n "$GENERATE_SHLIB_SCRIPT"; then
  123.   LD_FLAG=shared
  124.   DATA_ALIGNMENT=${DATA_ALIGNMENT_s-${DATA_ALIGNMENT_}}
  125.   CREATE_SHLIB=" "
  126.   # Note that TEXT_START_ADDR is set to NONPAGED_TEXT_START_ADDR.
  127.   (. ${srcdir}/scripttempl/${SCRIPT_NAME}.sc) | sed -e '/^ *$/d' > \
  128.     ldscripts/${EMULATION_NAME}.xs
  129. fi
  130.  
  131. test "$DEFAULT_EMULATION" = "$EMULATION_NAME" && COMPILE_IN=true
  132.  
  133. # Generate em_${EMULATION_NAME}.c.
  134. . ${srcdir}/emultempl/${TEMPLATE_NAME-generic}.em
  135.