portlint.pl 115 KB

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