pkgmaker 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. cd "$(dirname "$0")"
  2. export TOPDIR=$(realpath ..)
  3. if gmake --help >/dev/null 2>&1; then
  4. export GMAKE=gmake
  5. else
  6. export GMAKE=make
  7. fi
  8. (( x_cols = (COLUMNS > 10) ? COLUMNS - 2 : 80 ))
  9. typeset -L$x_cols pbar
  10. # build a cache of “ipkg package name” → “package conf option” for
  11. # use with dependency resolution
  12. rm -rf pkglist.d
  13. mkdir pkglist.d
  14. for dn in */Makefile; do
  15. dn=${dn%/*}
  16. pbar="Pass 1: $dn ..."
  17. print -nu2 "$pbar\r"
  18. cd $dn
  19. # ALL_PKGOPTS: all subpackage conf options
  20. # PKGNAME_*: subpackage (ipkg) package name, by subpackage option
  21. eval $($GMAKE dump="ALL_PKGOPTS \
  22. \$(foreach x,\${ALL_PKGOPTS},PKGNAME_\${x})")
  23. cd ..
  24. if [[ -z $ALL_PKGOPTS ]]; then
  25. print -u2 "Warning: $dn/Makefile contains no packages, skipped"
  26. continue
  27. fi
  28. for spcu in $ALL_PKGOPTS; do # spcu: package option, ucase
  29. eval sppn=\$PKGNAME_$spcu # sppn: subpackage (ipkg) name
  30. # once mksh R40 is out, use its new associative arrays here!
  31. print -r -- "$spcu" >pkglist.d/"$sppn"
  32. done
  33. done
  34. # build Config.in files and resolve dependencies
  35. for dn in */Makefile; do
  36. dn=${dn%/*}
  37. # skip if we take care of this one manually
  38. [[ -s $dn/Config.in.manual ]] && continue
  39. pbar="Pass 2: $dn ..."
  40. print -nu2 "$pbar\r"
  41. cd $dn
  42. # PKG_NAME: package name (directory, free-format)
  43. # PKG_FLAVOURS: all package flavours (boolean options), uppercase
  44. # PKG_DESCR: package description (directory)
  45. # PKG_URL: package homepage
  46. # PKG_CXX: uppercase varname part to use for CFrustFrust checks
  47. # ALL_PKGOPTS: all subpackage conf options
  48. # PKGNAME_*: subpackage (ipkg) package name, by subpackage option
  49. # PKGDESC_*: subpackage description, by subpackage option
  50. # PKGDEPS_*: subpackage depends on ipkg packages, by subpkg option
  51. # CFLINE_*: one free-format Config.in line per subpackage option
  52. # PKGFD_*: flavour description, per package flavour option
  53. eval $($GMAKE dump="PKG_NAME PKG_FLAVOURS PKG_DESCR PKG_URL PKG_CXX \
  54. ALL_PKGOPTS \$(foreach x,\${ALL_PKGOPTS},PKGNAME_\${x} \
  55. PKGDESC_\${x} PKGDEPS_\${x} CFLINE_\${x}) \
  56. \$(foreach x,\${PKG_FLAVOURS},PKGFD_\${x})")
  57. # dnu: directory name, uppercase, y/-+/_X/
  58. typeset -u dnu=${dn//-/_}
  59. dnu=${dnu//+/X}
  60. ( # fd 4 = Config.in; fd 5 = Config.in.lib
  61. g5=0
  62. # Handle master package (directory)
  63. print -u4 "config ADK_COMPILE_$dnu"
  64. if [[ -z $ALL_PKGOPTS ]]; then
  65. # pseudo package, does not produce an ipkg package
  66. ppnf=$PKG_NAME # ppnf: pseudopkg name, filled
  67. if [[ -n $PKG_DESCR ]]; then
  68. while (( ${#ppnf} < 34 )); do
  69. ppnf=$ppnf.
  70. done
  71. ppnf="$ppnf $PKG_DESCR"
  72. fi
  73. print -u4 "\tprompt \"$ppnf\""
  74. fi
  75. print -u4 \\ttristate
  76. if [[ -n $ALL_PKGOPTS ]]; then
  77. # real (master) package, contains 1+ ipkg (sub)packages
  78. print -nu4 \\tdepends on
  79. sp=' ' # local sp: space (or ' || ')
  80. for spcu in $ALL_PKGOPTS; do # spcu: package option, ucase
  81. print -nu4 "${sp}ADK_PACKAGE_$spcu"
  82. sp=' || '
  83. done
  84. print -u4
  85. fi
  86. print -u4 \\tdefault n
  87. # Handle subpackages / multipackages
  88. for spcu in $ALL_PKGOPTS; do # spcu: package option, ucase
  89. eval sppn=\$PKGNAME_$spcu # sppn: subpackage (ipkg) name
  90. eval desc=\$PKGDESC_$spcu # desc: subpackage description
  91. : ${desc:=$PKG_DESCR} # take from main pkg if empty
  92. eval deps=\$PKGDEPS_$spcu # deps: subpackage dependencies
  93. eval xline=\$CFLINE_$spcu # xline: one free-format line
  94. if [[ $spcu = LIB* ]]; then
  95. h=5 # divert to Config.in.lib
  96. (( g5++ )) && print -u5 # been here before
  97. else
  98. h=4 # divert to Config.in
  99. print -u4
  100. fi
  101. print -u$h config ADK_PACKAGE_$spcu
  102. spnf=$sppn # spnf: subpackage name, filled
  103. if [[ -n ${desc:-$PKG_NAME} ]]; then
  104. while (( ${#spnf} < 34 )); do
  105. spnf=$spnf.
  106. done
  107. spnf="$spnf ${desc:-$PKG_NAME}"
  108. fi
  109. print -u$h "\tprompt \"$spnf\""
  110. print -u$h \\ttristate
  111. print -u$h \\tdefault n
  112. for dep in $deps; do # dep: ipkg name of one rundep.
  113. # skip dependencies on uclibc++ and libstdcxx iff
  114. # we produce these automatically
  115. [[ -n $PKG_CXX && $dep = @(uclibc++|libstdcxx) ]] && \
  116. continue
  117. case $dep {
  118. (kmod-*)
  119. # produce dependency on kernel package
  120. # which have special name→sym mangling
  121. typeset -u udep=${dep//-/_}
  122. print -u$h "\tselect ADK_KPACKAGE_$udep"
  123. ;;
  124. (*)
  125. # produce dependency on regular package
  126. # where the symbol is cached (see above)
  127. print -u$h '\tselect' \
  128. ADK_PACKAGE_$(<../pkglist.d/"$dep")
  129. ;;
  130. }
  131. done
  132. print -u$h \\tselect ADK_COMPILE_$dnu
  133. [[ -n $xline ]] && print -u$h "\t$xline"
  134. if [[ -n $desc$PKG_URL ]]; then
  135. # produce (optional) help text
  136. print -u$h \\thelp
  137. [[ -n $desc ]] && print -u$h "\t $desc"
  138. [[ -n $desc && -n $PKG_URL ]] && print -u$h '\t '
  139. [[ -n $PKG_URL ]] && print -u$h "\t WWW: $PKG_URL"
  140. fi
  141. done
  142. # Handle CFrustFrust library selection, if necessary
  143. [[ -n $PKG_CXX ]] && cat >&4 <<EOF
  144. choice
  145. prompt "C++ library to use"
  146. depends on ADK_COMPILE_$dnu
  147. default ADK_COMPILE_${PKG_CXX}_WITH_STDCXX if ADK_TARGET_LIB_GLIBC || ADK_TARGET_LIB_EGLIBC
  148. default ADK_COMPILE_${PKG_CXX}_WITH_UCLIBCXX if ADK_TARGET_LIB_UCLIBC
  149. config ADK_COMPILE_${PKG_CXX}_WITH_STDCXX
  150. bool "GNU C++ library"
  151. select ADK_PACKAGE_LIBSTDCXX
  152. config ADK_COMPILE_${PKG_CXX}_WITH_UCLIBCXX
  153. bool "uClibc++ library"
  154. select ADK_PACKAGE_UCLIBCXX
  155. endchoice
  156. EOF
  157. # Handle flavours (per directory)
  158. for pfcu in $PKG_FLAVOURS; do # pfcu: pkg flavour conf opt.
  159. eval pfd=\$PKGFD_$pfcu # pfd: pkg flavour description
  160. print
  161. print config ADK_PACKAGE_${dnu}_$pfcu
  162. print "\tbool \"${pfd:-$PKG_NAME -> flavour $pfcu}\""
  163. print \\tdefault n
  164. print \\tdepends on ADK_COMPILE_$dnu
  165. print \\thelp
  166. print "\t flavour ADK_PACKAGE_${dnu}_$pfcu for $PKG_NAME"
  167. done >&4
  168. ) 4>Config.in 5>Config.in.lib
  169. cd ..
  170. done
  171. pbar=done
  172. print -u2 "$pbar"