mirror of the now-defunct rocklinux.org
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

297 lines
9.6 KiB

  1. #!/bin/bash
  2. #
  3. # --- ROCK-COPYRIGHT-NOTE-BEGIN ---
  4. #
  5. # This copyright note is auto-generated by ./scripts/Create-CopyPatch.
  6. # Please add additional copyright information _after_ the line containing
  7. # the ROCK-COPYRIGHT-NOTE-END tag. Otherwise it might get removed by
  8. # the ./scripts/Create-CopyPatch script. Do not edit this copyright text!
  9. #
  10. # ROCK Linux: rock-src/scripts/Build-Tools
  11. # ROCK Linux is Copyright (C) 1998 - 2003 Clifford Wolf
  12. #
  13. # This program is free software; you can redistribute it and/or modify
  14. # it under the terms of the GNU General Public License as published by
  15. # the Free Software Foundation; either version 2 of the License, or
  16. # (at your option) any later version. A copy of the GNU General Public
  17. # License can be found at Documentation/COPYING.
  18. #
  19. # Many people helped and are helping developing ROCK Linux. Please
  20. # have a look at http://www.rocklinux.org/ and the Documentation/TEAM
  21. # file for details.
  22. #
  23. # --- ROCK-COPYRIGHT-NOTE-END ---
  24. config=default
  25. stagelevel=9
  26. cleanup=0
  27. while [ "$1" ] ; do
  28. case "$1" in
  29. -cleanup) cleanup=1 ; shift ;;
  30. -cfg) config=$2 ; shift ; shift ;;
  31. -[0-9]) options="$options $1" ; stagelevel=${1#-} ; shift ;;
  32. *) echo "Usage: $0 [ -cfg config ] [ -0 | -9 ] \\"
  33. echo " ${0//?/ } [ -cleanup ]" ; exit 1 ;;
  34. esac
  35. done
  36. . ./scripts/parse-config
  37. . ./scripts/functions
  38. var_remove PATH ":" $base/build/$ROCKCFG_ID/$toolsdir/bin
  39. var_remove PATH ":" $base/build/$ROCKCFG_ID/$toolsdir/wrapper
  40. mkdir -p build/$ROCKCFG_ID/$toolsdir/bin
  41. mkdir -p build/$ROCKCFG_ID/$toolsdir/wrapper
  42. mkdir -p build/$ROCKCFG_ID/$toolsdir/lib
  43. if [ $toolsdir = tools.cross ]; then
  44. mkdir -p build/$ROCKCFG_ID/$toolsdir/{var/adm,etc,share,include}
  45. [ -L build/$ROCKCFG_ID/$toolsdir/usr ] ||
  46. ln -s . build/$ROCKCFG_ID/$toolsdir/usr
  47. [ -L build/$ROCKCFG_ID/$toolsdir/sbin ] ||
  48. ln -s bin build/$ROCKCFG_ID/$toolsdir/sbin
  49. [ -L build/$ROCKCFG_ID/$toolsdir/var/adm/logs ] ||
  50. ln -s ../../../root/var/adm/logs \
  51. build/$ROCKCFG_ID/$toolsdir/var/adm/logs
  52. mkdir -p build/$ROCKCFG_ID/root/var/adm/logs
  53. fi
  54. x="$( bash scripts/xfind.sh config/$config/. package/. scripts/. \
  55. misc/. architecture/. target/. ! -name '*.cache' \
  56. -newer build/$ROCKCFG_ID/$toolsdir/.lastupdate \
  57. -printf 'Found new/updated file: %p\n' 2> /dev/null )"
  58. if [ "$x" ] ; then
  59. echo_header Found $( echo "$x" | wc -l ) new/updated \
  60. files in source tree:
  61. echo "$x" | head -3 | sed 's,/\./,/,g' |
  62. while read y ; do echo_status $y ; done
  63. [ "$( echo "$x" | tail +4 )" ] &&
  64. echo_status "** list truncated to save space on the terminal **"
  65. if [ "$ROCK_DEBUG_TOOLS_SKIP" = 1 ]; then
  66. echo_error "Found \$ROCK_DEBUG_TOOLS_SKIP ..."
  67. else
  68. rm -f build/$ROCKCFG_ID/$toolsdir/.lastupdate
  69. if echo "$x" | grep -qv " config/$config/" ; then
  70. echo_header Re-running configuration:
  71. while read line ; do
  72. echo_status $line
  73. done < <( ./scripts/Config -cfg $config -oldconfig )
  74. fi
  75. fi
  76. fi
  77. if [ $cleanup = 1 ] ; then
  78. echo_header "Removing old stuff in $toolsdir/ directory ..."
  79. rm -f build/$ROCKCFG_ID/$toolsdir/wrapper/*
  80. rm -f build/$ROCKCFG_ID/$toolsdir/bin/getdu
  81. rm -f build/$ROCKCFG_ID/$toolsdir/bin/getfiles
  82. rm -f build/$ROCKCFG_ID/$toolsdir/bin/fl_wrparse
  83. rm -f build/$ROCKCFG_ID/$toolsdir/bin/fl_stparse
  84. rm -f build/$ROCKCFG_ID/$toolsdir/lib/fl_wrapper.so
  85. rm -f build/$ROCKCFG_ID/$toolsdir/lib/parse-config
  86. rm -f build/$ROCKCFG_ID/$toolsdir/.lastupdate
  87. fi
  88. if [ ! -f build/$ROCKCFG_ID/$toolsdir/.lastupdate ] ; then
  89. echo_header "Building tools in build/.../$toolsdir:"
  90. # CC, CXX, F77 and KCC Wrapper
  91. #
  92. wrappers="cmd_wrapper" ; wrappervars=""
  93. echo_status "Building $toolsdir/wrapper/cmd_wrapper."
  94. $BUILDCC -Wall -O2 misc/tools-source/cmd_wrapper.c \
  95. -DENVPREFIX='"CMD"' -DMYNAME='"cmd_wrapper"' \
  96. -o build/$ROCKCFG_ID/$toolsdir/wrapper/tmp.$$ || exit 1
  97. mv build/$ROCKCFG_ID/$toolsdir/wrapper/tmp.$$ \
  98. build/$ROCKCFG_ID/$toolsdir/wrapper/cmd_wrapper
  99. #
  100. build_wrapper() {
  101. local x="$( echo ${1//,/ } )" y z
  102. wrappervars="$wrappervars $x"
  103. while shift ; [ $# != 0 ]
  104. do
  105. wrappers="$wrappers $1"
  106. tmp=`mktemp -p build/$ROCKCFG_ID/$toolsdir/wrapper`
  107. {
  108. echo '#!/bin/bash'
  109. for y in $x ; do
  110. echo -n "[ \"\$${y}_WRAPPER_DEBUG\" = 1 ] && "
  111. echo "export CMD_WRAPPER_DEBUG=1"
  112. done
  113. for y in $x ; do
  114. echo -n "[ \"\$${y}_WRAPPER_BYPASS\" = 1 ] && "
  115. echo "export CMD_WRAPPER_BYPASS=1"
  116. done
  117. z=""; echo -n 'export CMD_WRAPPER_APPEND_PO="'
  118. for y in $x; do
  119. echo -n "${z}\$${y}_WRAPPER_APPEND_PO"; z=" "
  120. done ; echo '"'
  121. z=""; echo -n 'export CMD_WRAPPER_OTHERS="'
  122. for y in $x; do
  123. echo -n "${z}\$${y}_WRAPPER_OTHERS"; z=":"
  124. done ; echo '"'
  125. z=""; echo -n 'export CMD_WRAPPER_INSERT="'
  126. for y in $x; do
  127. echo -n "${z}\$${y}_WRAPPER_INSERT"; z=" "
  128. done ; echo '"'
  129. z=""; echo -n 'export CMD_WRAPPER_REMOVE="'
  130. for y in $x; do
  131. echo -n "${z}\$${y}_WRAPPER_REMOVE"; z=" "
  132. done ; echo '"'
  133. z=""; echo -n 'export CMD_WRAPPER_APPEND="'
  134. for y in $x; do
  135. echo -n "${z}\$${y}_WRAPPER_APPEND"; z=" "
  136. done ; echo '"'
  137. z=""; echo -n 'export CMD_WRAPPER_FILTER="'
  138. for y in $x; do
  139. echo -n "${z}\$${y}_WRAPPER_FILTER"; z="|"
  140. done ; echo '"'
  141. echo 'exec cmd_wrapper $( basename $0 ) "$@"'
  142. } > $tmp
  143. chmod +rx $tmp
  144. mv $tmp "build/$ROCKCFG_ID/$toolsdir/wrapper/$1"
  145. done
  146. }
  147. #
  148. while read script ; do . $script
  149. done < <( bash scripts/xfind.sh package/. target/$target/. misc/. -name 'wrappers.in' )
  150. #
  151. echo_status "Building $toolsdir/wrapper/strip_wrapper."
  152. cat << 'EOT' > build/$ROCKCFG_ID/$toolsdir/wrapper/strip_wrapper.$$
  153. #!/bin/sh
  154. if [ "$STRIP_WRAPPER_NOLOOP" = 1 ] ; then
  155. echo "Aaaaaeik! Strip wrapper is looping!" >&2
  156. exit 1
  157. fi
  158. if [ "$ROCKCFG_OPT" = 1 ] ; then
  159. PATH=${PATH//$STRIP_WRAPPER_MYPATH:/}
  160. export STRIP_WRAPPER_NOLOOP=1
  161. exec "`basename $0`" "$@"
  162. fi
  163. exit 0
  164. EOT
  165. chmod +x build/$ROCKCFG_ID/$toolsdir/wrapper/strip_wrapper.$$
  166. mv build/$ROCKCFG_ID/$toolsdir/wrapper/strip_wrapper.$$ \
  167. build/$ROCKCFG_ID/$toolsdir/wrapper/strip_wrapper
  168. wrappers="$wrappers strip_wrapper"
  169. #
  170. for x in strip $arch_target-strip ; do
  171. [ $crossnative = cross -a $x = strip ] && continue
  172. if [ -x "`type -p $x`" ] ; then
  173. ln -sf strip_wrapper \
  174. build/$ROCKCFG_ID/$toolsdir/wrapper/$x
  175. wrappers="$wrappers $x"
  176. fi
  177. done
  178. #
  179. echo_status "Building $toolsdir/wrapper/install_wrapper."
  180. cp misc/tools-source/install_wrapper.sh build/$ROCKCFG_ID/$toolsdir/wrapper/install_wrapper
  181. chmod +x build/$ROCKCFG_ID/$toolsdir/wrapper/install_wrapper
  182. ln -sf install_wrapper build/$ROCKCFG_ID/$toolsdir/wrapper/install
  183. ln -sf install_wrapper build/$ROCKCFG_ID/$toolsdir/wrapper/cp
  184. ln -sf install_wrapper build/$ROCKCFG_ID/$toolsdir/wrapper/ln
  185. ln -sf install_wrapper build/$ROCKCFG_ID/$toolsdir/wrapper/mv
  186. wrappers="$wrappers install_wrapper install cp ln mv"
  187. #
  188. for x in $( ls build/$ROCKCFG_ID/$toolsdir/wrapper/ )
  189. do
  190. z=0
  191. for y in $wrappers ; do
  192. [ "$x" = "$y" ] && z=1
  193. done
  194. if [ "$z" = 0 ] ; then
  195. rm -f build/$ROCKCFG_ID/$toolsdir/wrapper/$x
  196. fi
  197. done
  198. # Various small tools
  199. #
  200. for x in getdu getfiles fl_wrparse fl_stparse ; do
  201. echo_status "Building $toolsdir/bin/$x."
  202. $BUILDCC -Wall -O2 misc/tools-source/$x.c \
  203. -o build/$ROCKCFG_ID/$toolsdir/bin/$x.$$ || exit 1
  204. mv build/$ROCKCFG_ID/$toolsdir/bin/$x.$$ \
  205. build/$ROCKCFG_ID/$toolsdir/bin/$x
  206. done
  207. # Flist Wrapper Library
  208. #
  209. if [ "$ROCKCFG_FLIST" = "flwrapper" ] ; then
  210. echo_status "Building $toolsdir/lib/fl_wrapper.so."
  211. $BUILDCC -Wall -O2 -ldl -shared misc/tools-source/fl_wrapper.c \
  212. -o build/$ROCKCFG_ID/$toolsdir/lib/fl_wrapper.so.$$ || exit 1
  213. mv build/$ROCKCFG_ID/$toolsdir/lib/fl_wrapper.so.$$ \
  214. build/$ROCKCFG_ID/$toolsdir/lib/fl_wrapper.so
  215. echo_status "Testing $toolsdir/lib/fl_wrapper.so."
  216. if ! sh -c "LD_PRELOAD=\"\$LD_PRELOAD:build/\$ROCKCFG_ID/`
  217. `$toolsdir/lib/fl_wrapper.so\" date ; `
  218. `exit $?" >/dev/null 2>&1
  219. then
  220. echo_error "Detected a problem with the flist" \
  221. "wrapper lib on your system."
  222. echo_error "Please specify another flist-creation" \
  223. "system in your build configuration."
  224. rm -f build/$ROCKCFG_ID/$toolsdir/lib/fl_wrapper.so
  225. echo ; exit 1
  226. fi
  227. fi
  228. # Create Parse-Config Collection
  229. #
  230. echo_status "Creating $toolsdir/lib/parse-config."
  231. bash scripts/xfind.sh \
  232. architecture/$arch/. package/. target/$target/. misc/ -type f \
  233. '(' -name 'parse-config' -o -name 'parse-config-*' ')' \
  234. '(' ! -name 'parse-config-x' -o ! -name 'parse-config-*-x' ')' \
  235. '(' ! -name '*~' ')' \
  236. -printf '%f\t%p\n' | sort | awk '{ $1="."; print; }' \
  237. > build/$ROCKCFG_ID/$toolsdir/lib/parse-config.$$
  238. mv build/$ROCKCFG_ID/$toolsdir/lib/parse-config.$$ \
  239. build/$ROCKCFG_ID/$toolsdir/lib/parse-config
  240. # Create pkg_*_{pre,post}.conf files
  241. #
  242. rm -f build/$ROCKCFG_ID/$toolsdir/lib/pkg_*_{pre,post}.conf
  243. echo_status "Creating $toolsdir/lib/pkg_*_{pre,post}.conf"
  244. for x in `grep "^X" config/$config/packages | cut -d ' ' -f 4,5 | tr ' ' '/'`; do
  245. for y in `echo package/$x/pkg_*_{pre,post}.conf`; do
  246. if [ -f $y ]; then
  247. echo " . $y" >> build/$ROCKCFG_ID/$toolsdir/lib/${y##*/}
  248. fi
  249. done
  250. done
  251. echo -e "${wrappervars// /\n}" | grep . | sort -u |
  252. while read x ; do
  253. echo "export ${x}_WRAPPER_DEBUG=0 ${x}_WRAPPER_BYPASS=0"
  254. echo "export ${x}_WRAPPER_OTHERS='' ${x}_WRAPPER_REMOVE=''"
  255. echo "export ${x}_WRAPPER_INSERT='' ${x}_WRAPPER_APPEND=''"
  256. echo "export ${x}_WRAPPER_FILTER='' ${x}_WRAPPER_APPEND_PO=''"
  257. done > build/$ROCKCFG_ID/$toolsdir/lib/wrapper-config.$$
  258. mv build/$ROCKCFG_ID/$toolsdir/lib/wrapper-config.$$ \
  259. build/$ROCKCFG_ID/$toolsdir/lib/wrapper-config
  260. touch build/$ROCKCFG_ID/$toolsdir/.lastupdate
  261. fi
  262. exit 0