portlint.pl 117 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996
  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 non-FreeBSD code
  15. # was removed.
  16. #
  17. # $MCom$
  18. #
  19. use strict;
  20. use warnings;
  21. BEGIN { $ENV{ NO_COLOR } = 1 if not -t STDOUT; }
  22. use Getopt::Std;
  23. use File::Find;
  24. use IPC::Open2;
  25. use File::Basename;
  26. use Term::ANSIColor qw(:constants);
  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);
  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/fstab /etc/inetd.conf /proc);
  44. # version variables
  45. my $major = 2;
  46. my $minor = 22;
  47. my $micro = 1;
  48. # default setting - for FreeBSD
  49. my $portsdir = '/usr/ports';
  50. my $rcsidstr = 'FreeBSD';
  51. my $localbase = '/usr/local';
  52. my $numpitems = 6;
  53. my %lang_pref = qw(
  54. arabic ar
  55. chinese zh
  56. french fr
  57. german de
  58. hebrew iw
  59. hungarian hu
  60. japanese ja
  61. korean ko
  62. polish pl
  63. portuguese pt
  64. russian ru
  65. ukrainian uk
  66. vietnamese vi
  67. );
  68. my @lang_cat = keys %lang_pref;
  69. my @lang_short = values %lang_pref;
  70. my $re_lang_short = '(' . join('|', @lang_short) . ')-';
  71. my ($prog) = ($0 =~ /([^\/]+)$/);
  72. sub usage {
  73. print STDERR <<EOF;
  74. usage: $prog [-AabCcghmvtN] [-M ENV] [-B#] [port_directory]
  75. -a additional check for scripts/* and pkg-*
  76. -A turn on all additional checks (equivalent to -abcmNt)
  77. -b warn \$(VARIABLE)
  78. -c committer mode (implies -m)
  79. -C pedantic committer mode (equivalent to -abcmt)
  80. -g group errors together to avoid duplication (disabled if -v is specified)
  81. -h show summary of command line options
  82. -v verbose mode
  83. -t nit pick about use of spaces
  84. -m check \${PORTSDIR}/MOVED, UIDs, and GIDs files
  85. -N writing a new port
  86. -V print the version and exit
  87. -M ENV set make variables to ENV (ex. PORTSDIR=/usr/ports.work)
  88. -B# allow # contiguous blank lines (default: $contblank line)
  89. EOF
  90. exit 0;
  91. }
  92. sub version {
  93. print "$prog version $major.$minor.$micro\n";
  94. exit $major;
  95. }
  96. getopts('AabCcghmtvB:M:NV');
  97. &usage if $opt_h;
  98. &version if $opt_V;
  99. $extrafile = 1 if $opt_a || $opt_A || $opt_C;
  100. $parenwarn = 1 if $opt_b || $opt_A || $opt_C;
  101. $committer = 1 if $opt_c || $opt_A || $opt_C;
  102. $verbose = 1 if $opt_v;
  103. $grouperrs = 1 if $opt_g && !$opt_v;
  104. $checkmfiles = 1 if $opt_m || $opt_c || $opt_A || $opt_C;
  105. $newport = 1 if $opt_N || $opt_A;
  106. $usetabs = 1 if $opt_t || $opt_A || $opt_C;
  107. $contblank = $opt_B if $opt_B;
  108. $makeenv = $opt_M if $opt_M;
  109. $portdir = $ARGV[0] ? $ARGV[0] : '.';
  110. # The PORTSDIR environment variable overrides our defaults.
  111. # And if PORTSDIR is defined in /etc/make.conf, that will
  112. # be checked next.
  113. if (defined $ENV{'PORTSDIR'}) {
  114. $portsdir = $ENV{PORTSDIR};
  115. } else {
  116. my $mconf_portsdir = &get_makeconf_var('PORTSDIR');
  117. if ($mconf_portsdir ne '') {
  118. $portsdir = $mconf_portsdir;
  119. }
  120. }
  121. $ENV{'PL_GIT_IGNORE'} //= '';
  122. my $mfile_moved = "${portsdir}/MOVED";
  123. my $mfile_uids = "${portsdir}/UIDs";
  124. my $mfile_gids = "${portsdir}/GIDs";
  125. if ($verbose) {
  126. print "OK: config: portsdir: \"$portsdir\" ".
  127. "localbase: $localbase ".
  128. "\n";
  129. }
  130. #
  131. # just for safety.
  132. #
  133. if (! -d $portdir) {
  134. print STDERR "FATAL: invalid directory $portdir specified.\n";
  135. exit 1;
  136. }
  137. chdir "$portdir" || die "$portdir: $!";
  138. # get make vars
  139. my @varlist = qw(
  140. PORTNAME PORTVERSION PORTREVISION PORTEPOCH PKGNAME PKGBASE
  141. PKGNAMEPREFIX PKGNAMESUFFIX DISTVERSIONPREFIX DISTVERSION
  142. DISTVERSIONSUFFIX DISTNAME DISTFILES CATEGORIES MASTERDIR MAINTAINER
  143. MASTER_SITES WRKDIR WRKSRC NO_WRKSUBDIR SCRIPTDIR FILESDIR
  144. PKGDIR COMMENT WWW DESCR PLIST PKGCATEGORY PKGINSTALL PKGDEINSTALL
  145. PKGREQ PKGMESSAGE DISTINFO_FILE .CURDIR USE_LDCONFIG USE_AUTOTOOLS
  146. USE_GNOME USE_PERL5 USE_QT USE_QT5 INDEXFILE PKGORIGIN
  147. CONFLICTS CONFLICTS_BUILD CONFLICTS_INSTALL PKG_VERSION
  148. PLIST_FILES PLIST_DIRS PORTDOCS PORTEXAMPLES
  149. OPTIONS_DEFINE OPTIONS_RADIO OPTIONS_SINGLE OPTIONS_MULTI
  150. OPTIONS_GROUP OPTIONS_SUB INSTALLS_OMF USE_RC_SUBR USES DIST_SUBDIR
  151. ALLFILES CHECKSUM_ALGORITHMS INSTALLS_ICONS GNU_CONFIGURE
  152. CONFIGURE_ARGS MASTER_SITE_SUBDIR LICENSE LICENSE_COMB NO_STAGE
  153. DEVELOPER SUB_FILES SHEBANG_LANG MASTER_SITES_SUBDIRS FLAVORS
  154. USE_PYTHON LICENSE_PERMS USE_PYQT USE_GITHUB USE_GITLAB
  155. );
  156. my %makevar;
  157. my $i = 0;
  158. for (split(/\n/, get_makevar(@varlist))) {
  159. $_ =~ s/\0//;
  160. print "OK: makevar: $varlist[$i] = $_\n" if ($verbose);
  161. $makevar{$varlist[$i]} = $_;
  162. $i++;
  163. }
  164. #
  165. # variables for global checks.
  166. #
  167. my $sharedocused = 0;
  168. my %predefined = ();
  169. my @popt = ();
  170. # historical, no longer in FreeBSD's bsd.sites.mk
  171. foreach my $i (split(/\n/, <<EOF)) {
  172. GNU ftp://prep.ai.mit.edu/pub/gnu/%SUBDIR%/
  173. SUNSITE ftp://sunsite.unc.edu/pub/Linux/%SUBDIR%/
  174. EOF
  175. my ($j, $k) = split(/\t+/, $i);
  176. $predefined{$k} = $j;
  177. }
  178. # Read bsd.sites.mk
  179. my $sites_mk = "$portsdir/Mk/bsd.sites.mk";
  180. open(MK, $sites_mk) || die "$sites_mk: $!";
  181. my @site_groups = grep($_ = /^MASTER_SITE_(\w+)/ && $1, <MK>);
  182. close(MK);
  183. my $cmd = join(' -V MASTER_SITE_', "make $makeenv ", @site_groups);
  184. $i = 0;
  185. open2(\*IN, \*OUT, $cmd);
  186. close(OUT);
  187. while (<IN>) {
  188. my $g = $site_groups[$i];
  189. for my $s (split()) {
  190. $predefined{$s} = $g;
  191. }
  192. $i++;
  193. }
  194. close(IN);
  195. open(MK, 'Makefile') || die "Makefile: $!";
  196. my $ulineno = -1;
  197. my $uulineno = -1;
  198. my @muses = ();
  199. my @omuses = ();
  200. while (my $mline = <MK>) {
  201. if ($uulineno == -1 && $mline =~ /^USE_/) {
  202. $uulineno = $.;
  203. }
  204. if ($mline =~ /^USES[?+]?=\s*(.*)/) {
  205. if ($ulineno == -1) {
  206. $ulineno = $.;
  207. }
  208. if ($1) {
  209. push @muses, split(/\s+/, $1);
  210. }
  211. }
  212. if ($mline =~ /^[\w\d]+_USES[?+]?=\s*(.*)/) {
  213. if ($1) {
  214. push @omuses, split(/\s+/, $1);
  215. }
  216. }
  217. }
  218. if ($uulineno > -1 && $ulineno > -1 && $uulineno < $ulineno) {
  219. &perror("WARN", 'Makefile', $uulineno, "USE_* seen before USES. ".
  220. "According to the porters-handbook, USES must appear first.");
  221. }
  222. my %hmuses = map { $_ => 1 } @muses;
  223. foreach my $omuse (@omuses) {
  224. if ($hmuses{$omuse}) {
  225. &perror("WARN", 'Makefile', -1, "$omuse is specified in both USES ".
  226. "and a optional *_USES. It only needs to be specified in one.");
  227. }
  228. }
  229. foreach my $muse (@muses) {
  230. $makevar{USES} .= " " . $muse;
  231. }
  232. #
  233. # check for files.
  234. #
  235. my @checker = ($makevar{DESCR}, 'Makefile', $makevar{DISTINFO_FILE});
  236. my %checker = (
  237. $makevar{DESCR} => \&checkdescr,
  238. 'Makefile' => \&checkmakefile,
  239. $makevar{DISTINFO_FILE} => \&checkdistinfo
  240. );
  241. if ($extrafile) {
  242. my @files = (
  243. <$makevar{SCRIPTDIR}/*>,
  244. @makevar{qw(DESCR PLIST PKGINSTALL PKGDEINSTALL PKGREQ PKGMESSAGE)}
  245. );
  246. foreach my $i (@files) {
  247. next if (! -T $i);
  248. next if (defined $checker{$i});
  249. if ($i =~ /\bpkg-plist/) {
  250. unshift(@checker, $i);
  251. $checker{$i} = \&checkplist;
  252. } else {
  253. push(@checker, $i);
  254. $checker{$i} = \&checkpathname;
  255. }
  256. }
  257. }
  258. if ($checkmfiles) {
  259. foreach my $i ($mfile_moved, $mfile_uids, $mfile_gids) {
  260. next if (! -T $i);
  261. next if (defined $checker{$i});
  262. push(@checker, $i);
  263. $checker{$i} = \&checkmfile;
  264. }
  265. }
  266. foreach my $i (<$makevar{FILESDIR}/patch-*>) {
  267. next if (! -T $i);
  268. next if (defined $checker{$i});
  269. push(@checker, $i);
  270. $checker{$i} = \&checkpatch;
  271. }
  272. foreach my $i (@checker) {
  273. print "OK: checking $i.\n" if ($verbose);
  274. if (! -f "$i") {
  275. &perror("FATAL", "", -1, "no $i in \"$portdir\".") unless $i eq $makevar{DISTINFO_FILE} && $makevar{DISTFILES} eq "";
  276. } else {
  277. my $proc = $checker{$i};
  278. &$proc($i) || &perror("", "", -1, "Cannot open the file $i\n");
  279. if ($proc ne \&checkpatch) {
  280. &checklastline($i)
  281. || &perror("", "", -1, "Cannot open the file $i\n");
  282. }
  283. }
  284. }
  285. checkpatches(<$makevar{FILESDIR}/patch-*>);
  286. if ($committer) {
  287. sub find_proc {
  288. return if /^\.\.?$/;
  289. (my $fullname = $File::Find::name) =~ s#^\./##;
  290. print "OK: checking the file name of $fullname.\n" if ($verbose);
  291. if ($fullname eq 'work') {
  292. &perror("FATAL", $fullname, -1, "be sure to cleanup the working directory ".
  293. "before committing the port.");
  294. $File::Find::prune = 1;
  295. } elsif (-l) {
  296. &perror("WARN", $fullname, -1, "this is a symlink. ".
  297. "Please remove it.");
  298. } elsif (-z) {
  299. &perror("FATAL", $fullname, -1, "empty file and should be removed. ".
  300. "If it still needs to be there, put a dummy comment ".
  301. "to state that the file is intentionally left empty.");
  302. } elsif (-d && scalar(my @x = <$_/{*,.?*}>) <= 1) {
  303. &perror("FATAL", $fullname, -1, "empty directory should be removed.") unless ($fullname =~ /^\.git/);
  304. } elsif (/^\./) {
  305. &perror("WARN", $fullname, -1, "dotfiles are not preferred. ".
  306. "If this file is a dotfile to be installed as an example, ".
  307. "consider importing it as \"dot$_\".") unless
  308. (-d && $_ eq '.git');
  309. } elsif (/[^-.a-zA-Z0-9_\+]/) {
  310. &perror("WARN", $fullname, -1, "only use characters ".
  311. "[-_.a-zA-Z0-9+] for patch or script names.");
  312. } elsif (/\.(orig|rej|bak)$/ || /~$/ || /^\#/) {
  313. &perror("FATAL", $fullname, -1, "for safety, be sure to cleanup ".
  314. "backup files before committing the port.");
  315. } elsif (/(^|\.)core$/) {
  316. &perror("FATAL", $fullname, -1, "for safety, be sure to cleanup ".
  317. "core files before committing the port.");
  318. } elsif (/README.html/) {
  319. &perror("FATAL", $fullname, -1, "for safety, be sure to cleanup ".
  320. "README.html files before committing the port.");
  321. } elsif ($_ eq '.git' && -d) {
  322. &perror("FATAL", $fullname, -1, "for safety, be sure to cleanup ".
  323. "git files before committing the port.");
  324. $File::Find::prune = 1;
  325. } elsif (-f) {
  326. my $fullpath = $makevar{'.CURDIR'}.'/'.$fullname;
  327. my $result = `type git >/dev/null 2>&1 && git status --porcelain $fullpath`;
  328. chomp $result;
  329. if (substr($result, 0, 1) eq '?') {
  330. &perror("FATAL", "", -1, "$fullname not under git.")
  331. unless (eval { /$ENV{'PL_GIT_IGNORE'}/, 1 } &&
  332. /$ENV{'PL_GIT_IGNORE'}/);
  333. }
  334. }
  335. }
  336. find(\&find_proc, '.');
  337. # Check for ports that may break INDEX
  338. my $indexerr = `env LOCALBASE=/nonexistentlocal make $makeenv describe 2>&1 >/dev/null`;
  339. chomp $indexerr;
  340. $indexerr =~ tr/\n/ /s;
  341. &perror("FATAL", "", -1, "breaks INDEX ($indexerr).")
  342. if ($indexerr);
  343. # Suggest to set DEVELOPER knob in /etc/make.conf
  344. if (!$makevar{DEVELOPER}) {
  345. &perror("WARN", "", -1, "Consider to set DEVELOPER=yes in /etc/make.conf");
  346. }
  347. }
  348. if ($err || $warn) {
  349. my($errtext, $warntext) = ("error", "warning");
  350. $errtext .= "s" unless ($err == 1);
  351. $warntext .= "s" unless ($warn == 1);
  352. if ($grouperrs) {
  353. foreach my $msg (@errlst) {
  354. my $lines;
  355. if ($errcache{$msg} && scalar(@{$errcache{$msg}})) {
  356. $lines = "[" . (join(",", @{$errcache{$msg}})) . "]: ";
  357. } else {
  358. $lines = "";
  359. }
  360. $msg =~ s/%%LINES%%/$lines/;
  361. print $msg, "\n";
  362. }
  363. }
  364. if ($err > 0) {
  365. print BRIGHT_RED sprintf("%d fatal %s and %d %s found.", $err, $errtext, $warn, $warntext), RESET, "\n";
  366. } else {
  367. print BRIGHT_YELLOW sprintf("%d fatal %s and %d %s found.", $err, $errtext, $warn, $warntext), RESET, "\n";
  368. }
  369. } else {
  370. print BRIGHT_GREEN "looks fine.", RESET, "\n";
  371. }
  372. exit $err;
  373. #
  374. # distinfo
  375. #
  376. sub checkdistinfo {
  377. my($file) = @_;
  378. my($dist_subdir) = $makevar{DIST_SUBDIR};
  379. my(@allfiles) = split (/\s+/, $makevar{ALLFILES});
  380. my %algorithms = ();
  381. my %records = ();
  382. foreach my $i (split (/\s+/, uc ($makevar{CHECKSUM_ALGORITHMS}))) {
  383. $algorithms{$i} = 1;
  384. }
  385. open(IN, "< $file") || return 0;
  386. while (<IN>) {
  387. if (/^\s*$/) {
  388. &perror("FATAL", $file, $., "found blank line.");
  389. next;
  390. }
  391. if (/^TIMESTAMP\s+=\s+(\d+)$/) {
  392. my $now = time;
  393. if ($1 > $now) {
  394. &perror("FATAL", $file, $., "TIMESTAMP is in the future");
  395. }
  396. next;
  397. }
  398. if (/(\S+)\s+\((\S+)\)\s+=\s+(\S+)/) {
  399. my ($tag, $path, $value) = ($1, $2, $3);
  400. if ($records{$path}{$tag}) {
  401. &perror("FATAL", $file, $., "duplicate file listed.");
  402. }
  403. $records{$path}{$tag} = $value;
  404. if (!$algorithms{$tag} && $tag ne "SIZE") {
  405. &perror("FATAL", $file, $., "unsupported checksum algorithm ".
  406. "found: $tag.");
  407. }
  408. } else {
  409. &perror("FATAL", $file, $., "line format error.");
  410. }
  411. }
  412. close(IN);
  413. # For all files check SIZE and checksums
  414. foreach my $f (@allfiles) {
  415. # Remove hindering chars from DISTNAME
  416. $f =~ s/['\\]//g;
  417. my $path = $f;
  418. $path = "$dist_subdir/$f" if $dist_subdir;
  419. if (!defined($records{$path}{SIZE})) {
  420. &perror("FATAL", $file, -1, "has no SIZE record for $path.");
  421. }
  422. my $n = 0;
  423. foreach my $alg (keys %algorithms) {
  424. $n++ if exists($records{$path}{$alg});
  425. }
  426. if ($n == 0) {
  427. &perror("FATAL", $file, -1, "no checksum record for $path.");
  428. }
  429. if ($n < scalar(keys %algorithms)) {
  430. &perror("WARN", $file, -1, "no checksum records for all ".
  431. "supported algorithms (".join(" ",keys %algorithms).") for ".
  432. "$path.");
  433. }
  434. }
  435. return 1;
  436. }
  437. #
  438. # pkg-descr
  439. #
  440. sub checkdescr {
  441. my($file) = @_;
  442. my(%maxchars) = ($makevar{DESCR}, 80);
  443. my(%maxlines) = ($makevar{DESCR}, 24);
  444. my(%minlines) = ($makevar{DESCR}, 2);
  445. my(%toolongerrmsg) = ($makevar{DESCR},
  446. "exceeds $maxlines{$makevar{DESCR}} ".
  447. "lines, make it shorter if possible.");
  448. my(%tooshorterrmsg) = ($makevar{DESCR},
  449. "contains less than $minlines{$makevar{DESCR}} ".
  450. "lines, make it longer if possible.");
  451. my($longlines, $linecnt, $tmp) = (0, 0, "");
  452. open(IN, "< $file") || return 0;
  453. while (<IN>) {
  454. if ($_ =~ /[ \t]+\n?$/) {
  455. &perror("WARN", $file, $., "whitespace before end ".
  456. "of line.");
  457. }
  458. $tmp .= $_;
  459. chomp || &perror("WARN", $file, -1, "lines should terminate with a ".
  460. "newline (i.e. '\\n').");
  461. if (/ $/) {
  462. &perror("WARN", $file, -1, "lines should not contain carriage ".
  463. "returns. Strip all carriage returns (e.g. run dos2unix) ".
  464. "in $file.");
  465. }
  466. if (/^WWW:(\s+)(\S*)/) {
  467. my $wwwurl = $2;
  468. &perror("WARN", $file, -1, "the URL of the project website has been ".
  469. "moved into the Makefile. ".
  470. "Remove the WWW: line from this file and add \"WWW=$wwwurl\"".
  471. "to the Makefile immediately below the COMMENT line.");
  472. }
  473. $linecnt++;
  474. $longlines++ if ($maxchars{$file} < length);
  475. }
  476. if ($linecnt > $maxlines{$file}) {
  477. &perror("WARN", $file, -1, "$toolongerrmsg{$file}".
  478. "(currently $linecnt lines)");
  479. } elsif ($linecnt < $minlines{$file}) {
  480. &perror("WARN", $file, -1, "$tooshorterrmsg{$file}".
  481. "(currently $linecnt ".($linecnt > 1 ? "lines" : "line").")");
  482. } else {
  483. print "OK: $file: has $linecnt lines.\n" if ($verbose);
  484. }
  485. if ($longlines > 0) {
  486. &perror("WARN", $file, -1, "includes lines that exceed $maxchars{$file} ".
  487. "characters.");
  488. }
  489. if ($tmp =~ /[\033\200-\377]/) {
  490. &perror("WARN", $file, -1, "includes iso-8859-1, or ".
  491. "other local characters. files should be in ".
  492. "plain 7-bit ASCII");
  493. }
  494. close(IN);
  495. }
  496. #
  497. # pkg-plist
  498. #
  499. sub checkplist {
  500. my($file) = @_;
  501. my($curdir) = ($localbase);
  502. my $seen_special = 0;
  503. my $item_count = 0;
  504. my $owner_seen = 0;
  505. my $group_seen = 0;
  506. my $found_so = 0;
  507. # Variables that are allowed to be out-of-sync in the XXXDIR check.
  508. # E.g., %%PORTDOCS%%%%RUBY_MODDOCDIR%% will be OK because there is
  509. # no %%PORTRUBY_MODDOC%% substitution.
  510. my %check_xxxdir_ok = (
  511. "DOCS" => "DOCS",
  512. "EXAMPLES" => "EXAMPLES",
  513. "DATA" => "DATA",
  514. "RUBY_DOC" => "DOCS",
  515. "RUBY_EXAMPLES" => "EXAMPLES",
  516. "RUBY_MODDOC" => "DOCS",
  517. "RUBY_MODEXAMPLES" => "EXAMPLES",
  518. );
  519. open(IN, "< $file") || return 0;
  520. while (<IN>) {
  521. $item_count++;
  522. if ($_ =~ /[ \t]+\n?$/) {
  523. &perror("WARN", $file, $., "whitespace before end ".
  524. "of line.");
  525. }
  526. # make it easier to handle.
  527. $_ =~ s/\s+$//;
  528. $_ =~ s/\n$//;
  529. if ($_ eq "") {
  530. &perror("WARN", $file, $., "empty line found in plist.");
  531. }
  532. # store possible OPTIONS knobs for OPTIONS_SUB
  533. if ($makevar{OPTIONS_SUB}) {
  534. while (/\%\%([^%]+)\%\%/g) {
  535. if ($1 =~ /PORTDOCS/) {
  536. push @popt, "DOCS";
  537. } elsif ($1 =~ /PORTEXAMPLES/) {
  538. push @popt, "EXAMPLES";
  539. } else {
  540. push @popt, $1;
  541. }
  542. }
  543. }
  544. if ($_ =~ /\.DS_Store/) {
  545. &perror("WARN", $file, $., ".DS_Store meta data files must not ".
  546. "be installed.");
  547. }
  548. if (m'lib/perl5/site_perl/mach/%%PERL_VER%%') {
  549. &perror("WARN", $file, $., "use \%\%SITE_ARCH\%\% ".
  550. "instead of lib/perl5/site_perl/mach/\%\%PERL_VER\%\%");
  551. } elsif (m'lib/perl5/site_perl') {
  552. &perror("WARN", $file, $., "use \%\%SITE_PERL\%\% ".
  553. "instead of lib/perl5/site_perl.");
  554. }
  555. if (m'([\w\d]+-portbld-freebsd\d+\.\d+)') {
  556. &perror("WARN", $file, $., "possible direct use of the ".
  557. "CONFIGURE_TARGET value ($1). Consider using the plist ".
  558. "substitution %%CONFIGURE_TARGET%% instead.");
  559. }
  560. if (m'\@dirrm(try)?\s+libdata/pkgconfig') {
  561. &perror("FATAL", $file, $., "libdata/pkgconfig should not be ".
  562. "removed. It is listed in BSD.local.dist.");
  563. }
  564. if (m'\@dirrm(try)?\s') {
  565. &perror("WARN", $file, $., "\@dirrm[try] is deprecated. If you ".
  566. "require special directory handling, use \@dir instead and ".
  567. "consult the porter's handbook.");
  568. }
  569. if (m'\@cwd') {
  570. &perror("WARN", $file, $., "\@cwd is deprecated. Please use ".
  571. "absolute pathnames instead.");
  572. }
  573. if (m'\@stopdaemon\s') {
  574. &perror("WARN", $file, $., "\@stopdaemon is deprecated. The ".
  575. "pkg(8) has a generic mechanism to provide the same function, ".
  576. "see HANDLE_RC_SCRIPTS in pkg.conf(5).");
  577. }
  578. if (m'^\@(un)?exec') {
  579. &perror("WARN", $file, $., "@[un]exec is deprecated in ".
  580. "favor of \@<pre|post>[un]exec as the latter specifies ".
  581. "the exact part of the pkg lifecycle the commands need ".
  582. "to run");
  583. }
  584. $seen_special++ if /[\%\@]/;
  585. if ($_ =~ /^\@/) {
  586. if ($_ =~ /^\@(cwd|cd)[ \t]+(\S+)/) {
  587. $curdir = $2;
  588. } elsif ($_ =~ /^\@unexec[ \t]+rm[ \t]/) {
  589. if ($_ !~ /%[DB]/) {
  590. &perror("WARN", $file, $., "use \"%D\" or \"%B\" to ".
  591. "specify prefix.");
  592. }
  593. if ($_ !~ /true$/ && $_ !~ /rm -f/) {
  594. &perror("WARN", $file, $., "add \"2>&1 ".
  595. ">/dev/null || true\" ".
  596. "to \"\@unexec rm\".");
  597. }
  598. } elsif ($_ =~ /^\@unexec[ \t]+rmdir/) {
  599. if ($_ !~ /%[DB]/) {
  600. &perror("WARN", $file, $., "use \"%D\" or \"%B\" to ".
  601. "specify prefix.");
  602. }
  603. &perror("WARN", $file, $., "use \"\@dirrmtry\" ".
  604. "instead of \"\@unexec rmdir\".");
  605. } elsif ($_ =~ /^\@unexec[ \t]+install-info[ \t]+--delete\s+(.+)\s+(.+)$/) {
  606. &perror("WARN", $file, $., "\@unexec install-info is deprecated in favor of adding info files into the Makefile using the INFO macro.");
  607. } elsif ($_ =~ /^\@(pre|post)?(exec|unexec|)/) {
  608. if (/ldconfig/) {
  609. &perror("WARN", $file, $., "possible ".
  610. "direct use of ldconfig ".
  611. "in PLIST found. use ".
  612. "USE_LDCONFIG instead.");
  613. }
  614. if (/scrollkeeper/) {
  615. &perror("WARN", $file, $., "possible ".
  616. "direct use of scrollkeeper commands ".
  617. "in PLIST found. Use ".
  618. "INSTALLS_OMF instead ".
  619. "(see http://www.FreeBSD.org/gnome/docs/porting.html ".
  620. "for more details).");
  621. }
  622. } elsif ($_ =~ /^\@(comment)/) {
  623. &perror("FATAL", $file, $., "\$$rcsidstr\$ is deprecated in Git.") if (/\$$rcsidstr[:\$]/);
  624. } elsif ($_ =~ m!^\@(dirrm|dirrmtry)\s+/!) {
  625. &perror("WARN", $file, $., "Using \@$1 with absolute path ".
  626. "will not work as you expected in most cases. Use ".
  627. "\@dir... if you want to remove a directory such as ".
  628. "/var/\${PORTNAME}");
  629. } elsif ($_ eq "\@cwd") {
  630. ; # @cwd by itself means change directory back to the original
  631. # PREFIX.
  632. } elsif ($_ =~ /^\@\(/) {
  633. if ($_ !~ /^\@\([^,]*,[^,]*,[^\),]*(,[^\)]*)?\)/) {
  634. &perror("WARN", $file, $., "Invalid use of \@(...). ".
  635. "Arguments should be owner,group,perms[,fflags]");
  636. }
  637. } elsif ($_ =~ /^\@sample\s+(.+)/) {
  638. my $sl = $.;
  639. my @sampleparts = split(/\s+/, $1);
  640. if (scalar @sampleparts == 1 && $sampleparts[0] !~ /\.sample$/) {
  641. &perror("WARN", $file, $sl, "\@sample directive references".
  642. " file that does not end in ``.sample''. Sample".
  643. " files must end in ``.sample''.");
  644. }
  645. } elsif ($_ =~ /^\@owner/) {
  646. if ($_ =~ /^\@owner\s+.+/) {
  647. if ($owner_seen > 0) {
  648. &perror("WARN", $file, $., "Nested setting of \@owner ".
  649. "found. Reset \@owner before setting it again.");
  650. }
  651. $owner_seen++;
  652. } else {
  653. if ($owner_seen == 0) {
  654. &perror("WARN", $file, $., "\@owner reset seen before ".
  655. "a new owner section was started.");
  656. }
  657. $owner_seen--;
  658. }
  659. } elsif ($_ =~ /^\@group/) {
  660. if ($_ =~ /^\@group\s+.+/) {
  661. if ($group_seen > 0) {
  662. &perror("WARN", $file, $., "Nested setting of \@group ".
  663. "found. Reset \@group before setting it again.");
  664. }
  665. $group_seen++;
  666. } else {
  667. if ($group_seen == 0) {
  668. &perror("WARN", $file, $., "\@group reset seen before ".
  669. "a new group section was started.");
  670. }
  671. $group_seen--;
  672. }
  673. } elsif ($_ =~ /^\@(dir|dirrm|dirrmtry|rmtry|option|stopdaemon|owner|group|mode|fc|fcfontsdir|fontsdir|info|shell)\b/) {
  674. ; # no check made
  675. } else {
  676. &perror("WARN", $file, $.,
  677. "unknown pkg-plist directive \"$_\"");
  678. }
  679. next;
  680. }
  681. if ($_ =~ /charset\.alias$/ || $_ =~ /locale\.alias$/) {
  682. &perror("WARN", $file, $., "installing charset.alias or locale.alias, ".
  683. "please add USES[+]=gettext and use libintl from devel/gettext ".
  684. "instead of from outdated bundled one if possible. ".
  685. "See http://www.freebsd.org/cgi/query-pr.cgi?pr=ports/71531 ".
  686. "for more details.");
  687. }
  688. if ($_ =~ /\%gconf.*\.xml/ || $_ =~ /gconf.*\.schemas?/) {
  689. &perror("FATAL", $file, $., "explicitly listing \%gconf key files ".
  690. "or GConf schema files in the plist is not supported. ".
  691. "Use GCONF_SCHEMAS in the Makefile instead. ".
  692. "See http://www.FreeBSD.org/gnome/docs/porting.html ".
  693. "for more details.");
  694. }
  695. if ($_ =~ m|lib/pkgconfig/[^\/]+.pc$|) {
  696. &perror("FATAL", $file, $., "installing pkg-config files into ".
  697. "lib/pkgconfig. All pkg-config files must be installed ".
  698. "into libdata/pkgconfig for them to be found by pkg-config.");
  699. }
  700. if ($_ =~ m|lib[^\/]+\.so\.\d+$| &&
  701. $makevar{USE_LDCONFIG} eq '') {
  702. &perror("WARN", $file, $., "installing shared libraries, ".
  703. "please define USE_LDCONFIG as appropriate");
  704. } elsif ($_ =~ m|lib[^\/]+\.so[.\d]*$|) {
  705. $found_so++;
  706. }
  707. if ($_ =~ m|\.omf$| && $makevar{INSTALLS_OMF} eq '') {
  708. &perror("WARN", $file, $., "installing OMF files, ".
  709. "please define INSTALLS_OMF (see the FreeBSD GNOME ".
  710. "porting guide at ".
  711. "http://www.FreeBSD.org/gnome/docs/porting.html ".
  712. "for more details)");
  713. }
  714. if ($_ =~ m|\.desktop$| && $makevar{USES} !~ /\bdesktop-file-utils\b/) {
  715. &perror("WARN", $file, $., "this port installs .desktop files. ".
  716. "If the .desktop file(s) installed contain ``MimeType='', ".
  717. "you must add `desktop-file-utils` to USES.");
  718. }
  719. if ($_ =~ m|^(%%([^%]+)%%)?.*\.mo$| && $makevar{USES} !~ /\bgettext\b/) {
  720. my $show_nls_warn = 1;
  721. if ($2) {
  722. my $mv = get_makevar($2."_USES");
  723. if ($mv =~ /\bgettext\b/) {
  724. $show_nls_warn = 0;
  725. }
  726. }
  727. if ($show_nls_warn) {
  728. &perror("WARN", $file, $., "installing gettext translation files, ".
  729. "please define USES[+]=gettext as appropriate");
  730. }
  731. }
  732. if ($_ =~ m|\.core$| && $_ !~ /^\@/) {
  733. &perror("WARN", $file, $., "this port installs a file which ends ".
  734. "in \".core\". This file may be deleted if ".
  735. "daily_clean_disks_enable=\"YES\" in /etc/periodic.conf. ".
  736. "If possible, install this file with a different name.");
  737. }
  738. if ($_ =~ m|/a\.out$| && $_ !~ /^\@/) {
  739. &perror("WARN", $file, $., "this port installs a file named ".
  740. "\"a.out\". This file may be deleted if ".
  741. "daily_clean_disks_enable=\"YES\" in /etc/periodic.conf. ".
  742. "If possible, install this file with a different name.");
  743. }
  744. if ($_ =~ /\.info$/) {
  745. &perror("WARN", $file, $., "enumerating info files in the plist is deprecated in favor of adding info files into the Makefile using the INFO macro.");
  746. }
  747. if ($_ =~ /\.info-\d+$/) {
  748. &perror("FATAL", $file, $., "numbered info files are obsolete and not portable; add info files using the INFO macro in the Makefile.");
  749. }
  750. if ($_ =~ /^(\%\%PORTDOCS\%\%)?share\/doc\//) {
  751. &perror("WARN", $file, $., "If and only if your port is ".
  752. "DOCSDIR-safe (that is, a user can override DOCSDIR ".
  753. "when building this port and the port will still work ".
  754. "correctly) consider using DOCSDIR macro; if you are ".
  755. "unsure if this port is DOCSDIR-safe, then ignore ".
  756. "this warning");
  757. $sharedocused++;
  758. } elsif ($_ =~ /^(\%\%PORTDOCS\%\%)?\%\%DOCSDIR\%\%/) {
  759. $sharedocused++;
  760. }
  761. if ($_ =~ /^share\/examples\//) {
  762. &perror("WARN", $file, $., "If and only if your port is ".
  763. "EXAMPLESDIR-safe (that is, a user can override EXAMPLESDIR ".
  764. "when building this port and the port will still work ".
  765. "correctly) consider using EXAMPLESDIR macro; if you are ".
  766. "unsure if this port is EXAMPLESDIR-safe, then ignore this ".
  767. "warning");
  768. }
  769. {
  770. my $tmpportname = quotemeta($makevar{PORTNAME});
  771. if ($_ =~ /^share\/$tmpportname\//) {
  772. &perror("WARN", $file, $., "If and only if your port is ".
  773. "DATADIR-safe (that is, a user can override DATADIR when ".
  774. "building this port and the port will still work ".
  775. "correctly) consider using DATADIR macro; if you are ".
  776. "unsure if this port is DATADIR-safe, then ignore this ".
  777. "warning");
  778. }
  779. }
  780. if ($_ =~ m{^%%PORT(\w+)%%(.*?)%%(\w+)DIR%%(.*)$} and $1 ne $3 and
  781. defined($check_xxxdir_ok{$3})) {
  782. &perror("WARN", $file, $., "Do not mix %%PORT$1%% with %%$3DIR%%. ".
  783. "Use '%%PORT$check_xxxdir_ok{$3}%%$2%%$3DIR%%$4' instead and update Makefile ".
  784. "accordingly.") unless ($check_xxxdir_ok{$3} eq $1);
  785. }
  786. # It is now recommended for manpages to be installed under share/man.
  787. #if ($_ =~ m#share/man/#) {
  788. # &perror("FATAL", $file, $., "Man pages must be installed into ".
  789. # "``man'' not ``share/man''.");
  790. #}
  791. if ($_ =~ m#man/([^/]+/)?man[1-9ln]/([^\.]+\.[1-9ln])(\.gz)?$#) {
  792. if (!$3) {
  793. &perror("FATAL", $file, $., "Unpacked man file $2 listed. ".
  794. "Must be gzipped.");
  795. }
  796. }
  797. if ($curdir !~ m#^$localbase#) {
  798. &perror("WARN", $file, $., "installing to ".
  799. "directory $curdir discouraged. ".
  800. "could you please avoid it?");
  801. }
  802. if ("$curdir/$_" =~ m#^$localbase/share/doc/#) {
  803. print "OK: $file [$.]: seen installation to share/doc. ".
  804. "($curdir/$_)\n" if ($verbose);
  805. $sharedocused++;
  806. }
  807. }
  808. if ($owner_seen > 0) {
  809. &perror("WARN", $file, -1, "A \@owner section was started but never ".
  810. "reset. USe \@owner without any arguments to reset the owner");
  811. }
  812. if ($group_seen > 0) {
  813. &perror("WARN", $file, -1, "A \@group section was started but never ".
  814. "reset. Use \@group without any arguments to reset the group");
  815. }
  816. if (!$seen_special && $item_count < $numpitems) {
  817. &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.");
  818. }
  819. if ($makevar{USE_LDCONFIG} ne '' && !$found_so) {
  820. &perror("WARN", $file, -1, "You have defined USE_LDCONFIG, but this ".
  821. "port does not install any shared objects.");
  822. }
  823. close(IN);
  824. 1;
  825. }
  826. #
  827. # ${PORTSDIR}/MOVED, UIDs, GIDs files
  828. #
  829. sub checkmfile {
  830. my ($file) = @_;
  831. my $line = 0;
  832. my $format;
  833. my @entries;
  834. my @sorted;
  835. my $dosort;
  836. if ($file =~ m/MOVED$/) {
  837. $format = '^[^|]*\|[^|]*\|[^|]*\|[^|]*$';
  838. $dosort = 0;
  839. } elsif ($file =~ m/UIDs$/) {
  840. $format = '^[^:]+:\*:[0-9]+:[0-9]+:[^:]*:0:0:[^:]+:[^:]+:[^:]+$';
  841. $dosort = 1;
  842. } elsif ($file =~ m/GIDs$/) {
  843. $format = '^[^:]+:\*:[0-9]+:[^:]*$';
  844. $dosort = 1;
  845. } else {
  846. &perror("FATAL", $file, -1, "Internal error. ".
  847. "Invalid name for mfiles.");
  848. }
  849. open(IN, "<$file") || return 0;
  850. while (<IN>) {
  851. chomp;
  852. $line++;
  853. next if (m,^\s*#,);
  854. if (!m,${format},) {
  855. &perror("FATAL", $file, -1,
  856. "malformed line at ".
  857. "${line}.\n => $_");
  858. } else {
  859. push @entries, "$line:$_";
  860. next;
  861. }
  862. }
  863. if ($dosort) {
  864. my $errline;
  865. @sorted = sort {(split /:/, $a)[3] <=> (split /:/, $b)[3] } @entries;
  866. for (my $n = 0; $n < @entries; $n++) {
  867. if (!defined($sorted[$n]) or
  868. $entries[$n] ne $sorted[$n]) {
  869. ($line, $errline) = ($entries[$n] =~ m/([0-9]+):(.*)/);
  870. &perror("WARN", $file, -1,
  871. "malformed sorting order at " .
  872. "${line}.\n => $errline");
  873. }
  874. }
  875. }
  876. close(IN);
  877. }
  878. #
  879. # misc files
  880. #
  881. sub checkpathname {
  882. my($file) = @_;
  883. my($whole);
  884. open(IN, "< $file") || return 0;
  885. $whole = '';
  886. while (<IN>) {
  887. $whole .= $_;
  888. }
  889. &abspathname($whole, $file);
  890. close(IN);
  891. }
  892. sub checklastline {
  893. my($file) = @_;
  894. my($whole);
  895. open(IN, "< $file") || return 0;
  896. $whole = '';
  897. while (<IN>) {
  898. $whole .= $_;
  899. }
  900. if ($whole !~ /\n$/) {
  901. &perror("FATAL", $file, -1, "the last line has to be ".
  902. "terminated by \\n.");
  903. }
  904. if ($whole =~ /\n([ \t]*\n)+$/) {
  905. &perror("WARN", $file, -1, "seems to have unnecessary blank lines ".
  906. "at the last part.");
  907. }
  908. close(IN);
  909. }
  910. sub checkpatches {
  911. my (@patchfiles) = @_;
  912. my @patched_files;
  913. foreach my $file (@patchfiles) {
  914. open(IN, "< $file") || return 0;
  915. while (<IN>) {
  916. if ($_ =~ /^\+\+\+\s(.*?)\s.*/) {
  917. #if($1 ~~ @patched_files) {
  918. if (grep {$_ eq $1} @patched_files) {
  919. &perror("WARN", $file, -1, "$1 patched multiple times");
  920. }
  921. else {
  922. push(@patched_files, $1);
  923. }
  924. }
  925. }
  926. }
  927. }
  928. sub checkpatch {
  929. my($file) = @_;
  930. my($whole);
  931. if (-z "$file") {
  932. &perror("FATAL", $file, -1, "has no content. should be removed ".
  933. "from repository.");
  934. return;
  935. }
  936. my $bfile = basename($file);
  937. if (length $bfile > 100) {
  938. &perror("FATAL", $file, -1, "make sure patch file names contain no ".
  939. "more than 100 characters.");
  940. }
  941. open(IN, "< $file") || return 0;
  942. $whole = '';
  943. my $checked_header = 0;
  944. while (<IN>) {
  945. $whole .= $_;
  946. if (/^--- / && !$checked_header) {
  947. $checked_header = 1;
  948. if ($_ !~ /UTC\s*$/) {
  949. &perror("WARN", $file, -1, "patch was not generated using ".
  950. "``make makepatch''. It is recommended to use ".
  951. "``make makepatch'' when you need to [re-]generate a ".
  952. "patch to ensure proper patch format.");
  953. }
  954. }
  955. }
  956. if ($committer && $whole =~ /\wjavavm\w/) {
  957. my $lineno = &linenumber($`);
  958. &perror("WARN", $file, $lineno, "since javavmwrapper 2.0, the ".
  959. "``javavm'' command to invoke a JVM is deprecated. Use ".
  960. "``java'' instead");
  961. }
  962. if ($whole =~ / /) {
  963. my $lineno = &linenumber($`);
  964. &perror("WARN", $file, $lineno, "patch contains ^M characters. ".
  965. "Consider defining USES=dos2unix to remove DOS line endings ".
  966. "from source files.");
  967. }
  968. if ($whole !~ /\n$/s) {
  969. &perror("FATAL", $file, -1, "patch does not end with a newline, and the commit check ".
  970. "hook will fail.");
  971. }
  972. close(IN);
  973. }
  974. sub check_depends_syntax {
  975. my $tmp = shift;
  976. my $file = shift;
  977. my (%seen_depends, $j);
  978. $ENV{'PORTSDIR'} //= $portsdir;
  979. foreach my $i (grep(/^(PATCH_|EXTRACT_|LIB_|BUILD_|RUN_|TEST_|FETCH_)*DEPENDS[?+]?=/, split(/\n/, $tmp))) {
  980. $i =~ s/^((PATCH_|EXTRACT_|LIB_|BUILD_|RUN_|TEST_|FETCH_)*DEPENDS)[?+]?=[ \t]*//;
  981. $j = $1;
  982. $seen_depends{$j}++;
  983. if ($j ne 'DEPENDS' &&
  984. $i =~ /^\$\{([A-Z_]+DEPENDS)}\s*$/ &&
  985. $seen_depends{$1} &&
  986. $j ne $1)
  987. {
  988. print "OK: $j refers to $1, skipping checks.\n"
  989. if ($verbose);
  990. next;
  991. } elsif ($j ne 'DEPENDS' && $i =~ /^\$\{([A-Z_]+DEPENDS)}\s*$/ && !$seen_depends{$1}) {
  992. # make(1) does lazy variable evaluation, so we can use a variable before it is
  993. # declared. However, portlint scans line by line. Allow this behavior.
  994. print "OK: $j refers to $1 (which hasn't been declared yet, but it will work), skipping checks.\n"
  995. if ($verbose);
  996. next;
  997. }
  998. print "OK: checking ports listed in $j.\n" if ($verbose);
  999. my @ks = split(/\s+/, $i);
  1000. while (@ks) {
  1001. my $k = shift @ks;
  1002. if ($k =~ /^#/) {
  1003. last;
  1004. }
  1005. my $ok = $k;
  1006. if ($k =~ /^\$\{([^\}]+)\}$/) {
  1007. $k = get_makevar_shallow($1);
  1008. push @ks, split(/\s+/, $k);
  1009. next;
  1010. }
  1011. if ($k eq '') {
  1012. next;
  1013. }
  1014. my ($tmp_depends, $fl) = split(/\@/, $k);
  1015. $tmp_depends =~ s/\$\{[^}]+}//g;
  1016. my @l = split(':', $tmp_depends);
  1017. print "OK: checking dependency value for $j.\n"
  1018. if ($verbose);
  1019. if ($ok =~ /\$\{((PATCH_|EXTRACT_|LIB_|BUILD_|RUN_|TEST_|FETCH_)*DEPENDS)}/) {
  1020. &perror("WARN", $file, -1, "do not set $j to $ok. ".
  1021. "Instead, explicity list out required $j dependencies.");
  1022. }
  1023. if (($j ne 'DEPENDS'
  1024. && scalar(@l) != 2 && scalar(@l) != 3)) {
  1025. &perror("WARN", $file, -1, "wrong dependency value ".
  1026. "for $j. $j requires ".
  1027. "2 or 3 ".
  1028. "colon-separated tuples.");
  1029. next;
  1030. }
  1031. my %m = ();
  1032. $m{'dep'} = $l[0];
  1033. $m{'dir'} = $l[1];
  1034. $m{'fla'} = $fl // '';
  1035. $m{'tgt'} = $l[2] // '';
  1036. my %depmvars = ();
  1037. foreach my $dv ($m{'dep'}, $m{'dir'}, $m{'tgt'}) {
  1038. foreach my $mv ($dv =~ /\$\{([^}]+)\}/g) {
  1039. if (defined($depmvars{$mv})) {
  1040. next;
  1041. }
  1042. if (defined($makevar{$mv})) {
  1043. $depmvars{$mv} = $makevar{$mv};
  1044. } else {
  1045. $depmvars{$mv} = &get_makevar($mv);
  1046. }
  1047. }
  1048. }
  1049. # check Python flavor
  1050. my $bdir = basename($m{'dir'});
  1051. if ($bdir =~ /^py-/) {
  1052. if ($m{'fla'} ne '${PY_FLAVOR}') {
  1053. &perror("WARN", $file, -1, "you may want directory for ".
  1054. "dependency $m{'dep'} to be $m{'dir'}\@\${PY_FLAVOR}");
  1055. }
  1056. }
  1057. # check JAVALIBDIR
  1058. if ($m{'dep'} =~ m|share/java/classes|) {
  1059. &perror("FATAL", $file, -1, "you should use \${JAVALIBDIR} ".
  1060. "in BUILD_DEPENDS/RUN_DEPENDS to define ".
  1061. "dependencies on JAR files installed in ".
  1062. "\${JAVAJARDIR}");
  1063. }
  1064. foreach my $dv ($m{'dep'}, $m{'dir'}, $m{'tgt'}) {
  1065. foreach my $dmv (keys %depmvars) {
  1066. $dv =~ s/\$\{$dmv\}/$depmvars{$dmv}/g;
  1067. }
  1068. }
  1069. print "OK: dep=\"$m{'dep'}\", ".
  1070. "dir=\"$m{'dir'}\", tgt=\"$m{'tgt'}\"\n"
  1071. if ($verbose);
  1072. # check USES=perl5
  1073. if ($m{'dep'} =~ /^perl5(\.\d+)?$/) {
  1074. &perror("WARN", $file, -1, "dependency to perl5 ".
  1075. "listed in $j. consider using ".
  1076. "USES[+]=perl5.");
  1077. }
  1078. # Check for ${SITE_PERL} in depends
  1079. if ($m{'dep'} =~ m|^(\$\{SITE_PERL}/.*)$|) {
  1080. &perror("WARN", $file, -1, "dependency to $1 ".
  1081. "listed in $j. consider using p5-Example-Package-Name>=0. See ".
  1082. "http://www.freebsd.org/doc/en/books/porters-handbook/using-perl.html".
  1083. " for more details.");
  1084. }
  1085. # check USES=iconv
  1086. if ($m{'dep'} =~ /^(iconv\.\d+)$/) {
  1087. &perror("WARN", $file, -1, "dependency to $1 ".
  1088. "listed in $j. consider using ".
  1089. "USES[+]=iconv.");
  1090. }
  1091. # check USES=gettext
  1092. if ($m{'dep'} =~ /^(intl\.\d+)$/) {
  1093. &perror("WARN", $file, -1, "dependency to $1 ".
  1094. "listed in $j. consider using ".
  1095. "USES[+]=gettext.");
  1096. }
  1097. # check USES=gmake
  1098. if ($m{'dep'} =~ /^(gmake|\$\{GMAKE})$/) {
  1099. &perror("WARN", $file, -1, "dependency to $1 ".
  1100. "listed in $j. consider using ".
  1101. "USES[+]=gmake.");
  1102. }
  1103. my %udeps = (
  1104. 'bison' => 'bison',
  1105. 'fmake' => 'fmake',
  1106. );
  1107. foreach my $udep (keys %udeps) {
  1108. if ($m{'dep'} =~ /^$udep/) {
  1109. &perror("WARN", $file, -1, "dependency to $udep ".
  1110. "listed in $j. consider using ".
  1111. "USES[+]=$udeps{$udep}.");
  1112. }
  1113. }
  1114. # check USE_QT
  1115. if ($m{'dep'} =~ /^(qt\d)+$/) {
  1116. &perror("WARN", $file, -1, "dependency to $1 ".
  1117. "listed in $j. consider using ".
  1118. "USE_QT.");
  1119. }
  1120. # check LIBLTDL
  1121. if ($m{'dep'} =~ /^(ltdl\.\d)+$/) {
  1122. &perror("WARN", $file, -1, "dependency to $1 ".
  1123. "listed in $j. consider using ".
  1124. "USE_LIBLTDL.");
  1125. }
  1126. # check GHOSTSCRIPT
  1127. if ($m{'dep'} eq "gs") {
  1128. &perror("WARN", $file, -1, "dependency to gs ".
  1129. "listed in $j. consider using ".
  1130. "USE_GHOSTSCRIPT(_BUILD|_RUN).");
  1131. }
  1132. # check for PREFIX
  1133. if ($m{'dep'} =~ /\$\{PREFIX}/) {
  1134. &perror("FATAL", $file, -1, "\${PREFIX} must not be ".
  1135. "contained in *_DEPENDS. ".
  1136. "use \${LOCALBASE} instead.");
  1137. }
  1138. # Check for direct dependency on apache.
  1139. if ($m{'dep'} =~ /\/www\/apache\d*\//) {
  1140. &perror("FATAL", $file, -1, "do not depend on any apache ".
  1141. "port in *_DEPENDS directly. ".
  1142. "Instead use USE_APACHE=VERSION, where VERSION can be ".
  1143. "found in \${PORTSDIR}/Mk/Uses/apache.mk.");
  1144. }
  1145. # Check for over-specific shared library dependencies
  1146. if ($j eq 'LIB_DEPENDS' && $m{'dep'} =~ m/(\.\d+$)/) {
  1147. &perror("WARN", $file, -1, "$j don't specify the " .
  1148. "ABI version number $1 in $m{'dep'} unless it is " .
  1149. "really necessary.");
  1150. }
  1151. # Check for old-style LIB_DEPENDS
  1152. if ($j eq 'LIB_DEPENDS' && $m{'dep'} !~ m/^lib.*\.so$/) {
  1153. &perror("WARN", $file, -1, "$j the new format is ".
  1154. "libFOO.so (e.g., lib$m{'dep'}.so).");
  1155. }
  1156. # Check port dir existence
  1157. $k = $ENV{'PORTSDIR'}.'/'.$m{'dir'};
  1158. if (! -d $k) {
  1159. &perror("WARN", $file, -1, "no port directory $k ".
  1160. "found, even though it is ".
  1161. "listed in $j.");
  1162. } else {
  1163. print "OK: port directory $k found.\n"
  1164. if ($verbose);
  1165. }
  1166. # Check for relative path
  1167. if ($k =~ /\/\.\.\//) {
  1168. &perror("FATAL", $file, -1, "use absolute path".
  1169. "instead of $k in *_DEPENDS.");
  1170. } else {
  1171. print "OK: path for port directory $k is absolute.\n"
  1172. if ($verbose);
  1173. }
  1174. }
  1175. }
  1176. }
  1177. #
  1178. # Makefile
  1179. #
  1180. sub checkmakefile {
  1181. my($file) = @_;
  1182. my($rawwhole, $whole, $idx, @sections);
  1183. my($i, $j, $k, $l);
  1184. my @cat = ();
  1185. my $has_lang_cat = 0;
  1186. my $port_lang = '';
  1187. my $tmp;
  1188. my $bogusdistfiles = 0;
  1189. my @varnames = ();
  1190. my($portname, $portversion, $distfiles, $all_distfiles, $distversionprefix, $distversion, $distversionsuffix, $distname, $extractsufx) = ('') x 9;
  1191. my $masterport = 0;
  1192. my $slaveport = 0;
  1193. my $use_gnome_hack = 0;
  1194. my $use_java = 0;
  1195. my $use_ant = 0;
  1196. my($realwrksrc, $wrksrc, $nowrksubdir) = ('', '', '');
  1197. my(@mman, @pman);
  1198. my(@aopt, @mopt, @opt);
  1199. my($pkg_version, $versiondir, $versionfile) = ('', '', '');
  1200. my $indexfile = '';
  1201. my $useindex = 0;
  1202. my %deprecated = ();
  1203. my @deplist = ();
  1204. my %autocmdnames = ();
  1205. my $pre_mk_line = 0;
  1206. my $options_mk_line = 0;
  1207. my $docsused = 0;
  1208. my $optused = 0;
  1209. my $desktop_entries = '';
  1210. my $conflicts = "";
  1211. my $masterdir = $makevar{MASTERDIR};
  1212. if ($masterdir ne '' && $masterdir ne $makevar{'.CURDIR'}) {
  1213. $slaveport = 1;
  1214. }
  1215. open(IN, "< $file") || return 0;
  1216. $rawwhole = '';
  1217. $tmp = 0;
  1218. while (<IN>) {
  1219. if ($_ =~ /[ \t]+\n?$/) {
  1220. &perror("WARN", $file, $., "whitespace before ".
  1221. "end of line.");
  1222. }
  1223. if ($_ =~ /^ /) { # 8 spaces here!
  1224. &perror("WARN", $file, $., "use tab (not space) to make ".
  1225. "indentation");
  1226. }
  1227. if ($usetabs) {
  1228. if (m/^[A-Za-z0-9_-]+.?=\t*? \t*?/) {
  1229. if (m/[?+]=/) {
  1230. &perror("WARN", $file, $., "use a tab (not space) after a ".
  1231. "variable name");
  1232. } else {
  1233. &perror("FATAL", $file, $., "use a tab (not space) after a ".
  1234. "variable name");
  1235. }
  1236. }
  1237. }
  1238. $rawwhole .= $_;
  1239. if (/\\$/) {
  1240. # Concat continued lines.
  1241. chomp $rawwhole;
  1242. chop $rawwhole;
  1243. }
  1244. }
  1245. close(IN);
  1246. #
  1247. # whole file: blank lines.
  1248. #
  1249. $whole = "\n" . $rawwhole;
  1250. study $whole;
  1251. print "OK: checking contiguous blank lines in $file.\n"
  1252. if ($verbose);
  1253. $i = "\n" x ($contblank + 2);
  1254. if ($whole =~ /$i/) {
  1255. my $lineno = &linenumber($`);
  1256. &perror("FATAL", $file, $lineno, "contiguous blank lines ".
  1257. "(> $contblank lines) found.");
  1258. }
  1259. #
  1260. # whole file: header
  1261. #
  1262. my @lines = split("\n", $whole);
  1263. print "OK: checking header in $file.\n" if ($verbose);
  1264. if ($lines[1] =~ /^# (?:New )?[Pp]orts collection [mM]akefile/) {
  1265. &perror("FATAL", $file, 1, "old style headers found.");
  1266. } elsif ($lines[1] =~ /^# \$$rcsidstr[:\$]/) {
  1267. &perror("FATAL", $file, 1, "\$$rcsidstr\$ is deprecated in Git.");
  1268. } elsif ($lines[1] =~ /^# Created by: \S/) {
  1269. if ($lines[2] =~ /^# \$$rcsidstr[:\$]/) {
  1270. &perror("FATAL", $file, 2, "\$$rcsidstr\$ is deprecated in Git.");
  1271. }
  1272. if ($lines[2] !~ /^$/) {
  1273. #&perror("FATAL", $file, 2, "do not add extra ".
  1274. # "empty comments after header.");
  1275. }
  1276. # special case for $rcsidsrt\nMCom:
  1277. } elsif ($lines[1] =~ /^#\s+\$MCom[:\$]/ and $lines[2] =~ /^$/) {
  1278. # DO NOTHING
  1279. }
  1280. #
  1281. # whole file: $(VARIABLE)
  1282. #
  1283. if ($parenwarn) {
  1284. print "OK: checking for \$(VARIABLE).\n" if ($verbose);
  1285. if ($whole =~ /[^\$]\$\([\w\d]+\)/) {
  1286. my $lineno = &linenumber($`);
  1287. &perror("WARN", $file, $lineno, "use \${VARIABLE}, instead of ".
  1288. "\$(VARIABLE).");
  1289. }
  1290. }
  1291. #
  1292. # whole file: empty(${VARIABLE})
  1293. #
  1294. if ($parenwarn) {
  1295. print "OK: checking for empty(\${VARIABLE}).\n" if ($verbose);
  1296. if ($whole =~ /empty\(\$\{[\w\d]+/) {
  1297. my $lineno = &linenumber($`);
  1298. &perror("WARN", $file, $lineno, "use empty(VARIABLE), instead of ".
  1299. "empty(\${VARIABLE}).");
  1300. }
  1301. }
  1302. #
  1303. # whole file: use of !=
  1304. #
  1305. print "OK: checking for use of !=.\n" if ($verbose);
  1306. if ($whole =~ /^[\w\d_]+\!=/m) {
  1307. my $lineno = &linenumber($`);
  1308. &perror("WARN", $file, $lineno, "use of != in assignments is almost ".
  1309. "never a good thing to do. Try to avoid using them. See ".
  1310. "http://lists.freebsd.org/pipermail/freebsd-ports/2008-July/049777.html ".
  1311. "for some helpful hints on what to do instead.");
  1312. }
  1313. #
  1314. # whole file: use of .elseif
  1315. #
  1316. print "OK: checking for use of .elseif.\n" if ($verbose);
  1317. if ($whole =~ /^\.\s*else\s*if/m) {
  1318. my $lineno = &linenumber($`);
  1319. &perror("FATAL", $file, $lineno, "use of .elseif (or .else if) is not ".
  1320. "supported in all versions of FreeBSD. Use .elif instead.");
  1321. }
  1322. #
  1323. # whole file: use of @${INSTALL_foo}
  1324. #
  1325. print "OK: checking for use of muted INSTALL_ commands.\n" if ($verbose);
  1326. if ($whole =~ /^\s+\@\$\{INSTALL_/m) {
  1327. my $lineno = &linenumber($`);
  1328. &perror("WARN", $file, $lineno, "do not use muted INSTALL_foo ".
  1329. "commands (i.e., those that start with '\@'). These should be ".
  1330. "printed.");
  1331. }
  1332. #
  1333. # checking for use of ${ENV}
  1334. #
  1335. print "OK: checking for use of \${ENV} instead of \${SETENV}.\n" if ($verbose);
  1336. if ($whole =~ /\$\{ENV}/m) {
  1337. my $lineno = &linenumber($`);
  1338. &perror("WARN", $file, $lineno, "most uses of \${ENV} should really ".
  1339. "be \${SETENV} to avoid strange behaviors in sh(1).");
  1340. }
  1341. #
  1342. # whole file: use of IGNOREFILES
  1343. #
  1344. print "OK: checking for use of IGNOREFILES.\n" if ($verbose);
  1345. if ($whole =~ /\nIGNOREFILES.?=/m) {
  1346. my $lineno = &linenumber($`);
  1347. &perror("FATAL", $file, $lineno, "IGNOREFILES considered unsafe and ".
  1348. "not supported anymore.");
  1349. }
  1350. #
  1351. # whole file: use of PLIST_DIRSTRY
  1352. #
  1353. print "OK: checking for use of PLIST_DIRSTRY.\n" if ($verbose);
  1354. if ($whole =~ /\nPLIST_DIRSTRY.?=/m) {
  1355. my $lineno = &linenumber($`);
  1356. &perror("WARN", $file, $lineno, "PLIST_DIRSTRY is deprecated. Please ".
  1357. "use PLIST_DIRS instead.");
  1358. }
  1359. #
  1360. # whole file: PLIST_FILES and PLIST_DIRS
  1361. #
  1362. print "OK: checking PLIST_FILES and PLIST_DIRS.\n" if ($verbose);
  1363. my $python_plist = 0;
  1364. if ($makevar{USE_PYTHON} && $makevar{USE_PYTHON} =~ /\bautoplist\b/) {
  1365. $python_plist = 1;
  1366. }
  1367. if ($whole =~ /\nPLIST_FILES.?=/ || $whole =~ /\nPLIST_DIRS.?=/) {
  1368. if (-f 'pkg-plist') {
  1369. my $lineno = &linenumber($`);
  1370. &perror("WARN", $file, $lineno, "You may remove pkg-plist ".
  1371. "if you use PLIST_FILES and/or PLIST_DIRS.");
  1372. }
  1373. my @plist_files = split(/\s+/, $makevar{PLIST_FILES});
  1374. foreach my $plist_file (@plist_files) {
  1375. if ($plist_file =~ m|lib[^\/]+\.so(\.\d+)?$| &&
  1376. $makevar{USE_LDCONFIG} eq '') {
  1377. &perror("WARN", "", -1, "PLIST_FILES: installing shared libraries, ".
  1378. "please define USE_LDCONFIG as appropriate");
  1379. }
  1380. if ($plist_file =~ m|\.omf$| && $makevar{INSTALLS_OMF} eq '') {
  1381. &perror("WARN", "", -1, "PLIST_FILES: installing OMF files, ".
  1382. "please define INSTALLS_OMF (see the FreeBSD GNOME ".
  1383. "porting guide at ".
  1384. "http://www.FreeBSD.org/gnome/docs/porting.html ".
  1385. "for more details)");
  1386. }
  1387. if ($plist_file =~ m|\.core$| && $plist_file !~ /^\@/) {
  1388. &perror("WARN", "", -1, "PLIST_FILES: this port installs a file which ".
  1389. "ends in \".core\". This file may be deleted if ".
  1390. "daily_clean_disks_enable=\"YES\" in /etc/periodic.conf. ".
  1391. "If possible, install this file with a different name.");
  1392. }
  1393. if ($plist_file =~ /%%[\w_\d]+%%/) {
  1394. &perror("FATAL", "", -1, "PLIST_FILES: files cannot contain ".
  1395. "%%FOO%% variables. Use make variables and logic instead");
  1396. }
  1397. if ($plist_file =~ m|\.desktop$| && $makevar{USES} !~ /\bdesktop-file-utils\b/) {
  1398. &perror("FATAL", "", -1, "PLIST_FILES: this port installs .desktop files. ".
  1399. "please add `desktop-file-utils` to USES.");
  1400. }
  1401. }
  1402. }
  1403. #
  1404. # whole file: USE_* and others variables used too late
  1405. #
  1406. my @options_early = qw(
  1407. OPTIONS_DEFAULT
  1408. OPTIONS_DEFINE
  1409. OPTIONS_EXCLUDE
  1410. OPTIONS_GROUP.*?
  1411. OPTIONS_MULTI.*?
  1412. OPTIONS_RADIO.*?
  1413. OPTIONS_SINGLE.*?
  1414. );
  1415. pos($whole) = 0;
  1416. if ($whole =~ /^\.include\s+<bsd\.port\.pre\.mk>$/gm) {
  1417. # Remember position
  1418. $pre_mk_line = &linenumber($`) + 1;
  1419. print "OK: checking for USE_* used too late.\n" if ($verbose);
  1420. my @use_early = qw(
  1421. BZIP2
  1422. GNUSTEP
  1423. IMAKE
  1424. KDE(?:BASE|LIBS)_VER
  1425. (?:LIB)?RUBY
  1426. LINUX_PREFIX
  1427. OPENSSL
  1428. PYTHON
  1429. QT2?
  1430. QT_VER
  1431. X_PREFIX
  1432. ZIP
  1433. );
  1434. my @other_early = qw(
  1435. EMACS_PORT_NAME
  1436. );
  1437. my $earlypattern = join('|', 'USE_(?:'.join('|', @use_early).')',
  1438. @other_early, @options_early);
  1439. while ($whole =~ /^($earlypattern)[+?:!]?=/gmo) {
  1440. my $lineno = &linenumber($`);
  1441. &perror("FATAL", $file, $lineno, "$1 is set after ".
  1442. "including bsd.port.pre.mk.");
  1443. }
  1444. }
  1445. #
  1446. # whole file: check OPTIONS
  1447. #
  1448. print "OK: checking OPTIONS.\n" if ($verbose);
  1449. pos($whole) = 0;
  1450. if ($whole =~ /^\.include\s+<bsd\.port\.options\.mk>$/gm) {
  1451. # Remember position
  1452. $options_mk_line = &linenumber($`) + 1;
  1453. }
  1454. pos($whole) = 0;
  1455. if ($whole =~ /^\.include\s+<bsd\.port\.options\.mk>$/gm) {
  1456. my $earlypattern = join('|', @options_early);
  1457. while ($whole =~ /^($earlypattern)[+?]?=/gmo) {
  1458. my $lineno = &linenumber($`);
  1459. &perror("FATAL", $file, $lineno, "$1 is set after ".
  1460. "including bsd.port.options.mk.");
  1461. }
  1462. }
  1463. pos($whole) = 0;
  1464. foreach my $i ("OPTIONS_RADIO","OPTIONS_SINGLE",
  1465. "OPTIONS_MULTI","OPTIONS_GROUP") {
  1466. foreach my $j (split(/\s+/, $makevar{$i})) {
  1467. if ($j) {
  1468. my @ocount = split(/\s+/, get_makevar("${i}_${j}"));
  1469. if (!scalar(@ocount)) {
  1470. &perror("FATAL", $file, -1,
  1471. "Description for ${i}_${j} does not exist");
  1472. } else {
  1473. push @aopt, @ocount;
  1474. }
  1475. }
  1476. }
  1477. }
  1478. my @aropt = ();
  1479. while ($whole =~ /^OPTIONS_DEFINE_[\d\w]+(.)=\s*(.+)$/mg) {
  1480. push @aropt, split(/\s+/, $2);
  1481. }
  1482. @opt = split(/\s+/, $makevar{OPTIONS_DEFINE});
  1483. pos($whole) = 0;
  1484. while ($whole =~ /PORT_OPTIONS:M(\w+)/mg) {
  1485. push @mopt, $1;
  1486. my $lineno = &linenumber($`) + 1;
  1487. &perror("FATAL", $file, $lineno, "PORT_OPTIONS:M$1 is used before ".
  1488. "including bsd.port.pre.mk or bsd.port.options.mk.")
  1489. if ($optused && $lineno < $pre_mk_line &&
  1490. $lineno < $options_mk_line);
  1491. }
  1492. my @options_helpers = qw(
  1493. __DUMMY__
  1494. ALL_TARGET
  1495. BUILD_DEPENDS
  1496. EXTRACT_DEPENDS
  1497. FETCH_DEPENDS
  1498. LIB_DEPENDS
  1499. PKG_DEPENDS
  1500. RUN_DEPENDS
  1501. CATEGORIES
  1502. CFLAGS
  1503. CMAKE_OFF
  1504. CMAKE_ON
  1505. CMAKE_BOOL_OFF
  1506. CMAKE_BOOL
  1507. CONFIGURE_ENABLE
  1508. CONFIGURE_ENV
  1509. CONFIGURE_OFF
  1510. CONFIGURE_ON
  1511. CONFIGURE_WITH
  1512. CPPFLAGS
  1513. CXXFLAGS
  1514. DISTFILES
  1515. INSTALL_TARGET
  1516. LDFLAGS
  1517. MAKE_ARGS
  1518. MAKE_ENV
  1519. EXTRA_PATCHES
  1520. PATCHFILES
  1521. PATCH_DEPENDS
  1522. PATCH_SITES
  1523. PLIST_DIRS
  1524. PLIST_DIRSTRY
  1525. PLIST_FILES
  1526. QMAKE_OFF
  1527. QMAKE_ON
  1528. USE
  1529. USES
  1530. VARS
  1531. VARS_OFF
  1532. );
  1533. my $m = join("|", @options_helpers);
  1534. if ($makevar{OPTIONS_SUB}) {
  1535. if ($makevar{PLIST_FILES}) {
  1536. foreach my $i (split(/\s+/, $makevar{PLIST_FILES})) {
  1537. while ($i =~ /\%\%([^%]+)\%\%/g) {
  1538. push @popt, $1;
  1539. }
  1540. }
  1541. }
  1542. if ($makevar{PLIST_DIRS}) {
  1543. foreach my $i (split(/\s+/, $makevar{PLIST_DIRS})) {
  1544. while ($i =~ /\%\%([^%]+)\%\%/g) {
  1545. push @popt, $1;
  1546. }
  1547. }
  1548. }
  1549. if (-f 'pkg-plist') {
  1550. open(PL, 'pkg-plist');
  1551. my @pcontents = <PL>;
  1552. close(PL);
  1553. foreach my $i (@pcontents) {
  1554. while ($i =~ /\%\%([^%]+)\%\%/g) {
  1555. push @popt, $1;
  1556. }
  1557. }
  1558. }
  1559. # special cases for PORTDOCS/PORTEXAMPLES
  1560. push @popt, "DOCS" if $makevar{PORTDOCS};
  1561. push @popt, "EXAMPLES" if $makevar{PORTEXAMPLES};
  1562. # uniq(@popt)
  1563. my %seen = ();
  1564. @popt = grep { !$seen{$_}++ } @popt;
  1565. }
  1566. foreach my $i (@popt) {
  1567. if ($i eq 'PORTDOCS') {
  1568. if (!grep(/^DOCS$/, @opt)) {
  1569. &perror("FATAL", $file, -1, "PORTDOCS appears in plist ".
  1570. "but DOCS is not listed in OPTIONS_DEFINE.");
  1571. }
  1572. } elsif ($i eq 'PORTEXAMPLES') {
  1573. if (!grep(/^EXAMPLES$/, @opt)) {
  1574. &perror("FATAL", $file, -1, "PORTEXAMPLES appears in plist ".
  1575. "but EXAMPLES is not listed in OPTIONS_DEFINE.");
  1576. }
  1577. }
  1578. }
  1579. my %seen_opts = ();
  1580. foreach my $i ((@opt, @aopt, @aropt)) {
  1581. # skip global options
  1582. next if ($i eq 'DOCS' or $i eq 'NLS' or $i eq 'EXAMPLES' or $i eq 'IPV6' or $i eq 'X11' or $i eq 'DEBUG');
  1583. if (!$seen_opts{$i}) {
  1584. $seen_opts{$i}++;
  1585. my $odescr = &get_makevar("${i}_DESC");
  1586. if ($odescr eq "" && $whole !~ /^${i}_DESC.?=/m) {
  1587. &perror("FATAL", $file, -1, "OPTION $i does not have a description (${i}_DESC).");
  1588. }
  1589. }
  1590. if (!grep(/^$i$/, (@mopt, @popt))) {
  1591. if ($whole !~ /\n${i}_($m)(_\w+)?(.)?=[^\n]+/ and $whole !~ /\n[-\w]+-${i}-(on|off):\n/) {
  1592. my $found_opt_use = 0;
  1593. foreach my $oarg ('BUILD_DEPENDS', 'RUN_DEPENDS', 'LIB_DEPENDS') {
  1594. my $oarg_var = &get_makevar("${i}_${oarg}");
  1595. if ($oarg_var ne "") {
  1596. $found_opt_use = 1;
  1597. last;
  1598. }
  1599. }
  1600. if (!$found_opt_use) {
  1601. if (!$slaveport) {
  1602. &perror("WARN", $file, -1, "$i is listed in ".
  1603. "OPTIONS_DEFINE, but no PORT_OPTIONS:M$i appears.");
  1604. } else {
  1605. &perror("WARN", $file, -1, "$i is listed in ".
  1606. "OPTIONS_DEFINE, but no PORT_OPTIONS:M$i appears ".
  1607. "in this slave Makefile. Make sure it appears in ".
  1608. "the master's Makefile.");
  1609. }
  1610. }
  1611. }
  1612. }
  1613. }
  1614. foreach my $i (@mopt) {
  1615. if (!grep(/^$i$/, @opt, @aopt, @aropt)) {
  1616. # skip global options
  1617. next if ($i eq 'DOCS' or $i eq 'NLS' or $i eq 'EXAMPLES' or $i eq 'IPV6' or $i eq 'X11');
  1618. &perror("WARN", $file, -1, "$i appears in PORT_OPTIONS:M, ".
  1619. "but is not listed in OPTIONS_DEFINE.");
  1620. }
  1621. }
  1622. #
  1623. # whole file: check DESKTOP_ENTRIES for ${TRUE}/${FALSE}
  1624. #
  1625. print "OK: checking DESKTOP_ENTRIES for \${TRUE}/\${FALSE}.\n" if ($verbose);
  1626. $desktop_entries = &get_makevar_raw('DESKTOP_ENTRIES');
  1627. if ($desktop_entries =~ /\$\{TRUE}/ or $desktop_entries =~ /\$\{FALSE}/ or
  1628. $desktop_entries =~ /\"true\"/ or $desktop_entries =~ /\"false\"/) {
  1629. &perror("FATAL", $file, -1, "Use true/false (without quotes) instead of \${TRUE}/\${FALSE} in DESKTOP_ENTRIES.");
  1630. }
  1631. #
  1632. # whole file: USE_* as a user-settable option
  1633. #
  1634. print "OK: checking for USE_* as a user-settable option.\n" if ($verbose);
  1635. while ($whole =~ /\n\s*\.\s*(?:el)?if[^\n]*?\b(\w*USE_)(\w+)(?![^\n]*\n#?\.error)/g) {
  1636. my $lineno = &linenumber($`);
  1637. &perror("WARN", $file, $lineno, "is $1$2 a user-settable option? ".
  1638. "Consider using WITH_$2 instead.")
  1639. if ($1.$2 ne 'USE_GCC' && $1.$2 ne 'USE_LDCONFIG32');
  1640. }
  1641. #
  1642. # whole file: check for use of *_CMAKE_ARGS
  1643. #
  1644. print "OK: checking for use of *_CMAKE_ARGS instead of *_CMAKE_ON|OFF.\n" if ($verbose);
  1645. if ($whole =~ /\n([\w\d]+)_CMAKE_ARGS/) {
  1646. my $lineno = &linenumber($`);
  1647. &perror("WARN", $file, $lineno, "Use $1_CMAKE_ON or $1_CMAKE_OFF instead ".
  1648. "of $1_CMAKE_ARGS. The former macros will automatically update ".
  1649. "CMAKE_ARGS.");
  1650. }
  1651. #
  1652. # whole file: check that CMAKE_BOOL just has words
  1653. #
  1654. print "OK: checking that *_CMAKE_BOOL only contains words.\n" if ($verbose);
  1655. if ($whole =~ /\n([\w\d]+)_CMAKE_BOOL[?+:]?=([^\n]+)\n/) {
  1656. my $lineno = &linenumber($`);
  1657. my $o = $1;
  1658. if ($2 =~ /-D/) {
  1659. &perror("FATAL", $file, $lineno, "Only bare words can be used for ".
  1660. "${o}_CMAKE_BOOL. The -D flag will be added automatically.");
  1661. }
  1662. }
  1663. print "OK: checking that *CMAKE* co-occurs with *USES+=cmake.\n" if ($verbose);
  1664. while ($whole =~ /\n([\w\d]+_)?CMAKE_(ARGS|BOOL|BOOL_ON|BOOL_OFF|OFF|ON)\b/g) {
  1665. my $lineno = &linenumber($`);
  1666. my $o = $1;
  1667. my $found_cmake = 0;
  1668. unless ($makevar{USES} =~ /\b(cmake\b|cmake:)/) {
  1669. $o = "" unless ($o);
  1670. &perror("FATAL", $file, $lineno, "${o}CMAKE_$2 is set without USES+=cmake");
  1671. }
  1672. }
  1673. #
  1674. # whole file: NO_CHECKSUM
  1675. #
  1676. # XXX Don't compress newlines since it messes up line number calculation.
  1677. #$whole =~ s/\n#[^\n]*/\n/g;
  1678. #$whole =~ s/\n\n+/\n/g;
  1679. print "OK: checking NO_CHECKSUM.\n" if ($verbose);
  1680. if ($whole =~ /\nNO_CHECKSUM/) {
  1681. my $lineno = &linenumber($`);
  1682. &perror("FATAL", $file, $lineno, "NO_CHECKSUM is a user ".
  1683. "variable and is not to be set in a port's Makefile.");
  1684. }
  1685. #
  1686. # whole file: MACHINE_ARCH
  1687. #
  1688. print "OK: checking MACHINE_ARCH.\n" if ($verbose);
  1689. if ($whole =~ /\nMACHINE_ARCH/) {
  1690. my $lineno = &linenumber($`);
  1691. &perror("FATAL", $file, $lineno, "MACHINE_ARCH should never be ".
  1692. "overridden.");
  1693. }
  1694. #
  1695. # whole file: DEPRECATED
  1696. #
  1697. print "OK: checking DEPRECATED.\n" if ($verbose);
  1698. if ($whole =~ /\nDEPRECATED[+?]?=[ \t]*"/ &&
  1699. $whole !~ /\nDEPRECATED[+?]?=[ \t]*"\$\{BROKEN\}"/) {
  1700. my $lineno = &linenumber($`);
  1701. &perror("WARN", $file, $lineno, "DEPRECATED messages should not ".
  1702. "be quoted unless they are exactly \"\${BROKEN}\".");
  1703. }
  1704. if ($whole =~ /\nDEPRECATED[+?]?=[^"]*\$\{BROKEN\}/) {
  1705. my $lineno = &linenumber($`);
  1706. &perror("WARN", $file, $lineno, "\"\${BROKEN}\" must be quoted ".
  1707. "when it is the source of DEPRECATED.");
  1708. }
  1709. #
  1710. # whole file: BROKEN et al.
  1711. #
  1712. my ($var);
  1713. foreach $var (qw(IGNORE BROKEN(_[\w\d]+)? COMMENT FORBIDDEN MANUAL_PACKAGE_BUILD NO_CDROM NO_PACKAGE RESTRICTED)) {
  1714. print "OK: checking ${var}.\n" if ($verbose);
  1715. if ($whole =~ /\n${var}[+?]?=[ \t]+"/) {
  1716. my $lineno = &linenumber($`);
  1717. &perror("WARN", $file, $lineno, "${var} messages should not ".
  1718. "be quoted.");
  1719. }
  1720. }
  1721. if ($makevar{COMMENT} =~ /^An? / || $makevar{COMMENT} =~ /^The /) {
  1722. &perror("WARN", $file, -1, "COMMENT is not supposed to begin with ".
  1723. "'A ', 'An ', or 'The '.");
  1724. }
  1725. if ($whole =~ /\nIGNORE[+?]?=[ \t]+[^a-z \t]/ ||
  1726. $whole =~ /^IGNORE[+?]?=[ \t]+.*\.$/m) {
  1727. my $lineno = &linenumber($`);
  1728. &perror("WARN", $file, $lineno, "IGNORE messages should begin ".
  1729. "with a lowercase letter and end without a period.");
  1730. }
  1731. if ($whole =~ /\nBROKEN(_[\w\d]+)?[+?]?=[ \t]+[^a-z \t]/ ||
  1732. $whole =~ /^BROKEN(_[\w\d]+)?[+?]?=[ \t]+.*\.$/m) {
  1733. my $lineno = &linenumber($`);
  1734. &perror("WARN", $file, $lineno, "BROKEN messages should begin ".
  1735. "with a lowercase letter and end without a period.");
  1736. }
  1737. #
  1738. # whole file: PKGNAME
  1739. #
  1740. print "OK: checking PKGNAME.\n" if ($verbose);
  1741. if ($whole =~ /\nPKGNAME.?=/) {
  1742. my $lineno = &linenumber($`);
  1743. &perror("FATAL", $file, $lineno, "PKGNAME is obsoleted by PORTNAME, ".
  1744. "PORTVERSION, PKGNAMEPREFIX and PKGNAMESUFFIX.");
  1745. }
  1746. #
  1747. # whole file: MAKE_JOBS_UNSAFE
  1748. #
  1749. print "OK: checking for MAKE_JOBS_UNSAFE in combination with NO_BUILD.\n" if ($verbose);
  1750. if ($whole =~ /\nMAKE_JOBS_UNSAFE.?=/) {
  1751. my $matched = $1;
  1752. if ($whole =~ /\nNO_BUILD.?=/) {
  1753. my $lineno = &linenumber($`);
  1754. &perror("WARN", $file, $lineno, "MAKE_JOBS_UNSAFE should not ".
  1755. "be used in combination with NO_BUILD. You ".
  1756. "should remove MAKE_JOBS_UNSAFE from your Makefile.");
  1757. }
  1758. }
  1759. #
  1760. # whole file: Check if some macros are sorted
  1761. #
  1762. my @macros_to_sort = qw(
  1763. ONLY_FOR_ARCHS
  1764. NOT_FOR_ARCHS
  1765. );
  1766. print "OK: checking to see if certain macros are sorted.\n" if ($verbose);
  1767. foreach my $sorted_macro (@macros_to_sort) {
  1768. while ($whole =~ /\n$sorted_macro.?=\s*([^#\n]+)(#.*)?\n/g) {
  1769. my $lineno = &linenumber($`);
  1770. my $srex = $1;
  1771. $srex =~ s/\s+$//;
  1772. my @smacros = sort(split / /, $srex);
  1773. if (join(" ", @smacros) ne $srex) {
  1774. &perror("WARN", $file, $lineno, "the arguments to $sorted_macro ".
  1775. "are not sorted. Please consider sorting them.");
  1776. }
  1777. }
  1778. }
  1779. #
  1780. # whole file: USE_GNOME=pkgconfig
  1781. #
  1782. print "OK: checking for USE_GNOME=pkgconfig.\n" if ($verbose);
  1783. if ($makevar{USE_GNOME} =~ /pkgconfig/) {
  1784. &perror("WARN", $file, -1, "USE_GNOME=pkgconfig is now obsolete. ".
  1785. "Use USES[+]=pkgconfig instead.");
  1786. }
  1787. #
  1788. # whole file: using INSTALLS_ICONS when it is not wanted
  1789. #
  1790. if (!($makevar{INSTALLS_ICONS} eq '')) {
  1791. &perror("WARN", $file, -1, "INSTALLS_ICONS is now deprecated. It should be removed.");
  1792. }
  1793. #
  1794. # whole file: EXPIRATION_DATE
  1795. #
  1796. print "OK: checking for valid EXPIRATION_DATE.\n" if ($verbose);
  1797. my $edate;
  1798. if (($edate) = ($whole =~ m/\nEXPIRATION_DATE\??=[ \t]*([^\n]*)\n/)) {
  1799. my $lineno = &linenumber($`);
  1800. my $ndate = $edate;
  1801. if ($ndate eq '' || length $ndate < 10) {
  1802. $ndate = '0000-00-00';
  1803. }
  1804. if ($ndate ne strftime("%Y-%m-%d", 0, 0, 0,
  1805. substr($ndate, 8, 2),
  1806. substr($ndate, 5, 2) - 1,
  1807. substr($ndate, 0, 4) - 1900)) {
  1808. &perror("FATAL", $file, $lineno, "EXPIRATION_DATE ($edate) is ".
  1809. "either not in YYYY-MM-DD format or it is not a valid ".
  1810. "date.");
  1811. }
  1812. }
  1813. #
  1814. # whole file: IS_INTERACTIVE/NOPORTDOCS|PORT_OPTIONS:MDOCS
  1815. #
  1816. print "OK: checking IS_INTERACTIVE.\n" if ($verbose);
  1817. if ($whole =~ /\nIS_INTERACTIVE/) {
  1818. if ($whole !~ /defined\((BATCH|FOR_CDROM)\)/) {
  1819. my $lineno = &linenumber($`);
  1820. &perror("WARN", $file, $lineno, "use of IS_INTERACTIVE ".
  1821. "discouraged. provide batch mode by using BATCH and/or ".
  1822. "FOR_CDROM.");
  1823. }
  1824. }
  1825. print "OK: checking for use of PORT_OPTIONS:MDOCS.\n" if ($verbose);
  1826. if ($sharedocused && $whole =~ /PORT_OPTIONS:MDOCS/) {
  1827. $docsused++;
  1828. }
  1829. print "OK: checking for use of NOPORTDOCS.\n" if ($verbose);
  1830. if ($whole =~ /defined\s*\(?NOPORTDOCS\)?/ ||
  1831. $whole =~ /def\s*\(?NOPORTDOCS\)?/) {
  1832. my $lineno = &linenumber($`);
  1833. &perror("WARN", $file, $lineno, "NOPORTDOCS is deprecated. Please ".
  1834. "use PORT_OPTIONS:MDOCS instead.");
  1835. }
  1836. print "OK: checking for use of NOPORTEXAMPLES.\n" if ($verbose);
  1837. if ($whole =~ /defined\s*\(?NOPORTEXAMPLES\)?/ ||
  1838. $whole =~ /def\s*\(?NOPORTEXAMPLES\)?/) {
  1839. my $lineno = &linenumber($`);
  1840. &perror("WARN", $file, $lineno, "NOPORTEXAMPLES is deprecated. Please ".
  1841. "use PORT_OPTIONS:MEXAMPLES instead.");
  1842. }
  1843. if ($sharedocused && $whole !~ /defined\s*\(?NOPORTDOCS\)?/
  1844. && $whole !~ /def\s*\(?NOPORTDOCS\)?/) {
  1845. if ($docsused == 1
  1846. && $whole !~ m#(\$[\{\(]PREFIX[\}\)]|$localbase)/share/doc/#) {
  1847. &perror("WARN", $file, -1, "you should only use \".if \${PORT_OPTIONS:MDOCS}\" to wrap ".
  1848. "installation of files into $localbase/share/doc if the".
  1849. " collection of files is large and it takes considerable time".
  1850. " to copy.");
  1851. }
  1852. } else {
  1853. $docsused++;
  1854. }
  1855. if ($docsused > 1) {
  1856. &perror("FATAL", $file, -1, "Both NOPORTDOCS and PORT_OPTIONS:MDOCS are found. ".
  1857. "Remove one or another.");
  1858. }
  1859. print "OK: checking for use of NOPORTDOCS.\n" if ($verbose);
  1860. if ($whole =~ /NOPORTDOCS/) {
  1861. my $lineno = &linenumber($`);
  1862. &perror("WARN", $file, $lineno, "NOPORTDOCS found. Consider ".
  1863. "using PORT_OPTIONS:MDOCS.");
  1864. }
  1865. #
  1866. # whole file: check for USES[+]=gettext
  1867. #
  1868. print "OK: checking for USES=gettext without PORT_OPTIONS:MNLS.\n" if ($verbose);
  1869. if ($makevar{USES} =~ /\bgettext\b/ && $whole !~ /PORT_OPTIONS:MNLS/
  1870. && $whole !~ /NLS_USES=.*\bgettext\b/) {
  1871. &perror("WARN", $file, -1, "Consider adding support for a NLS ".
  1872. "knob to conditionally disable gettext support.");
  1873. }
  1874. #
  1875. # whole file: check for deprecated commands
  1876. #
  1877. print "OK: checking for deprecated macros.\n" if $verbose;
  1878. %deprecated = (
  1879. USE_RCORDER => 'USE_RC_SUBR',
  1880. );
  1881. @deplist = (\%deprecated);
  1882. for my $dlst (@deplist) {
  1883. my $hurl = $dlst->{'__HELP__'};
  1884. foreach my $depmacro (keys %{$dlst}) {
  1885. if ($whole =~ /\n($depmacro)[+?:!]?=/) {
  1886. my $derror = "$depmacro is ".
  1887. "deprecated, use $dlst->{$1} instead";
  1888. if (defined($hurl)) {
  1889. $derror .= " (see $hurl for more details)";
  1890. }
  1891. &perror("FATAL", $file, -1, $derror);
  1892. }
  1893. }
  1894. }
  1895. #
  1896. # whole file: DOS line endings
  1897. #
  1898. print "OK: checking for DOS line ending removal.\n" if ($verbose);
  1899. if ($whole =~ / / || $whole =~ /:cntrl:/) {
  1900. my $lineno = &linenumber($`);
  1901. &perror("WARN", $file, $lineno, "Possible manual removal of DOS ".
  1902. "line endings found. Consider defining USES=dos2unix instead.");
  1903. }
  1904. #
  1905. # whole file: direct use of command names
  1906. #
  1907. my %cmdnames = ();
  1908. print "OK: checking direct use of command names.\n" if ($verbose);
  1909. foreach my $i (qw(
  1910. awk basename brandelf cat chmod chown cp cpio dialog dirname egrep expr
  1911. false file find gmake grep gzcat ldconfig ln md5 mkdir mv objcopy paste patch
  1912. pax perl printf rm rmdir ruby sed sdl-config sh sort sysctl touch tr which
  1913. xargs xmkmf
  1914. )) {
  1915. $cmdnames{$i} = "\$\{\U$i\E\}";
  1916. }
  1917. $cmdnames{'echo'} = '${ECHO_CMD} or ${ECHO_MSG}';
  1918. $cmdnames{'env'} = '${SETENV}';
  1919. $cmdnames{'gunzip'} = '${GUNZIP_CMD}';
  1920. $cmdnames{'gzip'} = '${GZIP_CMD}';
  1921. $cmdnames{'install'} = '${INSTALL_foobar}';
  1922. $cmdnames{'python'} = '${PYTHON_CMD}';
  1923. $cmdnames{'sdl-config'} = '${SDL_CONFIG}';
  1924. $cmdnames{'strip'} = '${STRIP_CMD}';
  1925. $cmdnames{'unzip'} = '${UNZIP_CMD}';
  1926. $cmdnames{'pkg_create'} = '${PKG_CMD}';
  1927. foreach my $i (qw(aclocal autoconf autoheader automake autoreconf autoupdate autoscan ifnames libtoolize)) {
  1928. $autocmdnames{$i} = "\$\{" . ( ( $i !~ /auto|aclocal/ ) ? "AUTO" : "" ) . "\U$i\E\}";
  1929. }
  1930. #
  1931. # ignore parameter string to echo command.
  1932. # note that we leave the command as is, since we need to check the
  1933. # use of echo itself.
  1934. $j = $whole;
  1935. $j =~ s/([ \t][\@\-]{0,2})(echo|\$[\{\(]ECHO[\}\)]|\$[\{\(]ECHO_MSG[\}\)])[ \t]+(?:"(?:\\'|\\"|[^"])*"|'(?:\\'|\\"|[^'])*')[ \t]*;?(\n?)/$1$2;$3/g; #"
  1936. # ignore variables names in .for loops, but not what's at the end
  1937. # of the for loop
  1938. $j =~ s/(\.for +)([^ ]*)( .*)/$1$3/;
  1939. foreach my $i (keys %cmdnames) {
  1940. # XXX This is a hack. Really, we should break $j up into individual
  1941. # lines, and go through each one.
  1942. while ($j =~ /^(.*\b$i\b.*)$/gm) {
  1943. my $lineno = &linenumber($`);
  1944. my $curline = $1;
  1945. my $dte_test = $curline;
  1946. $dte_test =~ s/^\s+//g;
  1947. if ($desktop_entries =~ /\Q$dte_test\E$/) {
  1948. next;
  1949. }
  1950. if ($curline =~ /(?:^|\s)[\@\-]{0,2}$i(?:$|\s)/
  1951. && $curline !~ /^PORTNAME=[^\n]+$i/m
  1952. && $curline !~ /^[A-Z]+_TARGET[?+]?=[^\n]+$i/m
  1953. && $curline !~ /^[A-Z]+_INSTALL_TARGET[?+]?=[^\n]+$i/m
  1954. && $curline !~ /^IGNORE(_[\w\d]+)?(.)?=[^\n]+$i/m
  1955. && $curline !~ /^BROKEN(_[\w\d]+)?(.)?=[^\n]+$i/m
  1956. && $curline !~ /^RESTRICTED(.)?=[^\n]+$i/m
  1957. && $curline !~ /^NO_PACKAGE(.)?=[^\n]+$i/m
  1958. && $curline !~ /^NO_CDROM(.)?=[^\n]+$i/m
  1959. && $curline !~ /^MAINTAINER(.)?=[^\n]+$i/m
  1960. && $curline !~ /^WWW(.)?=[^\n]+$i/m
  1961. && $curline !~ /^CPE_VENDOR(.)?=[^\n]+$i/m
  1962. && $curline !~ /^CATEGORIES(.)?=[^\n]+$i/m
  1963. && $curline !~ /^(\w+)?USES(.)?=[^\n]+$i/m
  1964. && $curline !~ /^WX_COMPS(.)?=[^\n]+$i/m
  1965. && $curline !~ /^ONLY_FOR_ARCHS_REASON(_[\w\d]+)?(.)?=[^\n]+$i/m
  1966. && $curline !~ /^NOT_FOR_ARCHS_REASON(_[\w\d]+)?(.)?=[^\n]+$i/m
  1967. && $curline !~ /^SHEBANG_FILES(.)?=[^\n]+$i/m
  1968. && $curline !~ /^[\w\d]+_OLD_CMD(.)?=[^\n]+$i/m
  1969. && $curline !~ /^[A-Z0-9_]+_DESC=[^\n]+$i/m
  1970. && $curline !~ /#.*?$i/m
  1971. && $curline !~ /^\s*#.+$/m
  1972. && $curline !~ /\$\{MAKE_CMD\}.*\binstall\b/m
  1973. && $curline !~ /\-\-$i/m
  1974. && $curline !~ /^COMMENT(.)?=[^\n]+$i/m) {
  1975. &perror("WARN", $file, $lineno, "possible direct use of ".
  1976. "command \"$i\" found. use ".
  1977. "$cmdnames{$i} instead.");
  1978. }
  1979. }
  1980. }
  1981. foreach my $i (keys %autocmdnames) {
  1982. # XXX Same hack as above.
  1983. while ($j =~ /^(.*(\b$i\d*).*)$/gm) {
  1984. my $lm = $1;
  1985. my $sm = $2;
  1986. my $lineno = &linenumber($`);
  1987. if ($lm =~ /(^|\s+)[\@\-]{0,2}($i\d*)\b/
  1988. && $lm !~ /^[A-Z]+_TARGET[?+]?=[^\n]+($i\d*)/m
  1989. && $lm !~ /^IGNORE(.)?=[^\n]+($i\d*)/m
  1990. && $lm !~ /^BROKEN(.)?=[^\n]+($i\d*)/m
  1991. && $lm !~ /^RESTRICTED(.)?=[^\n]+($i\d*)/m
  1992. && $lm !~ /^NO_PACKAGE(.)?=[^\n]+($i\d*)/m
  1993. && $lm !~ /^NO_CDROM(.)?=[^\n]+($i\d*)/m
  1994. && $lm !~ /^MAINTAINER(.)?=[^\n]+($i\d*)/m
  1995. && $lm !~ /^WWW(.)?=[^\n]+($i\d*)/m
  1996. && $lm !~ /^CATEGORIES(.)?=[^\n]+($i\d*)/m
  1997. && $lm !~ /^USES(.)?=[^\n]+$i/m
  1998. && $lm !~ /^[A-Z0-9_]+_DESC=[^\n]+($i\d*)/m
  1999. && $lm !~ /^SHEBANG_FILES(.)?=[^\n]+($i\d*)/m
  2000. && $lm !~ /^USE_AUTOTOOLS(.)?=[^\n]+($i\d*)/m
  2001. && $lm !~ /^\s*#.+$/m
  2002. && $lm !~ /^COMMENT(.)?=[^\n]+($i\d*)/m) {
  2003. &perror("WARN", $file, $lineno, "possible direct use of ".
  2004. "command \"$sm\" found. Use $autocmdnames{$i} ".
  2005. "instead and set USES=autoreconf and GNU_CONFIGURE=yes");
  2006. }
  2007. }
  2008. }
  2009. if ($makevar{'USE_AUTOTOOLS'} =~ /\blibtool\b/) {
  2010. &perror("WARN", $file, -1, "USE_AUTOTOOLS=libtool is deprecated. ".
  2011. "Use USES=libtool instead.");
  2012. }
  2013. if ($makevar{'USE_AUTOTOOLS'} =~ /\blibtoolize\b/) {
  2014. &perror("WARN", $file, -1, "USE_AUTOTOOLS=libtoolize is deprecated. ".
  2015. "Use \"USES=autoreconf libtool\" instead.");
  2016. } elsif ($makevar{'USE_AUTOCONF'}) {
  2017. &perror("WARN", $file, -1, "USE_AUTOTOOLS is deprecated. ".
  2018. "Use USES=autoreconf and set GNU_CONFIGURE=yes instead.");
  2019. }
  2020. #
  2021. # whole file: check for use of paths that have macro replacements
  2022. #
  2023. my %pathnames = ();
  2024. print "OK: checking for paths that have macro replacements.\n"
  2025. if ($verbose);
  2026. $pathnames{'$\{PREFIX\}/share/java/classes'} = 'JAVADIR';
  2027. $pathnames{'$\{PREFIX\}/share/java'} = 'JAVASHAREDIR';
  2028. foreach my $i (keys %pathnames) {
  2029. my $lineno = &linenumber($`);
  2030. if ($j =~ m|$i|gm) {
  2031. &perror("FATAL", $file, $lineno, "you should use ".
  2032. "$pathnames{$i} rather than $i");
  2033. }
  2034. }
  2035. #
  2036. # whole file: ${GZIP_CMD} -9 (or any other number)
  2037. #
  2038. print "OK: checking for compression arguments passed to \${GZIP_CMD}.\n"
  2039. if ($verbose);
  2040. if ($j =~ /\$\{GZIP_CMD}\s+-(\w+(\s+-)?)*(\d)/) {
  2041. my $lineno = &linenumber($`);
  2042. &perror("WARN", $file, $lineno, "possible use of \"\${GZIP_CMD} -$3\" ".
  2043. "found. \${GZIP_CMD} includes \"-\${GZIP}\" which ".
  2044. "sets the compression level.");
  2045. }
  2046. #
  2047. # whole file: ${CHMOD} used
  2048. #
  2049. print "OK: checking for \${CHMOD}.\n" if ($verbose);
  2050. if ($j =~ /\n\s*\$\{CHMOD}/) {
  2051. my $lineno = &linenumber($`);
  2052. &perror("WARN", $file, $lineno, "possible use of \"\${CHMOD}\" ".
  2053. "found. Use @(owner,group,mode) syntax or \@owner/\@group ".
  2054. "operators in pkg-plist instead.");
  2055. }
  2056. #
  2057. # whole file: ${INSTALL} -o | -g used
  2058. #
  2059. print "OK: checking for \${INSTALL} -o | -g.\n" if ($verbose);
  2060. if ($j =~ /\n\s*\$\{INSTALL}(.*-\b(o|g)\b.*)/) {
  2061. my $lineno = &linenumber($`);
  2062. &perror("WARN", $file, $lineno, "possible use of \"\${INSTALL} -o | -g\" ".
  2063. "found. Use @(owner,group,mode) syntax or \@owner/\@group ".
  2064. "operators in pkg-plist instead.");
  2065. }
  2066. #
  2067. # whole file: ${MKDIR} -p
  2068. #
  2069. print "OK: checking for \${MKDIR} -p.\n"
  2070. if ($verbose);
  2071. if ($j =~ /\$\{MKDIR}\s+-p/) {
  2072. my $lineno = &linenumber($`);
  2073. &perror("WARN", $file, $lineno, "possible use of \"\${MKDIR} -p\" ".
  2074. "found. \${MKDIR} includes ".
  2075. "\"-p\" by default.");
  2076. }
  2077. #
  2078. # check for use of ${FIND} ... ${XARGS} ${RM}
  2079. #
  2080. print "OK: checking for instances of \${FIND} ... \${XARGS} \${RM}.\n"
  2081. if ($verbose);
  2082. if ($j =~ /\$\{FIND\}.*\|.*\$\{XARGS\}.*\$\{RM\}/) {
  2083. my $lineno = &linenumber($`);
  2084. &perror("WARN", $file, $lineno, "possible use of ".
  2085. "\"\${FIND} ... \${XARGS} \${RM}\" when ".
  2086. "\"\${FIND} ... -delete\" will work.");
  2087. }
  2088. #
  2089. # whole file: ${MACHINE_ARCH}
  2090. #
  2091. print "OK: checking for instances of \${MACHINE_ARCH} being test.\n"
  2092. if ($verbose);
  2093. if ($j =~ /\$\{MACHINE_ARCH}\s*[!=]=/) {
  2094. my $lineno = &linenumber($`);
  2095. &perror("FATAL", $file, $lineno, "MACHINE_ARCH should never be tested ".
  2096. "directly; use ARCH instead.");
  2097. }
  2098. #
  2099. # whole file: full path name
  2100. #
  2101. &abspathname($whole, $file);
  2102. #
  2103. # whole file: SITE_PERL
  2104. #
  2105. print "OK: checking SITE_PERL.\n" if ($verbose);
  2106. if ($whole =~ /\nSITE_PERL[?:]?=/) {
  2107. my $lineno = &linenumber($`);
  2108. &perror("FATAL", $file, $lineno, "use of SITE_PERL discouraged. ".
  2109. "it is set in bsd.port.mk.");
  2110. }
  2111. #
  2112. # whole file: ${LOCALBASE}/lib/perl5/site_perl
  2113. #
  2114. if ($j =~ m'\$\{(?:LOCALBASE|PREFIX)}/lib/perl5/site_perl') {
  2115. my $lineno = &linenumber($`);
  2116. if ($1 !~ /PREFIX/) {
  2117. &perror("WARN", $file, $lineno, "possible use of \"\${LOCALBASE}/lib/perl5/site_perl\" ".
  2118. "found. use \"\${SITE_PERL}\" instead.");
  2119. } else {
  2120. &perror("WARN", $file, $lineno, "possible use of \"\${PREFIX}/lib/perl5/site_perl\" ".
  2121. "found. use \"\${PREFIX}/\${SITE_PERL_REL}\" instead.");
  2122. }
  2123. }
  2124. #
  2125. # whole file: check for misuse of STAGE with SITE_PERL and SITE_ARCH
  2126. #
  2127. if ($j =~ m'\$\{STAGEDIR}\$\{SITE_PERL}') {
  2128. my $lineno = &linenumber($`);
  2129. &perror("WARN", $file, $lineno, "\${STAGEDIR}\${SITE_PERL} should be ".
  2130. "replaced by \${STAGEDIR}\${PREFIX}/\${SITE_PERL_REL}.");
  2131. }
  2132. if ($j =~ m'\$\{STAGEDIR}\$\{SITE_ARCH}') {
  2133. my $lineno = &linenumber($`);
  2134. &perror("WARN", $file, $lineno, "\${STAGEDIR}\${SITE_ARCH} should be ".
  2135. "replaced by \${STAGEDIR}\${PREFIX}/\${SITE_ARCH_REL}.");
  2136. }
  2137. #
  2138. # whole file: USE_GNOME check
  2139. #
  2140. if ($whole =~ /^USE_GNOME[?:]?=\s*(.*)$/m) {
  2141. if ($1 =~ /gnomehack/) {
  2142. $use_gnome_hack = 1;
  2143. }
  2144. }
  2145. #
  2146. # whole file: USE_KDE check
  2147. #
  2148. if ($whole =~ /^USE_KDE[?:]?=\s*(.*)$/m) {
  2149. if ($makevar{USES} !~ /\bkde:[45]/) {
  2150. my $lineno = &linenumber($`);
  2151. &perror("WARN", $file, $lineno, "USE_KDE is defined without ".
  2152. "defining USES=kde:[45]");
  2153. }
  2154. }
  2155. #
  2156. # whole file: USES=pyqt:5
  2157. #
  2158. if ($makevar{USES} =~ /\bpyqt:5/ && $whole !~ /^USE_PYQT[?:]?=\s(.*)$/m && $makevar{USE_PYQT} eq '') {
  2159. &perror("WARN", $file, -1, "When USES=pyqt:5 is defined, you must also define ".
  2160. "USE_PYQT=xxxx");
  2161. }
  2162. #
  2163. # whole file: USE_GCC checks
  2164. #
  2165. if ($whole =~ /^USE_GCC[?:]?=\s*([^\s#]*).*$/m) {
  2166. my $lineno = &linenumber($`);
  2167. my $gcc_val = $1;
  2168. if ($gcc_val eq 'any' || $gcc_val eq 'yes') {
  2169. # Just accept these two.
  2170. } elsif ($gcc_val !~ /\+/) {
  2171. &perror("WARN", $file, $lineno, "Setting a specific version for ".
  2172. "USE_GCC should only be done as a last resort. Unless you ".
  2173. "have confirmed this port does not build with later ".
  2174. "versions of GCC, please use USE_GCC=$gcc_val+.");
  2175. }
  2176. }
  2177. #
  2178. # whole file: USE_JAVA check
  2179. #
  2180. if ($whole =~ /^USE_JAVA[?:]?=\s*(.*)$/m) {
  2181. $use_java = 1;
  2182. }
  2183. #
  2184. # whole file: USE_ANT check
  2185. #
  2186. if ($whole =~ /^USE_ANT[?:]?=\s*(.*)$/m) {
  2187. $use_ant = 1;
  2188. }
  2189. #
  2190. # whole file: USE_JAVA not defined, but other Java components are requested
  2191. #
  2192. if (!$use_java && ($use_ant || $whole =~ /^JAVA_VERSION[?:]?=\s*(.*)$/m ||
  2193. $whole =~ /^JAVA_OS[?:]?=\s*(.*)$/m ||
  2194. $whole =~ /^JAVA_VENDOR[?:]?=\s*(.*)$/m ||
  2195. $whole =~ /^JAVA_RUN[?:]?=\s*(.*)$/m ||
  2196. $whole =~ /^JAVA_BUILD[?:]?=\s*(.*)$/m)) {
  2197. &perror("FATAL", $file, -1, "the port uses Java features, but USE_JAVA ".
  2198. "is not defined");
  2199. }
  2200. #
  2201. # whole file: check for USE_ANT and USES=gmake both defined
  2202. #
  2203. if ($use_ant && $makevar{USES} =~ /\bgmake\b/) {
  2204. &perror("WARN", $file, -1, "a port shall not define both USE_ANT ".
  2205. "and USES[+]=gmake");
  2206. }
  2207. #
  2208. # whole file: check for USE_APACHE=yes
  2209. #
  2210. if ($whole =~ /^USE_APACHE[?:]?=\s*(yes)$/m) {
  2211. &perror("FATAL", $file, -1, "Use USE_APACHE=VERSION ".
  2212. "(where version can be found in \${PORTSDIR}/Mk/bsd.apache.mk) ".
  2213. "instead of yes");
  2214. }
  2215. #
  2216. # whole file: check for WITH_APACHE\d+
  2217. #
  2218. if ($whole =~ /WITH_APACHE\d+/) {
  2219. &perror("FATAL", $file, -1, "Use WITH_APACHE=yes and .if ".
  2220. "\${APACHE_VERSION} [==|<|>] 13|20|22|24");
  2221. }
  2222. #
  2223. # whole file: check for JAVA_BUILD and NO_BUILD
  2224. #
  2225. if ($whole =~ /^NO_BUILD[?:]?=\s*(.*)$/m &&
  2226. $whole =~ /^JAVA_BUILD[?:]?=\s*(.*)$/m) {
  2227. &perror("FATAL", $file, -1, "JAVA_BUILD and NO_BUILD cannot be set ".
  2228. "at the same time");
  2229. }
  2230. #
  2231. # whole file: check for reassignment of ECHO_MSG
  2232. #
  2233. if ($whole =~ /^ECHO_MSG[?:]?=\s*(.*)$/m) {
  2234. &perror("FATAL", $file, -1, "Re-assigning ECHO_MSG can break ".
  2235. "``make readme''. Consider using \${PRINTF} directly instead ".
  2236. "for custom message output.");
  2237. }
  2238. #
  2239. # whole file: check for --build, --mandir, and --infodir
  2240. # when GNU_CONFIGURE
  2241. #
  2242. if ($makevar{GNU_CONFIGURE} ne '' &&
  2243. $makevar{CONFIGURE_ARGS} =~ /--(build|(man|info)dir)/) {
  2244. &perror("WARN", $file, -1, "--build, --mandir, and --infodir ".
  2245. "are not needed in CONFIGURE_ARGS as they are already set in ".
  2246. "bsd.port.mk.");
  2247. }
  2248. #
  2249. # whole file: check for redundant SHEBANG_LANGs
  2250. #
  2251. if ($whole =~ /^SHEBANG_LANG[?+]?=\s*(.*)$/m) {
  2252. my $sh_lang = $1;
  2253. my @shebang_langs = split(/\s+/, $makevar{SHEBANG_LANG} // '');
  2254. my %sh_seen = ();
  2255. foreach my $shebang_lang (@shebang_langs) {
  2256. if ($sh_seen{$shebang_lang}) {
  2257. $sh_seen{$shebang_lang}++;
  2258. } else {
  2259. $sh_seen{$shebang_lang} = 1;
  2260. }
  2261. if ($sh_seen{$shebang_lang} > 1 && $sh_lang =~ /\b$shebang_lang\b/) {
  2262. &perror("WARN", $file, -1, "$shebang_lang is already included in ".
  2263. "SHEBANG_LANG. You should remove this from $file.");
  2264. }
  2265. }
  2266. }
  2267. #
  2268. # whole file: CONFIGURE_ENV
  2269. #
  2270. if ($whole =~ /\nCONFIGURE_ENV[?:+]?=\s*([^\\\n]+(\\\n[^\\\n]+)*)/) {
  2271. my $configure_env = $1;
  2272. my $cflags = undef;
  2273. my $cxxflags = undef;
  2274. if ($configure_env =~ /\bCFLAGS="([^"]+)"/ ||
  2275. $configure_env =~ /\bCFLAGS='([^']+)'/ ||
  2276. $configure_env =~ /\bCFLAGS=(\S+)/) {
  2277. $cflags = $1;
  2278. }
  2279. if ($configure_env =~ /\bCXXFLAGS="([^"]+)"/ ||
  2280. $configure_env =~ /\bCXXFLAGS='([^']+)'/ ||
  2281. $configure_env =~ /\bCXXFLAGS=(\S+)/) {
  2282. $cxxflags = $1;
  2283. }
  2284. if (defined($cflags) || defined($cxxflags)) {
  2285. &perror("WARN", $file, -1, "CFLAGS/CXXFLAGS are not needed in ".
  2286. "CONFIGURE_ENV as they are already added there in bsd.port.mk.");
  2287. }
  2288. if ($makevar{GNU_CONFIGURE} ne '') {
  2289. if ((defined($cflags) && $cflags =~ /-I/) ||
  2290. (defined($cxxflags) && $cxxflags =~ /-I/)) {
  2291. &perror("WARN", $file, -1, "Consider passing include paths ".
  2292. "to configure via the CPPFLAGS macro ".
  2293. "(i.e. CPPFLAGS+=-I...)");
  2294. }
  2295. }
  2296. if (defined($cflags) && $cflags !~ /\$\{CFLAGS/) {
  2297. &perror("FATAL", $file, -1, "CFLAGS are clobbered in ".
  2298. "CONFIGURE_ENV. Alter CFLAGS in the Makefile with ".
  2299. "CFLAGS+=... instead");
  2300. }
  2301. if (defined($cxxflags) && $cxxflags !~ /\$\{CXXFLAGS/) {
  2302. &perror("FATAL", $file, -1, "CXXFLAGS are clobbered in ".
  2303. "CONFIGURE_ENV. Alter CXXFLAGS in the Makefile with ".
  2304. "CXXFLAGS+=... instead");
  2305. }
  2306. if ($configure_env =~ /(FC)=/ ||
  2307. $configure_env =~ /(F77)=/ ||
  2308. $configure_env =~ /(FFLAGS)=/) {
  2309. &perror("FATAL", $file, -1, "$1 is already ".
  2310. "passed in CONFIGURE_ENV via bsd.gcc.mk. If you need to ".
  2311. "override the default value, alter $1 in the Makefile ".
  2312. "instead with $1=...");
  2313. }
  2314. if ($configure_env =~ /(\bCPPFLAGS)=/) {
  2315. &perror("FATAL", $file, -1, "$1 is already ".
  2316. "passed in CONFIGURE_ENV via bsd.port.mk. If you need to ".
  2317. "override the default value, alter $1 in the Makefile ".
  2318. "instead with $1+=...");
  2319. }
  2320. if ($configure_env =~ /(\bLDFLAGS)=/) {
  2321. &perror("FATAL", $file, -1, "$1 is already passed in ".
  2322. "CONFIGURE_ENV via bsd.port.mk. If you need to ".
  2323. "override the default value, alter $1 in the Makefile ".
  2324. "instead with $1+=...");
  2325. }
  2326. }
  2327. #
  2328. # whole file: *FLAGS
  2329. #
  2330. foreach my $f (qw(CFLAGS CXXFLAGS CPPFLAGS LDFLAGS)) {
  2331. if ($whole =~ /^$f=/m) {
  2332. &perror("WARN", $file, -1, "$f is overridden in the Makefile ".
  2333. "clobbering a value possibly set by a user. Consider ".
  2334. "using $f+=... if you want to add or $f:=\${$f:C/...//} ".
  2335. "if you want to remove specific flags");
  2336. }
  2337. }
  2338. #
  2339. # whole file: MAKE_ENV
  2340. #
  2341. if ($whole =~ /\nMAKE_ENV[?:+]?=\s*([^\\\n]+(\\\n[^\\\n]+)*)/) {
  2342. my $make_env = $1;
  2343. if ($make_env =~ /(CPPFLAGS)=/) {
  2344. &perror("FATAL", $file, -1, "$1 is already ".
  2345. "passed in MAKE_ENV via bsd.port.mk. If you need to ".
  2346. "override the default value, alter $1 in the Makefile ".
  2347. "instead with $1=...");
  2348. }
  2349. }
  2350. #
  2351. # slave port check
  2352. #
  2353. if ($slaveport) {
  2354. print "OK: slave port detected, checking for inclusion of $masterdir/Makefile.\n"
  2355. if ($verbose);
  2356. if ($whole =~ /^\.\s*include\s*[<"]bsd\.port(?:\.post)?\.mk[">]/m) {
  2357. &perror("FATAL", $file, -1, "supposedly non-slave port with".
  2358. " .CURDIR != MASTERDIR");
  2359. } elsif ($whole =~ /^\.\s*include\s*[<"]bsd\.port\.pre\.mk[">]/m) {
  2360. &perror("FATAL", $file, -1, "slave ports may not include".
  2361. " bsd.port.pre.mk");
  2362. }
  2363. if ($whole !~ /\n\.include\s+"\$\{MASTERDIR\}\/Makefile"\s*$/s) {
  2364. &perror("FATAL", $file, -1, "the last line of a slave port's Makefile has to be".
  2365. ' .include "${MASTERDIR}/Makefile"');
  2366. }
  2367. print "OK: checking master port in $masterdir.\n" if ($verbose);
  2368. if (! -e "$masterdir/Makefile") {
  2369. &perror("WARN", "", -1, "unable to locate master port in $masterdir");
  2370. }
  2371. if ($whole !~ /^MASTERDIR=\s*\$\{\.CURDIR\}(?:\/\.\.){1,2}(?:\/[\w\@.+-]+){1,2}\s*$/m) {
  2372. &perror("WARN", $file, -1, "slave ports must define MASTERDIR=".
  2373. '${.CURDIR}/..(/../<category>)/<port>');
  2374. }
  2375. } else {
  2376. #$slaveport = 0;
  2377. print "OK: non-slave port detected, checking for anything after bsd.port(.post).mk.\n"
  2378. if ($verbose);
  2379. if ($whole !~ /\n\.include\s+<bsd\.port(?:\.post)?\.mk>\s*$/s &&
  2380. $whole !~ /\n\.endif\s*$/s) {
  2381. &perror("FATAL", $file, -1, "the last line of Makefile has to be".
  2382. ' .include <bsd.port(.post).mk> (or .endif in the case of a conditional)');
  2383. }
  2384. if ($whole =~ /^MASTERDIR\s*[+?:!]?\s*=/m) {
  2385. &perror("WARN", $file, -1, "non-slave ports may not define MASTERDIR");
  2386. }
  2387. }
  2388. #
  2389. # break the makefile into sections.
  2390. #
  2391. $tmp = $rawwhole;
  2392. $tmp =~ s/\\\n/ /g;
  2393. # keep comment, blank line, comment in the same section
  2394. # XXX: Take this out since it breaks some commenting; see PR240359.
  2395. #$tmp =~ s/(#.*\n)\n+(#.*)/$1$2/g;
  2396. @sections = split(/\n\n+/, $tmp);
  2397. for ($i = 0; $i <= $#sections; $i++) {
  2398. if ($sections[$i] !~ /\n$/) {
  2399. $sections[$i] .= "\n";
  2400. }
  2401. }
  2402. $idx = 0;
  2403. my @linestocheck = ();
  2404. # check if all lines in the first section are comments
  2405. if (grep(/^#/, split(/\n/, $sections[$idx])) == split(/\n/, $sections[$idx])) {
  2406. #
  2407. # section 1: comment lines.
  2408. #
  2409. print "OK: checking comment section of $file.\n" if ($verbose);
  2410. @linestocheck = split("\n", <<EOF);
  2411. Whom
  2412. Date [cC]reated
  2413. EOF
  2414. $tmp = $sections[$idx++];
  2415. $tmp = "\n" . $tmp; # to make the begin-of-line check easier
  2416. if ($tmp =~ /\n[^#]/) {
  2417. &perror("FATAL", $file, -1, "non-comment line in comment section.");
  2418. }
  2419. if ($tmp =~ m/Version [rR]equired/) {
  2420. &perror("WARN", $file, -1, "Version required is no longer needed in the comment section.");
  2421. }
  2422. }
  2423. #
  2424. # for the rest of the checks, comment lines are not important.
  2425. #
  2426. for ($i = 0; $i < scalar(@sections); $i++) {
  2427. $sections[$i] = "\n" . $sections[$i];
  2428. $sections[$i] =~ s/\n#[^\n]*//g;
  2429. $sections[$i] =~ s/\n\n+/\n/g;
  2430. $sections[$i] =~ s/^\n//;
  2431. }
  2432. #
  2433. # section 2: PORTNAME/PORTVERSION/...
  2434. #
  2435. print "OK: checking first section of $file (PORTNAME/...).\n"
  2436. if ($verbose);
  2437. $tmp = $sections[$idx++];
  2438. # check the order of items.
  2439. &checkorder('PORTNAME', $tmp, $file, qw(
  2440. PORTNAME PORTVERSION DISTVERSIONPREFIX DISTVERSION DISTVERSIONSUFFIX
  2441. PORTREVISION PORTEPOCH CATEGORIES MASTER_SITES MASTER_SITE_SUBDIR
  2442. PROJECTHOST PKGNAMEPREFIX PKGNAMESUFFIX DISTNAME EXTRACT_SUFX DISTFILES(_\w+)?
  2443. DIST_SUBDIR EXTRACT_ONLY
  2444. ));
  2445. # check the items that has to be there.
  2446. $tmp = "\n" . $tmp;
  2447. print "OK: checking PORTNAME/PORTVERSION/DISTVERSION.\n" if ($verbose);
  2448. if ($tmp !~ /\nPORTNAME(.)?=/) {
  2449. &perror("FATAL", $file, -1, "PORTNAME has to be there.") unless ($slaveport && $makevar{PORTNAME} ne '');
  2450. } elsif (defined $1 && $1 ne '') {
  2451. &perror("WARN", $file, -1, "unless this is a master port, PORTNAME has to be set by \"=\", ".
  2452. "not by \"$1=\".") unless ($masterport);
  2453. }
  2454. if ($tmp !~ /\n(PORTVERSION|DISTVERSION)(.)?=/) {
  2455. &perror("FATAL", $file, -1, "PORTVERSION or DISTVERSION has to be there.") unless (($makevar{PORTVERSION} ne '' || $makevar{DISTVERSION} ne ''));
  2456. if (!$slaveport && ($makevar{PORTVERSION} ne '' || $makevar{DISTVERSION} ne '')) {
  2457. &perror("WARN", $file, -1, "PORTVERSION/DISTVERSION is set externally to this port's Makefile, but this port is not configured as a slave port.");
  2458. }
  2459. } elsif (defined $2 && $2 ne '') {
  2460. &perror("WARN", $file, -1, "unless this is a master port, PORTVERSION has to be set by \"=\", ".
  2461. "not by \"$2=\".") unless ($masterport);
  2462. }
  2463. if ($tmp =~ /\nPORTVERSION.?=/ && $tmp =~ /\nDISTVERSION.?=/) {
  2464. &perror("FATAL", $file, -1, "either PORTVERSION or DISTVERSION must be ".
  2465. "specified, not both.");
  2466. }
  2467. if ($newport) {
  2468. print "OK: checking for existence of PORTREVISION in new port.\n"
  2469. if ($verbose);
  2470. if ($tmp =~ /^PORTREVISION(.)?=/m) {
  2471. &perror("WARN", $file, -1, "new ports should not set PORTREVISION.");
  2472. }
  2473. } elsif (!$slaveport) {
  2474. print "OK: checking for PORTREVISION=0.\n" if ($verbose);
  2475. if ($tmp =~ /^PORTREVISION=\s*0/m) {
  2476. &perror("WARN", $file, -1, "Setting PORTREVISION to 0 is not ".
  2477. "necessary.");
  2478. }
  2479. }
  2480. if ($newport) {
  2481. print "OK: checking for existence of PORTEPOCH in new port.\n"
  2482. if ($verbose);
  2483. if ($tmp =~ /^PORTEPOCH(.)?=/m) {
  2484. &perror("WARN", $file, -1, "new ports should not set PORTEPOCH.");
  2485. }
  2486. }
  2487. print "OK: checking CATEGORIES.\n" if ($verbose);
  2488. if ($tmp !~ /\nCATEGORIES(.)?=/) {
  2489. &perror("FATAL", $file, -1, "CATEGORIES has to be there.") unless ($makevar{CATEGORIES} ne '');
  2490. if (!$slaveport && $makevar{CATEGORIES} ne '') {
  2491. &perror("WARN", $file, -1, "CATEGORIES is set externally to this port's Makefile, but this port is not configured as a slave port.");
  2492. }
  2493. } elsif (defined $1 && ($i = $1) ne '' && $i =~ /[^?+]/) {
  2494. &perror("WARN", $file, -1, "unless this is a master port, CATEGORIES should be set by \"=\", \"?=\", or \"+=\", ".
  2495. "not by \"$i=\".") unless ($masterport);
  2496. }
  2497. @cat = split(/\s+/, $makevar{CATEGORIES});
  2498. if (@cat == 0) {
  2499. &perror("FATAL", $file, -1, "CATEGORIES left blank. set it to \"misc\"".
  2500. " if nothing seems apropriate.");
  2501. } else {
  2502. my %seencat = ();
  2503. foreach my $cat (@cat) {
  2504. if ($seencat{$cat}) {
  2505. &perror("WARN", $file, -1, "Duplicate category, $cat specified".
  2506. " in CATEGORIES.");
  2507. } else {
  2508. $seencat{$cat} = 1;
  2509. }
  2510. }
  2511. }
  2512. if ($use_java && !grep /^java$/, @cat) {
  2513. &perror("WARN", $file, -1, "the port uses Java but is not part of the ".
  2514. "``java'' category");
  2515. }
  2516. if (scalar(@cat) == 1 && $cat[0] eq "java") {
  2517. &perror("FATAL", $file, -1, "the ``java'' category shall not be the only ".
  2518. "one for a port");
  2519. }
  2520. if ($newport && scalar(@cat) > 0 && $cat[0] eq "java") {
  2521. &perror("WARN", $file, -1, "save for ports directly related to the Java ".
  2522. "language, porters are encouraged not to use ``java'' as ".
  2523. "the main category for a port");
  2524. }
  2525. if ($committer && $makevar{'.CURDIR'} =~ m/\Q${portsdir}\E\/([^\/]+)\/[^\/]+\/?$/) {
  2526. if ($cat[0] ne $1 && $makevar{PKGCATEGORY} ne $1 ) {
  2527. &perror("FATAL", $file, -1, "category \"$1\" must be listed first");
  2528. }
  2529. }
  2530. #MICHAEL: can these three lang cat checks be combined?
  2531. # skip the first category specification if it's a language specific one.
  2532. if (grep($_ eq $cat[0], @lang_cat)) {
  2533. $has_lang_cat = 1;
  2534. $port_lang = $lang_pref{$cat[0]};
  2535. shift @cat;
  2536. }
  2537. # skip further if more language specific ones follow.
  2538. if (@cat && grep($_ eq $cat[0], @lang_cat)) {
  2539. &perror("WARN", $file, -1, "multiple language specific categories detected. ".
  2540. "are you sure?");
  2541. do {
  2542. shift @cat;
  2543. } while (@cat && grep($_ eq $cat[0], @lang_cat));
  2544. }
  2545. # check x11 in CATEGORIES
  2546. #MICHAEL: I don't understand this line
  2547. if (2 <= @cat && $cat[1] eq "x11") {
  2548. &perror("WARN", $file, -1, "only specific kind of apps should ".
  2549. "specify \"x11\" in CATEGORIES. ".
  2550. "Do you mean just USE_XORG? ".
  2551. "Then remove \"x11\" from CATEGORIES.");
  2552. }
  2553. if (2 <= @cat) {
  2554. # skip the first one that we know is _not_ language specific.
  2555. shift @cat;
  2556. # any language specific one after non language specific ones?
  2557. foreach my $cat (@cat) {
  2558. if (grep($_ eq $cat, @lang_cat)) {
  2559. $has_lang_cat = 1;
  2560. $port_lang = $lang_pref{$cat};
  2561. &perror("WARN", $file, -1, "when you specify multiple categories, ".
  2562. "language specific category should come first.");
  2563. }
  2564. }
  2565. }
  2566. # check the URL
  2567. if (($tmp =~ /\nMASTER_SITES[+?]?=[ \t]*([^\n]*)\n/
  2568. && $1 !~ /^[ \t]*$/) || ($makevar{MASTER_SITES} ne '')) {
  2569. print "OK: seen MASTER_SITES, sanity checking URLs.\n"
  2570. if ($verbose);
  2571. my $urlseen = 0;
  2572. my @sites = split(/\s+/, $1 // '');
  2573. my $ftphttp = 0;
  2574. foreach my $i (@sites) {
  2575. last if ($i =~ /^#/);
  2576. if ($i =~ m#^\w+://#) {
  2577. $urlseen = 1;
  2578. $ftphttp = 1 if ($i =~ /^(ftp|http):/);
  2579. &urlcheck($i, $file);
  2580. unless (&is_predefined($i, $file)) {
  2581. print "OK: URL \"$i\" ok.\n"
  2582. if ($verbose);
  2583. }
  2584. } else {
  2585. my $good_ms = 1;
  2586. foreach my $mss (split(/\s+/, $makevar{MASTER_SITES_SUBDIRS})) {
  2587. my ($ms, $sd) = split(/:/, $mss);
  2588. if ($i =~ /^$ms/ && $i ne $ms) {
  2589. my $ip = $i;
  2590. $ip =~ s/^$ms\///;
  2591. my (@ip_parts) = split(/:/, $ip);
  2592. my $check_var = $ip_parts[0];
  2593. shift(@ip_parts);
  2594. foreach my $check_part (@ip_parts) {
  2595. if ($check_part =~ /^[A-Z]}/) {
  2596. $check_var .= ":$check_part";
  2597. }
  2598. }
  2599. my $exp_sd = get_makevar($check_var);
  2600. if ($exp_sd eq $sd) {
  2601. &perror("WARN", $file, -1, "typically when you specify magic site $ms ".
  2602. "you do not need anything else as $sd is assumed");
  2603. $good_ms = 0;
  2604. }
  2605. }
  2606. }
  2607. if ($good_ms) {
  2608. print "OK: non-URL \"$i\" ok.\n"
  2609. if ($verbose);
  2610. }
  2611. # Assume variables contain an ftp/http site.
  2612. $ftphttp = 1;
  2613. }
  2614. }
  2615. } else {
  2616. &perror("WARN", $file, -1, "no MASTER_SITES found. is it ok?");
  2617. }
  2618. # check DISTFILES and related items.
  2619. $distfiles = $1 if ($tmp =~ /\nDISTFILES[?]?=[ \t]*([^\n]+)\n/);
  2620. $all_distfiles = $1 if ($tmp =~ /\nDISTFILES[+?]?=[ \t]*([^\n]+)\n/);
  2621. $portname = $makevar{PORTNAME};
  2622. $portversion = $makevar{PORTVERSION};
  2623. $distversionprefix = $makevar{DISTVERSIONPREFIX};
  2624. $distversion = $makevar{DISTVERSION};
  2625. $distversionsuffix = $makevar{DISTVERSIONSUFFIX};
  2626. $distname = $1 if ($tmp =~ /\nDISTNAME[+?]?=[ \t]*([^\n]+)\n/);
  2627. $extractsufx = $1 if ($tmp =~ /\nEXTRACT_SUFX[+?]?=[ \t]*([^\n]+)\n/);
  2628. # check bogus EXTRACT_SUFX.
  2629. if ($extractsufx ne '') {
  2630. print "OK: seen EXTRACT_SUFX, checking value.\n" if ($verbose);
  2631. if ($all_distfiles ne '') {
  2632. &perror("WARN", $file, -1, "no need to define EXTRACT_SUFX if ".
  2633. "DISTFILES is defined.");
  2634. }
  2635. if ($extractsufx eq '.tar.gz') {
  2636. &perror("WARN", $file, -1, "EXTRACT_SUFX is \".tar.gz.\" ".
  2637. "by default. you don't need to specify it.");
  2638. }
  2639. if ($extractsufx =~ /^\.tar\.(bz2|lzma|xz|Z)$/) {
  2640. my $ext = $1;
  2641. $ext = 'bzip2' if ($ext eq 'bz2');
  2642. &perror("WARN", $file, -1, "EXTRACT_SUFX is \".tar.$ext\". ".
  2643. "Please use USES=tar:$ext instead.");
  2644. }
  2645. if ($extractsufx =~ /^\.(tgz|tbz|txz)$/) {
  2646. &perror("WARN", $file, -1, "EXTRACT_SUFX is \".$1\". ".
  2647. "Please use USES=tar:$1 instead.");
  2648. }
  2649. if ($extractsufx eq '.zip') {
  2650. &perror("WARN", $file, -1, "EXTRACT_SUFX is \".zip\" ".
  2651. "You should use USES[+]=zip instead.");
  2652. }
  2653. } else {
  2654. print "OK: no EXTRACT_SUFX seen, using default value.\n"
  2655. if ($verbose);
  2656. $extractsufx = '.tar.gz';
  2657. }
  2658. print "OK: sanity checking PORTNAME/PORTVERSION/DISTVERSIONPREFIX/DISTVERSION/DISTVERSIONSUFFIX.\n" if ($verbose);
  2659. if ($distname ne '') {
  2660. my $exp_distname = $makevar{DISTNAME};
  2661. if ($exp_distname eq "$portname-$portversion") {
  2662. &perror("WARN", $file, -1, "DISTNAME is \${PORTNAME}-\${PORTVERSION} by ".
  2663. "default, you don't need to define DISTNAME.");
  2664. } else {
  2665. if ($exp_distname eq "$portname-$distversionprefix$distversion$distversionsuffix") {
  2666. &perror("WARN", $file, -1, "DISTNAME is \${PORTNAME}-\${DISTVERSIONPREFIX}\${DISTVERSION}\${DISTVERSIONSUFFIX} by ".
  2667. "default, you don't need to define DISTNAME.");
  2668. }
  2669. }
  2670. if ($distname =~ /PORTREVISION/) {
  2671. &perror("FATAL", $file, -1, "DISTNAME contains a reference to ".
  2672. "PORTREVISION. You should only be using PORTVERSION");
  2673. }
  2674. if ($distname =~ /PORTEPOCH/) {
  2675. &perror("FATAL", $file, -1, "DISTNAME contains a reference to ".
  2676. "PORTEPOCH. You should only be using PORTVERSION");
  2677. }
  2678. }
  2679. if ($portname =~ /^$re_lang_short/) {
  2680. &perror("FATAL", $file, -1, "language prefix is automatically".
  2681. " set by PKGNAMEPREFIX.".
  2682. " you must remove it from PORTNAME.");
  2683. }
  2684. if ($portname =~ /([|<>=! ])/) {
  2685. &perror("FATAL", $file, -1, "PORTNAME contains the illegal character \"$1\".".
  2686. " You should modify \"$portname\".");
  2687. } elsif ($portname =~ /\$[\{\(].+[\}\)]/) {
  2688. &perror("WARN", $file, -1, "using variable in PORTNAME.".
  2689. " consider using PKGNAMEPREFIX and/or PKGNAMESUFFIX.");
  2690. } elsif ($portname =~ /([^\w._@+-])/) {
  2691. &perror("WARN", $file, -1, "using \"$1\" in PORTNAME.".
  2692. " You should modify \"$portname\".");
  2693. } elsif ($portname =~ /-/ && $distname ne '') {
  2694. &perror("WARN", $file, -1, "using hyphen in PORTNAME.".
  2695. " consider using PKGNAMEPREFIX and/or PKGNAMESUFFIX.");
  2696. }
  2697. if ($portversion eq '' && $distversion eq '') {
  2698. &perror("FATAL", $file, -1, "either PORTVERSION or DISTVERSION must be specified");
  2699. }
  2700. if ($portversion =~ /^pl[0-9]*$/
  2701. || $portversion =~ /^[0-9]*[A-Za-z]?[0-9]*([.+][0-9]*[A-Za-z]?[0-9+]*)*$/) {
  2702. print "OK: PORTVERSION \"$portversion\" looks fine.\n" if ($verbose);
  2703. } elsif ($portversion =~ /^[^\-]*\$[{\(].+[\)}][^\-]*$/) {
  2704. &perror("WARN", $file, -1, "using variable, \"$portversion\", as version ".
  2705. "number");
  2706. } elsif ($portversion =~ /([-,_<>=! #*])/) {
  2707. &perror("FATAL", $file, -1, "PORTVERSION must not contain \"$1\". ".
  2708. "You should modify \"$portversion\".");
  2709. } else {
  2710. &perror("FATAL", $file, -1, "PORTVERSION looks illegal. ".
  2711. "You should modify \"$portversion\".");
  2712. }
  2713. $pkg_version = $makevar{PKG_VERSION};
  2714. $conflicts = $makevar{CONFLICTS};
  2715. if ($makevar{CONFLICTS_BUILD}) {
  2716. $conflicts .= " " if $conflicts;
  2717. $conflicts .= $makevar{CONFLICTS_BUILD};
  2718. }
  2719. if ($makevar{CONFLICTS_INSTALL}) {
  2720. $conflicts .= " " if $conflicts;
  2721. $conflicts .= $makevar{CONFLICTS_INSTALL};
  2722. }
  2723. if ($conflicts) {
  2724. print "OK: checking CONFLICTS.\n" if ($verbose);
  2725. my %seen;
  2726. foreach my $conflict (split ' ', $conflicts) {
  2727. if (not $seen{$conflict}) {
  2728. if ($conflict =~ m/-\[0-9\]\*$/) {
  2729. &perror("WARN", $file, -1, "CONFLICTS definition \"$conflict\" ".
  2730. "ends in redundant version pattern. ".
  2731. "You should remove \"-[0-9]*\" from that pattern.");
  2732. }
  2733. $seen{$conflict} = 1;
  2734. }
  2735. }
  2736. }
  2737. $versiondir = $ENV{VERSIONDIR} // '/var/db/chkversion';
  2738. $indexfile = "$portsdir/$makevar{INDEXFILE}";
  2739. $versionfile = "$versiondir/VERSIONS";
  2740. $useindex = !-r "$versionfile";
  2741. $versionfile = $indexfile
  2742. if $useindex;
  2743. if (-r "$versionfile") {
  2744. print "OK: checking if PORTVERSION is going backwards.\n" if ($verbose);
  2745. open VERSIONS, "<$versionfile";
  2746. while (<VERSIONS>) {
  2747. my($origin, $version) = ('', '');
  2748. chomp;
  2749. next if /^(#|$)/;
  2750. if ($useindex) {
  2751. ($version, $origin) = split /\|/;
  2752. $origin =~ s,^.*/([^/]+/[^/]+)/?$,$1,;
  2753. } else {
  2754. ($origin, $version) = split;
  2755. }
  2756. if ($origin eq $makevar{PKGORIGIN}) {
  2757. my $newversion = $makevar{PKGNAME};
  2758. my $oldversion = $version;
  2759. my $result = '';
  2760. $newversion =~ s/^.*-//;
  2761. $oldversion =~ s/^.*-//;
  2762. $result = `$pkg_version -t '$newversion' '$oldversion'`;
  2763. chomp $result;
  2764. if ($result eq '<') {
  2765. &perror("FATAL", $file, -1, "$makevar{PKGNAME} < $version. ".
  2766. "Choose another PORTVERSION or bump PORTEPOCH.");
  2767. # $backwards{$origin} = "$pkgname{$origin} < $version";
  2768. }
  2769. last;
  2770. }
  2771. }
  2772. close VERSIONS;
  2773. }
  2774. # use INDEX (if present) to check for PKGBASE collisions
  2775. if (-r "$indexfile") {
  2776. open INDEX, "<$portsdir/$makevar{INDEXFILE}";
  2777. while (<INDEX>) {
  2778. my($origin, $pkgbase) = ('', '');
  2779. chomp;
  2780. next if /^(#|$)/;
  2781. ($pkgbase, $origin) = split /\|/;
  2782. $pkgbase =~ s,-[^-]+$,,;
  2783. $origin =~ s,^.*/([^/]+/[^/]+)/?$,$1,;
  2784. if ($pkgbase eq $makevar{PKGBASE} and $origin ne $makevar{PKGORIGIN}) {
  2785. &perror("FATAL", $file, -1, "The package base name \"$makevar{PKGBASE}\" is already in use by the \"$origin\" port. ".
  2786. "Choose another PORTNAME or use a PKGNAMEPREFIX or PKGNAMESUFFIX.");
  2787. }
  2788. }
  2789. close INDEX;
  2790. }
  2791. # verify that all flavors have distinct names
  2792. if ($makevar{FLAVORS}) {
  2793. my %PKGFLAVOR;
  2794. my @FLAVORS = split(/ /, $makevar{FLAVORS});
  2795. my $makeenv_save = $makeenv;
  2796. for my $flavor (@FLAVORS) {
  2797. $makeenv = $makeenv_save . " FLAVOR=$flavor";
  2798. my $pkgbase = &get_makevar("PKGBASE");
  2799. if ($PKGFLAVOR{$pkgbase}) {
  2800. &perror("FATAL", $file, -1, "The flavors \"$PKGFLAVOR{$pkgbase}\" and \"$flavor\" both generate a package named \"$pkgbase\". ".
  2801. "Make the package names unique, e.g., with different PKGNAMEPREFIX or PKGNAMESUFFIX values for each flavor.");
  2802. } else {
  2803. $PKGFLAVOR{$pkgbase} = $flavor;
  2804. }
  2805. }
  2806. my $makeenv = $makeenv_save;
  2807. }
  2808. # if DISTFILES have only single item, it is better to avoid DISTFILES
  2809. # and to use combination of DISTNAME and EXTRACT_SUFX (unless USE_GITHUB
  2810. # or USE_GITLAB is set to nodefault in which case it is fine).
  2811. # example:
  2812. # DISTFILES=package-1.0.tgz
  2813. # should be
  2814. # DISTNAME= package-1.0
  2815. # EXTRACT_SUFX= .tgz
  2816. if ($makevar{USE_GITHUB} ne 'nodefault' && $makevar{USE_GITLAB} ne 'nodefault') {
  2817. if ($distfiles =~ /^\S+$/ && $distfiles !~ /:[^\/:]+$/) {
  2818. $bogusdistfiles++;
  2819. print "OK: seen DISTFILES with single item, checking value.\n"
  2820. if ($verbose);
  2821. &perror("WARN", $file, -1, "use of DISTFILES with single file is ".
  2822. "discouraged. distribution filename should be set by ".
  2823. "DISTNAME and EXTRACT_SUFX.");
  2824. if ($distfiles eq (($distname ne '') ? $distname : "$portname-$portversion") . $extractsufx) {
  2825. &perror("WARN", $file, -1, "definition of DISTFILES not necessary. ".
  2826. "DISTFILES is \${DISTNAME}/\${EXTRACT_SUFX} ".
  2827. "by default.");
  2828. }
  2829. # display advice only in certain cases.
  2830. #MICHAEL: will this work with multiple distfiles in this list? what about
  2831. # doing the same sort of thing for DISTNAME, is it needed?
  2832. if ($distfiles =~ /^\Q$i\E([\-.].+)$/) {
  2833. &perror("WARN", $file, -1, "how about \"EXTRACT_SUFX=$1\"".
  2834. ", instead of DISTFILES?");
  2835. }
  2836. }
  2837. }
  2838. push(@varnames, qw(
  2839. PORTNAME PORTVERSION DISTVERSIONPREFIX DISTVERSION DISTVERSIONSUFFIX
  2840. PORTREVISION PORTEPOCH CATEGORIES MASTER_SITES MASTER_SITE_SUBDIR
  2841. PROJECTHOST PKGNAMEPREFIX PKGNAMESUFFIX DISTNAME EXTRACT_SUFX DISTFILES(_\w+)?
  2842. DIST_SUBDIR EXTRACT_ONLY
  2843. ));
  2844. #
  2845. # section 3: PATCH_SITES/PATCHFILES(optional)
  2846. #
  2847. print "OK: checking second section of $file (PATCH*: optional).\n"
  2848. if ($verbose);
  2849. $tmp = $sections[$idx] // '';
  2850. if ($tmp =~ /(PATCH_SITES|PATCH_SITE_SUBDIR|PATCHFILES|PATCH_DIST_STRIP)/) {
  2851. &checkearlier($file, $tmp, @varnames);
  2852. if ($tmp =~ /PATCH_SITES[?+]?=[^\n]+\n/) {
  2853. print "OK: seen PATCH_SITES.\n" if ($verbose);
  2854. $tmp =~ s/PATCH_SITES[?+]?=[^\n]+\n//;
  2855. }
  2856. if ($tmp =~ /PATCH_SITE_SUBDIR[?+]?=[^\n]+\n/) {
  2857. print "OK: seen PATCH_SITE_SUBDIR.\n" if ($verbose);
  2858. $tmp =~ s/PATCH_SITE_SUBDIR[?+]?=[^\n]+\n//;
  2859. }
  2860. if ($tmp =~ /PATCHFILES[?+]?=[^\n]+\n/) {
  2861. print "OK: seen PATCHFILES.\n" if ($verbose);
  2862. $tmp =~ s/PATCHFILES[?+]?=[^\n]+\n//;
  2863. }
  2864. if ($tmp =~ /PATCH_DIST_STRIP[?+]?=[^\n]+\n/) {
  2865. print "OK: seen PATCH_DIST_STRIP.\n" if ($verbose);
  2866. $tmp =~ s/PATCH_DIST_STRIP[?+]?=[^\n]+\n//;
  2867. }
  2868. &checkextra($tmp, 'PATCH_SITES', $file);
  2869. $idx++;
  2870. }
  2871. push(@varnames, qw(
  2872. PATCH_SITES PATCHFILES PATCH_DIST_STRIP
  2873. ));
  2874. #
  2875. # section 4: MAINTAINER
  2876. #
  2877. print "OK: checking third section of $file (MAINTAINER).\n"
  2878. if ($verbose);
  2879. $tmp = $sections[$idx] // '';
  2880. &checkearlier($file, $tmp, @varnames);
  2881. &checkorder('MAINTAINER', $tmp, $file, qw(
  2882. MAINTAINER COMMENT WWW
  2883. ));
  2884. $tmp = "\n" . $tmp;
  2885. if ($tmp =~ /\nMAINTAINER(\?)?=([^\n]+)/) {
  2886. my $addr = $2;
  2887. if (defined $1 && $1 ne '') {
  2888. &perror("WARN", $file, -1, "unless this is a master port, ".
  2889. "MAINTAINER has to be set by \"=\", ".
  2890. "not by \"$1=\".") unless ($masterport);
  2891. }
  2892. $addr =~ s/^\s*//;
  2893. $addr =~ s/\s*$//;
  2894. if ($addr =~ /[\s,<>()]/) {
  2895. &perror("FATAL", $file, -1, "MAINTAINER should be a single address without comment.");
  2896. }
  2897. if ($addr !~ /^[^\@]+\@[\w\d\-\.]+$/) {
  2898. &perror("FATAL", $file, -1, "MAINTAINER address, $addr, does not appear to be a valid email address.");
  2899. }
  2900. if ($newport && $addr =~ /ports\@freebsd.org/i) {
  2901. &perror("WARN", $file, -1, "new ports should not be maintained by ".
  2902. "ports\@FreeBSD.org.");
  2903. }
  2904. $tmp =~ s/\nMAINTAINER\??=[^\n]+//;
  2905. } elsif ($whole !~ /\nMAINTAINER[?]?=/) {
  2906. &perror("FATAL", $file, -1, "no MAINTAINER listed.") unless ($makevar{MAINTAINER} ne '');
  2907. if (!$slaveport && $makevar{MAINTAINER} ne '') {
  2908. &perror("WARN", $file, -1, "MAINTAINER is set externally to this port's Makefile, but this port is not configured as a slave port.");
  2909. }
  2910. }
  2911. $tmp =~ s/\n\n+/\n/g;
  2912. # check COMMENT
  2913. if ($tmp !~ /\nCOMMENT(.)?=/) {
  2914. &perror("FATAL", $file, -1, "COMMENT has to be there.") unless ($makevar{COMMENT} ne '');
  2915. if (!$slaveport && $makevar{COMMENT} ne '') {
  2916. &perror("WARN", $file, -1, "COMMENT is set externally to this port's Makefile, but this port is not configured as a slave port.");
  2917. }
  2918. } elsif (defined $1 && $1 ne '') {
  2919. &perror("WARN", $file, -1, "unless this is a master port, COMMENT has to be set by \"=\", ".
  2920. "not by \"$1=\".") unless ($masterport);
  2921. } else { # check for correctness
  2922. if (($makevar{COMMENT} !~ /^["\[0-9A-Z]/) || ($makevar{COMMENT} =~ m/\.$/)) { #"
  2923. &perror("WARN", $file, -1, "COMMENT should begin with a capital, and end without a period");
  2924. }
  2925. if (length($makevar{COMMENT}) > 70) {
  2926. &perror("WARN", $file, -1, "COMMENT exceeds 70 characters limit.");
  2927. }
  2928. }
  2929. # check WWW
  2930. if ($tmp !~ /\nWWW.?=\s*(\S+)/) {
  2931. &perror("WARN", $file, -1, "WWW should exist and immediately follow COMMENT.") unless ($makevar{WWW} ne '');
  2932. }
  2933. # check for correctness
  2934. {
  2935. my $wwwurl = $1 // $makevar{WWW};
  2936. if ($wwwurl and $wwwurl !~ m|^https?://|) {
  2937. &perror("WARN", $file, -1, "WWW URL, $wwwurl should begin with \"http://\" or \"https://\".");
  2938. }
  2939. if ($wwwurl =~ m|search.cpan.org|) {
  2940. if ($wwwurl =~ m|^http.?://search.cpan.org/~|) {
  2941. &perror("WARN", $file, -1, "consider changing WWW URL to https://search.cpan.org/dist/$makevar{PORTNAME}/");
  2942. }
  2943. if ($wwwurl =~ m,/$,) {
  2944. &perror("WARN", $file, -1, "end WWW CPAN URL with a \"/\"");
  2945. }
  2946. }
  2947. }
  2948. $idx++;
  2949. push(@varnames, qw(
  2950. MAINTAINER COMMENT WWW
  2951. ));
  2952. #
  2953. # section 5: LICENSE
  2954. #
  2955. print "OK: checking fourth section of $file (LICENSE).\n"
  2956. if ($verbose);
  2957. $tmp = $sections[$idx] // '';
  2958. if ($makevar{LICENSE}) {
  2959. &checkorder('LICENSE', $tmp, $file, qw(
  2960. LICENSE LICENSE_COMB LICENSE_GROUPS(_\w+)? LICENSE_NAME(_\w+)?
  2961. LICENSE_TEXT(_\w+)? LICENSE_FILE(_\w+)? LICENSE_PERMS(_\w+)?
  2962. LICENSE_DISTFILES(_\w+)?
  2963. ));
  2964. # check LICENSE
  2965. if ($makevar{LICENSE} && $makevar{LICENSE} ne '') {
  2966. my $comb = $makevar{LICENSE_COMB} // 'single';
  2967. my @tokens = split(/ /, $makevar{LICENSE});
  2968. if ($comb eq 'single' && scalar(@tokens) > 1) {
  2969. &perror("FATAL", $file, -1, "LICENSE contains multiple licenses but LICENSE_COMB is not set to 'dual' or 'multi'");
  2970. }
  2971. }
  2972. # check value of LICENSE_COMB
  2973. if ($makevar{LICENSE_COMB} && $makevar{LICENSE_COMB} !~ /^(single|dual|multi$)/) {
  2974. &perror("FATAL", $file, -1, "LICENSE_COMB contains invalid value '$1' - must be one of 'single', 'dual', 'multi'");
  2975. }
  2976. # Check for proper license file usage
  2977. while ($tmp =~ /\nLICENSE_FILE_([^\s=]+)([\s=])/g) {
  2978. my $lfn = $1;
  2979. my $nchar = $2;
  2980. if (!grep(/\b$lfn\b/, $makevar{LICENSE})) {
  2981. &perror("FATAL", $file, -1, "license specified is $makevar{LICENSE}, ".
  2982. "but found LICENSE_FILE for $lfn.");
  2983. }
  2984. if ($lfn =~ /\+$/ && $nchar eq '=') {
  2985. &perror("WARN", $file, -1, "if license ends with a '+', make sure ".
  2986. "LICENSE_FILE_$lfn is followed by a space before the '='.");
  2987. }
  2988. }
  2989. # Last-ditch check to make sure the license is sanely defined.
  2990. my $lic_check = system("make check-license 2>&1 >/dev/null");
  2991. if ($lic_check) {
  2992. &perror("FATAL", $file, -1, "Failed to validate port LICENSE '$makevar{LICENSE}' with ``make check-license''");
  2993. }
  2994. $idx++;
  2995. push(@varnames, qw(
  2996. LICENSE LICENSE_COMB LICENSE_GROUPS LICENSE_NAME
  2997. LICENSE_TEXT LICENSE_FILE LICENSE_PERMS
  2998. ));
  2999. } else {
  3000. &perror("WARN", $file, -1, "Consider defining LICENSE.");
  3001. }
  3002. #
  3003. # section 6: BROKEN/IGNORE/DEPRECATED (may not be there)
  3004. #
  3005. print "OK: checking sixth section of $file (BROKEN/IGNORE/DEPRECATED).\n"
  3006. if ($verbose);
  3007. $tmp = $sections[$idx] // '';
  3008. @linestocheck = qw(
  3009. DEPRECATED EXPIRATION_DATE FORBIDDEN BROKEN(_\w+)? IGNORE(_\w+)?
  3010. ONLY_FOR_ARCHS ONLY_FOR_ARCHS_REASON(_\w+)?
  3011. NOT_FOR_ARCHS NOT_FOR_ARCHS_REASON(_\w+)? LEGAL_TEXT
  3012. );
  3013. my $brokenpattern = "^(" . join("|", @linestocheck) . ")[?+:]?=";
  3014. if ($tmp =~ /$brokenpattern/) {
  3015. $idx++;
  3016. }
  3017. foreach my $i (@linestocheck) {
  3018. $tmp =~ s/$i[?+:]?=[^\n]+\n//g;
  3019. }
  3020. push(@varnames, @linestocheck);
  3021. &checkearlier($file, $tmp, @varnames);
  3022. #
  3023. # section 7: *_DEPENDS (may not be there)
  3024. #
  3025. print "OK: checking seventh section of $file (*_DEPENDS).\n"
  3026. if ($verbose);
  3027. $tmp = $sections[$idx] // '';
  3028. # Check for direct assignment of BUILD_DEPENDS to RUN_DEPENDS.
  3029. if ($tmp =~ /\nRUN_DEPENDS=[ \t]*\$\{BUILD_DEPENDS}/) {
  3030. &perror("FATAL", $file, -1, "RUN_DEPENDS should not be set to ".
  3031. "\${BUILD_DEPENDS} as \${BUILD_DEPENDS} includes other ".
  3032. "implicit dependencies. Instead, copy the explicit dependencies ".
  3033. "from BUILD_DEPENDS to RUN_DEPENDS. See ".
  3034. "http://www.freebsd.org/doc/en_US.ISO8859-1/books/porters-handbook/makefile-depend.html#AEN2154 ".
  3035. "for more details.");
  3036. }
  3037. @linestocheck = qw(
  3038. EXTRACT_DEPENDS LIB_DEPENDS PATCH_DEPENDS BUILD_DEPENDS RUN_DEPENDS
  3039. TEST_DEPENDS FETCH_DEPENDS DEPENDS_TARGET
  3040. );
  3041. if ($tmp =~ /^([\w\d]+_)?(PATCH_|EXTRACT_|LIB_|BUILD_|RUN_|TEST_|FETCH_)DEPENDS/m) {
  3042. &checkearlier($file, $tmp, @varnames);
  3043. check_depends_syntax($tmp, $file);
  3044. foreach my $i (@linestocheck) {
  3045. $tmp =~ s/^([\w\d]+_)?$i[?+:]?=[^\n]+\n//g;
  3046. }
  3047. # Remove any other *_DEPENDS lines as people may
  3048. # use a macro for common depends as described in
  3049. # section 5.9.2 of the Porter's Handbook.
  3050. $tmp =~ s/.+_DEPENDS[?+:]?=[^\n]+\n//g;
  3051. &checkextra($tmp, '*_DEPENDS', $file);
  3052. $idx++;
  3053. }
  3054. push(@varnames, @linestocheck);
  3055. &checkearlier($file, $tmp, @varnames);
  3056. # section 8: FLAVORS/FLAVOR(optional)
  3057. #
  3058. print "OK: check eighth section of $file (FLAVORS: optional).\n"
  3059. if ($verbose);
  3060. $tmp = $sections[$idx] // '';
  3061. if ($tmp =~ /(FLAVORS|FLAVOR)/) {
  3062. &checkearlier($file, $tmp, @varnames);
  3063. $idx++;
  3064. }
  3065. push(@varnames, qw(
  3066. FLAVORS FLAVOR
  3067. ));
  3068. # section 9: USES/USE_x(optional)
  3069. #
  3070. print "OK: check ninth section of $file (USES: optional).\n"
  3071. if ($verbose);
  3072. $tmp = $sections[$idx] // '';
  3073. my $use_github_set = 0;
  3074. if ($tmp =~ /(USES|USE_)/) {
  3075. &checkearlier($file, $tmp, @varnames);
  3076. foreach my $line (split(/(USE(?:S[?+]|[_\w\d]+)?=[^\n]+\n)/, $tmp)) {
  3077. if ($line =~ /USES[?+]?=[^\n]+\n/) {
  3078. print "OK: seen USES.\n" if ($verbose);
  3079. $tmp =~ s/USES[?+]?=[^\n]+\n//;
  3080. next;
  3081. }
  3082. if ($line =~ /USE([_\w\d]+)=[^\n]+\n/) {
  3083. print "OK: seen USE$1.\n" if ($verbose);
  3084. if ($tmp =~ /USE_GITHUB/) {
  3085. $use_github_set = 1;
  3086. }
  3087. print "OK: USE_GITHUB set\n" if($use_github_set && $verbose);
  3088. $tmp =~ s/USE([_\w\d]+)=[^\n]+\n//;
  3089. next;
  3090. }
  3091. }
  3092. print "OK: check if GH_ options are in use\n"
  3093. if ($verbose);
  3094. foreach my $line (split(/(GH(?:S[?+]|[_\w\d]+)?=[^\n]+\n)/, $tmp)) {
  3095. if ($line =~ /GH([_\w\d]+)=[^\n]+\n/) {
  3096. print "OK: seen GH$1.\n" if ($verbose);
  3097. print "No USE_GITHUB seen but GH$1 used\n"
  3098. unless ($use_github_set);
  3099. $tmp =~ s/GH([_\w\d]+)=[^\n]+\n//;
  3100. next;
  3101. }
  3102. }
  3103. # XXX: We should check this. But, one is allowed to add _related_ items to
  3104. # a USE_ or USES item in this same section. Since this would be an ever-
  3105. # moving target, remove the check.
  3106. #&checkextra($tmp, 'USES/USE_x', $file);
  3107. $idx++;
  3108. }
  3109. push(@varnames, qw(
  3110. USES
  3111. ));
  3112. #
  3113. # Makefile 10: check the rest of file
  3114. #
  3115. print "OK: checking the rest of the $file.\n" if ($verbose);
  3116. $tmp = join("\n\n", @sections[$idx .. scalar(@sections)-1]);
  3117. $tmp = "\n" . $tmp; # to make the begin-of-line check easier
  3118. &checkearlier($file, $tmp, @varnames);
  3119. # Check depends that might be specified based on the WITH_/WITHOUT_
  3120. # arguments and other external variables.
  3121. check_depends_syntax($tmp, $file);
  3122. # check WRKSRC/NO_WRKSUBDIR
  3123. #
  3124. # do not use DISTFILES/DISTNAME to control over WRKSRC.
  3125. # DISTNAME is for controlling distribution filename.
  3126. # example:
  3127. # DISTNAME= package
  3128. # DISTFILES=package-1.0.tgz
  3129. # should be
  3130. # DISTNAME= package-1.0
  3131. # EXTRACT_SUFX=.tgz
  3132. # WRKSRC= ${WRKDIR}/package
  3133. #
  3134. print "OK: checking WRKSRC.\n" if ($verbose);
  3135. $wrksrc = $nowrksubdir = '';
  3136. $wrksrc = $1 if ($tmp =~ /\nWRKSRC[+?]?=[ \t]*([^\n]*)\n/);
  3137. $nowrksubdir = $1 if ($tmp =~ /\nNO_WRKSUBDIR[+?]?=[ \t]*([^\n]*)\n/);
  3138. if ($nowrksubdir eq '') {
  3139. $realwrksrc = $wrksrc ? "$wrksrc/$distname"
  3140. : "\${WRKDIR}/$distname";
  3141. } else {
  3142. $realwrksrc = $wrksrc ? $wrksrc : '${WRKDIR}';
  3143. }
  3144. print "OK: WRKSRC seems to be $realwrksrc.\n" if ($verbose);
  3145. if ($nowrksubdir eq '') {
  3146. print "OK: no NO_WRKSUBDIR, checking value of WRKSRC.\n"
  3147. if ($verbose);
  3148. if ($wrksrc eq 'work' || $wrksrc =~ /^$[\{\(]WRKDIR[\}\)]/) {
  3149. &perror("WARN", $file, -1, "WRKSRC is set to meaningless value ".
  3150. "\"$1\".".
  3151. ($nowrksubdir eq ''
  3152. ? " use \"NO_WRKSUBDIR=yes\" instead."
  3153. : ""));
  3154. }
  3155. if ($bogusdistfiles) {
  3156. if ($distname ne '' && $wrksrc eq '') {
  3157. &perror("WARN", $file, -1, "do not use DISTFILES and DISTNAME ".
  3158. "to control WRKSRC. how about ".
  3159. "\"WRKSRC=\${WRKDIR}/$distname\"?");
  3160. } else {
  3161. &perror("WARN", $file, -1, "DISTFILES/DISTNAME affects WRKSRC. ".
  3162. "take caution when changing them.");
  3163. }
  3164. }
  3165. } else {
  3166. print "OK: seen NO_WRKSUBDIR, checking value of WRKSRC.\n"
  3167. if ($verbose);
  3168. if ($wrksrc eq 'work' || $wrksrc =~ /^$[\{\(]WRKDIR[\}\)]/) {
  3169. &perror("WARN", $file, -1, "definition of WRKSRC not necessary. ".
  3170. "WRKSRC is \${WRKDIR} by default.");
  3171. }
  3172. }
  3173. if ($tmp =~ /\nNO_PACKAGE[+?]?=/) {
  3174. &perror("WARN", $file, -1, "NO_PACKAGE is obsolete. It should be ".
  3175. "replaced with \"LICENSE_PERMS=no-pkg-mirror\"");
  3176. }
  3177. # check NO_STAGE
  3178. if ($makevar{NO_STAGE}) {
  3179. &perror("FATAL", $file, -1, "STAGE support is missing.");
  3180. }
  3181. # various MAN'uals related checks
  3182. if ($makevar{USE_PERL5} =~ /\b(configure|modbuild|modbuildtiny)\b/
  3183. && $tmp =~ /\nMAN3PREFIX=\s*\$\{PREFIX}\/lib\/perl5\/\$\{PERL_VER/) {
  3184. &perror("WARN", $file, -1, "MAN3PREFIX is ".
  3185. "\"\${PREFIX}/lib/perl5/\${PERL_VERSION}\" ".
  3186. "when USE_PERL5=configure|modbuild|modbuildtiny is set. You do not need to specify it.");
  3187. }
  3188. if ($tmp =~ /\nMAN[1-9LN][?]?=/) {
  3189. &perror("FATAL", $file, -1, "MAN[1-9LN] macro is not supported anymore. ".
  3190. "Please list manpages in plist.");
  3191. }
  3192. # check INFO
  3193. print "OK: checking INFO.\n" if ($verbose);
  3194. if ($tmp =~ /\nINFO=\s*([^\n]*)\n/) {
  3195. my @minfo = grep($_ !~ /^\s*$/, split(/\s+/, $1));
  3196. if ($tmp =~ /[\/|\s]install-info\s/) {
  3197. &perror("FATAL", $file, -1, "install-info is automatically run ".
  3198. "when INFO is defined.");
  3199. }
  3200. foreach $i (@minfo) {
  3201. if ($i =~ /\.info(-\d+)?$/) {
  3202. &perror("FATAL", $file, -1, "do not include the .info extension ".
  3203. "on files listed in the INFO macro.");
  3204. }
  3205. }
  3206. } elsif ($tmp =~ /[\/|\s]install-info\s/) {
  3207. &perror("WARN", $file, -1, "do not call install-info directly. Use the ".
  3208. "INFO macro instead.");
  3209. }
  3210. # check for HAS_CONFIGURE or GNU_CONFIGURE
  3211. if ($tmp =~ /\nGNU_CONFIGURE[?+]?=/
  3212. && $tmp =~ /\n(HAS_CONFIGURE)[?+]?=/) {
  3213. &perror("WARN", $file, -1, "since you already have GNU_CONFIGURE, ".
  3214. "you do not need $1.");
  3215. }
  3216. # check direct use of important make targets.
  3217. if ($tmp =~ /\n(fetch|extract|patch|configure|build|install):/) {
  3218. &perror("FATAL", $file, -1, "direct redefinition of make target \"$1\" ".
  3219. "discouraged. redefine \"do-$1\" instead.");
  3220. }
  3221. # check for incorrect use of the pre-everything target.
  3222. if ($tmp =~ /\npre-everything:[^:]/) {
  3223. &perror("FATAL", $file, -1, "use pre-everything:: instead of pre-everything:");
  3224. }
  3225. if ($tmp =~ /^pre-patch:/m && $use_gnome_hack) {
  3226. &perror("FATAL", $file, -1, "pre-patch target overwrites gnomehack component. ".
  3227. "use post-patch instead.");
  3228. }
  3229. if ($tmp =~ /^do-build:/m && $use_ant) {
  3230. &perror("WARN", $file, -1, "USE_ANT is intended only for ports that ".
  3231. "build with Ant. It is recommended not to override the default ".
  3232. "'do-build:' target when defining USE_ANT");
  3233. }
  3234. #
  3235. # check for deprecated use of USE_RC_SUBR, and current syntax
  3236. #
  3237. if ($tmp =~ /\nUSE_RC_SUBR=([\s]*)(.*)/) {
  3238. my $subr_value = $makevar{USE_RC_SUBR};
  3239. if ($subr_value eq '') {
  3240. $subr_value = $2;
  3241. }
  3242. if (($subr_value =~ /^yes$/i) ||
  3243. ($subr_value =~ /^true$/i) ||
  3244. ($subr_value =~ /^1$/)) {
  3245. &perror("FATAL", $file, -1, "The value of the USE_RC_SUBR variable ".
  3246. "should be the name of the intended rc.d script, and there ".
  3247. "should be a corresponding file in the files/ directory.");
  3248. } else {
  3249. foreach my $i (split(/\s/, $subr_value)) {
  3250. if ($i ne '' && -f "files/$i.in") {
  3251. if (open(RCIN, "< files/$i.in")) {
  3252. my @rccontents = <RCIN>;
  3253. my $found_provide = 0;
  3254. foreach my $line (@rccontents) {
  3255. if ($line =~ /^# PROVIDE:/) {
  3256. $found_provide = 1;
  3257. last;
  3258. }
  3259. }
  3260. if (!$found_provide) {
  3261. &perror("FATAL", "files/$i.in", -1, "rc.d script ".
  3262. "$i.in must contain a '# PROVIDE:' line in ".
  3263. "order to be started at boot time.");
  3264. }
  3265. close(RCIN);
  3266. }
  3267. }
  3268. }
  3269. }
  3270. }
  3271. # check for health of SUB_FILES
  3272. if ($tmp =~ /\nSUB_FILES=([\s]*)(.*)/) {
  3273. my $subr_value = $makevar{SUB_FILES};
  3274. if ($subr_value eq '') {
  3275. $subr_value = $2;
  3276. }
  3277. foreach my $i (split(/\s/, $subr_value)) {
  3278. my $mvar;
  3279. if ($i =~ /\$\{([^}]+)\}/) {
  3280. $mvar = $1;
  3281. if (defined($makevar{$mvar})) {
  3282. $i = $makevar{$mvar};
  3283. } else {
  3284. $i = &get_makevar($mvar);
  3285. }
  3286. }
  3287. if ($i ne '' && ! -f "files/$i.in") {
  3288. &perror("FATAL", $file, -1, "$i listed in SUB_FILES/USE_RC_SUBR, ".
  3289. "but files/$i.in is missing.");
  3290. } elsif ($i eq '' && $mvar && $mvar ne '') {
  3291. &perror("WARN", $file, -1, "possible undefined make variable ".
  3292. "$mvar used as the value for SUB_FILES/USE_RC_SUBR.");
  3293. }
  3294. }
  3295. }
  3296. 1;
  3297. }
  3298. sub perror($$$$) {
  3299. my($type, $file, $line, $msg) = @_;
  3300. my $color;
  3301. if ($type eq 'FATAL') {
  3302. $err++;
  3303. $color = BRIGHT_RED;
  3304. } else {
  3305. $warn++;
  3306. $color = BRIGHT_YELLOW;
  3307. }
  3308. if ($grouperrs) {
  3309. $msg = '%%LINES%%' . $msg;
  3310. if ($file ne "") {
  3311. $msg = $file . ": " . $msg;
  3312. }
  3313. $msg = $color . $type . RESET . ": " . $msg;
  3314. if (!$errcache{$msg}) {
  3315. push @errlst, $msg;
  3316. }
  3317. if ($line > -1) {
  3318. push @{$errcache{$msg}}, $line;
  3319. }
  3320. } else {
  3321. if ($line > -1) {
  3322. $msg = "[$line]: " . $msg;
  3323. }
  3324. if ($file ne "") {
  3325. $msg = $file . ": " . $msg;
  3326. }
  3327. $msg = ": " . $msg;
  3328. print $color, $type, RESET, $msg . "\n";
  3329. }
  3330. }
  3331. sub checkextra {
  3332. my($str, $section, $file) = @_;
  3333. $str = "\n" . $str if ($str !~ /^\n/);
  3334. $str =~ s/\n#[^\n]*/\n/g;
  3335. $str =~ s/\n\.[^\n]+/\n/g;
  3336. $str =~ s/\n\n+/\n/g;
  3337. $str =~ s/^\s+//;
  3338. $str =~ s/\s+$//;
  3339. return if ($str eq '');
  3340. if ($str =~ /^([\w\d]+)/) {
  3341. &perror("WARN", $file, -1, "extra item placed in the ".
  3342. "$section section, ".
  3343. "for example, \"$1\".");
  3344. } else {
  3345. &perror("WARN", $file, -1, "extra item placed in the ".
  3346. "$section section.");
  3347. }
  3348. }
  3349. sub checkorder {
  3350. my($section, $str, $file, @order) = @_;
  3351. my(@items, $i, $j, $k, $invalidorder);
  3352. print "OK: checking the order of $section section.\n" if ($verbose);
  3353. $str //= '';
  3354. @items = ();
  3355. foreach my $i (split("\n", $str)) {
  3356. $i =~ s/[+?]?=.*$//;
  3357. push(@items, $i);
  3358. }
  3359. @items = reverse(@items);
  3360. $j = -1;
  3361. $invalidorder = 0;
  3362. while (scalar(@items)) {
  3363. $i = pop(@items);
  3364. $k = 0;
  3365. while ($k < scalar(@order) && $order[$k] ne $i) {
  3366. if (defined $order[$k] &&
  3367. $order[$k] =~ /[\.\*\+\?\{\}\[\]\^\$\|]/ &&
  3368. $i =~ /$order[$k]/) {
  3369. last;
  3370. }
  3371. $k++;
  3372. }
  3373. if (defined $order[$k] && $order[$k] =~ /[\.\*\+\?\{\}\[\]\^\$\|]/ &&
  3374. $i =~ /$order[$k]/) {
  3375. if ($k < $j) {
  3376. &perror("FATAL", $file, -1, "$i appears out-of-order.");
  3377. $invalidorder++;
  3378. } else {
  3379. print "OK: seen $i, in order.\n" if ($verbose);
  3380. }
  3381. $j = $k;
  3382. } elsif (defined $order[$k] && $order[$k] eq $i) {
  3383. if ($k < $j) {
  3384. &perror("FATAL", $file, -1, "$i appears out-of-order.");
  3385. $invalidorder++;
  3386. } else {
  3387. print "OK: seen $i, in order.\n" if ($verbose);
  3388. }
  3389. $j = $k;
  3390. # This if condition tests for .if, .else (in all forms),
  3391. # .for and .endfor and .include
  3392. } elsif ($i !~ m/^\.(if|el|endif|for|endfor|include)/) {
  3393. &perror("FATAL", $file, -1, "extra item \"$i\" placed in the ".
  3394. "$section section.");
  3395. }
  3396. }
  3397. if ($invalidorder) {
  3398. &perror("FATAL", $file, -1, "order must be " . join('/', @order) . '.');
  3399. } else {
  3400. print "OK: $section section is ordered properly.\n"
  3401. if ($verbose);
  3402. }
  3403. }
  3404. sub checkearlier {
  3405. my($file, $str, @varnames) = @_;
  3406. $str //= '';
  3407. print "OK: checking items that have to appear earlier.\n" if ($verbose);
  3408. foreach my $i (@varnames) {
  3409. if ($str =~ /\n($i)\??=/) {
  3410. &perror("WARN", $file, -1, "\"$1\" has to appear earlier.");
  3411. }
  3412. }
  3413. }
  3414. sub linenumber {
  3415. my $text = shift;
  3416. my @lines;
  3417. @lines = split /\n/, $text;
  3418. return scalar(@lines) - 1;
  3419. }
  3420. sub abspathname {
  3421. my($str, $file) = @_;
  3422. my($s, $i, %cmdnames);
  3423. my($pre);
  3424. # trim all trailing backslash and newline
  3425. $str =~ s/\\\n\s*/ /g;
  3426. # ignore parameter string to reinplace command
  3427. $str =~ s/([ \t][\@-]?(?:sed|\$[\{\(]SED[\}\)]|\$[\{\(]REINPLACE_CMD[\}\)]))((?:\s+\-\w+)*\s+(?:"(?:\\"|[^"\n])*"|'(?:\\'|[^'\n])*'))+(.*)/$1$3/g; #'
  3428. # ignore parameter string to echo command
  3429. # XXX: This next pattern crashes Perl 5.8.7.
  3430. #$str =~ s/[ \t][\@-]?(echo|\$[\{\(]ECHO[\}\)]|\$[\{\(]ECHO_MSG[\}\)])[ \t]+("(\\'|\\"|[^"])*"|'(\\'|\\"|[^"])*')[ \t]*[;\n]//; #'
  3431. $str =~ s/[ \t][\@-]?(echo|\$[\{\(]ECHO[\}\)]|\$[\{\(]ECHO_MSG[\}\)])[ \t]+.*(;|$)//m; #'
  3432. print "OK: checking direct use of full pathnames in $file.\n"
  3433. if ($verbose);
  3434. foreach my $s (split(/\n+/, $str)) {
  3435. $i = '';
  3436. $s =~ s/#.*$//;
  3437. if ($s =~ /(^|[ \t\@'"-])(\/[\w\d])/) { #'
  3438. # suspected pathnames are recorded.
  3439. $i = $2 . $';
  3440. $pre = $` . $1;
  3441. if ($pre =~ /MASTER_SITE_SUBDIR/) {
  3442. # MASTER_SITE_SUBDIR lines are ok.
  3443. $i = '';
  3444. }
  3445. if ($s =~ /\$\{[^}]*?\Q$i\E/) {
  3446. # If we're inside a make variable, we probably do not have
  3447. # an absolute path.
  3448. $i = '';
  3449. }
  3450. }
  3451. if ($i ne '' && ! grep {$i =~ m|^$_|} @ALLOWED_FULL_PATHS) {
  3452. $i =~ s/\s.*$//;
  3453. $i =~ s/['"].*$//; #'
  3454. $i = substr($i, 0, 20) . '...' if (20 < length($i));
  3455. &perror("WARN", $file, -1, "possible use of absolute pathname ".
  3456. "\"$i\".");
  3457. }
  3458. }
  3459. foreach my $s (split(/\n+/, $str)) {
  3460. print "OK: checking direct use of pathnames, phase 1.\n" if ($verbose);
  3461. %cmdnames = split(/\n|\t+/, <<EOF);
  3462. /usr/opt \${PORTSDIR} instead
  3463. $portsdir \${PORTSDIR} instead
  3464. $localbase \${PREFIX} or \${LOCALBASE}, as appropriate
  3465. EOF
  3466. foreach my $i (keys %cmdnames) {
  3467. if ($s =~ /^[^#]*$i/) {
  3468. &perror("WARN", $file, -1, "possible direct use of \"$&\" ".
  3469. "found. if so, use $cmdnames{$i}.");
  3470. }
  3471. }
  3472. print "OK: checking direct use of pathnames, phase 2.\n" if ($verbose);
  3473. %cmdnames = split(/\n|\t+/, <<EOF);
  3474. distfiles \${DISTDIR} instead
  3475. pkg \${PKGDIR} instead
  3476. files \${FILESDIR} instead
  3477. scripts \${SCRIPTDIR} instead
  3478. patches \${PATCHDIR} instead
  3479. work \${WRKDIR} instead
  3480. EOF
  3481. foreach my $i (keys %cmdnames) {
  3482. # use (?![\w-]) instead of \b to exclude pkg-*
  3483. if ($file =~ /^[^#]*(\.\/|\$[\{\(]\.CURDIR[\}\)]\/|[ \t])(\b$i)(?![\w-])/
  3484. && $s !~ /^COMMENT(.)?=[^\n]+$i/m
  3485. && $s !~ /^IGNORE(.)?=[^\n]+$i/m
  3486. && $s !~ /^BROKEN(.)?=[^\n]+$i/m
  3487. && $s !~ /^RESTRICTED(.)?=[^\n]+$i/m
  3488. && $s !~ /^NO_PACKAGE(.)?=[^\n]+$i/m
  3489. && $s !~ /^NO_CDROM(.)?=[^\n]+$i/m
  3490. && $s !~ /^MAINTAINER(.)?=[^\n]+$i/m
  3491. && $s !~ /^CATEGORIES(.)?=[^\n]+$i/m
  3492. && $s !~ /^USES(.)?=[^\n]+$i/m
  3493. && $s !~ /^WX_COMPS(.)?=[^\n]+$i/m
  3494. && $s !~ /^SHEBANG_FILES(.)?=[^\n]+$i/m
  3495. && $s !~ /^[A-Z0-9_]+_DESC=[^\n]+$i/m
  3496. && $s !~ /^ONLY_FOR_ARCHS_REASON(.)?=[^\n]+$i/m
  3497. && $s !~ /^NOT_FOR_ARCHS_REASON(.)?=[^\n]+$i/m) {
  3498. &perror("WARN", $file, -1, "possible direct use of \"$i\" \"$s\" ".
  3499. "found. if so, use $cmdnames{$i}.");
  3500. }
  3501. }
  3502. }
  3503. }
  3504. sub get_makevar {
  3505. my($cmd, $result);
  3506. $cmd = join(' -V ', "make $makeenv MASTER_SITE_BACKUP=''", map { "'$_'" } @_);
  3507. $result = `$cmd`;
  3508. chomp $result;
  3509. # This bit of magic is interesting and repeated in the get_make* functions.
  3510. # It will ensure that all empty values for macros are replaced with a '\0' character
  3511. # to preserve their "place in line" for future parsing. This is only needed when passing
  3512. # multiple variables to these functions.
  3513. no warnings 'uninitialized';
  3514. $result =~ s/(?:^|(?<=\n))(?=\n|$)/$1\0$3/g;
  3515. if (${^CHILD_ERROR_NATIVE} != 0) {
  3516. die "\nFATAL ERROR: make(1) died with status ${^CHILD_ERROR_NATIVE} and returned '$result'";
  3517. }
  3518. # If the final value is just a '\0' strip it out.
  3519. $result =~ s/^\0$//;
  3520. return $result;
  3521. }
  3522. sub get_makevar_shallow {
  3523. my($cmd, $result);
  3524. $cmd = join(' -dV -V ', "make $makeenv MASTER_SITE_BACKUP=''", map { "'$_'" } @_);
  3525. $result = `$cmd`;
  3526. chomp $result;
  3527. no warnings 'uninitialized';
  3528. $result =~ s/(?:^|(?<=\n))(?=\n|$)/$1\0$3/g;
  3529. if (${^CHILD_ERROR_NATIVE} != 0) {
  3530. die "\nFATAL ERROR: make(1) died with status ${^CHILD_ERROR_NATIVE} and returned '$result'";
  3531. }
  3532. $result =~ s/^\0$//;
  3533. return $result;
  3534. }
  3535. sub get_makevar_raw {
  3536. my($cmd, $result);
  3537. $cmd = join(' -XV ', "make $makeenv MASTER_SITE_BACKUP=''", map { "'$_'" } @_);
  3538. $result = `$cmd`;
  3539. chomp $result;
  3540. no warnings 'uninitialized';
  3541. $result =~ s/(?:^|(?<=\n))(?=\n|$)/$1\0$3/g;
  3542. if (${^CHILD_ERROR_NATIVE} != 0) {
  3543. die "\nFATAL ERROR: make(1) died with status ${^CHILD_ERROR_NATIVE} and returned '$result'";
  3544. }
  3545. $result =~ s/^\0$//;
  3546. return $result;
  3547. }
  3548. # This uses a "null" makefile to extract options from /etc/make.conf without any overrides.
  3549. sub get_makeconf_var {
  3550. my($cmd, $result);
  3551. $cmd = join(' -V ', "echo '' | make $makeenv -f -", map { "'$_'"} @_);
  3552. $result =`$cmd`;
  3553. chomp $result;
  3554. no warnings 'uninitialized';
  3555. $result =~ s/(?:^|(?<=\n))(?=\n|$)/$1\0$3/g;
  3556. if (${^CHILD_ERROR_NATIVE} != 0) {
  3557. die "\nFATAL ERROR: make(1) died with status ${^CHILD_ERROR_NATIVE} and returned '$result'";
  3558. }
  3559. $result =~ s/^\0$//;
  3560. return $result;
  3561. }
  3562. sub is_predefined {
  3563. my($url, $file) = @_;
  3564. my($site, $site_re);
  3565. my $subdir_re = quotemeta quotemeta '/%SUBDIR%/';
  3566. for my $site (keys %predefined) {
  3567. $site_re = quotemeta $site;
  3568. $site_re =~ s,$subdir_re,/(.*)/,;
  3569. if ($url =~ /$site_re/ && $file) {
  3570. my $pe = "how about using \"\${MASTER_SITE_$predefined{$site}}\" ";
  3571. if ($1) {
  3572. $pe .= "with \"MASTER_SITE_SUBDIR=$1\", ";
  3573. }
  3574. $pe .= "instead of \"$url\"?";
  3575. &perror("WARN", $file, -1, $pe);
  3576. return &TRUE;
  3577. } elsif ($url =~ /$site_re/ && !$file) {
  3578. return &TRUE;
  3579. }
  3580. }
  3581. undef;
  3582. }
  3583. sub urlcheck {
  3584. my ($url, $file) = @_;
  3585. if ($url !~ m#^\w+://#) {
  3586. &perror("WARN", $file, -1, "\"$url\" doesn't appear to be a URL to me.");
  3587. }
  3588. if ($url !~ m#/(:[^/:]+)?$# && $url !~ m#:$#) {
  3589. &perror("FATAL", $file, -1, "URL \"$url\" should ".
  3590. "end with \"/\" or a group name (e.g. :something).");
  3591. }
  3592. if ($url =~ m#://[^/]*:/#) {
  3593. &perror("FATAL", $file, -1, "URL \"$url\" contains ".
  3594. "extra \":\".");
  3595. }
  3596. }
  3597. sub TRUE {1;}
  3598. # Local variables:
  3599. # tab-width: 4
  3600. # End: