pkgmaker 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  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. else
  164. h=4 # divert to Config.in
  165. print -u4
  166. fi
  167. print -u$h config ADK_PACKAGE_$spcu
  168. spnf=$sppn # spnf: subpackage name, filled
  169. if [[ -n ${desc:-$PKG_NAME} ]]; then
  170. while (( ${#spnf} < 34 )); do
  171. spnf=$spnf.
  172. done
  173. spnf="$spnf ${desc:-$PKG_NAME}"
  174. fi
  175. print -u$h "\tprompt \"$spnf\""
  176. print -u$h \\ttristate
  177. if [[ -n $PKG_MULTI ]]; then
  178. if [[ $spcu != $dnu ]]; then
  179. print -u$h "\tdepends on ADK_PACKAGE_$dnu"
  180. fi
  181. fi
  182. [[ -n $phd ]] && print -u$h "$phd"
  183. [[ -n $ptd ]] && print -u$h "$ptd"
  184. print -u$h "\tdefault ${dflt:-n}"
  185. for dep in $deps; do # dep: ipkg name of one rundep.
  186. # skip dependencies on uclibc++ and libstdcxx iff
  187. # we produce these automatically
  188. [[ -n $PKG_CXX && $dep = @(uclibc++|libstdcxx) ]] && \
  189. continue
  190. case $dep {
  191. (kmod-*)
  192. # produce dependency on kernel package
  193. # which have special name→sym mangling
  194. typeset -u udep=${dep//-/_}
  195. print -u$h "\tselect ADK_KPACKAGE_$udep"
  196. ;;
  197. (*)
  198. # produce dependency on regular package
  199. # where the symbol is cached (see above)
  200. print -u$h '\tselect' \
  201. ADK_PACKAGE_$(<../pkglist.d/"$dep")
  202. ;;
  203. }
  204. done
  205. print -u$h \\tselect ADK_COMPILE_$dnu
  206. [[ -n $xline ]] && print -u$h "\t$xline"
  207. if [[ -n $desc$PKG_URL ]]; then
  208. # produce (optional) help text
  209. print -u$h \\thelp
  210. [[ -n $desc ]] && print -u$h "\t $desc"
  211. [[ -n $desc && -n $PKG_URL ]] && print -u$h '\t '
  212. [[ -n $PKG_URL ]] && print -u$h "\t WWW: $PKG_URL"
  213. fi
  214. done
  215. # Handle CFrustFrust library selection, if necessary
  216. [[ -n $PKG_CXX ]] && cat >&4 <<EOF
  217. choice
  218. prompt "C++ library to use"
  219. depends on ADK_COMPILE_$dnu
  220. default ADK_COMPILE_${PKG_CXX}_WITH_STDCXX if ADK_TARGET_LIB_GLIBC || ADK_TARGET_LIB_EGLIBC
  221. default ADK_COMPILE_${PKG_CXX}_WITH_UCLIBCXX if ADK_TARGET_LIB_UCLIBC
  222. config ADK_COMPILE_${PKG_CXX}_WITH_STDCXX
  223. bool "GNU C++ library"
  224. select ADK_PACKAGE_LIBSTDCXX
  225. config ADK_COMPILE_${PKG_CXX}_WITH_UCLIBCXX
  226. bool "uClibc++ library"
  227. select ADK_PACKAGE_UCLIBCXX
  228. endchoice
  229. EOF
  230. # Handle flavours (per directory)
  231. for pfcu in $PKG_FLAVOURS; do # pfcu: pkg flavour conf opt.
  232. eval pfd=\$PKGFD_$pfcu # pfd: pkg flavour description
  233. print
  234. print config ADK_PACKAGE_${dnu}_$pfcu
  235. print "\tbool \"${pfd:-$PKG_NAME -> flavour $pfcu}\""
  236. print \\tdefault n
  237. print \\tdepends on ADK_COMPILE_$dnu
  238. print \\thelp
  239. print "\t flavour ADK_PACKAGE_${dnu}_$pfcu for $PKG_NAME"
  240. done >&4
  241. ) 4>Config.in 5>Config.in.lib
  242. cd ..
  243. done
  244. pbar=done
  245. print -u2 "$pbar"