PageRenderTime 54ms CodeModel.GetById 22ms RepoModel.GetById 1ms app.codeStats 0ms

/mk/scripts/genreadme.awk

https://bitbucket.org/dabomb69/pkgsrc
AWK | 852 lines | 591 code | 93 blank | 168 comment | 0 complexity | b80992d892a2c2b5c443d4e3e9c6765b MD5 | raw file
Possible License(s): Unlicense, Cube, BSD-2-Clause, IPL-1.0, BSD-3-Clause, LGPL-2.1, MIT, CC-BY-SA-3.0, Apache-2.0, MPL-2.0, MPL-2.0-no-copyleft-exception, GPL-3.0, WTFPL, LGPL-2.0, AGPL-1.0, GPL-2.0, LGPL-3.0, 0BSD, AGPL-3.0
  1. #!/usr/bin/awk -f
  2. # $NetBSD: genreadme.awk,v 1.33 2008/08/03 16:24:53 tnn Exp $
  3. #
  4. # Copyright (c) 2002, 2003, 2005, 2006 The NetBSD Foundation, Inc.
  5. # All rights reserved.
  6. #
  7. # This code is derived from software contributed to The NetBSD Foundation
  8. # by Dan McMahill.
  9. #
  10. # Redistribution and use in source and binary forms, with or without
  11. # modification, are permitted provided that the following conditions
  12. # are met:
  13. # 1. Redistributions of source code must retain the above copyright
  14. # notice, this list of conditions and the following disclaimer.
  15. # 2. Redistributions in binary form must reproduce the above copyright
  16. # notice, this list of conditions and the following disclaimer in the
  17. # documentation and/or other materials provided with the distribution.
  18. # 3. All advertising materials mentioning features or use of this software
  19. # must display the following acknowledgement:
  20. # This product includes software developed by the NetBSD
  21. # Foundation, Inc. and its contributors.
  22. # 4. Neither the name of The NetBSD Foundation nor the names of its
  23. # contributors may be used to endorse or promote products derived
  24. # from this software without specific prior written permission.
  25. #
  26. # THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
  27. # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
  28. # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  29. # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
  30. # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  31. # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  32. # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  33. # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  34. # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  35. # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  36. # POSSIBILITY OF SUCH DAMAGE.
  37. #
  38. # Global variables
  39. #-----------------
  40. # The following associative arrays are used for storing the dependency
  41. # information and other information for the packages
  42. #
  43. # topdepends[] : index=pkgdir (math/scilab)
  44. # List of explicitly listed depencencies by name.
  45. # I.e. "xless-[0-9]* pvm-3.4.3"
  46. #
  47. # alldepends[] : index=pkgdir (math/scilab)
  48. # Flattened dependency list by name.
  49. #
  50. BEGIN {
  51. do_pkg_readme=1;
  52. # set to 1 to use "README-new.html" as the name
  53. use_readme_new=0;
  54. if (use_readme_new) {
  55. readme_name = "README-new.html";
  56. }
  57. else {
  58. readme_name = "README.html";
  59. }
  60. printf("Reading database file\n");
  61. }
  62. #conflicts /usr/pkgsrc/math/scilab
  63. #depends /usr/pkgsrc/math/scilab xless-[0-9]*:../../x11/xless pvm-3.4.3:../../parallel/pvm3
  64. #
  65. /^(build_)?depends / {
  66. #
  67. # Read in the entire depends tree
  68. # These lines look like:
  69. #
  70. #depends /usr/pkgsrc/math/scilab xless-[0-9]*:../../x11/xless pvm-3.4.3:../../parallel/pvm3
  71. #build_depends /usr/pkgsrc/math/scilab libtool-base>=1.4.20010614nb9:../../devel/libtool-base
  72. #
  73. deptype=$1;
  74. # pkg=fulldir2pkgdir($2);
  75. pkg = $2;
  76. if (pkg in topdepends) {}
  77. else {topdepends[pkg] = "";}
  78. if (pkg in topbuilddepends) {}
  79. else {topbuilddepends[pkg] = "";}
  80. for (i = 3; i <= NF; i++) {
  81. split($i, a,":");
  82. pkgpat = a[1];
  83. pkgdir = a[2];
  84. sub(/[\.\/]*/, "", pkgdir);
  85. if (pkgdir !~ /\//) {
  86. pkgcat = pkg;
  87. gsub(/\/.*/, "", pkgcat);
  88. pkgdir=pkgcat "/" pkgdir;
  89. if (debug)
  90. printf("Corrected missing category directory to get \"%s\"\n",
  91. pkgdir);
  92. }
  93. if (debug){
  94. printf("package in directory %s %s on:\n",
  95. pkg, deptype);
  96. printf("\tpkgpat = %s\n", pkgpat);
  97. printf("\tpkgdir = %s\n", pkgdir);
  98. }
  99. #
  100. # store the package directory in a associative array with the wildcard
  101. # pattern as the index since we will need to be able to look this up later
  102. #
  103. pat2dir[pkgpat] = pkgdir;
  104. if (deptype == "depends") {
  105. topdepends[pkg] = topdepends[pkg] " " pkgpat " " ;
  106. if (debug) {
  107. printf("Appending %s to topdepends[%s] (%s)\n",
  108. pkgpat, pkg, topdepends[pkg]);
  109. }
  110. }
  111. else {
  112. if (debug) {
  113. printf("Appending %s to topbuilddepends[%s] (%s)\n",
  114. pkgpat, pkg, topbuilddepends[pkg]);
  115. }
  116. topbuilddepends[pkg] = topbuilddepends[pkg] " " pkgpat " " ;
  117. }
  118. }
  119. next;
  120. }
  121. /^comment /{
  122. dir = $2;
  123. gsub(/^comment[ \t]*/, "");
  124. tmp = substr($0, length($1) + 1);
  125. gsub(/^[ \t]*/, "", tmp);
  126. gsub(/&/, "\\\\\\&amp;", tmp);
  127. comment[dir] = tmp;
  128. next;
  129. }
  130. /^homepage /{
  131. homepage[$2] = $3;
  132. gsub(/&/, "\\\\&", homepage[$2]);
  133. next;
  134. }
  135. /^htmlname / {
  136. #
  137. # read lines like:
  138. # htmlname /usr/pkgsrc/archivers/arc <a href=../../archivers/arc/README.html>arc-5.21e</A>
  139. #
  140. # dir=fulldir2pkgdir($2);
  141. dir = $2;
  142. htmlname = $3;
  143. for (i = 4; i <= NF; i++){
  144. htmlname = htmlname " " $i;
  145. }
  146. # If we are using a name other than README.html, change it
  147. # here. This avoids having to process a huge line later which
  148. # makes lesser awks puke.
  149. gsub(/README.html/, readme_name, htmlname);
  150. dir2htmlname[dir] = htmlname;
  151. if (debug) printf("added dir2htmlname[%s]=%s\n", dir, htmlname);
  152. next;
  153. }
  154. /^index / {
  155. #
  156. # read lines like:
  157. #index /usr/pkgsrc/math/scilab scilab-2.6nb3
  158. # and store the directory name in a associative array where the index
  159. # is the package name and in a associative array that lets us lookup
  160. # name from directory. We use fuldir2pkgdir to get "math/scilab"
  161. # and drop the /usr/pkgsrc part.
  162. #
  163. # pkgname2dir[$3] = fulldir2pkgdir($2);
  164. # pkgdir2name[fulldir2pkgdir($2)] = $3;
  165. pkgname2dir[$3] = $2;
  166. pkgdir2name[$2] = $3;
  167. next;
  168. }
  169. /^license /{
  170. license[$2] = $3;
  171. next;
  172. }
  173. /^wildcard /{
  174. wildcard[$2] = $3;
  175. }
  176. #
  177. # Now recurse the tree to give a flattened depends list for each pkg
  178. #
  179. END {
  180. readme = TMPDIR "/" readme_name;
  181. if ( dependsfile == "" ) dependsfile = "/dev/stdout";
  182. if ( builddependsfile == "" ) builddependsfile = "/dev/stdout";
  183. printf("Making sure binary package cache file is up to date...\n");
  184. cmd = sprintf("%s AWK=%s CMP=%s FIND=%s GREP=%s GZIP_CMD=\"%s\" PKG_INFO=\"%s\" PKG_SUFX=%s SED=%s SORT=%s %s/mk/scripts/binpkg-cache %s --packages %s",
  185. SETENV, AWK, CMP, FIND, GREP, GZIP_CMD, PKG_INFO, PKG_SUFX, SED, SORT, PKGSRCDIR, summary, PACKAGES);
  186. if (debug) printf("\nExecute: %s\n",cmd);
  187. rc = system(cmd);
  188. if (rc != 0 && rc != 2) {
  189. printf("\n**** WARNING ****\n") > "/dev/stderr";
  190. printf("Command: %s\nfailed.", cmd) > "/dev/stderr";
  191. printf("**** ------- ****\n") > "/dev/stderr";
  192. exit(1);
  193. }
  194. if (rc == 2) {
  195. printf("\n**** WARNING ****\n") > "/dev/stderr";
  196. printf("* No binary packages directory found\n") > "/dev/stderr";
  197. printf("* List of binary packages will not be generated\n") > "/dev/stderr";
  198. printf("**** ------- ****\n") > "/dev/stderr";
  199. } else {
  200. printf("Loading binary package cache file...\n");
  201. load_cache_file( PACKAGES "/.pkgcache" );
  202. if(pkg_count["unknown"] > 0 ) {
  203. printf(" Loaded %d binary packages with unknown PKGPATH\n", pkg_count["unknown"]);
  204. }
  205. }
  206. printf("Flattening dependencies\n");
  207. printf("") > dependsfile;
  208. for (toppkg in topdepends){
  209. if (debug) printf("calling find_all_depends(%s, run)\n", toppkg);
  210. find_all_depends(toppkg, "run");
  211. if (debug) printf("%s depends on: %s, topdepends on %s\n",
  212. toppkg, alldepends[toppkg],
  213. topdepends[toppkg]);
  214. printf("%s depends on: %s\n",
  215. toppkg, alldepends[toppkg]) >> dependsfile;
  216. flatdepends[toppkg] = alldepends[toppkg];
  217. }
  218. close(dependsfile);
  219. # clear out the flattened depends list and repeat for the build depends
  220. for( key in alldepends ) {
  221. delete alldepends[key];
  222. }
  223. printf("Flattening build dependencies\n");
  224. printf("") > builddependsfile;
  225. for (toppkg in topbuilddepends){
  226. find_all_depends(toppkg, "build");
  227. printf("%s build_depends on: %s\n",
  228. toppkg, alldepends[toppkg]) >> builddependsfile;
  229. }
  230. close(builddependsfile);
  231. # extract date for vulnerabilities file
  232. if (SCAN_VULNERABILITIES == 0)
  233. vuldate="<TR><TD><I>(no vulnerabilities list, update pkg_install)</I>";
  234. else if (SCAN_VULNERABILITIES == 1)
  235. vuldate="<TR><TD><I>(no vulnerabilities list available)</I>";
  236. if (SINGLEPKG != "" ) {
  237. printf("Only creating README for %s\n",SINGLEPKG);
  238. for( key in topdepends ) {
  239. delete topdepends[key];
  240. }
  241. topdepends[SINGLEPKG] = "yes";
  242. }
  243. printf("Generating README.html files\n");
  244. pkgcnt = 0;
  245. if (do_pkg_readme) {
  246. templatefile = PKGSRCDIR "/templates/README.pkg";
  247. fatal_check_file(templatefile);
  248. for (toppkg in topdepends){
  249. pkgcnt++;
  250. pkgdir = PKGSRCDIR "/" toppkg;
  251. readmenew=pkgdir "/" readme_name;
  252. if (debug) printf("Creating %s for %s\n",
  253. readme, readmenew);
  254. printf(".");
  255. if ((pkgcnt % 100) == 0) {
  256. printf("\n%d\n", pkgcnt);
  257. }
  258. printf("") > readme;
  259. htmldeps = "";
  260. for( key in dpkgs ) {
  261. delete dpkgs[key];
  262. }
  263. split(alldepends[toppkg], dpkgs);
  264. i = 1;
  265. htmldeps_file = TMPDIR "/htmldep";
  266. printf("") > htmldeps_file;
  267. while(i in dpkgs){
  268. if (debug) {
  269. printf("\tdpkg=%s, pat2dir[%s] = %s\n",
  270. dpkgs[i],
  271. dpkgs[i],
  272. pat2dir[dpkgs[i]]);
  273. }
  274. nm=dpkgs[i];
  275. gsub(/&/, "\\&amp;", nm);
  276. gsub(/</, "\\&lt;", nm);
  277. gsub(/>/, "\\&gt;", nm);
  278. # htmldeps=sprintf("%s<a href=\"../../%s/%s\">%s</a>\n",
  279. # htmldeps,
  280. # pat2dir[dpkgs[i]],
  281. # readme_name, nm);
  282. # We use a temp file to hold the html dependencies because for
  283. # packages like gnome, this list can get very very large and
  284. # become larger than what some awk implementations can deal
  285. # with. The nawk shipped with solaris 9 is an example of
  286. # such a limited awk.
  287. printf("%s<a href=\"../../%s/%s\">%s</a>\n",
  288. htmldeps,
  289. pat2dir[dpkgs[i]],
  290. readme_name, nm) >> htmldeps_file;
  291. i = i + 1;
  292. }
  293. if ( i == 1 ) {
  294. printf("<EM>none</EM>") >> htmldeps_file;
  295. }
  296. close(htmldeps_file);
  297. if (debug) printf("wrote = %d entries to \"%s\"\n",
  298. i-1, htmldeps_file);
  299. vul = "";
  300. if (SCAN_VULNERABILITIES == 2) {
  301. pkgbase = pkgdir2name[toppkg];
  302. sub("-[^-]*$", "", pkgbase);
  303. cmd = sprintf("%s audit-history %s", PKG_ADMIN, pkgbase);
  304. while (cmd | getline vuln_entry) {
  305. split(vuln_entry, entry, " ");
  306. status_cmd = sprintf("if %s pmatch '%s' %s; then echo open; else echo fixed; fi",
  307. PKG_ADMIN, entry[1], pkgdir2name[toppkg]);
  308. status_cmd | getline status
  309. close(status_cmd)
  310. if (status == "open")
  311. status = "an <STRONG>OPEN</STRONG>";
  312. else
  313. status = "a " status;
  314. vul = sprintf("%s<LI>%s <a href=\"%s\">%s</a> vulnerability</LI>\n",
  315. vul, status, entry[3], entry[2]);
  316. }
  317. close(cmd);
  318. if ( vul == "" ) {
  319. vul="<I>(no vulnerabilities known)</I>";
  320. }
  321. }
  322. if (debug) {
  323. printf("Checking for binary package with lookup_cache( %s)\n",
  324. toppkg);
  325. }
  326. # lookup_cache( wildcard ) will produce HTML for the packages which are found
  327. lookup_cache( toppkg );
  328. if ( flatdepends[toppkg] ~ /^[ \t]*$/ ) {
  329. rundeps = "<EM>none</EM>";
  330. } else {
  331. rundeps = flatdepends[toppkg];
  332. }
  333. while((getline < templatefile) > 0){
  334. gsub(/%%PORT%%/, toppkg);
  335. gsub(/%%PKG%%/, pkgdir2name[toppkg]);
  336. gsub(/%%COMMENT%%/, comment[toppkg]);
  337. if (homepage[toppkg] == "") {
  338. gsub(/%%HOMEPAGE%%/, "");
  339. } else {
  340. gsub(/%%HOMEPAGE%%/,
  341. "<p>This package has a home page at <a HREF=\"" homepage[toppkg] "\">" homepage[toppkg] "</a>.</p>");
  342. }
  343. if (license[toppkg] == "") {
  344. gsub(/%%LICENSE%%/, "");
  345. } else {
  346. gsub(/%%LICENSE%%/,
  347. "<p>Please note that this package has a " license[toppkg] " license.</p>");
  348. }
  349. gsub(/%%VULNERABILITIES%%/, ""vul"");
  350. gsub(/%%VULDATE%%/, ""vuldate"");
  351. gsub(/%%RUN_DEPENDS%%/, ""rundeps"");
  352. line = $0;
  353. if( line ~/%%BIN_PKGS%%/ ) {
  354. gsub(/%%BIN_PKGS%%/, "", line);
  355. while((getline < binpkgs_file) > 0) {
  356. print >> readme;
  357. }
  358. close( binpkgs_file );
  359. }
  360. if( line ~/%%BUILD_DEPENDS%%/ ) {
  361. gsub(/%%BUILD_DEPENDS%%/, "", line);
  362. while((getline < htmldeps_file) > 0) {
  363. print >> readme;
  364. }
  365. close( htmldeps_file );
  366. }
  367. print line >> readme;
  368. }
  369. close(readme);
  370. close(templatefile);
  371. cmd = "if [ ! -d " pkgdir " ]; then exit 1 ; fi";
  372. if (debug) printf("Execute: %s\n",cmd);
  373. rc = system(cmd);
  374. if (rc != 0) {
  375. printf("\n**** WARNING ****\nPackage directory %s\n",
  376. pkgdir) > "/dev/stderr";
  377. printf("Does not exist. This is probably ") > "/dev/stderr";
  378. printf("due to an incorrect DEPENDS line.\n") > "/dev/stderr";
  379. printf("Try running: grep %s */*/Makefile\n", fulldir2pkgdir(pkgdir)) > "/dev/stderr";
  380. printf("or: grep %s */*/buildlink3.mk\n", fulldir2pkgdir(pkgdir)) > "/dev/stderr";
  381. printf("to find the problem\n", pkgdir) > "/dev/stderr";
  382. printf("**** ------- ****\n") > "/dev/stderr";
  383. } else {
  384. copy_readme(readmenew, readme);
  385. }
  386. }
  387. printf("\n");
  388. } # if (do_pkg_readme)
  389. printf("\n");
  390. if (SINGLEPKG != "" ) {
  391. close("/dev/stderr");
  392. exit 0;
  393. }
  394. printf("Generating category readmes\n");
  395. templatefile = PKGSRCDIR "/templates/README.category";
  396. fatal_check_file(templatefile);
  397. # string with URLs for all categories (used by the top README.html)
  398. allcat = "";
  399. # string with URLs for all pkgs (used by the top README-all.html)
  400. tot_numpkg = 0;
  401. top_make = PKGSRCDIR"/Makefile";
  402. while((getline < top_make) > 0){
  403. if ($0 ~ /^[ \t]*SUBDIR.*=[^\$]*$/) {
  404. category = $0;
  405. gsub(/^[ \t]*SUBDIR.*=[ \t]*/, "", category);
  406. catdir = PKGSRCDIR"/"category;
  407. readmenew = catdir"/"readme_name;
  408. printf("Category = %s\n", category);
  409. cat_make = catdir"/Makefile";
  410. pkgs = "";
  411. pkgs_file = TMPDIR "/pkgs_file";
  412. printf("") > pkgs_file;
  413. numpkg = 0;
  414. print "" > readme;
  415. while((getline < cat_make) > 0){
  416. if ($0 ~ /^[ \t]*SUBDIR.*=[^\$]*$/) {
  417. pkg = $0;
  418. gsub(/^[ \t]*SUBDIR.*=[ \t]*/, "",
  419. pkg);
  420. dir = category"/"pkg;
  421. numpkg++;
  422. tot_numpkg++;
  423. if (debug) {
  424. printf("\tAdding %s (%s : %s)\n",
  425. dir,
  426. pkgdir2name[dir],
  427. comment[dir]);
  428. }
  429. # pkgs = sprintf("%s<TR><TD VALIGN=TOP><a href=\"%s/%s\">%s</a>: %s<TD>\n",
  430. # pkgs, pkg, readme_name,
  431. # pkgdir2name[dir],
  432. # comment[dir]);
  433. # We use a temp file to hold the list of all packages because
  434. # this list can get very very large and
  435. # become larger than what some awk implementations can deal
  436. # with. The nawk shipped with solaris 9 is an example of
  437. # such a limited awk.
  438. printf("<TR><TD VALIGN=TOP><a href=\"%s/%s\">%s</a>: %s<TD>\n",
  439. pkg, readme_name,
  440. pkgdir2name[dir],
  441. comment[dir]) >> pkgs_file;
  442. allpkg[tot_numpkg] = sprintf("<!-- %s (for sorting) --><TR VALIGN=TOP><TD><a href=\"%s/%s/%s\">%s</a>: <TD>(<a href=\"%s/%s\">%s</a>) <td>%s\n",
  443. pkgdir2name[dir],
  444. category, pkg,
  445. readme_name,
  446. pkgdir2name[dir],
  447. category,
  448. readme_name,
  449. category,
  450. comment[dir]);
  451. # we need slightly fewer escapes here since we are not gsub()-ing
  452. # allpkg[] into the output files but just printf()-ing it.
  453. gsub(/\\&/, "\\&", allpkg[tot_numpkg]);
  454. } else if ($0 ~ /^[ \t]*COMMENT/) {
  455. descr = $0;
  456. gsub(/^[ \t]*COMMENT.*=[ \t]*/, "",
  457. descr);
  458. }
  459. }
  460. while ((getline < templatefile) > 0){
  461. gsub(/%%CATEGORY%%/, category);
  462. gsub(/%%NUMITEMS%%/, numpkg);
  463. gsub(/%%DESCR%%/, descr);
  464. line = $0
  465. if( $0 ~/%%SUBDIR%%/ ) {
  466. gsub(/%%SUBDIR%%/, "", line);
  467. while((getline < pkgs_file) > 0) {
  468. gsub(/README.html/, readme_name);
  469. print >> readme;
  470. }
  471. close( pkgs_file );
  472. }
  473. print line >> readme;
  474. }
  475. close(readme);
  476. close(templatefile);
  477. copy_readme(readmenew, readme);
  478. gsub(/href=\"/, "href=\""category"/", pkgs);
  479. allcat = sprintf("%s<TR><TD VALIGN=TOP><a href=\"%s/%s\">%s</a>: %s<TD>\n",
  480. allcat, category, readme_name,
  481. category, descr);
  482. close(cat_make);
  483. }
  484. }
  485. close(top_make);
  486. printf("Generating toplevel readmes:\n");
  487. templatefile = PKGSRCDIR "/templates/README.top";
  488. fatal_check_file(templatefile);
  489. readmenew = PKGSRCDIR "/"readme_name;
  490. printf("\t%s\n", readmenew);
  491. print "" > readme;
  492. while((getline < templatefile) > 0){
  493. gsub(/%%DESCR%%/, "");
  494. gsub(/%%SUBDIR%%/, allcat);
  495. gsub(/README.html/, readme_name);
  496. print >> readme;
  497. }
  498. close(readme);
  499. close(templatefile);
  500. copy_readme(readmenew, readme);
  501. templatefile = PKGSRCDIR "/templates/README.all";
  502. fatal_check_file(templatefile);
  503. readmenew = PKGSRCDIR "/README-all.html";
  504. printf("\t%s\n", readmenew);
  505. # sort the pkgs
  506. sfile = TMPDIR"/unsorted";
  507. spipe = "sort " sfile;
  508. i = 1;
  509. print "" >sfile;
  510. while(i in allpkg) {
  511. printf("%s",allpkg[i]) >> sfile;
  512. i++;
  513. }
  514. close(sfile);
  515. print "" > readme;
  516. while((getline < templatefile) > 0){
  517. line = $0;
  518. if ($0 ~ /%%PKGS%%/) {
  519. while((spipe | getline) > 0) {
  520. print >> readme;
  521. }
  522. close(spipe);
  523. } else {
  524. gsub(/%%DESCR%%/, "", line);
  525. gsub(/%%NPKGS%%/, tot_numpkg, line);
  526. gsub(/README.html/, readme_name, line);
  527. print line >> readme;
  528. }
  529. }
  530. close(readme);
  531. close(templatefile);
  532. copy_readme(readmenew, readme);
  533. close("/dev/stderr");
  534. exit 0;
  535. }
  536. function find_all_depends(pkg, type, pkgreg, i, deps, depdir, topdep){
  537. # pkg is the package directory, like math/scilab
  538. # printf("find_all_depends(%s, %s)\n", pkg, type);
  539. # if we find the package already has been fully depended
  540. # then return the depends list
  541. if (pkg in alldepends){
  542. if (debug) printf("\t%s is allready depended. Returning %s\n",
  543. pkg, alldepends[pkg]);
  544. return(alldepends[pkg]);
  545. }
  546. # if this package has no top dependencies, enter an empty flat dependency
  547. # list for it.
  548. if( type == "run" ) {
  549. # we only want DEPENDS
  550. topdep = topdepends[pkg];
  551. } else {
  552. # we want BUILD_DEPENDS and DEPENDS
  553. topdep = topdepends[pkg] " " topbuilddepends[pkg];
  554. }
  555. if (topdep ~ "^[ \t]*$") {
  556. alldepends[pkg] = " ";
  557. if (debug) printf("\t%s has no depends(%s). Returning %s\n",
  558. pkg, topdep, alldepends[pkg]);
  559. return(alldepends[pkg]);
  560. }
  561. # recursively gather depends that each of the depends has
  562. pkgreg = reg2str(pkg);
  563. split(topdep, deps);
  564. i = 1;
  565. alldepends[pkg] = " ";
  566. while ( i in deps ) {
  567. # figure out the directory name associated with the package hame
  568. # in (wild card/dewey) version form
  569. depdir = pat2dir[deps[i]];
  570. if (debug) printf("\tadding dependency #%d on \"%s\" (%s)\n",
  571. i, deps[i], depdir);
  572. # do not add ourselves to the list (should not happen, but
  573. # we would like to not get stuck in a loop if one exists)
  574. # if (" "deps[i]" " !~ pkgreg){
  575. # if we do not already have this dependency (deps[i]) listed, then add
  576. # it. However, we may have already added it because another package
  577. # we depend on may also have depended on
  578. # deps[i].
  579. if (alldepends[pkg] !~ reg2str(deps[i])){
  580. alldepends[pkg] = alldepends[pkg] " " deps[i] " " find_all_depends(depdir, type);
  581. }
  582. else {
  583. if (debug) printf("\t%s is already listed in %s\n",
  584. deps[i], alldepends[pkg]);
  585. }
  586. i = i + 1;
  587. } # while i
  588. if (debug) printf("\tcalling uniq() on alldepends[%s] = %s\n",
  589. pkg, alldepends[pkg]);
  590. alldepends[pkg] = uniq(alldepends[pkg]);
  591. if (debug) printf("\tuniq() output alldepends[%s] = %s\n",
  592. pkg, alldepends[pkg]);
  593. return(alldepends[pkg]);
  594. }
  595. #
  596. # take a string which has special characters like '+' in it and
  597. # escape them. Also put a space before and after since that's how
  598. # we'll distinguish things like gnome from gnome-libs
  599. #
  600. function reg2str(reg){
  601. gsub(/\./, "\\.", reg);
  602. gsub(/\+/, "\\+", reg);
  603. gsub(/\*/, "\\*", reg);
  604. gsub(/\?/, "\\?", reg);
  605. gsub(/\[/, "\\[", reg);
  606. gsub(/\]/, "\\]", reg);
  607. reg = " "reg" ";
  608. return(reg);
  609. }
  610. #
  611. # take a string which has a shell glob pattern and turn it into
  612. # an awk regular expression.
  613. #
  614. function glob2reg(reg){
  615. # escape some characters which are special in regular expressions
  616. gsub(/\./, "\\.", reg);
  617. gsub(/\+/, "\\+", reg);
  618. # and reformat some others
  619. gsub(/\*/, ".*", reg);
  620. gsub(/\?/, ".?", reg);
  621. # finally, expand {a,b,c} type patterns
  622. return(reg);
  623. }
  624. #
  625. # accepts a full path to a package directory, like "/usr/pkgsrc/math/scilab"
  626. # and returns just the last 2 directories, like "math/scilab"
  627. #
  628. function fulldir2pkgdir(d, i){
  629. i = match(d, /\/[^\/]+\/[^\/]+$/);
  630. return substr(d, i + 1);
  631. }
  632. #
  633. # take the depends lists and uniq them.
  634. #
  635. function uniq(list, deps, i, ulist){
  636. # split out the depends
  637. split(list, deps);
  638. i = 1;
  639. ulist = " ";
  640. while (i in deps){
  641. # printf("uniq(): Checking \"%s\"\n", ulist);
  642. # printf(" for \"%s\"\n", reg2str(deps[i]));
  643. if (ulist !~reg2str(deps[i])){
  644. ulist = ulist deps[i]" ";
  645. }
  646. i++;
  647. }
  648. return(ulist);
  649. }
  650. function fatal_check_file(file, cmd){
  651. cmd="test -f " file ;
  652. if (debug) printf("Execute: %s\n",cmd);
  653. if (system(cmd) != 0) {
  654. printf("**** FATAL ****\nRequired file %s does not exist\n",
  655. file) > "/dev/stderr";
  656. printf("**** ------- ****\n") > "/dev/stderr";
  657. close("/dev/stderr");
  658. exit(1);
  659. }
  660. }
  661. # 'new' is the newly created README.html file
  662. # 'old' is the existing (possibly not present) README.html file
  663. #
  664. # This function copies over the 'new' file if the 'old' one does
  665. # not exist or if they are different. In addition, the 'new' one
  666. # which is a temporary file is removed at the end
  667. function copy_readme(old, new, cmd, rc) {
  668. # if the README.html file does not exist at all then copy over
  669. # the one we created
  670. cmd = "if [ ! -f "old" ]; then cp " new " " old " ; fi";
  671. if (debug) printf("copy_readme() execute: %s\n",cmd);
  672. rc = system(cmd);
  673. if (rc != 0) {
  674. printf("**** WARNING ****\nThe command\n %s\n", cmd) > "/dev/stderr";
  675. printf("failed with result code %d\n", rc) > "/dev/stderr";
  676. printf("**** ------- ****\n") > "/dev/stderr";
  677. }
  678. # Compare the existing README.html file to the one we created. If they are
  679. # not the same, then copy over the one we created
  680. cmd = sprintf("%s -s %s %s ; if test $? -ne 0 ; then mv -f %s %s ; fi",
  681. CMP, new, old, new, old);
  682. if (debug) printf("copy_readme() execute: %s\n",cmd);
  683. rc = system(cmd);
  684. if (rc != 0) {
  685. printf("**** WARNING ****\nThe command\n %s\n", cmd) > "/dev/stderr";
  686. printf("failed with result code %d\n", rc) > "/dev/stderr";
  687. printf("**** ------- ****\n") > "/dev/stderr";
  688. }
  689. # If the temp file still exists, then delete it
  690. cmd = " if [ -f "new" ]; then rm -f "new" ; fi";
  691. if (debug) printf("copy_readme() execute: %s\n",cmd);
  692. rc = system(cmd);
  693. if (rc != 0) {
  694. printf("**** WARNING ****\nThe command\n %s\n", cmd) > "/dev/stderr";
  695. printf("failed with result code %d\n", rc) > "/dev/stderr";
  696. printf("**** ------- ****\n") > "/dev/stderr";
  697. }
  698. }
  699. function load_cache_file( file, pkgfile, opsys, osver, march, wk, rx ) {
  700. printf(" * %s\n", file);
  701. fatal_check_file( file );
  702. # read the cache file
  703. while( getline < file ) {
  704. # if this line points to another cache file, then recursively
  705. # load it
  706. if( $0 ~ /^pkgcache_cachefile/ ) {
  707. if( debug ) printf("\tFound pkgcache_cachefile line.\n");
  708. load_cache_file( $2 );
  709. } else if( $0 ~/^pkgcache_begin /) {
  710. pkgfile = $2;
  711. if( debug ) printf("\tStarting %s\n", pkgfile);
  712. opsys = "unknown";
  713. osver = "unknown";
  714. march = "unknown";
  715. pkgpath = "unknown";
  716. } else if( $0 ~/^PKGPATH=/ ) {
  717. pkgpath = $0;
  718. gsub(/PKGPATH=[ \t]*/, "", pkgpath);
  719. } else if( $0 ~/^OPSYS=/ ) {
  720. opsys = $0;
  721. gsub(/OPSYS=[ \t]*/, "", opsys);
  722. } else if( $0 ~/^OS_VERSION=/ ) {
  723. osver = $0;
  724. gsub(/OS_VERSION=[ \t]*/, "", osver);
  725. } else if( $0 ~/^MACHINE_ARCH=/ ) {
  726. march = $0;
  727. gsub(/MACHINE_ARCH=[ \t]*/, "", march);
  728. } else if( $0 ~/^pkgcache_end /) {
  729. if( debug ) printf("\t%s, OPSYS=%s, OS_VERSION=%s, MACHINE_ARCH=%s, PKGPATH=%s\n",
  730. pkgfile, opsys, osver, march, pkpath);
  731. pkg_count[pkgpath] = pkg_count[pkgpath] + 1;
  732. opsys_list[pkgpath, pkg_count[pkgpath]] = opsys;
  733. osver_list[pkgpath, pkg_count[pkgpath]] = osver;
  734. march_list[pkgpath, pkg_count[pkgpath]] = march;
  735. pkgfile_list[pkgpath, pkg_count[pkgpath]] = pkgfile;
  736. gsub(/.*\//, "", pkgfile);
  737. pkgnm_list[pkgpath, pkg_count[pkgpath]] = pkgfile;
  738. } else {
  739. # skip this line
  740. }
  741. }
  742. # close the cache file
  743. close( file );
  744. }
  745. function lookup_cache( d, binpkgs) {
  746. if( debug ) printf("lookup_cache( %s ): pkg_count = %d\n",
  747. d, pkg_count[d]);
  748. binpkgs_file = TMPDIR "/binpkgs";
  749. spipe = SORT " > " binpkgs_file;
  750. for(i=1 ; i<=pkg_count[d]; i=i+1) {
  751. printf("<TR><TD>%s:<TD><a href=\"%s/%s\">%s</a><TD>(%s %s)\n",
  752. march_list[d, i], PKG_URL, pkgfile_list[d, i], pkgnm_list[d, i],
  753. opsys_list[d, i], osver_list[d, i]) | spipe;
  754. }
  755. if( pkg_count[d] == 0 ) {
  756. printf("<TR><TD><EM>none</EM></TD></TR>\n") | spipe;
  757. }
  758. close( spipe );
  759. }