pkgmaker 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. unset MAKEFLAGS
  2. export MAKEFLAGS=s
  3. cd "$(dirname "$0")"
  4. export TOPDIR=$(realpath ..)
  5. if gmake --help >/dev/null 2>&1; then
  6. export GMAKE=gmake
  7. else
  8. export GMAKE=make
  9. fi
  10. GMAKE="$GMAKE --no-print-directory"
  11. (( x_cols = (COLUMNS > 10) ? COLUMNS - 2 : 80 ))
  12. typeset -L$x_cols pbar
  13. # build a cache of “ipkg package name” → “package conf option” for
  14. # use with dependency resolution
  15. rm -rf pkglist.d
  16. mkdir pkglist.d
  17. for dn in */Makefile; do
  18. dn=${dn%/*}
  19. pbar="Pass 1: $dn ..."
  20. print -nu2 "$pbar\r"
  21. cd $dn
  22. # ALL_PKGOPTS: all subpackage conf options
  23. # PKGNAME_*: subpackage (ipkg) package name, by subpackage option
  24. eval $($GMAKE dump="ALL_PKGOPTS \
  25. \$(foreach x,\${ALL_PKGOPTS},PKGNAME_\${x})")
  26. cd ..
  27. if [[ -z $ALL_PKGOPTS ]]; then
  28. #print -u2 "Warning: $dn/Makefile contains no packages, skipped"
  29. continue
  30. fi
  31. for spcu in $ALL_PKGOPTS; do # spcu: package option, ucase
  32. eval sppn=\$PKGNAME_$spcu # sppn: subpackage (ipkg) name
  33. # once mksh R40 is out, use its new associative arrays here!
  34. print -r -- "$spcu" >pkglist.d/"$sppn"
  35. done
  36. done
  37. # build Config.in files and resolve dependencies
  38. for dn in */Makefile; do
  39. dn=${dn%/*}
  40. # skip if we take care of this one manually
  41. [[ -s $dn/Config.in.manual ]] && continue
  42. pbar="Pass 2: $dn ..."
  43. print -nu2 "$pbar\r"
  44. cd $dn
  45. # PKG_NAME: package name (directory, free-format)
  46. # PKG_FLAVOURS: all package flavours (boolean options), uppercase
  47. # PKG_DESCR: package description (directory)
  48. # PKG_URL: package homepage
  49. # PKG_CXX: uppercase varname part to use for CFrustFrust checks
  50. # ALL_PKGOPTS: all subpackage conf options
  51. # PKGNAME_*: subpackage (ipkg) package name, by subpackage option
  52. # PKGDESC_*: subpackage description, by subpackage option
  53. # PKGDEPS_*: subpackage depends on ipkg packages, by subpkg option
  54. # PKGDFLT_*: subpackage 'default {:-n}', by subpackage option
  55. # CFLINE_*: one free-format Config.in line per subpackage option
  56. # PKGFD_*: flavour description, per package flavour option
  57. # PKG_{HOST,TARGET}_DEPENDS: add host or target dependencies
  58. eval $($GMAKE dump="PKG_NAME PKG_FLAVOURS PKG_DESCR PKG_URL PKG_MULTI PKG_CXX \
  59. ALL_PKGOPTS \$(foreach x,\${ALL_PKGOPTS},PKGNAME_\${x} \
  60. PKGDESC_\${x} PKGDEPS_\${x} PKGDFLT_\${x} CFLINE_\${x}) \
  61. \$(foreach x,\${PKG_FLAVOURS},PKGFD_\${x}) \
  62. PKG_HOST_DEPENDS PKG_TARGET_DEPENDS")
  63. # dnu: directory name, uppercase, y/-+/_X/
  64. typeset -u dnu=${dn//-/_}
  65. dnu=${dnu//+/X}
  66. ( # fd 4 = Config.in; fd 5 = Config.in.lib
  67. g5=0
  68. # Handle master package (directory)
  69. print -u4 "config ADK_COMPILE_$dnu"
  70. if [[ -z $ALL_PKGOPTS ]]; then
  71. # pseudo package, does not produce an ipkg package
  72. ppnf=$PKG_NAME # ppnf: pseudopkg name, filled
  73. if [[ -n $PKG_DESCR ]]; then
  74. while (( ${#ppnf} < 34 )); do
  75. ppnf=$ppnf.
  76. done
  77. ppnf="$ppnf $PKG_DESCR"
  78. fi
  79. print -u4 "\tprompt \"$ppnf\""
  80. fi
  81. print -u4 \\ttristate
  82. if [[ -n $ALL_PKGOPTS ]]; then
  83. # real (master) package, contains 1+ ipkg (sub)packages
  84. print -nu4 \\tdepends on
  85. sp=' ' # local sp: space (or ' || ')
  86. for spcu in $ALL_PKGOPTS; do # spcu: package option, ucase
  87. if [[ -n $PKG_MULTI ]]; then
  88. if [[ $dnu != $spcu ]]; then
  89. print -nu4 "${sp}ADK_PACKAGE_$spcu"
  90. sp=' || '
  91. else
  92. print -nu4 "${sp}ADK_HAVE_DOT_CONFIG"
  93. sp=' || '
  94. fi
  95. else
  96. print -nu4 "${sp}ADK_PACKAGE_$spcu"
  97. sp=' || '
  98. fi
  99. done
  100. print -u4
  101. fi
  102. print -u4 \\tdefault n
  103. # Handle NOT/ONLY_FOR_PLATFORM alikes
  104. phd= # phd: PKG_HOST_DEPENDS expand.
  105. if [[ -n $PKG_HOST_DEPENDS ]]; then
  106. phd='\tdepends on'
  107. if [[ $PKG_HOST_DEPENDS = *\!* ]]; then
  108. sp=' !'
  109. else
  110. sp=' '
  111. fi
  112. for x in $PKG_HOST_DEPENDS; do
  113. typeset -u x=${x#!}
  114. phd="$phd${sp}ADK_HOST_$x"
  115. if [[ $PKG_HOST_DEPENDS = *\!* ]]; then
  116. sp=' && !'
  117. else
  118. sp=' || '
  119. fi
  120. done
  121. fi
  122. ptd= # ptd: PKG_TARGET_DEPENDS exp.
  123. if [[ -n $PKG_TARGET_DEPENDS ]]; then
  124. ptd='\tdepends on'
  125. sp=' ' # local sp: space (or ' || ')
  126. if [[ $PKG_TARGET_DEPENDS = *\!* ]]; then
  127. sp=' !'
  128. else
  129. sp=' '
  130. fi
  131. for x in $PKG_TARGET_DEPENDS; do
  132. typeset -l x=${x#!}
  133. #XXX cache this with mksh R40+
  134. found=0
  135. while read friendlyname sym; do
  136. [[ $friendlyname = $x ]] || continue
  137. found=1
  138. break
  139. done <../../target/target.lst
  140. if (( !found )); then
  141. print -u2 "$dn: Target '$x' not found!"
  142. exit 1
  143. fi
  144. ptd="$ptd${sp}$sym"
  145. if [[ $PKG_TARGET_DEPENDS = *\!* ]]; then
  146. sp=' && !'
  147. else
  148. sp=' || '
  149. fi
  150. done
  151. fi
  152. # Handle subpackages / multipackages
  153. for spcu in $ALL_PKGOPTS; do # spcu: package option, ucase
  154. eval sppn=\$PKGNAME_$spcu # sppn: subpackage (ipkg) name
  155. eval desc=\$PKGDESC_$spcu # desc: subpackage description
  156. : ${desc:=$PKG_DESCR} # take from main pkg if empty
  157. eval deps=\$PKGDEPS_$spcu # deps: subpackage dependencies
  158. eval dflt=\$PKGDFLT_$spcu # dflt: config 'default' opt.
  159. eval xline=\$CFLINE_$spcu # xline: one free-format line
  160. if [[ $spcu = LIB* ]]; then
  161. h=5 # divert to Config.in.lib
  162. (( g5++ )) && print -u5 # been here before
  163. elif [[ $spcu = KMOD* ]]; then
  164. h=6
  165. (( g6++ )) && print -u6
  166. else
  167. h=4 # divert to Config.in
  168. print -u4
  169. fi
  170. print -u$h config ADK_PACKAGE_$spcu
  171. spnf=$sppn # spnf: subpackage name, filled
  172. if [[ -n ${desc:-$PKG_NAME} ]]; then
  173. while (( ${#spnf} < 34 )); do
  174. spnf=$spnf.
  175. done
  176. spnf="$spnf ${desc:-$PKG_NAME}"
  177. fi
  178. print -u$h "\tprompt \"$spnf\""
  179. print -u$h \\ttristate
  180. if [[ -n $PKG_MULTI ]]; then
  181. if [[ $spcu != $dnu ]]; then
  182. print -u$h "\tdepends on ADK_PACKAGE_$dnu"
  183. fi
  184. fi
  185. [[ -n $phd ]] && print -u$h "$phd"
  186. [[ -n $ptd ]] && print -u$h "$ptd"
  187. print -u$h "\tdefault ${dflt:-n}"
  188. for dep in $deps; do # dep: ipkg name of one rundep.
  189. # skip dependencies on uclibc++ and libstdcxx iff
  190. # we produce these automatically
  191. [[ -n $PKG_CXX && $dep = @(uclibc++|libstdcxx) ]] && \
  192. continue
  193. case $dep {
  194. (kmod-*)
  195. # produce dependency on kernel package
  196. # which have special name→sym mangling
  197. typeset -u udep=${dep//-/_}
  198. print -u$h "\tselect ADK_KPACKAGE_$udep"
  199. ;;
  200. (*)
  201. # produce dependency on regular package
  202. # where the symbol is cached (see above)
  203. print -u$h '\tselect' \
  204. ADK_PACKAGE_$(<../pkglist.d/"$dep")
  205. ;;
  206. }
  207. done
  208. print -u$h \\tselect ADK_COMPILE_$dnu
  209. [[ -n $xline ]] && print -u$h "\t$xline"
  210. if [[ -n $desc$PKG_URL ]]; then
  211. # produce (optional) help text
  212. print -u$h \\thelp
  213. [[ -n $desc ]] && print -u$h "\t $desc"
  214. [[ -n $desc && -n $PKG_URL ]] && print -u$h '\t '
  215. [[ -n $PKG_URL ]] && print -u$h "\t WWW: $PKG_URL"
  216. fi
  217. done
  218. # Handle CFrustFrust library selection, if necessary
  219. [[ -n $PKG_CXX ]] && cat >&4 <<EOF
  220. choice
  221. prompt "C++ library to use"
  222. depends on ADK_COMPILE_$dnu
  223. default ADK_COMPILE_${PKG_CXX}_WITH_STDCXX if ADK_TARGET_LIB_GLIBC || ADK_TARGET_LIB_EGLIBC
  224. default ADK_COMPILE_${PKG_CXX}_WITH_UCLIBCXX if ADK_TARGET_LIB_UCLIBC
  225. config ADK_COMPILE_${PKG_CXX}_WITH_STDCXX
  226. bool "GNU C++ library"
  227. select ADK_PACKAGE_LIBSTDCXX
  228. config ADK_COMPILE_${PKG_CXX}_WITH_UCLIBCXX
  229. bool "uClibc++ library"
  230. select ADK_PACKAGE_UCLIBCXX
  231. endchoice
  232. EOF
  233. # Handle flavours (per directory)
  234. for pfcu in $PKG_FLAVOURS; do # pfcu: pkg flavour conf opt.
  235. eval pfd=\$PKGFD_$pfcu # pfd: pkg flavour description
  236. print
  237. print config ADK_PACKAGE_${dnu}_$pfcu
  238. print "\tbool \"${pfd:-$PKG_NAME -> flavour $pfcu}\""
  239. print \\tdefault n
  240. print \\tdepends on ADK_COMPILE_$dnu
  241. print \\thelp
  242. print "\t flavour ADK_PACKAGE_${dnu}_$pfcu for $PKG_NAME"
  243. done >&4
  244. ) 4>Config.in 5>Config.in.lib 6>Config.in.kmod
  245. cd ..
  246. done