portlint.pl 101 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413
  1. #! /usr/bin/perl -w
  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. # $MCom$
  21. #
  22. use strict;
  23. use warnings;
  24. use Getopt::Std;
  25. use File::Find;
  26. use IPC::Open2;
  27. use POSIX qw(strftime);
  28. sub perror($$$$);
  29. our ($opt_a, $opt_A, $opt_b, $opt_C, $opt_c, $opt_g, $opt_h, $opt_m, $opt_t, $opt_v, $opt_M, $opt_N, $opt_B, $opt_V, @ALLOWED_FULL_PATHS, @MASTERSITES_WHITELIST);
  30. my ($err, $warn);
  31. my ($extrafile, $parenwarn, $committer, $verbose, $usetabs, $newport,
  32. $grouperrs, $checkmfiles);
  33. my $contblank;
  34. my $portdir;
  35. my $makeenv = "";
  36. my @errlst = ();
  37. my %errcache = ();
  38. $err = $warn = 0;
  39. $extrafile = $parenwarn = $committer = $verbose = $usetabs = $newport = 0;
  40. $checkmfiles = 0;
  41. $contblank = 1;
  42. $portdir = '.';
  43. @ALLOWED_FULL_PATHS = qw(/boot/loader.conf /compat/ /dev/null /etc/inetd.conf);
  44. @MASTERSITES_WHITELIST = qw(googlecode.com nodeload.github.com);
  45. # version variables
  46. my $major = 2;
  47. my $minor = 14;
  48. my $micro = 2;
  49. sub l { '[{(]'; }
  50. sub r { '[)}]'; }
  51. sub s { '[ \t]'; }
  52. my $l = &l;
  53. my $r = &r;
  54. my $s = &s;
  55. # default setting - for FreeBSD
  56. my $portsdir = '/usr/ports';
  57. my $rcsidstr = 'FreeBSD';
  58. my $multiplist = 0;
  59. my $ldconfigwithtrue = 0;
  60. my $rcsidinplist = 0;
  61. my $mancompress = 1;
  62. my $manstrict = 0;
  63. my $newxdef = 1;
  64. my $automan = 1;
  65. my $autoinfo = 1;
  66. my $manchapters = '123456789ln';
  67. my $localbase = '/usr/local';
  68. my $numpitems = 6;
  69. my %lang_pref = qw(
  70. arabic ar
  71. chinese zh
  72. french fr
  73. german de
  74. hebrew iw
  75. hungarian hu
  76. japanese ja
  77. korean ko
  78. polish pl
  79. portuguese pt
  80. russian ru
  81. ukrainian uk
  82. vietnamese vi
  83. );
  84. my @lang_cat = keys %lang_pref;
  85. my @lang_short = values %lang_pref;
  86. my $re_lang_short = '(' . join('|', @lang_short) . ')-';
  87. my ($prog) = ($0 =~ /([^\/]+)$/);
  88. sub usage {
  89. print STDERR <<EOF;
  90. usage: $prog [-AabCcghmvtN] [-M ENV] [-B#] [port_directory]
  91. -a additional check for scripts/* and pkg-*
  92. -A turn on all additional checks (equivalent to -abcmNt)
  93. -b warn \$(VARIABLE)
  94. -c committer mode (implies -m)
  95. -C pedantic committer mode (equivalent to -abcmt)
  96. -g group errors together to avoid duplication (disabled if -v is specified)
  97. -h show summary of command line options
  98. -v verbose mode
  99. -t nit pick about use of spaces
  100. -m check \${PORTSDIR}/MOVED, UIDs, and GIDs files
  101. -N writing a new port
  102. -V print the version and exit
  103. -M ENV set make variables to ENV (ex. PORTSDIR=/usr/ports.work)
  104. -B# allow # contiguous blank lines (default: $contblank line)
  105. EOF
  106. exit 0;
  107. }
  108. sub version {
  109. print "$prog version $major.$minor.$micro\n";
  110. exit $major;
  111. }
  112. getopts('AabCcghmtvB:M:NV');
  113. &usage if $opt_h;
  114. &version if $opt_V;
  115. $extrafile = 1 if $opt_a || $opt_A || $opt_C;
  116. $parenwarn = 1 if $opt_b || $opt_A || $opt_C;
  117. $committer = 1 if $opt_c || $opt_A || $opt_C;
  118. $verbose = 1 if $opt_v;
  119. $grouperrs = 1 if $opt_g && !$opt_v;
  120. $checkmfiles = 1 if $opt_m || $opt_c || $opt_A || $opt_C;
  121. $newport = 1 if $opt_N || $opt_A;
  122. $usetabs = 1 if $opt_t || $opt_A || $opt_C;
  123. $contblank = $opt_B if $opt_B;
  124. $makeenv = $opt_M if $opt_M;
  125. $portdir = $ARGV[0] ? $ARGV[0] : '.';
  126. # OS dependent configs
  127. # os portsdir rcsid mplist ldcfg plist-rcsid mancompresss strict localbase newxdef automan autoinfo
  128. my @osdep = split(/\n/, <<EOF);
  129. FreeBSD /usr/ports FreeBSD 0 0 0 1 0 /usr/local 1 1 1
  130. NetBSD /usr/pkgsrc NetBSD 1 1 1 0 1 /usr/pkg 0 0 0
  131. EOF
  132. my $osname = `uname -s`;
  133. $osname =~ s/\n$//;
  134. foreach my $i (@osdep) {
  135. if ($i =~ /^$osname\t(.*)/) {
  136. print "OK: found OS config for $osname.\n" if ($verbose);
  137. ($portsdir, $rcsidstr, $multiplist, $ldconfigwithtrue,
  138. $rcsidinplist, $mancompress, $manstrict, $localbase,
  139. $newxdef, $automan, $autoinfo)
  140. = split(/\t+/, $1);
  141. last;
  142. }
  143. }
  144. # The PORTSDIR environment variable overrides our defaults.
  145. $portsdir = $ENV{PORTSDIR} if ( defined $ENV{'PORTSDIR'} );
  146. my $mfile_moved = "${portsdir}/MOVED";
  147. my $mfile_uids = "${portsdir}/UIDs";
  148. my $mfile_gids = "${portsdir}/GIDs";
  149. if ($verbose) {
  150. print "OK: config: portsdir: \"$portsdir\" ".
  151. "rcsidstr: \"$rcsidstr\" ".
  152. "multiplist: $multiplist ".
  153. "ldconfigwithtrue: $ldconfigwithtrue ".
  154. "rcsidinplist: $rcsidinplist ".
  155. "mancompress: $mancompress ".
  156. "manstrict: $manstrict ".
  157. "localbase: $localbase ".
  158. "\n";
  159. }
  160. #
  161. # just for safety.
  162. #
  163. if (! -d $portdir) {
  164. print STDERR "FATAL: invalid directory $portdir specified.\n";
  165. exit 1;
  166. }
  167. chdir "$portdir" || die "$portdir: $!";
  168. # get make vars
  169. my @varlist = qw(
  170. PORTNAME PORTVERSION PORTREVISION PORTEPOCH PKGNAME PKGNAMEPREFIX
  171. PKGNAMESUFFIX DISTVERSIONPREFIX DISTVERSION DISTVERSIONSUFFIX
  172. DISTNAME DISTFILES CATEGORIES MASTERDIR MAINTAINER MASTER_SITES
  173. WRKDIR WRKSRC NO_WRKSUBDIR SCRIPTDIR FILESDIR
  174. PKGDIR COMMENT DESCR PLIST PKGCATEGORY PKGINSTALL PKGDEINSTALL
  175. PKGREQ PKGMESSAGE DISTINFO_FILE .CURDIR USE_LDCONFIG USE_AUTOTOOLS
  176. USE_GNOME INDEXFILE PKGORIGIN CONFLICTS PKG_VERSION PKGINSTALLVER
  177. PLIST_FILES OPTIONS OPTIONS_DEFINE INSTALLS_OMF USE_GETTEXT USE_RC_SUBR
  178. DIST_SUBDIR ALLFILES IGNOREFILES CHECKSUM_ALGORITHMS INSTALLS_ICONS
  179. GNU_CONFIGURE CONFIGURE_ARGS MASTER_SITE_SUBDIR LICENSE LICENSE_COMB
  180. );
  181. my $cmd = join(' -V ', "make $makeenv MASTER_SITE_BACKUP=''", @varlist);
  182. my %makevar;
  183. my $i = 0;
  184. for (split(/\n/, `$cmd`)) {
  185. print "OK: makevar: $varlist[$i] = $_\n" if ($verbose);
  186. $makevar{$varlist[$i]} = $_;
  187. $i++;
  188. }
  189. #
  190. # variables for global checks.
  191. #
  192. my $sharedocused = 0;
  193. my %plistmanall = ();
  194. my %plistmangz = ();
  195. my %plistman = ();
  196. my %manlangs = ();
  197. my %predefined = ();
  198. # historical, no longer in FreeBSD's bsd.sites.mk
  199. foreach my $i (split(/\n/, <<EOF)) {
  200. GNU ftp://prep.ai.mit.edu/pub/gnu/%SUBDIR%/
  201. GNU ftp://wuarchive.wustl.edu/systems/gnu/%SUBDIR%/
  202. GNU ftp://ftp.ecrc.net/pub/gnu/%SUBDIR%/
  203. PERL_CPAN ftp://ftp.cdrom.com/pub/perl/CPAN/modules/by-module/%SUBDIR%/
  204. SUNSITE ftp://sunsite.unc.edu/pub/Linux/%SUBDIR%/
  205. SUNSITE ftp://ftp.funet.fi/pub/mirrors/sunsite.unc.edu/pub/Linux/%SUBDIR%/
  206. SUNSITE ftp://ftp.infomagic.com/pub/mirrors/linux/sunsite/%SUBDIR%/
  207. TEX_CTAN ftp://ftp.cdrom.com/pub/tex/ctan/%SUBDIR%/
  208. TEX_CTAN ftp://ftp.tex.ac.uk/public/ctan/tex-archive/%SUBDIR%/
  209. GNOME ftp://ftp.cybertrails.com/pub/gnome/%SUBDIR%/
  210. AFTERSTEP ftp://ftp.alpha1.net/pub/mirrors/ftp.afterstep.org/%SUBDIR%/
  211. AFTERSTEP ftp://casper.yz.yamagata-u.ac.jp/pub/X11/apps/afterstep/%SUBDIR%/
  212. WINDOWMAKER ftp://ftp.io.com/pub/%SUBDIR%/
  213. EOF
  214. my ($j, $k) = split(/\t+/, $i);
  215. $predefined{$k} = $j;
  216. }
  217. # Read bsd.sites.mk
  218. my $sites_mk = "$portsdir/Mk/bsd.sites.mk";
  219. open(MK, $sites_mk) || die "$sites_mk: $!";
  220. my @site_groups = grep($_ = /^MASTER_SITE_(\w+)/ && $1, <MK>);
  221. close(MK);
  222. $cmd = join(' -V MASTER_SITE_', "make $makeenv ", @site_groups);
  223. $i = 0;
  224. open2(\*IN, \*OUT, $cmd);
  225. close(OUT);
  226. while (<IN>) {
  227. my $g = $site_groups[$i];
  228. for my $s (split()) {
  229. $predefined{$s} = $g;
  230. }
  231. $i++;
  232. }
  233. close(IN);
  234. #
  235. # check for files.
  236. #
  237. my @checker = ($makevar{DESCR}, 'Makefile', $makevar{DISTINFO_FILE});
  238. my %checker = (
  239. $makevar{DESCR} => \&checkdescr,
  240. 'Makefile' => \&checkmakefile,
  241. $makevar{DISTINFO_FILE} => \&checkdistinfo
  242. );
  243. if ($extrafile) {
  244. my @files = (
  245. <$makevar{SCRIPTDIR}/*>,
  246. @makevar{qw(DESCR PLIST PKGINSTALL PKGDEINSTALL PKGREQ PKGMESSAGE)}
  247. );
  248. foreach my $i (@files) {
  249. next if (! -T $i);
  250. next if (defined $checker{$i});
  251. if ($i =~ /\bpkg-plist$/
  252. || ($multiplist && $i =~ /\bpkg-plist/)) {
  253. unshift(@checker, $i);
  254. $checker{$i} = \&checkplist;
  255. } else {
  256. push(@checker, $i);
  257. $checker{$i} = \&checkpathname;
  258. }
  259. }
  260. }
  261. if ($checkmfiles) {
  262. foreach my $i ($mfile_moved, $mfile_uids, $mfile_gids) {
  263. next if (! -T $i);
  264. next if (defined $checker{$i});
  265. push(@checker, $i);
  266. $checker{$i} = \&checkmfile;
  267. }
  268. }
  269. foreach my $i (<$makevar{FILESDIR}/patch-*>) {
  270. next if (! -T $i);
  271. next if (defined $checker{$i});
  272. push(@checker, $i);
  273. $checker{$i} = \&checkpatch;
  274. }
  275. foreach my $i (@checker) {
  276. print "OK: checking $i.\n" if ($verbose);
  277. if (! -f "$i") {
  278. &perror("FATAL", "", -1, "no $i in \"$portdir\".") unless $i eq $makevar{DISTINFO_FILE} && $makevar{DISTFILES} eq "";
  279. } else {
  280. my $proc = $checker{$i};
  281. &$proc($i) || &perror("", "", -1, "Cannot open the file $i\n");
  282. if ($proc ne \&checkpatch) {
  283. &checklastline($i)
  284. || &perror("", "", -1, "Cannot open the file $i\n");
  285. }
  286. }
  287. }
  288. # Check to make sure there is no pkg-comment file anymore.
  289. if (-f 'pkg-comment') {
  290. &perror("FATAL", "", -1, "Use of pkg-comment is obsolete. Use the COMMENT macro within the port's Makefile instead.");
  291. }
  292. if ($committer) {
  293. sub find_proc {
  294. return if /^\.\.?$/;
  295. (my $fullname = $File::Find::name) =~ s#^\./##;
  296. print "OK: checking the file name of $fullname.\n" if ($verbose);
  297. if ($fullname eq 'work') {
  298. &perror("FATAL", $fullname, -1, "be sure to cleanup the working directory ".
  299. "before committing the port.");
  300. $File::Find::prune = 1;
  301. } elsif (-l) {
  302. &perror("WARN", $fullname, -1, "this is a symlink. ".
  303. "Please remove it.");
  304. } elsif (-z) {
  305. &perror("FATAL", $fullname, -1, "empty file and should be removed. ".
  306. "If it still needs to be there, put a dummy comment ".
  307. "to state that the file is intentionally left empty.");
  308. } elsif (-d && scalar(my @x = <$_/{*,.?*}>) <= 1) {
  309. &perror("FATAL", $fullname, -1, "empty directory should be removed.");
  310. } elsif (/^\./) {
  311. &perror("WARN", $fullname, -1, "dotfiles are not preferred. ".
  312. "If this file is a dotfile to be installed as an example, ".
  313. "consider importing it as \"dot$_\".");
  314. } elsif (/[^-.a-zA-Z0-9_\+]/) {
  315. &perror("WARN", $fullname, -1, "only use characters ".
  316. "[-_.a-zA-Z0-9+] for patch or script names.");
  317. } elsif (/\.(orig|rej|bak)$/ || /~$/ || /^\#/) {
  318. &perror("FATAL", $fullname, -1, "for safety, be sure to cleanup ".
  319. "backup files before committing the port.");
  320. } elsif (/(^|\.)core$/) {
  321. &perror("FATAL", $fullname, -1, "for safety, be sure to cleanup ".
  322. "core files before committing the port.");
  323. } elsif (/README.html/) {
  324. &perror("FATAL", $fullname, -1, "for safety, be sure to cleanup ".
  325. "README.html files before committing the port.");
  326. } elsif ($_ eq '.svn' && -d) {
  327. &perror("FATAL", $fullname, -1, "for safety, be sure to cleanup ".
  328. "Subversion files before committing the port.");
  329. } elsif ($_ eq 'CVS' && -d) {
  330. if ($newport) {
  331. &perror("FATAL", $fullname, -1, "for safety, be sure to cleanup ".
  332. "CVS directories before importing the new port.");
  333. }
  334. $File::Find::prune = 1;
  335. }
  336. }
  337. find(\&find_proc, '.');
  338. # Check for ports that may break INDEX
  339. my $indexerr = `env LOCALBASE=/nonexistentlocal make $makeenv describe 2>&1 >/dev/null`;
  340. chomp $indexerr;
  341. $indexerr =~ tr/\n/ /s;
  342. &perror("FATAL", "", -1, "breaks INDEX ($indexerr).")
  343. if ($indexerr);
  344. }
  345. if ($err || $warn) {
  346. my($errtext, $warntext) = ("error", "warning");
  347. $errtext .= "s" unless ($err == 1);
  348. $warntext .= "s" unless ($warn == 1);
  349. if ($grouperrs) {
  350. foreach my $msg (@errlst) {
  351. my $lines;
  352. if ($errcache{$msg} && scalar(@{$errcache{$msg}})) {
  353. $lines = "[" . (join(",", @{$errcache{$msg}})) . "]: ";
  354. } else {
  355. $lines = "";
  356. }
  357. $msg =~ s/%%LINES%%/$lines/;
  358. print $msg, "\n";
  359. }
  360. }
  361. printf("%d fatal %s and %d %s found.\n", $err, $errtext, $warn, $warntext);
  362. } else {
  363. print "looks fine.\n";
  364. }
  365. exit $err;
  366. #
  367. # distinfo
  368. #
  369. sub checkdistinfo {
  370. my($file) = @_;
  371. my($dist_subdir) = $makevar{DIST_SUBDIR};
  372. my(@allfiles) = split (/\s+/, $makevar{ALLFILES});
  373. my %ignorefiles = ();
  374. my %algorithms = ();
  375. my %records = ();
  376. foreach my $i (split (/\s+/, $makevar{IGNOREFILES})) {
  377. $ignorefiles{$i} = 1;
  378. }
  379. foreach my $i (split (/\s+/, uc ($makevar{CHECKSUM_ALGORITHMS}))) {
  380. $algorithms{$i} = 1;
  381. }
  382. if (scalar (%ignorefiles)) {
  383. &perror("WARN", "", -1, "Found IGNOREFILES. It is not recomended.");
  384. }
  385. open(IN, "< $file") || return 0;
  386. while (<IN>) {
  387. if (/^\s*$/) {
  388. &perror("FATAL", $file, $., "found blank line.");
  389. }
  390. m/(\S+)\s+\((\S+)\)\s+=\s+(\S+)/;
  391. if ($1 ne "" && $2 ne "" && $3 ne "") {
  392. my ($tag, $path, $value) = ($1, $2, $3);
  393. $records{$path}{$tag} = $value;
  394. if (!$algorithms{$tag} && $tag ne "SIZE") {
  395. &perror("FATAL", $file, $., "unsupported checksum algorithm ".
  396. "found: $tag.");
  397. }
  398. } else {
  399. &perror("FATAL", $file, $., "line format error.");
  400. }
  401. }
  402. close(IN);
  403. # For all files check SIZE and checksums
  404. foreach my $f (@allfiles) {
  405. # Remove hindering chars from DISTNAME
  406. $f =~ s/['\\]//g;
  407. my $path = $f;
  408. $path = "$dist_subdir/$f" if $dist_subdir;
  409. if (!defined($records{$path}{SIZE}) && !$ignorefiles{$f}) {
  410. &perror("FATAL", $file, -1, "has no SIZE record for $path.");
  411. }
  412. my $n = 0;
  413. foreach my $alg (keys %algorithms) {
  414. $n++ if exists($records{$path}{$alg});
  415. }
  416. if ($n == 0) {
  417. &perror("FATAL", $file, -1, "no checksum record for $path.");
  418. }
  419. if ($n < scalar(keys %algorithms)) {
  420. &perror("WARN", $file, -1, "no checksum records for all ".
  421. "supported algorithms (".join(" ",keys %algorithms).") for ".
  422. "$path.");
  423. }
  424. }
  425. return 1;
  426. }
  427. #
  428. # pkg-descr
  429. #
  430. sub checkdescr {
  431. my($file) = @_;
  432. my(%maxchars) = ($makevar{DESCR}, 80);
  433. my(%maxlines) = ($makevar{DESCR}, 24);
  434. my(%errmsg) = ($makevar{DESCR}, "exceeds $maxlines{$makevar{DESCR}} ".
  435. "lines, make it shorter if possible.");
  436. my($longlines, $linecnt, $tmp) = (0, 0, "");
  437. open(IN, "< $file") || return 0;
  438. while (<IN>) {
  439. $tmp .= $_;
  440. chomp || &perror("WARN", $file, -1, "lines should terminate with a ".
  441. "newline (i.e. '\\n').");
  442. if (/ $/) {
  443. &perror("WARN", $file, -1, "lines should not contain carriage ".
  444. "returns. Strip all carriage returns (e.g. run dos2unix) ".
  445. "in $file.");
  446. }
  447. if (/^WWW:(\s+)(\S*)/) {
  448. my $wwwurl = $2;
  449. if ($1 ne ' ') {
  450. &perror("WARN", $file, -1, "use WWW: with a single space, ".
  451. "then $wwwurl");
  452. }
  453. if ($wwwurl !~ m|^https?://|) {
  454. &perror("WARN", $file, -1, "WWW URL, $wwwurl should begin ".
  455. "with \"http://\" or \"https://\".");
  456. }
  457. if ($wwwurl =~ m|^http://search.cpan.org/~|) {
  458. &perror("WARN", $file, -1, "consider changing WWW URL to ".
  459. "http://search.cpan.org/dist/$makevar{PORTNAME}");
  460. }
  461. }
  462. $linecnt++;
  463. $longlines++ if ($maxchars{$file} < length);
  464. }
  465. if ($linecnt > $maxlines{$file}) {
  466. &perror("WARN", $file, -1, "$errmsg{$file}".
  467. "(currently $linecnt lines)");
  468. } else {
  469. print "OK: $file: has $linecnt lines.\n" if ($verbose);
  470. }
  471. if ($longlines > 0) {
  472. &perror("WARN", $file, -1, "includes lines that exceed $maxchars{$file} ".
  473. "characters.");
  474. }
  475. if ($tmp =~ /[\033\200-\377]/) {
  476. &perror("WARN", $file, -1, "includes iso-8859-1, or ".
  477. "other local characters. files should be in ".
  478. "plain 7-bit ASCII");
  479. }
  480. if ($file =~ /\bpkg-descr/ && $tmp =~ m,http://,) {
  481. my $has_url = 0;
  482. my $has_www = 0;
  483. my $cpan_url = 0;
  484. my $has_endslash = 0;
  485. foreach my $line (grep($_ =~ "http://", split(/\n+/, $tmp))) {
  486. $has_url = 1;
  487. if ($line =~ m,WWW:[ \t]+http://,) {
  488. $has_www = 1;
  489. if ($line =~ m,search.cpan.org,) {
  490. $cpan_url = 1;
  491. if ($line =~ m,/$,) {
  492. $has_endslash = 1;
  493. }
  494. }
  495. }
  496. }
  497. if (!$has_url) {
  498. &perror("WARN", $file, -1, "add \"WWW: UR:\" for this port if possible");
  499. }
  500. if ($cpan_url && !$has_endslash) {
  501. &perror("WARN", $file, -1, "end WWW CPAN URL with a \"/\"");
  502. }
  503. if ($has_url && ! $has_www) {
  504. &perror("FATAL", $file, -1, "contains a URL but no \"WWW:\"");
  505. }
  506. }
  507. close(IN);
  508. }
  509. #
  510. # pkg-plist
  511. #
  512. sub checkplist {
  513. my($file) = @_;
  514. my($curdir) = ($localbase);
  515. my($inforemoveseen, $infoinstallseen, $infoseen) = (0, 0, 0);
  516. my($infobeforeremove, $infoafterinstall) = (0, 0);
  517. my($infooverwrite) = (0);
  518. my($rcsidseen) = (0);
  519. my(@exec_info) = ();
  520. my(@unexec_info) = ();
  521. my(@infofile) = ();
  522. my $seen_dirrm_docsdir = 0;
  523. my $seen_special = 0;
  524. my $item_count = 0;
  525. # Variables that are allowed to be out-of-sync in the XXXDIR check.
  526. # E.g., %%PORTDOCS%%%%RUBY_MODDOCDIR%% will be OK because there is
  527. # no %%PORTRUBY_MODDOC%% substitution.
  528. my %check_xxxdir_ok = (
  529. "DOCS" => "DOCS",
  530. "EXAMPLES" => "EXAMPLES",
  531. "DATA" => "DATA",
  532. "RUBY_DOC" => "DOCS",
  533. "RUBY_EXAMPLES" => "EXAMPLES",
  534. "RUBY_MODDOC" => "DOCS",
  535. "RUBY_MODEXAMPLES" => "EXAMPLES",
  536. );
  537. open(IN, "< $file") || return 0;
  538. while (<IN>) {
  539. $item_count++;
  540. if ($_ =~ /[ \t]+\n?$/) {
  541. &perror("WARN", $file, $., "whitespace before end ".
  542. "of line.");
  543. }
  544. # make it easier to handle.
  545. $_ =~ s/\s+$//;
  546. $_ =~ s/\n$//;
  547. if ($_ =~ /\.DS_Store/) {
  548. &perror("WARN", $file, $., ".DS_Store meta data files must not ".
  549. "be installed.");
  550. }
  551. if ($osname eq 'NetBSD' && $_ =~ /<\$ARCH>/) {
  552. &perror("WARN", $file, $., "use of <\$ARCH> deprecated, ".
  553. "use \${MACHINE_ARCH} instead.");
  554. }
  555. if (m'lib/perl5/site_perl/%%PERL_VER%%') {
  556. &perror("WARN", $file, $., "use \%\%SITE_PERL\%\% ".
  557. "instead of lib/perl5/site_perl/\%\%PERL_VER\%\%.");
  558. }
  559. if ($osname ne 'NetBSD' && m'([\w\d]+-portbld-freebsd\d+\.\d+)') {
  560. &perror("WARN", $file, $., "possible direct use of the ".
  561. "CONFIGURE_TARGET value ($1). Consider using the plist ".
  562. "substitution %%CONFIGURE_TARGET%% instead.");
  563. }
  564. $seen_special++ if /[\%\@]/;
  565. $seen_dirrm_docsdir++ if /^(\%\%PORTDOCS\%\%)?\@dirrm\s+\%\%DOCSDIR\%\%/ || /^(\%\%PORTDOCS\%\%)?\@unexec\s+(\/bin\/)?rmdir\s+\%D\/\%\%DOCSDIR\%\%\s+2\>\s*\/dev\/null\s+\|\|\s+(\/usr\/bin\/)?true/;
  566. if ($_ =~ /^\@/) {
  567. if ($_ =~ /^\@(cwd|cd)[ \t]+(\S+)/) {
  568. $curdir = $2;
  569. } elsif ($_ =~ /^\@unexec[ \t]+rm[ \t]/) {
  570. if ($_ !~ /%[DB]/) {
  571. &perror("WARN", $file, $., "use \"%D\" or \"%B\" to ".
  572. "specify prefix.");
  573. }
  574. if ($_ !~ /true$/ && $_ !~ /rm -f/) {
  575. &perror("WARN", $file, $., "add \"2>&1 ".
  576. ">/dev/null || true\" ".
  577. "to \"\@unexec rm\".");
  578. }
  579. } elsif ($_ =~ /^\@unexec[ \t]+rmdir/) {
  580. if ($_ !~ /%[DB]/) {
  581. &perror("WARN", $file, $., "use \"%D\" or \"%B\" to ".
  582. "specify prefix.");
  583. }
  584. &perror("WARN", $file, $., "use \"\@dirrmtry\" ".
  585. "instead of \"\@unexec rmdir\".");
  586. } elsif (!$autoinfo && $_ =~ /^\@exec[ \t]+install-info\s+(.+)\s+(.+)$/) {
  587. $infoinstallseen = $.;
  588. push(@exec_info, $1);
  589. } elsif (!$autoinfo && $_ =~ /^\@unexec[ \t]+install-info[ \t]+--delete\s+(.+)\s+(.+)$/) {
  590. $inforemoveseen = $.;
  591. push(@unexec_info, $1);
  592. } elsif ($autoinfo && $_ =~ /^\@unexec[ \t]+install-info[ \t]+--delete\s+(.+)\s+(.+)$/) {
  593. &perror("WARN", $file, $., "\@unexec install-info is deprecated in favor of adding info files into the Makefile using the INFO macro.");
  594. } elsif ($_ =~ /^\@(exec|unexec)/) {
  595. if (/ldconfig/) {
  596. if ($ldconfigwithtrue
  597. && !/\/usr\/bin\/true/) {
  598. &perror("FATAL", $file, $., "ldconfig ".
  599. "must be used with ".
  600. "\"||/usr/bin/true\".");
  601. }
  602. &perror("WARN", $file, $., "possible ".
  603. "direct use of ldconfig ".
  604. "in PLIST found. use ".
  605. "USE_LDCONFIG instead.");
  606. }
  607. if (/scrollkeeper/) {
  608. &perror("WARN", $file, $., "possible ".
  609. "direct use of scrollkeeper commands ".
  610. "in PLIST found. Use ".
  611. "INSTALLS_OMF instead ".
  612. "(see http://www.FreeBSD.org/gnome/docs/porting.html ".
  613. "for more details).");
  614. }
  615. } elsif ($_ =~ /^\@(comment)/) {
  616. $rcsidseen++ if (/\$$rcsidstr[:\$]/);
  617. } elsif ($_ =~ /^\@(owner|group|mode)\s/) {
  618. &perror("WARN", $file, $., "\@$1 should not be needed");
  619. } elsif ($_ =~ m!^\@(dirrm|dirrmtry)\s+/!) {
  620. &perror("WARN", $file, $., "Using \@$1 with absolute path ".
  621. "will not work as you expected in most cases. Use ".
  622. "pkg-deinstall or \@unexec rmdir ... if you want to ".
  623. "remove a directory such as /var/\${PORTNAME}");
  624. } elsif ($_ =~ /^\@(dirrm|option|stopdaemon|rmtry)/) {
  625. ; # no check made
  626. } elsif ($_ eq "\@cwd") {
  627. ; # @cwd by itself means change directory back to the original
  628. # PREFIX.
  629. } else {
  630. &perror("WARN", $file, $.,
  631. "unknown pkg-plist directive \"$_\"");
  632. }
  633. next;
  634. }
  635. if ($_ =~ /^\//) {
  636. &perror("FATAL", $file, $., "use of full pathname ".
  637. "disallowed.");
  638. }
  639. if ($_ =~ /charset\.alias$/ || $_ =~ /locale\.alias$/) {
  640. &perror("WARN", $file, $., "installing charset.alias or locale.alias, ".
  641. "please add USE_GETTEXT=yes and use libintl from devel/gettext ".
  642. "instead of from outdated bundled one if possible. ".
  643. "See http://www.freebsd.org/cgi/query-pr.cgi?pr=ports/71531 ".
  644. "for more details.");
  645. }
  646. if ($_ =~ /\%gconf.*\.xml/ || $_ =~ /gconf.*\.schemas?/) {
  647. &perror("FATAL", $file, $., "explicitly listing \%gconf key files ".
  648. "or GConf schema files in the plist is not supported. ".
  649. "Use GCONF_SCHEMAS in the Makefile instead. ".
  650. "See http://www.FreeBSD.org/gnome/docs/porting.html ".
  651. "for more details.");
  652. }
  653. if ($_ =~ m|lib/pkgconfig/[^\/]+.pc$|) {
  654. &perror("FATAL", $file, $., "installing pkg-config files into ".
  655. "lib/pkgconfig. All pkg-config files must be installed ".
  656. "into libdata/pkgconfig for them to be found by pkg-config.");
  657. }
  658. if ($_ =~ m|lib[^\/]+\.so(\.\d+)?$| &&
  659. $makevar{USE_LDCONFIG} eq '') {
  660. &perror("WARN", $file, $., "installing shared libraries, ".
  661. "please define USE_LDCONFIG as appropriate");
  662. }
  663. if ($_ =~ m|^share/icons/.*/| &&
  664. $makevar{INSTALLS_ICONS} eq '') {
  665. &perror("WARN", $file, $., "installing icons, ".
  666. "please define INSTALLS_ICONS as appropriate");
  667. }
  668. if ($_ =~ m|\.omf$| && $makevar{INSTALLS_OMF} eq '') {
  669. &perror("WARN", $file, $., "installing OMF files, ".
  670. "please define INSTALLS_OMF (see the FreeBSD GNOME ".
  671. "porting guide at ".
  672. "http://www.FreeBSD.org/gnome/docs/porting.html ".
  673. "for more details)");
  674. }
  675. if ($_ =~ m|\.mo$| && $makevar{USE_GETTEXT} eq '') {
  676. &perror("WARN", $file, $., "installing gettext translation files, ".
  677. "please define USE_GETTEXT as appropriate");
  678. }
  679. if ($_ =~ m|\.core$| && $_ !~ /^\@/) {
  680. &perror("WARN", $file, $., "this port installs a file which ends ".
  681. "in \".core\". This file may be deleted if ".
  682. "daily_clean_disks_enable=\"YES\" in /etc/periodic.conf. ".
  683. "If possible, install this file with a different name.");
  684. }
  685. if ($_ =~ m|/a\.out$| && $_ !~ /^\@/) {
  686. &perror("WARN", $file, $., "this port installs a file named ".
  687. "\"a.out\". This file may be deleted if ".
  688. "daily_clean_disks_enable=\"YES\" in /etc/periodic.conf. ".
  689. "If possible, install this file with a different name.");
  690. }
  691. if ($autoinfo && $_ =~ /\.info$/) {
  692. &perror("WARN", $file, $., "enumerating info files in the plist is deprecated in favor of adding info files into the Makefile using the INFO macro.");
  693. }
  694. if ($autoinfo && $_ =~ /\.info-\d+$/) {
  695. &perror("FATAL", $file, $., "numbered info files are obsolete and not portable; add info files using the INFO macro in the Makefile.");
  696. }
  697. if (!$autoinfo) {
  698. if ($_ =~ /^info\/.*info(-[0-9]+)?$/) {
  699. $infoseen = $.;
  700. $infoafterinstall++ if ($infoinstallseen);
  701. $infobeforeremove++ if (!$inforemoveseen);
  702. push(@infofile, $_);
  703. }
  704. if ($_ =~ /^info\/dir$/) {
  705. &perror("FATAL", $file, $., "\"info/dir\" should not be listed.".
  706. "Use install-info to add/remove ".
  707. "an entry.");
  708. $infooverwrite++;
  709. }
  710. }
  711. if ($_ =~ /^(\%\%PORTDOCS\%\%)?share\/doc\//) {
  712. &perror("WARN", $file, $., "If and only if your port is ".
  713. "DOCSDIR-safe (that is, a user can override DOCSDIR ".
  714. "when building this port and the port will still work ".
  715. "correctly) consider using DOCSDIR macro; if you are ".
  716. "unsure if this this port is DOCSDIR-safe, then ignore ".
  717. "this warning");
  718. $sharedocused++;
  719. } elsif ($_ =~ /^(\%\%PORTDOCS\%\%)?\%\%DOCSDIR\%\%/) {
  720. $sharedocused++;
  721. }
  722. if ($_ =~ /^share\/examples\//) {
  723. &perror("WARN", $file, $., "If and only if your port is ".
  724. "EXAMPLESDIR-safe (that is, a user can override EXAMPLESDIR ".
  725. "when building this port and the port will still work ".
  726. "correctly) consider using EXAMPLESDIR macro; if you are ".
  727. "unsure if this port is EXAMPLESDIR-safe, then ignore this ".
  728. "warning");
  729. }
  730. {
  731. my $tmpportname = quotemeta($makevar{PORTNAME});
  732. if ($_ =~ /^share\/$tmpportname\//) {
  733. &perror("WARN", $file, $., "If and only if your port is ".
  734. "DATADIR-safe (that is, a user can override DATADIR when ".
  735. "building this port and the port will still work ".
  736. "correctly) consider using DATADIR macro; if you are ".
  737. "unsure if this port is DATADIR-safe, then ignore this ".
  738. "warning");
  739. }
  740. }
  741. if ($_ =~ m{^%%PORT(\w+)%%(.*?)%%(\w+)DIR%%(.*)$} and $1 ne $3) {
  742. &perror("WARN", $file, $., "Do not mix %%PORT$1%% with %%$3DIR%%. ".
  743. "Use '%%PORT$check_xxxdir_ok{$3}%%$2%%$3DIR%%$4' instead and update Makefile ".
  744. "accordingly.") unless (defined($check_xxxdir_ok{$3}) and
  745. $check_xxxdir_ok{$3} eq $1);
  746. }
  747. if ($_ =~ m#man/([^/]+/)?man([$manchapters])/([^\.]+\.[$manchapters])(\.gz)?$#) {
  748. if (!$4) {
  749. $plistman{$2} .= ' ' . $3;
  750. if ($mancompress) {
  751. &perror("FATAL", $file, $.,
  752. "unpacked man file $3 ".
  753. "listed. must be gzipped.");
  754. }
  755. } else {
  756. $plistmangz{$2} .= ' ' . $3;
  757. if (!$mancompress) {
  758. &perror("FATAL", $file, $.,
  759. "gzipped man file $3$4 ".
  760. "listed. unpacked one should ".
  761. "be installed.");
  762. }
  763. }
  764. $plistmanall{$2} .= ' ' . $3;
  765. if ($1) {
  766. $manlangs{substr($1, 0, length($1) - 1)}++;
  767. }
  768. }
  769. if ($curdir !~ m#^$localbase#
  770. && $curdir !~ m#^/usr/X11R6#) {
  771. &perror("WARN", $file, $., "installing to ".
  772. "directory $curdir discouraged. ".
  773. "could you please avoid it?");
  774. }
  775. if ("$curdir/$_" =~ m#^$localbase/share/doc#) {
  776. print "OK: $file [$.]: seen installation to share/doc. ".
  777. "($curdir/$_)\n" if ($verbose);
  778. $sharedocused++;
  779. }
  780. }
  781. if (!$seen_special && $item_count < $numpitems) {
  782. &perror("WARN", $file, -1, "There are only $item_count items in the plist. Consider using PLIST_FILES instead of pkg-plist when installing less than $numpitems items.");
  783. }
  784. if ($sharedocused && !$seen_dirrm_docsdir) {
  785. &perror("WARN", $file, -1, "Both ``\%\%PORTDOCS\%\%\@dirrm \%\%DOCSDIR\%\%'' and ``\%\%PORTDOCS\%\%\@unexec \%D/\%\%DOCSDIR\%\% 2>/dev/null || true'' are missing. At least one should be used.");
  786. }
  787. if (!$autoinfo) {
  788. # check that every infofile has an exec install-info and unexec install-info
  789. my $exec_install = join(" ", @exec_info);
  790. $exec_install .= ' ';
  791. my $unexec_install = join(" ", @unexec_info);
  792. $unexec_install .= ' ';
  793. foreach my $if (@infofile) {
  794. next if ($if =~ m/info-/);
  795. if ($exec_install !~ m/\%D\/\Q$if\E/) {
  796. &perror("FATAL", $file, -1, "you need an '\@exec install-info \%D/$if \%D/info/dir' line");
  797. }
  798. if ($unexec_install !~ m/\%D\/$if/) {
  799. &perror("FATAL", $file, -1, "you need an '\@unexec install-info --delete \%D/$if \%D/info/dir' line");
  800. }
  801. }
  802. }
  803. if ($rcsidinplist && !$rcsidseen) {
  804. &perror("FATAL", $file, -1, "RCS tag \"\$$rcsidstr\$\" must be present ".
  805. "as \@comment.")
  806. }
  807. if (((!$autoinfo && !$infoseen) || $autoinfo)) {
  808. close(IN);
  809. return 1;
  810. }
  811. if (!$autoinfo && $infoseen) {
  812. if (!$infoinstallseen) {
  813. if ($infooverwrite) {
  814. &perror("FATAL", $file, -1, "install-info must be used to ".
  815. "add/delete entries into \"info/dir\".");
  816. }
  817. &perror("FATAL", $file, -1, "\"\@exec install-info \%D/... \%D/info/dir\" must be placed ".
  818. "after all the info files.");
  819. } elsif ($infoafterinstall) {
  820. &perror("FATAL", $file, $infoinstallseen, "move ".
  821. "\"\@exec install-info\" line to make ".
  822. "sure that it is placed after all the info files.");
  823. }
  824. if (!$inforemoveseen) {
  825. &perror("FATAL", $file, -1, "\"\@unexec install-info --delete \%D/... \%D/info/dir\" must ".
  826. "be placed before any of the info files listed.");
  827. } elsif ($infobeforeremove) {
  828. &perror("FATAL", $file, $inforemoveseen, "move ".
  829. "\"\@exec install-info --delete\" ".
  830. "line to make sure ".
  831. "that it is placed before any of the info files. ");
  832. }
  833. }
  834. close(IN);
  835. }
  836. #
  837. # ${PORTSDIR}/MOVED, UIDs, GIDs files
  838. #
  839. sub checkmfile {
  840. my ($file) = @_;
  841. my $line = 0;
  842. my $format;
  843. my @entries;
  844. my @sorted;
  845. my $dosort;
  846. if ($file =~ m/MOVED$/) {
  847. $format = '^[^|]*\|[^|]*\|[^|]*\|[^|]*$';
  848. $dosort = 0;
  849. } elsif ($file =~ m/UIDs$/) {
  850. $format = '^[^:]+:\*:[0-9]+:[0-9]+:[^:]*:0:0:[^:]+:[^:]+:[^:]+$';
  851. $dosort = 1;
  852. } elsif ($file =~ m/GIDs$/) {
  853. $format = '^[^:]+:\*:[0-9]+:[^:]*$';
  854. $dosort = 1;
  855. } else {
  856. &perror("FATAL", $file, -1, "Internal error. ".
  857. "Invalid name for mfiles.");
  858. }
  859. open(IN, "<$file") || return 0;
  860. while (<IN>) {
  861. chomp;
  862. $line++;
  863. next if (m,^\s*#,);
  864. if (!m,${format},) {
  865. &perror("FATAL", $file, -1,
  866. "malformed line at ".
  867. "${line}.\n => $_");
  868. } else {
  869. push @entries, "$line:$_";
  870. next;
  871. }
  872. }
  873. if ($dosort) {
  874. my $errline;
  875. @sorted = sort {(split /:/, $a)[3] <=> (split /:/, $b)[3] } @entries;
  876. for (my $n = 0; $n < @entries; $n++) {
  877. if (!defined($sorted[$n]) or
  878. $entries[$n] ne $sorted[$n]) {
  879. ($line, $errline) = ($entries[$n] =~ m/([0-9]+):(.*)/);
  880. &perror("WARN", $file, -1,
  881. "malformed sorting order at " .
  882. "${line}.\n => $errline");
  883. }
  884. }
  885. }
  886. close(IN);
  887. }
  888. #
  889. # misc files
  890. #
  891. sub checkpathname {
  892. my($file) = @_;
  893. my($whole);
  894. open(IN, "< $file") || return 0;
  895. $whole = '';
  896. while (<IN>) {
  897. $whole .= $_;
  898. }
  899. &abspathname($whole, $file);
  900. close(IN);
  901. }
  902. sub checklastline {
  903. my($file) = @_;
  904. my($whole);
  905. open(IN, "< $file") || return 0;
  906. $whole = '';
  907. while (<IN>) {
  908. $whole .= $_;
  909. }
  910. if ($whole !~ /\n$/) {
  911. &perror("FATAL", $file, -1, "the last line has to be ".
  912. "terminated by \\n.");
  913. }
  914. if ($whole =~ /\n([ \t]*\n)+$/) {
  915. &perror("WARN", $file, -1, "seems to have unnecessary blank lines ".
  916. "at the last part.");
  917. }
  918. close(IN);
  919. }
  920. sub checkpatch {
  921. my($file) = @_;
  922. my($whole);
  923. if (-z "$file") {
  924. &perror("FATAL", $file, -1, "has no content. should be removed ".
  925. "from repository.");
  926. return;
  927. }
  928. open(IN, "< $file") || return 0;
  929. $whole = '';
  930. while (<IN>) {
  931. $whole .= $_;
  932. }
  933. if ($committer && $whole =~ /\$([A-Z][A-Za-z0-9]+)(:[^\n]+)?\$/) {
  934. my $lineno = &linenumber($`);
  935. &perror("WARN", $file, $lineno, "includes possible RCS tag \"\$$1\$\". ".
  936. "use binary mode (-ko) on commit/import.") unless
  937. $1 eq $rcsidstr;
  938. }
  939. if ($committer && $whole =~ /\wjavavm\w/) {
  940. my $lineno = &linenumber($`);
  941. &perror("WARN", $file, $lineno, "since javavmwrapper 2.0, the ".
  942. "``javavm'' command to invoke a JVM is deprecated. Use ".
  943. "``java'' instead");
  944. }
  945. if ($whole =~ / /) {
  946. my $lineno = &linenumber($`);
  947. &perror("WARN", $file, $lineno, "patch contains ^M characters. ".
  948. "Consider defining USE_DOS2UNIX to remove DOS line endings ".
  949. "from source files.");
  950. }
  951. close(IN);
  952. }
  953. sub check_depends_syntax {
  954. my $tmp = shift;
  955. my $file = shift;
  956. my (%seen_depends, $j);
  957. $ENV{'PORTSDIR'} //= $portsdir;
  958. foreach my $i (grep(/^(PATCH_|EXTRACT_|LIB_|BUILD_|RUN_|TEST_|FETCH_)*DEPENDS[?+]?=/, split(/\n/, $tmp))) {
  959. $i =~ s/^((PATCH_|EXTRACT_|LIB_|BUILD_|RUN_|TEST_|FETCH_)*DEPENDS)[?+]?=[ \t]*//;
  960. $j = $1;
  961. $seen_depends{$j}++;
  962. if ($j ne 'DEPENDS' &&
  963. $i =~ /^\${([A-Z_]+DEPENDS)}\s*$/ &&
  964. $seen_depends{$1} &&
  965. $j ne $1)
  966. {
  967. print "OK: $j refers to $1, skipping checks.\n"
  968. if ($verbose);
  969. next;
  970. }
  971. print "OK: checking ports listed in $j.\n"
  972. if ($verbose);
  973. foreach my $k (split(/\s+/, $i)) {
  974. if ($k =~ /^#/) {
  975. last;
  976. }
  977. if ($k =~ /^\$\{(\w+)\}$/) {
  978. $k = `make -V $1`;
  979. chomp $k;
  980. }
  981. my @l = split(':', $k);
  982. print "OK: checking dependency value for $j.\n"
  983. if ($verbose);
  984. if ($k =~ /\${((PATCH_|EXTRACT_|LIB_|BUILD_|RUN_|TEST_|FETCH_)*DEPENDS)}/) {
  985. &perror("WARN", $file, -1, "do not set $j to $k. ".
  986. "Instead, explicity list out required $j dependencies.");
  987. }
  988. if (($j ne 'DEPENDS'
  989. && scalar(@l) != 2 && scalar(@l) != 3)) {
  990. &perror("WARN", $file, -1, "wrong dependency value ".
  991. "for $j. $j requires ".
  992. "2 or 3 ".
  993. "colon-separated tuples.");
  994. next;
  995. }
  996. my %m = ();
  997. $m{'dep'} = $l[0];
  998. $m{'dir'} = $l[1];
  999. $m{'tgt'} = $l[2];
  1000. print "OK: dep=\"$m{'dep'}\", ".
  1001. "dir=\"$m{'dir'}\", tgt=\"$m{'tgt'}\"\n"
  1002. if ($verbose);
  1003. # check USE_PERL5
  1004. if ($m{'dep'} =~ /^perl5(\.\d+)?$/) {
  1005. &perror("WARN", $file, -1, "dependency to perl5 ".
  1006. "listed in $j. consider using ".
  1007. "USE_PERL5.");
  1008. }
  1009. # check USE_ICONV
  1010. if ($m{'dep'} =~ /^(iconv\.\d+)$/) {
  1011. &perror("WARN", $file, -1, "dependency to $1 ".
  1012. "listed in $j. consider using ".
  1013. "USE_ICONV.");
  1014. }
  1015. # check USE_GETTEXT
  1016. if ($m{'dep'} =~ /^(intl\.\d+)$/) {
  1017. &perror("WARN", $file, -1, "dependency to $1 ".
  1018. "listed in $j. consider using ".
  1019. "USE_GETTEXT.");
  1020. }
  1021. # check USE_GMAKE
  1022. if ($m{'dep'} =~ /^(gmake|\${GMAKE})$/) {
  1023. &perror("WARN", $file, -1, "dependency to $1 ".
  1024. "listed in $j. consider using ".
  1025. "USE_GMAKE.");
  1026. }
  1027. # check USE_QT
  1028. if ($m{'dep'} =~ /^(qt\d)+$/) {
  1029. &perror("WARN", $file, -1, "dependency to $1 ".
  1030. "listed in $j. consider using ".
  1031. "USE_QT.");
  1032. }
  1033. # check LIBLTDL
  1034. if ($m{'dep'} =~ /^(ltdl\.\d)+$/) {
  1035. &perror("WARN", $file, -1, "dependency to $1 ".
  1036. "listed in $j. consider using ".
  1037. "USE_LIBLTDL.");
  1038. }
  1039. # check CDRTOOLS
  1040. if ($m{'dir'} =~ /(cdrtools|cdrtools-cjk)$/) {
  1041. &perror("WARN", $file, -1, "dependency to $1 ".
  1042. "listed in $j. consider using ".
  1043. "USE_CDRTOOLS.");
  1044. }
  1045. # check GHOSTSCRIPT
  1046. if ($m{'dep'} eq "gs") {
  1047. &perror("WARN", $file, -1, "dependency to gs ".
  1048. "listed in $j. consider using ".
  1049. "USE_GHOSTSCRIPT(_BUILD|_RUN).");
  1050. }
  1051. # check JAVALIBDIR
  1052. if ($m{'dep'} =~ m|share/java/classes|) {
  1053. &perror("FATAL", $file, -1, "you should use \${JAVALIBDIR} ".
  1054. "in BUILD_DEPENDS/RUN_DEPENDS to define ".
  1055. "dependencies on JAR files installed in ".
  1056. "\${JAVAJARDIR}");
  1057. }
  1058. # check backslash in LIB_DEPENDS
  1059. if ($osname eq 'NetBSD' && $j eq 'LIB_DEPENDS'
  1060. && $m{'dep'} =~ /\\\\./) {
  1061. &perror("WARN", $file, -1, "use of backslashes in ".
  1062. "$j is deprecated.");
  1063. }
  1064. # check for PREFIX
  1065. if ($m{'dep'} =~ /\${PREFIX}/) {
  1066. &perror("FATAL", $file, -1, "\${PREFIX} must not be ".
  1067. "contained in *_DEPENDS. ".
  1068. "use \${LOCALBASE} instead.");
  1069. }
  1070. # Check for direct dependency on apache.
  1071. if ($m{'dep'} =~ /\/www\/apache\d*\//) {
  1072. &perror("FATAL", $file, -1, "do not depend on any apache ".
  1073. "port in *_DEPENDS directly. ".
  1074. "Instead use USE_APACHE=VERSION, where VERSION can be ".
  1075. "found in \${PORTSDIR}/Mk/bsd.apache.mk.");
  1076. }
  1077. # Check for over-specific shared library dependencies
  1078. if ($j eq 'LIB_DEPENDS' && $m{'dep'} =~ m/(\.\d+$)/) {
  1079. &perror("WARN", $file, -1, "$j don't specify the " .
  1080. "ABI version number $1 in $m{'dep'} unless it is " .
  1081. "really necessary.");
  1082. }
  1083. # check port dir existence
  1084. $k = $m{'dir'};
  1085. $k =~ s/\${PORTSDIR}/$ENV{'PORTSDIR'}/;
  1086. $k =~ s/\$[\({]PORTSDIR[\)}]/$ENV{'PORTSDIR'}/;
  1087. if (! -d $k) {
  1088. &perror("WARN", $file, -1, "no port directory $k ".
  1089. "found, even though it is ".
  1090. "listed in $j.");
  1091. } else {
  1092. print "OK: port directory $k found.\n"
  1093. if ($verbose);
  1094. }
  1095. }
  1096. }
  1097. }
  1098. #
  1099. # Makefile
  1100. #
  1101. sub checkmakefile {
  1102. my($file) = @_;
  1103. my($rawwhole, $whole, $idx, @sections);
  1104. my($i, $j, $k, $l);
  1105. my @cat = ();
  1106. my $has_lang_cat = 0;
  1107. my $port_lang = '';
  1108. my $tmp;
  1109. my $bogusdistfiles = 0;
  1110. my @varnames = ();
  1111. my($portname, $portversion, $distfiles, $distversionprefix, $distversion, $distversionsuffix, $distname, $extractsufx) = ('') x 8;
  1112. my $masterport = 0;
  1113. my $slaveport = 0;
  1114. my $use_gnome_hack = 0;
  1115. my $use_java = 0;
  1116. my $use_ant = 0;
  1117. my($realwrksrc, $wrksrc, $nowrksubdir) = ('', '', '');
  1118. my(@mman, @pman);
  1119. my(@mopt, @oopt);
  1120. my(@nmopt, @noopt);
  1121. my($pkg_version, $versiondir, $versionfile) = ('', '', '');
  1122. my $useindex = 0;
  1123. my %deprecated = ();
  1124. my @deplist = ();
  1125. my %autocmdnames = ();
  1126. my $pre_mk_line = 0;
  1127. my $options_mk_line = 0;
  1128. my $docsused = 0;
  1129. my $nlsused = 0;
  1130. my $newoptused = 0;
  1131. open(IN, "< $file") || return 0;
  1132. $rawwhole = '';
  1133. $tmp = 0;
  1134. while (<IN>) {
  1135. if ($_ =~ /[ \t]+\n?$/) {
  1136. &perror("WARN", $file, $., "whitespace before ".
  1137. "end of line.");
  1138. }
  1139. if ($_ =~ /^ /) { # 8 spaces here!
  1140. &perror("WARN", $file, $., "use tab (not space) to make ".
  1141. "indentation");
  1142. }
  1143. if ($usetabs) {
  1144. if (m/^[A-Za-z0-9_-]+.?= /) {
  1145. if (m/[?+]=/) {
  1146. &perror("WARN", $file, $., "use a tab (not space) after a ".
  1147. "variable name");
  1148. } else {
  1149. &perror("FATAL", $file, $., "use a tab (not space) after a ".
  1150. "variable name");
  1151. }
  1152. }
  1153. }
  1154. #
  1155. # I'm still not very convinced, for using this kind of magical word.
  1156. # 1. This kind of items are not important for Makefile;
  1157. # portlint should not require any additional rule to Makefile.
  1158. # portlint should simply implement items that are declared in Handbook.
  1159. # 2. If we have LINTSKIP, we can't stop people using LINTSKIP too much.
  1160. # IMHO it is better to warn the user and let the user think twice,
  1161. # than let the user escape from portlint.
  1162. # Uncomment this part if you are willing to use these magical words.
  1163. # Thu Jun 26 11:37:56 JST 1997
  1164. # -- itojun
  1165. #
  1166. # if ($_ =~ /^# LINTSKIP\n?$/) {
  1167. # print "OK: skipping from line $. in $file.\n"
  1168. # if ($verbose);
  1169. # $tmp = 1;
  1170. # next;
  1171. # }
  1172. # if ($_ =~ /^# LINTAGAIN\n?$/) {
  1173. # print "OK: check start again from line $. in $file.\n"
  1174. # if ($verbose);
  1175. # $tmp = 0;
  1176. # next;
  1177. # }
  1178. # if ($_ =~ /# LINTIGNORE/) {
  1179. # print "OK: ignoring line $. in $file.\n" if ($verbose);
  1180. # next;
  1181. # }
  1182. # next if ($tmp);
  1183. $rawwhole .= $_;
  1184. }
  1185. close(IN);
  1186. #
  1187. # whole file: blank lines.
  1188. #
  1189. $whole = "\n" . $rawwhole;
  1190. study $whole;
  1191. print "OK: checking contiguous blank lines in $file.\n"
  1192. if ($verbose);
  1193. $i = "\n" x ($contblank + 2);
  1194. if ($whole =~ /$i/) {
  1195. my $lineno = &linenumber($`);
  1196. &perror("FATAL", $file, $lineno, "contiguous blank lines ".
  1197. "(> $contblank lines) found.");
  1198. }
  1199. #
  1200. # whole file: header
  1201. #
  1202. my @lines = split("\n", $whole);
  1203. print "OK: checking header in $file.\n" if ($verbose);
  1204. if ($lines[1] =~ /^# (?:New )?[Pp]orts collection [mM]akefile/) {
  1205. &perror("FATAL", $file, 1, "old style headers found.");
  1206. } elsif ($lines[1] =~ /^# Created by: \S/) {
  1207. if ($lines[2] !~ /^# \$$rcsidstr[:\$]/) {
  1208. &perror("FATAL", $file, 2, "header should be ".
  1209. "followed by \$$rcsidstr\$.");
  1210. } elsif ($lines[3] !~ /^$/) {
  1211. #&perror("FATAL", $file, 3, "do not add extra ".
  1212. # "empty comments after header.");
  1213. }
  1214. } elsif ($lines[1] !~ /^# \$$rcsidstr[:\$]/ or $lines[2] !~ /^$/) {
  1215. &perror("FATAL", $file, 1, "incorrect header; ".
  1216. "use Created by: with a single space, then \$$rcsidstr\$.");
  1217. }
  1218. #
  1219. # whole file: $(VARIABLE)
  1220. #
  1221. if ($parenwarn) {
  1222. print "OK: checking for \$(VARIABLE).\n" if ($verbose);
  1223. if ($whole =~ /\$\([\w\d]+\)/) {
  1224. my $lineno = &linenumber($`);
  1225. &perror("WARN", $file, $lineno, "use \${VARIABLE}, instead of ".
  1226. "\$(VARIABLE).");
  1227. }
  1228. }
  1229. #
  1230. # whole file: empty(${VARIABLE})
  1231. #
  1232. if ($parenwarn) {
  1233. print "OK: checking for empty(\${VARIABLE}).\n" if ($verbose);
  1234. if ($whole =~ /empty\(\${[\w\d]+/) {
  1235. my $lineno = &linenumber($`);
  1236. &perror("WARN", $file, $lineno, "use empty(VARIABLE), instead of ".
  1237. "empty(\${VARIABLE}).");
  1238. }
  1239. }
  1240. #
  1241. # whole file: use of !=
  1242. #
  1243. print "OK: checking for use of !=.\n" if ($verbose);
  1244. if ($whole =~ /^[\w\d_]+\!=/m) {
  1245. my $lineno = &linenumber($`);
  1246. &perror("WARN", $file, $lineno, "use of != in assignments is almost ".
  1247. "never a good thing to do. Try to avoid using them. See ".
  1248. "http://lists.freebsd.org/pipermail/freebsd-ports/2008-July/049777.html ".
  1249. "for some helpful hints on what to do instead.");
  1250. }
  1251. #
  1252. # whole file: use of .elseif
  1253. #
  1254. print "OK: checking for use of .elseif.\n" if ($verbose);
  1255. if ($whole =~ /^\.\s*else\s*if/m) {
  1256. my $lineno = &linenumber($`);
  1257. &perror("FATAL", $file, $lineno, "use of .elseif (or .else if) is not
  1258. supported in all versions of FreeBSD. Use .elif instead.");
  1259. }
  1260. #
  1261. # whole file: PLIST_FILES and PLIST_DIRS
  1262. #
  1263. print "OK: checking PLIST_FILES and PLIST_DIRS.\n" if ($verbose);
  1264. if ($whole =~ /\nPLIST_FILES.?=/ || $whole =~ /\nPLIST_DIRS.?=/) {
  1265. if (-f 'pkg-plist') {
  1266. my $lineno = &linenumber($`);
  1267. &perror("WARN", $file, $lineno, "You may remove pkg-plist ".
  1268. "if you use PLIST_FILES and/or PLIST_DIRS.");
  1269. }
  1270. my @plist_files = split(/\s+/, $makevar{PLIST_FILES});
  1271. foreach my $plist_file (@plist_files) {
  1272. if ($plist_file =~ m|lib[^\/]+\.so(\.\d+)?$| &&
  1273. $makevar{USE_LDCONFIG} eq '') {
  1274. &perror("WARN", "", -1, "PLIST_FILES: installing shared libraries, ".
  1275. "please define USE_LDCONFIG as appropriate");
  1276. }
  1277. if ($plist_file =~ m|\.omf$| && $makevar{INSTALLS_OMF} eq '') {
  1278. &perror("WARN", "", -1, "PLIST_FILES: installing OMF files, ".
  1279. "please define INSTALLS_OMF (see the FreeBSD GNOME ".
  1280. "porting guide at ".
  1281. "http://www.FreeBSD.org/gnome/docs/porting.html ".
  1282. "for more details)");
  1283. }
  1284. if ($plist_file =~ m|\.core$| && $plist_file !~ /^\@/) {
  1285. &perror("WARN", "", -1, "this port installs a file which ".
  1286. "ends in \".core\". This file may be deleted if ".
  1287. "daily_clean_disks_enable=\"YES\" in /etc/periodic.conf. ".
  1288. "If possible, install this file with a different name.");
  1289. }
  1290. }
  1291. }
  1292. #
  1293. # whole file: USE_* and others variables used too late
  1294. #
  1295. my @options_early = qw(
  1296. OPTIONS
  1297. OPTIONS_DEFAULT
  1298. OPTIONS_DEFINE
  1299. OPTIONS_EXCLUDE
  1300. OPTIONS_GROUP.*?
  1301. OPTIONS_MULTI.*?
  1302. OPTIONS_RADIO.*?
  1303. OPTIONS_SINGLE.*?
  1304. );
  1305. pos($whole) = 0;
  1306. if ($whole =~ /^\.include\s+<bsd\.port\.pre\.mk>$/gm) {
  1307. # Remember position
  1308. $pre_mk_line = &linenumber($`) + 1;
  1309. print "OK: checking for USE_* used too late.\n" if ($verbose);
  1310. my @use_early = qw(
  1311. BZIP2
  1312. GNUSTEP
  1313. IMAKE
  1314. KDE(?:BASE|LIBS)_VER
  1315. (?:LIB)?RUBY
  1316. LINUX_PREFIX
  1317. OPENSSL
  1318. PYTHON
  1319. QT2?
  1320. QT_VER
  1321. X_PREFIX
  1322. ZIP
  1323. );
  1324. my @other_early = qw(
  1325. EMACS_PORT_NAME
  1326. );
  1327. my $earlypattern = join('|', 'USE_(?:'.join('|', @use_early).')',
  1328. @other_early, @options_early);
  1329. while ($whole =~ /^($earlypattern)[+?:!]?=/gmo) {
  1330. my $lineno = &linenumber($`);
  1331. &perror("FATAL", $file, $lineno, "$1 is set after ".
  1332. "including bsd.port.pre.mk.");
  1333. }
  1334. }
  1335. #
  1336. # whole file: check OPTIONS
  1337. #
  1338. print "OK: checking OPTIONS.\n" if ($verbose);
  1339. pos($whole) = 0;
  1340. if ($whole =~ /^\.include\s+<bsd\.port\.options\.mk>$/gm) {
  1341. # Remember position
  1342. $options_mk_line = &linenumber($`) + 1;
  1343. }
  1344. pos($whole) = 0;
  1345. if ($whole =~ /^\.include\s+<bsd\.port\.options\.mk>$/gm) {
  1346. my $earlypattern = join('|', @options_early);
  1347. while ($whole =~ /^($earlypattern)[+?]?=/gmo) {
  1348. my $lineno = &linenumber($`);
  1349. &perror("FATAL", $file, $lineno, "$1 is set after ".
  1350. "including bsd.port.options.mk.");
  1351. }
  1352. }
  1353. pos($whole) = 0;
  1354. if ($whole =~ /\nOPTIONS_DEFINE[+?]?=/) {
  1355. $newoptused++;
  1356. }
  1357. @oopt = ($makevar{OPTIONS} =~ /(\w+)\s+\".*?\"\s+\w+/sg);
  1358. @noopt = split(/\s+/, $makevar{OPTIONS_DEFINE});
  1359. if (scalar(@oopt) && $newoptused) {
  1360. &perror("FATAL", $file, -1, "Both old and new OPTIONS are found. ".
  1361. "Remove one or another.");
  1362. }
  1363. if (scalar(@oopt)) {
  1364. &perror("WARN", $file, -1, "Use of OPTIONS is obsolete. Use the ".
  1365. "new options framework.");
  1366. }
  1367. pos($whole) = 0;
  1368. while ($whole =~ /\(?\s*WITH(?:OUT)?_(\w+)\s*\)?/mg) {
  1369. push @mopt, $1;
  1370. my $lineno = &linenumber($`) + 1;
  1371. &perror("FATAL", $file, $lineno, "option WITH(OUT)_$1 is used before ".
  1372. "including bsd.port.pre.mk or bsd.port.options.mk.")
  1373. if (scalar(@oopt) && $lineno < $pre_mk_line &&
  1374. $lineno < $options_mk_line);
  1375. }
  1376. foreach my $i (@oopt) {
  1377. if (!grep(/^$i$/, @mopt)) {
  1378. &perror("WARN", $file, -1, "$i is listed in OPTIONS, ".
  1379. "but neither WITH_$i nor WITHOUT_$i appears.");
  1380. }
  1381. }
  1382. if ($newoptused) {
  1383. pos($whole) = 0;
  1384. while ($whole =~ /PORT_OPTIONS:M(\w+)/mg) {
  1385. push @nmopt, $1;
  1386. my $lineno = &linenumber($`) + 1;
  1387. &perror("FATAL", $file, $lineno, "option $1 is used before ".
  1388. "including bsd.port.pre.mk or bsd.port.options.mk.")
  1389. if ($newoptused && $lineno < $pre_mk_line &&
  1390. $lineno < $options_mk_line);
  1391. }
  1392. foreach my $i (@noopt) {
  1393. if (!grep(/^$i$/, @nmopt)) {
  1394. &perror("WARN", $file, -1, "$i is listed in OPTIONS_DEFINE, ".
  1395. "but no PORT_OPTIONS:M$i appears.");
  1396. }
  1397. }
  1398. }
  1399. foreach my $i (@mopt) {
  1400. next if ($i eq 'NLS'); # skip WITHOUT_NLS
  1401. if (!grep(/^$i$/, @oopt)) {
  1402. # XXX: disable temporarily.
  1403. # OPTIONS is still "in flux"
  1404. #&perror("WARN: $file: WITH_$i or WITHOUT_$i appears, ".
  1405. # "consider using OPTIONS macro.");
  1406. }
  1407. }
  1408. #
  1409. # whole file: USE_* as a user-settable option
  1410. #
  1411. print "OK: checking for USE_* as a user-settable option.\n" if ($verbose);
  1412. while ($whole =~ /\n\s*\.\s*(?:el)?if[^\n]*?\b(\w*USE_)(\w+)(?![^\n]*\n#?\.error)/g) {
  1413. my $lineno = &linenumber($`);
  1414. &perror("WARN", $file, $lineno, "is $1$2 a user-settable option? ".
  1415. "Consider using WITH_$2 instead.")
  1416. if ($1.$2 ne 'USE_GCC');
  1417. }
  1418. #
  1419. # whole file: NO_CHECKSUM
  1420. #
  1421. # XXX Don't compress newlines since it messes up line number calculation.
  1422. #$whole =~ s/\n#[^\n]*/\n/g;
  1423. #$whole =~ s/\n\n+/\n/g;
  1424. print "OK: checking NO_CHECKSUM.\n" if ($verbose);
  1425. if ($whole =~ /\nNO_CHECKSUM/) {
  1426. my $lineno = &linenumber($`);
  1427. &perror("FATAL", $file, $lineno, "NO_CHECKSUM is a user ".
  1428. "variable and is not to be set in a port's Makefile.");
  1429. }
  1430. #
  1431. # whole file: USE_SIZE
  1432. #
  1433. print "OK: checking USE_SIZE.\n" if ($verbose);
  1434. if ($whole =~ /\nUSE_SIZE/) {
  1435. my $lineno = &linenumber($`);
  1436. &perror("WARN", $file, $lineno, "use of USE_SIZE is no longer ".
  1437. "required.");
  1438. }
  1439. #
  1440. # whole file: MACHINE_ARCH
  1441. #
  1442. print "OK: checking MACHINE_ARCH.\n" if ($verbose);
  1443. if ($whole =~ /\nMACHINE_ARCH/) {
  1444. my $lineno = &linenumber($`);
  1445. &perror("FATAL", $file, $lineno, "MACHINE_ARCH should never be ".
  1446. "overridden.");
  1447. }
  1448. #
  1449. # whole file: DEPRECATED
  1450. #
  1451. print "OK: checking DEPRECATED.\n" if ($verbose);
  1452. if ($whole =~ /\nDEPRECATED[+?]?=[ \t]*"/ &&
  1453. $whole !~ /\nDEPRECATED[+?]?=[ \t]*"\$\{BROKEN\}"/) {
  1454. my $lineno = &linenumber($`);
  1455. &perror("WARN", $file, $lineno, "DEPRECATED messages should not ".
  1456. "be quoted unless they are exactly \"\${BROKEN}\".");
  1457. }
  1458. if ($whole =~ /\nDEPRECATED[+?]?=[^"]*\$\{BROKEN\}/) {
  1459. my $lineno = &linenumber($`);
  1460. &perror("WARN", $file, $lineno, "\"\${BROKEN}\" must be quoted ".
  1461. "when it is the source of DEPRECATED.");
  1462. }
  1463. #
  1464. # whole file: BROKEN et al.
  1465. #
  1466. my ($var);
  1467. foreach $var (qw(IGNORE BROKEN COMMENT FORBIDDEN MANUAL_PACKAGE_BUILD NO_CDROM NO_PACKAGE RESTRICTED)) {
  1468. print "OK: checking ${var}.\n" if ($verbose);
  1469. if ($whole =~ /\n${var}[+?]?=[ \t]+"/) {
  1470. my $lineno = &linenumber($`);
  1471. &perror("WARN", $file, $lineno, "${var} messages should not ".
  1472. "be quoted.");
  1473. }
  1474. }
  1475. if ($whole =~ /\nIGNORE[+?]?=[ \t]+[^a-z \t]/ ||
  1476. $whole =~ /^IGNORE[+?]?=[ \t]+.*\.$/m) {
  1477. my $lineno = &linenumber($`);
  1478. &perror("WARN", $file, $lineno, "IGNORE messages should begin ".
  1479. "with a lowercase letter and end without a period.");
  1480. }
  1481. #
  1482. # whole file: PKGNAME
  1483. #
  1484. print "OK: checking PKGNAME.\n" if ($verbose);
  1485. if ($whole =~ /\nPKGNAME.?=/) {
  1486. my $lineno = &linenumber($`);
  1487. &perror("FATAL", $file, $lineno, "PKGNAME is obsoleted by PORTNAME, ".
  1488. "PORTVERSION, PKGNAMEPREFIX and PKGNAMESUFFIX.");
  1489. }
  1490. #
  1491. # whole file: USE_REINPLACE
  1492. #
  1493. print "OK: checking for USE_REINPLACE.\n" if ($verbose);
  1494. if ($whole =~ /\nUSE_REINPLACE.?=/) {
  1495. my $lineno = &linenumber($`);
  1496. &perror("WARN", $file, $lineno, "USE_REINPLACE is now obsolete. ".
  1497. "You can safely use REINPLACE_CMD without it.");
  1498. }
  1499. #
  1500. # whole file: MAKE_JOBS_[UN]SAFE
  1501. #
  1502. print "OK: checking for MAKE_JOBS_SAFE in combination with NO_BUILD.\n" if ($verbose);
  1503. if ($whole =~ /\n(MAKE_JOBS_(UN)?SAFE).?=/) {
  1504. my $matched = $1;
  1505. if ($whole =~ /\nNO_BUILD.?=/) {
  1506. my $lineno = &linenumber($`);
  1507. &perror("WARN", $file, $lineno, "$matched should not ".
  1508. "be used in combination with NO_BUILD. You ".
  1509. "should remove $matched from your Makefile.");
  1510. }
  1511. }
  1512. #
  1513. # whole file: USE_GETOPT_LONG
  1514. #
  1515. print "OK: checking for USE_GETOPT_LONG.\n" if ($verbose);
  1516. if ($whole =~ /\nUSE_GETOPT_LONG.?=/) {
  1517. my $lineno = &linenumber($`);
  1518. &perror("WARN", $file, $lineno, "USE_GETOPT_LONG is now obsolete. ".
  1519. "You can safely remove this macro from your Makefile.");
  1520. }
  1521. #
  1522. # whole file: USE_GNOME=pkgconfig
  1523. #
  1524. print "OK: checking for USE_GNOME=pkgconfig.\n" if ($verbose);
  1525. if ($makevar{USE_GNOME} =~ /pkgconfig/) {
  1526. &perror("WARN", $file, -1, "USE_GNOME=pkgconfig is now obsolete. ".
  1527. "Use USE_PKGCONFIG instead.");
  1528. }
  1529. #
  1530. # whole file: EXPIRATION_DATE
  1531. #
  1532. print "OK: checking for valid EXPIRATION_DATE.\n" if ($verbose);
  1533. my $edate;
  1534. if (($edate) = ($whole =~ m/\nEXPIRATION_DATE\??=[ \t]*([^\n]*)\n/)) {
  1535. my $lineno = &linenumber($`);
  1536. if ($edate ne strftime("%Y-%m-%d", 0, 0, 0,
  1537. substr($edate, 8, 2),
  1538. substr($edate, 5, 2) - 1,
  1539. substr($edate, 0, 4) - 1900)) {
  1540. &perror("FATAL", $file, $lineno, "EXPIRATION_DATE ($edate) is ".
  1541. "either not in YYYY-MM-DD format or it is not a valid ".
  1542. "date.");
  1543. }
  1544. }
  1545. #
  1546. # whole file: IS_INTERACTIVE/NOPORTDOCS|PORT_OPTIONS:MDOCS
  1547. #
  1548. print "OK: checking IS_INTERACTIVE.\n" if ($verbose);
  1549. if ($whole =~ /\nIS_INTERACTIVE/) {
  1550. if ($whole !~ /defined\((BATCH|FOR_CDROM)\)/) {
  1551. my $lineno = &linenumber($`);
  1552. &perror("WARN", $file, $lineno, "use of IS_INTERACTIVE ".
  1553. "discouraged. provide batch mode by using BATCH and/or ".
  1554. "FOR_CDROM.");
  1555. }
  1556. }
  1557. print "OK: checking for use of PORT_OPTIONS:MDOCS.\n" if ($verbose);
  1558. if ($sharedocused && $whole =~ /PORT_OPTIONS:MDOCS/) {
  1559. $docsused++;
  1560. }
  1561. print "OK: checking for use of NOPORTDOCS.\n" if ($verbose);
  1562. if ($whole =~ /NOPORTSDOC/) {
  1563. my $lineno = &linenumber($`);
  1564. &perror("WARN", $file, $lineno, "NOPORTSDOC found. Do you ".
  1565. "mean NOPORTDOCS?");
  1566. }
  1567. if ($sharedocused && $whole !~ /defined\s*\(?NOPORTDOCS\)?/
  1568. && $whole !~ /def\s*\(?NOPORTDOCS\)?/) {
  1569. if ($docsused == 0 && $whole !~ m#(\$[\{\(]PREFIX[\}\)]|$localbase)/share/doc#) {
  1570. &perror("WARN", $file, -1, "use \".if !defined(NOPORTDOCS)\" to wrap ".
  1571. "installation of files into $localbase/share/doc.");
  1572. }
  1573. } else {
  1574. $docsused++;
  1575. }
  1576. if ($docsused > 1) {
  1577. &perror("FATAL", $file, -1, "Both NOPORTDOCS and PORT_OPTIONS:MDOCS are found. ".
  1578. "Remove one or another.");
  1579. }
  1580. print "OK: checking for use of NOPORTDOCS.\n" if ($verbose);
  1581. if ($whole =~ /NOPORTDOCS/) {
  1582. my $lineno = &linenumber($`);
  1583. &perror("WARN", $file, $lineno, "NOPORTDOCS found. Consider ".
  1584. "using PORT_OPTIONS:MDOCS");
  1585. }
  1586. #
  1587. # whole file: check for USE_GETTEXT
  1588. #
  1589. print "OK: checking for USE_GETTEXT without PORT_OPTIONS:MNLS.\n" if ($verbose);
  1590. if ($whole =~ /\nUSE_GETTEXT/ && $whole =~ /PORT_OPTIONS:MNLS/) {
  1591. $nlsused++;
  1592. }
  1593. print "OK: checking for USE_GETTEXT without WITHOUT_NLS.\n" if ($verbose);
  1594. if ($whole =~ /\nUSE_GETTEXT/ && $whole !~ /def(?:ined)?\s*\(?WITHOUT_NLS\)?/) {
  1595. if ($nlsused == 0) {
  1596. &perror("WARN", $file, -1, "Consider adding support for a WITHOUT_NLS ".
  1597. "knob to conditionally disable gettext support.");
  1598. }
  1599. } else {
  1600. $nlsused++;
  1601. }
  1602. if ($nlsused > 1) {
  1603. &perror("FATAL", $file, -1, "Both WITHOUT_NLS and PORT_OPTIONS:MNLS are found. ".
  1604. "Remove one or another.");
  1605. }
  1606. #
  1607. # whole file: check for deprecated commands
  1608. #
  1609. print "OK: checking for deprecated macros.\n" if $verbose;
  1610. %deprecated = (
  1611. USE_MESA => 'USE_GL',
  1612. USE_RCORDER => 'USE_RC_SUBR',
  1613. INSTALLS_SHLIB => 'USE_LDCONFIG',
  1614. APACHE_COMPAT => 'USE_APACHE',
  1615. USE_XPM => 'USE_X11=xpm',
  1616. );
  1617. @deplist = (\%deprecated);
  1618. for my $dlst (@deplist) {
  1619. my $hurl = $dlst->{'__HELP__'};
  1620. foreach my $depmacro (keys %{$dlst}) {
  1621. if ($whole =~ /\n($depmacro)[+?:!]?=/) {
  1622. my $derror = "$depmacro is ".
  1623. "deprecated, use $dlst->{$1} instead";
  1624. if (defined($hurl)) {
  1625. $derror .= " (see $hurl for more details)";
  1626. }
  1627. &perror("FATAL", $file, -1, $derror);
  1628. }
  1629. }
  1630. }
  1631. #
  1632. # whole file: DOS line endings
  1633. #
  1634. print "OK: checking for DOS line ending removal.\n" if ($verbose);
  1635. if ($whole =~ / / || $whole =~ /:cntrl:/) {
  1636. my $lineno = &linenumber($`);
  1637. &perror("WARN", $file, $lineno, "Possible manual removal of DOS ".
  1638. "line endings found. Consider defining USE_DOS2UNIX instead.");
  1639. }
  1640. #
  1641. # whole file: direct use of command names
  1642. #
  1643. my %cmdnames = ();
  1644. print "OK: checking direct use of command names.\n" if ($verbose);
  1645. foreach my $i (qw(
  1646. awk basename brandelf cat chmod chown cp cpio dialog dirname egrep expr
  1647. false file find gmake grep gzcat ldconfig ln md5 mkdir mv objcopy paste patch
  1648. pax perl printf rm rmdir pkg_add pkg_delete pkg_info pkg_version
  1649. ruby sed sh sort sysctl touch tr which xargs xmkmf
  1650. )) {
  1651. $cmdnames{$i} = "\$\{\U$i\E\}";
  1652. }
  1653. $cmdnames{'echo'} = '${ECHO_CMD} or ${ECHO_MSG}';
  1654. $cmdnames{'env'} = '${SETENV}';
  1655. $cmdnames{'gunzip'} = '${GUNZIP_CMD}';
  1656. $cmdnames{'gzip'} = '${GZIP_CMD}';
  1657. $cmdnames{'install'} = '${INSTALL_foobaa}';
  1658. $cmdnames{'python'} = '${PYTHON_CMD}';
  1659. $cmdnames{'strip'} = '${STRIP_CMD}';
  1660. $cmdnames{'unzip'} = '${UNZIP_CMD}';
  1661. $cmdnames{'pkg_create'} = '${PKG_CMD}';
  1662. foreach my $i (qw(aclocal autoconf autoheader automake autoreconf autoupdate autoscan ifnames libtool libtoolize)) {
  1663. $autocmdnames{$i} = "\$\{" . ( ( $i !~ /auto|aclocal|libtool/ ) ? "AUTO" : "" ) . "\U$i\E\}";
  1664. }
  1665. #
  1666. # ignore parameter string to echo command.
  1667. # note that we leave the command as is, since we need to check the
  1668. # use of echo itself.
  1669. $j = $whole;
  1670. $j =~ s/([ \t][\@\-]{0,2})(echo|\$[\{\(]ECHO[\}\)]|\$[\{\(]ECHO_MSG[\}\)])[ \t]+(?:"(?:\\'|\\"|[^"])*"|'(?:\\'|\\"|[^'])*')[ \t]*;?(\n?)/$1$2;$3/g; #"
  1671. # ignore variables names in .for loops, but not what's at the end
  1672. # of the for loop
  1673. $j =~ s/(\.for +)([^ ]*)( .*)/$1$3/;
  1674. foreach my $i (keys %cmdnames) {
  1675. # XXX This is a hack. Really, we should break $j up into individual
  1676. # lines, and go through each one.
  1677. while ($j =~ /^(.*$i.*)$/gm) {
  1678. my $curline = $1;
  1679. my $lineno = &linenumber($`);
  1680. if ($curline =~ /(?:^|\s)[\@\-]{0,2}$i(?:$|\s)/
  1681. && $curline !~ /^[A-Z]+_TARGET[?+]?=[^\n]+$i/m
  1682. && $curline !~ /^IGNORE(.)?=[^\n]+$i/m
  1683. && $curline !~ /^BROKEN(.)?=[^\n]+$i/m
  1684. && $curline !~ /^RESTRICTED(.)?=[^\n]+$i/m
  1685. && $curline !~ /^NO_PACKAGE(.)?=[^\n]+$i/m
  1686. && $curline !~ /^NO_CDROM(.)?=[^\n]+$i/m
  1687. && $curline !~ /^MAINTAINER(.)?=[^\n]+$i/m
  1688. && $curline !~ /^CATEGORIES(.)?=[^\n]+$i/m
  1689. && $curline !~ /^WX_COMPS(.)?=[^\n]+$i/m
  1690. && $curline !~ /^\s*#.+$/m
  1691. && $curline !~ /\-\-$i/m
  1692. && $curline !~ /^COMMENT(.)?=[^\n]+$i/m) {
  1693. &perror("WARN", $file, $lineno, "possible direct use of ".
  1694. "command \"$i\" found. use ".
  1695. "$cmdnames{$i} instead.");
  1696. }
  1697. }
  1698. }
  1699. foreach my $i (keys %autocmdnames) {
  1700. # XXX Same hack as above.
  1701. while ($j =~ /^(.*($i\d*).*)$/gm) {
  1702. my $lm = $1;
  1703. my $sm = $2;
  1704. my $lineno = &linenumber($`);
  1705. if ($lm =~ /(^|\s+)[\@\-]{0,2}($i\d*)\b/
  1706. && $lm !~ /^[A-Z]+_TARGET[?+]?=[^\n]+($i\d*)/m
  1707. && $lm !~ /^IGNORE(.)?=[^\n]+($i\d*)/m
  1708. && $lm !~ /^BROKEN(.)?=[^\n]+($i\d*)/m
  1709. && $lm !~ /^RESTRICTED(.)?=[^\n]+($i\d*)/m
  1710. && $lm !~ /^NO_PACKAGE(.)?=[^\n]+($i\d*)/m
  1711. && $lm !~ /^NO_CDROM(.)?=[^\n]+($i\d*)/m
  1712. && $lm !~ /^MAINTAINER(.)?=[^\n]+($i\d*)/m
  1713. && $lm !~ /^CATEGORIES(.)?=[^\n]+($i\d*)/m
  1714. && $lm !~ /^USE_AUTOTOOLS(.)?=[^\n]+($i\d*)/m
  1715. && $lm !~ /^\s*#.+$/m
  1716. && $lm !~ /^COMMENT(.)?=[^\n]+($i\d*)/m) {
  1717. &perror("WARN", $file, $lineno, "possible direct use of ".
  1718. "command \"$sm\" found. Use $autocmdnames{$i} ".
  1719. "instead and set according USE_AUTOTOOLS=<tool> macro");
  1720. }
  1721. }
  1722. }
  1723. #
  1724. # whole file: check for use of paths that have macro replacements
  1725. #
  1726. my %pathnames = ();
  1727. print "OK: checking for paths that have macro replacements.\n"
  1728. if ($verbose);
  1729. $pathnames{'${PREFIX}/share/java/classes'} = 'JAVADIR';
  1730. $pathnames{'${PREFIX}/share/java'} = 'JAVASHAREDIR';
  1731. foreach my $i (keys %pathnames) {
  1732. my $lineno = &linenumber($`);
  1733. if ($j =~ m|$i|gm) {
  1734. &perror("FATAL", $file, $lineno, "you should use ".
  1735. "$pathnames{$i} rather than $i");
  1736. }
  1737. }
  1738. #
  1739. # whole file: ldconfig must come with "true" command
  1740. #
  1741. print "OK: checking that ldconfig is properly checked.\n"
  1742. if ($verbose);
  1743. if ($ldconfigwithtrue
  1744. && $j =~ /(ldconfig|\$[{(]LDCONFIG[)}])/
  1745. && $j !~ /(\/usr\/bin\/true|\$[{(]TRUE[)}])/) {
  1746. my $lineno = &linenumber($`);
  1747. &perror("FATAL", $file, $lineno, "ldconfig must be used with ".
  1748. "\"||\${TRUE}\".");
  1749. }
  1750. #
  1751. # whole file: ${GZIP_CMD} -9 (or any other number)
  1752. #
  1753. print "OK: checking for compression arguments passed to \${GZIP_CMD}.\n"
  1754. if ($verbose);
  1755. if ($j =~ /\${GZIP_CMD}\s+-(\w+(\s+-)?)*(\d)/) {
  1756. my $lineno = &linenumber($`);
  1757. &perror("WARN", $file, $lineno, "possible use of \"\${GZIP_CMD} -$3\" ".
  1758. "found. \${GZIP_CMD} includes \"-\${GZIP}\" which ".
  1759. "sets the compression level.");
  1760. }
  1761. #
  1762. # whole file: ${MKDIR} -p
  1763. #
  1764. print "OK: checking for \${MKDIR} -p.\n"
  1765. if ($verbose);
  1766. if ($j =~ /\${MKDIR}\s+-p/) {
  1767. my $lineno = &linenumber($`);
  1768. &perror("WARN", $file, $lineno, "possible use of \"\${MKDIR} -p\" ".
  1769. "found. \${MKDIR} includes ".
  1770. "\"-p\" by default.");
  1771. }
  1772. #
  1773. # check for use of ${FIND} ... ${XARGS} ${RM}
  1774. #
  1775. print "OK: checking for instances of \${FIND} ... \${XARGS} \${RM}.\n"
  1776. if ($verbose);
  1777. if ($j =~ /\$\{FIND\}.*\|.*\$\{XARGS\}.*\$\{RM\}/) {
  1778. my $lineno = &linenumber($`);
  1779. &perror("WARN", $file, $lineno, "possible use of ".
  1780. "\"\${FIND} ... \${XARGS} \${RM}\" when ".
  1781. "\"\${FIND} ... -delete\" will work.");
  1782. }
  1783. #
  1784. # whole file: ${MACHINE_ARCH}
  1785. #
  1786. print "OK: checking for instances of \${MACHINE_ARCH} being test.\n"
  1787. if ($verbose);
  1788. if ($j =~ /\${MACHINE_ARCH}\s*[!=]=/) {
  1789. my $lineno = &linenumber($`);
  1790. &perror("FATAL", $file, $lineno, "MACHINE_ARCH should never be tested ".
  1791. "directly; use ARCH instead.");
  1792. }
  1793. #
  1794. # whole file: full path name
  1795. #
  1796. &abspathname($whole, $file);
  1797. #
  1798. # whole file: SITE_PERL
  1799. #
  1800. print "OK: checking SITE_PERL.\n" if ($verbose);
  1801. if ($whole =~ /\nSITE_PERL[?:]?=/) {
  1802. my $lineno = &linenumber($`);
  1803. &perror("FATAL", $file, $lineno, "use of SITE_PERL discouraged. ".
  1804. "it is set in bsd.port.mk.");
  1805. }
  1806. #
  1807. # whole file: ${LOCALBASE}/lib/perl5/site_perl/${PERL_VER}
  1808. #
  1809. if ($j =~ m'\${(?:LOCALBASE|PREFIX)}/lib/perl5/site_perl/\${PERL_VER}') {
  1810. my $lineno = &linenumber($`);
  1811. &perror("WARN", $file, $lineno, "possible use of \"\${LOCALBASE}/lib/perl5/site_perl/\${PERL_VER}\" ".
  1812. "found. use \"\${SITE_PERL}\" instead.");
  1813. }
  1814. #
  1815. # whole file: USE_GNOME check
  1816. #
  1817. if ($whole =~ /^USE_GNOME[?:]?=\s*(.*)$/m) {
  1818. if ($1 =~ /gnomehack/) {
  1819. $use_gnome_hack = 1;
  1820. }
  1821. }
  1822. #
  1823. # whole file: USE_GCC checks
  1824. #
  1825. if ($whole =~ /^USE_GCC[?:]?=\s*(.*)$/m) {
  1826. my $lineno = &linenumber($`);
  1827. my $gcc_val = $1;
  1828. if ($gcc_val eq 'any' || $gcc_val eq 'yes') {
  1829. # Just accept these two.
  1830. } elsif ($gcc_val =~ /3\.[234]\+/) {
  1831. &perror("WARN", $file, $lineno, "USE_GCC=3.2+, USE_GCC=3.3+, ".
  1832. "and USE_GCC=3.4+ are noops on all currently (and future) ".
  1833. "supported versions of FreeBSD. Do not use them.");
  1834. } elsif ($gcc_val eq "4.1+") {
  1835. &perror("WARN", $file, $lineno, "USE_GCC=4.2+ is recommended ".
  1836. "over USE_GCC=4.1+ since the former is the system compiler ".
  1837. "for FreeBSD 7.X.");
  1838. } elsif ($gcc_val !~ /\+/ && $gcc_val ne 'any') {
  1839. &perror("WARN", $file, $lineno, "Setting a specific version for ".
  1840. "USE_GCC should only be done as a last resort. Unless you ".
  1841. "have confirmed this port does not build with later ".
  1842. "versions of GCC, please use USE_GCC=$gcc_val+.");
  1843. }
  1844. }
  1845. #
  1846. # whole file: USE_JAVA check
  1847. #
  1848. if ($whole =~ /^USE_JAVA[?:]?=\s*(.*)$/m) {
  1849. $use_java = 1;
  1850. }
  1851. #
  1852. # whole file: USE_ANT check
  1853. #
  1854. if ($whole =~ /^USE_ANT[?:]?=\s*(.*)$/m) {
  1855. $use_ant = 1;
  1856. }
  1857. #
  1858. # whole file: USE_JAVA not defined, but other Java components are requested
  1859. #
  1860. if (!$use_java && ($use_ant || $whole =~ /^JAVA_VERSION[?:]?=\s*(.*)$/m ||
  1861. $whole =~ /^JAVA_OS[?:]?=\s*(.*)$/m ||
  1862. $whole =~ /^JAVA_VENDOR[?:]?=\s*(.*)$/m ||
  1863. $whole =~ /^JAVA_RUN[?:]?=\s*(.*)$/m ||
  1864. $whole =~ /^JAVA_BUILD[?:]?=\s*(.*)$/m)) {
  1865. &perror("FATAL", $file, -1, "the port uses Java features, but USE_JAVA ".
  1866. "is not defined");
  1867. }
  1868. #
  1869. # whole file: check for USE_ANT and USE_GMAKE both defined
  1870. #
  1871. if ($use_ant && $whole =~ /^USE_GMAKE[?:]?=\s*(.*)$/m) {
  1872. &perror("WARN", $file, -1, "a port shall not define both USE_ANT ".
  1873. "and USE_GMAKE");
  1874. }
  1875. #
  1876. # whole file: check for USE_APACHE=yes
  1877. #
  1878. if ($whole =~ /^USE_APACHE[?:]?=\s*(yes)$/m) {
  1879. &perror("FATAL", $file, -1, "Use USE_APACHE=VERSION ".
  1880. "(where version can be found in \${PORTSDIR}/Mk/bsd.apache.mk) ".
  1881. "instead of yes");
  1882. }
  1883. #
  1884. # whole file: check for WITH_APACHE\d+
  1885. #
  1886. if ($whole =~ /WITH_APACHE\d+/) {
  1887. &perror("FATAL", $file, -1, "Use WITH_APACHE=yes and .if ".
  1888. "\${APACHE_VERSION} [==|<|>] 13|20|22|24");
  1889. }
  1890. #
  1891. # whole file: check for JAVA_BUILD and NO_BUILD
  1892. #
  1893. if ($whole =~ /^NO_BUILD[?:]?=\s*(.*)$/m &&
  1894. $whole =~ /^JAVA_BUILD[?:]?=\s*(.*)$/m) {
  1895. &perror("FATAL", $file, -1, "JAVA_BUILD and NO_BUILD cannot be set ".
  1896. "at the same time");
  1897. }
  1898. #
  1899. # whole file: check for reassignment of ECHO_MSG
  1900. #
  1901. if ($whole =~ /^ECHO_MSG[?:]?=\s*(.*)$/m) {
  1902. &perror("FATAL", $file, -1, "Re-assigning ECHO_MSG can break ".
  1903. "``make readme''. Consider using \${PRINTF} directly instead ".
  1904. "for custom message output.");
  1905. }
  1906. #
  1907. # whole file: check for --build, --mandir, and --infodir
  1908. # when GNU_CONFIGURE
  1909. #
  1910. if (exists $makevar{GNU_CONFIGURE} &&
  1911. $makevar{GNU_CONFIGURE} ne '' &&
  1912. $makevar{CONFIGURE_ARGS} =~ /--(build|(man|info)dir)/) {
  1913. &perror("WARN", $file, -1, "--build, --mandir, and --infodir ".
  1914. "are not needed in CONFIGURE_ARGS as they are already set in ".
  1915. "bsd.port.mk.");
  1916. }
  1917. #
  1918. # whole file: CONFIGURE_ENV
  1919. #
  1920. if ($whole =~ /\nCONFIGURE_ENV[?:+]?=\s*([^\\\n]+(\\\n[^\\\n]+)*)/) {
  1921. my $configure_env = $1;
  1922. my $cflags = undef;
  1923. my $cxxflags = undef;
  1924. if ($configure_env =~ /\bCFLAGS="([^"]+)"/ ||
  1925. $configure_env =~ /\bCFLAGS='([^']+)'/ ||
  1926. $configure_env =~ /\bCFLAGS=(\S+)/) {
  1927. $cflags = $1;
  1928. }
  1929. if ($configure_env =~ /\bCXXFLAGS="([^"]+)"/ ||
  1930. $configure_env =~ /\bCXXFLAGS='([^']+)'/ ||
  1931. $configure_env =~ /\bCXXFLAGS=(\S+)/) {
  1932. $cxxflags = $1;
  1933. }
  1934. if (defined($cflags) || defined($cxxflags)) {
  1935. &perror("WARN", $file, -1, "CFLAGS/CXXFLAGS are not needed in ".
  1936. "CONFIGURE_ENV as they are already added there in bsd.port.mk.");
  1937. }
  1938. if ($makevar{GNU_CONFIGURE} ne '') {
  1939. if ((defined($cflags) && $cflags =~ /-I/) ||
  1940. (defined($cxxflags) && $cxxflags =~ /-I/)) {
  1941. &perror("WARN", $file, -1, "Consider passing include paths ".
  1942. "to configure via the CPPFLAGS macro ".
  1943. "(i.e. CPPFLAGS+=-I...)");
  1944. }
  1945. }
  1946. if (defined($cflags) && $cflags !~ /\$\{CFLAGS/) {
  1947. &perror("FATAL", $file, -1, "CFLAGS are clobbered in ".
  1948. "CONFIGURE_ENV. Alter CFLAGS in the Makefile with ".
  1949. "CFLAGS+=... instead");
  1950. }
  1951. if (defined($cxxflags) && $cflags !~ /\$\{CXXFLAGS/) {
  1952. &perror("FATAL", $file, -1, "CXXFLAGS are clobbered in ".
  1953. "CONFIGURE_ENV. Alter CXXFLAGS in the Makefile with ".
  1954. "CXXFLAGS+=... instead");
  1955. }
  1956. if ($configure_env =~ /(FC)=/ ||
  1957. $configure_env =~ /(F77)=/ ||
  1958. $configure_env =~ /(FFLAGS)=/) {
  1959. &perror("FATAL", $file, -1, "$1 is already ".
  1960. "passed in CONFIGURE_ENV via bsd.gcc.mk. If you need to ".
  1961. "override the default value, alter $1 in the Makefile ".
  1962. "instead with $1=...");
  1963. }
  1964. if ($configure_env =~ /(\bCPPFLAGS)=/) {
  1965. &perror("FATAL", $file, -1, "$1 is already ".
  1966. "passed in CONFIGURE_ENV via bsd.port.mk. If you need to ".
  1967. "override the default value, alter $1 in the Makefile ".
  1968. "instead with $1+=...");
  1969. }
  1970. if ($configure_env =~ /(\bLDFLAGS)=/) {
  1971. &perror("FATAL", $file, -1, "$1 is already passed in ".
  1972. "CONFIGURE_ENV via bsd.port.mk. If you need to ".
  1973. "override the default value, alter $1 in the Makefile ".
  1974. "instead with $1+=...");
  1975. }
  1976. }
  1977. #
  1978. # whole file: *FLAGS
  1979. #
  1980. foreach my $f (qw(CFLAGS CXXFLAGS CPPFLAGS LDFLAGS)) {
  1981. if ($whole =~ /^$f=/m) {
  1982. &perror("WARN", $file, -1, "$f is overridden in the Makefile ".
  1983. "clobbering a value possibly set by a user. Consider ".
  1984. "using $f+=... if you want to add or $f:=\${$f:C/...//} ".
  1985. "if you want to remove specific flags");
  1986. }
  1987. }
  1988. #
  1989. # whole file: MAKE_ENV
  1990. #
  1991. if ($whole =~ /\nMAKE_ENV[?:+]?=\s*([^\\\n]+(\\\n[^\\\n]+)*)/) {
  1992. my $make_env = $1;
  1993. if ($make_env =~ /(CPPFLAGS)=/) {
  1994. &perror("FATAL", $file, -1, "$1 is already ".
  1995. "passed in MAKE_ENV via bsd.port.mk. If you need to ".
  1996. "override the default value, alter $1 in the Makefile ".
  1997. "instead with $1=...");
  1998. }
  1999. }
  2000. #
  2001. # slave port check
  2002. #
  2003. my $masterdir = $makevar{MASTERDIR};
  2004. if ($masterdir ne '' && $masterdir ne $makevar{'.CURDIR'}) {
  2005. $slaveport = 1;
  2006. print "OK: slave port detected, checking for inclusion of $masterdir/Makefile.\n"
  2007. if ($verbose);
  2008. if ($whole =~ /^\.\s*include\s*[<"]bsd\.port(?:\.post)?\.mk[">]/m) {
  2009. &perror("FATAL", $file, -1, "supposedly non-slave port with".
  2010. " .CURDIR != MASTERDIR");
  2011. } elsif ($whole =~ /^\.\s*include\s*[<"]bsd\.port\.pre\.mk[">]/m) {
  2012. &perror("FATAL", $file, -1, "slave ports may not include".
  2013. " bsd.port.pre.mk");
  2014. }
  2015. if ($whole !~ /\n\.include\s+"\$\{MASTERDIR\}\/Makefile"\s*$/s) {
  2016. &perror("FATAL", $file, -1, "the last line of a slave port's Makefile has to be".
  2017. ' .include "${MASTERDIR}/Makefile"');
  2018. }
  2019. print "OK: checking master port in $masterdir.\n" if ($verbose);
  2020. if (! -e "$masterdir/Makefile") {
  2021. &perror("WARN", "", -1, "unable to locate master port in $masterdir");
  2022. }
  2023. if ($whole !~ /^MASTERDIR=\s*\$\{\.CURDIR\}(?:\/\.\.){1,2}(?:\/[\w\@.+-]+){1,2}\s*$/m) {
  2024. &perror("WARN", $file, -1, "slave ports must define MASTERDIR=".
  2025. '${.CURDIR}/..(/../<category>)/<port>');
  2026. }
  2027. } else {
  2028. #$slaveport = 0;
  2029. print "OK: non-slave port detected, checking for anything after bsd.port(.post).mk.\n"
  2030. if ($verbose);
  2031. if ($whole !~ /\n\.include\s+<bsd\.port(?:\.post)?\.mk>\s*$/s) {
  2032. &perror("FATAL", $file, -1, "the last line of Makefile has to be".
  2033. ' .include <bsd.port(.post).mk>');
  2034. }
  2035. if ($whole =~ /^MASTERDIR\s*[+?:!]?\s*=/m) {
  2036. &perror("WARN", $file, -1, "non-slave ports may not define MASTERDIR");
  2037. }
  2038. }
  2039. #
  2040. # break the makefile into sections.
  2041. #
  2042. $tmp = $rawwhole;
  2043. # keep comment, blank line, comment in the same section
  2044. $tmp =~ s/(#.*\n)\n+(#.*)/$1$2/g;
  2045. $tmp =~ s/\\\n\n/\n/g;
  2046. @sections = split(/\n\n+/, $tmp);
  2047. for ($i = 0; $i <= $#sections; $i++) {
  2048. if ($sections[$i] !~ /\n$/) {
  2049. $sections[$i] .= "\n";
  2050. }
  2051. }
  2052. $idx = 0;
  2053. #
  2054. # section 1: comment lines.
  2055. #
  2056. print "OK: checking comment section of $file.\n" if ($verbose);
  2057. my @linestocheck = split("\n", <<EOF);
  2058. Whom
  2059. Date [cC]reated
  2060. EOF
  2061. if ($osname eq 'NetBSD') {
  2062. unshift(@linestocheck, '(New )?[pP](ackage|ort)s [cC]ollection [mM]akefile [fF]or');
  2063. }
  2064. $tmp = $sections[$idx++];
  2065. $tmp = "\n" . $tmp; # to make the begin-of-line check easier
  2066. if ($tmp =~ /\n[^#]/) {
  2067. &perror("FATAL", $file, -1, "non-comment line in comment section.");
  2068. }
  2069. if ($osname eq 'NetBSD') {
  2070. foreach my $i (@linestocheck) {
  2071. $j = $i;
  2072. $j =~ s/\(.*\)\?//g;
  2073. $j =~ s/\[(.)[^\]]*\]/$1/g;
  2074. if ($tmp !~ /# $i:[ \t]+\S+/) {
  2075. &perror("FATAL", $file, -1, "no \"$j\" line in comment section.");
  2076. } else {
  2077. print "OK: \"$j\" seen in $file.\n" if ($verbose);
  2078. }
  2079. }
  2080. }
  2081. if ($tmp =~ m/Version [rR]equired/) {
  2082. &perror("WARN", $file, -1, "Version required is no longer needed in the comment section.");
  2083. }
  2084. my $tmp2 = "";
  2085. for (split(/\n/, $tmp)) {
  2086. $tmp2 .= $_ if (m/\$$rcsidstr/);
  2087. }
  2088. if ($tmp2 !~ /#(\s+)\$$rcsidstr([^\$]*)\$$/) {
  2089. &perror("FATAL", $file, -1, "no \$$rcsidstr\$ line in comment ".
  2090. "section.");
  2091. } else {
  2092. print "OK: \$$rcsidstr\$ seen in $file.\n" if ($verbose);
  2093. if ($1 ne ' ') {
  2094. &perror("WARN", $file, -1, "please use single whitespace ".
  2095. "right before \$$rcsidstr\$ tag.");
  2096. }
  2097. if ($2 ne '') {
  2098. if ($verbose || $newport) { # XXX
  2099. &perror("WARN", $file, -1,
  2100. ($newport ? 'for new port, '
  2101. : 'is it a new port? if so, ').
  2102. "make \$$rcsidstr\$ tag in comment ".
  2103. "section empty, to make SVN happy.");
  2104. }
  2105. }
  2106. }
  2107. #
  2108. # for the rest of the checks, comment lines are not important.
  2109. #
  2110. for ($i = 0; $i < scalar(@sections); $i++) {
  2111. $sections[$i] = "\n" . $sections[$i];
  2112. $sections[$i] =~ s/\n#[^\n]*//g;
  2113. $sections[$i] =~ s/\n\n+/\n/g;
  2114. $sections[$i] =~ s/\\\n/ /g;
  2115. $sections[$i] =~ s/^\n//;
  2116. }
  2117. #
  2118. # section 2: PORTNAME/PORTVERSION/...
  2119. #
  2120. print "OK: checking first section of $file (PORTNAME/...).\n"
  2121. if ($verbose);
  2122. $tmp = $sections[$idx++];
  2123. # check the order of items.
  2124. &checkorder('PORTNAME', $tmp, $file, qw(
  2125. PORTNAME PORTVERSION DISTVERSIONPREFIX DISTVERSION DISTVERSIONSUFFIX
  2126. PORTREVISION PORTEPOCH CATEGORIES MASTER_SITES MASTER_SITE_SUBDIR
  2127. PROJECTHOST PKGNAMEPREFIX PKGNAMESUFFIX DISTNAME EXTRACT_SUFX DISTFILES
  2128. DIST_SUBDIR EXTRACT_ONLY
  2129. ));
  2130. # check the items that has to be there.
  2131. $tmp = "\n" . $tmp;
  2132. print "OK: checking PORTNAME/PORTVERSION/DISTVERSION.\n" if ($verbose);
  2133. if ($tmp !~ /\nPORTNAME(.)?=/) {
  2134. &perror("FATAL", $file, -1, "PORTNAME has to be there.") unless ($slaveport && $makevar{PORTNAME} ne '');
  2135. } elsif (defined $1 && $1 ne '') {
  2136. &perror("WARN", $file, -1, "unless this is a master port, PORTNAME has to be set by \"=\", ".
  2137. "not by \"$1=\".") unless ($masterport);
  2138. }
  2139. if ($tmp !~ /\n(PORTVERSION|DISTVERSION)(.)?=/) {
  2140. &perror("FATAL", $file, -1, "PORTVERSION or DISTVERSION has to be there.") unless (($makevar{PORTVERSION} ne '' || $makevar{DISTVERSION} ne ''));
  2141. if (!$slaveport && ($makevar{PORTVERSION} ne '' || $makevar{DISTVERSION} ne '')) {
  2142. &perror("WARN", $file, -1, "PORTVERSION/DISTVERSION is set externally to this port's Makefile, but this port is not configured as a slave port.");
  2143. }
  2144. } elsif (defined $2 && $2 ne '') {
  2145. &perror("WARN", $file, -1, "unless this is a master port, PORTVERSION has to be set by \"=\", ".
  2146. "not by \"$2=\".") unless ($masterport);
  2147. }
  2148. if ($tmp =~ /\nPORTVERSION.?=/ && $tmp =~ /\nDISTVERSION.?=/) {
  2149. &perror("FATAL", $file, -1, "either PORTVERSION or DISTVERSION must be ".
  2150. "specified, not both.");
  2151. }
  2152. if ($newport) {
  2153. print "OK: checking for existence of PORTREVISION in new port.\n"
  2154. if ($verbose);
  2155. if ($tmp =~ /^PORTREVISION(.)?=/m) {
  2156. &perror("WARN", $file, -1, "new ports should not set PORTREVISION.");
  2157. }
  2158. } elsif (!$slaveport) {
  2159. print "OK: checking for PORTREVISION=0.\n" if ($verbose);
  2160. if ($tmp =~ /^PORTREVISION=\s*0/m) {
  2161. &perror("WARN", $file, -1, "Setting PORTREVISION to 0 is not ".
  2162. "necessary.");
  2163. }
  2164. }
  2165. if ($newport) {
  2166. print "OK: checking for existence of PORTEPOCH in new port.\n"
  2167. if ($verbose);
  2168. if ($tmp =~ /^PORTEPOCH(.)?=/m) {
  2169. &perror("WARN", $file, -1, "new ports should not set PORTEPOCH.");
  2170. }
  2171. }
  2172. print "OK: checking CATEGORIES.\n" if ($verbose);
  2173. if ($tmp !~ /\nCATEGORIES(.)?=/) {
  2174. &perror("FATAL", $file, -1, "CATEGORIES has to be there.") unless ($makevar{CATEGORIES} ne '');
  2175. if (!$slaveport && $makevar{CATEGORIES} ne '') {
  2176. &perror("WARN", $file, -1, "CATEGORIES is set externally to this port's Makefile, but this port is not configured as a slave port.");
  2177. }
  2178. } elsif (defined $1 && ($i = $1) ne '' && $i =~ /[^?+]/) {
  2179. &perror("WARN", $file, -1, "unless this is a master port, CATEGORIES should be set by \"=\", \"?=\", or \"+=\", ".
  2180. "not by \"$i=\".") unless ($masterport);
  2181. }
  2182. @cat = split(/\s+/, $makevar{CATEGORIES});
  2183. if (@cat == 0) {
  2184. &perror("FATAL", $file, -1, "CATEGORIES left blank. set it to \"misc\"".
  2185. " if nothing seems apropriate.");
  2186. } else {
  2187. my %seencat = ();
  2188. foreach my $cat (@cat) {
  2189. if ($seencat{$cat}) {
  2190. &perror("WARN", $file, -1, "Duplicate category, $cat specified".
  2191. " in CATEGORIES.");
  2192. } else {
  2193. $seencat{$cat} = 1;
  2194. }
  2195. }
  2196. }
  2197. if ($use_java && !grep /^java$/, @cat) {
  2198. &perror("WARN", $file, -1, "the port uses Java but is not part of the ".
  2199. "``java'' category");
  2200. }
  2201. if (scalar(@cat) == 1 && $cat[0] eq "java") {
  2202. &perror("FATAL", $file, -1, "the ``java'' category shall not be the only ".
  2203. "one for a port");
  2204. }
  2205. if ($newport && scalar(@cat) > 0 && $cat[0] eq "java") {
  2206. &perror("WARN", $file, -1, "save for ports directly related to the Java ".
  2207. "language, porters are encouraged not to use ``java'' as ".
  2208. "the main category for a port");
  2209. }
  2210. if ($committer && $makevar{'.CURDIR'} =~ m'${portsdir}/([^/]+)/[^/]+/?$') {
  2211. if ($cat[0] ne $1 && $makevar{PKGCATEGORY} ne $1 ) {
  2212. &perror("FATAL", $file, -1, "category \"$1\" must be listed first");
  2213. }
  2214. }
  2215. #MICHAEL: can these three lang cat checks be combined?
  2216. # skip the first category specification if it's a language specific one.
  2217. if (grep($_ eq $cat[0], @lang_cat)) {
  2218. $has_lang_cat = 1;
  2219. $port_lang = $lang_pref{$cat[0]};
  2220. shift @cat;
  2221. }
  2222. # skip further if more language specific ones follow.
  2223. if (@cat && grep($_ eq $cat[0], @lang_cat)) {
  2224. &perror("WARN", $file, -1, "multiple language specific categories detected. ".
  2225. "are you sure?");
  2226. do {
  2227. shift @cat;
  2228. } while (@cat && grep($_ eq $cat[0], @lang_cat));
  2229. }
  2230. # check x11 in CATEGORIES
  2231. if ($newxdef) {
  2232. #MICHAEL: I don't understand this line
  2233. if (2 <= @cat && $cat[1] eq "x11") {
  2234. &perror("WARN", $file, -1, "only specific kind of apps should ".
  2235. "specify \"x11\" in CATEGORIES. ".
  2236. "Do you mean just USE_XORG? ".
  2237. "Then remove \"x11\" from CATEGORIES.");
  2238. }
  2239. }
  2240. if (2 <= @cat) {
  2241. # skip the first one that we know is _not_ language specific.
  2242. shift @cat;
  2243. # any language specific one after non language specific ones?
  2244. foreach my $cat (@cat) {
  2245. if (grep($_ eq $cat, @lang_cat)) {
  2246. $has_lang_cat = 1;
  2247. $port_lang = $lang_pref{$cat};
  2248. &perror("WARN", $file, -1, "when you specify multiple categories, ".
  2249. "language specific category should come first.");
  2250. }
  2251. }
  2252. }
  2253. # check number of MASTER_SITES
  2254. if ($makevar{MASTER_SITES} ne '' &&
  2255. ! grep {$makevar{MASTER_SITES} =~ m|$_|} @MASTERSITES_WHITELIST) {
  2256. my @sites = split(/\s+/, $makevar{MASTER_SITES});
  2257. if (scalar(@sites) == 1) {
  2258. &perror("WARN", $file, -1, "only one MASTER_SITE configured. ".
  2259. "Consider adding additional mirrors.");
  2260. }
  2261. }
  2262. # check the URL
  2263. if (($tmp =~ /\nMASTER_SITES[+?]?=[ \t]*([^\n]*)\n/
  2264. && $1 !~ /^[ \t]*$/) || ($makevar{MASTER_SITES} ne '')) {
  2265. print "OK: seen MASTER_SITES, sanity checking URLs.\n"
  2266. if ($verbose);
  2267. my @sites = split(/\s+/, $1 // '');
  2268. my $skipnext = 0;
  2269. foreach my $i (@sites) {
  2270. if ($skipnext) {
  2271. $skipnext = 0;
  2272. next;
  2273. }
  2274. $skipnext++ if ($i =~ /^#/);
  2275. if ($i =~ m#^\w+://#) {
  2276. &urlcheck($i, $file);
  2277. unless (&is_predefined($i, $file)) {
  2278. print "OK: URL \"$i\" ok.\n"
  2279. if ($verbose);
  2280. }
  2281. } else {
  2282. print "OK: non-URL \"$i\" ok.\n"
  2283. if ($verbose);
  2284. }
  2285. }
  2286. } else {
  2287. &perror("WARN", $file, -1, "no MASTER_SITES found. is it ok?");
  2288. }
  2289. # check DISTFILES and related items.
  2290. $distfiles = $1 if ($tmp =~ /\nDISTFILES[+?]?=[ \t]*([^\n]+)\n/);
  2291. #$portname = $1 if ($tmp =~ /\nPORTNAME[+?]?=[ \t]*([^\n]+)\n/);
  2292. #$portversion = $1 if ($tmp =~ /\nPORTVERSION[+?]?=[ \t]*([^\n]+)\n/);
  2293. $portname = $makevar{PORTNAME};
  2294. $portversion = $makevar{PORTVERSION};
  2295. $distversionprefix = $makevar{DISTVERSIONPREFIX};
  2296. $distversion = $makevar{DISTVERSION};
  2297. $distversionsuffix = $makevar{DISTVERSIONSUFFIX};
  2298. $distname = $1 if ($tmp =~ /\nDISTNAME[+?]?=[ \t]*([^\n]+)\n/);
  2299. $extractsufx = $1 if ($tmp =~ /\nEXTRACT_SUFX[+?]?=[ \t]*([^\n]+)\n/);
  2300. # check bogus EXTRACT_SUFX.
  2301. if ($extractsufx ne '') {
  2302. print "OK: seen EXTRACT_SUFX, checking value.\n" if ($verbose);
  2303. if ($distfiles ne '') {
  2304. &perror("WARN", $file, -1, "no need to define EXTRACT_SUFX if ".
  2305. "DISTFILES is defined.");
  2306. }
  2307. if ($extractsufx eq '.tar.gz') {
  2308. &perror("WARN", $file, -1, "EXTRACT_SUFX is \".tar.gz.\" ".
  2309. "by default. you don't need to specify it.");
  2310. }
  2311. if ($extractsufx eq '.tar.bz2') {
  2312. &perror("WARN", $file, -1, "EXTRACT_SUFX is \".tar.bz2.\" ".
  2313. "You should use USE_BZIP2 instead.");
  2314. }
  2315. if ($extractsufx eq '.zip') {
  2316. &perror("WARN", $file, -1, "EXTRACT_SUFX is \".zip\" ".
  2317. "You should use USE_ZIP instead.");
  2318. }
  2319. } else {
  2320. print "OK: no EXTRACT_SUFX seen, using default value.\n"
  2321. if ($verbose);
  2322. $extractsufx = '.tar.gz';
  2323. }
  2324. print "OK: sanity checking PORTNAME/PORTVERSION/DISTVERSIONPREFIX/DISTVERSION/DISTVERSIONSUFFIX.\n" if ($verbose);
  2325. if ($distname ne '') {
  2326. my $exp_distname = $makevar{DISTNAME};
  2327. if ($exp_distname eq "$portname-$portversion") {
  2328. &perror("WARN", $file, -1, "DISTNAME is \${PORTNAME}-\${PORTVERSION} by ".
  2329. "default, you don't need to define DISTNAME.");
  2330. } else {
  2331. if ($exp_distname eq "$portname-$distversionprefix$distversion$distversionsuffix") {
  2332. &perror("WARN", $file, -1, "DISTNAME is \${PORTNAME}-\${DISTVERSIONPREFIX}\${DISTVERSION}\${DISTVERSIONSUFFIX} by ".
  2333. "default, you don't need to define DISTNAME.");
  2334. }
  2335. }
  2336. if ($distname =~ /PORTREVISION/) {
  2337. &perror("FATAL", $file, -1, "DISTNAME contains a reference to ".
  2338. "PORTREVISION. You should only be using PORTVERSION");
  2339. }
  2340. if ($distname =~ /PORTEPOCH/) {
  2341. &perror("FATAL", $file, -1, "DISTNAME contains a reference to ".
  2342. "PORTEPOCH. You should only be using PORTVERSION");
  2343. }
  2344. }
  2345. if ($portname =~ /^$re_lang_short/) {
  2346. &perror("FATAL", $file, -1, "language prefix is automatically".
  2347. " set by PKGNAMEPREFIX.".
  2348. " you must remove it from PORTNAME.");
  2349. }
  2350. if ($portname =~ /([|<>=! ])/) {
  2351. &perror("FATAL", $file, -1, "PORTNAME contains the illegal character \"$1\".".
  2352. " You should modify \"$portname\".");
  2353. } elsif ($portname =~ /\$[\{\(].+[\}\)]/) {
  2354. &perror("WARN", $file, -1, "using variable in PORTNAME.".
  2355. " consider using PKGNAMEPREFIX and/or PKGNAMESUFFIX.");
  2356. } elsif ($portname =~ /([^\w._@+-])/) {
  2357. &perror("WARN", $file, -1, "using \"$1\" in PORTNAME.".
  2358. " You should modify \"$portname\".");
  2359. } elsif ($portname =~ /-/ && $distname ne '') {
  2360. &perror("WARN", $file, -1, "using hyphen in PORTNAME.".
  2361. " consider using PKGNAMEPREFIX and/or PKGNAMESUFFIX.");
  2362. }
  2363. if ($portversion eq '' && $distversion eq '') {
  2364. &perror("FATAL", $file, -1, "either PORTVERSION or DISTVERSION must be specified");
  2365. }
  2366. if ($portversion =~ /^pl[0-9]*$/
  2367. || $portversion =~ /^[0-9]*[A-Za-z]?[0-9]*(\.[0-9]*[A-Za-z]?[0-9+]*)*$/) {
  2368. print "OK: PORTVERSION \"$portversion\" looks fine.\n" if ($verbose);
  2369. } elsif ($portversion =~ /^[^\-]*\$[{\(].+[\)}][^\-]*$/) {
  2370. &perror("WARN", $file, -1, "using variable, \"$portversion\", as version ".
  2371. "number");
  2372. } elsif ($portversion =~ /([-,_<>=! #*])/) {
  2373. &perror("FATAL", $file, -1, "PORTVERSION must not contain \"$1\". ".
  2374. "You should modify \"$portversion\".");
  2375. } else {
  2376. &perror("FATAL", $file, -1, "PORTVERSION looks illegal. ".
  2377. "You should modify \"$portversion\".");
  2378. }
  2379. $pkg_version = $makevar{PKG_VERSION};
  2380. if ($makevar{CONFLICTS}) {
  2381. print "OK: checking CONFLICTS.\n" if ($verbose);
  2382. foreach my $conflict (split ' ', $makevar{CONFLICTS}) {
  2383. my $selfconflict;
  2384. if ($makevar{PKGINSTALLVER} ne "" &&
  2385. $makevar{PKGINSTALLVER} >= 20040125) {
  2386. $selfconflict = !system($pkg_version, '-T',
  2387. $makevar{PKGNAME}, $conflict);
  2388. } else {
  2389. my $conflictre = $conflict;
  2390. $conflictre =~ s/[.+]/\\$&/g;
  2391. $conflictre =~ s/\*/.*/g;
  2392. $conflictre =~ s/\?/./g;
  2393. $conflictre =~ s/\[!/[^/g;
  2394. $selfconflict = ($makevar{PKGNAME} =~ /^$conflictre$/);
  2395. }
  2396. if ($conflict !~ /(?:[<>=]|[]?*]$)/) {
  2397. &perror("WARN", "", -1, "Conflict \"$conflict\" specified too narrow. ".
  2398. "You should end it with a wildcard (-[0-9]*).");
  2399. } elsif ($conflict !~ /[<>=-][^-]*[0-9][^-]*$/) {
  2400. &perror("WARN", "", -1, "Conflict \"$conflict\" specified too broad. ".
  2401. "You should end it with a version number fragment (-[0-9]*).");
  2402. }
  2403. if ($selfconflict) {
  2404. &perror("FATAL", "", -1, "Package conflicts with itself. ".
  2405. "You should remove \"$conflict\" from CONFLICTS.");
  2406. }
  2407. }
  2408. }
  2409. $versiondir = $ENV{VERSIONDIR} // '/var/db/chkversion';
  2410. $versionfile = "$versiondir/VERSIONS";
  2411. $useindex = !-r "$versionfile";
  2412. $versionfile = "$portsdir/$makevar{INDEXFILE}"
  2413. if $useindex;
  2414. if (-r "$versionfile") {
  2415. print "OK: checking if PORTVERSION is going backwards.\n" if ($verbose);
  2416. open VERSIONS, "<$versionfile";
  2417. while (<VERSIONS>) {
  2418. my($origin, $version) = ('', '');
  2419. chomp;
  2420. next if /^(#|$)/;
  2421. if ($useindex) {
  2422. ($version, $origin) = split /\|/;
  2423. $origin =~ s,^.*/([^/]+/[^/]+)/?$,$1,;
  2424. } else {
  2425. ($origin, $version) = split;
  2426. }
  2427. if ($origin eq $makevar{PKGORIGIN}) {
  2428. my $newversion = $makevar{PKGNAME};
  2429. my $oldversion = $version;
  2430. my $result = '';
  2431. $newversion =~ s/^.*-//;
  2432. $oldversion =~ s/^.*-//;
  2433. $result = `$pkg_version -t '$newversion' '$oldversion'`;
  2434. chomp $result;
  2435. if ($result eq '<') {
  2436. &perror("FATAL", $file, -1, "$makevar{PKGNAME} < $version. ".
  2437. "Choose another PORTVERSION or bump PORTEPOCH.");
  2438. # $backwards{$origin} = "$pkgname{$origin} < $version";
  2439. }
  2440. last;
  2441. }
  2442. }
  2443. close VERSIONS;
  2444. }
  2445. # if DISTFILES have only single item, it is better to avoid DISTFILES
  2446. # and to use combination of DISTNAME and EXTRACT_SUFX.
  2447. # example:
  2448. # DISTFILES=package-1.0.tgz
  2449. # should be
  2450. # DISTNAME= package-1.0
  2451. # EXTRACT_SUFX= .tgz
  2452. if ($distfiles =~ /^\S+$/ && $distfiles !~ /:[^\/:]+$/) {
  2453. $bogusdistfiles++;
  2454. print "OK: seen DISTFILES with single item, checking value.\n"
  2455. if ($verbose);
  2456. &perror("WARN", $file, -1, "use of DISTFILES with single file ".
  2457. "discouraged. distribution filename should be set by ".
  2458. "DISTNAME and EXTRACT_SUFX.");
  2459. if ($distfiles eq (($distname ne '') ? $distname : "$portname-$portversion") . $extractsufx) {
  2460. &perror("WARN", $file, -1, "definition of DISTFILES not necessary. ".
  2461. "DISTFILES is \${DISTNAME}/\${EXTRACT_SUFX} ".
  2462. "by default.");
  2463. }
  2464. # display advice only in certain cases.
  2465. #MICHAEL: will this work with multiple distfiles in this list? what about
  2466. # doing the same sort of thing for DISTNAME, is it needed?
  2467. if ($distfiles =~ /^\Q$i\E([\-.].+)$/) {
  2468. &perror("WARN", $file, -1, "how about \"EXTRACT_SUFX=$1\"".
  2469. ", instead of DISTFILES?");
  2470. }
  2471. }
  2472. # additional checks for committer.
  2473. if ($committer && $has_lang_cat) {
  2474. &perror("WARN", $file, -1, "be sure to include language code ".
  2475. "\"$port_lang-\" ".
  2476. "in the module alias name.");
  2477. }
  2478. if ($committer) {
  2479. if (opendir(DIR, ".")) {
  2480. my @tgz = grep(/\.tgz$/, readdir(DIR));
  2481. closedir(DIR);
  2482. if (@tgz) {
  2483. my $tgz = (2 <= @tgz)
  2484. ? '{' . join(',', @tgz) . '}'
  2485. : $tgz[0];
  2486. &perror("WARN", "", -1, "be sure to remove $portdir/$tgz ".
  2487. "before committing the port.");
  2488. }
  2489. }
  2490. }
  2491. push(@varnames, qw(
  2492. PORTNAME PORTVERSION PORTREVISION PORTEPOCH CATEGORIES MASTER_SITES
  2493. PKGNAMEPREFIX PKGNAMESUFFIX DISTNAME EXTRACT_SUFX
  2494. DISTFILES EXTRACT_ONLY
  2495. ));
  2496. #
  2497. # section 3: PATCH_SITES/PATCHFILES(optional)
  2498. #
  2499. print "OK: checking second section of $file (PATCH*: optional).\n"
  2500. if ($verbose);
  2501. $tmp = $sections[$idx];
  2502. if ($tmp =~ /(PATCH_SITES|PATCH_SITE_SUBDIR|PATCHFILES|PATCH_DIST_STRIP)/) {
  2503. &checkearlier($file, $tmp, @varnames);
  2504. if ($tmp =~ /PATCH_SITES[?+]?=[^\n]+\n/) {
  2505. print "OK: seen PATCH_SITES.\n" if ($verbose);
  2506. $tmp =~ s/PATCH_SITES[?+]?=[^\n]+\n//;
  2507. }
  2508. if ($tmp =~ /PATCH_SITE_SUBDIR[?+]?=[^\n]+\n/) {
  2509. print "OK: seen PATCH_SITE_SUBDIR.\n" if ($verbose);
  2510. $tmp =~ s/PATCH_SITE_SUBDIR[?+]?=[^\n]+\n//;
  2511. }
  2512. if ($tmp =~ /PATCHFILES[?+]?=[^\n]+\n/) {
  2513. print "OK: seen PATCHFILES.\n" if ($verbose);
  2514. $tmp =~ s/PATCHFILES[?+]?=[^\n]+\n//;
  2515. }
  2516. if ($tmp =~ /PATCH_DIST_STRIP[?+]?=[^\n]+\n/) {
  2517. print "OK: seen PATCH_DIST_STRIP.\n" if ($verbose);
  2518. $tmp =~ s/PATCH_DIST_STRIP[?+]?=[^\n]+\n//;
  2519. }
  2520. &checkextra($tmp, 'PATCH_SITES', $file);
  2521. $idx++;
  2522. }
  2523. push(@varnames, qw(
  2524. PATCH_SITES PATCHFILES PATCH_DIST_STRIP
  2525. ));
  2526. #
  2527. # section 4: MAINTAINER
  2528. #
  2529. print "OK: checking third section of $file (MAINTAINER).\n"
  2530. if ($verbose);
  2531. $tmp = $sections[$idx];
  2532. &checkearlier($file, $tmp, @varnames);
  2533. &checkorder('MAINTAINER', $tmp, $file, qw(
  2534. MAINTAINER COMMENT
  2535. ));
  2536. $tmp = "\n" . $tmp;
  2537. if ($tmp =~ /\nMAINTAINER(\?)?=([^\n]+)/) {
  2538. my $addr = $2;
  2539. if (defined $1 && $1 ne '') {
  2540. &perror("WARN", $file, -1, "unless this is a master port, ".
  2541. "MAINTAINER has to be set by \"=\", ".
  2542. "not by \"$1=\".") unless ($masterport);
  2543. }
  2544. $addr =~ s/^\s*//;
  2545. $addr =~ s/\s*$//;
  2546. if ($addr =~ /[\s,<>()]/) {
  2547. &perror("FATAL", $file, -1, "MAINTAINER should be a single address without comment.");
  2548. }
  2549. if ($addr !~ /^[^\@]+\@[\w\d\-\.]+$/) {
  2550. &perror("FATAL", $file, -1, "MAINTAINER address, $addr, does not appear to be a valid email address.");
  2551. }
  2552. if ($newport && $addr =~ /ports\@freebsd.org/i) {
  2553. &perror("WARN", $file, -1, "new ports should not be maintained by ".
  2554. "ports\@FreeBSD.org.");
  2555. }
  2556. $tmp =~ s/\nMAINTAINER\??=[^\n]+//;
  2557. } elsif ($whole !~ /\nMAINTAINER[?]?=/) {
  2558. &perror("FATAL", $file, -1, "no MAINTAINER listed.") unless ($makevar{MAINTAINER} ne '');
  2559. if (!$slaveport && $makevar{MAINTAINER} ne '') {
  2560. &perror("WARN", $file, -1, "MAINTAINER is set externally to this port's Makefile, but this port is not configured as a slave port.");
  2561. }
  2562. }
  2563. $tmp =~ s/\n\n+/\n/g;
  2564. # check COMMENT
  2565. if ($tmp !~ /\nCOMMENT(.)?=/) {
  2566. &perror("FATAL", $file, -1, "COMMENT has to be there.") unless ($makevar{COMMENT} ne '');
  2567. if (!$slaveport && $makevar{COMMENT} ne '') {
  2568. &perror("WARN", $file, -1, "COMMENT is set externally to this port's Makefile, but this port is not configured as a slave port.");
  2569. }
  2570. } elsif (defined $1 && $1 ne '') {
  2571. &perror("WARN", $file, -1, "unless this is a master port, COMMENT has to be set by \"=\", ".
  2572. "not by \"$1=\".") unless ($masterport);
  2573. } else { # check for correctness
  2574. if (($makevar{COMMENT} !~ /^["\[0-9A-Z]/) || ($makevar{COMMENT} =~ m/\.$/)) { #"
  2575. &perror("WARN", $file, -1, "COMMENT should begin with a capital, and end without a period");
  2576. } elsif (length($makevar{COMMENT}) > 70) {
  2577. &perror("WARN", $file, -1, "COMMENT exceeds 70 characters limit.");
  2578. }
  2579. }
  2580. $idx++;
  2581. push(@varnames, qw(
  2582. MAINTAINER COMMENT
  2583. ));
  2584. #
  2585. # section 5: LICENSE
  2586. #
  2587. print "OK: checking fourth section of $file (LICENSE).\n"
  2588. if ($verbose);
  2589. $tmp = $sections[$idx];
  2590. if ($makevar{LICENSE}) {
  2591. &checkorder('LICENSE', $tmp, $file, qw(
  2592. LICENSE LICENSE_COMB LICENSE_GROUPS(_\w+)? LICENSE_NAME(_\w+)?
  2593. LICENSE_TEXT(_\w+)? LICENSE_FILE(_\w+)? LICENSE_PERMS(_\w+)?
  2594. LICENSE_DISTFILES(_\w+)?
  2595. ));
  2596. # check LICENSE
  2597. if ($makevar{LICENSE} && $makevar{LICENSE} ne '') {
  2598. my $comb = $makevar{LICENSE_COMB} // 'single';
  2599. my @tokens = split(/ /, $makevar{LICENSE});
  2600. if ($comb eq 'single' && scalar(@tokens) > 1) {
  2601. &perror("FATAL", $file, -1, "LICENSE contains multiple licenses but LICENSE_COMB is not set to 'dual' or 'multi'");
  2602. }
  2603. }
  2604. # check value of LICENSE_COMB
  2605. if ($makevar{LICENSE_COMB} && $makevar{LICENSE_COMB} !~ /^(single|dual|multi$)/) {
  2606. &perror("FATAL", $file, -1, "LICENSE_COMB contains invalid value '$1' - must be one of 'single', 'dual', 'multi'");
  2607. }
  2608. $idx++;
  2609. push(@varnames, qw(
  2610. LICENSE LICENSE_COMB LICENSE_GROUPS LICENSE_NAME
  2611. LICENSE_TEXT LICENSE_FILE LICENSE_PERMS
  2612. ));
  2613. }
  2614. #
  2615. # section 6: *_DEPENDS (may not be there)
  2616. #
  2617. print "OK: checking fifth section of $file (*_DEPENDS).\n"
  2618. if ($verbose);
  2619. $tmp = $sections[$idx];
  2620. # Check for direct assignment of BUILD_DEPENDS to RUN_DEPENDS.
  2621. if ($tmp =~ /\nRUN_DEPENDS=[ \t]*\${BUILD_DEPENDS}/) {
  2622. &perror("FATAL", $file, -1, "RUN_DEPENDS should not be set to ".
  2623. "\${BUILD_DEPENDS} as \${BUILD_DEPENDS} includes other ".
  2624. "implicit dependencies. Instead, copy the explicit dependencies ".
  2625. "from BUILD_DEPENDS to RUN_DEPENDS. See ".
  2626. "http://www.freebsd.org/doc/en_US.ISO8859-1/books/porters-handbook/makefile-depend.html#AEN2154 ".
  2627. "for more details.");
  2628. }
  2629. # NOTE: EXEC_DEPENDS is obsolete, so it should not be listed.
  2630. @linestocheck = qw(
  2631. EXTRACT_DEPENDS LIB_DEPENDS PATCH_DEPENDS BUILD_DEPENDS RUN_DEPENDS
  2632. TEST_DEPENDS FETCH_DEPENDS DEPENDS_TARGET
  2633. );
  2634. if ($tmp =~ /^(PATCH_|EXTRACT_|LIB_|BUILD_|RUN_|TEST_|FETCH_)DEPENDS/m) {
  2635. &checkearlier($file, $tmp, @varnames);
  2636. check_depends_syntax($tmp, $file);
  2637. foreach my $i (@linestocheck) {
  2638. $tmp =~ s/$i[?+:]?=[^\n]+\n//g;
  2639. }
  2640. &checkextra($tmp, '*_DEPENDS', $file);
  2641. $idx++;
  2642. }
  2643. push(@varnames, @linestocheck);
  2644. &checkearlier($file, $tmp, @varnames);
  2645. #
  2646. # Makefile 7: check the rest of file
  2647. #
  2648. print "OK: checking the rest of the $file.\n" if ($verbose);
  2649. $tmp = join("\n\n", @sections[$idx .. scalar(@sections)-1]);
  2650. $tmp = "\n" . $tmp; # to make the begin-of-line check easier
  2651. &checkearlier($file, $tmp, @varnames);
  2652. # Check depends that might be specified based on the WITH_/WITHOUT_
  2653. # arguments and other external variables.
  2654. check_depends_syntax($tmp, $file);
  2655. # check WRKSRC/NO_WRKSUBDIR
  2656. #
  2657. # do not use DISTFILES/DISTNAME to control over WRKSRC.
  2658. # DISTNAME is for controlling distribution filename.
  2659. # example:
  2660. # DISTNAME= package
  2661. # DISTFILES=package-1.0.tgz
  2662. # should be
  2663. # DISTNAME= package-1.0
  2664. # EXTRACT_SUFX=.tgz
  2665. # WRKSRC= ${WRKDIR}/package
  2666. #
  2667. print "OK: checking WRKSRC.\n" if ($verbose);
  2668. $wrksrc = $nowrksubdir = '';
  2669. $wrksrc = $1 if ($tmp =~ /\nWRKSRC[+?]?=[ \t]*([^\n]*)\n/);
  2670. $nowrksubdir = $1 if ($tmp =~ /\nNO_WRKSUBDIR[+?]?=[ \t]*([^\n]*)\n/);
  2671. if ($nowrksubdir eq '') {
  2672. $realwrksrc = $wrksrc ? "$wrksrc/$distname"
  2673. : "\${WRKDIR}/$distname";
  2674. } else {
  2675. $realwrksrc = $wrksrc ? $wrksrc : '${WRKDIR}';
  2676. }
  2677. print "OK: WRKSRC seems to be $realwrksrc.\n" if ($verbose);
  2678. if ($nowrksubdir eq '') {
  2679. print "OK: no NO_WRKSUBDIR, checking value of WRKSRC.\n"
  2680. if ($verbose);
  2681. if ($wrksrc eq 'work' || $wrksrc =~ /^$[\{\(]WRKDIR[\}\)]/) {
  2682. &perror("WARN", $file, -1, "WRKSRC is set to meaningless value ".
  2683. "\"$1\".".
  2684. ($nowrksubdir eq ''
  2685. ? " use \"NO_WRKSUBDIR=yes\" instead."
  2686. : ""));
  2687. }
  2688. if ($bogusdistfiles) {
  2689. if ($distname ne '' && $wrksrc eq '') {
  2690. &perror("WARN", $file, -1, "do not use DISTFILES and DISTNAME ".
  2691. "to control WRKSRC. how about ".
  2692. "\"WRKSRC=\${WRKDIR}/$distname\"?");
  2693. } else {
  2694. &perror("WARN", $file, -1, "DISTFILES/DISTNAME affects WRKSRC. ".
  2695. "take caution when changing them.");
  2696. }
  2697. }
  2698. } else {
  2699. print "OK: seen NO_WRKSUBDIR, checking value of WRKSRC.\n"
  2700. if ($verbose);
  2701. if ($wrksrc eq 'work' || $wrksrc =~ /^$[\{\(]WRKDIR[\}\)]/) {
  2702. &perror("WARN", $file, -1, "definition of WRKSRC not necessary. ".
  2703. "WRKSRC is \${WRKDIR} by default.");
  2704. }
  2705. }
  2706. # check RESTRICTED/NO_CDROM/NO_PACKAGE
  2707. print "OK: checking RESTRICTED/NO_CDROM/NO_PACKAGE.\n" if ($verbose);
  2708. if ($committer && $tmp =~ /\n(RESTRICTED|NO_CDROM|NO_PACKAGE)[+?]?=/) {
  2709. &perror("WARN", $file, -1, "\"$1\" found. do not forget to update ".
  2710. "ports/LEGAL.");
  2711. }
  2712. # check NO_CONFIGURE/NO_PATCH
  2713. print "OK: checking NO_CONFIGURE/NO_PATCH.\n" if ($verbose);
  2714. if ($tmp =~ /\n(NO_CONFIGURE|NO_PATCH)[+?]?=/) {
  2715. &perror("FATAL", $file, -1, "\"$1\" was obsoleted. remove this.");
  2716. }
  2717. # check MAN[1-9LN]
  2718. print "OK: checking MAN[0-9LN].\n" if ($verbose);
  2719. foreach my $i (keys %plistmanall) {
  2720. print "OK: pkg-plist MAN$i=$plistmanall{$i}\n" if ($verbose);
  2721. }
  2722. if ($tmp =~ /PERL_CONFIGURE=\s*/
  2723. && $tmp =~ /^MAN3PREFIX=\s*\${PREFIX}\/lib\/perl5\/\${PERL_VERSION}/) {
  2724. &perror("WARN", $file, -1, "MAN3PREFIX is ".
  2725. "\"\${PREFIX}/lib/perl5/\${PERL_VERSION}\" ".
  2726. "when PERL_CONFIGURE is set. You do not need to specify it.");
  2727. }
  2728. foreach my $i (split(//, $manchapters)) {
  2729. if ($tmp =~ /^MAN\U$i\E=\s*([^\n]*)\n/) {
  2730. print "OK: Makefile MAN\U$i\E=$1\n" if ($verbose);
  2731. }
  2732. }
  2733. foreach my $i (split(//, $manchapters)) {
  2734. next if ($i eq '');
  2735. my @mansecs = grep(/^MAN\U$i\E=\s*(.*)/, split(/\n/, $tmp));
  2736. if (scalar @mansecs > 1) {
  2737. &perror("FATAL", $file, -1, "duplicate MAN$i macro. ".
  2738. "Only the last MAN$i macro will be processed. Use ".
  2739. "MAN$i+=... instead to append man pages.");
  2740. }
  2741. if ($tmp =~ /^MAN\U$i\E=\s*([^\n]*)\n/) {
  2742. @mman = grep($_ !~ /^\s*$/, split(/\s+/, $1));
  2743. @pman = grep($_ !~ /^\s*$/,
  2744. split(/\s+/, $plistmanall{$i} // ''));
  2745. foreach my $j (@mman) {
  2746. print "OK: checking $j (Makefile)\n"
  2747. if ($verbose);
  2748. if ($automan && grep($_ eq $j, @pman)) {
  2749. &perror("FATAL", $file, -1, "duplicated manpage ".
  2750. "entry $j: content of ".
  2751. "MAN\U$i\E will be automatically ".
  2752. "added to pkg-plist.");
  2753. } elsif (!$automan && !grep($_ eq $j, @pman)) {
  2754. &perror("WARN", $file, -1, "manpage $j ".
  2755. "MAN\U$i\E but not in pkg-plist.");
  2756. }
  2757. }
  2758. foreach my $j (@pman) {
  2759. print "OK: checking $j (pkg-plist)\n" if ($verbose);
  2760. if (!grep($_ eq $j, @mman)) {
  2761. &perror("WARN", $file, -1, "manpage $j in pkg-plist ".
  2762. "but not in MAN\U$i\E.");
  2763. }
  2764. }
  2765. } else {
  2766. if ($plistmanall{$i}) {
  2767. if ($manstrict) {
  2768. &perror("FATAL", $file, -1, "manpage for chapter ".
  2769. "$i must be listed in ".
  2770. "MAN\U$i\E. ");
  2771. } else {
  2772. &perror("WARN", $file, -1, "manpage for chapter ".
  2773. "$i should be listed in ".
  2774. "MAN\U$i\E, ".
  2775. "even if compression is ".
  2776. "not necessary.");
  2777. }
  2778. }
  2779. if ($mancompress && $plistman{$i}) {
  2780. &perror("WARN", $file, -1, "MAN\U$i\E will help you ".
  2781. "compressing manual page in chapter ".
  2782. "\"$i\".");
  2783. } elsif (!$mancompress && $plistmangz{$i}) {
  2784. &perror("WARN", $file, -1, "MAN\U$i\E will help you ".
  2785. "uncompressing manual page in chapter ".
  2786. "\"$i\".");
  2787. }
  2788. }
  2789. }
  2790. if ($tmp !~ /MANLANG/ && scalar(keys %manlangs)) {
  2791. $i = (keys %manlangs)[0];
  2792. &perror("WARN", $file, -1, "how about using MANLANG for ".
  2793. "designating manual language, such as \"$i\"?");
  2794. }
  2795. # check INFO
  2796. print "OK: checking INFO.\n" if ($verbose);
  2797. if ($autoinfo && $tmp =~ /\nINFO=\s*([^\n]*)\n/) {
  2798. my @minfo = grep($_ !~ /^\s*$/, split(/\s+/, $1));
  2799. if ($tmp =~ /[\/|\s]install-info\s/) {
  2800. &perror("FATAL", $file, -1, "install-info is automatically run ".
  2801. "when INFO is defined.");
  2802. }
  2803. foreach $i (@minfo) {
  2804. if ($i =~ /\.info(-\d+)?$/) {
  2805. &perror("FATAL", $file, -1, "do not include the .info extension ".
  2806. "on files listed in the INFO macro.");
  2807. }
  2808. }
  2809. } elsif ($autoinfo && $tmp =~ /[\/|\s]install-info\s/) {
  2810. &perror("WARN", $file, -1, "do not call install-info directly. Use the ".
  2811. "INFO macro instead.");
  2812. }
  2813. # check for HAS_CONFIGURE or GNU_CONFIGURE
  2814. if ($tmp =~ /\nGNU_CONFIGURE[?+]?=/
  2815. && $tmp =~ /\n(HAS_CONFIGURE)[?+]?=/) {
  2816. &perror("WARN", $file, -1, "since you already have GNU_CONFIGURE, ".
  2817. "you do not need $1.");
  2818. }
  2819. # check direct use of important make targets.
  2820. if ($tmp =~ /\n(fetch|extract|patch|configure|build|install):/) {
  2821. &perror("FATAL", $file, -1, "direct redefinition of make target \"$1\" ".
  2822. "discouraged. redefine \"do-$1\" instead.");
  2823. }
  2824. # check for incorrect use of the pre-everything target.
  2825. if ($tmp =~ /\npre-everything:[^:]/) {
  2826. &perror("FATAL", $file, -1, "use pre-everything:: instead of pre-everything:");
  2827. }
  2828. if ($tmp =~ /^pre-patch:/m && $use_gnome_hack) {
  2829. &perror("FATAL", $file, -1, "pre-patch target overwrites gnomehack component. ".
  2830. "use post-patch instead.");
  2831. }
  2832. if ($tmp =~ /^do-build:/m && $use_ant) {
  2833. &perror("WARN", $file, -1, "USE_ANT is intended only for ports that ".
  2834. "build with Ant. It is recommended not to override the default ".
  2835. "'do-build:' target when defining USE_ANT");
  2836. }
  2837. #
  2838. # check for deprecated use of USE_RC_SUBR, and current syntax
  2839. #
  2840. if ($tmp =~ /\nUSE_RC_SUBR=([\s]*)(.*)/) {
  2841. my $subr_value = $makevar{USE_RC_SUBR};
  2842. if ($subr_value eq '') {
  2843. $subr_value = $2;
  2844. }
  2845. if (($subr_value =~ /^yes$/i) ||
  2846. ($subr_value =~ /^true$/i) ||
  2847. ($subr_value =~ /^1$/)) {
  2848. &perror("FATAL", $file, -1, "The value of the USE_RC_SUBR variable ".
  2849. "should be the name of the intended rc.d script, and there ".
  2850. "should be a corresponding file in the files/ directory.");
  2851. } else {
  2852. foreach my $i (split(/\s/, $subr_value)) {
  2853. my $mvar;
  2854. if ($i =~ /\$\{([^}]+)\}/) {
  2855. $mvar = $1;
  2856. if (defined($makevar{$mvar})) {
  2857. $i = $makevar{$mvar};
  2858. } else {
  2859. $i = &getMakevar($mvar);
  2860. }
  2861. }
  2862. if ($i ne '' && ! -f "files/$i.in") {
  2863. &perror("FATAL", $file, -1, "$i listed in USE_RC_SUBR, ".
  2864. "but files/$i.in is missing.");
  2865. } elsif ($i eq '' && $mvar ne '') {
  2866. &perror("WARN", $file, -1, "possible undefined make variable ".
  2867. "$mvar used as the value for USE_RC_SUBR.");
  2868. }
  2869. }
  2870. }
  2871. }
  2872. 1;
  2873. }
  2874. sub perror($$$$) {
  2875. my($type, $file, $line, $msg) = @_;
  2876. if ($type eq 'FATAL') {
  2877. $err++;
  2878. } else {
  2879. $warn++;
  2880. }
  2881. if ($grouperrs) {
  2882. $msg = '%%LINES%%' . $msg;
  2883. if ($file ne "") {
  2884. $msg = $file . ": " . $msg;
  2885. }
  2886. $msg = $type . ": " . $msg;
  2887. if (!$errcache{$msg}) {
  2888. push @errlst, $msg;
  2889. }
  2890. if ($line > -1) {
  2891. push @{$errcache{$msg}}, $line;
  2892. }
  2893. } else {
  2894. if ($line > -1) {
  2895. $msg = "[$line]: " . $msg;
  2896. }
  2897. if ($file ne "") {
  2898. $msg = $file . ": " . $msg;
  2899. }
  2900. $msg = $type . ": " . $msg;
  2901. print $msg . "\n";
  2902. }
  2903. }
  2904. sub checkextra {
  2905. my($str, $section, $file) = @_;
  2906. $str = "\n" . $str if ($str !~ /^\n/);
  2907. $str =~ s/\n#[^\n]*/\n/g;
  2908. $str =~ s/\n\.[^\n]+/\n/g;
  2909. $str =~ s/\n\n+/\n/g;
  2910. $str =~ s/^\s+//;
  2911. $str =~ s/\s+$//;
  2912. return if ($str eq '');
  2913. if ($str =~ /^([\w\d]+)/) {
  2914. &perror("WARN", $file, -1, "extra item placed in the ".
  2915. "$section section, ".
  2916. "for example, \"$1\".");
  2917. } else {
  2918. &perror("WARN", $file, -1, "extra item placed in the ".
  2919. "$section section.");
  2920. }
  2921. }
  2922. sub checkorder {
  2923. my($section, $str, $file, @order) = @_;
  2924. my(@items, $i, $j, $k, $invalidorder);
  2925. print "OK: checking the order of $section section.\n" if ($verbose);
  2926. @items = ();
  2927. foreach my $i (split("\n", $str)) {
  2928. $i =~ s/[+?]?=.*$//;
  2929. push(@items, $i);
  2930. }
  2931. @items = reverse(@items);
  2932. $j = -1;
  2933. $invalidorder = 0;
  2934. while (scalar(@items)) {
  2935. $i = pop(@items);
  2936. $k = 0;
  2937. while ($k < scalar(@order) && $order[$k] ne $i) {
  2938. if (defined $order[$k] &&
  2939. $order[$k] =~ /[\.\*\+\?\{\}\[\]\^\$\|]/ &&
  2940. $i =~ /$order[$k]/) {
  2941. last;
  2942. }
  2943. $k++;
  2944. }
  2945. if (defined $order[$k] && $order[$k] =~ /[\.\*\+\?\{\}\[\]\^\$\|]/ &&
  2946. $i =~ /$order[$k]/) {
  2947. if ($k < $j) {
  2948. &perror("FATAL", $file, -1, "$i appears out-of-order.");
  2949. $invalidorder++;
  2950. } else {
  2951. print "OK: seen $i, in order.\n" if ($verbose);
  2952. }
  2953. $j = $k;
  2954. } elsif (defined $order[$k] && $order[$k] eq $i) {
  2955. if ($k < $j) {
  2956. &perror("FATAL", $file, -1, "$i appears out-of-order.");
  2957. $invalidorder++;
  2958. } else {
  2959. print "OK: seen $i, in order.\n" if ($verbose);
  2960. }
  2961. $j = $k;
  2962. # This if condition tests for .if, .else (in all forms),
  2963. # .for and .endfor and .include
  2964. } elsif ($i !~ m/^\.(if|el|endif|for|endfor|include)/) {
  2965. &perror("FATAL", $file, -1, "extra item \"$i\" placed in the ".
  2966. "$section section.");
  2967. }
  2968. }
  2969. if ($invalidorder) {
  2970. &perror("FATAL", $file, -1, "order must be " . join('/', @order) . '.');
  2971. } else {
  2972. print "OK: $section section is ordered properly.\n"
  2973. if ($verbose);
  2974. }
  2975. }
  2976. sub checkearlier {
  2977. my($file, $str, @varnames) = @_;
  2978. my($i);
  2979. print "OK: checking items that has to appear earlier.\n" if ($verbose);
  2980. foreach my $i (@varnames) {
  2981. if ($str =~ /\n$i\??=/) {
  2982. &perror("WARN", $file, -1, "\"$i\" has to appear earlier.");
  2983. }
  2984. }
  2985. }
  2986. sub linenumber {
  2987. my $text = shift;
  2988. my @lines;
  2989. @lines = split /\n/, $text;
  2990. return scalar(@lines);
  2991. }
  2992. sub abspathname {
  2993. my($str, $file) = @_;
  2994. my($s, $i, %cmdnames);
  2995. my($pre);
  2996. # trim all trailing backslash and newline
  2997. $str =~ s/\\\n\s*/ /g;
  2998. # ignore parameter string to reinplace command
  2999. $str =~ s/([ \t][\@-]?(?:sed|\$[\{\(]SED[\}\)]|\$[\{\(]REINPLACE_CMD[\}\)]))((?:\s+\-\w+)*\s+(?:"(?:\\"|[^"\n])*"|'(?:\\'|[^'\n])*'))+(.*)/$1$3/g; #'
  3000. # ignore parameter string to echo command
  3001. # XXX: This next pattern crashes Perl 5.8.7.
  3002. #$str =~ s/[ \t][\@-]?(echo|\$[\{\(]ECHO[\}\)]|\$[\{\(]ECHO_MSG[\}\)])[ \t]+("(\\'|\\"|[^"])*"|'(\\'|\\"|[^"])*')[ \t]*[;\n]//; #'
  3003. $str =~ s/[ \t][\@-]?(echo|\$[\{\(]ECHO[\}\)]|\$[\{\(]ECHO_MSG[\}\)])[ \t]+.*(;|$)//m; #'
  3004. print "OK: checking direct use of full pathnames in $file.\n"
  3005. if ($verbose);
  3006. foreach my $s (split(/\n+/, $str)) {
  3007. $i = '';
  3008. $s =~ s/#.*$//;
  3009. if ($s =~ /(^|[ \t\@'"-])(\/[\w\d])/) { #'
  3010. # suspected pathnames are recorded.
  3011. $i = $2 . $';
  3012. $pre = $` . $1;
  3013. if ($pre =~ /MASTER_SITE_SUBDIR/) {
  3014. # MASTER_SITE_SUBDIR lines are ok.
  3015. $i = '';
  3016. }
  3017. }
  3018. if ($i ne '' && ! grep {$i =~ m|^$_|} @ALLOWED_FULL_PATHS) {
  3019. $i =~ s/\s.*$//;
  3020. $i =~ s/['"].*$//; #'
  3021. $i = substr($i, 0, 20) . '...' if (20 < length($i));
  3022. &perror("WARN", $file, -1, "possible use of absolute pathname ".
  3023. "\"$i\".");
  3024. }
  3025. }
  3026. print "OK: checking direct use of pathnames, phase 1.\n" if ($verbose);
  3027. %cmdnames = split(/\n|\t+/, <<EOF);
  3028. /usr/opt \${PORTSDIR} instead
  3029. $portsdir \${PORTSDIR} instead
  3030. $localbase \${PREFIX} or \${LOCALBASE}, as appropriate
  3031. EOF
  3032. foreach my $i (keys %cmdnames) {
  3033. if ($str =~ /$i/) {
  3034. &perror("WARN", $file, -1, "possible direct use of \"$&\" ".
  3035. "found. if so, use $cmdnames{$i}.");
  3036. }
  3037. }
  3038. print "OK: checking direct use of pathnames, phase 2.\n" if ($verbose);
  3039. %cmdnames = split(/\n|\t+/, <<EOF);
  3040. distfiles \${DISTDIR} instead
  3041. pkg \${PKGDIR} instead
  3042. files \${FILESDIR} instead
  3043. scripts \${SCRIPTDIR} instead
  3044. patches \${PATCHDIR} instead
  3045. work \${WRKDIR} instead
  3046. EOF
  3047. foreach my $i (keys %cmdnames) {
  3048. if ($str =~ /(\.\/|\$[\{\(]\.CURDIR[\}\)]\/|[ \t])(\b$i)\//) {
  3049. &perror("WARN", $file, -1, "possible direct use of \"$i\" ".
  3050. "found. if so, use $cmdnames{$i}.");
  3051. }
  3052. }
  3053. }
  3054. sub get_makevar {
  3055. my($mvar) = @_;
  3056. my($cmd, $result);
  3057. $cmd = join(' -V ', "make $makeenv MASTER_SITE_BACKUP=''", $mvar);
  3058. $result = `$cmd`;
  3059. return chomp $result;
  3060. }
  3061. sub is_predefined {
  3062. my($url, $file) = @_;
  3063. my($site, $site_re);
  3064. my $subdir_re = quotemeta quotemeta '/%SUBDIR%/';
  3065. for my $site (keys %predefined) {
  3066. $site_re = quotemeta $site;
  3067. $site_re =~ s,$subdir_re,/(.*)/,;
  3068. if ($url =~ /$site_re/) {
  3069. &perror("WARN", $file, -1, "how about using ".
  3070. "\"\${MASTER_SITE_$predefined{$site}}\" with ".
  3071. "\"MASTER_SITE_SUBDIR=$1\", instead of \"$url\"?");
  3072. return &TRUE;
  3073. }
  3074. }
  3075. undef;
  3076. }
  3077. sub urlcheck {
  3078. my ($url, $file) = @_;
  3079. if ($url !~ m#^\w+://#) {
  3080. &perror("WARN", $file, -1, "\"$url\" doesn't appear to be a URL to me.");
  3081. }
  3082. if ($url !~ m#/(:[^/:]+)?$#) {
  3083. &perror("FATAL", $file, -1, "URL \"$url\" should ".
  3084. "end with \"/\" or a group name (e.g. :something).");
  3085. }
  3086. if ($url =~ m#://[^/]*:/#) {
  3087. &perror("FATAL", $file, -1, "URL \"$url\" contains ".
  3088. "extra \":\".");
  3089. }
  3090. if ($osname eq 'FreeBSD' && $url =~ m#(www\.freebsd\.org)/~.+/#i) {
  3091. &perror("WARN", $file, -1, "URL \"$url\", ".
  3092. "$1 should be ".
  3093. "people.FreeBSD.org");
  3094. }
  3095. }
  3096. sub TRUE {1;}
  3097. # Local variables:
  3098. # tab-width: 4
  3099. # End: