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.

322 lines
11 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 ; echo "Usage: $0 [ -cfg <config> ] [ -0 | -1 | ... | -9 ] \\"
  33. echo " ${0//?/ } [ -cleanup ]"
  34. echo
  35. echo " Create various helper applications needed by Build-Pkg and other scripts."
  36. echo
  37. echo " -cfg <config> the configuration to use"
  38. echo " -0 to -9 set stagelevel"
  39. echo " -cleanup force a rebuild of files"
  40. echo ; exit 1 ;;
  41. esac
  42. done
  43. . ./scripts/parse-config
  44. . ./scripts/functions
  45. var_remove PATH ":" $base/build/$ROCKCFG_ID/ROCK/$toolsdir/bin
  46. var_remove PATH ":" $base/build/$ROCKCFG_ID/ROCK/$toolsdir/wrapper
  47. mkdir -p build/$ROCKCFG_ID/ROCK/$toolsdir/bin
  48. mkdir -p build/$ROCKCFG_ID/ROCK/$toolsdir/wrapper
  49. mkdir -p build/$ROCKCFG_ID/ROCK/$toolsdir/lib
  50. if [ $toolsdir = tools.cross ]; then
  51. mkdir -p build/$ROCKCFG_ID/ROCK/$toolsdir/{var/adm,etc,share,include}
  52. [ -L build/$ROCKCFG_ID/ROCK/$toolsdir/usr ] ||
  53. ln -s . build/$ROCKCFG_ID/ROCK/$toolsdir/usr
  54. [ -L build/$ROCKCFG_ID/ROCK/$toolsdir/sbin ] ||
  55. ln -s bin build/$ROCKCFG_ID/ROCK/$toolsdir/sbin
  56. [ -L build/$ROCKCFG_ID/ROCK/$toolsdir/var/adm/logs ] ||
  57. ln -s ../../../../var/adm/logs \
  58. build/$ROCKCFG_ID/ROCK/$toolsdir/var/adm/logs
  59. mkdir -p build/$ROCKCFG_ID/var/adm/logs
  60. fi
  61. x="$( bash scripts/xfind.sh config/$config/. package/. scripts/. \
  62. misc/. architecture/. target/. ! -name '*.cache' \
  63. -newer build/$ROCKCFG_ID/ROCK/$toolsdir/.lastupdate \
  64. -printf 'Found new/updated file: %p\n' 2> /dev/null )"
  65. if [ "$x" ] ; then
  66. echo_header Found $( echo "$x" | wc -l ) new/updated \
  67. files in source tree:
  68. echo "$x" | head -n 3 | sed 's,/\./,/,g' |
  69. while read y ; do echo_status $y ; done
  70. [ "$( echo "$x" | tail -n +4 )" ] &&
  71. echo_status "** list truncated to save space on the terminal **"
  72. if [ "$ROCK_DEBUG_TOOLS_SKIP" = 1 ]; then
  73. echo_error "Found \$ROCK_DEBUG_TOOLS_SKIP ..."
  74. else
  75. rm -f build/$ROCKCFG_ID/ROCK/$toolsdir/.lastupdate
  76. if echo "$x" | grep -qv " config/$config/" ; then
  77. echo_header Re-running configuration:
  78. while read line ; do
  79. echo_status $line
  80. done < <( ./scripts/Config -cfg $config -oldconfig )
  81. fi
  82. fi
  83. fi
  84. if [ $cleanup = 1 ] ; then
  85. echo_header "Removing old stuff in $toolsdir/ directory ..."
  86. rm -f build/$ROCKCFG_ID/ROCK/$toolsdir/wrapper/*
  87. rm -f build/$ROCKCFG_ID/ROCK/$toolsdir/bin/getdu
  88. rm -f build/$ROCKCFG_ID/ROCK/$toolsdir/bin/getfiles
  89. rm -f build/$ROCKCFG_ID/ROCK/$toolsdir/bin/fl_wrparse
  90. rm -f build/$ROCKCFG_ID/ROCK/$toolsdir/bin/fl_stparse
  91. rm -f build/$ROCKCFG_ID/ROCK/$toolsdir/lib/fl_wrapper.so
  92. rm -f build/$ROCKCFG_ID/ROCK/$toolsdir/lib/parse-config
  93. rm -f build/$ROCKCFG_ID/ROCK/$toolsdir/lib/parse-config-fixarch
  94. rm -f build/$ROCKCFG_ID/ROCK/$toolsdir/.lastupdate
  95. fi
  96. if [ ! -f build/$ROCKCFG_ID/ROCK/$toolsdir/.lastupdate ] ; then
  97. echo_header "Building tools in build/.../ROCK/$toolsdir:"
  98. # CC, CXX, F77 and KCC Wrapper
  99. #
  100. wrappers="cmd_wrapper" ; wrappervars=""
  101. echo_status "Building $toolsdir/wrapper/cmd_wrapper."
  102. $BUILDCC -Wall -O2 misc/tools-source/cmd_wrapper.c \
  103. -DENVPREFIX='"CMD"' -DMYNAME='"cmd_wrapper"' \
  104. -o build/$ROCKCFG_ID/ROCK/$toolsdir/wrapper/tmp.$$ || exit 1
  105. mv build/$ROCKCFG_ID/ROCK/$toolsdir/wrapper/tmp.$$ \
  106. build/$ROCKCFG_ID/ROCK/$toolsdir/wrapper/cmd_wrapper
  107. #
  108. build_wrapper() {
  109. local x="$( echo ${1//,/ } )" y z
  110. wrappervars="$wrappervars $x"
  111. while shift ; [ $# != 0 ]
  112. do
  113. wrappers="$wrappers $1"
  114. tmp=`mktemp -p build/$ROCKCFG_ID/ROCK/$toolsdir/wrapper`
  115. {
  116. echo '#!/bin/bash'
  117. for y in $x ; do
  118. echo -n "[ \"\$${y}_WRAPPER_DEBUG\" = 1 ] && "
  119. echo "export CMD_WRAPPER_DEBUG=1"
  120. done
  121. for y in $x ; do
  122. echo -n "[ \"\$${y}_WRAPPER_BYPASS\" = 1 ] && "
  123. echo "export CMD_WRAPPER_BYPASS=1"
  124. done
  125. z=""; echo -n 'export CMD_WRAPPER_APPEND_PO="'
  126. for y in $x; do
  127. echo -n "${z}\$${y}_WRAPPER_APPEND_PO"; z=" "
  128. done ; echo '"'
  129. z=""; echo -n 'export CMD_WRAPPER_OTHERS="'
  130. for y in $x; do
  131. echo -n "${z}\$${y}_WRAPPER_OTHERS"; z=":"
  132. done ; echo '"'
  133. z=""; echo -n 'export CMD_WRAPPER_INSERT="'
  134. for y in $x; do
  135. echo -n "${z}\$${y}_WRAPPER_INSERT"; z=" "
  136. done ; echo '"'
  137. z=""; echo -n 'export CMD_WRAPPER_REMOVE="'
  138. for y in $x; do
  139. echo -n "${z}\$${y}_WRAPPER_REMOVE"; z=" "
  140. done ; echo '"'
  141. z=""; echo -n 'export CMD_WRAPPER_APPEND="'
  142. for y in $x; do
  143. echo -n "${z}\$${y}_WRAPPER_APPEND"; z=" "
  144. done ; echo '"'
  145. z=""; echo -n 'export CMD_WRAPPER_FILTER="'
  146. for y in $x; do
  147. echo -n "${z}\$${y}_WRAPPER_FILTER"; z="|"
  148. done ; echo '"'
  149. echo 'exec cmd_wrapper $( basename $0 ) "$@"'
  150. } > $tmp
  151. chmod +rx $tmp
  152. mv $tmp "build/$ROCKCFG_ID/ROCK/$toolsdir/wrapper/$1"
  153. done
  154. }
  155. #
  156. while read script ; do . $script
  157. done < <( bash scripts/xfind.sh package/. target/$target/. misc/. -name 'wrappers.in' )
  158. #
  159. echo_status "Building $toolsdir/wrapper/strip_wrapper."
  160. cat << EOT > build/$ROCKCFG_ID/ROCK/$toolsdir/wrapper/strip_wrapper.$$
  161. #!/bin/sh
  162. if [ "\$STRIP_WRAPPER_NOLOOP" = 1 ] ; then
  163. echo "Aaaaaeik! Strip wrapper is looping!" >&2
  164. exit 1
  165. fi
  166. if [ "\$ROCKCFG_DEBUG" = 0 ] ; then
  167. PATH=\${PATH//\$STRIP_WRAPPER_MYPATH:/}
  168. export STRIP_WRAPPER_NOLOOP=1
  169. exec "\$( basename \$0 )" "\$@"
  170. fi
  171. exit 0
  172. EOT
  173. chmod +x build/$ROCKCFG_ID/ROCK/$toolsdir/wrapper/strip_wrapper.$$
  174. mv build/$ROCKCFG_ID/ROCK/$toolsdir/wrapper/strip_wrapper.$$ \
  175. build/$ROCKCFG_ID/ROCK/$toolsdir/wrapper/strip_wrapper
  176. wrappers="$wrappers strip_wrapper"
  177. #
  178. for x in strip $arch_target-strip ; do
  179. [ $crossnative = cross -a $x = strip ] && continue
  180. if [ -x "`type -p $x`" ] ; then
  181. ln -sf strip_wrapper \
  182. build/$ROCKCFG_ID/ROCK/$toolsdir/wrapper/$x
  183. wrappers="$wrappers $x"
  184. fi
  185. done
  186. #
  187. echo_status "Building $toolsdir/wrapper/install_wrapper."
  188. cp misc/tools-source/install_wrapper.sh build/$ROCKCFG_ID/ROCK/$toolsdir/wrapper/install_wrapper
  189. chmod +x build/$ROCKCFG_ID/ROCK/$toolsdir/wrapper/install_wrapper
  190. ln -sf install_wrapper build/$ROCKCFG_ID/ROCK/$toolsdir/wrapper/install
  191. ln -sf install_wrapper build/$ROCKCFG_ID/ROCK/$toolsdir/wrapper/cp
  192. ln -sf install_wrapper build/$ROCKCFG_ID/ROCK/$toolsdir/wrapper/ln
  193. ln -sf install_wrapper build/$ROCKCFG_ID/ROCK/$toolsdir/wrapper/mv
  194. wrappers="$wrappers install_wrapper install cp ln mv"
  195. #
  196. for x in $( ls build/$ROCKCFG_ID/ROCK/$toolsdir/wrapper/ )
  197. do
  198. z=0
  199. for y in $wrappers ; do
  200. [ "$x" = "$y" ] && z=1
  201. done
  202. if [ "$z" = 0 ] ; then
  203. rm -f build/$ROCKCFG_ID/ROCK/$toolsdir/wrapper/$x
  204. fi
  205. done
  206. # Various small tools
  207. #
  208. for x in getdu getfiles fl_wrparse fl_stparse descparser; do
  209. echo_status "Building $toolsdir/bin/$x."
  210. $BUILDCC -Wall -O2 misc/tools-source/$x.c \
  211. -o build/$ROCKCFG_ID/ROCK/$toolsdir/bin/$x.$$ || exit 1
  212. mv build/$ROCKCFG_ID/ROCK/$toolsdir/bin/$x.$$ \
  213. build/$ROCKCFG_ID/ROCK/$toolsdir/bin/$x
  214. done
  215. # Flist Wrapper Library
  216. #
  217. if [ "$ROCKCFG_FLIST" = "flwrapper" ] ; then
  218. echo_status "Building $toolsdir/lib/fl_wrapper.so."
  219. $BUILDCC -Wall -O2 -ldl -fPIC -shared misc/tools-source/fl_wrapper.c \
  220. -o build/$ROCKCFG_ID/ROCK/$toolsdir/lib/fl_wrapper.so.$$ || exit 1
  221. mv build/$ROCKCFG_ID/ROCK/$toolsdir/lib/fl_wrapper.so.$$ \
  222. build/$ROCKCFG_ID/ROCK/$toolsdir/lib/fl_wrapper.so
  223. echo_status "Testing $toolsdir/lib/fl_wrapper.so."
  224. if ! sh -c "LD_PRELOAD=\"\$LD_PRELOAD:build/\$ROCKCFG_ID/`
  225. `$toolsdir/lib/fl_wrapper.so\" date ; `
  226. `exit $?" >/dev/null 2>&1
  227. then
  228. echo_error "Detected a problem with the flist" \
  229. "wrapper lib on your system."
  230. echo_error "Please specify another flist-creation" \
  231. "system in your build configuration."
  232. rm -f build/$ROCKCFG_ID/ROCK/$toolsdir/lib/fl_wrapper.so
  233. echo ; exit 1
  234. fi
  235. fi
  236. # Create Parse-Config Collection
  237. #
  238. echo_status "Creating $toolsdir/lib/parse-config."
  239. bash scripts/xfind.sh \
  240. architecture/$arch/. package/. target/$target/. misc/ -type f \
  241. '(' -name 'parse-config' -o -name 'parse-config-*' ')' \
  242. '(' ! -name 'parse-config-x' -o ! -name 'parse-config-*-x' ')' \
  243. '(' ! -name '*~' ')' \
  244. -printf '%f\t%p\n' | sort | awk '{ $1="."; print; }' \
  245. > build/$ROCKCFG_ID/ROCK/$toolsdir/lib/parse-config.$$
  246. mv build/$ROCKCFG_ID/ROCK/$toolsdir/lib/parse-config.$$ \
  247. build/$ROCKCFG_ID/ROCK/$toolsdir/lib/parse-config
  248. bash scripts/xfind.sh \
  249. architecture/$arch/. package/. target/$target/. misc/ -type f \
  250. -name 'parse-config-fixarch' \
  251. -printf '%f\t%p\n' | sort | awk '{ $1="."; print; }' \
  252. > build/$ROCKCFG_ID/ROCK/$toolsdir/lib/parse-config-fixarch.$$
  253. mv build/$ROCKCFG_ID/ROCK/$toolsdir/lib/parse-config-fixarch.$$ \
  254. build/$ROCKCFG_ID/ROCK/$toolsdir/lib/parse-config-fixarch
  255. # Create pkg_*_{pre,post}.conf files
  256. #
  257. rm -f build/$ROCKCFG_ID/ROCK/$toolsdir/lib/pkg_*_{pre,post}.conf
  258. echo_status "Creating $toolsdir/lib/pkg_*_{pre,post}.conf"
  259. for x in `grep "^X" config/$config/packages | cut -d ' ' -f 4,5 | tr ' ' '/'`; do
  260. for y in `echo package/$x/pkg_*_{pre,post}.conf`; do
  261. if [ -f $y ]; then
  262. echo " . $y" >> build/$ROCKCFG_ID/ROCK/$toolsdir/lib/${y##*/}
  263. fi
  264. done
  265. done
  266. # Create pkgmapper script
  267. #
  268. bash scripts/xfind.sh package/. -type f -name 'pkgmapper.in' \
  269. -printf '%f\t%p\n' | sort | awk '{ $1="."; print; }' \
  270. > build/$ROCKCFG_ID/ROCK/$toolsdir/lib/pkgmapper.$$
  271. mv build/$ROCKCFG_ID/ROCK/$toolsdir/lib/pkgmapper.$$ \
  272. build/$ROCKCFG_ID/ROCK/$toolsdir/lib/pkgmapper
  273. # Create cmd_wrapper config
  274. #
  275. echo -e "${wrappervars// /\n}" | grep . | sort -u |
  276. while read x ; do
  277. echo "export ${x}_WRAPPER_DEBUG=0 ${x}_WRAPPER_BYPASS=0"
  278. echo "export ${x}_WRAPPER_OTHERS='' ${x}_WRAPPER_REMOVE=''"
  279. echo "export ${x}_WRAPPER_INSERT='' ${x}_WRAPPER_APPEND=''"
  280. echo "export ${x}_WRAPPER_FILTER='' ${x}_WRAPPER_APPEND_PO=''"
  281. done > build/$ROCKCFG_ID/ROCK/$toolsdir/lib/wrapper-config.$$
  282. mv build/$ROCKCFG_ID/ROCK/$toolsdir/lib/wrapper-config.$$ \
  283. build/$ROCKCFG_ID/ROCK/$toolsdir/lib/wrapper-config
  284. touch build/$ROCKCFG_ID/ROCK/$toolsdir/.lastupdate
  285. fi
  286. exit 0