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.

176 lines
4.3 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/Create-DepDB
  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. cachedir="package"
  25. descdir="package"
  26. debug=''
  27. while [ "$1" ] ; do
  28. case "$1" in
  29. -cachedir)
  30. cachedir=$2 ; shift ; shift ;;
  31. -descdir)
  32. descdir=$2 ; shift ; shift ;;
  33. -debug)
  34. debug=$2 ; shift ; shift ;;
  35. *)
  36. echo "Usage: $0 [ -cachedir cachedir ] [ -descdir descdir ] \\"
  37. echo " ${0//?/ } [ -debug pkg ] > filename"
  38. exit 1 ;;
  39. esac
  40. done
  41. echo -n "Creating dependency database ..." >&2
  42. sedscript1=`mktemp` ; sedscript2=`mktemp`
  43. while read package command args
  44. do
  45. package=${package%.desc:*}
  46. package=${package##*/} ; set -- $args
  47. case "$command" in
  48. group)
  49. echo -e "/^$package\$/ a \\\\\n$*" >> $sedscript1
  50. echo -e "/^$*\$/ a \\\\\n$package" >> $sedscript2
  51. esac
  52. done < <( egrep '^\[(E|DEP|DEPENDENCY)\]' $descdir/*/*/*.desc )
  53. if [ -f create_depdb.cache ] ; then
  54. cat create_depdb.cache
  55. else
  56. for x in $cachedir/*/*/*.cache ; do
  57. y=${x%/*.cache} ; y=${y##*/}
  58. z=${x%/*/*.cache} ; z=${z##*/}
  59. priority=$( egrep '^\[(P|PRI|PRIORITY)\] ' \
  60. $descdir/$z/$y/$y.desc | \
  61. tr '\t' ' ' | tr -s ' ' | cut -f3,4 -d' ' | \
  62. sed 's,9 , ,; s,-,,g; s,.*\(.\) ,\1.,' )
  63. buildtime=$( grep '^\[BUILDTIME\] ' $x | cut -f2 -d' ' )
  64. [ "$buildtime" ] || continue
  65. deps=$( grep '^\[DEP\] ' $x | cut -f2- -d' ' | tr ' ' '\n' | \
  66. sed -f $sedscript1 | sed -f $sedscript2 | \
  67. sort -u | grep -vx $y )
  68. echo $y $buildtime $priority $deps $y
  69. done | if [ "$debug" ] ; then tee create_depdb.cache ; else cat ; fi
  70. fi | gawk '
  71. function getpri(package) {
  72. datafile="'$tmp1'";
  73. delete todo;
  74. delete done;
  75. todo[ package ] = 1;
  76. returncode=0;
  77. endloop=0;
  78. level=0;
  79. if (debug != "") {
  80. print "";
  81. print "Creating priority for " package " ...";
  82. }
  83. while ( ! endloop ) {
  84. endloop=1; level++;
  85. for (pkg in todo) {
  86. endloop=0;
  87. delete todo[pkg];
  88. done[pkg] = 1;
  89. firstdebug=1;
  90. for (nextpkg in database) {
  91. if ( index(database[nextpkg], " " pkg " ") ) {
  92. if ( ! (nextpkg in done) &&
  93. ! (nextpkg in todo) &&
  94. ! (nextpkg in ignore) ) {
  95. if ("x" orderdb[nextpkg] < "x" orderdb[pkg]) {
  96. if (debug != "") {
  97. if (firstdebug)
  98. print "\n\t(" level ") Found " \
  99. "dependencies for " pkg ":";
  100. print "\t\t" pkg ": " \
  101. "required by " nextpkg \
  102. " (ignore reverse dep)";
  103. firstdebug=0;
  104. }
  105. } else {
  106. if (debug != "") {
  107. if (firstdebug)
  108. print "\n\t(" level ") Found " \
  109. "dependencies for " pkg ":";
  110. print "\t\t" pkg ": " \
  111. "required by " nextpkg;
  112. firstdebug=0;
  113. }
  114. todo[nextpkg] = 1;
  115. returncode++;
  116. }
  117. }
  118. }
  119. }
  120. }
  121. }
  122. return returncode;
  123. }
  124. BEGIN {
  125. counter=0;
  126. debug="'$debug'";
  127. }
  128. {
  129. orderdb[$1]=$3; $3=0;
  130. database[$1]=$0;
  131. if (NF > 102) {
  132. printf "\rPackage %s has %d dependencies. I don'\''t " \
  133. "believe this.\n", $1, NF - 3 > "/dev/stderr";
  134. ignore[$1] = 1;
  135. }
  136. counter++;
  137. }
  138. END {
  139. if (debug != "") {
  140. pri=getpri(debug);
  141. print "\nResulting Priority: " pri;
  142. } else {
  143. for (package in database) {
  144. printf "\rCreating dependency database (" \
  145. counter ") ... \b" > "/dev/stderr";
  146. $0 = database[package]; $3 = getpri(package);
  147. $1 = $1 ":"; print; counter--;
  148. }
  149. print "\rCreating dependency database ... " \
  150. "done." > "/dev/stderr";
  151. }
  152. }
  153. ' | if [ "$debug" ] ; then cat ; else sort ; fi
  154. rm -f $sedscript1
  155. rm -f $sedscript2