portlint.pl 116 KB

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