portlint.pl 57 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057
  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 = 0;
  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";
  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. # Check for ports that may break INDEX
  304. my $indexerr = `env LOCALBASE=/nonexistentlocal X11BASE=/nonexistentx make $makeenv describe 2>&1 >/dev/null`;
  305. chomp $indexerr;
  306. $indexerr =~ tr/\n/ /s;
  307. &perror("FATAL: breaks INDEX ($indexerr).")
  308. if ($indexerr);
  309. }
  310. if ($err || $warn) {
  311. print "$err fatal errors and $warn warnings found.\n"
  312. } else {
  313. print "looks fine.\n";
  314. }
  315. exit $err;
  316. #
  317. # pkg-descr
  318. #
  319. sub checkdescr {
  320. my($file) = @_;
  321. my(%maxchars) = ($makevar{DESCR}, 80);
  322. my(%maxlines) = ($makevar{DESCR}, 24);
  323. my(%errmsg) = ($makevar{DESCR}, "exceeds $maxlines{$makevar{DESCR}} ".
  324. "lines, make it shorter if possible.");
  325. my($longlines, $linecnt, $tmp) = (0, 0, "");
  326. open(IN, "< $file") || return 0;
  327. while (<IN>) {
  328. $tmp .= $_;
  329. chomp || &perror("WARN: $file should terminate in '\n'.");
  330. $linecnt++;
  331. $longlines++ if ($maxchars{$file} < length);
  332. }
  333. if ($linecnt > $maxlines{$file}) {
  334. &perror("WARN: $file $errmsg{$file}".
  335. "(currently $linecnt lines)");
  336. } else {
  337. print "OK: $file has $linecnt lines.\n" if ($verbose);
  338. }
  339. if ($longlines > 0) {
  340. &perror("WARN: $file includes lines that exceed $maxchars{$file} ".
  341. "characters.");
  342. }
  343. if ($tmp =~ /[\033\200-\377]/) {
  344. &perror("WARN: $file includes iso-8859-1, or ".
  345. "other local characters. $file should be ".
  346. "plain ascii file.");
  347. }
  348. if ($file =~ /\bpkg-descr/ && $tmp =~ m,http://,) {
  349. my $has_url = 0;
  350. my $has_www = 0;
  351. foreach my $line (grep($_ =~ "http://", split(/\n+/, $tmp))) {
  352. $has_url = 1;
  353. if ($line =~ m,WWW:[ \t]+http://,) {
  354. $has_www = 1;
  355. }
  356. }
  357. if ($has_url && ! $has_www) {
  358. &perror("FATAL: $file: contains a URL but no WWW:");
  359. }
  360. }
  361. close(IN);
  362. }
  363. #
  364. # pkg-plist
  365. #
  366. sub checkplist {
  367. my($file) = @_;
  368. my($curdir) = ($localbase);
  369. my(%omfremoveseen) = ();
  370. my(%omfinstallseen) = ();
  371. my(%omfseen) = ();
  372. my($inforemoveseen, $infoinstallseen, $infoseen) = (0, 0, 0);
  373. my(%omfafterinstall) = ();
  374. my(%omfafterremove) = ();
  375. my($infobeforeremove, $infoafterinstall) = (0, 0);
  376. my($infooverwrite) = (0);
  377. my($rcsidseen) = (0);
  378. my(@exec_omf) = ();
  379. my(@exec_info) = ();
  380. my(@unexec_omf) = ();
  381. my(@unexec_info) = ();
  382. my(@omffile) = ();
  383. my(@infofile) = ();
  384. open(IN, "< $file") || return 0;
  385. while (<IN>) {
  386. if ($_ =~ /[ \t]+\n?$/) {
  387. &perror("WARN: $file $.: whitespace before end ".
  388. "of line.");
  389. }
  390. # make it easier to handle.
  391. $_ =~ s/\s+$//;
  392. $_ =~ s/\n$//;
  393. if ($osname eq 'NetBSD' && $_ =~ /<\$ARCH>/) {
  394. &perror("WARN: $file $.: use of <\$ARCH> deprecated, ".
  395. "use \${MACHINE_ARCH} instead.");
  396. }
  397. if (m'lib/perl5/site_perl/%%PERL_VER%%') {
  398. &perror("WARN: $file $.: use \%\%SITE_PERL\%\% ".
  399. "instead of lib/perl5/site_perl/\%\%PERL_VER\%\%.");
  400. }
  401. if ($_ =~ /^\@/) {
  402. if ($_ =~ /^\@(cwd|cd)[ \t]+(\S+)/) {
  403. $curdir = $2;
  404. } elsif ($_ =~ /^\@unexec[ \t]+rm[ \t]/) {
  405. if ($_ !~ /%[DB]/) {
  406. &perror("WARN: pkg-plist:$. use \"%D\" or \"%B\" to ".
  407. "specify prefix.");
  408. }
  409. if ($_ !~ /true$/ && $_ !~ /rm -f/) {
  410. &perror("WARN: pkg-plist:$. add \"2>&1 ".
  411. ">/dev/null || true\" ".
  412. "to \"\@unexec rm\".");
  413. }
  414. } elsif ($_ =~ /^\@unexec[ \t]+rmdir/) {
  415. if ($_ !~ /%[DB]/) {
  416. &perror("WARN: pkg-plist:$. use \"%D\" or \"%B\" to ".
  417. "specify prefix.");
  418. }
  419. if ($_ !~ /true$/) {
  420. &perror("WARN: pkg-plist:$. use \"\@dirrm\" ".
  421. "instead of \"\@unexec rmdir\".");
  422. }
  423. } elsif ($_ =~ /^\@exec[ \t]+scrollkeeper-install[ \t]+-q\s+(\S+)\s+.+$/) {
  424. push(@exec_omf, $1);
  425. my $ot = $1;
  426. $ot =~ s/^\%D\///;
  427. $omfinstallseen{$ot} = $.;
  428. } elsif (!$autoinfo && $_ =~ /^\@exec[ \t]+install-info\s+(.+)\s+(.+)$/) {
  429. $infoinstallseen = $.;
  430. push(@exec_info, $1);
  431. } elsif ($autoinfo && $_ =~ /^\@exec[ \t]+install-info\s+(.+)\s+(.+)$/) {
  432. &perror("WARN: \@exec install-info is deprecated in favor of adding info files into the Makefile using the INFO macro.");
  433. } elsif ($_ =~ /^\@unexec[ \t]+scrollkeeper-uninstall[ \t]+-q\s+(\S+)\s+.+$/) {
  434. push(@unexec_omf, $1);
  435. my $ot = $1;
  436. $ot =~ s/^\%D\///;
  437. $omfremoveseen{$ot} = $.;
  438. } elsif (!$autoinfo && $_ =~ /^\@unexec[ \t]+install-info[ \t]+--delete\s+(.+)\s+(.+)$/) {
  439. $inforemoveseen = $.;
  440. push(@unexec_info, $1);
  441. } elsif ($autoinfo && $_ =~ /^\@unexec[ \t]+install-info[ \t]+--delete\s+(.+)\s+(.+)$/) {
  442. &perror("WARN: \@unexec install-info is deprecated in favor of adding info files into the Makefile using the INFO macro.");
  443. } elsif ($_ =~ /^\@(exec|unexec)/) {
  444. if (/ldconfig/) {
  445. if ($ldconfigwithtrue
  446. && !/\/usr\/bin\/true/) {
  447. &perror("FATAL: $file $.: ldconfig ".
  448. "must be used with ".
  449. "\"||/usr/bin/true\".");
  450. }
  451. &perror("WARN: $file $.: possible ".
  452. "direct use of ldconfig ".
  453. "in PLIST found. use ".
  454. "INSTALLS_SHLIB instead.");
  455. }
  456. } elsif ($_ =~ /^\@(comment)/) {
  457. $rcsidseen++ if (/\$$rcsidstr[:\$]/);
  458. } elsif ($_ =~ /^\@(owner|group)\s/) {
  459. &perror("WARN: \@$1 should not be needed in pkg-plist");
  460. } elsif ($_ =~ /^\@(dirrm|option)/) {
  461. ; # no check made
  462. } else {
  463. &perror("WARN: $file $.: ".
  464. "unknown pkg-plist directive \"$_\"");
  465. }
  466. next;
  467. }
  468. if ($_ =~ /^\//) {
  469. &perror("FATAL: $file $.: use of full pathname ".
  470. "disallowed.");
  471. }
  472. if ($_ =~ /\.la$/) {
  473. &perror("WARN: $file $.: installing libtool archives, ".
  474. "please use USE_LIBTOOL in Makefile if possible");
  475. }
  476. if ($_ =~ /\.so(\.\d+)?$/ && $makevar{INSTALLS_SHLIB} eq '') {
  477. &perror("WARN: $file $.: installing shared libraries, ".
  478. "please define INSTALLS_SHLIB as appropriate");
  479. }
  480. if ($autoinfo && $_ =~ /\.info$/) {
  481. &perror("WARN: $file $.: enumerating info files in the plist is deprecated in favor of adding info files into the Makefile using the INFO macro.");
  482. }
  483. if ($autoinfo && $_ =~ /\.info-\d+$/) {
  484. &perror("FATAL: $file $.: numbered info files are obsolete and not portable; add info files using the INFO macro in the Makefile.");
  485. }
  486. if ($_ =~ /.*\.omf$/) {
  487. $omfseen{$_} = $.;
  488. $omfafterinstall{$_}++ if ($omfinstallseen{$_});
  489. $omfafterremove{$_}++ if ($omfremoveseen{$_});
  490. push(@omffile, $_);
  491. }
  492. if (!$autoinfo) {
  493. if ($_ =~ /^info\/.*info(-[0-9]+)?$/) {
  494. $infoseen = $.;
  495. $infoafterinstall++ if ($infoinstallseen);
  496. $infobeforeremove++ if (!$inforemoveseen);
  497. push(@infofile, $_);
  498. }
  499. if ($_ =~ /^info\/dir$/) {
  500. &perror("FATAL: \"info/dir\" should not be listed in ".
  501. "$file. use install-info to add/remove ".
  502. "an entry.");
  503. $infooverwrite++;
  504. }
  505. }
  506. if ($_ =~ /^(\%\%PORTDOCS\%\%)?share\/doc\//) {
  507. &perror("WARN: $file $.: consider using DOCSDIR macro");
  508. $sharedocused++;
  509. } elsif ($_ =~ /^(\%\%PORTDOCS\%\%)?\%\%DOCSDIR\%\%/) {
  510. $sharedocused++;
  511. }
  512. if ($_ =~ /^share\/examples\//) {
  513. &perror("WARN: $file $.: consider using EXAMPLESDIR macro");
  514. }
  515. if ($_ =~ m#man/([^/]+/)?man([$manchapters])/([^\.]+\.[$manchapters])(\.gz)?$#) {
  516. if ($4 eq '') {
  517. $plistman{$2} .= ' ' . $3;
  518. if ($mancompress) {
  519. &perror("FATAL: $file $.: ".
  520. "unpacked man file $3 ".
  521. "listed. must be gzipped.");
  522. }
  523. } else {
  524. $plistmangz{$2} .= ' ' . $3;
  525. if (!$mancompress) {
  526. &perror("FATAL: $file $.: ".
  527. "gzipped man file $3$4 ".
  528. "listed. unpacked one should ".
  529. "be installed.");
  530. }
  531. }
  532. $plistmanall{$2} .= ' ' . $3;
  533. if ($1 ne '') {
  534. $manlangs{substr($1, 0, length($1) - 1)}++;
  535. }
  536. }
  537. if ($curdir !~ m#^$localbase#
  538. && $curdir !~ m#^/usr/X11R6#) {
  539. &perror("WARN: $file $.: installing to ".
  540. "directory $curdir discouraged. ".
  541. "could you please avoid it?");
  542. }
  543. if ("$curdir/$_" =~ m#^$localbase/share/doc#) {
  544. print "OK: seen installation to share/doc in $file. ".
  545. "($curdir/$_)\n" if ($verbose);
  546. $sharedocused++;
  547. }
  548. }
  549. # Check that each OMF file has an install and deinstall line.
  550. my $omf_install = join(" ", @exec_omf);
  551. $omf_install .= ' ';
  552. my $omf_deinstall = join(" ", @unexec_omf);
  553. $omf_deinstall .= ' ';
  554. foreach my $of (@omffile) {
  555. if ($omf_install !~ /\%D\/\Q$of\E/) {
  556. &perror("FATAL: you need an '\@exec scrollkeeper-install -q \%D/$of 2>/dev/null || /usr/bin/true' line in your pkg-plist");
  557. }
  558. if ($omf_deinstall !~ /\%D\/$of/) {
  559. &perror("FATAL: you need an '\@unexec scrollkeeper-uninstall -q \%D/$of 2>/dev/null || /usr/bin/true' line in your pkg-plist");
  560. }
  561. }
  562. if (!$autoinfo) {
  563. # check that every infofile has an exec install-info and unexec install-info
  564. my $exec_install = join(" ", @exec_info);
  565. $exec_install .= ' ';
  566. my $unexec_install = join(" ", @unexec_info);
  567. $unexec_install .= ' ';
  568. foreach my $if (@infofile) {
  569. next if ($if =~ m/info-/);
  570. if ($exec_install !~ m/\%D\/\Q$if\E/) {
  571. &perror("FATAL: you need an '\@exec install-info \%D/$if \%D/info/dir' line in your pkg-plist");
  572. }
  573. if ($unexec_install !~ m/\%D\/$if/) {
  574. &perror("FATAL: you need an '\@unexec install-info --delete \%D/$if \%D/info/dir' line in your pkg-plist");
  575. }
  576. }
  577. }
  578. if ($rcsidinplist && !$rcsidseen) {
  579. &perror("FATAL: RCS tag \"\$$rcsidstr\$\" must be present ".
  580. "in $file as \@comment.")
  581. }
  582. if (((!$autoinfo && !$infoseen) || $autoinfo) && !scalar(keys %omfseen)) {
  583. close(IN);
  584. return 1;
  585. }
  586. if (scalar(keys %omfseen)) {
  587. if (!scalar(keys %omfinstallseen)) {
  588. &perror("FATAL: scrollkeeper-install must be used to ".
  589. "add/delete entries from the ScrollKeeper OMF database.");
  590. } else {
  591. foreach my $of (keys %omfseen) {
  592. if ($omfafterinstall{$of}) {
  593. &perror("FATAL: move \"\@exec scrollkeeper-install\" ".
  594. "line to make sure that it is placed after ".
  595. "the $of entry. (currently on line ".
  596. "$omfinstallseen{$of} in $file)");
  597. }
  598. }
  599. }
  600. if (!scalar(keys %omfremoveseen)) {
  601. &perror("FATAL: \"\@unexec scrollkeeper-uninstall\" must be ".
  602. "placed after the OMF file it uninstalls.");
  603. } else {
  604. foreach my $of (keys %omfseen) {
  605. if ($omfafterremove{$of}) {
  606. &perror("FATAL: move \"\@unexec scrollkeeper-uninstall\" ".
  607. "line to make sure that it is placed after ".
  608. "the $of entry. (currently on line ".
  609. "$omfremoveseen{$of} in $file)");
  610. }
  611. }
  612. }
  613. }
  614. if (!$autoinfo && $infoseen) {
  615. if (!$infoinstallseen) {
  616. if ($infooverwrite) {
  617. &perror("FATAL: install-info must be used to ".
  618. "add/delete entries into \"info/dir\".");
  619. }
  620. &perror("FATAL: \"\@exec install-info \%D/... \%D/info/dir\" must be placed ".
  621. "after all the info files.");
  622. } elsif ($infoafterinstall) {
  623. &perror("FATAL: move \"\@exec install-info\" line to make ".
  624. "sure that it is placed after all the info files. ".
  625. "(currently on line $infoinstallseen in $file)");
  626. }
  627. if (!$inforemoveseen) {
  628. &perror("FATAL: \"\@unexec install-info --delete \%D/... \%D/info/dir\" must ".
  629. "be placed before any of the info files listed.");
  630. } elsif ($infobeforeremove) {
  631. &perror("FATAL: move \"\@exec install-info --delete\" ".
  632. "line to make sure ".
  633. "that it is placed before any of the info files. ".
  634. "(currently on line $inforemoveseen in $file)");
  635. }
  636. }
  637. close(IN);
  638. }
  639. #
  640. # misc files
  641. #
  642. sub checkpathname {
  643. my($file) = @_;
  644. my($whole);
  645. open(IN, "< $file") || return 0;
  646. $whole = '';
  647. while (<IN>) {
  648. $whole .= $_;
  649. }
  650. &abspathname($whole, $file);
  651. close(IN);
  652. }
  653. sub checklastline {
  654. my($file) = @_;
  655. my($whole);
  656. open(IN, "< $file") || return 0;
  657. $whole = '';
  658. while (<IN>) {
  659. $whole .= $_;
  660. }
  661. if ($whole !~ /\n$/) {
  662. &perror("FATAL: the last line of $file has to be ".
  663. "terminated by \\n.");
  664. }
  665. if ($whole =~ /\n([ \t]*\n)+$/) {
  666. &perror("WARN: $file seems to have unnecessary blank lines ".
  667. "at the last part.");
  668. }
  669. close(IN);
  670. }
  671. sub checkpatch {
  672. my($file) = @_;
  673. my($whole);
  674. if (-z "$file") {
  675. &perror("FATAL: $file has no content. should be removed ".
  676. "from repository.");
  677. return;
  678. }
  679. open(IN, "< $file") || return 0;
  680. $whole = '';
  681. while (<IN>) {
  682. $whole .= $_;
  683. }
  684. if ($committer && $whole =~ /\$([A-Za-z0-9]+)[:\$]/) {
  685. &perror("WARN: $file includes possible RCS tag \"\$$1\$\". ".
  686. "use binary mode (-ko) on commit/import.") unless
  687. $1 eq $rcsidstr;
  688. }
  689. close(IN);
  690. }
  691. #
  692. # Makefile
  693. #
  694. sub checkmakefile {
  695. my($file) = @_;
  696. my($rawwhole, $whole, $idx, @sections);
  697. my($i, $j, $k, $l);
  698. my @cat = ();
  699. my $has_lang_cat = 0;
  700. my $port_lang = '';
  701. my $tmp;
  702. my $bogusdistfiles = 0;
  703. my @varnames = ();
  704. my($portname, $portversion, $distfiles, $distname, $extractsufx) = ('', '', '', '', '');
  705. my $masterport = 0;
  706. my $slaveport = 0;
  707. my $use_gnome_hack = 0;
  708. my($realwrksrc, $wrksrc, $nowrksubdir) = ('', '', '');
  709. my(@mman, @pman);
  710. open(IN, "< $file") || return 0;
  711. $rawwhole = '';
  712. $tmp = 0;
  713. while (<IN>) {
  714. if ($_ =~ /[ \t]+\n?$/) {
  715. &perror("WARN: $file $.: whitespace before ".
  716. "end of line.");
  717. }
  718. if ($_ =~ /^ /) { # 8 spaces here!
  719. &perror("WARN: $file $.: use tab (not space) to make ".
  720. "indentation");
  721. }
  722. if ($usetabs) {
  723. if (m/^[A-Za-z0-9_-]+.?= /) {
  724. if (m/[?+]=/) {
  725. &perror("WARN: $file $.: use a tab (not space) after a ".
  726. "variable name");
  727. } else {
  728. &perror("FATAL: $file $.: use a tab (not space) after a ".
  729. "variable name");
  730. }
  731. }
  732. }
  733. #
  734. # I'm still not very convinced, for using this kind of magical word.
  735. # 1. This kind of items are not important for Makefile;
  736. # portlint should not require any additional rule to Makefile.
  737. # portlint should simply implement items that are declared in Handbook.
  738. # 2. If we have LINTSKIP, we can't stop people using LINTSKIP too much.
  739. # IMHO it is better to warn the user and let the user think twice,
  740. # than let the user escape from portlint.
  741. # Uncomment this part if you are willing to use these magical words.
  742. # Thu Jun 26 11:37:56 JST 1997
  743. # -- itojun
  744. #
  745. # if ($_ =~ /^# LINTSKIP\n?$/) {
  746. # print "OK: skipping from line $. in $file.\n"
  747. # if ($verbose);
  748. # $tmp = 1;
  749. # next;
  750. # }
  751. # if ($_ =~ /^# LINTAGAIN\n?$/) {
  752. # print "OK: check start again from line $. in $file.\n"
  753. # if ($verbose);
  754. # $tmp = 0;
  755. # next;
  756. # }
  757. # if ($_ =~ /# LINTIGNORE/) {
  758. # print "OK: ignoring line $. in $file.\n" if ($verbose);
  759. # next;
  760. # }
  761. # next if ($tmp);
  762. $rawwhole .= $_;
  763. }
  764. close(IN);
  765. #
  766. # whole file: blank lines.
  767. #
  768. $whole = "\n" . $rawwhole;
  769. study $whole;
  770. print "OK: checking contiguous blank lines in $file.\n"
  771. if ($verbose);
  772. $i = "\n" x ($contblank + 2);
  773. if ($whole =~ /$i/) {
  774. &perror("FATAL: contiguous blank lines (> $contblank lines) found ".
  775. "in $file at line " . (&linenumber($`)) . ".");
  776. }
  777. #
  778. # whole file: $(VARIABLE)
  779. #
  780. if ($parenwarn) {
  781. print "OK: checking for \$(VARIABLE).\n" if ($verbose);
  782. if ($whole =~ /\$\([\w\d]+\)/) {
  783. &perror("WARN: use \${VARIABLE}, instead of ".
  784. "\$(VARIABLE) at line " . (&linenumber($`)) . ".");
  785. }
  786. }
  787. #
  788. # whole file: USE_* used too late
  789. #
  790. pos($whole) = 0;
  791. if ($whole =~ /^\.include\s+<bsd\.port\.pre\.mk>$/gm) {
  792. print "OK: checking for USE_* used too late.\n" if ($verbose);
  793. my @use_early = qw(
  794. APACHE
  795. GNUSTEP
  796. IMAKE
  797. JAVA
  798. KDE(?:BASE|LIBS)_VER
  799. LIBRUBY
  800. LINUX_PREFIX
  801. OPENSSL
  802. PYTHON
  803. QT2?
  804. QT_VER
  805. RUBY
  806. X_PREFIX
  807. );
  808. my @other_early = qw(
  809. EMACS_PORT_NAME
  810. );
  811. my $earlypattern = join('|', 'USE_(?:'.join('|', @use_early).')',
  812. @other_early);
  813. while ($whole =~ /^($earlypattern)[+?:!]?=/gmo) {
  814. &perror("FATAL: $1 is set at line " . (&linenumber($`)) . " after ".
  815. "including bsd.port.pre.mk.");
  816. }
  817. }
  818. #
  819. # whole file: anything after bsd.port(.post).mk
  820. #
  821. print "OK: checking for anything after bsd.port(.post).mk.\n"
  822. if ($verbose);
  823. if ($whole =~ /^\.include\s+<bsd\.port(?:\.post)\.mk>\s*[^\s]/m) {
  824. &perror("FATAL: do not include anything after bsd.port(.post).mk.");
  825. }
  826. #
  827. # whole file: USE_* as a user-settable option
  828. #
  829. print "OK: checking for USE_* as a user-settable option.\n" if ($verbose);
  830. while ($whole =~ /\n\s*\.\s*(?:el)?if[^\n]*?\b(\w*USE_)(\w+)(?\![^\n]*\n#?\.error)/g) {
  831. my $lineno = &linenumber($`);
  832. &perror("WARN: is $1$2 a user-settable option at line $lineno? ".
  833. "Consider using WITH_$2 instead.")
  834. if ($1.$2 ne 'USE_GCC');
  835. }
  836. #
  837. # whole file: NO_CHECKSUM
  838. #
  839. # XXX Don't compress newlines since it messes up line number calculation.
  840. #$whole =~ s/\n#[^\n]*/\n/g;
  841. #$whole =~ s/\n\n+/\n/g;
  842. print "OK: checking NO_CHECKSUM.\n" if ($verbose);
  843. if ($whole =~ /\nNO_CHECKSUM/) {
  844. &perror("FATAL: use of NO_CHECKSUM discouraged. ".
  845. "it is intended to be a user variable.");
  846. }
  847. #
  848. # whole file: PKGNAME
  849. #
  850. print "OK: checking PKGNAME.\n" if ($verbose);
  851. if ($whole =~ /\nPKGNAME.?=/) {
  852. &perror("FATAL: PKGNAME is obsoleted by PORTNAME, ".
  853. "PORTVERSION, PKGNAMEPREFIX and PKGNAMESUFFIX.");
  854. }
  855. #
  856. # whole file: IS_INTERACTIVE/NOPORTDOCS
  857. #
  858. print "OK: checking IS_INTERACTIVE.\n" if ($verbose);
  859. if ($whole =~ /\nIS_INTERACTIVE/) {
  860. if ($whole !~ /defined\((BATCH|FOR_CDROM)\)/) {
  861. &perror("WARN: use of IS_INTERACTIVE discouraged. ".
  862. "provide batch mode by using BATCH and/or ".
  863. "FOR_CDROM.");
  864. }
  865. }
  866. print "OK: checking for use of NOPORTDOCS.\n" if ($verbose);
  867. if ($whole =~ /NOPORTSDOC/) {
  868. &perror("WARN: NOPORTSDOC found at " . (&linenumber($`)) . ". Do you ".
  869. "mean NOPORTDOCS?");
  870. }
  871. if ($sharedocused && $whole !~ /defined\s*\(?NOPORTDOCS\)?/
  872. && $whole !~ /def\s*\(?NOPORTDOCS\)?/
  873. && $whole !~ m#(\$[\{\(]PREFIX[\}\)]|$localbase)/share/doc#) {
  874. &perror("WARN: use \".if !defined(NOPORTDOCS)\" to wrap ".
  875. "installation of files into $localbase/share/doc.");
  876. }
  877. #
  878. # whole file: direct use of command names
  879. #
  880. my %cmdnames = ();
  881. print "OK: checking direct use of command names.\n" if ($verbose);
  882. foreach my $i (qw(
  883. awk basename cat chmod chown cp echo expr false file find gmake grep gzcat
  884. ldconfig ln md5 mkdir mv patch perl rm rmdir ruby sed sh touch tr which xargs xmkmf
  885. )) {
  886. $cmdnames{$i} = "\$\{\U$i\E\}";
  887. }
  888. $cmdnames{'env'} = '${SETENV}';
  889. $cmdnames{'gunzip'} = '${GUNZIP_CMD}';
  890. $cmdnames{'gzip'} = '${GZIP_CMD}';
  891. $cmdnames{'install'} = '${INSTALL_foobaa}';
  892. $cmdnames{'python'} = '${PYTHON_CMD}';
  893. $cmdnames{'strip'} = '${STRIP_CMD}';
  894. foreach my $i (qw(aclocal autoconf autoheader automake autoreconf autoupdate autoscan ifnames libtool libtoolize)) {
  895. $autocmdnames{$i} = "\$\{" . ( ( $i !~ /auto|aclocal|libtool/ ) ? "AUTO" : "" ) . "\U$i\E\}";
  896. }
  897. #
  898. # ignore parameter string to echo command.
  899. # note that we leave the command as is, since we need to check the
  900. # use of echo itself.
  901. $j = $whole;
  902. $j =~ s/([ \t][\@\-]{0,2})(echo|\$[\{\(]ECHO[\}\)]|\$[\{\(]ECHO_MSG[\}\)])[ \t]+("(\\'|\\"|[^"])*"|'(\\'|\\"|[^'])*')[ \t]*[;\n]/$1$2;\n/g; #"
  903. foreach my $i (keys %cmdnames) {
  904. # XXX This is a hack. Really, we should break $j up into individual
  905. # lines, and go through each one.
  906. # if ($j =~ /([^ \t\/]*[ \t\/][\@\-]{0,2}$i[ \t\n;][^\n]*\n?)/) {
  907. while ($j =~ /^(.*$i.*)$/gm) {
  908. my $curline = $1;
  909. my $lineno = &linenumber($`);
  910. if ($curline =~ /(^|\s+)[\@\-]{0,2}$i\b/
  911. && $curline !~ /^[A-Z]+_TARGET[?+]?=[^\n]+$i/m
  912. && $curline !~ /^IGNORE(.)?=[^\n]+$i/m
  913. && $curline !~ /^BROKEN(.)?=[^\n]+$i/m
  914. && $curline !~ /^RESTRICTED(.)?=[^\n]+$i/m
  915. && $curline !~ /^NO_PACKAGE(.)?=[^\n]+$i/m
  916. && $curline !~ /^NO_CDROM(.)?=[^\n]+$i/m
  917. && $curline !~ /^CATEGORIES(.)?=[^\n]+$i/m
  918. && $curline !~ /^COMMENT(.)?=[^\n]+$i/m) {
  919. &perror("WARN: possible direct use of command \"$i\" ".
  920. "found at line $lineno. use $cmdnames{$i} instead.");
  921. }
  922. }
  923. }
  924. foreach my $i (keys %autocmdnames) {
  925. # XXX Same hack as above.
  926. # if ($j =~ /([^ \t\/]*[ \t\/][\@\-]{0,2}($i\d*)[ \t\n;][^\n]*\n?)/) {
  927. while ($j =~ /^(.*($i\d*).*)$/gm) {
  928. my $lm = $1;
  929. my $sm = $2;
  930. my $lineno = &linenumber($`);
  931. if ($lm =~ /(^|\s+)[\@\-]{0,2}($i\d*)\b/
  932. && $lm !~ /^[A-Z]+_TARGET[?+]?=[^\n]+($i\d*)/m
  933. && $lm !~ /^IGNORE(.)?=[^\n]+($i\d*)/m
  934. && $lm !~ /^BROKEN(.)?=[^\n]+($i\d*)/m
  935. && $lm !~ /^RESTRICTED(.)?=[^\n]+($i\d*)/m
  936. && $lm !~ /^NO_PACKAGE(.)?=[^\n]+($i\d*)/m
  937. && $lm !~ /^NO_CDROM(.)?=[^\n]+($i\d*)/m
  938. && $lm !~ /^CATEGORIES(.)?=[^\n]+($i\d*)/m
  939. && $lm !~ /^COMMENT(.)?=[^\n]+($i\d*)/m) {
  940. &perror("WARN: possible direct use of command \"$sm\" ".
  941. "found at line $lineno. Use $autocmdnames{$i} ".
  942. "instead and set according USE_*_VER= flag");
  943. }
  944. }
  945. }
  946. #
  947. # whole file: ldconfig must come with "true" command
  948. #
  949. if ($ldconfigwithtrue
  950. && $j =~ /(ldconfig|\$[{(]LDCONFIG[)}])/
  951. && $j !~ /(\/usr\/bin\/true|\$[{(]TRUE[)}])/) {
  952. &perror("FATAL: ldconfig must be used with \"||\${TRUE}\".");
  953. }
  954. #
  955. # whole file: ${GZIP_CMD} -9 (or any other number)
  956. #
  957. if ($j =~ /\${GZIP_CMD}\s+-(\w+(\s+-)?)*(\d)/) {
  958. &perror("WARN: possible use of \"\${GZIP_CMD} -$3\" ".
  959. "found. \${GZIP_CMD} includes \"-\${GZIP}\" which ".
  960. "sets the compression level.");
  961. }
  962. #
  963. # whole file: ${MKDIR} -p
  964. #
  965. if ($j =~ /\${MKDIR}\s+-p/) {
  966. &perror("WARN: possible use of \"\${MKDIR} -p\" ".
  967. "found at line " . (&linenumber($`)) . ". \${MKDIR} includes ".
  968. "\"-p\" by default.");
  969. }
  970. #
  971. # whole file: full path name
  972. #
  973. &abspathname($whole, $file);
  974. #
  975. # whole file: SITE_PERL
  976. #
  977. print "OK: checking SITE_PERL.\n" if ($verbose);
  978. if ($whole =~ /\nSITE_PERL[?:]?=/) {
  979. &perror("FATAL: use of SITE_PERL discouraged. ".
  980. "it is set in bsd.port.mk.");
  981. }
  982. #
  983. # whole file: ${LOCALBASE}/lib/perl5/site_perl/${PERL_VER}
  984. #
  985. if ($j =~ m'\${(?:LOCALBASE|PREFIX)}/lib/perl5/site_perl/\${PERL_VER}') {
  986. &perror("WARN: possible use of \"\${LOCALBASE}/lib/perl5/site_perl/\${PERL_VER}\" ".
  987. "found. use \"\${SITE_PERL}\" instead.");
  988. }
  989. #
  990. # whole file: USE_GNOME check
  991. #
  992. if ($whole =~ /^USE_GNOME[?:]?=\s*(.*)$/m) {
  993. if ($1 =~ /gnomehack/) {
  994. $use_gnome_hack = 1;
  995. }
  996. }
  997. #
  998. # whole file: check for deprecated USE_MESA
  999. #
  1000. if ($whole =~ /^USE_MESA[?:]?=/m) {
  1001. &perror("WARN: USE_MESA is deprecated at line " . (&linenumber($`)) .
  1002. ". use USE_GL instead.");
  1003. }
  1004. #
  1005. # slave port check
  1006. #
  1007. my $masterdir = $makevar{MASTERDIR};
  1008. if ($masterdir ne '' && $masterdir ne $makevar{'.CURDIR'}) {
  1009. $slaveport = 1;
  1010. print "OK: slave port detected, checking for inclusion of $masterdir/Makefile.\n"
  1011. if ($verbose);
  1012. if ($whole !~ /\n\.include\s+[<"]\$\{MASTERDIR\}\/Makefile[">]\s*$/) {
  1013. &perror('FATAL: the last line of a slave port\'s Makefile has to be'.
  1014. ' .include "${MASTERDIR}/Makefile"');
  1015. }
  1016. print "OK: checking master port in $masterdir.\n" if ($verbose);
  1017. if (! -e "$masterdir/Makefile") {
  1018. &perror("WARN: unable to locate master port in $masterdir");
  1019. }
  1020. }
  1021. #
  1022. # break the makefile into sections.
  1023. #
  1024. $tmp = $rawwhole;
  1025. # keep comment, blank line, comment in the same section
  1026. $tmp =~ s/(#.*\n)\n+(#.*)/$1$2/g;
  1027. @sections = split(/\n\n+/, $tmp);
  1028. for ($i = 0; $i <= $#sections; $i++) {
  1029. if ($sections[$i] !~ /\n$/) {
  1030. $sections[$i] .= "\n";
  1031. }
  1032. }
  1033. $idx = 0;
  1034. #
  1035. # section 1: comment lines.
  1036. #
  1037. print "OK: checking comment section of $file.\n" if ($verbose);
  1038. my @linestocheck = split("\n", <<EOF);
  1039. Whom
  1040. Date [cC]reated
  1041. EOF
  1042. if ($osname eq 'NetBSD') {
  1043. unshift(@linestocheck, '(New )?[pP](ackage|ort)s [cC]ollection [mM]akefile [fF]or');
  1044. } else {
  1045. unshift(@linestocheck, '(New )?[pP]orts [cC]ollection [mM]akefile [fF]or');
  1046. }
  1047. $tmp = $sections[$idx++];
  1048. $tmp = "\n" . $tmp; # to make the begin-of-line check easier
  1049. if ($tmp =~ /\n[^#]/) {
  1050. &perror("FATAL: non-comment line in comment section of $file.");
  1051. }
  1052. foreach my $i (@linestocheck) {
  1053. $j = $i;
  1054. $j =~ s/\(.*\)\?//g;
  1055. $j =~ s/\[(.)[^\]]*\]/$1/g;
  1056. if ($tmp !~ /# $i:[ \t]+\S+/) {
  1057. &perror("FATAL: no \"$j\" line in comment section of $file.");
  1058. } else {
  1059. print "OK: \"$j\" seen in $file.\n" if ($verbose);
  1060. }
  1061. }
  1062. if ($tmp =~ m/Version [rR]equired/) {
  1063. &perror("WARN: Version required is no longer needed in the comment section of $file.");
  1064. }
  1065. my $tmp2 = "";
  1066. for (split(/\n/, $tmp)) {
  1067. $tmp2 .= $_ if (m/\$$rcsidstr/);
  1068. }
  1069. if ($tmp2 !~ /#(\s+)\$$rcsidstr([^\$]*)\$$/) {
  1070. &perror("FATAL: no \$$rcsidstr\$ line in $file comment ".
  1071. "section.");
  1072. } else {
  1073. print "OK: \$$rcsidstr\$ seen in $file.\n" if ($verbose);
  1074. if ($1 ne ' ') {
  1075. &perror("WARN: please use single whitespace ".
  1076. "right before \$$rcsidstr\$ tag.");
  1077. }
  1078. if ($2 ne '') {
  1079. if ($verbose || $newport) { # XXX
  1080. &perror("WARN: ".
  1081. ($newport ? 'for new port, '
  1082. : 'is it a new port? if so, ').
  1083. "make \$$rcsidstr\$ tag in comment ".
  1084. "section empty, to make CVS happy.");
  1085. }
  1086. }
  1087. }
  1088. #
  1089. # for the rest of the checks, comment lines are not important.
  1090. #
  1091. for ($i = 0; $i < scalar(@sections); $i++) {
  1092. $sections[$i] = "\n" . $sections[$i];
  1093. $sections[$i] =~ s/\n#[^\n]*//g;
  1094. $sections[$i] =~ s/\n\n+/\n/g;
  1095. $sections[$i] =~ s/\\\n/ /g;
  1096. $sections[$i] =~ s/^\n//;
  1097. }
  1098. #
  1099. #
  1100. # section 2: PORTNAME/PORTVERSION/...
  1101. #
  1102. print "OK: checking first section of $file (PORTNAME/...).\n"
  1103. if ($verbose);
  1104. $tmp = $sections[$idx++];
  1105. # check the order of items.
  1106. &checkorder('PORTNAME', $tmp, qw(
  1107. PORTNAME PORTVERSION PORTREVISION PORTEPOCH CATEGORIES MASTER_SITES
  1108. MASTER_SITE_SUBDIR PKGNAMEPREFIX PKGNAMESUFFIX DISTNAME EXTRACT_SUFX
  1109. DISTFILES DIST_SUBDIR EXTRACT_ONLY
  1110. ));
  1111. # check the items that has to be there.
  1112. $tmp = "\n" . $tmp;
  1113. print "OK: checking PORTNAME/PORTVERSION.\n" if ($verbose);
  1114. if ($tmp !~ /\nPORTNAME(.)?=/) {
  1115. &perror("FATAL: PORTNAME has to be there.") unless ($slaveport && $makevar{PORTNAME} ne '');
  1116. } elsif ($1 ne '') {
  1117. &perror("WARN: unless this is a master port, PORTNAME has to be set by \"=\", ".
  1118. "not by \"$1=\".") unless ($masterport);
  1119. }
  1120. if ($tmp !~ /\nPORTVERSION(.)?=/) {
  1121. &perror("FATAL: PORTVERSION has to be there.") unless ($slaveport && $makevar{PORTVERSION} ne '');
  1122. } elsif ($1 ne '') {
  1123. &perror("WARN: unless this is a master port, PORTVERSION has to be set by \"=\", ".
  1124. "not by \"$1=\".") unless ($masterport);
  1125. }
  1126. print "OK: checking CATEGORIES.\n" if ($verbose);
  1127. if ($tmp !~ /\nCATEGORIES(.)?=/) {
  1128. &perror("FATAL: CATEGORIES has to be there.") unless ($slaveport && $makevar{CATEGORIES} ne '');
  1129. } elsif (($i = $1) ne '' && $i =~ /[^?+]/) {
  1130. &perror("WARN: unless this is a master port, CATEGORIES should be set by \"=\", \"?=\", or \"+=\", ".
  1131. "not by \"$i=\".") unless ($masterport);
  1132. }
  1133. @cat = split(/\s+/, $makevar{CATEGORIES});
  1134. if (@cat == 0) {
  1135. &perror("FATAL: CATEGORIES left blank. set it to \"misc\"".
  1136. " if nothing seems apropriate.");
  1137. }
  1138. if ($committer && $makevar{'.CURDIR'} =~ m'/([^/]+)/[^/]+/?$') {
  1139. if ($cat[0] ne $1 && $makevar{PKGCATEGORY} ne $1 ) {
  1140. &perror("FATAL: category \"$1\" must be listed first");
  1141. }
  1142. }
  1143. #MICHAEL: can these three lang cat checks be combined?
  1144. # skip the first category specification if it's a language specific one.
  1145. if (grep($_ eq $cat[0], @lang_cat)) {
  1146. $has_lang_cat = 1;
  1147. $port_lang = $lang_pref{$cat[0]};
  1148. shift @cat;
  1149. }
  1150. # skip further if more language specific ones follow.
  1151. if (@cat && grep($_ eq $cat[0], @lang_cat)) {
  1152. &perror("WARN: multiple language specific categories detected. ".
  1153. "are you sure?");
  1154. do {
  1155. shift @cat;
  1156. } while (@cat && grep($_ eq $cat[0], @lang_cat));
  1157. }
  1158. # check x11 in CATEGORIES
  1159. if ($newxdef) {
  1160. #MICHAEL: I don't understand this line
  1161. if (2 <= @cat && $cat[1] eq "x11") {
  1162. &perror("WARN: only specific kind of apps should ".
  1163. "specify \"x11\" in CATEGORIES. ".
  1164. "Do you mean just USE_XLIB? ".
  1165. "Then remove \"x11\" from CATEGORIES.");
  1166. }
  1167. }
  1168. if (2 <= @cat) {
  1169. # skip the first one that we know is _not_ language specific.
  1170. shift @cat;
  1171. # any language specific one after non language specific ones?
  1172. foreach my $cat (@cat) {
  1173. if (grep($_ eq $cat, @lang_cat)) {
  1174. $has_lang_cat = 1;
  1175. $port_lang = $lang_pref{$cat};
  1176. &perror("WARN: when you specify multiple categories, ".
  1177. "language specific category should come first.");
  1178. }
  1179. }
  1180. }
  1181. # check the URL
  1182. if (($tmp =~ /\nMASTER_SITES[+?]?=[ \t]*([^\n]*)\n/
  1183. && $1 !~ /^[ \t]*$/) || ($makevar{MASTER_SITES} ne '')) {
  1184. print "OK: seen MASTER_SITES, sanity checking URLs.\n"
  1185. if ($verbose);
  1186. my @sites = split(/\s+/, $1);
  1187. my $skipnext = 0;
  1188. foreach my $i (@sites) {
  1189. if ($skipnext) {
  1190. $skipnext = 0;
  1191. next;
  1192. }
  1193. $skipnext++ if ($i =~ /^#/);
  1194. if ($i =~ m#^\w+://#) {
  1195. &urlcheck($i);
  1196. unless (&is_predefined($i)) {
  1197. print "OK: URL \"$i\" ok.\n"
  1198. if ($verbose);
  1199. }
  1200. } else {
  1201. print "OK: non-URL \"$i\" ok.\n"
  1202. if ($verbose);
  1203. }
  1204. }
  1205. } else {
  1206. &perror("WARN: no MASTER_SITES found. is it ok?");
  1207. }
  1208. # check DISTFILES and related items.
  1209. $distfiles = $1 if ($tmp =~ /\nDISTFILES[+?]?=[ \t]*([^\n]+)\n/);
  1210. #$portname = $1 if ($tmp =~ /\nPORTNAME[+?]?=[ \t]*([^\n]+)\n/);
  1211. #$portversion = $1 if ($tmp =~ /\nPORTVERSION[+?]?=[ \t]*([^\n]+)\n/);
  1212. $portname = $makevar{PORTNAME};
  1213. $portversion = $makevar{PORTVERSION};
  1214. $distname = $1 if ($tmp =~ /\nDISTNAME[+?]?=[ \t]*([^\n]+)\n/);
  1215. $extractsufx = $1 if ($tmp =~ /\nEXTRACT_SUFX[+?]?=[ \t]*([^\n]+)\n/);
  1216. # check bogus EXTRACT_SUFX.
  1217. if ($extractsufx ne '') {
  1218. print "OK: seen EXTRACT_SUFX, checking value.\n" if ($verbose);
  1219. if ($distfiles ne '') {
  1220. &perror("WARN: no need to define EXTRACT_SUFX if ".
  1221. "DISTFILES is defined.");
  1222. }
  1223. if ($extractsufx eq '.tar.gz') {
  1224. &perror("WARN: EXTRACT_SUFX is \".tar.gz.\" ".
  1225. "by default. you don't need to specify it.");
  1226. }
  1227. } else {
  1228. print "OK: no EXTRACT_SUFX seen, using default value.\n"
  1229. if ($verbose);
  1230. $extractsufx = '.tar.gz';
  1231. }
  1232. print "OK: sanity checking PORTNAME/PORTVERSION.\n" if ($verbose);
  1233. if ($distname ne '' && $distname eq "$portname-$portversion") {
  1234. &perror("WARN: DISTNAME is \${PORTNAME}-\${PORTVERSION} by default, ".
  1235. "you don't need to define DISTNAME.");
  1236. }
  1237. if ($portname =~ /^$re_lang_short/) {
  1238. &perror("FATAL: language prefix is automatically".
  1239. " set by PKGNAMEPREFIX.".
  1240. " you must remove it from PORTNAME.");
  1241. }
  1242. if ($portname =~ /\$[\{\(].+[\}\)]/) {
  1243. &perror("WARN: using variable in PORTNAME.".
  1244. " consider using PKGNAMEPREFIX and/or PKGNAMESUFFIX.");
  1245. } elsif ($portname =~ /-/ && $distname ne '') {
  1246. &perror("WARN: using hyphen in PORTNAME.".
  1247. " consider using PKGNAMEPREFIX and/or PKGNAMESUFFIX.");
  1248. }
  1249. if ($portversion eq '') {
  1250. &perror("FATAL: PORTVERSION must be specified");
  1251. }
  1252. if ($portversion =~ /^pl[0-9]*$/
  1253. || $portversion =~ /^[0-9]*[A-Za-z]?[0-9]*(\.[0-9]*[A-Za-z]?[0-9]*)*$/) {
  1254. print "OK: PORTVERSION \"$portversion\" looks fine.\n" if ($verbose);
  1255. } elsif ($portversion =~ /^[^\-]*\$[{\(].+[\)}][^\-]*$/) {
  1256. &perror("WARN: using variable, \"$portversion\", as version number");
  1257. } elsif ($portversion =~ /-/) {
  1258. &perror("FATAL: PORTVERSION should not contain a hyphen.".
  1259. "should modify \"$portversion\".");
  1260. } else {
  1261. &perror("FATAL: PORTVERSION looks illegal. ".
  1262. "should modify \"$portversion\".");
  1263. }
  1264. # if DISTFILES have only single item, it is better to avoid DISTFILES
  1265. # and to use combination of DISTNAME and EXTRACT_SUFX.
  1266. # example:
  1267. # DISTFILES=package-1.0.tgz
  1268. # should be
  1269. # DISTNAME= package-1.0
  1270. # EXTRACT_SUFX= .tgz
  1271. if ($distfiles =~ /^\S+$/ && $distfiles !~ /:[^\/:]+$/) {
  1272. $bogusdistfiles++;
  1273. print "OK: seen DISTFILES with single item, checking value.\n"
  1274. if ($verbose);
  1275. &perror("WARN: use of DISTFILES with single file ".
  1276. "discouraged. distribution filename should be set by ".
  1277. "DISTNAME and EXTRACT_SUFX.");
  1278. if ($distfiles eq (($distname ne '') ? $distname : "$portname-$portversion") . $extractsufx) {
  1279. &perror("WARN: definition of DISTFILES not necessary. ".
  1280. "DISTFILES is \${DISTNAME}/\${EXTRACT_SUFX} ".
  1281. "by default.");
  1282. }
  1283. # display advice only in certain cases.
  1284. #MICHAEL: will this work with multiple distfiles in this list? what about
  1285. # doing the same sort of thing for DISTNAME, is it needed?
  1286. if ($distfiles =~ /^\Q$i\E([\-.].+)$/) {
  1287. &perror("WARN: how about \"EXTRACT_SUFX=$1\"".
  1288. ", instead of DISTFILES?");
  1289. }
  1290. }
  1291. # additional checks for committer.
  1292. if ($committer && $has_lang_cat) {
  1293. &perror("WARN: be sure to include language code \"$port_lang-\" ".
  1294. "in the module alias name.");
  1295. }
  1296. if ($committer) {
  1297. if (opendir(DIR, ".")) {
  1298. my @tgz = grep(/\.tgz$/, readdir(DIR));
  1299. closedir(DIR);
  1300. if (@tgz) {
  1301. my $tgz = (2 <= @tgz)
  1302. ? '{' . join(',', @tgz) . '}'
  1303. : $tgz[0];
  1304. &perror("WARN: be sure to remove $portdir/$tgz ".
  1305. "before committing the port.");
  1306. }
  1307. }
  1308. }
  1309. push(@varnames, qw(
  1310. PORTNAME PORTVERSION PORTREVISION PORTEPOCH CATEGORIES MASTER_SITES
  1311. MASTER_SITE_SUBDIR PKGNAMEPREFIX PKGNAMESUFFIX DISTNAME EXTRACT_SUFX
  1312. DISTFILES EXTRACT_ONLY
  1313. ));
  1314. #
  1315. # section 3: PATCH_SITES/PATCHFILES(optional)
  1316. #
  1317. print "OK: checking second section of $file (PATCH*: optional).\n"
  1318. if ($verbose);
  1319. $tmp = $sections[$idx];
  1320. if ($tmp =~ /(PATCH_SITES|PATCH_SITE_SUBDIR|PATCHFILES|PATCH_DIST_STRIP)/) {
  1321. &checkearlier($file, $tmp, @varnames);
  1322. if ($tmp =~ /^PATCH_SITES=/) {
  1323. print "OK: seen PATCH_SITES.\n" if ($verbose);
  1324. $tmp =~ s/^[^\n]+\n//;
  1325. }
  1326. if ($tmp =~ /^PATCH_SITE_SUBDIR=/) {
  1327. print "OK: seen PATCH_SITE_SUBDIR.\n" if ($verbose);
  1328. $tmp =~ s/^[^\n]+\n//;
  1329. }
  1330. if ($tmp =~ /^PATCHFILES=/) {
  1331. print "OK: seen PATCHFILES.\n" if ($verbose);
  1332. $tmp =~ s/^[^\n]+\n//;
  1333. }
  1334. if ($tmp =~ /^PATCH_DIST_STRIP=/) {
  1335. print "OK: seen PATCH_DIST_STRIP.\n" if ($verbose);
  1336. $tmp =~ s/^[^\n]+\n//;
  1337. }
  1338. &checkextra($tmp, 'PATCH_SITES');
  1339. $idx++;
  1340. }
  1341. push(@varnames, qw(
  1342. PATCH_SITES PATCHFILES PATCH_DIST_STRIP
  1343. ));
  1344. #
  1345. # section 4: MAINTAINER
  1346. #
  1347. print "OK: checking third section of $file (MAINTAINER).\n"
  1348. if ($verbose);
  1349. $tmp = $sections[$idx++];
  1350. &checkearlier($file, $tmp, @varnames);
  1351. &checkorder('MAINTAINER', $tmp, qw(
  1352. MAINTAINER COMMENT
  1353. ));
  1354. $tmp = "\n" . $tmp;
  1355. if ($tmp =~ /\nMAINTAINER\??=([^\n]+)/) {
  1356. my $addr = $1;
  1357. $addr =~ s/^\s*//;
  1358. $addr =~ s/\s*$//;
  1359. if ($addr =~ /[\s,<>()]/) {
  1360. &perror("FATAL: MAINTAINER should be a single address without comment.");
  1361. }
  1362. if ($addr !~ /^[^\@]+\@[\w\d\-\.]+$/) {
  1363. &perror("FATAL: MAINTAINER address, $addr, does not appear to be a valid email address.");
  1364. }
  1365. $tmp =~ s/\nMAINTAINER\??=[^\n]+//;
  1366. } elsif ($whole !~ /\nMAINTAINER[?]?=/) {
  1367. &perror("FATAL: no MAINTAINER listed in $file.") unless ($slaveport && $makevar{MAINTAINER} ne '');
  1368. }
  1369. $tmp =~ s/\n\n+/\n/g;
  1370. # check COMMENT
  1371. if ($tmp !~ /\nCOMMENT(.)?=/) {
  1372. &perror("FATAL: COMMENT has to be there.") unless ($slaveport && $makevar{COMMENT} ne '');
  1373. } elsif ($1 ne '') {
  1374. &perror("WARN: unless this is a master port, COMMENT has to be set by \"=\", ".
  1375. "not by \"$1=\".") unless ($masterport);
  1376. } else { # check for correctness
  1377. if (($makevar{COMMENT} !~ /^["0-9A-Z]/) || ($makevar{COMMENT} =~ m/\.$/)) { #"
  1378. &perror("WARN: COMMENT should begin with a capital, and end without a period");
  1379. } elsif (length($makevar{COMMENT}) > 70) {
  1380. &perror("WARN: COMMENT exceeds 70 characters limit.");
  1381. }
  1382. }
  1383. push(@varnames, qw(
  1384. MAINTAINER COMMENT
  1385. ));
  1386. #
  1387. # section 5: *_DEPENDS (may not be there)
  1388. #
  1389. print "OK: checking fourth section of $file (*_DEPENDS).\n"
  1390. if ($verbose);
  1391. $tmp = $sections[$idx];
  1392. # NOTE: EXEC_DEPENDS is obsolete, so it should not be listed.
  1393. @linestocheck = qw(
  1394. EXTRACT_DEPENDS LIB_DEPENDS PATCH_DEPENDS BUILD_DEPENDS RUN_DEPENDS
  1395. FETCH_DEPENDS DEPENDS DEPENDS_TARGET
  1396. );
  1397. if ($tmp =~ /(LIB_|BUILD_|RUN_|FETCH_)?DEPENDS/) {
  1398. &checkearlier($file, $tmp, @varnames);
  1399. my %seen_depends;
  1400. if (!defined $ENV{'PORTSDIR'}) {
  1401. $ENV{'PORTSDIR'} = $portsdir;
  1402. }
  1403. foreach my $i (grep(/^[A-Z_]*DEPENDS[?+]?=/, split(/\n/, $tmp))) {
  1404. $i =~ s/^([A-Z_]*DEPENDS)[?+]?=[ \t]*//;
  1405. $j = $1;
  1406. $seen_depends{$j}++;
  1407. if ($j ne 'DEPENDS' &&
  1408. $i =~ /^\${([A-Z_]+DEPENDS)}\s*$/ &&
  1409. $seen_depends{$1} &&
  1410. $j ne $1)
  1411. {
  1412. print "OK: $j refers to $1, skipping checks.\n"
  1413. if ($verbose);
  1414. next;
  1415. }
  1416. print "OK: checking ports listed in $j.\n"
  1417. if ($verbose);
  1418. foreach my $k (split(/\s+/, $i)) {
  1419. my @l = split(':', $k);
  1420. print "OK: checking dependency value for $j.\n"
  1421. if ($verbose);
  1422. if (($j eq 'DEPENDS'
  1423. && scalar(@l) != 1 && scalar(@l) != 2)
  1424. || ($j ne 'DEPENDS'
  1425. && scalar(@l) != 2 && scalar(@l) != 3)) {
  1426. &perror("WARN: wrong dependency value ".
  1427. "for $j. $j requires ".
  1428. ($j eq 'DEPENDS'
  1429. ? "1 or 2 "
  1430. : "2 or 3 ").
  1431. "colon-separated tuples.");
  1432. next;
  1433. }
  1434. my %m = ();
  1435. if ($j eq 'DEPENDS') {
  1436. $m{'dir'} = $l[0];
  1437. $m{'tgt'} = $l[1];
  1438. } else {
  1439. $m{'dep'} = $l[0];
  1440. $m{'dir'} = $l[1];
  1441. $m{'tgt'} = $l[2];
  1442. }
  1443. print "OK: dep=\"$m{'dep'}\", ".
  1444. "dir=\"$m{'dir'}\", tgt=\"$m{'tgt'}\"\n"
  1445. if ($verbose);
  1446. # check USE_PERL5
  1447. if ($m{'dep'} =~ /^perl5(\.\d+)?$/) {
  1448. &perror("WARN: dependency to perl5 ".
  1449. "listed in $j. consider using ".
  1450. "USE_PERL5.");
  1451. }
  1452. # check USE_GMAKE
  1453. if ($m{'dep'} =~ /^(gmake|\${GMAKE})$/) {
  1454. &perror("WARN: dependency to $1 ".
  1455. "listed in $j. consider using ".
  1456. "USE_GMAKE.");
  1457. }
  1458. # check USE_QT
  1459. if ($m{'dep'} =~ /^(qt\d)+$/) {
  1460. &perror("WARN: dependency to $1 ".
  1461. "listed in $j. consider using ".
  1462. "USE_QT.");
  1463. }
  1464. # check USE_GETOPT_LONG
  1465. if ($m{'dep'} =~ /^(gnugetopt\.\d)+$/) {
  1466. &perror("WARN: dependency to $1 ".
  1467. "listed in $j. consider using ".
  1468. "USE_GETOPT_LONG.");
  1469. }
  1470. # check backslash in LIB_DEPENDS
  1471. if ($osname eq 'NetBSD' && $j eq 'LIB_DEPENDS'
  1472. && $m{'dep'} =~ /\\\\./) {
  1473. &perror("WARN: use of backslashes in ".
  1474. "$j is deprecated.");
  1475. }
  1476. # check for PREFIX
  1477. if ($m{'dep'} =~ /\${PREFIX}/) {
  1478. &perror("FATAL: \${PREFIX} must not be ".
  1479. "contained in *_DEPENDS. ".
  1480. "use \${LOCALBASE} or ".
  1481. "\${X11BASE} instead.");
  1482. }
  1483. # check port dir existence
  1484. $k = $m{'dir'};
  1485. $k =~ s/\${PORTSDIR}/$ENV{'PORTSDIR'}/;
  1486. $k =~ s/\$[\({]PORTSDIR[\)}]/$ENV{'PORTSDIR'}/;
  1487. if (! -d $k) {
  1488. &perror("WARN: no port directory $k ".
  1489. "found, even though it is ".
  1490. "listed in $j.");
  1491. } else {
  1492. print "OK: port directory $k found.\n"
  1493. if ($verbose);
  1494. }
  1495. }
  1496. }
  1497. foreach my $i (@linestocheck) {
  1498. $tmp =~ s/$i[?+]?=[^\n]+\n//g;
  1499. }
  1500. &checkextra($tmp, '*_DEPENDS');
  1501. $idx++;
  1502. }
  1503. push(@varnames, @linestocheck);
  1504. &checkearlier($file, $tmp, @varnames);
  1505. #
  1506. # Makefile 6: check the rest of file
  1507. #
  1508. print "OK: checking the rest of the $file.\n" if ($verbose);
  1509. $tmp = join("\n\n", @sections[$idx .. scalar(@sections)-1]);
  1510. $tmp = "\n" . $tmp; # to make the begin-of-line check easier
  1511. &checkearlier($file, $tmp, @varnames);
  1512. # check WRKSRC/NO_WRKSUBDIR
  1513. #
  1514. # do not use DISTFILES/DISTNAME to control over WRKSRC.
  1515. # DISTNAME is for controlling distribution filename.
  1516. # example:
  1517. # DISTNAME= package
  1518. # DISTFILES=package-1.0.tgz
  1519. # should be
  1520. # DISTNAME= package-1.0
  1521. # EXTRACT_SUFX=.tgz
  1522. # WRKSRC= ${WRKDIR}/package
  1523. #
  1524. print "OK: checking WRKSRC.\n" if ($verbose);
  1525. $wrksrc = $nowrksubdir = '';
  1526. $wrksrc = $1 if ($tmp =~ /\nWRKSRC[+?]?=[ \t]*([^\n]*)\n/);
  1527. $nowrksubdir = $1 if ($tmp =~ /\nNO_WRKSUBDIR[+?]?=[ \t]*([^\n]*)\n/);
  1528. if ($nowrksubdir eq '') {
  1529. $realwrksrc = $wrksrc ? "$wrksrc/$distname"
  1530. : "\${WRKDIR}/$distname";
  1531. } else {
  1532. $realwrksrc = $wrksrc ? $wrksrc : '${WRKDIR}';
  1533. }
  1534. print "OK: WRKSRC seems to be $realwrksrc.\n" if ($verbose);
  1535. if ($nowrksubdir eq '') {
  1536. print "OK: no NO_WRKSUBDIR, checking value of WRKSRC.\n"
  1537. if ($verbose);
  1538. if ($wrksrc eq 'work' || $wrksrc =~ /^$[\{\(]WRKDIR[\}\)]/) {
  1539. &perror("WARN: WRKSRC is set to meaningless value ".
  1540. "\"$1\".".
  1541. ($nowrksubdir eq ''
  1542. ? " use \"NO_WRKSUBDIR=yes\" instead."
  1543. : ""));
  1544. }
  1545. if ($bogusdistfiles) {
  1546. if ($distname ne '' && $wrksrc eq '') {
  1547. &perror("WARN: do not use DISTFILES and DISTNAME ".
  1548. "to control WRKSRC. how about ".
  1549. "\"WRKSRC=\${WRKDIR}/$distname\"?");
  1550. } else {
  1551. &perror("WARN: DISTFILES/DISTNAME affects WRKSRC. ".
  1552. "take caution when changing them.");
  1553. }
  1554. }
  1555. } else {
  1556. print "OK: seen NO_WRKSUBDIR, checking value of WRKSRC.\n"
  1557. if ($verbose);
  1558. if ($wrksrc eq 'work' || $wrksrc =~ /^$[\{\(]WRKDIR[\}\)]/) {
  1559. &perror("WARN: definition of WRKSRC not necessary. ".
  1560. "WRKSRC is \${WRKDIR} by default.");
  1561. }
  1562. }
  1563. # check RESTRICTED/NO_CDROM/NO_PACKAGE
  1564. print "OK: checking RESTRICTED/NO_CDROM/NO_PACKAGE.\n" if ($verbose);
  1565. if ($committer && $tmp =~ /\n(RESTRICTED|NO_CDROM|NO_PACKAGE)[+?]?=/) {
  1566. &perror("WARN: \"$1\" found. do not forget to update ".
  1567. "ports/LEGAL.");
  1568. }
  1569. # check NO_CONFIGURE/NO_PATCH
  1570. print "OK: checking NO_CONFIGURE/NO_PATCH.\n" if ($verbose);
  1571. if ($tmp =~ /\n(NO_CONFIGURE|NO_PATCH)[+?]?=/) {
  1572. &perror("FATAL: \"$1\" was obsoleted. remove this.");
  1573. }
  1574. # check MAN[1-9LN]
  1575. print "OK: checking MAN[0-9LN].\n" if ($verbose);
  1576. foreach my $i (keys %plistmanall) {
  1577. print "OK: pkg-plist MAN$i=$plistmanall{$i}\n" if ($verbose);
  1578. }
  1579. foreach my $i (split(//, $manchapters)) {
  1580. if ($tmp =~ /MAN\U$i\E=\s*([^\n]*)\n/) {
  1581. print "OK: Makefile MAN\U$i\E=$1\n" if ($verbose);
  1582. }
  1583. }
  1584. foreach my $i (split(//, $manchapters)) {
  1585. next if ($i eq '');
  1586. if ($tmp =~ /MAN\U$i\E=\s*([^\n]*)\n/) {
  1587. @mman = grep($_ !~ /^\s*$/, split(/\s+/, $1));
  1588. @pman = grep($_ !~ /^\s*$/,
  1589. split(/\s+/, $plistmanall{$i}));
  1590. foreach my $j (@mman) {
  1591. print "OK: checking $j (Makefile)\n"
  1592. if ($verbose);
  1593. if ($automan && grep($_ eq $j, @pman)) {
  1594. &perror("FATAL: duplicated manpage ".
  1595. "entry $j: content of ".
  1596. "MAN\U$i\E will be automatically ".
  1597. "added to pkg-plist.");
  1598. } elsif (!$automan && !grep($_ eq $j, @pman)) {
  1599. &perror("WARN: manpage $j in $file ".
  1600. "MAN\U$i\E but not in pkg-plist.");
  1601. }
  1602. }
  1603. foreach my $j (@pman) {
  1604. print "OK: checking $j (pkg-plist)\n" if ($verbose);
  1605. if (!grep($_ eq $j, @mman)) {
  1606. &perror("WARN: manpage $j in pkg-plist ".
  1607. "but not in $file MAN\U$i\E.");
  1608. }
  1609. }
  1610. } else {
  1611. if ($plistmanall{$i}) {
  1612. if ($manstrict) {
  1613. &perror("FATAL: manpage for chapter ".
  1614. "$i must be listed in ".
  1615. "$file MAN\U$i\E. ");
  1616. } else {
  1617. &perror("WARN: manpage for chapter ".
  1618. "$i should be listed in ".
  1619. "MAN\U$i\E, ".
  1620. "even if compression is ".
  1621. "not necessary.");
  1622. }
  1623. }
  1624. if ($mancompress && $plistman{$i}) {
  1625. &perror("WARN: MAN\U$i\E will help you ".
  1626. "compressing manual page in chapter ".
  1627. "\"$i\".");
  1628. } elsif (!$mancompress && $plistmangz{$i}) {
  1629. &perror("WARN: MAN\U$i\E will help you ".
  1630. "uncompressing manual page in chapter ".
  1631. "\"$i\".");
  1632. }
  1633. }
  1634. }
  1635. if ($tmp !~ /MANLANG/ && scalar(keys %manlangs)) {
  1636. $i = (keys %manlangs)[0];
  1637. &perror("WARN: how about using MANLANG for ".
  1638. "designating manual language, such as \"$i\"?");
  1639. }
  1640. # check INFO
  1641. print "OK: checking INFO.\n" if ($verbose);
  1642. if ($autoinfo && $tmp =~ /\nINFO=\s*([^\n]*)\n/) {
  1643. my @minfo = grep($_ !~ /^\s*$/, split(/\s+/, $1));
  1644. foreach $i (@minfo) {
  1645. if ($i =~ /\.info(-\d+)?$/) {
  1646. &perror("FATAL: do not include the .info extension ".
  1647. "on files listed in the INFO macro.");
  1648. }
  1649. }
  1650. }
  1651. # check USE_X11 and USE_IMAKE
  1652. if ($tmp =~ /\nUSE_IMAKE[?+]?=/
  1653. && $tmp =~ /\n(USE_X11)[?+]?=/) {
  1654. &perror("WARN: since you already have USE_IMAKE, ".
  1655. "you don't need $1.");
  1656. }
  1657. # check USE_X11 and USE_IMAKE
  1658. if ($newxdef && $tmp =~ /\nUSE_IMAKE[?+]?=/
  1659. && $tmp =~ /\n(USE_X_PREFIX)[?+]?=/) {
  1660. &perror("WARN: since you already have USE_IMAKE, ".
  1661. "you don't need $1.");
  1662. }
  1663. # check USE_X11 and USE_X_PREFIX
  1664. if ($newxdef && $tmp =~ /\nUSE_X11[?+]?=/
  1665. && $tmp !~ /\nUSE_X_PREFIX[?+]?=/) {
  1666. &perror("FATAL: meaning of USE_X11 was changed in Aug 1998. ".
  1667. "use USE_X_PREFIX instead.");
  1668. }
  1669. # check direct use of important make targets.
  1670. if ($tmp =~ /\n(fetch|extract|patch|configure|build|install):/) {
  1671. &perror("FATAL: direct redefinition of make target \"$1\" ".
  1672. "discouraged. redefine \"do-$1\" instead.");
  1673. }
  1674. # check for incorrect use of the pre-everything target.
  1675. if ($tmp =~ /\npre-everything:[^:]/) {
  1676. &perror("FATAL: use pre-everything:: instead of pre-everything:");
  1677. }
  1678. if ($tmp =~ /^pre-patch:/m && $use_gnome_hack) {
  1679. &perror("FATAL: pre-patch target overwrites gnomehack component. ".
  1680. "use post-patch instead.");
  1681. }
  1682. 1;
  1683. }
  1684. sub perror {
  1685. my(@msg) = @_;
  1686. if ($msg[0] =~ /^FATAL/) {
  1687. $err++;
  1688. } else {
  1689. $warn++;
  1690. }
  1691. print join("\n", @msg) . "\n";
  1692. }
  1693. sub checkextra {
  1694. my($str, $section) = @_;
  1695. $str = "\n" . $str if ($str !~ /^\n/);
  1696. $str =~ s/\n#[^\n]*/\n/g;
  1697. $str =~ s/\n\.[^\n]+/\n/g;
  1698. $str =~ s/\n\n+/\n/g;
  1699. $str =~ s/^\s+//;
  1700. $str =~ s/\s+$//;
  1701. return if ($str eq '');
  1702. if ($str =~ /^([\w\d]+)/) {
  1703. &perror("WARN: extra item placed in the ".
  1704. "$section section, ".
  1705. "for example, \"$1\".");
  1706. } else {
  1707. &perror("WARN: extra item placed in the ".
  1708. "$section section.");
  1709. }
  1710. }
  1711. sub checkorder {
  1712. my($section, $str, @order) = @_;
  1713. my(@items, $i, $j, $k, $invalidorder);
  1714. print "OK: checking the order of $section section.\n" if ($verbose);
  1715. @items = ();
  1716. foreach my $i (split("\n", $str)) {
  1717. $i =~ s/[+?]?=.*$//;
  1718. push(@items, $i);
  1719. }
  1720. @items = reverse(@items);
  1721. $j = -1;
  1722. $invalidorder = 0;
  1723. while (scalar(@items)) {
  1724. $i = pop(@items);
  1725. $k = 0;
  1726. while ($k < scalar(@order) && $order[$k] ne $i) {
  1727. $k++;
  1728. }
  1729. if ($order[$k] eq $i) {
  1730. if ($k < $j) {
  1731. &perror("FATAL: $i appears out-of-order.");
  1732. $invalidorder++;
  1733. } else {
  1734. print "OK: seen $i, in order.\n" if ($verbose);
  1735. }
  1736. $j = $k;
  1737. # This if condition tests for .if, .else (in all forms),
  1738. # .for and .endfor and .include
  1739. } elsif ($i !~ m/^\.(if|el|endif|for|endfor|include)/) {
  1740. &perror("FATAL: extra item \"$i\" placed in the ".
  1741. "$section section.");
  1742. }
  1743. }
  1744. if ($invalidorder) {
  1745. &perror("FATAL: order must be " . join('/', @order) . '.');
  1746. } else {
  1747. print "OK: $section section is ordered properly.\n"
  1748. if ($verbose);
  1749. }
  1750. }
  1751. sub checkearlier {
  1752. my($file, $str, @varnames) = @_;
  1753. my($i);
  1754. print "OK: checking items that has to appear earlier.\n" if ($verbose);
  1755. foreach my $i (@varnames) {
  1756. if ($str =~ /\n$i\??=/) {
  1757. &perror("WARN: \"$i\" has to appear earlier in $file.");
  1758. }
  1759. }
  1760. }
  1761. sub linenumber {
  1762. my $text = shift;
  1763. my @lines;
  1764. @lines = split /\n/, $text;
  1765. return scalar(@lines);
  1766. }
  1767. sub abspathname {
  1768. my($str, $file) = @_;
  1769. my($s, $i, %cmdnames);
  1770. my($pre);
  1771. # ignore parameter string to echo command
  1772. $str =~ s/[ \t][\@-]?(echo|\$[\{\(]ECHO[\}\)]|\$[\{\(]ECHO_MSG[\}\)])[ \t]+("(\\'|\\"|[^"])*"|'(\\'|\\"|[^"])*')[ \t]*[;\n]//; #'
  1773. print "OK: checking direct use of full pathnames in $file.\n"
  1774. if ($verbose);
  1775. foreach my $s (split(/\n+/, $str)) {
  1776. $i = '';
  1777. if ($s =~ /(^|[ \t\@'"-])(\/[\w\d])/) { #'
  1778. # suspected pathnames are recorded.
  1779. $i = $2 . $';
  1780. $pre = $` . $1;
  1781. if ($pre =~ /MASTER_SITE_SUBDIR/) {
  1782. # MASTER_SITE_SUBDIR lines are ok.
  1783. $i = '';
  1784. }
  1785. }
  1786. if ($i ne '') {
  1787. $i =~ s/\s.*$//;
  1788. $i =~ s/['"].*$//; #'
  1789. $i = substr($i, 0, 20) . '...' if (20 < length($i));
  1790. &perror("WARN: possible use of absolute pathname ".
  1791. "\"$i\", in $file.") unless ($i =~ m,^/compat/,);
  1792. }
  1793. }
  1794. print "OK: checking direct use of pathnames, phase 1.\n" if ($verbose);
  1795. %cmdnames = split(/\n|\t+/, <<EOF);
  1796. /usr/opt \${PORTSDIR} instead
  1797. $portsdir \${PORTSDIR} instead
  1798. $localbase \${PREFIX} or \${LOCALBASE}, as appropriate
  1799. /usr/X11 \${PREFIX} or \${X11BASE}, as appropriate
  1800. EOF
  1801. foreach my $i (keys %cmdnames) {
  1802. if ($str =~ /$i/) {
  1803. &perror("WARN: possible direct use of \"$&\" ".
  1804. "found in $file. if so, use $cmdnames{$i}.");
  1805. }
  1806. }
  1807. print "OK: checking direct use of pathnames, phase 2.\n" if ($verbose);
  1808. %cmdnames = split(/\n|\t+/, <<EOF);
  1809. distfiles \${DISTDIR} instead
  1810. pkg \${PKGDIR} instead
  1811. files \${FILESDIR} instead
  1812. scripts \${SCRIPTDIR} instead
  1813. patches \${PATCHDIR} instead
  1814. work \${WRKDIR} instead
  1815. EOF
  1816. foreach my $i (keys %cmdnames) {
  1817. if ($str =~ /(\.\/|\$[\{\(]\.CURDIR[\}\)]\/|[ \t])(\b$i)\//) {
  1818. &perror("WARN: possible direct use of \"$i\" ".
  1819. "found in $file. if so, use $cmdnames{$i}.");
  1820. }
  1821. }
  1822. }
  1823. sub is_predefined {
  1824. my($url) = @_;
  1825. my($site, $site_re);
  1826. my $subdir_re = quotemeta quotemeta '/%SUBDIR%/';
  1827. for my $site (keys %predefined) {
  1828. $site_re = quotemeta $site;
  1829. $site_re =~ s,$subdir_re,/(.*)/,;
  1830. if ($url =~ /$site_re/) {
  1831. &perror("WARN: how about using ".
  1832. "\"\${MASTER_SITE_$predefined{$site}}\" with ".
  1833. "\"MASTER_SITE_SUBDIR=$1\", instead of \"$url\"?");
  1834. return &TRUE;
  1835. }
  1836. }
  1837. undef;
  1838. }
  1839. sub urlcheck {
  1840. my ($url) = @_;
  1841. if ($url !~ m#^\w+://#) {
  1842. &perror("WARN: \"$url\" doesn't appear to be a URL to me.");
  1843. }
  1844. if ($url !~ m#/(:[^/:]+)?$#) {
  1845. &perror("FATAL: URL \"$url\" should ".
  1846. "end with \"/\" or a group name (e.g. :something).");
  1847. }
  1848. if ($url =~ m#://[^/]*:/#) {
  1849. &perror("FATAL: URL \"$url\" contains ".
  1850. "extra \":\".");
  1851. }
  1852. if ($osname == 'FreeBSD' && $url =~ m#(www\.freebsd\.org)/~.+/#i) {
  1853. &perror("WARN: URL \"$url\", ".
  1854. "$1 should be ".
  1855. "people.FreeBSD.org");
  1856. }
  1857. }
  1858. sub TRUE {1;}
  1859. # Local variables:
  1860. # tab-width: 4
  1861. # End: