portlint.pl 61 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220
  1. #! /usr/bin/perl
  2. # ex:ts=4
  3. #
  4. # portlint - lint for port directory
  5. # implemented by:
  6. # Jun-ichiro itojun Hagino <itojun@itojun.org>
  7. # Yoshishige Arai <ryo2@on.rim.or.jp>
  8. #
  9. # Copyright(c) 1997 by Jun-ichiro Hagino <itojun@itojun.org>.
  10. # All rights reserved.
  11. # Freely redistributable. Absolutely no warranty.
  12. #
  13. # Please note that this perl code used to be able to handle (Open|Net|Free)BSD
  14. # bsd.port.mk. There are significant differences in those so you'll have
  15. # hard time upgrading this...
  16. # This code now mainly supports FreeBSD, but patches to update support for
  17. # OpenBSD and NetBSD will be accepted.
  18. #
  19. # $FreeBSD$
  20. # $Id$
  21. #
  22. use vars qw/ $opt_a $opt_A $opt_b $opt_c $opt_h $opt_t $opt_v $opt_M $opt_N $opt_B $opt_V /;
  23. use Getopt::Std;
  24. use File::Find;
  25. use IPC::Open2;
  26. #use strict;
  27. my ($err, $warn);
  28. my ($extrafile, $parenwarn, $committer, $verbose, $usetabs, $newport);
  29. my $contblank;
  30. my $portdir;
  31. my $makeenv = "";
  32. $err = $warn = 0;
  33. $extrafile = $parenwarn = $committer = $verbose = $usetabs = $newport = 0;
  34. $contblank = 1;
  35. $portdir = '.';
  36. # version variables
  37. my $major = 2;
  38. my $minor = 5;
  39. my $micro = 2;
  40. sub l { '[{(]'; }
  41. sub r { '[)}]'; }
  42. sub s { '[ \t]'; }
  43. my $l = &l;
  44. my $r = &r;
  45. my $s = &s;
  46. # default setting - for FreeBSD
  47. my $portsdir = '/usr/ports';
  48. my $rcsidstr = 'FreeBSD';
  49. my $multiplist = 0;
  50. my $ldconfigwithtrue = 0;
  51. my $rcsidinplist = 0;
  52. my $mancompress = 1;
  53. my $manstrict = 0;
  54. my $newxdef = 1;
  55. my $automan = 1;
  56. my $autoinfo = 1;
  57. my $manchapters = '123456789ln';
  58. my $localbase = '/usr/local';
  59. my %lang_pref = qw(
  60. arabic ar
  61. chinese zh
  62. french fr
  63. german de
  64. hebrew iw
  65. hungarian hu
  66. japanese ja
  67. korean ko
  68. polish pl
  69. portuguese pt
  70. russian ru
  71. ukrainian uk
  72. vietnamese vi
  73. );
  74. my @lang_cat = keys %lang_pref;
  75. my @lang_short = values %lang_pref;
  76. my $re_lang_short = '(' . join('|', @lang_short) . ')-';
  77. my ($prog) = ($0 =~ /([^\/]+)$/);
  78. sub usage {
  79. print STDERR <<EOF;
  80. usage: $prog [-AabchvtN] [-M ENV] [-B#] [port_directory]
  81. -a additional check for scripts/* and pkg-*
  82. -A turn on all additional checks (equivalent to -abcNt)
  83. -b warn \$(VARIABLE)
  84. -c committer mode
  85. -h show summary of command line options
  86. -v verbose mode
  87. -t nit pick about use of spaces
  88. -N writing a new port
  89. -V print the version and exit
  90. -M ENV set make variables to ENV (ex. PORTSDIR=/usr/ports.work)
  91. -B# allow # contiguous blank lines (default: $contblank line)
  92. EOF
  93. exit 0;
  94. }
  95. sub version {
  96. print "$prog version $major.$minor.$micro\n";
  97. exit $major;
  98. }
  99. getopts('AabchtvB:M:NV');
  100. &usage if $opt_h;
  101. &version if $opt_V;
  102. $extrafile = 1 if $opt_a || $opt_A;
  103. $parenwarn = 1 if $opt_b || $opt_A;
  104. $committer = 1 if $opt_c || $opt_A;
  105. $verbose = 1 if $opt_v;
  106. $newport = 1 if $opt_N || $opt_A;
  107. $usetabs = 1 if $opt_t || $opt_A;
  108. $contblank = $opt_B if $opt_B;
  109. $makeenv = $opt_M if $opt_M;
  110. $portdir = $ARGV[0] ? $ARGV[0] : '.';
  111. # OS dependent configs
  112. # os portsdir rcsid mplist ldcfg plist-rcsid mancompresss strict localbase newxdef automan autoinfo
  113. my @osdep = split(/\n/, <<EOF);
  114. FreeBSD /usr/ports FreeBSD 0 0 0 1 0 /usr/local 1 1 1
  115. NetBSD /usr/pkgsrc NetBSD 1 1 1 0 1 /usr/pkg 0 0 0
  116. EOF
  117. my $osname = `uname -s`;
  118. $osname =~ s/\n$//;
  119. foreach my $i (@osdep) {
  120. if ($i =~ /^$osname\t(.*)/) {
  121. print "OK: found OS config for $osname.\n" if ($verbose);
  122. ($portsdir, $rcsidstr, $multiplist, $ldconfigwithtrue,
  123. $rcsidinplist, $mancompress, $manstrict, $localbase,
  124. $newxdef, $automan, $autoinfo)
  125. = split(/\t+/, $1);
  126. last;
  127. }
  128. }
  129. # The PORTSDIR environment variable overrides our defaults.
  130. $portsdir = $ENV{PORTSDIR} if ( defined $ENV{'PORTSDIR'} );
  131. if ($verbose) {
  132. print "OK: config: portsdir: \"$portsdir\" ".
  133. "rcsidstr: \"$rcsidstr\" ".
  134. "multiplist: $multiplist ".
  135. "ldconfigwithtrue: $ldconfigwithtrue ".
  136. "rcsidinplist: $rcsidinplist ".
  137. "mancompress: $mancompress ".
  138. "manstrict: $manstrict ".
  139. "localbase: $localbase ".
  140. "\n";
  141. }
  142. #
  143. # just for safety.
  144. #
  145. if (! -d $portdir) {
  146. print STDERR "FATAL: invalid directory $portdir specified.\n";
  147. exit 1;
  148. }
  149. chdir "$portdir" || die "$portdir: $!";
  150. # get make vars
  151. my @varlist = qw(
  152. PORTNAME PORTVERSION PORTREVISION PORTEPOCH PKGNAME PKGNAMEPREFIX
  153. PKGNAMESUFFIX DISTNAME DISTFILES CATEGORIES MASTERDIR MAINTAINER
  154. MASTER_SITES WRKDIR WRKSRC NO_WRKSUBDIR PATCHDIR SCRIPTDIR FILESDIR
  155. PKGDIR COMMENT DESCR PLIST PKGCATEGORY PKGINSTALL PKGDEINSTALL
  156. PKGREQ PKGMESSAGE MD5_FILE .CURDIR INSTALLS_SHLIB
  157. );
  158. my $cmd = join(' -V ', "make $makeenv MASTER_SITE_BACKUP=''", @varlist);
  159. my %makevar;
  160. my $i = 0;
  161. for (split(/\n/, `$cmd`)) {
  162. print "OK: makevar: $varlist[$i] = $_\n" if ($verbose);
  163. $makevar{$varlist[$i]} = $_;
  164. $i++;
  165. }
  166. #
  167. # variables for global checks.
  168. #
  169. my $sharedocused = 0;
  170. my %plistmanall = ();
  171. my %plistmangz = ();
  172. my %plistman = ();
  173. my %manlangs = ();
  174. my %predefined = ();
  175. # historical, no longer in FreeBSD's bsd.sites.mk
  176. foreach my $i (split(/\n/, <<EOF)) {
  177. GNU ftp://prep.ai.mit.edu/pub/gnu/%SUBDIR%/
  178. GNU ftp://wuarchive.wustl.edu/systems/gnu/%SUBDIR%/
  179. GNU ftp://ftp.ecrc.net/pub/gnu/%SUBDIR%/
  180. PERL_CPAN ftp://ftp.cdrom.com/pub/perl/CPAN/modules/by-module/%SUBDIR%/
  181. SUNSITE ftp://sunsite.unc.edu/pub/Linux/%SUBDIR%/
  182. SUNSITE ftp://ftp.funet.fi/pub/mirrors/sunsite.unc.edu/pub/Linux/%SUBDIR%/
  183. SUNSITE ftp://ftp.infomagic.com/pub/mirrors/linux/sunsite/%SUBDIR%/
  184. TEX_CTAN ftp://ftp.cdrom.com/pub/tex/ctan/%SUBDIR%/
  185. TEX_CTAN ftp://ftp.tex.ac.uk/public/ctan/tex-archive/%SUBDIR%/
  186. GNOME ftp://ftp.cybertrails.com/pub/gnome/%SUBDIR%/
  187. AFTERSTEP ftp://ftp.alpha1.net/pub/mirrors/ftp.afterstep.org/%SUBDIR%/
  188. AFTERSTEP ftp://casper.yz.yamagata-u.ac.jp/pub/X11/apps/afterstep/%SUBDIR%/
  189. WINDOWMAKER ftp://ftp.io.com/pub/%SUBDIR%/
  190. EOF
  191. my ($j, $k) = split(/\t+/, $i);
  192. $predefined{$k} = $j;
  193. }
  194. # Read bsd.sites.mk
  195. $sites_mk = "$portsdir/Mk/bsd.sites.mk";
  196. open(MK, $sites_mk) || die "$sites_mk: $!";
  197. my @site_groups = grep($_ = /^MASTER_SITE_(\w+)/ && $1, <MK>);
  198. close(MK);
  199. $cmd = join(' -V MASTER_SITE_', "make $makeenv -f - all", @site_groups);
  200. $i = 0;
  201. open2(IN, OUT, $cmd);
  202. print OUT <<EOF;
  203. all:
  204. # do nothing
  205. .include "$sites_mk"
  206. EOF
  207. close(OUT);
  208. while (<IN>) {
  209. my $g = $site_groups[$i];
  210. for my $s (split()) {
  211. $predefined{$s} = $g;
  212. }
  213. $i++;
  214. }
  215. close(IN);
  216. #
  217. # check for files.
  218. #
  219. my @checker = ($makevar{DESCR}, 'Makefile', $makevar{MD5_FILE});
  220. my %checker = (
  221. $makevar{DESCR} => 'checkdescr',
  222. 'Makefile' => 'checkmakefile',
  223. $makevar{MD5_FILE} => 'TRUE'
  224. );
  225. if ($extrafile) {
  226. my @files = (
  227. <$makevar{SCRIPTDIR}/*>,
  228. @makevar{DESCR,PLIST,PKGINSTALL,PKGDEINSTALL,PKGREQ,PKGMESSAGE}
  229. );
  230. foreach my $i (@files) {
  231. next if (! -T $i);
  232. next if (defined $checker{$i});
  233. if ($i =~ /\bpkg-plist$/
  234. || ($multiplist && $i =~ /\bpkg-plist/)) {
  235. unshift(@checker, $i);
  236. $checker{$i} = 'checkplist';
  237. } else {
  238. push(@checker, $i);
  239. $checker{$i} = 'checkpathname';
  240. }
  241. }
  242. }
  243. foreach my $i (<$makevar{PATCHDIR}/patch-*>) {
  244. next if (! -T $i);
  245. next if (defined $checker{$i});
  246. push(@checker, $i);
  247. $checker{$i} = 'checkpatch';
  248. }
  249. foreach my $i (@checker) {
  250. print "OK: checking $i.\n" if ($verbose);
  251. if (! -f "$i") {
  252. &perror("FATAL: no $i in \"$portdir\".") unless $i eq $makevar{MD5_FILE} && $makevar{DISTFILES} eq "";
  253. } else {
  254. my $proc = $checker{$i};
  255. &$proc($i) || &perror("Cannot open the file $i\n");
  256. if ($proc ne 'checkpatch') {
  257. &checklastline($i)
  258. || &perror("Cannot open the file $i\n");
  259. }
  260. }
  261. }
  262. # Check to make sure there is no pkg-comment file anymore.
  263. if (-f 'pkg-comment') {
  264. &perror("FATAL: Use of pkg-comment is obsolete. Use the COMMENT macro within the port's Makefile instead.");
  265. }
  266. if ($committer) {
  267. sub find_proc {
  268. return if /^\.\.?$/;
  269. (my $fullname = $File::Find::name) =~ s#^\./##;
  270. print "OK: checking the file name of $fullname.\n" if ($verbose);
  271. if ($fullname eq 'work') {
  272. &perror("FATAL: $fullname: be sure to cleanup the working directory ".
  273. "before committing the port.");
  274. $File::Find::prune = 1;
  275. } elsif (-l) {
  276. &perror("Warning: $fullname: this is a symlink. ".
  277. "CVS will ignore it.");
  278. } elsif (-z) {
  279. &perror("FATAL: $fullname: empty file and should be removed. ".
  280. "If it still needs to be there, put a dummy comment ".
  281. "to state that the file is intentionally left empty.");
  282. } elsif (-d && scalar(my @x = <$_/{*,.?*}>) <= 1) {
  283. &perror("FATAL: $fullname: empty directory should be removed.");
  284. } elsif (/^\./) {
  285. &perror("Warning: $fullname: dotfiles are not preferred. ".
  286. "If this file is a dotfile to be installed as an example, ".
  287. "consider importing it as \"dot$_\".");
  288. } elsif (/\.(orig|rej|bak)$/ || /~$/ || /^\#/) {
  289. &perror("FATAL: $fullname: for safety, be sure to cleanup ".
  290. "backup files before committing the port.");
  291. } elsif (/(^|\.)core$/) {
  292. &perror("FATAL: $fullname: for safety, be sure to cleanup ".
  293. "core files before committing the port.");
  294. } elsif ($_ eq 'CVS' && -d) {
  295. if ($newport) {
  296. &perror("FATAL: $fullname: for safety, be sure to cleanup ".
  297. "CVS directories before importing the new port.");
  298. }
  299. $File::Find::prune = 1;
  300. }
  301. }
  302. find(\&find_proc, '.');
  303. sub checksubdir {
  304. my $dir = shift;
  305. print "OK: checking CVS status of \"$dir\".\n" if ($verbose);
  306. opendir DIR, $dir;
  307. my @filenames = readdir DIR;
  308. closedir DIR;
  309. my %entries;
  310. if (-f "$dir/CVS/Entries") {
  311. open ENTRIES, "<$dir/CVS/Entries";
  312. while (<ENTRIES>) {
  313. chomp;
  314. my @entry = split /\//;
  315. if ($entry[0] eq 'D') {
  316. $entries{ $entry[1] } = $entry[0]
  317. if $entry[1];
  318. }
  319. elsif ($entry[0] eq '') {
  320. if ($entry[2] =~ /^-/) {
  321. $entries{ $entry[1] } = 'x';
  322. }
  323. elsif ($entry[2] eq '0') {
  324. $entries{ $entry[1] } = 'n';
  325. }
  326. else {
  327. $entries{ $entry[1] } = 'f';
  328. }
  329. }
  330. else {
  331. &perror("WARN: can not parse CVS line $_");
  332. }
  333. }
  334. close ENTRIES;
  335. } else {
  336. &perror("WARN: no CVS directories. Use -n to check a new port.");
  337. return;
  338. }
  339. if (-f "$dir/CVS/Entries.Log") {
  340. open ENTRIES, "<$dir/CVS/Entries.Log";
  341. while (<ENTRIES>) {
  342. chomp;
  343. my $cmd;
  344. my @entry = split /\//;
  345. if (/^(.) (.*)$/) {
  346. $cmd = $1;
  347. @entry = split /\//, $2;
  348. }
  349. else {
  350. $cmd = 'A';
  351. @entry = split /\//;
  352. }
  353. if ($cmd eq 'A') {
  354. if ($entry[0] eq 'D') {
  355. $entries{ $entry[1] } = $entry[0]
  356. if $entry[1];
  357. }
  358. elsif ($entry[0] eq '') {
  359. if ($entry[2] =~ /^-/) {
  360. $entries{ $entry[1] } = 'x';
  361. }
  362. elsif ($entry[2] eq '0') {
  363. $entries{ $entry[1] } = 'n';
  364. }
  365. else {
  366. $entries{ $entry[1] } = 'f';
  367. }
  368. }
  369. else {
  370. &perror("WARN: can not parse CVS line $_");
  371. }
  372. }
  373. elsif ($cmd eq 'R') {
  374. delete $entries{ $entry[1] }
  375. if $entry[1];
  376. }
  377. # ignore unknown commands
  378. }
  379. close ENTRIES;
  380. }
  381. foreach (@filenames) {
  382. next
  383. if /^(?:\.\.?|CVS)$/;
  384. my $filename = $dir eq '.' ? $_ : "$dir/$_";
  385. if (-d $filename) {
  386. if (!$entries{$_} || $entries{$_} ne 'D') {
  387. &perror("FATAL: directory $filename not in CVS.");
  388. }
  389. else {
  390. delete $entries{$_};
  391. checksubdir($filename);
  392. }
  393. }
  394. else {
  395. if (!$entries{$_}) {
  396. &perror("FATAL: file $filename not in CVS.");
  397. }
  398. elsif ($entries{$_} eq 'D') {
  399. &perror("FATAL: file $filename is a directory in CVS.");
  400. }
  401. elsif ($entries{$_} eq 'x') {
  402. &perror("FATAL: file $filename is deleted in CVS.");
  403. }
  404. elsif ($entries{$_} eq 'n') {
  405. if (!system("egrep", "-q", "\\\$$rcsidstr\[^\$\]+\\\$", $filename)) {
  406. &perror("WARN: RCS tag \"\$$rcsidstr\$\" ".
  407. "should be empty in new file $filename.");
  408. }
  409. delete $entries{$_};
  410. }
  411. else {
  412. delete $entries{$_};
  413. }
  414. }
  415. }
  416. while (my ($file, $type) = each %entries) {
  417. next if $type eq 'x';
  418. if ($type eq 'D') {
  419. &perror("FATAL: CVS directory $dir/$file missing");
  420. }
  421. else {
  422. &perror("FATAL: CVS file $dir/$file missing");
  423. }
  424. }
  425. }
  426. checksubdir('.')
  427. unless $newport;
  428. # Check for ports that may break INDEX
  429. my $indexerr = `env LOCALBASE=/nonexistentlocal X11BASE=/nonexistentx make $makeenv describe 2>&1 >/dev/null`;
  430. chomp $indexerr;
  431. $indexerr =~ tr/\n/ /s;
  432. &perror("FATAL: breaks INDEX ($indexerr).")
  433. if ($indexerr);
  434. }
  435. if ($err || $warn) {
  436. print "$err fatal errors and $warn warnings found.\n"
  437. } else {
  438. print "looks fine.\n";
  439. }
  440. exit $err;
  441. #
  442. # pkg-descr
  443. #
  444. sub checkdescr {
  445. my($file) = @_;
  446. my(%maxchars) = ($makevar{DESCR}, 80);
  447. my(%maxlines) = ($makevar{DESCR}, 24);
  448. my(%errmsg) = ($makevar{DESCR}, "exceeds $maxlines{$makevar{DESCR}} ".
  449. "lines, make it shorter if possible.");
  450. my($longlines, $linecnt, $tmp) = (0, 0, "");
  451. open(IN, "< $file") || return 0;
  452. while (<IN>) {
  453. $tmp .= $_;
  454. chomp || &perror("WARN: $file: should terminate in '\n'.");
  455. $linecnt++;
  456. $longlines++ if ($maxchars{$file} < length);
  457. }
  458. if ($linecnt > $maxlines{$file}) {
  459. &perror("WARN: $file $errmsg{$file}".
  460. "(currently $linecnt lines)");
  461. } else {
  462. print "OK: $file: has $linecnt lines.\n" if ($verbose);
  463. }
  464. if ($longlines > 0) {
  465. &perror("WARN: $file: includes lines that exceed $maxchars{$file} ".
  466. "characters.");
  467. }
  468. if ($tmp =~ /[\033\200-\377]/) {
  469. &perror("WARN: $file: includes iso-8859-1, or ".
  470. "other local characters. files should be in ".
  471. "plain 7-bit ASCII");
  472. }
  473. if ($file =~ /\bpkg-descr/ && $tmp =~ m,http://,) {
  474. my $has_url = 0;
  475. my $has_www = 0;
  476. foreach my $line (grep($_ =~ "http://", split(/\n+/, $tmp))) {
  477. $has_url = 1;
  478. if ($line =~ m,WWW:[ \t]+http://,) {
  479. $has_www = 1;
  480. }
  481. }
  482. if ($has_url && ! $has_www) {
  483. &perror("FATAL: $file: contains a URL but no \"WWW:\"");
  484. }
  485. }
  486. close(IN);
  487. }
  488. #
  489. # pkg-plist
  490. #
  491. sub checkplist {
  492. my($file) = @_;
  493. my($curdir) = ($localbase);
  494. my(%omfremoveseen) = ();
  495. my(%omfinstallseen) = ();
  496. my(%omfseen) = ();
  497. my($inforemoveseen, $infoinstallseen, $infoseen) = (0, 0, 0);
  498. my(%omfafterinstall) = ();
  499. my(%omfafterremove) = ();
  500. my($infobeforeremove, $infoafterinstall) = (0, 0);
  501. my($infooverwrite) = (0);
  502. my($rcsidseen) = (0);
  503. my(@exec_omf) = ();
  504. my(@exec_info) = ();
  505. my(@unexec_omf) = ();
  506. my(@unexec_info) = ();
  507. my(@omffile) = ();
  508. my(@infofile) = ();
  509. open(IN, "< $file") || return 0;
  510. while (<IN>) {
  511. if ($_ =~ /[ \t]+\n?$/) {
  512. &perror("WARN: $file [$.]: whitespace before end ".
  513. "of line.");
  514. }
  515. # make it easier to handle.
  516. $_ =~ s/\s+$//;
  517. $_ =~ s/\n$//;
  518. if ($osname eq 'NetBSD' && $_ =~ /<\$ARCH>/) {
  519. &perror("WARN: $file [$.]: use of <\$ARCH> deprecated, ".
  520. "use \${MACHINE_ARCH} instead.");
  521. }
  522. if (m'lib/perl5/site_perl/%%PERL_VER%%') {
  523. &perror("WARN: $file [$.]: use \%\%SITE_PERL\%\% ".
  524. "instead of lib/perl5/site_perl/\%\%PERL_VER\%\%.");
  525. }
  526. if ($_ =~ /^\@/) {
  527. if ($_ =~ /^\@(cwd|cd)[ \t]+(\S+)/) {
  528. $curdir = $2;
  529. } elsif ($_ =~ /^\@unexec[ \t]+rm[ \t]/) {
  530. if ($_ !~ /%[DB]/) {
  531. &perror("WARN: $file [$.]: use \"%D\" or \"%B\" to ".
  532. "specify prefix.");
  533. }
  534. if ($_ !~ /true$/ && $_ !~ /rm -f/) {
  535. &perror("WARN: $file [$.]: add \"2>&1 ".
  536. ">/dev/null || true\" ".
  537. "to \"\@unexec rm\".");
  538. }
  539. } elsif ($_ =~ /^\@unexec[ \t]+rmdir/) {
  540. if ($_ !~ /%[DB]/) {
  541. &perror("WARN: $file [$.]: use \"%D\" or \"%B\" to ".
  542. "specify prefix.");
  543. }
  544. if ($_ !~ /true$/) {
  545. &perror("WARN: $file [$.]: use \"\@dirrm\" ".
  546. "instead of \"\@unexec rmdir\".");
  547. }
  548. } elsif ($_ =~ /^\@exec[ \t]+scrollkeeper-install[ \t]+-q\s+(\S+)\s+.+$/) {
  549. push(@exec_omf, $1);
  550. my $ot = $1;
  551. $ot =~ s/^\%D\///;
  552. $omfinstallseen{$ot} = $.;
  553. } elsif (!$autoinfo && $_ =~ /^\@exec[ \t]+install-info\s+(.+)\s+(.+)$/) {
  554. $infoinstallseen = $.;
  555. push(@exec_info, $1);
  556. } elsif ($autoinfo && $_ =~ /^\@exec[ \t]+install-info\s+(.+)\s+(.+)$/) {
  557. &perror("WARN: $file [$.]: \@exec install-info is deprecated in favor of adding info files into the Makefile using the INFO macro.");
  558. } elsif ($_ =~ /^\@unexec[ \t]+scrollkeeper-uninstall[ \t]+-q\s+(\S+)\s+.+$/) {
  559. push(@unexec_omf, $1);
  560. my $ot = $1;
  561. $ot =~ s/^\%D\///;
  562. $omfremoveseen{$ot} = $.;
  563. } elsif (!$autoinfo && $_ =~ /^\@unexec[ \t]+install-info[ \t]+--delete\s+(.+)\s+(.+)$/) {
  564. $inforemoveseen = $.;
  565. push(@unexec_info, $1);
  566. } elsif ($autoinfo && $_ =~ /^\@unexec[ \t]+install-info[ \t]+--delete\s+(.+)\s+(.+)$/) {
  567. &perror("WARN: $file [$.]: \@unexec install-info is deprecated in favor of adding info files into the Makefile using the INFO macro.");
  568. } elsif ($_ =~ /^\@(exec|unexec)/) {
  569. if (/ldconfig/) {
  570. if ($ldconfigwithtrue
  571. && !/\/usr\/bin\/true/) {
  572. &perror("FATAL: $file [$.]: ldconfig ".
  573. "must be used with ".
  574. "\"||/usr/bin/true\".");
  575. }
  576. &perror("WARN: $file [$.]: possible ".
  577. "direct use of ldconfig ".
  578. "in PLIST found. use ".
  579. "INSTALLS_SHLIB instead.");
  580. }
  581. } elsif ($_ =~ /^\@(comment)/) {
  582. $rcsidseen++ if (/\$$rcsidstr[:\$]/);
  583. } elsif ($_ =~ /^\@(owner|group)\s/) {
  584. &perror("WARN: $file [$.]: \@$1 should not be needed");
  585. } elsif ($_ =~ /^\@(dirrm|option)/) {
  586. ; # no check made
  587. } else {
  588. &perror("WARN: $file [$.]: ".
  589. "unknown pkg-plist directive \"$_\"");
  590. }
  591. next;
  592. }
  593. if ($_ =~ /^\//) {
  594. &perror("FATAL: $file [$.]: use of full pathname ".
  595. "disallowed.");
  596. }
  597. if ($_ =~ /\.la$/) {
  598. &perror("WARN: $file [$.]: installing libtool archives, ".
  599. "please use USE_LIBTOOL in Makefile if possible");
  600. }
  601. if ($_ =~ /\.so(\.\d+)?$/ && $makevar{INSTALLS_SHLIB} eq '') {
  602. &perror("WARN: $file [$.]: installing shared libraries, ".
  603. "please define INSTALLS_SHLIB as appropriate");
  604. }
  605. if ($autoinfo && $_ =~ /\.info$/) {
  606. &perror("WARN: $file [$.]: enumerating info files in the plist is deprecated in favor of adding info files into the Makefile using the INFO macro.");
  607. }
  608. if ($autoinfo && $_ =~ /\.info-\d+$/) {
  609. &perror("FATAL: $file [$.]: numbered info files are obsolete and not portable; add info files using the INFO macro in the Makefile.");
  610. }
  611. if ($_ =~ /.*\.omf$/) {
  612. $omfseen{$_} = $.;
  613. $omfafterinstall{$_}++ if ($omfinstallseen{$_});
  614. $omfafterremove{$_}++ if ($omfremoveseen{$_});
  615. push(@omffile, $_);
  616. }
  617. if (!$autoinfo) {
  618. if ($_ =~ /^info\/.*info(-[0-9]+)?$/) {
  619. $infoseen = $.;
  620. $infoafterinstall++ if ($infoinstallseen);
  621. $infobeforeremove++ if (!$inforemoveseen);
  622. push(@infofile, $_);
  623. }
  624. if ($_ =~ /^info\/dir$/) {
  625. &perror("FATAL: $file [$.]: \"info/dir\" should not be listed.".
  626. "use install-info to add/remove ".
  627. "an entry.");
  628. $infooverwrite++;
  629. }
  630. }
  631. if ($_ =~ /^(\%\%PORTDOCS\%\%)?share\/doc\//) {
  632. &perror("WARN: $file [$.]: consider using DOCSDIR macro");
  633. $sharedocused++;
  634. } elsif ($_ =~ /^(\%\%PORTDOCS\%\%)?\%\%DOCSDIR\%\%/) {
  635. $sharedocused++;
  636. }
  637. if ($_ =~ /^share\/examples\//) {
  638. &perror("WARN: $file [$.]: consider using EXAMPLESDIR macro");
  639. }
  640. if ($_ =~ m#man/([^/]+/)?man([$manchapters])/([^\.]+\.[$manchapters])(\.gz)?$#) {
  641. if ($4 eq '') {
  642. $plistman{$2} .= ' ' . $3;
  643. if ($mancompress) {
  644. &perror("FATAL: $file [$.]: ".
  645. "unpacked man file $3 ".
  646. "listed. must be gzipped.");
  647. }
  648. } else {
  649. $plistmangz{$2} .= ' ' . $3;
  650. if (!$mancompress) {
  651. &perror("FATAL: $file [$.]: ".
  652. "gzipped man file $3$4 ".
  653. "listed. unpacked one should ".
  654. "be installed.");
  655. }
  656. }
  657. $plistmanall{$2} .= ' ' . $3;
  658. if ($1 ne '') {
  659. $manlangs{substr($1, 0, length($1) - 1)}++;
  660. }
  661. }
  662. if ($curdir !~ m#^$localbase#
  663. && $curdir !~ m#^/usr/X11R6#) {
  664. &perror("WARN: $file [$.]: installing to ".
  665. "directory $curdir discouraged. ".
  666. "could you please avoid it?");
  667. }
  668. if ("$curdir/$_" =~ m#^$localbase/share/doc#) {
  669. print "OK: $file [$.]: seen installation to share/doc. ".
  670. "($curdir/$_)\n" if ($verbose);
  671. $sharedocused++;
  672. }
  673. }
  674. # Check that each OMF file has an install and deinstall line.
  675. my $omf_install = join(" ", @exec_omf);
  676. $omf_install .= ' ';
  677. my $omf_deinstall = join(" ", @unexec_omf);
  678. $omf_deinstall .= ' ';
  679. foreach my $of (@omffile) {
  680. if ($omf_install !~ /\%D\/\Q$of\E/) {
  681. &perror("FATAL: $file: you need an '\@exec scrollkeeper-install -q \%D/$of 2>/dev/null || /usr/bin/true' line");
  682. }
  683. if ($omf_deinstall !~ /\%D\/$of/) {
  684. &perror("FATAL: $file: you need an '\@unexec scrollkeeper-uninstall -q \%D/$of 2>/dev/null || /usr/bin/true' line");
  685. }
  686. }
  687. if (!$autoinfo) {
  688. # check that every infofile has an exec install-info and unexec install-info
  689. my $exec_install = join(" ", @exec_info);
  690. $exec_install .= ' ';
  691. my $unexec_install = join(" ", @unexec_info);
  692. $unexec_install .= ' ';
  693. foreach my $if (@infofile) {
  694. next if ($if =~ m/info-/);
  695. if ($exec_install !~ m/\%D\/\Q$if\E/) {
  696. &perror("FATAL: $file: you need an '\@exec install-info \%D/$if \%D/info/dir' line");
  697. }
  698. if ($unexec_install !~ m/\%D\/$if/) {
  699. &perror("FATAL: $file: you need an '\@unexec install-info --delete \%D/$if \%D/info/dir' line");
  700. }
  701. }
  702. }
  703. if ($rcsidinplist && !$rcsidseen) {
  704. &perror("FATAL: $file: RCS tag \"\$$rcsidstr\$\" must be present ".
  705. "as \@comment.")
  706. }
  707. if (((!$autoinfo && !$infoseen) || $autoinfo) && !scalar(keys %omfseen)) {
  708. close(IN);
  709. return 1;
  710. }
  711. if (scalar(keys %omfseen)) {
  712. if (!scalar(keys %omfinstallseen)) {
  713. &perror("FATAL: $file: scrollkeeper-install must be used to ".
  714. "add/delete entries from the ScrollKeeper OMF database.");
  715. } else {
  716. foreach my $of (keys %omfseen) {
  717. if ($omfafterinstall{$of}) {
  718. &perror("FATAL: $file [$omfinstallseen{$of}]: move ".
  719. "\"\@exec scrollkeeper-install\" ".
  720. "line to make sure that it is placed after ".
  721. "the $of entry.");
  722. }
  723. }
  724. }
  725. if (!scalar(keys %omfremoveseen)) {
  726. &perror("FATAL: $file: \"\@unexec scrollkeeper-uninstall\" must ".
  727. "be placed after the OMF file it uninstalls.");
  728. } else {
  729. foreach my $of (keys %omfseen) {
  730. if ($omfafterremove{$of}) {
  731. &perror("FATAL: $file [$omfremoveseen{$of}]: move ".
  732. "\"\@unexec scrollkeeper-uninstall\" ".
  733. "line to make sure that it is placed after ".
  734. "the $of entry.");
  735. }
  736. }
  737. }
  738. }
  739. if (!$autoinfo && $infoseen) {
  740. if (!$infoinstallseen) {
  741. if ($infooverwrite) {
  742. &perror("FATAL: $file: install-info must be used to ".
  743. "add/delete entries into \"info/dir\".");
  744. }
  745. &perror("FATAL: $file: \"\@exec install-info \%D/... \%D/info/dir\" must be placed ".
  746. "after all the info files.");
  747. } elsif ($infoafterinstall) {
  748. &perror("FATAL: $file [$infoinstallseen]: move ".
  749. "\"\@exec install-info\" line to make ".
  750. "sure that it is placed after all the info files.");
  751. }
  752. if (!$inforemoveseen) {
  753. &perror("FATAL: $file: \"\@unexec install-info --delete \%D/... \%D/info/dir\" must ".
  754. "be placed before any of the info files listed.");
  755. } elsif ($infobeforeremove) {
  756. &perror("FATAL: $file [$inforemoveseen]: move ".
  757. "\"\@exec install-info --delete\" ".
  758. "line to make sure ".
  759. "that it is placed before any of the info files. ");
  760. }
  761. }
  762. close(IN);
  763. }
  764. #
  765. # misc files
  766. #
  767. sub checkpathname {
  768. my($file) = @_;
  769. my($whole);
  770. open(IN, "< $file") || return 0;
  771. $whole = '';
  772. while (<IN>) {
  773. $whole .= $_;
  774. }
  775. &abspathname($whole, $file);
  776. close(IN);
  777. }
  778. sub checklastline {
  779. my($file) = @_;
  780. my($whole);
  781. open(IN, "< $file") || return 0;
  782. $whole = '';
  783. while (<IN>) {
  784. $whole .= $_;
  785. }
  786. if ($whole !~ /\n$/) {
  787. &perror("FATAL: $file: the last line has to be ".
  788. "terminated by \\n.");
  789. }
  790. if ($whole =~ /\n([ \t]*\n)+$/) {
  791. &perror("WARN: $file: seems to have unnecessary blank lines ".
  792. "at the last part.");
  793. }
  794. close(IN);
  795. }
  796. sub checkpatch {
  797. my($file) = @_;
  798. my($whole);
  799. if (-z "$file") {
  800. &perror("FATAL: $file: has no content. should be removed ".
  801. "from repository.");
  802. return;
  803. }
  804. open(IN, "< $file") || return 0;
  805. $whole = '';
  806. while (<IN>) {
  807. $whole .= $_;
  808. }
  809. if ($committer && $whole =~ /\$([A-Za-z0-9]+)[:\$]/) {
  810. my $lineno = &linenumber($`);
  811. &perror("WARN: $file [$lineno]: includes possible RCS tag \"\$$1\$\". ".
  812. "use binary mode (-ko) on commit/import.") unless
  813. $1 eq $rcsidstr;
  814. }
  815. close(IN);
  816. }
  817. #
  818. # Makefile
  819. #
  820. sub checkmakefile {
  821. my($file) = @_;
  822. my($rawwhole, $whole, $idx, @sections);
  823. my($i, $j, $k, $l);
  824. my @cat = ();
  825. my $has_lang_cat = 0;
  826. my $port_lang = '';
  827. my $tmp;
  828. my $bogusdistfiles = 0;
  829. my @varnames = ();
  830. my($portname, $portversion, $distfiles, $distname, $extractsufx) = ('', '', '', '', '');
  831. my $masterport = 0;
  832. my $slaveport = 0;
  833. my $use_gnome_hack = 0;
  834. my($realwrksrc, $wrksrc, $nowrksubdir) = ('', '', '');
  835. my(@mman, @pman);
  836. open(IN, "< $file") || return 0;
  837. $rawwhole = '';
  838. $tmp = 0;
  839. while (<IN>) {
  840. if ($_ =~ /[ \t]+\n?$/) {
  841. &perror("WARN: $file [$.]: whitespace before ".
  842. "end of line.");
  843. }
  844. if ($_ =~ /^ /) { # 8 spaces here!
  845. &perror("WARN: $file [$.]: use tab (not space) to make ".
  846. "indentation");
  847. }
  848. if ($usetabs) {
  849. if (m/^[A-Za-z0-9_-]+.?= /) {
  850. if (m/[?+]=/) {
  851. &perror("WARN: $file [$.]: use a tab (not space) after a ".
  852. "variable name");
  853. } else {
  854. &perror("FATAL: $file [$.]: use a tab (not space) after a ".
  855. "variable name");
  856. }
  857. }
  858. }
  859. #
  860. # I'm still not very convinced, for using this kind of magical word.
  861. # 1. This kind of items are not important for Makefile;
  862. # portlint should not require any additional rule to Makefile.
  863. # portlint should simply implement items that are declared in Handbook.
  864. # 2. If we have LINTSKIP, we can't stop people using LINTSKIP too much.
  865. # IMHO it is better to warn the user and let the user think twice,
  866. # than let the user escape from portlint.
  867. # Uncomment this part if you are willing to use these magical words.
  868. # Thu Jun 26 11:37:56 JST 1997
  869. # -- itojun
  870. #
  871. # if ($_ =~ /^# LINTSKIP\n?$/) {
  872. # print "OK: skipping from line $. in $file.\n"
  873. # if ($verbose);
  874. # $tmp = 1;
  875. # next;
  876. # }
  877. # if ($_ =~ /^# LINTAGAIN\n?$/) {
  878. # print "OK: check start again from line $. in $file.\n"
  879. # if ($verbose);
  880. # $tmp = 0;
  881. # next;
  882. # }
  883. # if ($_ =~ /# LINTIGNORE/) {
  884. # print "OK: ignoring line $. in $file.\n" if ($verbose);
  885. # next;
  886. # }
  887. # next if ($tmp);
  888. $rawwhole .= $_;
  889. }
  890. close(IN);
  891. #
  892. # whole file: blank lines.
  893. #
  894. $whole = "\n" . $rawwhole;
  895. study $whole;
  896. print "OK: checking contiguous blank lines in $file.\n"
  897. if ($verbose);
  898. $i = "\n" x ($contblank + 2);
  899. if ($whole =~ /$i/) {
  900. my $lineno = &linenumber($`);
  901. &perror("FATAL: $file [$lineno]: contiguous blank lines ".
  902. "(> $contblank lines) found.");
  903. }
  904. #
  905. # whole file: $(VARIABLE)
  906. #
  907. if ($parenwarn) {
  908. print "OK: checking for \$(VARIABLE).\n" if ($verbose);
  909. if ($whole =~ /\$\([\w\d]+\)/) {
  910. my $lineno = &linenumber($`);
  911. &perror("WARN: $file [$lineno]: use \${VARIABLE}, instead of ".
  912. "\$(VARIABLE).");
  913. }
  914. }
  915. #
  916. # whole file: USE_* used too late
  917. #
  918. pos($whole) = 0;
  919. if ($whole =~ /^\.include\s+<bsd\.port\.pre\.mk>$/gm) {
  920. print "OK: checking for USE_* used too late.\n" if ($verbose);
  921. my @use_early = qw(
  922. APACHE
  923. GNUSTEP
  924. IMAKE
  925. JAVA
  926. KDE(?:BASE|LIBS)_VER
  927. LIBRUBY
  928. LINUX_PREFIX
  929. OPENSSL
  930. PYTHON
  931. QT2?
  932. QT_VER
  933. RUBY
  934. X_PREFIX
  935. );
  936. my @other_early = qw(
  937. EMACS_PORT_NAME
  938. );
  939. my $earlypattern = join('|', 'USE_(?:'.join('|', @use_early).')',
  940. @other_early);
  941. while ($whole =~ /^($earlypattern)[+?:!]?=/gmo) {
  942. my $lineno = &linenumber($`);
  943. &perror("FATAL: $file [$lineno]: $1 is set after ".
  944. "including bsd.port.pre.mk.");
  945. }
  946. }
  947. #
  948. # whole file: anything after bsd.port(.post).mk
  949. #
  950. print "OK: checking for anything after bsd.port(.post).mk.\n"
  951. if ($verbose);
  952. if ($whole =~ /^\.include\s+<bsd\.port(?:\.post)\.mk>\s*[^\s]/m) {
  953. &perror("FATAL: $file: do not include anything after ".
  954. "bsd.port(.post).mk.");
  955. }
  956. #
  957. # whole file: USE_* as a user-settable option
  958. #
  959. print "OK: checking for USE_* as a user-settable option.\n" if ($verbose);
  960. while ($whole =~ /\n\s*\.\s*(?:el)?if[^\n]*?\b(\w*USE_)(\w+)(?\![^\n]*\n#?\.error)/g) {
  961. my $lineno = &linenumber($`);
  962. &perror("WARN: $file [$lineno]: is $1$2 a user-settable option? ".
  963. "Consider using WITH_$2 instead.")
  964. if ($1.$2 ne 'USE_GCC');
  965. }
  966. #
  967. # whole file: NO_CHECKSUM
  968. #
  969. # XXX Don't compress newlines since it messes up line number calculation.
  970. #$whole =~ s/\n#[^\n]*/\n/g;
  971. #$whole =~ s/\n\n+/\n/g;
  972. print "OK: checking NO_CHECKSUM.\n" if ($verbose);
  973. if ($whole =~ /\nNO_CHECKSUM/) {
  974. my $lineno = &linenumber($`);
  975. &perror("FATAL: $file [$lineno]: use of NO_CHECKSUM discouraged. ".
  976. "it is intended to be a user variable.");
  977. }
  978. #
  979. # whole file: PKGNAME
  980. #
  981. print "OK: checking PKGNAME.\n" if ($verbose);
  982. if ($whole =~ /\nPKGNAME.?=/) {
  983. my $lineno = &linenumber($`);
  984. &perror("FATAL: $file [$lineno]: PKGNAME is obsoleted by PORTNAME, ".
  985. "PORTVERSION, PKGNAMEPREFIX and PKGNAMESUFFIX.");
  986. }
  987. #
  988. # whole file: IS_INTERACTIVE/NOPORTDOCS
  989. #
  990. print "OK: checking IS_INTERACTIVE.\n" if ($verbose);
  991. if ($whole =~ /\nIS_INTERACTIVE/) {
  992. if ($whole !~ /defined\((BATCH|FOR_CDROM)\)/) {
  993. my $lineno = &linenumber($`);
  994. &perror("WARN: $file [$lineno]: use of IS_INTERACTIVE ".
  995. "discouraged. provide batch mode by using BATCH and/or ".
  996. "FOR_CDROM.");
  997. }
  998. }
  999. print "OK: checking for use of NOPORTDOCS.\n" if ($verbose);
  1000. if ($whole =~ /NOPORTSDOC/) {
  1001. my $lineno = &linenumber($`);
  1002. &perror("WARN: $file [$lineno]: NOPORTSDOC found. Do you ".
  1003. "mean NOPORTDOCS?");
  1004. }
  1005. if ($sharedocused && $whole !~ /defined\s*\(?NOPORTDOCS\)?/
  1006. && $whole !~ /def\s*\(?NOPORTDOCS\)?/
  1007. && $whole !~ m#(\$[\{\(]PREFIX[\}\)]|$localbase)/share/doc#) {
  1008. &perror("WARN: $file: use \".if !defined(NOPORTDOCS)\" to wrap ".
  1009. "installation of files into $localbase/share/doc.");
  1010. }
  1011. #
  1012. # whole file: direct use of command names
  1013. #
  1014. my %cmdnames = ();
  1015. print "OK: checking direct use of command names.\n" if ($verbose);
  1016. foreach my $i (qw(
  1017. awk basename cat chmod chown cp echo expr false file find gmake grep gzcat
  1018. ldconfig ln md5 mkdir mv patch perl rm rmdir ruby sed sh touch tr which xargs xmkmf
  1019. )) {
  1020. $cmdnames{$i} = "\$\{\U$i\E\}";
  1021. }
  1022. $cmdnames{'env'} = '${SETENV}';
  1023. $cmdnames{'gunzip'} = '${GUNZIP_CMD}';
  1024. $cmdnames{'gzip'} = '${GZIP_CMD}';
  1025. $cmdnames{'install'} = '${INSTALL_foobaa}';
  1026. $cmdnames{'python'} = '${PYTHON_CMD}';
  1027. $cmdnames{'strip'} = '${STRIP_CMD}';
  1028. foreach my $i (qw(aclocal autoconf autoheader automake autoreconf autoupdate autoscan ifnames libtool libtoolize)) {
  1029. $autocmdnames{$i} = "\$\{" . ( ( $i !~ /auto|aclocal|libtool/ ) ? "AUTO" : "" ) . "\U$i\E\}";
  1030. }
  1031. #
  1032. # ignore parameter string to echo command.
  1033. # note that we leave the command as is, since we need to check the
  1034. # use of echo itself.
  1035. $j = $whole;
  1036. $j =~ s/([ \t][\@\-]{0,2})(echo|\$[\{\(]ECHO[\}\)]|\$[\{\(]ECHO_MSG[\}\)])[ \t]+("(\\'|\\"|[^"])*"|'(\\'|\\"|[^'])*')[ \t]*;?(\n?)/$1$2;$3/g; #"
  1037. foreach my $i (keys %cmdnames) {
  1038. # XXX This is a hack. Really, we should break $j up into individual
  1039. # lines, and go through each one.
  1040. while ($j =~ /^(.*$i.*)$/gm) {
  1041. my $curline = $1;
  1042. my $lineno = &linenumber($`);
  1043. if ($curline =~ /(^|\s+)[\@\-]{0,2}$i\b/
  1044. && $curline !~ /^[A-Z]+_TARGET[?+]?=[^\n]+$i/m
  1045. && $curline !~ /^IGNORE(.)?=[^\n]+$i/m
  1046. && $curline !~ /^BROKEN(.)?=[^\n]+$i/m
  1047. && $curline !~ /^RESTRICTED(.)?=[^\n]+$i/m
  1048. && $curline !~ /^NO_PACKAGE(.)?=[^\n]+$i/m
  1049. && $curline !~ /^NO_CDROM(.)?=[^\n]+$i/m
  1050. && $curline !~ /^CATEGORIES(.)?=[^\n]+$i/m
  1051. && $curline !~ /^COMMENT(.)?=[^\n]+$i/m) {
  1052. &perror("WARN: $file [$lineno]: possible direct use of ".
  1053. "command \"$i\" found. use ".
  1054. "$cmdnames{$i} instead.");
  1055. }
  1056. }
  1057. }
  1058. foreach my $i (keys %autocmdnames) {
  1059. # XXX Same hack as above.
  1060. while ($j =~ /^(.*($i\d*).*)$/gm) {
  1061. my $lm = $1;
  1062. my $sm = $2;
  1063. my $lineno = &linenumber($`);
  1064. if ($lm =~ /(^|\s+)[\@\-]{0,2}($i\d*)\b/
  1065. && $lm !~ /^[A-Z]+_TARGET[?+]?=[^\n]+($i\d*)/m
  1066. && $lm !~ /^IGNORE(.)?=[^\n]+($i\d*)/m
  1067. && $lm !~ /^BROKEN(.)?=[^\n]+($i\d*)/m
  1068. && $lm !~ /^RESTRICTED(.)?=[^\n]+($i\d*)/m
  1069. && $lm !~ /^NO_PACKAGE(.)?=[^\n]+($i\d*)/m
  1070. && $lm !~ /^NO_CDROM(.)?=[^\n]+($i\d*)/m
  1071. && $lm !~ /^CATEGORIES(.)?=[^\n]+($i\d*)/m
  1072. && $lm !~ /^COMMENT(.)?=[^\n]+($i\d*)/m) {
  1073. &perror("WARN: $file [$lineno]: possible direct use of ".
  1074. "command \"$sm\" found. Use $autocmdnames{$i} ".
  1075. "instead and set according USE_*_VER= flag");
  1076. }
  1077. }
  1078. }
  1079. #
  1080. # whole file: ldconfig must come with "true" command
  1081. #
  1082. if ($ldconfigwithtrue
  1083. && $j =~ /(ldconfig|\$[{(]LDCONFIG[)}])/
  1084. && $j !~ /(\/usr\/bin\/true|\$[{(]TRUE[)}])/) {
  1085. my $lineno = &linenumber($`);
  1086. &perror("FATAL: $file [$lineno]: ldconfig must be used with ".
  1087. "\"||\${TRUE}\".");
  1088. }
  1089. #
  1090. # whole file: ${GZIP_CMD} -9 (or any other number)
  1091. #
  1092. if ($j =~ /\${GZIP_CMD}\s+-(\w+(\s+-)?)*(\d)/) {
  1093. my $lineno = &linenumber($`);
  1094. &perror("WARN: $file [$lineno]: possible use of \"\${GZIP_CMD} -$3\" ".
  1095. "found. \${GZIP_CMD} includes \"-\${GZIP}\" which ".
  1096. "sets the compression level.");
  1097. }
  1098. #
  1099. # whole file: ${MKDIR} -p
  1100. #
  1101. if ($j =~ /\${MKDIR}\s+-p/) {
  1102. my $lineno = &linenumber($`);
  1103. &perror("WARN: $file [$lineno]: possible use of \"\${MKDIR} -p\" ".
  1104. "found. \${MKDIR} includes ".
  1105. "\"-p\" by default.");
  1106. }
  1107. #
  1108. # whole file: full path name
  1109. #
  1110. &abspathname($whole, $file);
  1111. #
  1112. # whole file: SITE_PERL
  1113. #
  1114. print "OK: checking SITE_PERL.\n" if ($verbose);
  1115. if ($whole =~ /\nSITE_PERL[?:]?=/) {
  1116. my $lineno = &linenumber($`);
  1117. &perror("FATAL: $file [$lineno]: use of SITE_PERL discouraged. ".
  1118. "it is set in bsd.port.mk.");
  1119. }
  1120. #
  1121. # whole file: ${LOCALBASE}/lib/perl5/site_perl/${PERL_VER}
  1122. #
  1123. if ($j =~ m'\${(?:LOCALBASE|PREFIX)}/lib/perl5/site_perl/\${PERL_VER}') {
  1124. my $lineno = &linenumber($`);
  1125. &perror("WARN: $file [$lineno]: possible use of \"\${LOCALBASE}/lib/perl5/site_perl/\${PERL_VER}\" ".
  1126. "found. use \"\${SITE_PERL}\" instead.");
  1127. }
  1128. #
  1129. # whole file: USE_GNOME check
  1130. #
  1131. if ($whole =~ /^USE_GNOME[?:]?=\s*(.*)$/m) {
  1132. if ($1 =~ /gnomehack/) {
  1133. $use_gnome_hack = 1;
  1134. }
  1135. }
  1136. #
  1137. # whole file: check for deprecated USE_MESA
  1138. #
  1139. if ($whole =~ /^USE_MESA[?:]?=/m) {
  1140. my $lineno = &linenumber($`);
  1141. &perror("WARN: $file [$lineno]: USE_MESA is deprecated".
  1142. ". use USE_GL instead.");
  1143. }
  1144. #
  1145. # slave port check
  1146. #
  1147. my $masterdir = $makevar{MASTERDIR};
  1148. if ($masterdir ne '' && $masterdir ne $makevar{'.CURDIR'}) {
  1149. $slaveport = 1;
  1150. print "OK: slave port detected, checking for inclusion of $masterdir/Makefile.\n"
  1151. if ($verbose);
  1152. if ($whole !~ /\n\.include\s+[<"]\$\{MASTERDIR\}\/Makefile[">]\s*$/) {
  1153. &perror('FATAL: $file: the last line of a slave port\'s Makefile has to be'.
  1154. ' .include "${MASTERDIR}/Makefile"');
  1155. }
  1156. print "OK: checking master port in $masterdir.\n" if ($verbose);
  1157. if (! -e "$masterdir/Makefile") {
  1158. &perror("WARN: unable to locate master port in $masterdir");
  1159. }
  1160. }
  1161. #
  1162. # break the makefile into sections.
  1163. #
  1164. $tmp = $rawwhole;
  1165. # keep comment, blank line, comment in the same section
  1166. $tmp =~ s/(#.*\n)\n+(#.*)/$1$2/g;
  1167. @sections = split(/\n\n+/, $tmp);
  1168. for ($i = 0; $i <= $#sections; $i++) {
  1169. if ($sections[$i] !~ /\n$/) {
  1170. $sections[$i] .= "\n";
  1171. }
  1172. }
  1173. $idx = 0;
  1174. #
  1175. # section 1: comment lines.
  1176. #
  1177. print "OK: checking comment section of $file.\n" if ($verbose);
  1178. my @linestocheck = split("\n", <<EOF);
  1179. Whom
  1180. Date [cC]reated
  1181. EOF
  1182. if ($osname eq 'NetBSD') {
  1183. unshift(@linestocheck, '(New )?[pP](ackage|ort)s [cC]ollection [mM]akefile [fF]or');
  1184. } else {
  1185. unshift(@linestocheck, '(New )?[pP]orts [cC]ollection [mM]akefile [fF]or');
  1186. }
  1187. $tmp = $sections[$idx++];
  1188. $tmp = "\n" . $tmp; # to make the begin-of-line check easier
  1189. if ($tmp =~ /\n[^#]/) {
  1190. &perror("FATAL: $file: non-comment line in comment section.");
  1191. }
  1192. foreach my $i (@linestocheck) {
  1193. $j = $i;
  1194. $j =~ s/\(.*\)\?//g;
  1195. $j =~ s/\[(.)[^\]]*\]/$1/g;
  1196. if ($tmp !~ /# $i:[ \t]+\S+/) {
  1197. &perror("FATAL: $file: no \"$j\" line in comment section.");
  1198. } else {
  1199. print "OK: \"$j\" seen in $file.\n" if ($verbose);
  1200. }
  1201. }
  1202. if ($tmp =~ m/Version [rR]equired/) {
  1203. &perror("WARN: $file: Version required is no longer needed in the comment section.");
  1204. }
  1205. my $tmp2 = "";
  1206. for (split(/\n/, $tmp)) {
  1207. $tmp2 .= $_ if (m/\$$rcsidstr/);
  1208. }
  1209. if ($tmp2 !~ /#(\s+)\$$rcsidstr([^\$]*)\$$/) {
  1210. &perror("FATAL: $file: no \$$rcsidstr\$ line in comment ".
  1211. "section.");
  1212. } else {
  1213. print "OK: \$$rcsidstr\$ seen in $file.\n" if ($verbose);
  1214. if ($1 ne ' ') {
  1215. &perror("WARN: $file: please use single whitespace ".
  1216. "right before \$$rcsidstr\$ tag.");
  1217. }
  1218. if ($2 ne '') {
  1219. if ($verbose || $newport) { # XXX
  1220. &perror("WARN: $file: ".
  1221. ($newport ? 'for new port, '
  1222. : 'is it a new port? if so, ').
  1223. "make \$$rcsidstr\$ tag in comment ".
  1224. "section empty, to make CVS happy.");
  1225. }
  1226. }
  1227. }
  1228. #
  1229. # for the rest of the checks, comment lines are not important.
  1230. #
  1231. for ($i = 0; $i < scalar(@sections); $i++) {
  1232. $sections[$i] = "\n" . $sections[$i];
  1233. $sections[$i] =~ s/\n#[^\n]*//g;
  1234. $sections[$i] =~ s/\n\n+/\n/g;
  1235. $sections[$i] =~ s/\\\n/ /g;
  1236. $sections[$i] =~ s/^\n//;
  1237. }
  1238. #
  1239. #
  1240. # section 2: PORTNAME/PORTVERSION/...
  1241. #
  1242. print "OK: checking first section of $file (PORTNAME/...).\n"
  1243. if ($verbose);
  1244. $tmp = $sections[$idx++];
  1245. # check the order of items.
  1246. &checkorder('PORTNAME', $tmp, $file, qw(
  1247. PORTNAME PORTVERSION PORTREVISION PORTEPOCH CATEGORIES MASTER_SITES
  1248. MASTER_SITE_SUBDIR PKGNAMEPREFIX PKGNAMESUFFIX DISTNAME EXTRACT_SUFX
  1249. DISTFILES DIST_SUBDIR EXTRACT_ONLY
  1250. ));
  1251. # check the items that has to be there.
  1252. $tmp = "\n" . $tmp;
  1253. print "OK: checking PORTNAME/PORTVERSION.\n" if ($verbose);
  1254. if ($tmp !~ /\nPORTNAME(.)?=/) {
  1255. &perror("FATAL: $file: PORTNAME has to be there.") unless ($slaveport && $makevar{PORTNAME} ne '');
  1256. } elsif ($1 ne '') {
  1257. &perror("WARN: $file: unless this is a master port, PORTNAME has to be set by \"=\", ".
  1258. "not by \"$1=\".") unless ($masterport);
  1259. }
  1260. if ($tmp !~ /\nPORTVERSION(.)?=/) {
  1261. &perror("FATAL: $file: PORTVERSION has to be there.") unless ($slaveport && $makevar{PORTVERSION} ne '');
  1262. } elsif ($1 ne '') {
  1263. &perror("WARN: $file: unless this is a master port, PORTVERSION has to be set by \"=\", ".
  1264. "not by \"$1=\".") unless ($masterport);
  1265. }
  1266. if ($newport) {
  1267. print "OK: checking for existence of PORTREVISION in new port.\n"
  1268. if ($verbose);
  1269. if ($tmp =~ /^PORTREVISION(.)?=/m) {
  1270. &perror("WARN: $file: new ports should not set PORTREVISION.");
  1271. }
  1272. }
  1273. if ($newport) {
  1274. print "OK: checking for existence of PORTEPOCH in new port.\n"
  1275. if ($verbose);
  1276. if ($tmp =~ /^PORTEPOCH(.)?=/m) {
  1277. &perror("WARN: $file: new ports should not set PORTEPOCH.");
  1278. }
  1279. }
  1280. print "OK: checking CATEGORIES.\n" if ($verbose);
  1281. if ($tmp !~ /\nCATEGORIES(.)?=/) {
  1282. &perror("FATAL: $file: CATEGORIES has to be there.") unless ($slaveport && $makevar{CATEGORIES} ne '');
  1283. } elsif (($i = $1) ne '' && $i =~ /[^?+]/) {
  1284. &perror("WARN: $file: unless this is a master port, CATEGORIES should be set by \"=\", \"?=\", or \"+=\", ".
  1285. "not by \"$i=\".") unless ($masterport);
  1286. }
  1287. @cat = split(/\s+/, $makevar{CATEGORIES});
  1288. if (@cat == 0) {
  1289. &perror("FATAL: $file: CATEGORIES left blank. set it to \"misc\"".
  1290. " if nothing seems apropriate.");
  1291. }
  1292. if ($committer && $makevar{'.CURDIR'} =~ m'/([^/]+)/[^/]+/?$') {
  1293. if ($cat[0] ne $1 && $makevar{PKGCATEGORY} ne $1 ) {
  1294. &perror("FATAL: $file: category \"$1\" must be listed first");
  1295. }
  1296. }
  1297. #MICHAEL: can these three lang cat checks be combined?
  1298. # skip the first category specification if it's a language specific one.
  1299. if (grep($_ eq $cat[0], @lang_cat)) {
  1300. $has_lang_cat = 1;
  1301. $port_lang = $lang_pref{$cat[0]};
  1302. shift @cat;
  1303. }
  1304. # skip further if more language specific ones follow.
  1305. if (@cat && grep($_ eq $cat[0], @lang_cat)) {
  1306. &perror("WARN: $file: multiple language specific categories detected. ".
  1307. "are you sure?");
  1308. do {
  1309. shift @cat;
  1310. } while (@cat && grep($_ eq $cat[0], @lang_cat));
  1311. }
  1312. # check x11 in CATEGORIES
  1313. if ($newxdef) {
  1314. #MICHAEL: I don't understand this line
  1315. if (2 <= @cat && $cat[1] eq "x11") {
  1316. &perror("WARN: $file: only specific kind of apps should ".
  1317. "specify \"x11\" in CATEGORIES. ".
  1318. "Do you mean just USE_XLIB? ".
  1319. "Then remove \"x11\" from CATEGORIES.");
  1320. }
  1321. }
  1322. if (2 <= @cat) {
  1323. # skip the first one that we know is _not_ language specific.
  1324. shift @cat;
  1325. # any language specific one after non language specific ones?
  1326. foreach my $cat (@cat) {
  1327. if (grep($_ eq $cat, @lang_cat)) {
  1328. $has_lang_cat = 1;
  1329. $port_lang = $lang_pref{$cat};
  1330. &perror("WARN: $file: when you specify multiple categories, ".
  1331. "language specific category should come first.");
  1332. }
  1333. }
  1334. }
  1335. # check the URL
  1336. if (($tmp =~ /\nMASTER_SITES[+?]?=[ \t]*([^\n]*)\n/
  1337. && $1 !~ /^[ \t]*$/) || ($makevar{MASTER_SITES} ne '')) {
  1338. print "OK: seen MASTER_SITES, sanity checking URLs.\n"
  1339. if ($verbose);
  1340. my @sites = split(/\s+/, $1);
  1341. my $skipnext = 0;
  1342. foreach my $i (@sites) {
  1343. if ($skipnext) {
  1344. $skipnext = 0;
  1345. next;
  1346. }
  1347. $skipnext++ if ($i =~ /^#/);
  1348. if ($i =~ m#^\w+://#) {
  1349. &urlcheck($i, $file);
  1350. unless (&is_predefined($i, $file)) {
  1351. print "OK: URL \"$i\" ok.\n"
  1352. if ($verbose);
  1353. }
  1354. } else {
  1355. print "OK: non-URL \"$i\" ok.\n"
  1356. if ($verbose);
  1357. }
  1358. }
  1359. } else {
  1360. &perror("WARN: $file: no MASTER_SITES found. is it ok?");
  1361. }
  1362. # check DISTFILES and related items.
  1363. $distfiles = $1 if ($tmp =~ /\nDISTFILES[+?]?=[ \t]*([^\n]+)\n/);
  1364. #$portname = $1 if ($tmp =~ /\nPORTNAME[+?]?=[ \t]*([^\n]+)\n/);
  1365. #$portversion = $1 if ($tmp =~ /\nPORTVERSION[+?]?=[ \t]*([^\n]+)\n/);
  1366. $portname = $makevar{PORTNAME};
  1367. $portversion = $makevar{PORTVERSION};
  1368. $distname = $1 if ($tmp =~ /\nDISTNAME[+?]?=[ \t]*([^\n]+)\n/);
  1369. $extractsufx = $1 if ($tmp =~ /\nEXTRACT_SUFX[+?]?=[ \t]*([^\n]+)\n/);
  1370. # check bogus EXTRACT_SUFX.
  1371. if ($extractsufx ne '') {
  1372. print "OK: seen EXTRACT_SUFX, checking value.\n" if ($verbose);
  1373. if ($distfiles ne '') {
  1374. &perror("WARN: $file: no need to define EXTRACT_SUFX if ".
  1375. "DISTFILES is defined.");
  1376. }
  1377. if ($extractsufx eq '.tar.gz') {
  1378. &perror("WARN: $file: EXTRACT_SUFX is \".tar.gz.\" ".
  1379. "by default. you don't need to specify it.");
  1380. }
  1381. } else {
  1382. print "OK: no EXTRACT_SUFX seen, using default value.\n"
  1383. if ($verbose);
  1384. $extractsufx = '.tar.gz';
  1385. }
  1386. print "OK: sanity checking PORTNAME/PORTVERSION.\n" if ($verbose);
  1387. if ($distname ne '' && $distname eq "$portname-$portversion") {
  1388. &perror("WARN: $file: DISTNAME is \${PORTNAME}-\${PORTVERSION} by ".
  1389. "default, you don't need to define DISTNAME.");
  1390. }
  1391. if ($portname =~ /^$re_lang_short/) {
  1392. &perror("FATAL: $file: language prefix is automatically".
  1393. " set by PKGNAMEPREFIX.".
  1394. " you must remove it from PORTNAME.");
  1395. }
  1396. if ($portname =~ /\$[\{\(].+[\}\)]/) {
  1397. &perror("WARN: $file: using variable in PORTNAME.".
  1398. " consider using PKGNAMEPREFIX and/or PKGNAMESUFFIX.");
  1399. } elsif ($portname =~ /-/ && $distname ne '') {
  1400. &perror("WARN: $file: using hyphen in PORTNAME.".
  1401. " consider using PKGNAMEPREFIX and/or PKGNAMESUFFIX.");
  1402. }
  1403. if ($portversion eq '') {
  1404. &perror("FATAL: $file: PORTVERSION must be specified");
  1405. }
  1406. if ($portversion =~ /^pl[0-9]*$/
  1407. || $portversion =~ /^[0-9]*[A-Za-z]?[0-9]*(\.[0-9]*[A-Za-z]?[0-9]*)*$/) {
  1408. print "OK: PORTVERSION \"$portversion\" looks fine.\n" if ($verbose);
  1409. } elsif ($portversion =~ /^[^\-]*\$[{\(].+[\)}][^\-]*$/) {
  1410. &perror("WARN: $file: using variable, \"$portversion\", as version ".
  1411. "number");
  1412. } elsif ($portversion =~ /-/) {
  1413. &perror("FATAL: $file: PORTVERSION should not contain a hyphen.".
  1414. "should modify \"$portversion\".");
  1415. } else {
  1416. &perror("FATAL: $file: PORTVERSION looks illegal. ".
  1417. "should modify \"$portversion\".");
  1418. }
  1419. # if DISTFILES have only single item, it is better to avoid DISTFILES
  1420. # and to use combination of DISTNAME and EXTRACT_SUFX.
  1421. # example:
  1422. # DISTFILES=package-1.0.tgz
  1423. # should be
  1424. # DISTNAME= package-1.0
  1425. # EXTRACT_SUFX= .tgz
  1426. if ($distfiles =~ /^\S+$/ && $distfiles !~ /:[^\/:]+$/) {
  1427. $bogusdistfiles++;
  1428. print "OK: seen DISTFILES with single item, checking value.\n"
  1429. if ($verbose);
  1430. &perror("WARN: $file: use of DISTFILES with single file ".
  1431. "discouraged. distribution filename should be set by ".
  1432. "DISTNAME and EXTRACT_SUFX.");
  1433. if ($distfiles eq (($distname ne '') ? $distname : "$portname-$portversion") . $extractsufx) {
  1434. &perror("WARN: $file: definition of DISTFILES not necessary. ".
  1435. "DISTFILES is \${DISTNAME}/\${EXTRACT_SUFX} ".
  1436. "by default.");
  1437. }
  1438. # display advice only in certain cases.
  1439. #MICHAEL: will this work with multiple distfiles in this list? what about
  1440. # doing the same sort of thing for DISTNAME, is it needed?
  1441. if ($distfiles =~ /^\Q$i\E([\-.].+)$/) {
  1442. &perror("WARN: $file: how about \"EXTRACT_SUFX=$1\"".
  1443. ", instead of DISTFILES?");
  1444. }
  1445. }
  1446. # additional checks for committer.
  1447. if ($committer && $has_lang_cat) {
  1448. &perror("WARN: $file: be sure to include language code ".
  1449. "\"$port_lang-\" ".
  1450. "in the module alias name.");
  1451. }
  1452. if ($committer) {
  1453. if (opendir(DIR, ".")) {
  1454. my @tgz = grep(/\.tgz$/, readdir(DIR));
  1455. closedir(DIR);
  1456. if (@tgz) {
  1457. my $tgz = (2 <= @tgz)
  1458. ? '{' . join(',', @tgz) . '}'
  1459. : $tgz[0];
  1460. &perror("WARN: be sure to remove $portdir/$tgz ".
  1461. "before committing the port.");
  1462. }
  1463. }
  1464. }
  1465. push(@varnames, qw(
  1466. PORTNAME PORTVERSION PORTREVISION PORTEPOCH CATEGORIES MASTER_SITES
  1467. MASTER_SITE_SUBDIR PKGNAMEPREFIX PKGNAMESUFFIX DISTNAME EXTRACT_SUFX
  1468. DISTFILES EXTRACT_ONLY
  1469. ));
  1470. #
  1471. # section 3: PATCH_SITES/PATCHFILES(optional)
  1472. #
  1473. print "OK: checking second section of $file (PATCH*: optional).\n"
  1474. if ($verbose);
  1475. $tmp = $sections[$idx];
  1476. if ($tmp =~ /(PATCH_SITES|PATCH_SITE_SUBDIR|PATCHFILES|PATCH_DIST_STRIP)/) {
  1477. &checkearlier($file, $tmp, @varnames);
  1478. if ($tmp =~ /^PATCH_SITES=/) {
  1479. print "OK: seen PATCH_SITES.\n" if ($verbose);
  1480. $tmp =~ s/^[^\n]+\n//;
  1481. }
  1482. if ($tmp =~ /^PATCH_SITE_SUBDIR=/) {
  1483. print "OK: seen PATCH_SITE_SUBDIR.\n" if ($verbose);
  1484. $tmp =~ s/^[^\n]+\n//;
  1485. }
  1486. if ($tmp =~ /^PATCHFILES=/) {
  1487. print "OK: seen PATCHFILES.\n" if ($verbose);
  1488. $tmp =~ s/^[^\n]+\n//;
  1489. }
  1490. if ($tmp =~ /^PATCH_DIST_STRIP=/) {
  1491. print "OK: seen PATCH_DIST_STRIP.\n" if ($verbose);
  1492. $tmp =~ s/^[^\n]+\n//;
  1493. }
  1494. &checkextra($tmp, 'PATCH_SITES', $file);
  1495. $idx++;
  1496. }
  1497. push(@varnames, qw(
  1498. PATCH_SITES PATCHFILES PATCH_DIST_STRIP
  1499. ));
  1500. #
  1501. # section 4: MAINTAINER
  1502. #
  1503. print "OK: checking third section of $file (MAINTAINER).\n"
  1504. if ($verbose);
  1505. $tmp = $sections[$idx++];
  1506. &checkearlier($file, $tmp, @varnames);
  1507. &checkorder('MAINTAINER', $tmp, $file, qw(
  1508. MAINTAINER COMMENT
  1509. ));
  1510. $tmp = "\n" . $tmp;
  1511. if ($tmp =~ /\nMAINTAINER\??=([^\n]+)/) {
  1512. my $addr = $1;
  1513. $addr =~ s/^\s*//;
  1514. $addr =~ s/\s*$//;
  1515. if ($addr =~ /[\s,<>()]/) {
  1516. &perror("FATAL: $file: MAINTAINER should be a single address without comment.");
  1517. }
  1518. if ($addr !~ /^[^\@]+\@[\w\d\-\.]+$/) {
  1519. &perror("FATAL: $file: MAINTAINER address, $addr, does not appear to be a valid email address.");
  1520. }
  1521. $tmp =~ s/\nMAINTAINER\??=[^\n]+//;
  1522. } elsif ($whole !~ /\nMAINTAINER[?]?=/) {
  1523. &perror("FATAL: $file: no MAINTAINER listed.") unless ($slaveport && $makevar{MAINTAINER} ne '');
  1524. }
  1525. $tmp =~ s/\n\n+/\n/g;
  1526. # check COMMENT
  1527. if ($tmp !~ /\nCOMMENT(.)?=/) {
  1528. &perror("FATAL: $file: COMMENT has to be there.") unless ($slaveport && $makevar{COMMENT} ne '');
  1529. } elsif ($1 ne '') {
  1530. &perror("WARN: $file: unless this is a master port, COMMENT has to be set by \"=\", ".
  1531. "not by \"$1=\".") unless ($masterport);
  1532. } else { # check for correctness
  1533. if (($makevar{COMMENT} !~ /^["0-9A-Z]/) || ($makevar{COMMENT} =~ m/\.$/)) { #"
  1534. &perror("WARN: $file: COMMENT should begin with a capital, and end without a period");
  1535. } elsif (length($makevar{COMMENT}) > 70) {
  1536. &perror("WARN: $file: COMMENT exceeds 70 characters limit.");
  1537. }
  1538. }
  1539. push(@varnames, qw(
  1540. MAINTAINER COMMENT
  1541. ));
  1542. #
  1543. # section 5: *_DEPENDS (may not be there)
  1544. #
  1545. print "OK: checking fourth section of $file (*_DEPENDS).\n"
  1546. if ($verbose);
  1547. $tmp = $sections[$idx];
  1548. # NOTE: EXEC_DEPENDS is obsolete, so it should not be listed.
  1549. @linestocheck = qw(
  1550. EXTRACT_DEPENDS LIB_DEPENDS PATCH_DEPENDS BUILD_DEPENDS RUN_DEPENDS
  1551. FETCH_DEPENDS DEPENDS DEPENDS_TARGET
  1552. );
  1553. if ($tmp =~ /(LIB_|BUILD_|RUN_|FETCH_)?DEPENDS/) {
  1554. &checkearlier($file, $tmp, @varnames);
  1555. my %seen_depends;
  1556. if (!defined $ENV{'PORTSDIR'}) {
  1557. $ENV{'PORTSDIR'} = $portsdir;
  1558. }
  1559. foreach my $i (grep(/^[A-Z_]*DEPENDS[?+]?=/, split(/\n/, $tmp))) {
  1560. $i =~ s/^([A-Z_]*DEPENDS)[?+]?=[ \t]*//;
  1561. $j = $1;
  1562. $seen_depends{$j}++;
  1563. if ($j ne 'DEPENDS' &&
  1564. $i =~ /^\${([A-Z_]+DEPENDS)}\s*$/ &&
  1565. $seen_depends{$1} &&
  1566. $j ne $1)
  1567. {
  1568. print "OK: $j refers to $1, skipping checks.\n"
  1569. if ($verbose);
  1570. next;
  1571. }
  1572. print "OK: checking ports listed in $j.\n"
  1573. if ($verbose);
  1574. foreach my $k (split(/\s+/, $i)) {
  1575. my @l = split(':', $k);
  1576. print "OK: checking dependency value for $j.\n"
  1577. if ($verbose);
  1578. if (($j eq 'DEPENDS'
  1579. && scalar(@l) != 1 && scalar(@l) != 2)
  1580. || ($j ne 'DEPENDS'
  1581. && scalar(@l) != 2 && scalar(@l) != 3)) {
  1582. &perror("WARN: $file: wrong dependency value ".
  1583. "for $j. $j requires ".
  1584. ($j eq 'DEPENDS'
  1585. ? "1 or 2 "
  1586. : "2 or 3 ").
  1587. "colon-separated tuples.");
  1588. next;
  1589. }
  1590. my %m = ();
  1591. if ($j eq 'DEPENDS') {
  1592. $m{'dir'} = $l[0];
  1593. $m{'tgt'} = $l[1];
  1594. } else {
  1595. $m{'dep'} = $l[0];
  1596. $m{'dir'} = $l[1];
  1597. $m{'tgt'} = $l[2];
  1598. }
  1599. print "OK: dep=\"$m{'dep'}\", ".
  1600. "dir=\"$m{'dir'}\", tgt=\"$m{'tgt'}\"\n"
  1601. if ($verbose);
  1602. # check USE_PERL5
  1603. if ($m{'dep'} =~ /^perl5(\.\d+)?$/) {
  1604. &perror("WARN: $file: dependency to perl5 ".
  1605. "listed in $j. consider using ".
  1606. "USE_PERL5.");
  1607. }
  1608. # check USE_GMAKE
  1609. if ($m{'dep'} =~ /^(gmake|\${GMAKE})$/) {
  1610. &perror("WARN: $file: dependency to $1 ".
  1611. "listed in $j. consider using ".
  1612. "USE_GMAKE.");
  1613. }
  1614. # check USE_QT
  1615. if ($m{'dep'} =~ /^(qt\d)+$/) {
  1616. &perror("WARN: $file: dependency to $1 ".
  1617. "listed in $j. consider using ".
  1618. "USE_QT.");
  1619. }
  1620. # check USE_GETOPT_LONG
  1621. if ($m{'dep'} =~ /^(gnugetopt\.\d)+$/) {
  1622. &perror("WARN: $file: dependency to $1 ".
  1623. "listed in $j. consider using ".
  1624. "USE_GETOPT_LONG.");
  1625. }
  1626. # check backslash in LIB_DEPENDS
  1627. if ($osname eq 'NetBSD' && $j eq 'LIB_DEPENDS'
  1628. && $m{'dep'} =~ /\\\\./) {
  1629. &perror("WARN: $file: use of backslashes in ".
  1630. "$j is deprecated.");
  1631. }
  1632. # check for PREFIX
  1633. if ($m{'dep'} =~ /\${PREFIX}/) {
  1634. &perror("FATAL: $file: \${PREFIX} must not be ".
  1635. "contained in *_DEPENDS. ".
  1636. "use \${LOCALBASE} or ".
  1637. "\${X11BASE} instead.");
  1638. }
  1639. # check port dir existence
  1640. $k = $m{'dir'};
  1641. $k =~ s/\${PORTSDIR}/$ENV{'PORTSDIR'}/;
  1642. $k =~ s/\$[\({]PORTSDIR[\)}]/$ENV{'PORTSDIR'}/;
  1643. if (! -d $k) {
  1644. &perror("WARN: $file: no port directory $k ".
  1645. "found, even though it is ".
  1646. "listed in $j.");
  1647. } else {
  1648. print "OK: port directory $k found.\n"
  1649. if ($verbose);
  1650. }
  1651. }
  1652. }
  1653. foreach my $i (@linestocheck) {
  1654. $tmp =~ s/$i[?+]?=[^\n]+\n//g;
  1655. }
  1656. &checkextra($tmp, '*_DEPENDS', $file);
  1657. $idx++;
  1658. }
  1659. push(@varnames, @linestocheck);
  1660. &checkearlier($file, $tmp, @varnames);
  1661. #
  1662. # Makefile 6: check the rest of file
  1663. #
  1664. print "OK: checking the rest of the $file.\n" if ($verbose);
  1665. $tmp = join("\n\n", @sections[$idx .. scalar(@sections)-1]);
  1666. $tmp = "\n" . $tmp; # to make the begin-of-line check easier
  1667. &checkearlier($file, $tmp, @varnames);
  1668. # check WRKSRC/NO_WRKSUBDIR
  1669. #
  1670. # do not use DISTFILES/DISTNAME to control over WRKSRC.
  1671. # DISTNAME is for controlling distribution filename.
  1672. # example:
  1673. # DISTNAME= package
  1674. # DISTFILES=package-1.0.tgz
  1675. # should be
  1676. # DISTNAME= package-1.0
  1677. # EXTRACT_SUFX=.tgz
  1678. # WRKSRC= ${WRKDIR}/package
  1679. #
  1680. print "OK: checking WRKSRC.\n" if ($verbose);
  1681. $wrksrc = $nowrksubdir = '';
  1682. $wrksrc = $1 if ($tmp =~ /\nWRKSRC[+?]?=[ \t]*([^\n]*)\n/);
  1683. $nowrksubdir = $1 if ($tmp =~ /\nNO_WRKSUBDIR[+?]?=[ \t]*([^\n]*)\n/);
  1684. if ($nowrksubdir eq '') {
  1685. $realwrksrc = $wrksrc ? "$wrksrc/$distname"
  1686. : "\${WRKDIR}/$distname";
  1687. } else {
  1688. $realwrksrc = $wrksrc ? $wrksrc : '${WRKDIR}';
  1689. }
  1690. print "OK: WRKSRC seems to be $realwrksrc.\n" if ($verbose);
  1691. if ($nowrksubdir eq '') {
  1692. print "OK: no NO_WRKSUBDIR, checking value of WRKSRC.\n"
  1693. if ($verbose);
  1694. if ($wrksrc eq 'work' || $wrksrc =~ /^$[\{\(]WRKDIR[\}\)]/) {
  1695. &perror("WARN: $file: WRKSRC is set to meaningless value ".
  1696. "\"$1\".".
  1697. ($nowrksubdir eq ''
  1698. ? " use \"NO_WRKSUBDIR=yes\" instead."
  1699. : ""));
  1700. }
  1701. if ($bogusdistfiles) {
  1702. if ($distname ne '' && $wrksrc eq '') {
  1703. &perror("WARN: $file: do not use DISTFILES and DISTNAME ".
  1704. "to control WRKSRC. how about ".
  1705. "\"WRKSRC=\${WRKDIR}/$distname\"?");
  1706. } else {
  1707. &perror("WARN: $file: DISTFILES/DISTNAME affects WRKSRC. ".
  1708. "take caution when changing them.");
  1709. }
  1710. }
  1711. } else {
  1712. print "OK: seen NO_WRKSUBDIR, checking value of WRKSRC.\n"
  1713. if ($verbose);
  1714. if ($wrksrc eq 'work' || $wrksrc =~ /^$[\{\(]WRKDIR[\}\)]/) {
  1715. &perror("WARN: $file: definition of WRKSRC not necessary. ".
  1716. "WRKSRC is \${WRKDIR} by default.");
  1717. }
  1718. }
  1719. # check RESTRICTED/NO_CDROM/NO_PACKAGE
  1720. print "OK: checking RESTRICTED/NO_CDROM/NO_PACKAGE.\n" if ($verbose);
  1721. if ($committer && $tmp =~ /\n(RESTRICTED|NO_CDROM|NO_PACKAGE)[+?]?=/) {
  1722. &perror("WARN: $file: \"$1\" found. do not forget to update ".
  1723. "ports/LEGAL.");
  1724. }
  1725. # check NO_CONFIGURE/NO_PATCH
  1726. print "OK: checking NO_CONFIGURE/NO_PATCH.\n" if ($verbose);
  1727. if ($tmp =~ /\n(NO_CONFIGURE|NO_PATCH)[+?]?=/) {
  1728. &perror("FATAL: $file: \"$1\" was obsoleted. remove this.");
  1729. }
  1730. # check MAN[1-9LN]
  1731. print "OK: checking MAN[0-9LN].\n" if ($verbose);
  1732. foreach my $i (keys %plistmanall) {
  1733. print "OK: pkg-plist MAN$i=$plistmanall{$i}\n" if ($verbose);
  1734. }
  1735. foreach my $i (split(//, $manchapters)) {
  1736. if ($tmp =~ /MAN\U$i\E=\s*([^\n]*)\n/) {
  1737. print "OK: Makefile MAN\U$i\E=$1\n" if ($verbose);
  1738. }
  1739. }
  1740. foreach my $i (split(//, $manchapters)) {
  1741. next if ($i eq '');
  1742. if ($tmp =~ /MAN\U$i\E=\s*([^\n]*)\n/) {
  1743. @mman = grep($_ !~ /^\s*$/, split(/\s+/, $1));
  1744. @pman = grep($_ !~ /^\s*$/,
  1745. split(/\s+/, $plistmanall{$i}));
  1746. foreach my $j (@mman) {
  1747. print "OK: checking $j (Makefile)\n"
  1748. if ($verbose);
  1749. if ($automan && grep($_ eq $j, @pman)) {
  1750. &perror("FATAL: $file: duplicated manpage ".
  1751. "entry $j: content of ".
  1752. "MAN\U$i\E will be automatically ".
  1753. "added to pkg-plist.");
  1754. } elsif (!$automan && !grep($_ eq $j, @pman)) {
  1755. &perror("WARN: $file: manpage $j ".
  1756. "MAN\U$i\E but not in pkg-plist.");
  1757. }
  1758. }
  1759. foreach my $j (@pman) {
  1760. print "OK: checking $j (pkg-plist)\n" if ($verbose);
  1761. if (!grep($_ eq $j, @mman)) {
  1762. &perror("WARN: $file: manpage $j in pkg-plist ".
  1763. "but not in MAN\U$i\E.");
  1764. }
  1765. }
  1766. } else {
  1767. if ($plistmanall{$i}) {
  1768. if ($manstrict) {
  1769. &perror("FATAL: $file: manpage for chapter ".
  1770. "$i must be listed in ".
  1771. "MAN\U$i\E. ");
  1772. } else {
  1773. &perror("WARN: $file: manpage for chapter ".
  1774. "$i should be listed in ".
  1775. "MAN\U$i\E, ".
  1776. "even if compression is ".
  1777. "not necessary.");
  1778. }
  1779. }
  1780. if ($mancompress && $plistman{$i}) {
  1781. &perror("WARN: $file: MAN\U$i\E will help you ".
  1782. "compressing manual page in chapter ".
  1783. "\"$i\".");
  1784. } elsif (!$mancompress && $plistmangz{$i}) {
  1785. &perror("WARN: $file: MAN\U$i\E will help you ".
  1786. "uncompressing manual page in chapter ".
  1787. "\"$i\".");
  1788. }
  1789. }
  1790. }
  1791. if ($tmp !~ /MANLANG/ && scalar(keys %manlangs)) {
  1792. $i = (keys %manlangs)[0];
  1793. &perror("WARN: $file: how about using MANLANG for ".
  1794. "designating manual language, such as \"$i\"?");
  1795. }
  1796. # check INFO
  1797. print "OK: checking INFO.\n" if ($verbose);
  1798. if ($autoinfo && $tmp =~ /\nINFO=\s*([^\n]*)\n/) {
  1799. my @minfo = grep($_ !~ /^\s*$/, split(/\s+/, $1));
  1800. foreach $i (@minfo) {
  1801. if ($i =~ /\.info(-\d+)?$/) {
  1802. &perror("FATAL: $file: do not include the .info extension ".
  1803. "on files listed in the INFO macro.");
  1804. }
  1805. }
  1806. }
  1807. # check USE_X11 and USE_IMAKE
  1808. if ($tmp =~ /\nUSE_IMAKE[?+]?=/
  1809. && $tmp =~ /\n(USE_X11)[?+]?=/) {
  1810. &perror("WARN: $file: since you already have USE_IMAKE, ".
  1811. "you don't need $1.");
  1812. }
  1813. # check USE_X11 and USE_IMAKE
  1814. if ($newxdef && $tmp =~ /\nUSE_IMAKE[?+]?=/
  1815. && $tmp =~ /\n(USE_X_PREFIX)[?+]?=/) {
  1816. &perror("WARN: $file: since you already have USE_IMAKE, ".
  1817. "you don't need $1.");
  1818. }
  1819. # check USE_X11 and USE_X_PREFIX
  1820. if ($newxdef && $tmp =~ /\nUSE_X11[?+]?=/
  1821. && $tmp !~ /\nUSE_X_PREFIX[?+]?=/) {
  1822. &perror("FATAL: $file: meaning of USE_X11 was changed in Aug 1998. ".
  1823. "use USE_X_PREFIX instead.");
  1824. }
  1825. # check direct use of important make targets.
  1826. if ($tmp =~ /\n(fetch|extract|patch|configure|build|install):/) {
  1827. &perror("FATAL: $file: direct redefinition of make target \"$1\" ".
  1828. "discouraged. redefine \"do-$1\" instead.");
  1829. }
  1830. # check for incorrect use of the pre-everything target.
  1831. if ($tmp =~ /\npre-everything:[^:]/) {
  1832. &perror("FATAL: $file: use pre-everything:: instead of pre-everything:");
  1833. }
  1834. if ($tmp =~ /^pre-patch:/m && $use_gnome_hack) {
  1835. &perror("FATAL: $file: pre-patch target overwrites gnomehack component. ".
  1836. "use post-patch instead.");
  1837. }
  1838. 1;
  1839. }
  1840. sub perror {
  1841. my(@msg) = @_;
  1842. if ($msg[0] =~ /^FATAL/) {
  1843. $err++;
  1844. } else {
  1845. $warn++;
  1846. }
  1847. print join("\n", @msg) . "\n";
  1848. }
  1849. sub checkextra {
  1850. my($str, $section, $file) = @_;
  1851. $str = "\n" . $str if ($str !~ /^\n/);
  1852. $str =~ s/\n#[^\n]*/\n/g;
  1853. $str =~ s/\n\.[^\n]+/\n/g;
  1854. $str =~ s/\n\n+/\n/g;
  1855. $str =~ s/^\s+//;
  1856. $str =~ s/\s+$//;
  1857. return if ($str eq '');
  1858. if ($str =~ /^([\w\d]+)/) {
  1859. &perror("WARN: $file: extra item placed in the ".
  1860. "$section section, ".
  1861. "for example, \"$1\".");
  1862. } else {
  1863. &perror("WARN: $file: extra item placed in the ".
  1864. "$section section.");
  1865. }
  1866. }
  1867. sub checkorder {
  1868. my($section, $str, $file, @order) = @_;
  1869. my(@items, $i, $j, $k, $invalidorder);
  1870. print "OK: checking the order of $section section.\n" if ($verbose);
  1871. @items = ();
  1872. foreach my $i (split("\n", $str)) {
  1873. $i =~ s/[+?]?=.*$//;
  1874. push(@items, $i);
  1875. }
  1876. @items = reverse(@items);
  1877. $j = -1;
  1878. $invalidorder = 0;
  1879. while (scalar(@items)) {
  1880. $i = pop(@items);
  1881. $k = 0;
  1882. while ($k < scalar(@order) && $order[$k] ne $i) {
  1883. $k++;
  1884. }
  1885. if ($order[$k] eq $i) {
  1886. if ($k < $j) {
  1887. &perror("FATAL: $file: $i appears out-of-order.");
  1888. $invalidorder++;
  1889. } else {
  1890. print "OK: seen $i, in order.\n" if ($verbose);
  1891. }
  1892. $j = $k;
  1893. # This if condition tests for .if, .else (in all forms),
  1894. # .for and .endfor and .include
  1895. } elsif ($i !~ m/^\.(if|el|endif|for|endfor|include)/) {
  1896. &perror("FATAL: $file: extra item \"$i\" placed in the ".
  1897. "$section section.");
  1898. }
  1899. }
  1900. if ($invalidorder) {
  1901. &perror("FATAL: $file: order must be " . join('/', @order) . '.');
  1902. } else {
  1903. print "OK: $section section is ordered properly.\n"
  1904. if ($verbose);
  1905. }
  1906. }
  1907. sub checkearlier {
  1908. my($file, $str, @varnames) = @_;
  1909. my($i);
  1910. print "OK: checking items that has to appear earlier.\n" if ($verbose);
  1911. foreach my $i (@varnames) {
  1912. if ($str =~ /\n$i\??=/) {
  1913. &perror("WARN: $file: \"$i\" has to appear earlier.");
  1914. }
  1915. }
  1916. }
  1917. sub linenumber {
  1918. my $text = shift;
  1919. my @lines;
  1920. @lines = split /\n/, $text;
  1921. return scalar(@lines);
  1922. }
  1923. sub abspathname {
  1924. my($str, $file) = @_;
  1925. my($s, $i, %cmdnames);
  1926. my($pre);
  1927. # ignore parameter string to echo command
  1928. $str =~ s/[ \t][\@-]?(echo|\$[\{\(]ECHO[\}\)]|\$[\{\(]ECHO_MSG[\}\)])[ \t]+("(\\'|\\"|[^"])*"|'(\\'|\\"|[^"])*')[ \t]*[;\n]//; #'
  1929. print "OK: checking direct use of full pathnames in $file.\n"
  1930. if ($verbose);
  1931. foreach my $s (split(/\n+/, $str)) {
  1932. $i = '';
  1933. if ($s =~ /(^|[ \t\@'"-])(\/[\w\d])/) { #'
  1934. # suspected pathnames are recorded.
  1935. $i = $2 . $';
  1936. $pre = $` . $1;
  1937. if ($pre =~ /MASTER_SITE_SUBDIR/) {
  1938. # MASTER_SITE_SUBDIR lines are ok.
  1939. $i = '';
  1940. }
  1941. }
  1942. if ($i ne '') {
  1943. $i =~ s/\s.*$//;
  1944. $i =~ s/['"].*$//; #'
  1945. $i = substr($i, 0, 20) . '...' if (20 < length($i));
  1946. &perror("WARN: $file: possible use of absolute pathname ".
  1947. "\"$i\".") unless ($i =~ m,^/compat/,);
  1948. }
  1949. }
  1950. print "OK: checking direct use of pathnames, phase 1.\n" if ($verbose);
  1951. %cmdnames = split(/\n|\t+/, <<EOF);
  1952. /usr/opt \${PORTSDIR} instead
  1953. $portsdir \${PORTSDIR} instead
  1954. $localbase \${PREFIX} or \${LOCALBASE}, as appropriate
  1955. /usr/X11 \${PREFIX} or \${X11BASE}, as appropriate
  1956. EOF
  1957. foreach my $i (keys %cmdnames) {
  1958. if ($str =~ /$i/) {
  1959. &perror("WARN: $file: possible direct use of \"$&\" ".
  1960. "found. if so, use $cmdnames{$i}.");
  1961. }
  1962. }
  1963. print "OK: checking direct use of pathnames, phase 2.\n" if ($verbose);
  1964. %cmdnames = split(/\n|\t+/, <<EOF);
  1965. distfiles \${DISTDIR} instead
  1966. pkg \${PKGDIR} instead
  1967. files \${FILESDIR} instead
  1968. scripts \${SCRIPTDIR} instead
  1969. patches \${PATCHDIR} instead
  1970. work \${WRKDIR} instead
  1971. EOF
  1972. foreach my $i (keys %cmdnames) {
  1973. if ($str =~ /(\.\/|\$[\{\(]\.CURDIR[\}\)]\/|[ \t])(\b$i)\//) {
  1974. &perror("WARN: $file: possible direct use of \"$i\" ".
  1975. "found. if so, use $cmdnames{$i}.");
  1976. }
  1977. }
  1978. }
  1979. sub is_predefined {
  1980. my($url, $file) = @_;
  1981. my($site, $site_re);
  1982. my $subdir_re = quotemeta quotemeta '/%SUBDIR%/';
  1983. for my $site (keys %predefined) {
  1984. $site_re = quotemeta $site;
  1985. $site_re =~ s,$subdir_re,/(.*)/,;
  1986. if ($url =~ /$site_re/) {
  1987. &perror("WARN: $file: how about using ".
  1988. "\"\${MASTER_SITE_$predefined{$site}}\" with ".
  1989. "\"MASTER_SITE_SUBDIR=$1\", instead of \"$url\"?");
  1990. return &TRUE;
  1991. }
  1992. }
  1993. undef;
  1994. }
  1995. sub urlcheck {
  1996. my ($url, $file) = @_;
  1997. if ($url !~ m#^\w+://#) {
  1998. &perror("WARN: $file: \"$url\" doesn't appear to be a URL to me.");
  1999. }
  2000. if ($url !~ m#/(:[^/:]+)?$#) {
  2001. &perror("FATAL: $file: URL \"$url\" should ".
  2002. "end with \"/\" or a group name (e.g. :something).");
  2003. }
  2004. if ($url =~ m#://[^/]*:/#) {
  2005. &perror("FATAL: $file: URL \"$url\" contains ".
  2006. "extra \":\".");
  2007. }
  2008. if ($osname == 'FreeBSD' && $url =~ m#(www\.freebsd\.org)/~.+/#i) {
  2009. &perror("WARN: $file: URL \"$url\", ".
  2010. "$1 should be ".
  2011. "people.FreeBSD.org");
  2012. }
  2013. }
  2014. sub TRUE {1;}
  2015. # Local variables:
  2016. # tab-width: 4
  2017. # End: