portlint.pl 114 KB

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