1
0

pkgmaker 10 KB

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