pkgmaker 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353
  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. # check for trailing whitespace
  14. #grep -H '[[:space:]]$' */Makefile && print "Found trailing whitespace, please fix"
  15. # build a cache of “ipkg package name” → “package conf option” for
  16. # use with dependency resolution
  17. rm -rf pkglist.d
  18. mkdir pkglist.d
  19. for dn in */Makefile; do
  20. dn=${dn%/*}
  21. pbar="Pass 1: $dn ..."
  22. print -nu2 "$pbar\r"
  23. cd $dn
  24. # ALL_PKGOPTS: all subpackage conf options
  25. # PKGNAME_*: subpackage (ipkg) package name, by subpackage option
  26. eval $($GMAKE dump="ALL_PKGOPTS \
  27. \$(foreach x,\${ALL_PKGOPTS},PKGNAME_\${x})")
  28. cd ..
  29. if [[ -z $ALL_PKGOPTS ]]; then
  30. #print -u2 "Warning: $dn/Makefile contains no packages, skipped"
  31. continue
  32. fi
  33. for spcu in $ALL_PKGOPTS; do # spcu: package option, ucase
  34. eval sppn=\$PKGNAME_$spcu # sppn: subpackage (ipkg) name
  35. # once mksh R40 is out, use its new associative arrays here!
  36. print -r -- "$spcu" >pkglist.d/"$sppn"
  37. done
  38. done
  39. # build Config.in files and resolve dependencies
  40. rm -f package_sections
  41. rm -rf pkgconfigs.d
  42. mkdir pkgconfigs.d
  43. for dn in */Makefile; do
  44. dn=${dn%/*}
  45. pbar="Pass 2: $dn ..."
  46. print -nu2 "$pbar\r"
  47. mkdir pkgconfigs.d/$dn
  48. cd $dn
  49. # PKG_NAME: package name (directory, free-format)
  50. # PKG_FLAVOURS: all package flavours (boolean options), uppercase
  51. # PKG_CHOICES: all package choices (boolean options), uppercase
  52. # PKG_DESCR: package description (directory)
  53. # PKG_URL: package homepage
  54. # PKG_CXX: uppercase varname part to use for CFrustFrust checks
  55. # ALL_PKGOPTS: all subpackage conf options
  56. # PKGNAME_*: subpackage (ipkg) package name, by subpackage option
  57. # PKGDESC_*: subpackage description, by subpackage option
  58. # PKGDEPS_*: subpackage depends on ipkg packages, by subpkg option
  59. # PKGDFLT_*: subpackage 'default {:-n}', by subpackage option
  60. # CFLINE_*: one free-format Config.in line per subpackage option
  61. # PKGFD_*: flavour description, per package flavour option
  62. # PKG_{HOST,TARGET}_DEPENDS: add host or target dependencies
  63. eval $($GMAKE dump="PKG_NAME PKG_FLAVOURS PKG_CHOICES PKG_DESCR PKG_SECTION PKG_URL PKG_MULTI PKG_CXX \
  64. ALL_PKGOPTS \$(foreach x,\${ALL_PKGOPTS},PKGNAME_\${x} \
  65. PKGDESC_\${x} PKGDEPS_\${x} PKGDFLT_\${x} PKGSECT_\${x} CFLINE_\${x}) \
  66. \$(foreach x,\${PKG_FLAVOURS},PKGFD_\${x}) \
  67. \$(foreach x,\${PKG_FLAVOURS},PKGFS_\${x}) \
  68. \$(foreach x,\${PKG_CHOICES},PKGCD_\${x}) \
  69. \$(foreach x,\${PKG_CHOICES},PKGCS_\${x}) \
  70. PKG_HOST_DEPENDS PKG_TARGET_DEPENDS")
  71. # dnu: directory name, uppercase, y/-+/_X/
  72. typeset -u dnu=${dn//-/_}
  73. dnu=${dnu//+/X}
  74. echo "pkgconfigs.d/$dn/Config.in ${PKG_SECTION:=none}" >>../package_sections
  75. echo "$dn/Config.in.manual ${PKG_SECTION:=none}" >>../package_sections
  76. # skip if we take care of this one manually
  77. [[ $dn != "base-files" ]] && [[ -s Config.in.manual ]] && { cd ..; continue; }
  78. exec 4>../pkgconfigs.d/$dn/Config.in
  79. # Handle master package (directory)
  80. print -u4 "config ADK_COMPILE_$dnu"
  81. if [[ -z $ALL_PKGOPTS ]]; then
  82. # pseudo package, does not produce an ipkg package
  83. ppnf=$PKG_NAME # ppnf: pseudopkg name, filled
  84. if [[ -n $PKG_DESCR ]]; then
  85. while (( ${#ppnf} < 34 )); do
  86. ppnf=$ppnf.
  87. done
  88. ppnf="$ppnf $PKG_DESCR"
  89. fi
  90. print -u4 "\tprompt \"$ppnf\""
  91. fi
  92. print -u4 \\ttristate
  93. if [[ -n $ALL_PKGOPTS ]]; then
  94. # real (master) package, contains 1+ ipkg (sub)packages
  95. print -nu4 \\tdepends on
  96. sp=' ' # local sp: space (or ' || ')
  97. for spcu in $ALL_PKGOPTS; do # spcu: package option, ucase
  98. if [[ -n $PKG_MULTI ]]; then
  99. if [[ $dnu != $spcu ]]; then
  100. print -nu4 "${sp}ADK_PACKAGE_$spcu"
  101. sp=' || '
  102. else
  103. print -nu4 "${sp}ADK_HAVE_DOT_CONFIG"
  104. sp=' || '
  105. fi
  106. else
  107. print -nu4 "${sp}ADK_PACKAGE_$spcu"
  108. sp=' || '
  109. fi
  110. done
  111. print -u4
  112. fi
  113. print -u4 \\tdefault n
  114. # Handle NOT/ONLY_FOR_PLATFORM alikes
  115. phd= # phd: PKG_HOST_DEPENDS expand.
  116. if [[ -n $PKG_HOST_DEPENDS ]]; then
  117. phd='\tdepends on'
  118. if [[ $PKG_HOST_DEPENDS = *\!* ]]; then
  119. sp=' !'
  120. else
  121. sp=' '
  122. fi
  123. for x in $PKG_HOST_DEPENDS; do
  124. typeset -u x=${x#!}
  125. phd="$phd${sp}ADK_HOST_$x"
  126. if [[ $PKG_HOST_DEPENDS = *\!* ]]; then
  127. sp=' && !'
  128. else
  129. sp=' || '
  130. fi
  131. done
  132. fi
  133. ptd= # ptd: PKG_TARGET_DEPENDS exp.
  134. if [[ -n $PKG_TARGET_DEPENDS ]]; then
  135. ptd='\tdepends on'
  136. sp=' ' # local sp: space (or ' || ')
  137. if [[ $PKG_TARGET_DEPENDS = *\!* ]]; then
  138. sp=' !'
  139. else
  140. sp=' '
  141. fi
  142. for x in $PKG_TARGET_DEPENDS; do
  143. typeset -l x=${x#!}
  144. #XXX cache this with mksh R40+
  145. found=0
  146. while read friendlyname sym; do
  147. [[ $friendlyname = $x ]] || continue
  148. found=1
  149. break
  150. done <../../target/target.lst
  151. if (( !found )); then
  152. print -u2 "$dn: Target '$x' not found!"
  153. exit 1
  154. fi
  155. ptd="$ptd${sp}$sym"
  156. if [[ $PKG_TARGET_DEPENDS = *\!* ]]; then
  157. sp=' && !'
  158. else
  159. sp=' || '
  160. fi
  161. done
  162. fi
  163. # Handle subpackages / multipackages
  164. for spcu in $ALL_PKGOPTS; do # spcu: package option, ucase
  165. eval sppn=\$PKGNAME_$spcu # sppn: subpackage (ipkg) name
  166. eval desc=\$PKGDESC_$spcu # desc: subpackage description
  167. : ${desc:=$PKG_DESCR} # take from main pkg if empty
  168. eval sect=\$PKGSECT_$spcu # sect: subpackage section
  169. : ${sect:=$PKG_SECTION} # take from main pkg if empty
  170. eval deps=\$PKGDEPS_$spcu # deps: subpackage dependencies
  171. eval dflt=\$PKGDFLT_$spcu # dflt: config 'default' opt.
  172. eval xline=\$CFLINE_$spcu # xline: one free-format line
  173. echo "pkgconfigs.d/$dn/Config.in.$sppn $sect" >>../package_sections
  174. exec 4>../pkgconfigs.d/$dn/Config.in.$sppn
  175. h=4
  176. print -u$h config ADK_PACKAGE_$spcu
  177. spnf=$sppn # spnf: subpackage name, filled
  178. if [[ -n ${desc:-$PKG_NAME} ]]; then
  179. while (( ${#spnf} < 34 )); do
  180. spnf=$spnf.
  181. done
  182. spnf="$spnf ${desc:-$PKG_NAME}"
  183. fi
  184. print -u$h "\tprompt \"$spnf\""
  185. print -u$h \\ttristate
  186. if [[ -n $PKG_MULTI ]]; then
  187. if [[ $spcu != $dnu ]]; then
  188. print -u$h "\tdepends on ADK_PACKAGE_$dnu"
  189. fi
  190. fi
  191. [[ -n $phd ]] && print -u$h "$phd"
  192. [[ -n $ptd ]] && print -u$h "$ptd"
  193. print -u$h "\tdefault ${dflt:-n}"
  194. for dep in $deps; do # dep: ipkg name of one rundep.
  195. # skip dependencies on uclibc++ and libstdcxx iff
  196. # we produce these automatically
  197. [[ -n $PKG_CXX && $dep = @(uclibc++|libstdcxx) ]] && \
  198. continue
  199. case $dep {
  200. (kmod-*)
  201. # produce dependency on kernel package
  202. # which have special name→sym mangling
  203. typeset -u udep=${dep//-/_}
  204. print -u$h "\tselect ADK_KPACKAGE_$udep"
  205. ;;
  206. (*)
  207. # produce dependency on regular package
  208. # where the symbol is cached (see above)
  209. if [[ ! -f ../pkglist.d/"$dep" ]]; then
  210. print -u2 "Warning: $PKG_NAME: unreachable dependency '$dep'"
  211. continue
  212. fi
  213. print -u$h '\tselect' \
  214. ADK_PACKAGE_$(<../pkglist.d/"$dep")
  215. ;;
  216. }
  217. done
  218. print -u$h \\tselect ADK_COMPILE_$dnu
  219. [[ -n $xline ]] && print -u$h "\t$xline"
  220. if [[ -n $desc$PKG_URL ]]; then
  221. # produce (optional) help text
  222. print -u$h \\thelp
  223. [[ -n $desc ]] && print -u$h "\t $desc"
  224. [[ -n $desc && -n $PKG_URL ]] && print -u$h '\t '
  225. [[ -n $PKG_URL ]] && print -u$h "\t WWW: $PKG_URL"
  226. fi
  227. done
  228. # Handle CFrustFrust library selection, if necessary
  229. [[ -n $PKG_CXX ]] && cat >&4 <<EOF
  230. choice
  231. prompt "C++ library to use"
  232. depends on ADK_COMPILE_$dnu
  233. default ADK_COMPILE_${PKG_CXX}_WITH_STDCXX if ADK_TARGET_LIB_GLIBC || ADK_TARGET_LIB_EGLIBC
  234. default ADK_COMPILE_${PKG_CXX}_WITH_UCLIBCXX if ADK_TARGET_LIB_UCLIBC
  235. config ADK_COMPILE_${PKG_CXX}_WITH_STDCXX
  236. bool "GNU C++ library"
  237. select ADK_PACKAGE_LIBSTDCXX
  238. config ADK_COMPILE_${PKG_CXX}_WITH_UCLIBCXX
  239. bool "uClibc++ library"
  240. select ADK_PACKAGE_UCLIBCXX
  241. endchoice
  242. EOF
  243. [[ -n $PKG_CHOICES ]] && cat >&4 <<EOF
  244. choice
  245. prompt "Package flavour choice"
  246. depends on ADK_COMPILE_$dnu
  247. EOF
  248. # Handle choices
  249. for pfco in $PKG_CHOICES; do
  250. eval pfcd=\$PKGCD_$pfco
  251. eval pfcs=\$PKGCS_$pfco
  252. typeset -u pfcs=${pfcs#!}
  253. print
  254. print config ADK_PACKAGE_${dnu}_$pfco
  255. print "\tbool \"$pfcd\""
  256. print "\\tselect ADK_PACKAGE_${pfcs}"
  257. done >&4
  258. [[ -n $PKG_CHOICES ]] && cat >&4 <<EOF
  259. endchoice
  260. EOF
  261. # Handle flavours (per directory)
  262. for pfcu in $PKG_FLAVOURS; do # pfcu: pkg flavour conf opt.
  263. eval pfd=\$PKGFD_$pfcu # pfd: pkg flavour description
  264. eval pfs=\$PKGFS_$pfcu # pfs: pkg flavour dependencies
  265. print
  266. print config ADK_PACKAGE_${dnu}_$pfcu
  267. print "\tbool \"${pfd:-$PKG_NAME -> flavour $pfcu}\""
  268. print \\tdefault n
  269. print \\tdepends on ADK_COMPILE_$dnu
  270. for pfso in $pfs; do
  271. typeset -u pfso=${pfso#!}
  272. print \\tselect ADK_PACKAGE_${pfso}
  273. done
  274. print \\thelp
  275. print "\t flavour ADK_PACKAGE_${dnu}_$pfcu for $PKG_NAME"
  276. done >&4
  277. cd ..
  278. done
  279. # return good if given file exists and is non-empty
  280. function non_empty_file() {
  281. [[ -f "$1" ]] || return 1
  282. [[ -n "$(cat "$1")" ]] || return 1
  283. return 0
  284. }
  285. # print the verbose section name for a given section tag
  286. function lookup_section_string() {
  287. str="$(grep ^$1\ sections.lst | cut -d ' ' -f '2-')"
  288. [[ -n $str ]] && { echo $str; return; }
  289. echo $1
  290. }
  291. # print the first prompt's first word's value in a given Config.in file
  292. function get_first_prompt() {
  293. prompt="$(grep -m 1 "prompt " $1 | sed -n 's/.*"\([^ \.]*\)[ \.].*"/\1/p')"
  294. [[ -n $prompt ]] && echo $prompt
  295. }
  296. # prepare Config.in list for sorting
  297. while read config_in section; do
  298. pbar="Pass 3: $config_in ..."
  299. print -nu2 "$pbar\r"
  300. non_empty_file $config_in || continue
  301. prompt="$(get_first_prompt $config_in)"
  302. [[ -n $prompt ]] || continue
  303. echo "$prompt $config_in $(lookup_section_string $section)"
  304. done <package_sections >package_section_list
  305. # create the Config.in.auto from the sorted list from above
  306. cursec=""
  307. sort -k 3 -k 1 -f package_section_list | while read name file section; do
  308. pbar="Pass 4: $name ..."
  309. print -nu2 "$pbar\r"
  310. if [[ $cursec != $section ]]; then
  311. [[ -n $cursec ]] && print "endmenu\n"
  312. print "menu \"$section\""
  313. cursec="$section"
  314. fi
  315. print "source \"package/$file\""
  316. print -u3 "source \"package/${file%.*}\""
  317. done >Config.in.auto 3>Config.in.auto.pre
  318. print "endmenu\n" >>Config.in.auto
  319. grep pkgconfigs.d Config.in.auto.pre | sort | uniq > Config.in.auto.global
  320. rm -f package_sections package_section_list Config.in.auto.pre