manual.html 553 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>The Buildroot user manual</title><link rel="stylesheet" type="text/css" href="docbook-xsl.css" /><meta name="generator" content="DocBook XSL Stylesheets Vsnapshot" /></head><body><div xml:lang="en" class="book" lang="en"><div class="titlepage"><div><div><h1 class="title"><a id="idm1"></a>The Buildroot user manual</h1></div></div><hr /></div><div class="toc"><p><strong>Table of Contents</strong></p><dl class="toc"><dt><span class="preface"><a href="#idm4"></a></span></dt><dt><span class="part"><a href="#_getting_started">I. Getting started</a></span></dt><dd><dl><dt><span class="chapter"><a href="#_about_buildroot">1. About Buildroot</a></span></dt><dt><span class="chapter"><a href="#requirement">2. System requirements</a></span></dt><dd><dl><dt><span class="section"><a href="#requirement-mandatory">2.1. Mandatory packages</a></span></dt><dt><span class="section"><a href="#requirement-optional">2.2. Optional packages</a></span></dt></dl></dd><dt><span class="chapter"><a href="#getting-buildroot">3. Getting Buildroot</a></span></dt><dt><span class="chapter"><a href="#_buildroot_quick_start">4. Buildroot quick start</a></span></dt><dt><span class="chapter"><a href="#community-resources">5. Community resources</a></span></dt></dl></dd><dt><span class="part"><a href="#_user_guide">II. User guide</a></span></dt><dd><dl><dt><span class="chapter"><a href="#configure">6. Buildroot configuration</a></span></dt><dd><dl><dt><span class="section"><a href="#_cross_compilation_toolchain">6.1. Cross-compilation toolchain</a></span></dt><dt><span class="section"><a href="#_dev_management">6.2. /dev management</a></span></dt><dt><span class="section"><a href="#init-system">6.3. init system</a></span></dt></dl></dd><dt><span class="chapter"><a href="#_configuration_of_other_components">7. Configuration of other components</a></span></dt><dt><span class="chapter"><a href="#_general_buildroot_usage">8. General Buildroot usage</a></span></dt><dd><dl><dt><span class="section"><a href="#make-tips">8.1. <span class="emphasis"><em>make</em></span> tips</a></span></dt><dt><span class="section"><a href="#full-rebuild">8.2. Understanding when a full rebuild is necessary</a></span></dt><dt><span class="section"><a href="#rebuild-pkg">8.3. Understanding how to rebuild packages</a></span></dt><dt><span class="section"><a href="#_offline_builds">8.4. Offline builds</a></span></dt><dt><span class="section"><a href="#_building_out_of_tree">8.5. Building out-of-tree</a></span></dt><dt><span class="section"><a href="#env-vars">8.6. Environment variables</a></span></dt><dt><span class="section"><a href="#_dealing_efficiently_with_filesystem_images">8.7. Dealing efficiently with filesystem images</a></span></dt><dt><span class="section"><a href="#_details_about_packages">8.8. Details about packages</a></span></dt><dt><span class="section"><a href="#_graphing_the_dependencies_between_packages">8.9. Graphing the dependencies between packages</a></span></dt><dt><span class="section"><a href="#_graphing_the_build_duration">8.10. Graphing the build duration</a></span></dt><dt><span class="section"><a href="#graph-size">8.11. Graphing the filesystem size contribution of packages</a></span></dt><dt><span class="section"><a href="#top-level-parallel-build">8.12. Top-level parallel build</a></span></dt><dt><span class="section"><a href="#_advanced_usage">8.13. Advanced usage</a></span></dt></dl></dd><dt><span class="chapter"><a href="#customize">9. Project-specific customization</a></span></dt><dd><dl><dt><span class="section"><a href="#customize-dir-structure">9.1. Recommended directory structure</a></span></dt><dt><span class="section"><a href="#outside-br-custom">9.2. Keeping customizations outside of Buildroot</a></span></dt><dt><span class="section"><a href="#customize-store-buildroot-config">9.3. Storing the Buildroot configuration</a></span></dt><dt><span class="section"><a href="#customize-store-package-config">9.4. Storing the configuration of other components</a></span></dt><dt><span class="section"><a href="#rootfs-custom">9.5. Customizing the generated target filesystem</a></span></dt><dt><span class="section"><a href="#customize-users">9.6. Adding custom user accounts</a></span></dt><dt><span class="section"><a href="#_customization_emphasis_after_emphasis_the_images_have_been_created">9.7. Customization <span class="emphasis"><em>after</em></span> the images have been created</a></span></dt><dt><span class="section"><a href="#_adding_project_specific_patches_and_hashes">9.8. Adding project-specific patches and hashes</a></span></dt><dt><span class="section"><a href="#customize-packages">9.9. Adding project-specific packages</a></span></dt><dt><span class="section"><a href="#_quick_guide_to_storing_your_project_specific_customizations">9.10. Quick guide to storing your project-specific customizations</a></span></dt></dl></dd><dt><span class="chapter"><a href="#integration">10. Integration topics</a></span></dt><dd><dl><dt><span class="section"><a href="#integration-systemd">10.1. Systemd</a></span></dt><dt><span class="section"><a href="#selinux">10.2. Using SELinux in Buildroot</a></span></dt></dl></dd><dt><span class="chapter"><a href="#_frequently_asked_questions_amp_troubleshooting">11. Frequently Asked Questions &amp; Troubleshooting</a></span></dt><dd><dl><dt><span class="section"><a href="#faq-boot-hang-after-starting">11.1. The boot hangs after <span class="emphasis"><em>Starting network…</em></span></a></span></dt><dt><span class="section"><a href="#faq-no-compiler-on-target">11.2. Why is there no compiler on the target?</a></span></dt><dt><span class="section"><a href="#faq-no-dev-files-on-target">11.3. Why are there no development files on the target?</a></span></dt><dt><span class="section"><a href="#faq-no-doc-on-target">11.4. Why is there no documentation on the target?</a></span></dt><dt><span class="section"><a href="#faq-why-not-visible-package">11.5. Why are some packages not visible in the Buildroot config menu?</a></span></dt><dt><span class="section"><a href="#faq-why-not-use-target-as-chroot">11.6. Why not use the target directory as a chroot directory?</a></span></dt><dt><span class="section"><a href="#faq-no-binary-packages">11.7. Why doesn’t Buildroot generate binary packages (.deb, .ipkg…)?</a></span></dt><dt><span class="section"><a href="#faq-speeding-up-build">11.8. How to speed-up the build process?</a></span></dt><dt><span class="section"><a href="#faq-2038">11.9. How does Buildroot support Y2038?</a></span></dt></dl></dd><dt><span class="chapter"><a href="#_known_issues">12. Known issues</a></span></dt><dt><span class="chapter"><a href="#legal-info">13. Legal notice and licensing</a></span></dt><dd><dl><dt><span class="section"><a href="#_complying_with_open_source_licenses">13.1. Complying with open source licenses</a></span></dt><dt><span class="section"><a href="#legal-info-buildroot">13.2. Complying with the Buildroot license</a></span></dt></dl></dd><dt><span class="chapter"><a href="#_beyond_buildroot">14. Beyond Buildroot</a></span></dt><dd><dl><dt><span class="section"><a href="#_boot_the_generated_images">14.1. Boot the generated images</a></span></dt><dt><span class="section"><a href="#_chroot">14.2. Chroot</a></span></dt></dl></dd></dl></dd><dt><span class="part"><a href="#_developer_guide">III. Developer guide</a></span></dt><dd><dl><dt><span class="chapter"><a href="#_how_buildroot_works">15. How Buildroot works</a></span></dt><dt><span class="chapter"><a href="#_coding_style">16. Coding style</a></span></dt><dd><dl><dt><span class="section"><a href="#writing-rules-config-in">16.1. <code class="literal">Config.in</code> file</a></span></dt><dt><span class="section"><a href="#writing-rules-mk">16.2. The <code class="literal">.mk</code> file</a></span></dt><dt><span class="section"><a href="#writing-genimage-cfg">16.3. The <code class="literal">genimage.cfg</code> file</a></span></dt><dt><span class="section"><a href="#_the_documentation">16.4. The documentation</a></span></dt><dt><span class="section"><a href="#_support_scripts">16.5. Support scripts</a></span></dt></dl></dd><dt><span class="chapter"><a href="#adding-board-support">17. Adding support for a particular board</a></span></dt><dt><span class="chapter"><a href="#adding-packages">18. Adding new packages to Buildroot</a></span></dt><dd><dl><dt><span class="section"><a href="#_package_directory">18.1. Package directory</a></span></dt><dt><span class="section"><a href="#_config_files">18.2. Config files</a></span></dt><dt><span class="section"><a href="#_the_literal_mk_literal_file">18.3. The <code class="literal">.mk</code> file</a></span></dt><dt><span class="section"><a href="#adding-packages-hash">18.4. The <code class="literal">.hash</code> file</a></span></dt><dt><span class="section"><a href="#adding-packages-start-script">18.5. The <code class="literal">SNNfoo</code> start script</a></span></dt><dt><span class="section"><a href="#_infrastructure_for_packages_with_specific_build_systems">18.6. Infrastructure for packages with specific build systems</a></span></dt><dt><span class="section"><a href="#_infrastructure_for_autotools_based_packages">18.7. Infrastructure for autotools-based packages</a></span></dt><dt><span class="section"><a href="#_infrastructure_for_cmake_based_packages">18.8. Infrastructure for CMake-based packages</a></span></dt><dt><span class="section"><a href="#_infrastructure_for_python_packages">18.9. Infrastructure for Python packages</a></span></dt><dt><span class="section"><a href="#_infrastructure_for_luarocks_based_packages">18.10. Infrastructure for LuaRocks-based packages</a></span></dt><dt><span class="section"><a href="#_infrastructure_for_perl_cpan_packages">18.11. Infrastructure for Perl/CPAN packages</a></span></dt><dt><span class="section"><a href="#_infrastructure_for_virtual_packages">18.12. Infrastructure for virtual packages</a></span></dt><dt><span class="section"><a href="#_infrastructure_for_packages_using_kconfig_for_configuration_files">18.13. Infrastructure for packages using kconfig for configuration files</a></span></dt><dt><span class="section"><a href="#_infrastructure_for_rebar_based_packages">18.14. Infrastructure for rebar-based packages</a></span></dt><dt><span class="section"><a href="#_infrastructure_for_waf_based_packages">18.15. Infrastructure for Waf-based packages</a></span></dt><dt><span class="section"><a href="#_infrastructure_for_meson_based_packages">18.16. Infrastructure for Meson-based packages</a></span></dt><dt><span class="section"><a href="#_infrastructure_for_cargo_based_packages">18.17. Infrastructure for Cargo-based packages</a></span></dt><dt><span class="section"><a href="#_infrastructure_for_go_packages">18.18. Infrastructure for Go packages</a></span></dt><dt><span class="section"><a href="#_infrastructure_for_qmake_based_packages">18.19. Infrastructure for QMake-based packages</a></span></dt><dt><span class="section"><a href="#_infrastructure_for_packages_building_kernel_modules">18.20. Infrastructure for packages building kernel modules</a></span></dt><dt><span class="section"><a href="#_infrastructure_for_asciidoc_documents">18.21. Infrastructure for asciidoc documents</a></span></dt><dt><span class="section"><a href="#linux-kernel-specific-infra">18.22. Infrastructure specific to the Linux kernel package</a></span></dt><dt><span class="section"><a href="#hooks">18.23. Hooks available in the various build steps</a></span></dt><dt><span class="section"><a href="#_gettext_integration_and_interaction_with_packages">18.24. Gettext integration and interaction with packages</a></span></dt><dt><span class="section"><a href="#_tips_and_tricks">18.25. Tips and tricks</a></span></dt><dt><span class="section"><a href="#_conclusion">18.26. Conclusion</a></span></dt></dl></dd><dt><span class="chapter"><a href="#patch-policy">19. Patching a package</a></span></dt><dd><dl><dt><span class="section"><a href="#_providing_patches">19.1. Providing patches</a></span></dt><dt><span class="section"><a href="#patch-apply-order">19.2. How patches are applied</a></span></dt><dt><span class="section"><a href="#_format_and_licensing_of_the_package_patches">19.3. Format and licensing of the package patches</a></span></dt><dt><span class="section"><a href="#_additional_patch_documentation">19.4. Additional patch documentation</a></span></dt></dl></dd><dt><span class="chapter"><a href="#download-infra">20. Download infrastructure</a></span></dt><dt><span class="chapter"><a href="#debugging-buildroot">21. Debugging Buildroot</a></span></dt><dt><span class="chapter"><a href="#_contributing_to_buildroot">22. Contributing to Buildroot</a></span></dt><dd><dl><dt><span class="section"><a href="#_reproducing_analyzing_and_fixing_bugs">22.1. Reproducing, analyzing and fixing bugs</a></span></dt><dt><span class="section"><a href="#_analyzing_and_fixing_autobuild_failures">22.2. Analyzing and fixing autobuild failures</a></span></dt><dt><span class="section"><a href="#_reviewing_and_testing_patches">22.3. Reviewing and testing patches</a></span></dt><dt><span class="section"><a href="#_work_on_items_from_the_todo_list">22.4. Work on items from the TODO list</a></span></dt><dt><span class="section"><a href="#submitting-patches">22.5. Submitting patches</a></span></dt><dt><span class="section"><a href="#reporting-bugs">22.6. Reporting issues/bugs or getting help</a></span></dt><dt><span class="section"><a href="#_using_the_runtime_tests_framework">22.7. Using the runtime tests framework</a></span></dt></dl></dd><dt><span class="chapter"><a href="#DEVELOPERS">23. DEVELOPERS file and get-developers</a></span></dt><dt><span class="chapter"><a href="#RELENG">24. Release Engineering</a></span></dt><dd><dl><dt><span class="section"><a href="#_releases">24.1. Releases</a></span></dt><dt><span class="section"><a href="#_development">24.2. Development</a></span></dt></dl></dd></dl></dd><dt><span class="part"><a href="#_appendix">IV. Appendix</a></span></dt><dd><dl><dt><span class="chapter"><a href="#makedev-syntax">25. Makedev syntax documentation</a></span></dt><dt><span class="chapter"><a href="#makeuser-syntax">26. Makeusers syntax documentation</a></span></dt><dd><dl><dt><span class="section"><a href="#_caveat_with_automatic_uids_and_gids">26.1. Caveat with automatic UIDs and GIDs</a></span></dt></dl></dd><dt><span class="chapter"><a href="#migrating-from-ol-versions">27. Migrating from older Buildroot versions</a></span></dt><dd><dl><dt><span class="section"><a href="#migrating-approach">27.1. General approach</a></span></dt><dt><span class="section"><a href="#br2-external-converting">27.2. Migrating to 2016.11</a></span></dt><dt><span class="section"><a href="#migrating-host-usr">27.3. Migrating to 2017.08</a></span></dt><dt><span class="section"><a href="#migrating-svn-externals">27.4. Migrating to 2023.11</a></span></dt></dl></dd></dl></dd></dl></div><div class="list-of-examples"><p><strong>List of Examples</strong></p><dl><dt>18.1. <a href="#idm3373">Config script: <span class="emphasis"><em>divine</em></span> package</a></dt><dt>18.2. <a href="#idm3380">Config script: <span class="emphasis"><em>imagemagick</em></span> package:</a></dt></dl></div><div class="preface"><div class="titlepage"><div><div><h1 class="title"><a id="idm4"></a></h1></div></div></div><p>Buildroot 2024.02.10 manual generated on 2025-01-09
  3. 13:44:22 UTC from git revision c9620ac37e</p><p>The Buildroot manual is written by the Buildroot developers.
  4. It is licensed under the GNU General Public License, version 2. Refer to the
  5. <a class="ulink" href="http://git.buildroot.org/buildroot/tree/COPYING?id=c9620ac37e658d177821be85b4c9484e71e19710" target="_top">COPYING</a>
  6. file in the Buildroot sources for the full text of this license.</p><p>Copyright © The Buildroot developers &lt;<a class="ulink" href="mailto:buildroot@buildroot.org" target="_top">buildroot@buildroot.org</a>&gt;</p><div class="informalfigure"><div class="mediaobject"><img src="logo.png" alt="logo.png" /></div></div></div><div class="part"><div class="titlepage"><div><div><h1 class="title"><a id="_getting_started"></a>Part I. Getting started</h1></div></div></div><div class="chapter"><div class="titlepage"><div><div><h2 class="title"><a id="_about_buildroot"></a>Chapter 1. About Buildroot</h2></div></div></div><p>Buildroot is a tool that simplifies and automates the process of
  7. building a complete Linux system for an embedded system, using
  8. cross-compilation.</p><p>In order to achieve this, Buildroot is able to generate a
  9. cross-compilation toolchain, a root filesystem, a Linux kernel image
  10. and a bootloader for your target. Buildroot can be used for any
  11. combination of these options, independently (you can for example use
  12. an existing cross-compilation toolchain, and build only your root
  13. filesystem with Buildroot).</p><p>Buildroot is useful mainly for people working with embedded systems.
  14. Embedded systems often use processors that are not the regular x86
  15. processors everyone is used to having in his PC. They can be PowerPC
  16. processors, MIPS processors, ARM processors, etc.</p><p>Buildroot supports numerous processors and their variants; it also
  17. comes with default configurations for several boards available
  18. off-the-shelf. Besides this, a number of third-party projects are based on,
  19. or develop their BSP <a href="#ftn.idm25" class="footnote" id="idm25"><sup class="footnote">[1]</sup></a> or
  20. SDK <a href="#ftn.idm27" class="footnote" id="idm27"><sup class="footnote">[2]</sup></a> on top of Buildroot.</p><div class="footnotes"><br /><hr style="width:100; text-align:left;margin-left: 0" /><div id="ftn.idm25" class="footnote"><p><a href="#idm25" class="simpara"><sup class="simpara">[1] </sup></a>BSP: Board Support Package</p></div><div id="ftn.idm27" class="footnote"><p><a href="#idm27" class="simpara"><sup class="simpara">[2] </sup></a>SDK: Software Development Kit</p></div></div></div><div class="chapter"><div class="titlepage"><div><div><h2 class="title"><a id="requirement"></a>Chapter 2. System requirements</h2></div></div></div><p>Buildroot is designed to run on Linux systems.</p><p>While Buildroot itself will build most host packages it needs for the
  21. compilation, certain standard Linux utilities are expected to be
  22. already installed on the host system. Below you will find an overview of
  23. the mandatory and optional packages (note that package names may vary
  24. between distributions).</p><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="requirement-mandatory"></a>2.1. Mandatory packages</h2></div></div></div><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p class="simpara">
  25. Build tools:
  26. </p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: circle; "><li class="listitem">
  27. <code class="literal">which</code>
  28. </li><li class="listitem">
  29. <code class="literal">sed</code>
  30. </li><li class="listitem">
  31. <code class="literal">make</code> (version 3.81 or any later)
  32. </li><li class="listitem">
  33. <code class="literal">binutils</code>
  34. </li><li class="listitem">
  35. <code class="literal">build-essential</code> (only for Debian based systems)
  36. </li><li class="listitem">
  37. <code class="literal">diffutils</code>
  38. </li><li class="listitem">
  39. <code class="literal">gcc</code> (version 4.8 or any later)
  40. </li><li class="listitem">
  41. <code class="literal">g++</code> (version 4.8 or any later)
  42. </li><li class="listitem">
  43. <code class="literal">bash</code>
  44. </li><li class="listitem">
  45. <code class="literal">patch</code>
  46. </li><li class="listitem">
  47. <code class="literal">gzip</code>
  48. </li><li class="listitem">
  49. <code class="literal">bzip2</code>
  50. </li><li class="listitem">
  51. <code class="literal">perl</code> (version 5.8.7 or any later)
  52. </li><li class="listitem">
  53. <code class="literal">tar</code>
  54. </li><li class="listitem">
  55. <code class="literal">cpio</code>
  56. </li><li class="listitem">
  57. <code class="literal">unzip</code>
  58. </li><li class="listitem">
  59. <code class="literal">rsync</code>
  60. </li><li class="listitem">
  61. <code class="literal">file</code> (must be in <code class="literal">/usr/bin/file</code>)
  62. </li><li class="listitem">
  63. <code class="literal">bc</code>
  64. </li><li class="listitem">
  65. <code class="literal">findutils</code>
  66. </li></ul></div></li><li class="listitem"><p class="simpara">
  67. Source fetching tools:
  68. </p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: circle; "><li class="listitem">
  69. <code class="literal">wget</code>
  70. </li></ul></div></li></ul></div></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="requirement-optional"></a>2.2. Optional packages</h2></div></div></div><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p class="simpara">
  71. Recommended dependencies:
  72. </p><p class="simpara">Some features or utilities in Buildroot, like the legal-info, or the
  73. graph generation tools, have additional dependencies. Although they
  74. are not mandatory for a simple build, they are still highly recommended:</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: circle; "><li class="listitem">
  75. <code class="literal">python</code> (version 2.7 or any later)
  76. </li></ul></div></li><li class="listitem"><p class="simpara">
  77. Configuration interface dependencies:
  78. </p><p class="simpara">For these libraries, you need to install both runtime and development
  79. data, which in many distributions are packaged separately. The
  80. development packages typically have a <span class="emphasis"><em>-dev</em></span> or <span class="emphasis"><em>-devel</em></span> suffix.</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: circle; "><li class="listitem">
  81. <code class="literal">ncurses5</code> to use the <span class="emphasis"><em>menuconfig</em></span> interface
  82. </li><li class="listitem">
  83. <code class="literal">qt5</code> to use the <span class="emphasis"><em>xconfig</em></span> interface
  84. </li><li class="listitem">
  85. <code class="literal">glib2</code>, <code class="literal">gtk2</code> and <code class="literal">glade2</code> to use the <span class="emphasis"><em>gconfig</em></span> interface
  86. </li></ul></div></li><li class="listitem"><p class="simpara">
  87. Source fetching tools:
  88. </p><p class="simpara">In the official tree, most of the package sources are retrieved using
  89. <code class="literal">wget</code> from <span class="emphasis"><em>ftp</em></span>, <span class="emphasis"><em>http</em></span> or <span class="emphasis"><em>https</em></span> locations. A few packages are only
  90. available through a version control system. Moreover, Buildroot is
  91. capable of downloading sources via other tools, like <code class="literal">git</code> or <code class="literal">scp</code>
  92. (refer to <a class="xref" href="#download-infra" title="Chapter 20. Download infrastructure">Chapter 20, <em>Download infrastructure</em></a> for more details). If you enable
  93. packages using any of these methods, you will need to install the
  94. corresponding tool on the host system:</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: circle; "><li class="listitem">
  95. <code class="literal">bazaar</code>
  96. </li><li class="listitem">
  97. <code class="literal">cvs</code>
  98. </li><li class="listitem">
  99. <code class="literal">git</code>
  100. </li><li class="listitem">
  101. <code class="literal">mercurial</code>
  102. </li><li class="listitem">
  103. <code class="literal">scp</code>
  104. </li><li class="listitem">
  105. <code class="literal">sftp</code>
  106. </li><li class="listitem">
  107. <code class="literal">subversion</code>
  108. </li></ul></div></li><li class="listitem"><p class="simpara">
  109. Java-related packages, if the Java Classpath needs to be built for
  110. the target system:
  111. </p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: circle; "><li class="listitem">
  112. The <code class="literal">javac</code> compiler
  113. </li><li class="listitem">
  114. The <code class="literal">jar</code> tool
  115. </li></ul></div></li><li class="listitem"><p class="simpara">
  116. Documentation generation tools:
  117. </p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: circle; "><li class="listitem">
  118. <code class="literal">asciidoc</code>, version 8.6.3 or higher
  119. </li><li class="listitem">
  120. <code class="literal">w3m</code>
  121. </li><li class="listitem">
  122. <code class="literal">python</code> with the <code class="literal">argparse</code> module (automatically present in 2.7+ and 3.2+)
  123. </li><li class="listitem">
  124. <code class="literal">dblatex</code> (required for the pdf manual only)
  125. </li></ul></div></li><li class="listitem"><p class="simpara">
  126. Graph generation tools:
  127. </p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: circle; "><li class="listitem">
  128. <code class="literal">graphviz</code> to use <span class="emphasis"><em>graph-depends</em></span> and <span class="emphasis"><em>&lt;pkg&gt;-graph-depends</em></span>
  129. </li><li class="listitem">
  130. <code class="literal">python-matplotlib</code> to use <span class="emphasis"><em>graph-build</em></span>
  131. </li></ul></div></li><li class="listitem"><p class="simpara">
  132. Package statistics tools (<span class="emphasis"><em>pkg-stats</em></span>):
  133. </p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: circle; "><li class="listitem">
  134. <code class="literal">python-aiohttp</code>
  135. </li></ul></div></li></ul></div></div></div><div class="chapter"><div class="titlepage"><div><div><h2 class="title"><a id="getting-buildroot"></a>Chapter 3. Getting Buildroot</h2></div></div></div><p>Buildroot releases are made every 3 months, in February, May, August and
  136. November. Release numbers are in the format YYYY.MM, so for example
  137. 2013.02, 2014.08.</p><p>Release tarballs are available at <a class="ulink" href="http://buildroot.org/downloads/" target="_top">http://buildroot.org/downloads/</a>.</p><p>For your convenience, a <a class="ulink" href="https://www.vagrantup.com/" target="_top">Vagrantfile</a> is
  138. available in <code class="literal">support/misc/Vagrantfile</code> in the Buildroot source tree
  139. to quickly set up a virtual machine with the needed dependencies to
  140. get started.</p><p>If you want to setup an isolated buildroot environment on Linux or Mac
  141. Os X, paste this line onto your terminal:</p><pre class="screen">curl -O https://buildroot.org/downloads/Vagrantfile; vagrant up</pre><p>If you are on Windows, paste this into your powershell:</p><pre class="screen">(new-object System.Net.WebClient).DownloadFile(
  142. "https://buildroot.org/downloads/Vagrantfile","Vagrantfile");
  143. vagrant up</pre><p>If you want to follow development, you can use the daily snapshots or
  144. make a clone of the Git repository. Refer to the
  145. <a class="ulink" href="http://buildroot.org/download" target="_top">Download page</a> of the Buildroot website
  146. for more details.</p></div><div class="chapter"><div class="titlepage"><div><div><h2 class="title"><a id="_buildroot_quick_start"></a>Chapter 4. Buildroot quick start</h2></div></div></div><p><span class="strong"><strong>Important</strong></span>: you can and should <span class="strong"><strong>build everything as a normal user</strong></span>. There
  147. is no need to be root to configure and use Buildroot. By running all
  148. commands as a regular user, you protect your system against packages
  149. behaving badly during compilation and installation.</p><p>The first step when using Buildroot is to create a configuration.
  150. Buildroot has a nice configuration tool similar to the one you can
  151. find in the <a class="ulink" href="http://www.kernel.org/" target="_top">Linux kernel</a> or in
  152. <a class="ulink" href="http://www.busybox.net/" target="_top">BusyBox</a>.</p><p>From the buildroot directory, run</p><pre class="screen"> $ make menuconfig</pre><p>for the original curses-based configurator, or</p><pre class="screen"> $ make nconfig</pre><p>for the new curses-based configurator, or</p><pre class="screen"> $ make xconfig</pre><p>for the Qt-based configurator, or</p><pre class="screen"> $ make gconfig</pre><p>for the GTK-based configurator.</p><p>All of these "make" commands will need to build a configuration
  153. utility (including the interface), so you may need to install
  154. "development" packages for relevant libraries used by the
  155. configuration utilities. Refer to <a class="xref" href="#requirement" title="Chapter 2. System requirements">Chapter 2, <em>System requirements</em></a> for more details,
  156. specifically the <a class="link" href="#requirement-optional" title="2.2. Optional packages">optional requirements</a>
  157. to get the dependencies of your favorite interface.</p><p>For each menu entry in the configuration tool, you can find associated
  158. help that describes the purpose of the entry. Refer to <a class="xref" href="#configure" title="Chapter 6. Buildroot configuration">Chapter 6, <em>Buildroot configuration</em></a>
  159. for details on some specific configuration aspects.</p><p>Once everything is configured, the configuration tool generates a
  160. <code class="literal">.config</code> file that contains the entire configuration. This file will be
  161. read by the top-level Makefile.</p><p>To start the build process, simply run:</p><pre class="screen"> $ make</pre><p>By default, Buildroot does not support top-level parallel build, so
  162. running <code class="literal">make -jN</code> is not necessary. There is however experimental
  163. support for top-level parallel build, see
  164. <a class="xref" href="#top-level-parallel-build" title="8.12. Top-level parallel build">Section 8.12, “Top-level parallel build”</a>.</p><p>The <code class="literal">make</code> command will generally perform the following steps:</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
  165. download source files (as required);
  166. </li><li class="listitem">
  167. configure, build and install the cross-compilation toolchain, or
  168. simply import an external toolchain;
  169. </li><li class="listitem">
  170. configure, build and install selected target packages;
  171. </li><li class="listitem">
  172. build a kernel image, if selected;
  173. </li><li class="listitem">
  174. build a bootloader image, if selected;
  175. </li><li class="listitem">
  176. create a root filesystem in selected formats.
  177. </li></ul></div><p>Buildroot output is stored in a single directory, <code class="literal">output/</code>.
  178. This directory contains several subdirectories:</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
  179. <code class="literal">images/</code> where all the images (kernel image, bootloader and root
  180. filesystem images) are stored. These are the files you need to put
  181. on your target system.
  182. </li><li class="listitem">
  183. <code class="literal">build/</code> where all the components are built (this includes tools
  184. needed by Buildroot on the host and packages compiled for the
  185. target). This directory contains one subdirectory for each of these
  186. components.
  187. </li><li class="listitem">
  188. <code class="literal">host/</code> contains both the tools built for the host, and the sysroot
  189. of the target toolchain. The former is an installation of tools
  190. compiled for the host that are needed for the proper execution of
  191. Buildroot, including the cross-compilation toolchain. The latter
  192. is a hierarchy similar to a root filesystem hierarchy. It contains
  193. the headers and libraries of all user-space packages that provide
  194. and install libraries used by other packages. However, this
  195. directory is <span class="emphasis"><em>not</em></span> intended to be the root filesystem for the target:
  196. it contains a lot of development files, unstripped binaries and
  197. libraries that make it far too big for an embedded system. These
  198. development files are used to compile libraries and applications for
  199. the target that depend on other libraries.
  200. </li><li class="listitem">
  201. <code class="literal">staging/</code> is a symlink to the target toolchain sysroot inside
  202. <code class="literal">host/</code>, which exists for backwards compatibility.
  203. </li><li class="listitem">
  204. <code class="literal">target/</code> which contains <span class="emphasis"><em>almost</em></span> the complete root filesystem for
  205. the target: everything needed is present except the device files in
  206. <code class="literal">/dev/</code> (Buildroot can’t create them because Buildroot doesn’t run
  207. as root and doesn’t want to run as root). Also, it doesn’t have the correct
  208. permissions (e.g. setuid for the busybox binary). Therefore, this directory
  209. <span class="strong"><strong>should not be used on your target</strong></span>. Instead, you should use one of
  210. the images built in the <code class="literal">images/</code> directory. If you need an
  211. extracted image of the root filesystem for booting over NFS, then
  212. use the tarball image generated in <code class="literal">images/</code> and extract it as
  213. root. Compared to <code class="literal">staging/</code>, <code class="literal">target/</code> contains only the files and
  214. libraries needed to run the selected target applications: the
  215. development files (headers, etc.) are not present, the binaries are
  216. stripped.
  217. </li></ul></div><p>These commands, <code class="literal">make menuconfig|nconfig|gconfig|xconfig</code> and <code class="literal">make</code>, are the
  218. basic ones that allow to easily and quickly generate images fitting
  219. your needs, with all the features and applications you enabled.</p><p>More details about the "make" command usage are given in
  220. <a class="xref" href="#make-tips" title="8.1. make tips">Section 8.1, “<span class="emphasis"><em>make</em></span> tips”</a>.</p></div><div class="chapter"><div class="titlepage"><div><div><h2 class="title"><a id="community-resources"></a>Chapter 5. Community resources</h2></div></div></div><p>Like any open source project, Buildroot has different ways to share
  221. information in its community and outside.</p><p>Each of those ways may interest you if you are looking for some help,
  222. want to understand Buildroot or contribute to the project.</p><div class="variablelist"><dl class="variablelist"><dt><span class="term">
  223. Mailing List
  224. </span></dt><dd><p class="simpara">Buildroot has a mailing list for discussion and development. It is the
  225. main method of interaction for Buildroot users and developers.</p><p class="simpara">Only subscribers to the Buildroot mailing list are allowed to post to
  226. this list. You can subscribe via the
  227. <a class="ulink" href="http://lists.buildroot.org/mailman/listinfo/buildroot" target="_top">mailing list info
  228. page</a>.</p><p class="simpara">Mails that are sent to the mailing list are also available in the
  229. mailing list archives, available through
  230. <a class="ulink" href="http://lists.buildroot.org/pipermail/buildroot" target="_top">Mailman</a> or at
  231. <a class="ulink" href="https://lore.kernel.org/buildroot/" target="_top">lore.kernel.org</a>.</p></dd><dt><span class="term">
  232. IRC
  233. </span></dt><dd><p class="simpara">The Buildroot IRC channel <a class="ulink" href="irc://irc.oftc.net/#buildroot" target="_top">#buildroot</a> is
  234. hosted on <a class="ulink" href="https://www.oftc.net/WebChat/" target="_top">OFTC</a>. It is a useful place to
  235. ask quick questions or discuss on certain topics.</p><p class="simpara">When asking for help on IRC, share relevant logs or pieces of code
  236. using a code sharing website, such as <a class="ulink" href="https://paste.ack.tf/" target="_top">https://paste.ack.tf/</a>.</p><p class="simpara">Note that for certain questions, posting to the mailing list may be
  237. better as it will reach more people, both developers and users.</p></dd><dt><span class="term">
  238. Bug tracker
  239. </span></dt><dd>Bugs in Buildroot can be reported via the mailing list or alternatively
  240. via the <a class="ulink" href="https://bugs.buildroot.org/buglist.cgi?product=buildroot" target="_top">Buildroot
  241. bugtracker</a>. Please refer to <a class="xref" href="#reporting-bugs" title="22.6. Reporting issues/bugs or getting help">Section 22.6, “Reporting issues/bugs or getting help”</a> before creating a bug
  242. report.</dd><dt><span class="term">
  243. Wiki
  244. </span></dt><dd><a class="ulink" href="http://elinux.org/Buildroot" target="_top">The Buildroot wiki page</a> is hosted on
  245. the <a class="ulink" href="http://elinux.org" target="_top">eLinux</a> wiki. It contains some useful links, an
  246. overview of past and upcoming events, and a TODO list.</dd><dt><span class="term">
  247. Patchwork
  248. </span></dt><dd><p class="simpara">Patchwork is a web-based patch tracking system designed to facilitate
  249. the contribution and management of contributions to an open-source
  250. project. Patches that have been sent to a mailing list are 'caught' by
  251. the system, and appear on a web page. Any comments posted that
  252. reference the patch are appended to the patch page too. For more
  253. information on Patchwork see
  254. <a class="ulink" href="http://jk.ozlabs.org/projects/patchwork/" target="_top">http://jk.ozlabs.org/projects/patchwork/</a>.</p><p class="simpara">Buildroot’s Patchwork website is mainly for use by Buildroot’s
  255. maintainer to ensure patches aren’t missed. It is also used by Buildroot
  256. patch reviewers (see also <a class="xref" href="#apply-patches-patchwork" title="22.3.1. Applying Patches from Patchwork">Section 22.3.1, “Applying Patches from Patchwork”</a>).
  257. However, since the website exposes patches and their corresponding
  258. review comments in a clean and concise web interface, it can be useful
  259. for all Buildroot developers.</p><p class="simpara">The Buildroot patch management interface is available at
  260. <a class="ulink" href="https://patchwork.ozlabs.org/project/buildroot/list/" target="_top">https://patchwork.ozlabs.org/project/buildroot/list/</a>.</p></dd></dl></div></div></div><div class="part"><div class="titlepage"><div><div><h1 class="title"><a id="_user_guide"></a>Part II. User guide</h1></div></div></div><div class="chapter"><div class="titlepage"><div><div><h2 class="title"><a id="configure"></a>Chapter 6. Buildroot configuration</h2></div></div></div><p>All the configuration options in <code class="literal">make *config</code> have a help text
  261. providing details about the option.</p><p>The <code class="literal">make *config</code> commands also offer a search tool. Read the help
  262. message in the different frontend menus to know how to use it:</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
  263. in <span class="emphasis"><em>menuconfig</em></span>, the search tool is called by pressing <code class="literal">/</code>;
  264. </li><li class="listitem">
  265. in <span class="emphasis"><em>xconfig</em></span>, the search tool is called by pressing <code class="literal">Ctrl</code> + <code class="literal">f</code>.
  266. </li></ul></div><p>The result of the search shows the help message of the matching items.
  267. In <span class="emphasis"><em>menuconfig</em></span>, numbers in the left column provide a shortcut to the
  268. corresponding entry. Just type this number to directly jump to the
  269. entry, or to the containing menu in case the entry is not selectable due
  270. to a missing dependency.</p><p>Although the menu structure and the help text of the entries should be
  271. sufficiently self-explanatory, a number of topics require additional
  272. explanation that cannot easily be covered in the help text and are
  273. therefore covered in the following sections.</p><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="_cross_compilation_toolchain"></a>6.1. Cross-compilation toolchain</h2></div></div></div><p>A compilation toolchain is the set of tools that allows you to compile
  274. code for your system. It consists of a compiler (in our case, <code class="literal">gcc</code>),
  275. binary utils like assembler and linker (in our case, <code class="literal">binutils</code>) and a
  276. C standard library (for example
  277. <a class="ulink" href="http://www.gnu.org/software/libc/libc.html" target="_top">GNU Libc</a>,
  278. <a class="ulink" href="http://www.uclibc-ng.org/" target="_top">uClibc-ng</a>).</p><p>The system installed on your development station certainly already has
  279. a compilation toolchain that you can use to compile an application
  280. that runs on your system. If you’re using a PC, your compilation
  281. toolchain runs on an x86 processor and generates code for an x86
  282. processor. Under most Linux systems, the compilation toolchain uses
  283. the GNU libc (glibc) as the C standard library. This compilation
  284. toolchain is called the "host compilation toolchain". The machine on
  285. which it is running, and on which you’re working, is called the "host
  286. system" <a href="#ftn.idm375" class="footnote" id="idm375"><sup class="footnote">[3]</sup></a>.</p><p>The compilation toolchain is provided by your distribution, and
  287. Buildroot has nothing to do with it (other than using it to build a
  288. cross-compilation toolchain and other tools that are run on the
  289. development host).</p><p>As said above, the compilation toolchain that comes with your system
  290. runs on and generates code for the processor in your host system. As
  291. your embedded system has a different processor, you need a
  292. cross-compilation toolchain - a compilation toolchain that runs on
  293. your <span class="emphasis"><em>host system</em></span> but generates code for your <span class="emphasis"><em>target system</em></span> (and
  294. target processor). For example, if your host system uses x86 and your
  295. target system uses ARM, the regular compilation toolchain on your host
  296. runs on x86 and generates code for x86, while the cross-compilation
  297. toolchain runs on x86 and generates code for ARM.</p><p>Buildroot provides two solutions for the cross-compilation toolchain:</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
  298. The <span class="strong"><strong>internal toolchain backend</strong></span>, called <code class="literal">Buildroot toolchain</code> in
  299. the configuration interface.
  300. </li><li class="listitem">
  301. The <span class="strong"><strong>external toolchain backend</strong></span>, called <code class="literal">External toolchain</code> in
  302. the configuration interface.
  303. </li></ul></div><p>The choice between these two solutions is done using the <code class="literal">Toolchain
  304. Type</code> option in the <code class="literal">Toolchain</code> menu. Once one solution has been
  305. chosen, a number of configuration options appear, they are detailed in
  306. the following sections.</p><div class="section"><div class="titlepage"><div><div><h3 class="title"><a id="internal-toolchain-backend"></a>6.1.1. Internal toolchain backend</h3></div></div></div><p>The <span class="emphasis"><em>internal toolchain backend</em></span> is the backend where Buildroot builds
  307. by itself a cross-compilation toolchain, before building the userspace
  308. applications and libraries for your target embedded system.</p><p>This backend supports several C libraries:
  309. <a class="ulink" href="http://www.uclibc-ng.org" target="_top">uClibc-ng</a>,
  310. <a class="ulink" href="http://www.gnu.org/software/libc/libc.html" target="_top">glibc</a> and
  311. <a class="ulink" href="http://www.musl-libc.org" target="_top">musl</a>.</p><p>Once you have selected this backend, a number of options appear. The
  312. most important ones allow to:</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
  313. Change the version of the Linux kernel headers used to build the
  314. toolchain. This item deserves a few explanations. In the process of
  315. building a cross-compilation toolchain, the C library is being
  316. built. This library provides the interface between userspace
  317. applications and the Linux kernel. In order to know how to "talk"
  318. to the Linux kernel, the C library needs to have access to the
  319. <span class="emphasis"><em>Linux kernel headers</em></span> (i.e. the <code class="literal">.h</code> files from the kernel), which
  320. define the interface between userspace and the kernel (system
  321. calls, data structures, etc.). Since this interface is backward
  322. compatible, the version of the Linux kernel headers used to build
  323. your toolchain do not need to match <span class="emphasis"><em>exactly</em></span> the version of the
  324. Linux kernel you intend to run on your embedded system. They only
  325. need to have a version equal or older to the version of the Linux
  326. kernel you intend to run. If you use kernel headers that are more
  327. recent than the Linux kernel you run on your embedded system, then
  328. the C library might be using interfaces that are not provided by
  329. your Linux kernel.
  330. </li><li class="listitem">
  331. Change the version of the GCC compiler, binutils and the C library.
  332. </li><li class="listitem">
  333. Select a number of toolchain options (uClibc only): whether the
  334. toolchain should have RPC support (used mainly for NFS),
  335. wide-char support, locale support (for internationalization),
  336. C++ support or thread support. Depending on which options you choose,
  337. the number of userspace applications and libraries visible in
  338. Buildroot menus will change: many applications and libraries require
  339. certain toolchain options to be enabled. Most packages show a comment
  340. when a certain toolchain option is required to be able to enable
  341. those packages. If needed, you can further refine the uClibc
  342. configuration by running <code class="literal">make uclibc-menuconfig</code>. Note however that
  343. all packages in Buildroot are tested against the default uClibc
  344. configuration bundled in Buildroot: if you deviate from this
  345. configuration by removing features from uClibc, some packages may no
  346. longer build.
  347. </li></ul></div><p>It is worth noting that whenever one of those options is modified,
  348. then the entire toolchain and system must be rebuilt. See
  349. <a class="xref" href="#full-rebuild" title="8.2. Understanding when a full rebuild is necessary">Section 8.2, “Understanding when a full rebuild is necessary”</a>.</p><p>Advantages of this backend:</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
  350. Well integrated with Buildroot
  351. </li><li class="listitem">
  352. Fast, only builds what’s necessary
  353. </li></ul></div><p>Drawbacks of this backend:</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
  354. Rebuilding the toolchain is needed when doing <code class="literal">make clean</code>, which
  355. takes time. If you’re trying to reduce your build time, consider
  356. using the <span class="emphasis"><em>External toolchain backend</em></span>.
  357. </li></ul></div></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a id="external-toolchain-backend"></a>6.1.2. External toolchain backend</h3></div></div></div><p>The <span class="emphasis"><em>external toolchain backend</em></span> allows to use existing pre-built
  358. cross-compilation toolchains. Buildroot knows about a number of
  359. well-known cross-compilation toolchains (from
  360. <a class="ulink" href="http://www.linaro.org" target="_top">Linaro</a> for ARM,
  361. <a class="ulink" href="http://www.mentor.com/embedded-software/sourcery-tools/sourcery-codebench/editions/lite-edition/" target="_top">Sourcery
  362. CodeBench</a> for ARM, x86-64, PowerPC, and MIPS, and is capable of
  363. downloading them automatically, or it can be pointed to a custom
  364. toolchain, either available for download or installed locally.</p><p>Then, you have three solutions to use an external toolchain:</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
  365. Use a predefined external toolchain profile, and let Buildroot
  366. download, extract and install the toolchain. Buildroot already knows
  367. about a few CodeSourcery and Linaro toolchains. Just select the
  368. toolchain profile in <code class="literal">Toolchain</code> from the available ones. This is
  369. definitely the easiest solution.
  370. </li><li class="listitem">
  371. Use a predefined external toolchain profile, but instead of having
  372. Buildroot download and extract the toolchain, you can tell Buildroot
  373. where your toolchain is already installed on your system. Just
  374. select the toolchain profile in <code class="literal">Toolchain</code> through the available
  375. ones, unselect <code class="literal">Download toolchain automatically</code>, and fill the
  376. <code class="literal">Toolchain path</code> text entry with the path to your cross-compiling
  377. toolchain.
  378. </li><li class="listitem">
  379. Use a completely custom external toolchain. This is particularly
  380. useful for toolchains generated using crosstool-NG or with Buildroot
  381. itself. To do this, select the <code class="literal">Custom toolchain</code> solution in the
  382. <code class="literal">Toolchain</code> list. You need to fill the <code class="literal">Toolchain path</code>, <code class="literal">Toolchain
  383. prefix</code> and <code class="literal">External toolchain C library</code> options. Then, you have
  384. to tell Buildroot what your external toolchain supports. If your
  385. external toolchain uses the <span class="emphasis"><em>glibc</em></span> library, you only have to tell
  386. whether your toolchain supports C++ or not and whether it has
  387. built-in RPC support. If your external toolchain uses the <span class="emphasis"><em>uClibc</em></span>
  388. library, then you have to tell Buildroot if it supports RPC,
  389. wide-char, locale, program invocation, threads and C++.
  390. At the beginning of the execution, Buildroot will tell you if
  391. the selected options do not match the toolchain configuration.
  392. </li></ul></div><p>Our external toolchain support has been tested with toolchains from
  393. CodeSourcery and Linaro, toolchains generated by
  394. <a class="ulink" href="http://crosstool-ng.org" target="_top">crosstool-NG</a>, and toolchains generated by
  395. Buildroot itself. In general, all toolchains that support the
  396. <span class="emphasis"><em>sysroot</em></span> feature should work. If not, do not hesitate to contact the
  397. developers.</p><p>We do not support toolchains or SDK generated by OpenEmbedded or
  398. Yocto, because these toolchains are not pure toolchains (i.e. just the
  399. compiler, binutils, the C and C++ libraries). Instead these toolchains
  400. come with a very large set of pre-compiled libraries and
  401. programs. Therefore, Buildroot cannot import the <span class="emphasis"><em>sysroot</em></span> of the
  402. toolchain, as it would contain hundreds of megabytes of pre-compiled
  403. libraries that are normally built by Buildroot.</p><p>We also do not support using the distribution toolchain (i.e. the
  404. gcc/binutils/C library installed by your distribution) as the
  405. toolchain to build software for the target. This is because your
  406. distribution toolchain is not a "pure" toolchain (i.e. only with the
  407. C/C++ library), so we cannot import it properly into the Buildroot
  408. build environment. So even if you are building a system for a x86 or
  409. x86_64 target, you have to generate a cross-compilation toolchain with
  410. Buildroot or crosstool-NG.</p><p>If you want to generate a custom toolchain for your project, that can
  411. be used as an external toolchain in Buildroot, our recommendation is
  412. to build it either with Buildroot itself (see
  413. <a class="xref" href="#build-toolchain-with-buildroot" title="6.1.3. Build an external toolchain with Buildroot">Section 6.1.3, “Build an external toolchain with Buildroot”</a>) or with
  414. <a class="ulink" href="http://crosstool-ng.org" target="_top">crosstool-NG</a>.</p><p>Advantages of this backend:</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
  415. Allows to use well-known and well-tested cross-compilation
  416. toolchains.
  417. </li><li class="listitem">
  418. Avoids the build time of the cross-compilation toolchain, which is
  419. often very significant in the overall build time of an embedded
  420. Linux system.
  421. </li></ul></div><p>Drawbacks of this backend:</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
  422. If your pre-built external toolchain has a bug, may be hard to get a
  423. fix from the toolchain vendor, unless you build your external
  424. toolchain by yourself using Buildroot or Crosstool-NG.
  425. </li></ul></div></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a id="build-toolchain-with-buildroot"></a>6.1.3. Build an external toolchain with Buildroot</h3></div></div></div><p>The Buildroot internal toolchain option can be used to create an
  426. external toolchain. Here are a series of steps to build an internal
  427. toolchain and package it up for reuse by Buildroot itself (or other
  428. projects).</p><p>Create a new Buildroot configuration, with the following details:</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
  429. Select the appropriate <span class="strong"><strong>Target options</strong></span> for your target CPU
  430. architecture
  431. </li><li class="listitem">
  432. In the <span class="strong"><strong>Toolchain</strong></span> menu, keep the default of <span class="strong"><strong>Buildroot toolchain</strong></span>
  433. for <span class="strong"><strong>Toolchain type</strong></span>, and configure your toolchain as desired
  434. </li><li class="listitem">
  435. In the <span class="strong"><strong>System configuration</strong></span> menu, select <span class="strong"><strong>None</strong></span> as the <span class="strong"><strong>Init
  436. system</strong></span> and <span class="strong"><strong>none</strong></span> as <span class="strong"><strong>/bin/sh</strong></span>
  437. </li><li class="listitem">
  438. In the <span class="strong"><strong>Target packages</strong></span> menu, disable <span class="strong"><strong>BusyBox</strong></span>
  439. </li><li class="listitem">
  440. In the <span class="strong"><strong>Filesystem images</strong></span> menu, disable <span class="strong"><strong>tar the root filesystem</strong></span>
  441. </li></ul></div><p>Then, we can trigger the build, and also ask Buildroot to generate a
  442. SDK. This will conveniently generate for us a tarball which contains
  443. our toolchain:</p><pre class="screen">make sdk</pre><p>This produces the SDK tarball in <code class="literal">$(O)/images</code>, with a name similar to
  444. <code class="literal">arm-buildroot-linux-uclibcgnueabi_sdk-buildroot.tar.gz</code>. Save this
  445. tarball, as it is now the toolchain that you can re-use as an external
  446. toolchain in other Buildroot projects.</p><p>In those other Buildroot projects, in the <span class="strong"><strong>Toolchain</strong></span> menu:</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
  447. Set <span class="strong"><strong>Toolchain type</strong></span> to <span class="strong"><strong>External toolchain</strong></span>
  448. </li><li class="listitem">
  449. Set <span class="strong"><strong>Toolchain</strong></span> to <span class="strong"><strong>Custom toolchain</strong></span>
  450. </li><li class="listitem">
  451. Set <span class="strong"><strong>Toolchain origin</strong></span> to <span class="strong"><strong>Toolchain to be downloaded and installed</strong></span>
  452. </li><li class="listitem">
  453. Set <span class="strong"><strong>Toolchain URL</strong></span> to <code class="literal">file:///path/to/your/sdk/tarball.tar.gz</code>
  454. </li></ul></div><div class="section"><div class="titlepage"><div><div><h4 class="title"><a id="_external_toolchain_wrapper"></a>External toolchain wrapper</h4></div></div></div><p>When using an external toolchain, Buildroot generates a wrapper program,
  455. that transparently passes the appropriate options (according to the
  456. configuration) to the external toolchain programs. In case you need to
  457. debug this wrapper to check exactly what arguments are passed, you can
  458. set the environment variable <code class="literal">BR2_DEBUG_WRAPPER</code> to either one of:</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
  459. <code class="literal">0</code>, empty or not set: no debug
  460. </li><li class="listitem">
  461. <code class="literal">1</code>: trace all arguments on a single line
  462. </li><li class="listitem">
  463. <code class="literal">2</code>: trace one argument per line
  464. </li></ul></div></div></div></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="_dev_management"></a>6.2. /dev management</h2></div></div></div><p>On a Linux system, the <code class="literal">/dev</code> directory contains special files, called
  465. <span class="emphasis"><em>device files</em></span>, that allow userspace applications to access the
  466. hardware devices managed by the Linux kernel. Without these <span class="emphasis"><em>device
  467. files</em></span>, your userspace applications would not be able to use the
  468. hardware devices, even if they are properly recognized by the Linux
  469. kernel.</p><p>Under <code class="literal">System configuration</code>, <code class="literal">/dev management</code>, Buildroot offers four
  470. different solutions to handle the <code class="literal">/dev</code> directory :</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
  471. The first solution is <span class="strong"><strong>Static using device table</strong></span>. This is the old
  472. classical way of handling device files in Linux. With this method,
  473. the device files are persistently stored in the root filesystem
  474. (i.e. they persist across reboots), and there is nothing that will
  475. automatically create and remove those device files when hardware
  476. devices are added or removed from the system. Buildroot therefore
  477. creates a standard set of device files using a <span class="emphasis"><em>device table</em></span>, the
  478. default one being stored in <code class="literal">system/device_table_dev.txt</code> in the
  479. Buildroot source code. This file is processed when Buildroot
  480. generates the final root filesystem image, and the <span class="emphasis"><em>device files</em></span>
  481. are therefore not visible in the <code class="literal">output/target</code> directory. The
  482. <code class="literal">BR2_ROOTFS_STATIC_DEVICE_TABLE</code> option allows to change the
  483. default device table used by Buildroot, or to add an additional
  484. device table, so that additional <span class="emphasis"><em>device files</em></span> are created by
  485. Buildroot during the build. So, if you use this method, and a
  486. <span class="emphasis"><em>device file</em></span> is missing in your system, you can for example create
  487. a <code class="literal">board/&lt;yourcompany&gt;/&lt;yourproject&gt;/device_table_dev.txt</code> file
  488. that contains the description of your additional <span class="emphasis"><em>device files</em></span>,
  489. and then you can set <code class="literal">BR2_ROOTFS_STATIC_DEVICE_TABLE</code> to
  490. <code class="literal">system/device_table_dev.txt
  491. board/&lt;yourcompany&gt;/&lt;yourproject&gt;/device_table_dev.txt</code>. For more
  492. details about the format of the device table file, see
  493. <a class="xref" href="#makedev-syntax" title="Chapter 25. Makedev syntax documentation">Chapter 25, <em>Makedev syntax documentation</em></a>.
  494. </li><li class="listitem">
  495. The second solution is <span class="strong"><strong>Dynamic using devtmpfs only</strong></span>. <span class="emphasis"><em>devtmpfs</em></span> is
  496. a virtual filesystem inside the Linux kernel that has been
  497. introduced in kernel 2.6.32 (if you use an older kernel, it is not
  498. possible to use this option). When mounted in <code class="literal">/dev</code>, this virtual
  499. filesystem will automatically make <span class="emphasis"><em>device files</em></span> appear and
  500. disappear as hardware devices are added and removed from the
  501. system. This filesystem is not persistent across reboots: it is
  502. filled dynamically by the kernel. Using <span class="emphasis"><em>devtmpfs</em></span> requires the
  503. following kernel configuration options to be enabled:
  504. <code class="literal">CONFIG_DEVTMPFS</code> and <code class="literal">CONFIG_DEVTMPFS_MOUNT</code>. When Buildroot is in
  505. charge of building the Linux kernel for your embedded device, it
  506. makes sure that those two options are enabled. However, if you
  507. build your Linux kernel outside of Buildroot, then it is your
  508. responsibility to enable those two options (if you fail to do so,
  509. your Buildroot system will not boot).
  510. </li><li class="listitem">
  511. The third solution is <span class="strong"><strong>Dynamic using devtmpfs + mdev</strong></span>. This method
  512. also relies on the <span class="emphasis"><em>devtmpfs</em></span> virtual filesystem detailed above (so
  513. the requirement to have <code class="literal">CONFIG_DEVTMPFS</code> and
  514. <code class="literal">CONFIG_DEVTMPFS_MOUNT</code> enabled in the kernel configuration still
  515. apply), but adds the <code class="literal">mdev</code> userspace utility on top of it. <code class="literal">mdev</code>
  516. is a program part of BusyBox that the kernel will call every time a
  517. device is added or removed. Thanks to the <code class="literal">/etc/mdev.conf</code>
  518. configuration file, <code class="literal">mdev</code> can be configured to for example, set
  519. specific permissions or ownership on a device file, call a script
  520. or application whenever a device appears or disappear,
  521. etc. Basically, it allows <span class="emphasis"><em>userspace</em></span> to react on device addition
  522. and removal events. <code class="literal">mdev</code> can for example be used to automatically
  523. load kernel modules when devices appear on the system. <code class="literal">mdev</code> is
  524. also important if you have devices that require a firmware, as it
  525. will be responsible for pushing the firmware contents to the
  526. kernel. <code class="literal">mdev</code> is a lightweight implementation (with fewer
  527. features) of <code class="literal">udev</code>. For more details about <code class="literal">mdev</code> and the syntax
  528. of its configuration file, see
  529. <a class="ulink" href="http://git.busybox.net/busybox/tree/docs/mdev.txt" target="_top">http://git.busybox.net/busybox/tree/docs/mdev.txt</a>.
  530. </li><li class="listitem">
  531. The fourth solution is <span class="strong"><strong>Dynamic using devtmpfs + eudev</strong></span>. This
  532. method also relies on the <span class="emphasis"><em>devtmpfs</em></span> virtual filesystem detailed
  533. above, but adds the <code class="literal">eudev</code> userspace daemon on top of it. <code class="literal">eudev</code>
  534. is a daemon that runs in the background, and gets called by the
  535. kernel when a device gets added or removed from the system. It is a
  536. more heavyweight solution than <code class="literal">mdev</code>, but provides higher
  537. flexibility. <code class="literal">eudev</code> is a standalone version of <code class="literal">udev</code>, the
  538. original userspace daemon used in most desktop Linux distributions,
  539. which is now part of Systemd. For more details, see
  540. <a class="ulink" href="http://en.wikipedia.org/wiki/Udev" target="_top">http://en.wikipedia.org/wiki/Udev</a>.
  541. </li></ul></div><p>The Buildroot developers recommendation is to start with the <span class="strong"><strong>Dynamic
  542. using devtmpfs only</strong></span> solution, until you have the need for userspace
  543. to be notified when devices are added/removed, or if firmwares are
  544. needed, in which case <span class="strong"><strong>Dynamic using devtmpfs + mdev</strong></span> is usually a
  545. good solution.</p><p>Note that if <code class="literal">systemd</code> is chosen as init system, /dev management will
  546. be performed by the <code class="literal">udev</code> program provided by <code class="literal">systemd</code>.</p></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="init-system"></a>6.3. init system</h2></div></div></div><p>The <span class="emphasis"><em>init</em></span> program is the first userspace program started by the
  547. kernel (it carries the PID number 1), and is responsible for starting
  548. the userspace services and programs (for example: web server,
  549. graphical applications, other network servers, etc.).</p><p>Buildroot allows to use three different types of init systems, which
  550. can be chosen from <code class="literal">System configuration</code>, <code class="literal">Init system</code>:</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
  551. The first solution is <span class="strong"><strong>BusyBox</strong></span>. Amongst many programs, BusyBox has
  552. an implementation of a basic <code class="literal">init</code> program, which is sufficient
  553. for most embedded systems. Enabling the <code class="literal">BR2_INIT_BUSYBOX</code> will
  554. ensure BusyBox will build and install its <code class="literal">init</code> program. This is
  555. the default solution in Buildroot. The BusyBox <code class="literal">init</code> program will
  556. read the <code class="literal">/etc/inittab</code> file at boot to know what to do. The syntax
  557. of this file can be found in
  558. <a class="ulink" href="http://git.busybox.net/busybox/tree/examples/inittab" target="_top">http://git.busybox.net/busybox/tree/examples/inittab</a> (note that
  559. BusyBox <code class="literal">inittab</code> syntax is special: do not use a random <code class="literal">inittab</code>
  560. documentation from the Internet to learn about BusyBox
  561. <code class="literal">inittab</code>). The default <code class="literal">inittab</code> in Buildroot is stored in
  562. <code class="literal">package/busybox/inittab</code>. Apart from mounting a few important
  563. filesystems, the main job the default inittab does is to start the
  564. <code class="literal">/etc/init.d/rcS</code> shell script, and start a <code class="literal">getty</code> program (which
  565. provides a login prompt).
  566. </li><li class="listitem">
  567. The second solution is <span class="strong"><strong>systemV</strong></span>. This solution uses the old
  568. traditional <span class="emphasis"><em>sysvinit</em></span> program, packed in Buildroot in
  569. <code class="literal">package/sysvinit</code>. This was the solution used in most desktop
  570. Linux distributions, until they switched to more recent
  571. alternatives such as Upstart or Systemd. <code class="literal">sysvinit</code> also works with
  572. an <code class="literal">inittab</code> file (which has a slightly different syntax than the
  573. one from BusyBox). The default <code class="literal">inittab</code> installed with this init
  574. solution is located in <code class="literal">package/sysvinit/inittab</code>.
  575. </li><li class="listitem">
  576. The third solution is <span class="strong"><strong>systemd</strong></span>. <code class="literal">systemd</code> is the new generation
  577. init system for Linux. It does far more than traditional <span class="emphasis"><em>init</em></span>
  578. programs: aggressive parallelization capabilities, uses socket and
  579. D-Bus activation for starting services, offers on-demand starting
  580. of daemons, keeps track of processes using Linux control groups,
  581. supports snapshotting and restoring of the system state,
  582. etc. <code class="literal">systemd</code> will be useful on relatively complex embedded
  583. systems, for example the ones requiring D-Bus and services
  584. communicating between each other. It is worth noting that <code class="literal">systemd</code>
  585. brings a fairly big number of large dependencies: <code class="literal">dbus</code>, <code class="literal">udev</code>
  586. and more. For more details about <code class="literal">systemd</code>, see
  587. <a class="ulink" href="http://www.freedesktop.org/wiki/Software/systemd" target="_top">http://www.freedesktop.org/wiki/Software/systemd</a>.
  588. </li></ul></div><p>The solution recommended by Buildroot developers is to use the
  589. <span class="strong"><strong>BusyBox init</strong></span> as it is sufficient for most embedded
  590. systems. <span class="strong"><strong>systemd</strong></span> can be used for more complex situations.</p></div><div class="footnotes"><br /><hr style="width:100; text-align:left;margin-left: 0" /><div id="ftn.idm375" class="footnote"><p><a href="#idm375" class="simpara"><sup class="simpara">[3] </sup></a>This terminology differs from what is used by GNU
  591. configure, where the host is the machine on which the application will
  592. run (which is usually the same as target)</p></div></div></div><div class="chapter"><div class="titlepage"><div><div><h2 class="title"><a id="_configuration_of_other_components"></a>Chapter 7. Configuration of other components</h2></div></div></div><p>Before attempting to modify any of the components below, make sure you
  593. have already configured Buildroot itself, and have enabled the
  594. corresponding package.</p><div class="variablelist"><dl class="variablelist"><dt><span class="term">
  595. BusyBox
  596. </span></dt><dd><p class="simpara">If you already have a BusyBox configuration file, you can directly
  597. specify this file in the Buildroot configuration, using
  598. <code class="literal">BR2_PACKAGE_BUSYBOX_CONFIG</code>. Otherwise, Buildroot will start from a
  599. default BusyBox configuration file.</p><p class="simpara">To make subsequent changes to the configuration, use <code class="literal">make
  600. busybox-menuconfig</code> to open the BusyBox configuration editor.</p><p class="simpara">It is also possible to specify a BusyBox configuration file through an
  601. environment variable, although this is not recommended. Refer to
  602. <a class="xref" href="#env-vars" title="8.6. Environment variables">Section 8.6, “Environment variables”</a> for more details.</p></dd><dt><span class="term">
  603. uClibc
  604. </span></dt><dd>Configuration of uClibc is done in the same way as for BusyBox. The
  605. configuration variable to specify an existing configuration file is
  606. <code class="literal">BR2_UCLIBC_CONFIG</code>. The command to make subsequent changes is <code class="literal">make
  607. uclibc-menuconfig</code>.</dd><dt><span class="term">
  608. Linux kernel
  609. </span></dt><dd><p class="simpara">If you already have a kernel configuration file, you can directly
  610. specify this file in the Buildroot configuration, using
  611. <code class="literal">BR2_LINUX_KERNEL_USE_CUSTOM_CONFIG</code>.</p><p class="simpara">If you do not yet have a kernel configuration file, you can either start
  612. by specifying a defconfig in the Buildroot configuration, using
  613. <code class="literal">BR2_LINUX_KERNEL_USE_DEFCONFIG</code>, or start by creating an empty file and
  614. specifying it as custom configuration file, using
  615. <code class="literal">BR2_LINUX_KERNEL_USE_CUSTOM_CONFIG</code>.</p><p class="simpara">To make subsequent changes to the configuration, use <code class="literal">make
  616. linux-menuconfig</code> to open the Linux configuration editor.</p></dd><dt><span class="term">
  617. Barebox
  618. </span></dt><dd>Configuration of Barebox is done in the same way as for the Linux
  619. kernel. The corresponding configuration variables are
  620. <code class="literal">BR2_TARGET_BAREBOX_USE_CUSTOM_CONFIG</code> and
  621. <code class="literal">BR2_TARGET_BAREBOX_USE_DEFCONFIG</code>. To open the configuration editor,
  622. use <code class="literal">make barebox-menuconfig</code>.</dd><dt><span class="term">
  623. U-Boot
  624. </span></dt><dd>Configuration of U-Boot (version 2015.04 or newer) is done in the same
  625. way as for the Linux kernel. The corresponding configuration variables
  626. are <code class="literal">BR2_TARGET_UBOOT_USE_CUSTOM_CONFIG</code> and
  627. <code class="literal">BR2_TARGET_UBOOT_USE_DEFCONFIG</code>. To open the configuration editor,
  628. use <code class="literal">make uboot-menuconfig</code>.</dd></dl></div></div><div class="chapter"><div class="titlepage"><div><div><h2 class="title"><a id="_general_buildroot_usage"></a>Chapter 8. General Buildroot usage</h2></div></div></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="make-tips"></a>8.1. <span class="emphasis"><em>make</em></span> tips</h2></div></div></div><p>This is a collection of tips that help you make the most of Buildroot.</p><p><strong>Display all commands executed by make: </strong>
  629. </p><pre class="screen"> $ make V=1 &lt;target&gt;</pre><p>
  630. </p><p><strong>Display the list of boards with a defconfig: </strong>
  631. </p><pre class="screen"> $ make list-defconfigs</pre><p>
  632. </p><p><strong>Display all available targets: </strong>
  633. </p><pre class="screen"> $ make help</pre><p>
  634. </p><p>Not all targets are always available,
  635. some settings in the <code class="literal">.config</code> file may hide some targets:</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
  636. <code class="literal">busybox-menuconfig</code> only works when <code class="literal">busybox</code> is enabled;
  637. </li><li class="listitem">
  638. <code class="literal">linux-menuconfig</code> and <code class="literal">linux-savedefconfig</code> only work when
  639. <code class="literal">linux</code> is enabled;
  640. </li><li class="listitem">
  641. <code class="literal">uclibc-menuconfig</code> is only available when the uClibc C library is
  642. selected in the internal toolchain backend;
  643. </li><li class="listitem">
  644. <code class="literal">barebox-menuconfig</code> and <code class="literal">barebox-savedefconfig</code> only work when the
  645. <code class="literal">barebox</code> bootloader is enabled.
  646. </li><li class="listitem">
  647. <code class="literal">uboot-menuconfig</code> and <code class="literal">uboot-savedefconfig</code> only work when the
  648. <code class="literal">U-Boot</code> bootloader is enabled and the <code class="literal">uboot</code> build system is set
  649. to <code class="literal">Kconfig</code>.
  650. </li></ul></div><p><strong>Cleaning: </strong>Explicit cleaning is required when any of the architecture or toolchain
  651. configuration options are changed.</p><p>To delete all build products (including build directories, host, staging
  652. and target trees, the images and the toolchain):</p><pre class="screen"> $ make clean</pre><p><strong>Generating the manual: </strong>The present manual sources are located in the <span class="emphasis"><em>docs/manual</em></span> directory.
  653. To generate the manual:</p><pre class="screen"> $ make manual-clean
  654. $ make manual</pre><p>The manual outputs will be generated in <span class="emphasis"><em>output/docs/manual</em></span>.</p><div class="itemizedlist"><p class="title"><strong>Notes</strong></p><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
  655. A few tools are required to build the documentation (see:
  656. <a class="xref" href="#requirement-optional" title="2.2. Optional packages">Section 2.2, “Optional packages”</a>).
  657. </li></ul></div><p><strong>Resetting Buildroot for a new target: </strong>To delete all build products as well as the configuration:</p><pre class="screen"> $ make distclean</pre><p><strong>Notes. </strong>If <code class="literal">ccache</code> is enabled, running <code class="literal">make clean</code> or <code class="literal">distclean</code> does
  658. not empty the compiler cache used by Buildroot. To delete it, refer
  659. to <a class="xref" href="#ccache" title="8.13.3. Using ccache in Buildroot">Section 8.13.3, “Using <code class="literal">ccache</code> in Buildroot”</a>.</p><p><strong>Dumping the internal make variables: </strong>One can dump the variables known to make, along with their values:</p><pre class="screen"> $ make -s printvars VARS='VARIABLE1 VARIABLE2'
  660. VARIABLE1=value_of_variable
  661. VARIABLE2=value_of_variable</pre><p>It is possible to tweak the output using some variables:</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
  662. <code class="literal">VARS</code> will limit the listing to variables which names match the
  663. specified make-patterns - this must be set else nothing is printed
  664. </li><li class="listitem">
  665. <code class="literal">QUOTED_VARS</code>, if set to <code class="literal">YES</code>, will single-quote the value
  666. </li><li class="listitem">
  667. <code class="literal">RAW_VARS</code>, if set to <code class="literal">YES</code>, will print the unexpanded value
  668. </li></ul></div><p>For example:</p><pre class="screen"> $ make -s printvars VARS=BUSYBOX_%DEPENDENCIES
  669. BUSYBOX_DEPENDENCIES=skeleton toolchain
  670. BUSYBOX_FINAL_ALL_DEPENDENCIES=skeleton toolchain
  671. BUSYBOX_FINAL_DEPENDENCIES=skeleton toolchain
  672. BUSYBOX_FINAL_PATCH_DEPENDENCIES=
  673. BUSYBOX_RDEPENDENCIES=ncurses util-linux</pre><pre class="screen"> $ make -s printvars VARS=BUSYBOX_%DEPENDENCIES QUOTED_VARS=YES
  674. BUSYBOX_DEPENDENCIES='skeleton toolchain'
  675. BUSYBOX_FINAL_ALL_DEPENDENCIES='skeleton toolchain'
  676. BUSYBOX_FINAL_DEPENDENCIES='skeleton toolchain'
  677. BUSYBOX_FINAL_PATCH_DEPENDENCIES=''
  678. BUSYBOX_RDEPENDENCIES='ncurses util-linux'</pre><pre class="screen"> $ make -s printvars VARS=BUSYBOX_%DEPENDENCIES RAW_VARS=YES
  679. BUSYBOX_DEPENDENCIES=skeleton toolchain
  680. BUSYBOX_FINAL_ALL_DEPENDENCIES=$(sort $(BUSYBOX_FINAL_DEPENDENCIES) $(BUSYBOX_FINAL_PATCH_DEPENDENCIES))
  681. BUSYBOX_FINAL_DEPENDENCIES=$(sort $(BUSYBOX_DEPENDENCIES))
  682. BUSYBOX_FINAL_PATCH_DEPENDENCIES=$(sort $(BUSYBOX_PATCH_DEPENDENCIES))
  683. BUSYBOX_RDEPENDENCIES=ncurses util-linux</pre><p>The output of quoted variables can be reused in shell scripts, for example:</p><pre class="screen"> $ eval $(make -s printvars VARS=BUSYBOX_DEPENDENCIES QUOTED_VARS=YES)
  684. $ echo $BUSYBOX_DEPENDENCIES
  685. skeleton toolchain</pre></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="full-rebuild"></a>8.2. Understanding when a full rebuild is necessary</h2></div></div></div><p>Buildroot does not attempt to detect what parts of the system should
  686. be rebuilt when the system configuration is changed through <code class="literal">make
  687. menuconfig</code>, <code class="literal">make xconfig</code> or one of the other configuration
  688. tools. In some cases, Buildroot should rebuild the entire system, in
  689. some cases, only a specific subset of packages. But detecting this in
  690. a completely reliable manner is very difficult, and therefore the
  691. Buildroot developers have decided to simply not attempt to do this.</p><p>Instead, it is the responsibility of the user to know when a full
  692. rebuild is necessary. As a hint, here are a few rules of thumb that
  693. can help you understand how to work with Buildroot:</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
  694. When the target architecture configuration is changed, a complete
  695. rebuild is needed. Changing the architecture variant, the binary
  696. format or the floating point strategy for example has an impact on
  697. the entire system.
  698. </li><li class="listitem">
  699. When the toolchain configuration is changed, a complete rebuild
  700. generally is needed. Changing the toolchain configuration often
  701. involves changing the compiler version, the type of C library or
  702. its configuration, or some other fundamental configuration item,
  703. and these changes have an impact on the entire system.
  704. </li><li class="listitem">
  705. When an additional package is added to the configuration, a full
  706. rebuild is not necessarily needed. Buildroot will detect that this
  707. package has never been built, and will build it. However, if this
  708. package is a library that can optionally be used by packages that
  709. have already been built, Buildroot will not automatically rebuild
  710. those. Either you know which packages should be rebuilt, and you
  711. can rebuild them manually, or you should do a full rebuild. For
  712. example, let’s suppose you have built a system with the <code class="literal">ctorrent</code>
  713. package, but without <code class="literal">openssl</code>. Your system works, but you realize
  714. you would like to have SSL support in <code class="literal">ctorrent</code>, so you enable the
  715. <code class="literal">openssl</code> package in Buildroot configuration and restart the
  716. build. Buildroot will detect that <code class="literal">openssl</code> should be built and
  717. will be build it, but it will not detect that <code class="literal">ctorrent</code> should be
  718. rebuilt to benefit from <code class="literal">openssl</code> to add OpenSSL support. You will
  719. either have to do a full rebuild, or rebuild <code class="literal">ctorrent</code> itself.
  720. </li><li class="listitem">
  721. When a package is removed from the configuration, Buildroot does
  722. not do anything special. It does not remove the files installed by
  723. this package from the target root filesystem or from the toolchain
  724. <span class="emphasis"><em>sysroot</em></span>. A full rebuild is needed to get rid of this
  725. package. However, generally you don’t necessarily need this package
  726. to be removed right now: you can wait for the next lunch break to
  727. restart the build from scratch.
  728. </li><li class="listitem">
  729. When the sub-options of a package are changed, the package is not
  730. automatically rebuilt. After making such changes, rebuilding only
  731. this package is often sufficient, unless enabling the package
  732. sub-option adds some features to the package that are useful for
  733. another package which has already been built. Again, Buildroot does
  734. not track when a package should be rebuilt: once a package has been
  735. built, it is never rebuilt unless explicitly told to do so.
  736. </li><li class="listitem">
  737. When a change to the root filesystem skeleton is made, a full
  738. rebuild is needed. However, when changes to the root filesystem
  739. overlay, a post-build script or a post-image script are made,
  740. there is no need for a full rebuild: a simple <code class="literal">make</code> invocation
  741. will take the changes into account.
  742. </li><li class="listitem">
  743. When a package listed in <code class="literal">FOO_DEPENDENCIES</code> is rebuilt or removed,
  744. the package <code class="literal">foo</code> is not automatically rebuilt. For example, if a
  745. package <code class="literal">bar</code> is listed in <code class="literal">FOO_DEPENDENCIES</code> with <code class="literal">FOO_DEPENDENCIES
  746. = bar</code> and the configuration of the <code class="literal">bar</code> package is changed, the
  747. configuration change would not result in a rebuild of package <code class="literal">foo</code>
  748. automatically. In this scenario, you may need to either rebuild any
  749. packages in your build which reference <code class="literal">bar</code> in their <code class="literal">DEPENDENCIES</code>,
  750. or perform a full rebuild to ensure any <code class="literal">bar</code> dependent packages are
  751. up to date.
  752. </li></ul></div><p>Generally speaking, when you’re facing a build error and you’re unsure
  753. of the potential consequences of the configuration changes you’ve
  754. made, do a full rebuild. If you get the same build error, then you are
  755. sure that the error is not related to partial rebuilds of packages,
  756. and if this error occurs with packages from the official Buildroot, do
  757. not hesitate to report the problem! As your experience with Buildroot
  758. progresses, you will progressively learn when a full rebuild is really
  759. necessary, and you will save more and more time.</p><p>For reference, a full rebuild is achieved by running:</p><pre class="screen">$ make clean all</pre></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="rebuild-pkg"></a>8.3. Understanding how to rebuild packages</h2></div></div></div><p>One of the most common questions asked by Buildroot users is how to
  760. rebuild a given package or how to remove a package without rebuilding
  761. everything from scratch.</p><p>Removing a package is unsupported by Buildroot without
  762. rebuilding from scratch. This is because Buildroot doesn’t keep track
  763. of which package installs what files in the <code class="literal">output/staging</code> and
  764. <code class="literal">output/target</code> directories, or which package would be compiled differently
  765. depending on the availability of another package.</p><p>The easiest way to rebuild a single package from scratch is to remove
  766. its build directory in <code class="literal">output/build</code>. Buildroot will then re-extract,
  767. re-configure, re-compile and re-install this package from scratch. You
  768. can ask buildroot to do this with the <code class="literal">make &lt;package&gt;-dirclean</code> command.</p><p>On the other hand, if you only want to restart the build process of a
  769. package from its compilation step, you can run <code class="literal">make &lt;package&gt;-rebuild</code>. It
  770. will restart the compilation and installation of the package, but not from
  771. scratch: it basically re-executes <code class="literal">make</code> and <code class="literal">make install</code> inside the package,
  772. so it will only rebuild files that changed.</p><p>If you want to restart the build process of a package from its configuration
  773. step, you can run <code class="literal">make &lt;package&gt;-reconfigure</code>. It will restart the
  774. configuration, compilation and installation of the package.</p><p>While <code class="literal">&lt;package&gt;-rebuild</code> implies <code class="literal">&lt;package&gt;-reinstall</code> and
  775. <code class="literal">&lt;package&gt;-reconfigure</code> implies <code class="literal">&lt;package&gt;-rebuild</code>, these targets as well
  776. as <code class="literal">&lt;package&gt;</code> only act on the said package, and do not trigger re-creating
  777. the root filesystem image. If re-creating the root filesystem in necessary,
  778. one should in addition run <code class="literal">make</code> or <code class="literal">make all</code>.</p><p>Internally, Buildroot creates so-called <span class="emphasis"><em>stamp files</em></span> to keep track of
  779. which build steps have been completed for each package. They are
  780. stored in the package build directory,
  781. <code class="literal">output/build/&lt;package&gt;-&lt;version&gt;/</code> and are named
  782. <code class="literal">.stamp_&lt;step-name&gt;</code>. The commands detailed above simply manipulate
  783. these stamp files to force Buildroot to restart a specific set of
  784. steps of a package build process.</p><p>Further details about package special make targets are explained in
  785. <a class="xref" href="#pkg-build-steps" title="8.13.5. Package-specific make targets">Section 8.13.5, “Package-specific <span class="emphasis"><em>make</em></span> targets”</a>.</p></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="_offline_builds"></a>8.4. Offline builds</h2></div></div></div><p>If you intend to do an offline build and just want to download
  786. all sources that you previously selected in the configurator
  787. (<span class="emphasis"><em>menuconfig</em></span>, <span class="emphasis"><em>nconfig</em></span>, <span class="emphasis"><em>xconfig</em></span> or <span class="emphasis"><em>gconfig</em></span>), then issue:</p><pre class="screen"> $ make source</pre><p>You can now disconnect or copy the content of your <code class="literal">dl</code>
  788. directory to the build-host.</p></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="_building_out_of_tree"></a>8.5. Building out-of-tree</h2></div></div></div><p>As default, everything built by Buildroot is stored in the directory
  789. <code class="literal">output</code> in the Buildroot tree.</p><p>Buildroot also supports building out of tree with a syntax similar to
  790. the Linux kernel. To use it, add <code class="literal">O=&lt;directory&gt;</code> to the make command
  791. line:</p><pre class="screen"> $ make O=/tmp/build menuconfig</pre><p>Or:</p><pre class="screen"> $ cd /tmp/build; make O=$PWD -C path/to/buildroot menuconfig</pre><p>All the output files will be located under <code class="literal">/tmp/build</code>. If the <code class="literal">O</code>
  792. path does not exist, Buildroot will create it.</p><p><span class="strong"><strong>Note:</strong></span> the <code class="literal">O</code> path can be either an absolute or a relative path, but if it’s
  793. passed as a relative path, it is important to note that it is interpreted
  794. relative to the main Buildroot source directory, <span class="strong"><strong>not</strong></span> the current working
  795. directory.</p><p>When using out-of-tree builds, the Buildroot <code class="literal">.config</code> and temporary
  796. files are also stored in the output directory. This means that you can
  797. safely run multiple builds in parallel using the same source tree as
  798. long as they use unique output directories.</p><p>For ease of use, Buildroot generates a Makefile wrapper in the output
  799. directory - so after the first run, you no longer need to pass <code class="literal">O=&lt;…&gt;</code>
  800. and <code class="literal">-C &lt;…&gt;</code>, simply run (in the output directory):</p><pre class="screen"> $ make &lt;target&gt;</pre></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="env-vars"></a>8.6. Environment variables</h2></div></div></div><p>Buildroot also honors some environment variables, when they are passed
  801. to <code class="literal">make</code> or set in the environment:</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
  802. <code class="literal">HOSTCXX</code>, the host C++ compiler to use
  803. </li><li class="listitem">
  804. <code class="literal">HOSTCC</code>, the host C compiler to use
  805. </li><li class="listitem">
  806. <code class="literal">UCLIBC_CONFIG_FILE=&lt;path/to/.config&gt;</code>, path to
  807. the uClibc configuration file, used to compile uClibc, if an
  808. internal toolchain is being built.
  809. Note that the uClibc configuration file can also be set from the
  810. configuration interface, so through the Buildroot <code class="literal">.config</code> file; this
  811. is the recommended way of setting it.
  812. </li><li class="listitem">
  813. <code class="literal">BUSYBOX_CONFIG_FILE=&lt;path/to/.config&gt;</code>, path to
  814. the BusyBox configuration file.
  815. Note that the BusyBox configuration file can also be set from the
  816. configuration interface, so through the Buildroot <code class="literal">.config</code> file; this
  817. is the recommended way of setting it.
  818. </li><li class="listitem">
  819. <code class="literal">BR2_CCACHE_DIR</code> to override the directory where
  820. Buildroot stores the cached files when using ccache.
  821. </li><li class="listitem">
  822. <code class="literal">BR2_DL_DIR</code> to override the directory in which
  823. Buildroot stores/retrieves downloaded files.
  824. Note that the Buildroot download directory can also be set from the
  825. configuration interface, so through the Buildroot <code class="literal">.config</code> file. See
  826. <a class="xref" href="#download-location" title="8.13.4. Location of downloaded packages">Section 8.13.4, “Location of downloaded packages”</a> for more details on how you can set the download
  827. directory.
  828. </li><li class="listitem">
  829. <code class="literal">BR2_GRAPH_ALT</code>, if set and non-empty, to use an alternate color-scheme in
  830. build-time graphs
  831. </li><li class="listitem">
  832. <code class="literal">BR2_GRAPH_OUT</code> to set the filetype of generated graphs, either <code class="literal">pdf</code> (the
  833. default), or <code class="literal">png</code>.
  834. </li><li class="listitem">
  835. <code class="literal">BR2_GRAPH_DEPS_OPTS</code> to pass extra options to the dependency graph; see
  836. <a class="xref" href="#graph-depends">Section 8.9, “Graphing the dependencies between packages”</a> for the accepted options
  837. </li><li class="listitem">
  838. <code class="literal">BR2_GRAPH_DOT_OPTS</code> is passed verbatim as options to the <code class="literal">dot</code> utility to
  839. draw the dependency graph.
  840. </li><li class="listitem">
  841. <code class="literal">BR2_GRAPH_SIZE_OPTS</code> to pass extra options to the size graph; see
  842. <a class="xref" href="#graph-size" title="8.11. Graphing the filesystem size contribution of packages">Section 8.11, “Graphing the filesystem size contribution of packages”</a> for the acepted options
  843. </li></ul></div><p>An example that uses config files located in the toplevel directory and
  844. in your $HOME:</p><pre class="screen"> $ make UCLIBC_CONFIG_FILE=uClibc.config BUSYBOX_CONFIG_FILE=$HOME/bb.config</pre><p>If you want to use a compiler other than the default <code class="literal">gcc</code>
  845. or <code class="literal">g</code>++ for building helper-binaries on your host, then do</p><pre class="screen"> $ make HOSTCXX=g++-4.3-HEAD HOSTCC=gcc-4.3-HEAD</pre></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="_dealing_efficiently_with_filesystem_images"></a>8.7. Dealing efficiently with filesystem images</h2></div></div></div><p>Filesystem images can get pretty big, depending on the filesystem you choose,
  846. the number of packages, whether you provisioned free space… Yet, some
  847. locations in the filesystems images may just be <span class="emphasis"><em>empty</em></span> (e.g. a long run of
  848. <span class="emphasis"><em>zeroes</em></span>); such a file is called a <span class="emphasis"><em>sparse</em></span> file.</p><p>Most tools can handle sparse files efficiently, and will only store or write
  849. those parts of a sparse file that are not empty.</p><p>For example:</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p class="simpara">
  850. <code class="literal">tar</code> accepts the <code class="literal">-S</code> option to tell it to only store non-zero blocks
  851. of sparse files:
  852. </p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: circle; "><li class="listitem">
  853. <code class="literal">tar cf archive.tar -S [files…]</code> will efficiently store sparse files
  854. in a tarball
  855. </li><li class="listitem">
  856. <code class="literal">tar xf archive.tar -S</code> will efficiently store sparse files extracted
  857. from a tarball
  858. </li></ul></div></li><li class="listitem"><p class="simpara">
  859. <code class="literal">cp</code> accepts the <code class="literal">--sparse=WHEN</code> option (<code class="literal">WHEN</code> is one of <code class="literal">auto</code>,
  860. <code class="literal">never</code> or <code class="literal">always</code>):
  861. </p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: circle; "><li class="listitem">
  862. <code class="literal">cp --sparse=always source.file dest.file</code> will make <code class="literal">dest.file</code> a
  863. sparse file if <code class="literal">source.file</code> has long runs of zeroes
  864. </li></ul></div></li></ul></div><p>Other tools may have similar options. Please consult their respective man
  865. pages.</p><p>You can use sparse files if you need to store the filesystem images (e.g.
  866. to transfer from one machine to another), or if you need to send them (e.g.
  867. to the Q&amp;A team).</p><p>Note however that flashing a filesystem image to a device while using the
  868. sparse mode of <code class="literal">dd</code> may result in a broken filesystem (e.g. the block bitmap
  869. of an ext2 filesystem may be corrupted; or, if you have sparse files in
  870. your filesystem, those parts may not be all-zeroes when read back). You
  871. should only use sparse files when handling files on the build machine, not
  872. when transferring them to an actual device that will be used on the target.</p></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="_details_about_packages"></a>8.8. Details about packages</h2></div></div></div><p><a id="package-details"></a>Buildroot can produce a JSON blurb that describes the set of enabled
  873. packages in the current configuration, together with their
  874. dependencies, licenses and other metadata. This JSON blurb is produced
  875. by using the <code class="literal">show-info</code> make target:</p><pre class="screen">make show-info</pre><p>Buildroot can also produce details about packages as HTML and JSON
  876. output using the <code class="literal">pkg-stats</code> make target. Amongst other things, these
  877. details include whether known CVEs (security vulnerabilities) affect
  878. the packages in your current configuration. It also shows if there is
  879. a newer upstream version for those packages.</p><pre class="screen">make pkg-stats</pre></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="_graphing_the_dependencies_between_packages"></a>8.9. Graphing the dependencies between packages</h2></div></div></div><p><a id="graph-depends"></a>One of Buildroot’s jobs is to know the dependencies between packages,
  880. and make sure they are built in the right order. These dependencies
  881. can sometimes be quite complicated, and for a given system, it is
  882. often not easy to understand why such or such package was brought into
  883. the build by Buildroot.</p><p>In order to help understanding the dependencies, and therefore better
  884. understand what is the role of the different components in your
  885. embedded Linux system, Buildroot is capable of generating dependency
  886. graphs.</p><p>To generate a dependency graph of the full system you have compiled,
  887. simply run:</p><pre class="screen">make graph-depends</pre><p>You will find the generated graph in
  888. <code class="literal">output/graphs/graph-depends.pdf</code>.</p><p>If your system is quite large, the dependency graph may be too complex
  889. and difficult to read. It is therefore possible to generate the
  890. dependency graph just for a given package:</p><pre class="screen">make &lt;pkg&gt;-graph-depends</pre><p>You will find the generated graph in
  891. <code class="literal">output/graph/&lt;pkg&gt;-graph-depends.pdf</code>.</p><p>Note that the dependency graphs are generated using the <code class="literal">dot</code> tool
  892. from the <span class="emphasis"><em>Graphviz</em></span> project, which you must have installed on your
  893. system to use this feature. In most distributions, it is available as
  894. the <code class="literal">graphviz</code> package.</p><p>By default, the dependency graphs are generated in the PDF
  895. format. However, by passing the <code class="literal">BR2_GRAPH_OUT</code> environment variable, you
  896. can switch to other output formats, such as PNG, PostScript or
  897. SVG. All formats supported by the <code class="literal">-T</code> option of the <code class="literal">dot</code> tool are
  898. supported.</p><pre class="screen">BR2_GRAPH_OUT=svg make graph-depends</pre><p>The <code class="literal">graph-depends</code> behaviour can be controlled by setting options in the
  899. <code class="literal">BR2_GRAPH_DEPS_OPTS</code> environment variable. The accepted options are:</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
  900. <code class="literal">--depth N</code>, <code class="literal">-d N</code>, to limit the dependency depth to <code class="literal">N</code> levels. The
  901. default, <code class="literal">0</code>, means no limit.
  902. </li><li class="listitem">
  903. <code class="literal">--stop-on PKG</code>, <code class="literal">-s PKG</code>, to stop the graph on the package <code class="literal">PKG</code>.
  904. <code class="literal">PKG</code> can be an actual package name, a glob, the keyword <span class="emphasis"><em>virtual</em></span>
  905. (to stop on virtual packages), or the keyword <span class="emphasis"><em>host</em></span> (to stop on
  906. host packages). The package is still present on the graph, but its
  907. dependencies are not.
  908. </li><li class="listitem">
  909. <code class="literal">--exclude PKG</code>, <code class="literal">-x PKG</code>, like <code class="literal">--stop-on</code>, but also omits <code class="literal">PKG</code> from
  910. the graph.
  911. </li><li class="listitem">
  912. <code class="literal">--transitive</code>, <code class="literal">--no-transitive</code>, to draw (or not) the transitive
  913. dependencies. The default is to not draw transitive dependencies.
  914. </li><li class="listitem">
  915. <code class="literal">--colors R,T,H</code>, the comma-separated list of colors to draw the
  916. root package (<code class="literal">R</code>), the target packages (<code class="literal">T</code>) and the host packages
  917. (<code class="literal">H</code>). Defaults to: <code class="literal">lightblue,grey,gainsboro</code>
  918. </li></ul></div><pre class="screen">BR2_GRAPH_DEPS_OPTS='-d 3 --no-transitive --colors=red,green,blue' make graph-depends</pre></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="_graphing_the_build_duration"></a>8.10. Graphing the build duration</h2></div></div></div><p><a id="graph-duration"></a>When the build of a system takes a long time, it is sometimes useful
  919. to be able to understand which packages are the longest to build, to
  920. see if anything can be done to speed up the build. In order to help
  921. such build time analysis, Buildroot collects the build time of each
  922. step of each package, and allows to generate graphs from this data.</p><p>To generate the build time graph after a build, run:</p><pre class="screen">make graph-build</pre><p>This will generate a set of files in <code class="literal">output/graphs</code> :</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
  923. <code class="literal">build.hist-build.pdf</code>, a histogram of the build time for each
  924. package, ordered in the build order.
  925. </li><li class="listitem">
  926. <code class="literal">build.hist-duration.pdf</code>, a histogram of the build time for each
  927. package, ordered by duration (longest first)
  928. </li><li class="listitem">
  929. <code class="literal">build.hist-name.pdf</code>, a histogram of the build time for each
  930. package, order by package name.
  931. </li><li class="listitem">
  932. <code class="literal">build.pie-packages.pdf</code>, a pie chart of the build time per package
  933. </li><li class="listitem">
  934. <code class="literal">build.pie-steps.pdf</code>, a pie chart of the global time spent in each
  935. step of the packages build process.
  936. </li></ul></div><p>This <code class="literal">graph-build</code> target requires the Python Matplotlib and Numpy
  937. libraries to be installed (<code class="literal">python-matplotlib</code> and <code class="literal">python-numpy</code> on
  938. most distributions), and also the <code class="literal">argparse</code> module if you’re using a
  939. Python version older than 2.7 (<code class="literal">python-argparse</code> on most
  940. distributions).</p><p>By default, the output format for the graph is PDF, but a different
  941. format can be selected using the <code class="literal">BR2_GRAPH_OUT</code> environment variable. The
  942. only other format supported is PNG:</p><pre class="screen">BR2_GRAPH_OUT=png make graph-build</pre></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="graph-size"></a>8.11. Graphing the filesystem size contribution of packages</h2></div></div></div><p>When your target system grows, it is sometimes useful to understand
  943. how much each Buildroot package is contributing to the overall root
  944. filesystem size. To help with such an analysis, Buildroot collects
  945. data about files installed by each package and using this data,
  946. generates a graph and CSV files detailing the size contribution of
  947. the different packages.</p><p>To generate these data after a build, run:</p><pre class="screen">make graph-size</pre><p>This will generate:</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
  948. <code class="literal">output/graphs/graph-size.pdf</code>, a pie chart of the contribution of
  949. each package to the overall root filesystem size
  950. </li><li class="listitem">
  951. <code class="literal">output/graphs/package-size-stats.csv</code>, a CSV file giving the size
  952. contribution of each package to the overall root filesystem size
  953. </li><li class="listitem">
  954. <code class="literal">output/graphs/file-size-stats.csv</code>, a CSV file giving the size
  955. contribution of each installed file to the package it belongs, and
  956. to the overall filesystem size.
  957. </li></ul></div><p>This <code class="literal">graph-size</code> target requires the Python Matplotlib library to be
  958. installed (<code class="literal">python-matplotlib</code> on most distributions), and also the
  959. <code class="literal">argparse</code> module if you’re using a Python version older than 2.7
  960. (<code class="literal">python-argparse</code> on most distributions).</p><p>Just like for the duration graph, a <code class="literal">BR2_GRAPH_OUT</code> environment variable
  961. is supported to adjust the output file format. See <a class="xref" href="#graph-depends">Section 8.9, “Graphing the dependencies between packages”</a>
  962. for details about this environment variable.</p><p>Additionally, one may set the environment variable <code class="literal">BR2_GRAPH_SIZE_OPTS</code>
  963. to further control the generated graph. Accepted options are:</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
  964. <code class="literal">--size-limit X</code>, <code class="literal">-l X</code>, will group all packages which individual
  965. contribution is below <code class="literal">X</code> percent, to a single entry labelled <span class="emphasis"><em>Others</em></span>
  966. in the graph. By default, <code class="literal">X=0.01</code>, which means packages each
  967. contributing less than 1% are grouped under <span class="emphasis"><em>Others</em></span>. Accepted values
  968. are in the range <code class="literal">[0.0..1.0]</code>.
  969. </li><li class="listitem">
  970. <code class="literal">--iec</code>, <code class="literal">--binary</code>, <code class="literal">--si</code>, <code class="literal">--decimal</code>, to use IEC (binary, powers
  971. of 1024) or SI (decimal, powers of 1000; the default) prefixes.
  972. </li><li class="listitem">
  973. <code class="literal">--biggest-first</code>, to sort packages in decreasing size order, rather
  974. than in increasing size order.
  975. </li></ul></div><p><strong>Note. </strong>The collected filesystem size data is only meaningful after a complete
  976. clean rebuild. Be sure to run <code class="literal">make clean all</code> before using <code class="literal">make
  977. graph-size</code>.</p><p>To compare the root filesystem size of two different Buildroot compilations,
  978. for example after adjusting the configuration or when switching to another
  979. Buildroot release, use the <code class="literal">size-stats-compare</code> script. It takes two
  980. <code class="literal">file-size-stats.csv</code> files (produced by <code class="literal">make graph-size</code>) as input.
  981. Refer to the help text of this script for more details:</p><pre class="screen">utils/size-stats-compare -h</pre></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="top-level-parallel-build"></a>8.12. Top-level parallel build</h2></div></div></div><p><strong>Note. </strong>This section deals with a very experimental feature, which is known to
  982. break even in some non-unusual situations. Use at your own risk.</p><p>Buildroot has always been capable of using parallel build on a per
  983. package basis: each package is built by Buildroot using <code class="literal">make -jN</code> (or
  984. the equivalent invocation for non-make-based build systems). The level
  985. of parallelism is by default number of CPUs + 1, but it can be
  986. adjusted using the <code class="literal">BR2_JLEVEL</code> configuration option.</p><p>Until 2020.02, Buildroot was however building packages in a serial
  987. fashion: each package was built one after the other, without
  988. parallelization of the build between packages. As of 2020.02,
  989. Buildroot has experimental support for <span class="strong"><strong>top-level parallel build</strong></span>,
  990. which allows some signicant build time savings by building packages
  991. that have no dependency relationship in parallel. This feature is
  992. however marked as experimental and is known not to work in some cases.</p><p>In order to use top-level parallel build, one must:</p><div class="orderedlist"><ol class="orderedlist" type="1"><li class="listitem">
  993. Enable the option <code class="literal">BR2_PER_PACKAGE_DIRECTORIES</code> in the Buildroot
  994. configuration
  995. </li><li class="listitem">
  996. Use <code class="literal">make -jN</code> when starting the Buildroot build
  997. </li></ol></div><p>Internally, the <code class="literal">BR2_PER_PACKAGE_DIRECTORIES</code> will enable a mechanism
  998. called <span class="strong"><strong>per-package directories</strong></span>, which will have the following
  999. effects:</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
  1000. Instead of a global <span class="emphasis"><em>target</em></span> directory and a global <span class="emphasis"><em>host</em></span> directory
  1001. common to all packages, per-package <span class="emphasis"><em>target</em></span> and <span class="emphasis"><em>host</em></span> directories
  1002. will be used, in <code class="literal">$(O)/per-package/&lt;pkg&gt;/target/</code> and
  1003. <code class="literal">$(O)/per-package/&lt;pkg&gt;/host/</code> respectively. Those folders will be
  1004. populated from the corresponding folders of the package dependencies
  1005. at the beginning of <code class="literal">&lt;pkg&gt;</code> build. The compiler and all other tools
  1006. will therefore only be able to see and access files installed by
  1007. dependencies explicitly listed by <code class="literal">&lt;pkg&gt;</code>.
  1008. </li><li class="listitem">
  1009. At the end of the build, the global <span class="emphasis"><em>target</em></span> and <span class="emphasis"><em>host</em></span> directories
  1010. will be populated, located in <code class="literal">$(O)/target</code> and <code class="literal">$(O)/host</code>
  1011. respectively. This means that during the build, those folders will
  1012. be empty and it’s only at the very end of the build that they will
  1013. be populated.
  1014. </li></ul></div></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="_advanced_usage"></a>8.13. Advanced usage</h2></div></div></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a id="_using_the_generated_toolchain_outside_buildroot"></a>8.13.1. Using the generated toolchain outside Buildroot</h3></div></div></div><p>You may want to compile, for your target, your own programs or other
  1015. software that are not packaged in Buildroot. In order to do this you
  1016. can use the toolchain that was generated by Buildroot.</p><p>The toolchain generated by Buildroot is located by default in
  1017. <code class="literal">output/host/</code>. The simplest way to use it is to add
  1018. <code class="literal">output/host/bin/</code> to your PATH environment variable and then to
  1019. use <code class="literal">ARCH-linux-gcc</code>, <code class="literal">ARCH-linux-objdump</code>, <code class="literal">ARCH-linux-ld</code>, etc.</p><p>Alternatively, Buildroot can also export the toolchain and the development
  1020. files of all selected packages, as an SDK, by running the command
  1021. <code class="literal">make sdk</code>. This generates a tarball of the content of the host directory
  1022. <code class="literal">output/host/</code>, named <code class="literal">&lt;TARGET-TUPLE&gt;_sdk-buildroot.tar.gz</code> (which can be
  1023. overridden by setting the environment variable <code class="literal">BR2_SDK_PREFIX</code>) and
  1024. located in the output directory <code class="literal">output/images/</code>.</p><p>This tarball can then be distributed to application developers, when
  1025. they want to develop their applications that are not (yet) packaged as
  1026. a Buildroot package.</p><p>Upon extracting the SDK tarball, the user must run the script
  1027. <code class="literal">relocate-sdk.sh</code> (located at the top directory of the SDK), to make
  1028. sure all paths are updated with the new location.</p><p>Alternatively, if you just want to prepare the SDK without generating
  1029. the tarball (e.g. because you will just be moving the <code class="literal">host</code> directory,
  1030. or will be generating the tarball on your own), Buildroot also allows
  1031. you to just prepare the SDK with <code class="literal">make prepare-sdk</code> without actually
  1032. generating a tarball.</p><p>For your convenience, by selecting the option
  1033. <code class="literal">BR2_PACKAGE_HOST_ENVIRONMENT_SETUP</code>, you can get a
  1034. <code class="literal">environment-setup</code> script installed in <code class="literal">output/host/</code> and therefore
  1035. in your SDK. This script can be sourced with
  1036. <code class="literal">. your/sdk/path/environment-setup</code> to export a number of environment
  1037. variables that will help cross-compile your projects using the
  1038. Buildroot SDK: the <code class="literal">PATH</code> will contain the SDK binaries, standard
  1039. <span class="emphasis"><em>autotools</em></span> variables will be defined with the appropriate values, and
  1040. <code class="literal">CONFIGURE_FLAGS</code> will contain basic <code class="literal">./configure</code> options to
  1041. cross-compile <span class="emphasis"><em>autotools</em></span> projects. It also provides some useful
  1042. commands. Note however that once this script is sourced, the
  1043. environment is setup only for cross-compilation, and no longer for
  1044. native compilation.</p></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a id="_using_literal_gdb_literal_in_buildroot"></a>8.13.2. Using <code class="literal">gdb</code> in Buildroot</h3></div></div></div><p>Buildroot allows to do cross-debugging, where the debugger runs on the
  1045. build machine and communicates with <code class="literal">gdbserver</code> on the target to
  1046. control the execution of the program.</p><p>To achieve this:</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
  1047. If you are using an <span class="emphasis"><em>internal toolchain</em></span> (built by Buildroot), you
  1048. must enable <code class="literal">BR2_PACKAGE_HOST_GDB</code>, <code class="literal">BR2_PACKAGE_GDB</code> and
  1049. <code class="literal">BR2_PACKAGE_GDB_SERVER</code>. This ensures that both the cross gdb and
  1050. gdbserver get built, and that gdbserver gets installed to your target.
  1051. </li><li class="listitem">
  1052. If you are using an <span class="emphasis"><em>external toolchain</em></span>, you should enable
  1053. <code class="literal">BR2_TOOLCHAIN_EXTERNAL_GDB_SERVER_COPY</code>, which will copy the
  1054. gdbserver included with the external toolchain to the target. If your
  1055. external toolchain does not have a cross gdb or gdbserver, it is also
  1056. possible to let Buildroot build them, by enabling the same options as
  1057. for the <span class="emphasis"><em>internal toolchain backend</em></span>.
  1058. </li></ul></div><p>Now, to start debugging a program called <code class="literal">foo</code>, you should run on the
  1059. target:</p><pre class="screen">gdbserver :2345 foo</pre><p>This will cause <code class="literal">gdbserver</code> to listen on TCP port 2345 for a connection
  1060. from the cross gdb.</p><p>Then, on the host, you should start the cross gdb using the following
  1061. command line:</p><pre class="screen">&lt;buildroot&gt;/output/host/bin/&lt;tuple&gt;-gdb -ix &lt;buildroot&gt;/output/staging/usr/share/buildroot/gdbinit foo</pre><p>Of course, <code class="literal">foo</code> must be available in the current directory, built
  1062. with debugging symbols. Typically you start this command from the
  1063. directory where <code class="literal">foo</code> is built (and not from <code class="literal">output/target/</code> as the
  1064. binaries in that directory are stripped).</p><p>The <code class="literal">&lt;buildroot&gt;/output/staging/usr/share/buildroot/gdbinit</code> file will tell the
  1065. cross gdb where to find the libraries of the target.</p><p>Finally, to connect to the target from the cross gdb:</p><pre class="screen">(gdb) target remote &lt;target ip address&gt;:2345</pre></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a id="ccache"></a>8.13.3. Using <code class="literal">ccache</code> in Buildroot</h3></div></div></div><p><a class="ulink" href="http://ccache.samba.org" target="_top">ccache</a> is a compiler cache. It stores the
  1066. object files resulting from each compilation process, and is able to
  1067. skip future compilation of the same source file (with same compiler
  1068. and same arguments) by using the pre-existing object files. When doing
  1069. almost identical builds from scratch a number of times, it can nicely
  1070. speed up the build process.</p><p><code class="literal">ccache</code> support is integrated in Buildroot. You just have to enable
  1071. <code class="literal">Enable compiler cache</code> in <code class="literal">Build options</code>. This will automatically
  1072. build <code class="literal">ccache</code> and use it for every host and target compilation.</p><p>The cache is located in the directory defined by the <code class="literal">BR2_CCACHE_DIR</code>
  1073. configuration option, which defaults to
  1074. <code class="literal">$HOME/.buildroot-ccache</code>. This default location is outside of
  1075. Buildroot output directory so that it can be shared by separate
  1076. Buildroot builds. If you want to get rid of the cache, simply remove
  1077. this directory.</p><p>You can get statistics on the cache (its size, number of hits,
  1078. misses, etc.) by running <code class="literal">make ccache-stats</code>.</p><p>The make target <code class="literal">ccache-options</code> and the <code class="literal">CCACHE_OPTIONS</code> variable
  1079. provide more generic access to the ccache. For example</p><pre class="screen"># set cache limit size
  1080. make CCACHE_OPTIONS="--max-size=5G" ccache-options
  1081. # zero statistics counters
  1082. make CCACHE_OPTIONS="--zero-stats" ccache-options</pre><p><code class="literal">ccache</code> makes a hash of the source files and of the compiler options.
  1083. If a compiler option is different, the cached object file will not be
  1084. used. Many compiler options, however, contain an absolute path to the
  1085. staging directory. Because of this, building in a different output
  1086. directory would lead to many cache misses.</p><p>To avoid this issue, buildroot has the <code class="literal">Use relative paths</code> option
  1087. (<code class="literal">BR2_CCACHE_USE_BASEDIR</code>). This will rewrite all absolute paths that
  1088. point inside the output directory into relative paths. Thus, changing
  1089. the output directory no longer leads to cache misses.</p><p>A disadvantage of the relative paths is that they also end up to be
  1090. relative paths in the object file. Therefore, for example, the debugger
  1091. will no longer find the file, unless you cd to the output directory
  1092. first.</p><p>See <a class="ulink" href="https://ccache.samba.org/manual.html#_compiling_in_different_directories" target="_top">the
  1093. ccache manual’s section on "Compiling in different directories"</a> for
  1094. more details about this rewriting of absolute paths.</p><p>When <code class="literal">ccache</code> is enabled in Buildroot using the <code class="literal">BR2_CCACHE=y</code> option:</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
  1095. <code class="literal">ccache</code> is used during the Buildroot build itself
  1096. </li><li class="listitem">
  1097. <code class="literal">ccache</code> is not used when building outside of Buildroot, for example
  1098. when directly calling the cross-compiler or using the SDK
  1099. </li></ul></div><p>One can override this behavior using the <code class="literal">BR2_USE_CCACHE</code> environment
  1100. variable: when set to <code class="literal">1</code>, usage of ccache is enabled (default during
  1101. the Buildroot build), when unset or set to a value different from <code class="literal">1</code>,
  1102. usage of ccache is disabled.</p></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a id="download-location"></a>8.13.4. Location of downloaded packages</h3></div></div></div><p>The various tarballs that are downloaded by Buildroot are all stored
  1103. in <code class="literal">BR2_DL_DIR</code>, which by default is the <code class="literal">dl</code> directory. If you want
  1104. to keep a complete version of Buildroot which is known to be working
  1105. with the associated tarballs, you can make a copy of this directory.
  1106. This will allow you to regenerate the toolchain and the target
  1107. filesystem with exactly the same versions.</p><p>If you maintain several Buildroot trees, it might be better to have a
  1108. shared download location. This can be achieved by pointing the
  1109. <code class="literal">BR2_DL_DIR</code> environment variable to a directory. If this is
  1110. set, then the value of <code class="literal">BR2_DL_DIR</code> in the Buildroot configuration is
  1111. overridden. The following line should be added to <code class="literal">&lt;~/.bashrc&gt;</code>.</p><pre class="screen"> export BR2_DL_DIR=&lt;shared download location&gt;</pre><p>The download location can also be set in the <code class="literal">.config</code> file, with the
  1112. <code class="literal">BR2_DL_DIR</code> option. Unlike most options in the .config file, this value
  1113. is overridden by the <code class="literal">BR2_DL_DIR</code> environment variable.</p></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a id="pkg-build-steps"></a>8.13.5. Package-specific <span class="emphasis"><em>make</em></span> targets</h3></div></div></div><p>Running <code class="literal">make &lt;package&gt;</code> builds and installs that particular package
  1114. and its dependencies.</p><p>For packages relying on the Buildroot infrastructure, there are
  1115. numerous special make targets that can be called independently like
  1116. this:</p><pre class="screen">make &lt;package&gt;-&lt;target&gt;</pre><p>The package build targets are (in the order they are executed):</p><div class="informaltable"><table class="informaltable" cellpadding="4px" style="border-collapse: collapse;border-top: 3px solid #527bbd; border-bottom: 3px solid #527bbd; border-left: 3px solid #527bbd; border-right: 3px solid #527bbd; " width="90%"><colgroup><col class="col_1" /><col class="col_2" /></colgroup><thead><tr><th style="border-right: 1px solid #527bbd; border-bottom: 1px solid #527bbd; " align="center" valign="top"> command/target </th><th style="border-bottom: 1px solid #527bbd; " align="left" valign="top"> Description</th></tr></thead><tbody><tr><td style="border-right: 1px solid #527bbd; border-bottom: 1px solid #527bbd; " align="center" valign="top"><p><code class="literal">source</code></p></td><td style="border-bottom: 1px solid #527bbd; " align="left" valign="top"><p>Fetch the source (download the tarball, clone
  1117. the source repository, etc)</p></td></tr><tr><td style="border-right: 1px solid #527bbd; border-bottom: 1px solid #527bbd; " align="center" valign="top"><p><code class="literal">depends</code></p></td><td style="border-bottom: 1px solid #527bbd; " align="left" valign="top"><p>Build and install all dependencies required to
  1118. build the package</p></td></tr><tr><td style="border-right: 1px solid #527bbd; border-bottom: 1px solid #527bbd; " align="center" valign="top"><p><code class="literal">extract</code></p></td><td style="border-bottom: 1px solid #527bbd; " align="left" valign="top"><p>Put the source in the package build directory
  1119. (extract the tarball, copy the source, etc)</p></td></tr><tr><td style="border-right: 1px solid #527bbd; border-bottom: 1px solid #527bbd; " align="center" valign="top"><p><code class="literal">patch</code></p></td><td style="border-bottom: 1px solid #527bbd; " align="left" valign="top"><p>Apply the patches, if any</p></td></tr><tr><td style="border-right: 1px solid #527bbd; border-bottom: 1px solid #527bbd; " align="center" valign="top"><p><code class="literal">configure</code></p></td><td style="border-bottom: 1px solid #527bbd; " align="left" valign="top"><p>Run the configure commands, if any</p></td></tr><tr><td style="border-right: 1px solid #527bbd; border-bottom: 1px solid #527bbd; " align="center" valign="top"><p><code class="literal">build</code></p></td><td style="border-bottom: 1px solid #527bbd; " align="left" valign="top"><p>Run the compilation commands</p></td></tr><tr><td style="border-right: 1px solid #527bbd; border-bottom: 1px solid #527bbd; " align="center" valign="top"><p><code class="literal">install-staging</code></p></td><td style="border-bottom: 1px solid #527bbd; " align="left" valign="top"><p><span class="strong"><strong>target package:</strong></span> Run the installation of the package in the
  1120. staging directory, if necessary</p></td></tr><tr><td style="border-right: 1px solid #527bbd; border-bottom: 1px solid #527bbd; " align="center" valign="top"><p><code class="literal">install-target</code></p></td><td style="border-bottom: 1px solid #527bbd; " align="left" valign="top"><p><span class="strong"><strong>target package:</strong></span> Run the installation of the package in the
  1121. target directory, if necessary</p></td></tr><tr><td style="border-right: 1px solid #527bbd; " align="center" valign="top"><p><code class="literal">install</code></p></td><td style="" align="left" valign="top"><p><span class="strong"><strong>target package:</strong></span> Run the 2 previous installation commands</p>
  1122. <p><span class="strong"><strong>host package:</strong></span> Run the installation of the package in the host
  1123. directory</p></td></tr></tbody></table></div><p>Additionally, there are some other useful make targets:</p><div class="informaltable"><table class="informaltable" cellpadding="4px" style="border-collapse: collapse;border-top: 3px solid #527bbd; border-bottom: 3px solid #527bbd; border-left: 3px solid #527bbd; border-right: 3px solid #527bbd; " width="90%"><colgroup><col class="col_1" /><col class="col_2" /></colgroup><thead><tr><th style="border-right: 1px solid #527bbd; border-bottom: 1px solid #527bbd; " align="center" valign="top"> command/target </th><th style="border-bottom: 1px solid #527bbd; " align="left" valign="top"> Description</th></tr></thead><tbody><tr><td style="border-right: 1px solid #527bbd; border-bottom: 1px solid #527bbd; " align="center" valign="top"><p><code class="literal">show-depends</code></p></td><td style="border-bottom: 1px solid #527bbd; " align="left" valign="top"><p>Displays the first-order dependencies required to build the
  1124. package</p></td></tr><tr><td style="border-right: 1px solid #527bbd; border-bottom: 1px solid #527bbd; " align="center" valign="top"><p><code class="literal">show-recursive-depends</code></p></td><td style="border-bottom: 1px solid #527bbd; " align="left" valign="top"><p>Recursively displays the dependencies
  1125. required to build the package</p></td></tr><tr><td style="border-right: 1px solid #527bbd; border-bottom: 1px solid #527bbd; " align="center" valign="top"><p><code class="literal">show-rdepends</code></p></td><td style="border-bottom: 1px solid #527bbd; " align="left" valign="top"><p>Displays the first-order reverse dependencies of
  1126. the package (i.e packages that directly depend on it)</p></td></tr><tr><td style="border-right: 1px solid #527bbd; border-bottom: 1px solid #527bbd; " align="center" valign="top"><p><code class="literal">show-recursive-rdepends</code></p></td><td style="border-bottom: 1px solid #527bbd; " align="left" valign="top"><p>Recursively displays the reverse
  1127. dependencies of the package (i.e the packages that depend on it,
  1128. directly or indirectly)</p></td></tr><tr><td style="border-right: 1px solid #527bbd; border-bottom: 1px solid #527bbd; " align="center" valign="top"><p><code class="literal">graph-depends</code></p></td><td style="border-bottom: 1px solid #527bbd; " align="left" valign="top"><p>Generate a dependency graph of the package, in the
  1129. context of the current Buildroot configuration. See
  1130. <a class="link" href="#graph-depends">this section</a> for more details about dependency
  1131. graphs.</p></td></tr><tr><td style="border-right: 1px solid #527bbd; border-bottom: 1px solid #527bbd; " align="center" valign="top"><p><code class="literal">graph-rdepends</code></p></td><td style="border-bottom: 1px solid #527bbd; " align="left" valign="top"><p>Generate a graph of this package reverse
  1132. dependencies (i.e the packages that depend on it, directly or
  1133. indirectly)</p></td></tr><tr><td style="border-right: 1px solid #527bbd; border-bottom: 1px solid #527bbd; " align="center" valign="top"><p><code class="literal">dirclean</code></p></td><td style="border-bottom: 1px solid #527bbd; " align="left" valign="top"><p>Remove the whole package build directory</p></td></tr><tr><td style="border-right: 1px solid #527bbd; border-bottom: 1px solid #527bbd; " align="center" valign="top"><p><code class="literal">reinstall</code></p></td><td style="border-bottom: 1px solid #527bbd; " align="left" valign="top"><p>Re-run the install commands</p></td></tr><tr><td style="border-right: 1px solid #527bbd; border-bottom: 1px solid #527bbd; " align="center" valign="top"><p><code class="literal">rebuild</code></p></td><td style="border-bottom: 1px solid #527bbd; " align="left" valign="top"><p>Re-run the compilation commands - this only makes
  1134. sense when using the <code class="literal">OVERRIDE_SRCDIR</code> feature or when you modified a file
  1135. directly in the build directory</p></td></tr><tr><td style="border-right: 1px solid #527bbd; " align="center" valign="top"><p><code class="literal">reconfigure</code></p></td><td style="" align="left" valign="top"><p>Re-run the configure commands, then rebuild - this only
  1136. makes sense when using the <code class="literal">OVERRIDE_SRCDIR</code> feature or when you modified a
  1137. file directly in the build directory</p></td></tr></tbody></table></div></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a id="_using_buildroot_during_development"></a>8.13.6. Using Buildroot during development</h3></div></div></div><p>The normal operation of Buildroot is to download a tarball, extract
  1138. it, configure, compile and install the software component found inside
  1139. this tarball. The source code is extracted in
  1140. <code class="literal">output/build/&lt;package&gt;-&lt;version&gt;</code>, which is a temporary directory:
  1141. whenever <code class="literal">make clean</code> is used, this directory is entirely removed, and
  1142. re-created at the next <code class="literal">make</code> invocation. Even when a Git or
  1143. Subversion repository is used as the input for the package source
  1144. code, Buildroot creates a tarball out of it, and then behaves as it
  1145. normally does with tarballs.</p><p>This behavior is well-suited when Buildroot is used mainly as an
  1146. integration tool, to build and integrate all the components of an
  1147. embedded Linux system. However, if one uses Buildroot during the
  1148. development of certain components of the system, this behavior is not
  1149. very convenient: one would instead like to make a small change to the
  1150. source code of one package, and be able to quickly rebuild the system
  1151. with Buildroot.</p><p>Making changes directly in <code class="literal">output/build/&lt;package&gt;-&lt;version&gt;</code> is not
  1152. an appropriate solution, because this directory is removed on <code class="literal">make
  1153. clean</code>.</p><p>Therefore, Buildroot provides a specific mechanism for this use case:
  1154. the <code class="literal">&lt;pkg&gt;_OVERRIDE_SRCDIR</code> mechanism. Buildroot reads an <span class="emphasis"><em>override</em></span>
  1155. file, which allows the user to tell Buildroot the location of the
  1156. source for certain packages.</p><p>The default location of the override file is <code class="literal">$(CONFIG_DIR)/local.mk</code>,
  1157. as defined by the <code class="literal">BR2_PACKAGE_OVERRIDE_FILE</code> configuration option.
  1158. <code class="literal">$(CONFIG_DIR)</code> is the location of the Buildroot <code class="literal">.config</code> file, so
  1159. <code class="literal">local.mk</code> by default lives side-by-side with the <code class="literal">.config</code> file,
  1160. which means:</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
  1161. In the top-level Buildroot source directory for in-tree builds
  1162. (i.e., when <code class="literal">O=</code> is not used)
  1163. </li><li class="listitem">
  1164. In the out-of-tree directory for out-of-tree builds (i.e., when
  1165. <code class="literal">O=</code> is used)
  1166. </li></ul></div><p>If a different location than these defaults is required, it can be
  1167. specified through the <code class="literal">BR2_PACKAGE_OVERRIDE_FILE</code> configuration
  1168. option.</p><p>In this <span class="emphasis"><em>override</em></span> file, Buildroot expects to find lines of the form:</p><pre class="screen">&lt;pkg1&gt;_OVERRIDE_SRCDIR = /path/to/pkg1/sources
  1169. &lt;pkg2&gt;_OVERRIDE_SRCDIR = /path/to/pkg2/sources</pre><p>For example:</p><pre class="screen">LINUX_OVERRIDE_SRCDIR = /home/bob/linux/
  1170. BUSYBOX_OVERRIDE_SRCDIR = /home/bob/busybox/</pre><p>When Buildroot finds that for a given package, an
  1171. <code class="literal">&lt;pkg&gt;_OVERRIDE_SRCDIR</code> has been defined, it will no longer attempt to
  1172. download, extract and patch the package. Instead, it will directly use
  1173. the source code available in the specified directory and <code class="literal">make clean</code>
  1174. will not touch this directory. This allows to point Buildroot to your
  1175. own directories, that can be managed by Git, Subversion, or any other
  1176. version control system. To achieve this, Buildroot will use <span class="emphasis"><em>rsync</em></span> to
  1177. copy the source code of the component from the specified
  1178. <code class="literal">&lt;pkg&gt;_OVERRIDE_SRCDIR</code> to <code class="literal">output/build/&lt;package&gt;-custom/</code>.</p><p>This mechanism is best used in conjunction with the <code class="literal">make
  1179. &lt;pkg&gt;-rebuild</code> and <code class="literal">make &lt;pkg&gt;-reconfigure</code> targets. A <code class="literal">make
  1180. &lt;pkg&gt;-rebuild all</code> sequence will <span class="emphasis"><em>rsync</em></span> the source code from
  1181. <code class="literal">&lt;pkg&gt;_OVERRIDE_SRCDIR</code> to <code class="literal">output/build/&lt;package&gt;-custom</code> (thanks to
  1182. <span class="emphasis"><em>rsync</em></span>, only the modified files are copied), and restart the build
  1183. process of just this package.</p><p>In the example of the <code class="literal">linux</code> package above, the developer can then
  1184. make a source code change in <code class="literal">/home/bob/linux</code> and then run:</p><pre class="screen">make linux-rebuild all</pre><p>and in a matter of seconds gets the updated Linux kernel image in
  1185. <code class="literal">output/images</code>. Similarly, a change can be made to the BusyBox source
  1186. code in <code class="literal">/home/bob/busybox</code>, and after:</p><pre class="screen">make busybox-rebuild all</pre><p>the root filesystem image in <code class="literal">output/images</code> contains the updated
  1187. BusyBox.</p><p>Source trees for big projects often contain hundreds or thousands of
  1188. files which are not needed for building, but will slow down the process
  1189. of copying the sources with <span class="emphasis"><em>rsync</em></span>. Optionally, it is possible define
  1190. <code class="literal">&lt;pkg&gt;_OVERRIDE_SRCDIR_RSYNC_EXCLUSIONS</code> to skip syncing certain files
  1191. from the source tree. For example, when working on the <code class="literal">webkitgtk</code>
  1192. package, the following will exclude the tests and in-tree builds from
  1193. a local WebKit source tree:</p><pre class="screen">WEBKITGTK_OVERRIDE_SRCDIR = /home/bob/WebKit
  1194. WEBKITGTK_OVERRIDE_SRCDIR_RSYNC_EXCLUSIONS = \
  1195. --exclude JSTests --exclude ManualTests --exclude PerformanceTests \
  1196. --exclude WebDriverTests --exclude WebKitBuild --exclude WebKitLibraries \
  1197. --exclude WebKit.xcworkspace --exclude Websites --exclude Examples</pre><p>By default, Buildroot skips syncing of VCS artifacts (e.g., the <span class="strong"><strong>.git</strong></span> and
  1198. <span class="strong"><strong>.svn</strong></span> directories). Some packages prefer to have these VCS directories
  1199. available during build, for example for automatically determining a precise
  1200. commit reference for version information. To undo this built-in filtering at a
  1201. cost of a slower speed, add these directories back:</p><pre class="screen">LINUX_OVERRIDE_SRCDIR_RSYNC_EXCLUSIONS = --include .git</pre></div></div></div><div class="chapter"><div class="titlepage"><div><div><h2 class="title"><a id="customize"></a>Chapter 9. Project-specific customization</h2></div></div></div><p>Typical actions you may need to perform for a given project are:</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
  1202. configuring Buildroot (including build options and toolchain,
  1203. bootloader, kernel, package and filesystem image type selection)
  1204. </li><li class="listitem">
  1205. configuring other components, like the Linux kernel and BusyBox
  1206. </li><li class="listitem"><p class="simpara">
  1207. customizing the generated target filesystem
  1208. </p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: circle; "><li class="listitem">
  1209. adding or overwriting files on the target filesystem (using
  1210. <code class="literal">BR2_ROOTFS_OVERLAY</code>)
  1211. </li><li class="listitem">
  1212. modifying or deleting files on the target filesystem (using
  1213. <code class="literal">BR2_ROOTFS_POST_BUILD_SCRIPT</code>)
  1214. </li><li class="listitem">
  1215. running arbitrary commands prior to generating the filesystem image
  1216. (using <code class="literal">BR2_ROOTFS_POST_BUILD_SCRIPT</code>)
  1217. </li><li class="listitem">
  1218. setting file permissions and ownership (using
  1219. <code class="literal">BR2_ROOTFS_DEVICE_TABLE</code>)
  1220. </li><li class="listitem">
  1221. adding custom devices nodes (using
  1222. <code class="literal">BR2_ROOTFS_STATIC_DEVICE_TABLE</code>)
  1223. </li></ul></div></li><li class="listitem">
  1224. adding custom user accounts (using <code class="literal">BR2_ROOTFS_USERS_TABLES</code>)
  1225. </li><li class="listitem">
  1226. running arbitrary commands after generating the filesystem image
  1227. (using <code class="literal">BR2_ROOTFS_POST_IMAGE_SCRIPT</code>)
  1228. </li><li class="listitem">
  1229. adding project-specific patches to some packages (using
  1230. <code class="literal">BR2_GLOBAL_PATCH_DIR</code>)
  1231. </li><li class="listitem">
  1232. adding project-specific packages
  1233. </li></ul></div><p>An important note regarding such <span class="emphasis"><em>project-specific</em></span> customizations:
  1234. please carefully consider which changes are indeed project-specific and
  1235. which changes are also useful to developers outside your project. The
  1236. Buildroot community highly recommends and encourages the upstreaming of
  1237. improvements, packages and board support to the official Buildroot
  1238. project. Of course, it is sometimes not possible or desirable to
  1239. upstream because the changes are highly specific or proprietary.</p><p>This chapter describes how to make such project-specific customizations
  1240. in Buildroot and how to store them in a way that you can build the same
  1241. image in a reproducible way, even after running <span class="emphasis"><em>make clean</em></span>. By
  1242. following the recommended strategy, you can even use the same Buildroot
  1243. tree to build multiple distinct projects!</p><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="customize-dir-structure"></a>9.1. Recommended directory structure</h2></div></div></div><p>When customizing Buildroot for your project, you will be creating one or
  1244. more project-specific files that need to be stored somewhere. While most
  1245. of these files could be placed in <span class="emphasis"><em>any</em></span> location as their path is to be
  1246. specified in the Buildroot configuration, the Buildroot developers
  1247. recommend a specific directory structure which is described in this
  1248. section.</p><p>Orthogonal to this directory structure, you can choose <span class="emphasis"><em>where</em></span> you place
  1249. this structure itself: either inside the Buildroot tree, or outside of
  1250. it using a br2-external tree. Both options are valid, the choice is up
  1251. to you.</p><pre class="screen">+-- board/
  1252. | +-- &lt;company&gt;/
  1253. | +-- &lt;boardname&gt;/
  1254. | +-- linux.config
  1255. | +-- busybox.config
  1256. | +-- &lt;other configuration files&gt;
  1257. | +-- post_build.sh
  1258. | +-- post_image.sh
  1259. | +-- rootfs_overlay/
  1260. | | +-- etc/
  1261. | | +-- &lt;some files&gt;
  1262. | +-- patches/
  1263. | +-- foo/
  1264. | | +-- &lt;some patches&gt;
  1265. | +-- libbar/
  1266. | +-- &lt;some other patches&gt;
  1267. |
  1268. +-- configs/
  1269. | +-- &lt;boardname&gt;_defconfig
  1270. |
  1271. +-- package/
  1272. | +-- &lt;company&gt;/
  1273. | +-- Config.in (if not using a br2-external tree)
  1274. | +-- &lt;company&gt;.mk (if not using a br2-external tree)
  1275. | +-- package1/
  1276. | | +-- Config.in
  1277. | | +-- package1.mk
  1278. | +-- package2/
  1279. | +-- Config.in
  1280. | +-- package2.mk
  1281. |
  1282. +-- Config.in (if using a br2-external tree)
  1283. +-- external.mk (if using a br2-external tree)
  1284. +-- external.desc (if using a br2-external tree)</pre><p>Details on the files shown above are given further in this chapter.</p><p>Note: if you choose to place this structure outside of the Buildroot
  1285. tree but in a br2-external tree, the &lt;company&gt; and possibly &lt;boardname&gt;
  1286. components may be superfluous and can be left out.</p><div class="section"><div class="titlepage"><div><div><h3 class="title"><a id="_implementing_layered_customizations"></a>9.1.1. Implementing layered customizations</h3></div></div></div><p>It is quite common for a user to have several related projects that partly
  1287. need the same customizations. Instead of duplicating these
  1288. customizations for each project, it is recommended to use a layered
  1289. customization approach, as explained in this section.</p><p>Almost all of the customization methods available in Buildroot, like
  1290. post-build scripts and root filesystem overlays, accept a
  1291. space-separated list of items. The specified items are always treated in
  1292. order, from left to right. By creating more than one such item, one for
  1293. the common customizations and another one for the really
  1294. project-specific customizations, you can avoid unnecessary duplication.
  1295. Each layer is typically embodied by a separate directory inside
  1296. <code class="literal">board/&lt;company&gt;/</code>. Depending on your projects, you could even introduce
  1297. more than two layers.</p><p>An example directory structure for where a user has two customization
  1298. layers <span class="emphasis"><em>common</em></span> and <span class="emphasis"><em>fooboard</em></span> is:</p><pre class="screen">+-- board/
  1299. +-- &lt;company&gt;/
  1300. +-- common/
  1301. | +-- post_build.sh
  1302. | +-- rootfs_overlay/
  1303. | | +-- ...
  1304. | +-- patches/
  1305. | +-- ...
  1306. |
  1307. +-- fooboard/
  1308. +-- linux.config
  1309. +-- busybox.config
  1310. +-- &lt;other configuration files&gt;
  1311. +-- post_build.sh
  1312. +-- rootfs_overlay/
  1313. | +-- ...
  1314. +-- patches/
  1315. +-- ...</pre><p>For example, if the user has the <code class="literal">BR2_GLOBAL_PATCH_DIR</code> configuration
  1316. option set as:</p><pre class="screen">BR2_GLOBAL_PATCH_DIR="board/&lt;company&gt;/common/patches board/&lt;company&gt;/fooboard/patches"</pre><p>then first the patches from the <span class="emphasis"><em>common</em></span> layer would be applied,
  1317. followed by the patches from the <span class="emphasis"><em>fooboard</em></span> layer.</p></div></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="outside-br-custom"></a>9.2. Keeping customizations outside of Buildroot</h2></div></div></div><p>As already briefly mentioned in <a class="xref" href="#customize-dir-structure" title="9.1. Recommended directory structure">Section 9.1, “Recommended directory structure”</a>, you can
  1318. place project-specific customizations in two locations:</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
  1319. directly within the Buildroot tree, typically maintaining them using
  1320. branches in a version control system so that upgrading to a newer
  1321. Buildroot release is easy.
  1322. </li><li class="listitem">
  1323. outside of the Buildroot tree, using the <span class="emphasis"><em>br2-external</em></span> mechanism.
  1324. This mechanism allows to keep package recipes, board support and
  1325. configuration files outside of the Buildroot tree, while still
  1326. having them nicely integrated in the build logic. We call this
  1327. location a <span class="emphasis"><em>br2-external tree</em></span>. This section explains how to use
  1328. the br2-external mechanism and what to provide in a br2-external
  1329. tree.
  1330. </li></ul></div><p>One can tell Buildroot to use one or more br2-external trees by setting
  1331. the <code class="literal">BR2_EXTERNAL</code> make variable set to the path(s) of the br2-external
  1332. tree(s) to use. It can be passed to any Buildroot <code class="literal">make</code> invocation. It
  1333. is automatically saved in the hidden <code class="literal">.br2-external.mk</code> file in the output
  1334. directory. Thanks to this, there is no need to pass <code class="literal">BR2_EXTERNAL</code> at
  1335. every <code class="literal">make</code> invocation. It can however be changed at any time by
  1336. passing a new value, and can be removed by passing an empty value.</p><p><strong>Note. </strong>The path to a br2-external tree can be either absolute or relative.
  1337. If it is passed as a relative path, it is important to note that it is
  1338. interpreted relative to the main Buildroot source directory, <span class="strong"><strong>not</strong></span> to
  1339. the Buildroot output directory.</p><p><strong>Note: </strong>If using an br2-external tree from before Buildroot 2016.11, you need to
  1340. convert it before you can use it with Buildroot 2016.11 onward. See
  1341. <a class="xref" href="#br2-external-converting" title="27.2. Migrating to 2016.11">Section 27.2, “Migrating to 2016.11”</a> for help on doing so.</p><p>Some examples:</p><pre class="screen">buildroot/ $ make BR2_EXTERNAL=/path/to/foo menuconfig</pre><p>From now on, definitions from the <code class="literal">/path/to/foo</code> br2-external tree
  1342. will be used:</p><pre class="screen">buildroot/ $ make
  1343. buildroot/ $ make legal-info</pre><p>We can switch to another br2-external tree at any time:</p><pre class="screen">buildroot/ $ make BR2_EXTERNAL=/where/we/have/bar xconfig</pre><p>We can also use multiple br2-external trees:</p><pre class="screen">buildroot/ $ make BR2_EXTERNAL=/path/to/foo:/where/we/have/bar menuconfig</pre><p>Or disable the usage of any br2-external tree:</p><pre class="screen">buildroot/ $ make BR2_EXTERNAL= xconfig</pre><div class="section"><div class="titlepage"><div><div><h3 class="title"><a id="_layout_of_a_br2_external_tree"></a>9.2.1. Layout of a br2-external tree</h3></div></div></div><p>A br2-external tree must contain at least those three files, described
  1344. in the following chapters:</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
  1345. <code class="literal">external.desc</code>
  1346. </li><li class="listitem">
  1347. <code class="literal">external.mk</code>
  1348. </li><li class="listitem">
  1349. <code class="literal">Config.in</code>
  1350. </li></ul></div><p>Apart from those mandatory files, there may be additional and optional
  1351. content that may be present in a br2-external tree, like the <code class="literal">configs/</code>
  1352. or <code class="literal">provides/</code> directories. They are described in the following chapters
  1353. as well.</p><p>A complete example br2-external tree layout is also described later.</p><div class="section"><div class="titlepage"><div><div><h4 class="title"><a id="_the_literal_external_desc_literal_file"></a>The <code class="literal">external.desc</code> file</h4></div></div></div><p>That file describes the br2-external tree: the <span class="emphasis"><em>name</em></span> and <span class="emphasis"><em>description</em></span>
  1354. for that br2-external tree.</p><p>The format for this file is line based, with each line starting by a
  1355. keyword, followed by a colon and one or more spaces, followed by the
  1356. value assigned to that keyword. There are two keywords currently
  1357. recognised:</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p class="simpara">
  1358. <code class="literal">name</code>, mandatory, defines the name for that br2-external tree. That
  1359. name must only use ASCII characters in the set <code class="literal">[A-Za-z0-9_]</code>; any
  1360. other character is forbidden. Buildroot sets the variable
  1361. <code class="literal">BR2_EXTERNAL_$(NAME)_PATH</code> to the absolute path of the br2-external
  1362. tree, so that you can use it to refer to your br2-external tree. This
  1363. variable is available both in Kconfig, so you can use it to source your
  1364. Kconfig files (see below) and in the Makefile, so that you can use it
  1365. to include other Makefiles (see below) or refer to other files (like
  1366. data files) from your br2-external tree.
  1367. </p><p><strong>Note: </strong>Since it is possible to use multiple br2-external trees at once, this
  1368. name is used by Buildroot to generate variables for each of those trees.
  1369. That name is used to identify your br2-external tree, so try to come up
  1370. with a name that really describes your br2-external tree, in order for
  1371. it to be relatively unique, so that it does not clash with another name
  1372. from another br2-external tree, especially if you are planning on
  1373. somehow sharing your br2-external tree with third parties or using
  1374. br2-external trees from third parties.</p></li><li class="listitem">
  1375. <code class="literal">desc</code>, optional, provides a short description for that br2-external
  1376. tree. It shall fit on a single line, is mostly free-form (see below),
  1377. and is used when displaying information about a br2-external tree (e.g.
  1378. above the list of defconfig files, or as the prompt in the menuconfig);
  1379. as such, it should relatively brief (40 chars is probably a good upper
  1380. limit). The description is available in the <code class="literal">BR2_EXTERNAL_$(NAME)_DESC</code>
  1381. variable.
  1382. </li></ul></div><p>Examples of names and the corresponding <code class="literal">BR2_EXTERNAL_$(NAME)_PATH</code>
  1383. variables:</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
  1384. <code class="literal">FOO</code> → <code class="literal">BR2_EXTERNAL_FOO_PATH</code>
  1385. </li><li class="listitem">
  1386. <code class="literal">BAR_42</code> → <code class="literal">BR2_EXTERNAL_BAR_42_PATH</code>
  1387. </li></ul></div><p>In the following examples, it is assumed the name to be set to <code class="literal">BAR_42</code>.</p><p><strong>Note: </strong>Both <code class="literal">BR2_EXTERNAL_$(NAME)_PATH</code> and <code class="literal">BR2_EXTERNAL_$(NAME)_DESC</code> are
  1388. available in the Kconfig files and the Makefiles. They are also
  1389. exported in the environment so are available in post-build, post-image
  1390. and in-fakeroot scripts.</p></div><div class="section"><div class="titlepage"><div><div><h4 class="title"><a id="_the_literal_config_in_literal_and_literal_external_mk_literal_files"></a>The <code class="literal">Config.in</code> and <code class="literal">external.mk</code> files</h4></div></div></div><p>Those files (which may each be empty) can be used to define package
  1391. recipes (i.e. <code class="literal">foo/Config.in</code> and <code class="literal">foo/foo.mk</code> like for packages bundled
  1392. in Buildroot itself) or other custom configuration options or make logic.</p><p>Buildroot automatically includes the <code class="literal">Config.in</code> from each br2-external
  1393. tree to make it appear in the top-level configuration menu, and includes
  1394. the <code class="literal">external.mk</code> from each br2-external tree with the rest of the
  1395. makefile logic.</p><p>The main usage of this is to store package recipes. The recommended way
  1396. to do this is to write a <code class="literal">Config.in</code> file that looks like:</p><pre class="screen">source "$BR2_EXTERNAL_BAR_42_PATH/package/package1/Config.in"
  1397. source "$BR2_EXTERNAL_BAR_42_PATH/package/package2/Config.in"</pre><p>Then, have an <code class="literal">external.mk</code> file that looks like:</p><pre class="screen">include $(sort $(wildcard $(BR2_EXTERNAL_BAR_42_PATH)/package/*/*.mk))</pre><p>And then in <code class="literal">$(BR2_EXTERNAL_BAR_42_PATH)/package/package1</code> and
  1398. <code class="literal">$(BR2_EXTERNAL_BAR_42_PATH)/package/package2</code> create normal
  1399. Buildroot package recipes, as explained in <a class="xref" href="#adding-packages" title="Chapter 18. Adding new packages to Buildroot">Chapter 18, <em>Adding new packages to Buildroot</em></a>.
  1400. If you prefer, you can also group the packages in subdirectories
  1401. called &lt;boardname&gt; and adapt the above paths accordingly.</p><p>You can also define custom configuration options in <code class="literal">Config.in</code> and
  1402. custom make logic in <code class="literal">external.mk</code>.</p></div><div class="section"><div class="titlepage"><div><div><h4 class="title"><a id="_the_literal_configs_literal_directory"></a>The <code class="literal">configs/</code> directory</h4></div></div></div><p>One can store Buildroot defconfigs in the <code class="literal">configs</code> subdirectory of
  1403. the br2-external tree. Buildroot will automatically show them in the
  1404. output of <code class="literal">make list-defconfigs</code> and allow them to be loaded with the
  1405. normal <code class="literal">make &lt;name&gt;_defconfig</code> command. They will be visible in the
  1406. <span class="emphasis"><em>make list-defconfigs</em></span> output, below an <code class="literal">External configs</code> label that
  1407. contains the name of the br2-external tree they are defined in.</p><p><strong>Note: </strong>If a defconfig file is present in more than one br2-external tree, then
  1408. the one from the last br2-external tree is used. It is thus possible
  1409. to override a defconfig bundled in Buildroot or another br2-external
  1410. tree.</p></div><div class="section"><div class="titlepage"><div><div><h4 class="title"><a id="_the_literal_provides_literal_directory"></a>The <code class="literal">provides/</code> directory</h4></div></div></div><p>For some packages, Buildroot provides a choice between two (or more)
  1411. implementations of API-compatible such packages. For example, there is
  1412. a choice to choose either libjpeg or jpeg-turbo; there is one between
  1413. openssl or libressl; there is one to select one of the known,
  1414. pre-configured toolchains…</p><p>It is possible for a br2-external to extend those choices, by providing
  1415. a set of files that define those alternatives:</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
  1416. <code class="literal">provides/toolchains.in</code> defines the pre-configured toolchains, which
  1417. will then be listed in the toolchain selection;
  1418. </li><li class="listitem">
  1419. <code class="literal">provides/jpeg.in</code> defines the alternative libjpeg implementations;
  1420. </li><li class="listitem">
  1421. <code class="literal">provides/openssl.in</code> defines the alternative openssl implementations;
  1422. </li><li class="listitem">
  1423. <code class="literal">provides/skeleton.in</code> defines the alternative skeleton implementations;
  1424. </li><li class="listitem">
  1425. <code class="literal">provides/init.in</code> defines the alternative init system implementations, this
  1426. can be used to select a default skeleton for your init.
  1427. </li></ul></div></div><div class="section"><div class="titlepage"><div><div><h4 class="title"><a id="_free_form_content"></a>Free-form content</h4></div></div></div><p>One can store all the board-specific configuration files there, such
  1428. as the kernel configuration, the root filesystem overlay, or any other
  1429. configuration file for which Buildroot allows to set the location (by
  1430. using the <code class="literal">BR2_EXTERNAL_$(NAME)_PATH</code> variable). For example, you
  1431. could set the paths to a global patch directory, to a rootfs overlay
  1432. and to the kernel configuration file as follows (e.g. by running
  1433. <code class="literal">make menuconfig</code> and filling in these options):</p><pre class="screen">BR2_GLOBAL_PATCH_DIR=$(BR2_EXTERNAL_BAR_42_PATH)/patches/
  1434. BR2_ROOTFS_OVERLAY=$(BR2_EXTERNAL_BAR_42_PATH)/board/&lt;boardname&gt;/overlay/
  1435. BR2_LINUX_KERNEL_CUSTOM_CONFIG_FILE=$(BR2_EXTERNAL_BAR_42_PATH)/board/&lt;boardname&gt;/kernel.config</pre></div><div class="section"><div class="titlepage"><div><div><h4 class="title"><a id="_additional_linux_kernel_extensions"></a>Additional Linux kernel extensions</h4></div></div></div><p>Additional Linux kernel extensions (see <a class="xref" href="#linux-kernel-ext" title="18.22.2. linux-kernel-extensions">Section 18.22.2, “linux-kernel-extensions”</a>) can
  1436. be added by storing them in the <code class="literal">linux/</code> directory at the root of a
  1437. br2-external tree.</p></div><div class="section"><div class="titlepage"><div><div><h4 class="title"><a id="_example_layout"></a>Example layout</h4></div></div></div><p>Here is an example layout using all features of br2-external (the sample
  1438. content is shown for the file above it, when it is relevant to explain
  1439. the br2-external tree; this is all entirely made up just for the sake of
  1440. illustration, of course):</p><pre class="screen">/path/to/br2-ext-tree/
  1441. |- external.desc
  1442. | |name: BAR_42
  1443. | |desc: Example br2-external tree
  1444. | `----
  1445. |
  1446. |- Config.in
  1447. | |source "$BR2_EXTERNAL_BAR_42_PATH/toolchain/toolchain-external-mine/Config.in.options"
  1448. | |source "$BR2_EXTERNAL_BAR_42_PATH/package/pkg-1/Config.in"
  1449. | |source "$BR2_EXTERNAL_BAR_42_PATH/package/pkg-2/Config.in"
  1450. | |source "$BR2_EXTERNAL_BAR_42_PATH/package/my-jpeg/Config.in"
  1451. | |
  1452. | |config BAR_42_FLASH_ADDR
  1453. | | hex "my-board flash address"
  1454. | | default 0x10AD
  1455. | `----
  1456. |
  1457. |- external.mk
  1458. | |include $(sort $(wildcard $(BR2_EXTERNAL_BAR_42_PATH)/package/*/*.mk))
  1459. | |include $(sort $(wildcard $(BR2_EXTERNAL_BAR_42_PATH)/toolchain/*/*.mk))
  1460. | |
  1461. | |flash-my-board:
  1462. | | $(BR2_EXTERNAL_BAR_42_PATH)/board/my-board/flash-image \
  1463. | | --image $(BINARIES_DIR)/image.bin \
  1464. | | --address $(BAR_42_FLASH_ADDR)
  1465. | `----
  1466. |
  1467. |- package/pkg-1/Config.in
  1468. | |config BR2_PACKAGE_PKG_1
  1469. | | bool "pkg-1"
  1470. | | help
  1471. | | Some help about pkg-1
  1472. | `----
  1473. |- package/pkg-1/pkg-1.hash
  1474. |- package/pkg-1/pkg-1.mk
  1475. | |PKG_1_VERSION = 1.2.3
  1476. | |PKG_1_SITE = /some/where/to/get/pkg-1
  1477. | |PKG_1_LICENSE = blabla
  1478. | |
  1479. | |define PKG_1_INSTALL_INIT_SYSV
  1480. | | $(INSTALL) -D -m 0755 $(PKG_1_PKGDIR)/S99my-daemon \
  1481. | | $(TARGET_DIR)/etc/init.d/S99my-daemon
  1482. | |endef
  1483. | |
  1484. | |$(eval $(autotools-package))
  1485. | `----
  1486. |- package/pkg-1/S99my-daemon
  1487. |
  1488. |- package/pkg-2/Config.in
  1489. |- package/pkg-2/pkg-2.hash
  1490. |- package/pkg-2/pkg-2.mk
  1491. |
  1492. |- provides/jpeg.in
  1493. | |config BR2_PACKAGE_MY_JPEG
  1494. | | bool "my-jpeg"
  1495. | `----
  1496. |- package/my-jpeg/Config.in
  1497. | |config BR2_PACKAGE_PROVIDES_JPEG
  1498. | | default "my-jpeg" if BR2_PACKAGE_MY_JPEG
  1499. | `----
  1500. |- package/my-jpeg/my-jpeg.mk
  1501. | |# This is a normal package .mk file
  1502. | |MY_JPEG_VERSION = 1.2.3
  1503. | |MY_JPEG_SITE = https://example.net/some/place
  1504. | |MY_JPEG_PROVIDES = jpeg
  1505. | |$(eval $(autotools-package))
  1506. | `----
  1507. |
  1508. |- provides/init.in
  1509. | |config BR2_INIT_MINE
  1510. | | bool "my custom init"
  1511. | | select BR2_PACKAGE_MY_INIT
  1512. | | select BR2_PACKAGE_SKELETON_INIT_MINE if BR2_ROOTFS_SKELETON_DEFAULT
  1513. | `----
  1514. |
  1515. |- provides/skeleton.in
  1516. | |config BR2_ROOTFS_SKELETON_MINE
  1517. | | bool "my custom skeleton"
  1518. | | select BR2_PACKAGE_SKELETON_MINE
  1519. | `----
  1520. |- package/skeleton-mine/Config.in
  1521. | |config BR2_PACKAGE_SKELETON_MINE
  1522. | | bool
  1523. | | select BR2_PACKAGE_HAS_SKELETON
  1524. | |
  1525. | |config BR2_PACKAGE_PROVIDES_SKELETON
  1526. | | default "skeleton-mine" if BR2_PACKAGE_SKELETON_MINE
  1527. | `----
  1528. |- package/skeleton-mine/skeleton-mine.mk
  1529. | |SKELETON_MINE_ADD_TOOLCHAIN_DEPENDENCY = NO
  1530. | |SKELETON_MINE_ADD_SKELETON_DEPENDENCY = NO
  1531. | |SKELETON_MINE_PROVIDES = skeleton
  1532. | |SKELETON_MINE_INSTALL_STAGING = YES
  1533. | |$(eval $(generic-package))
  1534. | `----
  1535. |
  1536. |- provides/toolchains.in
  1537. | |config BR2_TOOLCHAIN_EXTERNAL_MINE
  1538. | | bool "my custom toolchain"
  1539. | | depends on BR2_some_arch
  1540. | | select BR2_INSTALL_LIBSTDCPP
  1541. | `----
  1542. |- toolchain/toolchain-external-mine/Config.in.options
  1543. | |if BR2_TOOLCHAIN_EXTERNAL_MINE
  1544. | |config BR2_TOOLCHAIN_EXTERNAL_PREFIX
  1545. | | default "arch-mine-linux-gnu"
  1546. | |config BR2_PACKAGE_PROVIDES_TOOLCHAIN_EXTERNAL
  1547. | | default "toolchain-external-mine"
  1548. | |endif
  1549. | `----
  1550. |- toolchain/toolchain-external-mine/toolchain-external-mine.mk
  1551. | |TOOLCHAIN_EXTERNAL_MINE_SITE = https://example.net/some/place
  1552. | |TOOLCHAIN_EXTERNAL_MINE_SOURCE = my-toolchain.tar.gz
  1553. | |$(eval $(toolchain-external-package))
  1554. | `----
  1555. |
  1556. |- linux/Config.ext.in
  1557. | |config BR2_LINUX_KERNEL_EXT_EXAMPLE_DRIVER
  1558. | | bool "example-external-driver"
  1559. | | help
  1560. | | Example external driver
  1561. | |---
  1562. |- linux/linux-ext-example-driver.mk
  1563. |
  1564. |- configs/my-board_defconfig
  1565. | |BR2_GLOBAL_PATCH_DIR="$(BR2_EXTERNAL_BAR_42_PATH)/patches/"
  1566. | |BR2_ROOTFS_OVERLAY="$(BR2_EXTERNAL_BAR_42_PATH)/board/my-board/overlay/"
  1567. | |BR2_ROOTFS_POST_IMAGE_SCRIPT="$(BR2_EXTERNAL_BAR_42_PATH)/board/my-board/post-image.sh"
  1568. | |BR2_LINUX_KERNEL_CUSTOM_CONFIG_FILE="$(BR2_EXTERNAL_BAR_42_PATH)/board/my-board/kernel.config"
  1569. | `----
  1570. |
  1571. |- patches/linux/0001-some-change.patch
  1572. |- patches/linux/0002-some-other-change.patch
  1573. |- patches/busybox/0001-fix-something.patch
  1574. |
  1575. |- board/my-board/kernel.config
  1576. |- board/my-board/overlay/var/www/index.html
  1577. |- board/my-board/overlay/var/www/my.css
  1578. |- board/my-board/flash-image
  1579. `- board/my-board/post-image.sh
  1580. |#!/bin/sh
  1581. |generate-my-binary-image \
  1582. | --root ${BINARIES_DIR}/rootfs.tar \
  1583. | --kernel ${BINARIES_DIR}/zImage \
  1584. | --dtb ${BINARIES_DIR}/my-board.dtb \
  1585. | --output ${BINARIES_DIR}/image.bin
  1586. `----</pre><p>The br2-external tree will then be visible in the menuconfig (with
  1587. the layout expanded):</p><pre class="screen">External options ---&gt;
  1588. *** Example br2-external tree (in /path/to/br2-ext-tree/)
  1589. [ ] pkg-1
  1590. [ ] pkg-2
  1591. (0x10AD) my-board flash address</pre><p>If you are using more than one br2-external tree, it would look like
  1592. (with the layout expanded and the second one with name <code class="literal">FOO_27</code> but no
  1593. <code class="literal">desc:</code> field in <code class="literal">external.desc</code>):</p><pre class="screen">External options ---&gt;
  1594. Example br2-external tree ---&gt;
  1595. *** Example br2-external tree (in /path/to/br2-ext-tree)
  1596. [ ] pkg-1
  1597. [ ] pkg-2
  1598. (0x10AD) my-board flash address
  1599. FOO_27 ---&gt;
  1600. *** FOO_27 (in /path/to/another-br2-ext)
  1601. [ ] foo
  1602. [ ] bar</pre><p>Additionally, the jpeg provider will be visible in the jpeg choice:</p><pre class="screen">Target packages ---&gt;
  1603. Libraries ---&gt;
  1604. Graphics ---&gt;
  1605. [*] jpeg support
  1606. jpeg variant () ---&gt;
  1607. ( ) jpeg
  1608. ( ) jpeg-turbo
  1609. *** jpeg from: Example br2-external tree ***
  1610. (X) my-jpeg
  1611. *** jpeg from: FOO_27 ***
  1612. ( ) another-jpeg</pre><p>And similarly for the toolchains:</p><pre class="screen">Toolchain ---&gt;
  1613. Toolchain () ---&gt;
  1614. ( ) Custom toolchain
  1615. *** Toolchains from: Example br2-external tree ***
  1616. (X) my custom toolchain</pre><p><strong>Note. </strong>The toolchain options in <code class="literal">toolchain/toolchain-external-mine/Config.in.options</code>
  1617. will not appear in the <code class="literal">Toolchain</code> menu. They must be explicitly included
  1618. from within the br2-external’s top-level <code class="literal">Config.in</code> and will thus appear
  1619. in the <code class="literal">External options</code> menu.</p></div></div></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="customize-store-buildroot-config"></a>9.3. Storing the Buildroot configuration</h2></div></div></div><p>The Buildroot configuration can be stored using the command
  1620. <code class="literal">make savedefconfig</code>.</p><p>This strips the Buildroot configuration down by removing configuration
  1621. options that are at their default value. The result is stored in a file
  1622. called <code class="literal">defconfig</code>. If you want to save it in another place, change the
  1623. <code class="literal">BR2_DEFCONFIG</code> option in the Buildroot configuration itself, or call
  1624. make with <code class="literal">make savedefconfig BR2_DEFCONFIG=&lt;path-to-defconfig&gt;</code>.</p><p>The recommended place to store this defconfig is
  1625. <code class="literal">configs/&lt;boardname&gt;_defconfig</code>. If you follow this recommendation, the
  1626. configuration will be listed in <code class="literal">make list-defconfigs</code> and can be set
  1627. again by running <code class="literal">make &lt;boardname&gt;_defconfig</code>.</p><p>Alternatively, you can copy the file to any other place and rebuild with
  1628. <code class="literal">make defconfig BR2_DEFCONFIG=&lt;path-to-defconfig-file&gt;</code>.</p></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="customize-store-package-config"></a>9.4. Storing the configuration of other components</h2></div></div></div><p>The configuration files for BusyBox, the Linux kernel, Barebox, U-Boot
  1629. and uClibc should be stored as well if changed. For each of these
  1630. components, a Buildroot configuration option exists to point to an input
  1631. configuration file, e.g. <code class="literal">BR2_LINUX_KERNEL_CUSTOM_CONFIG_FILE</code>. To store
  1632. their configuration, set these configuration options to a path where you
  1633. want to save the configuration files, and then use the helper targets
  1634. described below to actually store the configuration.</p><p>As explained in <a class="xref" href="#customize-dir-structure" title="9.1. Recommended directory structure">Section 9.1, “Recommended directory structure”</a>, the recommended path to
  1635. store these configuration files is
  1636. <code class="literal">board/&lt;company&gt;/&lt;boardname&gt;/foo.config</code>.</p><p>Make sure that you create a configuration file <span class="emphasis"><em>before</em></span> changing
  1637. the <code class="literal">BR2_LINUX_KERNEL_CUSTOM_CONFIG_FILE</code> etc. options. Otherwise,
  1638. Buildroot will try to access this config file, which doesn’t exist
  1639. yet, and will fail. You can create the configuration file by running
  1640. <code class="literal">make linux-menuconfig</code> etc.</p><p>Buildroot provides a few helper targets to make the saving of
  1641. configuration files easier.</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
  1642. <code class="literal">make linux-update-defconfig</code> saves the linux configuration to the
  1643. path specified by <code class="literal">BR2_LINUX_KERNEL_CUSTOM_CONFIG_FILE</code>. It
  1644. simplifies the config file by removing default values. However,
  1645. this only works with kernels starting from 2.6.33. For earlier
  1646. kernels, use <code class="literal">make linux-update-config</code>.
  1647. </li><li class="listitem">
  1648. <code class="literal">make busybox-update-config</code> saves the busybox configuration to the
  1649. path specified by <code class="literal">BR2_PACKAGE_BUSYBOX_CONFIG</code>.
  1650. </li><li class="listitem">
  1651. <code class="literal">make uclibc-update-config</code> saves the uClibc configuration to the
  1652. path specified by <code class="literal">BR2_UCLIBC_CONFIG</code>.
  1653. </li><li class="listitem">
  1654. <code class="literal">make barebox-update-defconfig</code> saves the barebox configuration to the
  1655. path specified by <code class="literal">BR2_TARGET_BAREBOX_CUSTOM_CONFIG_FILE</code>.
  1656. </li><li class="listitem">
  1657. <code class="literal">make uboot-update-defconfig</code> saves the U-Boot configuration to the
  1658. path specified by <code class="literal">BR2_TARGET_UBOOT_CUSTOM_CONFIG_FILE</code>.
  1659. </li><li class="listitem">
  1660. For at91bootstrap3, no helper exists so you have to copy the config
  1661. file manually to <code class="literal">BR2_TARGET_AT91BOOTSTRAP3_CUSTOM_CONFIG_FILE</code>.
  1662. </li></ul></div></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="rootfs-custom"></a>9.5. Customizing the generated target filesystem</h2></div></div></div><p>Besides changing the configuration through <code class="literal">make *config</code>,
  1663. there are a few other ways to customize the resulting target filesystem.</p><p>The two recommended methods, which can co-exist, are root filesystem
  1664. overlay(s) and post build script(s).</p><div class="variablelist"><dl class="variablelist"><dt><span class="term">
  1665. Root filesystem overlays (<code class="literal">BR2_ROOTFS_OVERLAY</code>)
  1666. </span></dt><dd><p class="simpara">A filesystem overlay is a tree of files that is copied directly
  1667. over the target filesystem after it has been built. To enable this
  1668. feature, set config option <code class="literal">BR2_ROOTFS_OVERLAY</code> (in the <code class="literal">System
  1669. configuration</code> menu) to the root of the overlay. You can even specify
  1670. multiple overlays, space-separated. If you specify a relative path,
  1671. it will be relative to the root of the Buildroot tree. Hidden
  1672. directories of version control systems, like <code class="literal">.git</code>, <code class="literal">.svn</code>, <code class="literal">.hg</code>,
  1673. etc., files called <code class="literal">.empty</code> and files ending in <code class="literal">~</code> are excluded from
  1674. the copy.</p><p class="simpara">When <code class="literal">BR2_ROOTFS_MERGED_USR</code> is enabled, then the overlay must not
  1675. contain the <span class="emphasis"><em>/bin</em></span>, <span class="emphasis"><em>/lib</em></span> or <span class="emphasis"><em>/sbin</em></span> directories, as Buildroot will
  1676. create them as symbolic links to the relevant folders in <span class="emphasis"><em>/usr</em></span>. In
  1677. such a situation, should the overlay have any programs or libraries,
  1678. they should be placed in <span class="emphasis"><em>/usr/bin</em></span>, <span class="emphasis"><em>/usr/sbin</em></span> and <span class="emphasis"><em>/usr/lib</em></span>.</p><p class="simpara">As shown in <a class="xref" href="#customize-dir-structure" title="9.1. Recommended directory structure">Section 9.1, “Recommended directory structure”</a>, the recommended path for
  1679. this overlay is <code class="literal">board/&lt;company&gt;/&lt;boardname&gt;/rootfs-overlay</code>.</p></dd><dt><span class="term">
  1680. Post-build scripts (<code class="literal">BR2_ROOTFS_POST_BUILD_SCRIPT</code>)
  1681. </span></dt><dd><p class="simpara">Post-build scripts are shell scripts called <span class="emphasis"><em>after</em></span> Buildroot builds
  1682. all the selected software, but <span class="emphasis"><em>before</em></span> the rootfs images are
  1683. assembled. To enable this feature, specify a space-separated list of
  1684. post-build scripts in config option <code class="literal">BR2_ROOTFS_POST_BUILD_SCRIPT</code> (in
  1685. the <code class="literal">System configuration</code> menu). If you specify a relative path, it
  1686. will be relative to the root of the Buildroot tree.</p><p class="simpara">Using post-build scripts, you can remove or modify any file in your
  1687. target filesystem. You should, however, use this feature with care.
  1688. Whenever you find that a certain package generates wrong or unneeded
  1689. files, you should fix that package rather than work around it with some
  1690. post-build cleanup scripts.</p><p class="simpara">As shown in <a class="xref" href="#customize-dir-structure" title="9.1. Recommended directory structure">Section 9.1, “Recommended directory structure”</a>, the recommended path for
  1691. this script is <code class="literal">board/&lt;company&gt;/&lt;boardname&gt;/post_build.sh</code>.</p><p class="simpara">The post-build scripts are run with the main Buildroot tree as current
  1692. working directory. The path to the target filesystem is passed as the
  1693. first argument to each script. If the config option
  1694. <code class="literal">BR2_ROOTFS_POST_SCRIPT_ARGS</code> is not empty, these arguments will be
  1695. passed to the script too. All the scripts will be passed the exact
  1696. same set of arguments, it is not possible to pass different sets of
  1697. arguments to each script.</p><p class="simpara">In addition, you may also use these environment variables:</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
  1698. <code class="literal">BR2_CONFIG</code>: the path to the Buildroot .config file
  1699. </li><li class="listitem">
  1700. <code class="literal">CONFIG_DIR</code>: the directory containing the .config file, and
  1701. therefore the top-level Buildroot Makefile to use (which is
  1702. correct for both in-tree and out-of-tree builds)
  1703. </li><li class="listitem">
  1704. <code class="literal">HOST_DIR</code>, <code class="literal">STAGING_DIR</code>, <code class="literal">TARGET_DIR</code>: see
  1705. <a class="xref" href="#generic-package-reference" title="18.6.2. generic-package reference">Section 18.6.2, “<code class="literal">generic-package</code> reference”</a>
  1706. </li><li class="listitem">
  1707. <code class="literal">BUILD_DIR</code>: the directory where packages are extracted and built
  1708. </li><li class="listitem">
  1709. <code class="literal">BINARIES_DIR</code>: the place where all binary files (aka images) are
  1710. stored
  1711. </li><li class="listitem">
  1712. <code class="literal">BASE_DIR</code>: the base output directory
  1713. </li></ul></div></dd></dl></div><p>Below three more methods of customizing the target filesystem are
  1714. described, but they are not recommended.</p><div class="variablelist"><dl class="variablelist"><dt><span class="term">
  1715. Direct modification of the target filesystem
  1716. </span></dt><dd><p class="simpara">For temporary modifications, you can modify the target filesystem
  1717. directly and rebuild the image. The target filesystem is available
  1718. under <code class="literal">output/target/</code>. After making your changes, run <code class="literal">make</code> to
  1719. rebuild the target filesystem image.</p><p class="simpara">This method allows you to do anything to the target filesystem, but if
  1720. you need to clean your Buildroot tree using <code class="literal">make clean</code>, these
  1721. changes will be lost. Such cleaning is necessary in several cases,
  1722. refer to <a class="xref" href="#full-rebuild" title="8.2. Understanding when a full rebuild is necessary">Section 8.2, “Understanding when a full rebuild is necessary”</a> for details. This solution is therefore
  1723. only useful for quick tests: <span class="emphasis"><em>changes do not survive the <code class="literal">make clean</code>
  1724. command</em></span>. Once you have validated your changes, you should make sure
  1725. that they will persist after a <code class="literal">make clean</code>, using a root filesystem
  1726. overlay or a post-build script.</p></dd><dt><span class="term">
  1727. Custom target skeleton (<code class="literal">BR2_ROOTFS_SKELETON_CUSTOM</code>)
  1728. </span></dt><dd><p class="simpara">The root filesystem image is created from a target skeleton, on top of
  1729. which all packages install their files. The skeleton is copied to the
  1730. target directory <code class="literal">output/target</code> before any package is built and
  1731. installed. The default target skeleton provides the standard Unix
  1732. filesystem layout and some basic init scripts and configuration files.</p><p class="simpara">If the default skeleton (available under <code class="literal">system/skeleton</code>) does not
  1733. match your needs, you would typically use a root filesystem overlay or
  1734. post-build script to adapt it. However, if the default skeleton is
  1735. entirely different than what you need, using a custom skeleton may be
  1736. more suitable.</p><p class="simpara">To enable this feature, enable config option
  1737. <code class="literal">BR2_ROOTFS_SKELETON_CUSTOM</code> and set <code class="literal">BR2_ROOTFS_SKELETON_CUSTOM_PATH</code>
  1738. to the path of your custom skeleton. Both options are available in the
  1739. <code class="literal">System configuration</code> menu. If you specify a relative path, it will
  1740. be relative to the root of the Buildroot tree.</p><p class="simpara">Custom skeletons don’t need to contain the <span class="emphasis"><em>/bin</em></span>, <span class="emphasis"><em>/lib</em></span> or <span class="emphasis"><em>/sbin</em></span>
  1741. directories, since they are created automatically during the build.
  1742. When <code class="literal">BR2_ROOTFS_MERGED_USR</code> is enabled, then the custom skeleton must
  1743. not contain the <span class="emphasis"><em>/bin</em></span>, <span class="emphasis"><em>/lib</em></span> or <span class="emphasis"><em>/sbin</em></span> directories, as Buildroot
  1744. will create them as symbolic links to the relevant folders in <span class="emphasis"><em>/usr</em></span>.
  1745. In such a situation, should the skeleton have any programs or
  1746. libraries, they should be placed in <span class="emphasis"><em>/usr/bin</em></span>, <span class="emphasis"><em>/usr/sbin</em></span> and
  1747. <span class="emphasis"><em>/usr/lib</em></span>.</p><p class="simpara">This method is not recommended because it duplicates the entire
  1748. skeleton, which prevents taking advantage of the fixes or improvements
  1749. brought to the default skeleton in later Buildroot releases.</p></dd><dt><span class="term">
  1750. Post-fakeroot scripts (<code class="literal">BR2_ROOTFS_POST_FAKEROOT_SCRIPT</code>)
  1751. </span></dt><dd><p class="simpara">When aggregating the final images, some parts of the process requires
  1752. root rights: creating device nodes in <code class="literal">/dev</code>, setting permissions or
  1753. ownership to files and directories… To avoid requiring actual root
  1754. rights, Buildroot uses <code class="literal">fakeroot</code> to simulate root rights. This is not
  1755. a complete substitute for actually being root, but is enough for what
  1756. Buildroot needs.</p><p class="simpara">Post-fakeroot scripts are shell scripts that are called at the <span class="emphasis"><em>end</em></span> of
  1757. the fakeroot phase, <span class="emphasis"><em>right before</em></span> the filesystem image generator is
  1758. called. As such, they are called in the fakeroot context.</p><p class="simpara">Post-fakeroot scripts can be useful in case you need to tweak the
  1759. filesystem to do modifications that are usually only available to the
  1760. root user.</p><p><strong>Note: </strong>It is recommended to use the existing mechanisms to set file permissions
  1761. or create entries in <code class="literal">/dev</code> (see <a class="xref" href="#customize-device-permission" title="9.5.1. Setting file permissions and ownership and adding custom devices nodes">Section 9.5.1, “Setting file permissions and ownership and adding custom devices nodes”</a>) or
  1762. to create users (see <a class="xref" href="#customize-users" title="9.6. Adding custom user accounts">Section 9.6, “Adding custom user accounts”</a>)</p><p><strong>Note: </strong>The difference between post-build scripts (above) and fakeroot scripts,
  1763. is that post-build scripts are not called in the fakeroot context.</p><p><strong>Note: </strong>Using <code class="literal">fakeroot</code> is not an absolute substitute for actually being root.
  1764. <code class="literal">fakeroot</code> only ever fakes the file access rights and types (regular,
  1765. block-or-char device…) and uid/gid; these are emulated in-memory.</p></dd></dl></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a id="customize-device-permission"></a>9.5.1. Setting file permissions and ownership and adding custom devices nodes</h3></div></div></div><p>Sometimes it is needed to set specific permissions or ownership on files
  1766. or device nodes. For example, certain files may need to be owned by
  1767. root. Since the post-build scripts are not run as root, you cannot do
  1768. such changes from there unless you use an explicit fakeroot from the
  1769. post-build script.</p><p>Instead, Buildroot provides support for so-called <span class="emphasis"><em>permission tables</em></span>.
  1770. To use this feature, set config option <code class="literal">BR2_ROOTFS_DEVICE_TABLE</code> to a
  1771. space-separated list of permission tables, regular text files following
  1772. the <a class="link" href="#makedev-syntax" title="Chapter 25. Makedev syntax documentation">makedev syntax</a>.</p><p>If you are using a static device table (i.e. not using <code class="literal">devtmpfs</code>,
  1773. <code class="literal">mdev</code>, or <code class="literal">(e)udev</code>) then you can add device nodes using the same
  1774. syntax, in so-called <span class="emphasis"><em>device tables</em></span>. To use this feature, set config
  1775. option <code class="literal">BR2_ROOTFS_STATIC_DEVICE_TABLE</code> to a space-separated list of
  1776. device tables.</p><p>As shown in <a class="xref" href="#customize-dir-structure" title="9.1. Recommended directory structure">Section 9.1, “Recommended directory structure”</a>, the recommended location for
  1777. such files is <code class="literal">board/&lt;company&gt;/&lt;boardname&gt;/</code>.</p><p>It should be noted that if the specific permissions or device nodes are
  1778. related to a specific application, you should set variables
  1779. <code class="literal">FOO_PERMISSIONS</code> and <code class="literal">FOO_DEVICES</code> in the package’s <code class="literal">.mk</code> file instead
  1780. (see <a class="xref" href="#generic-package-reference" title="18.6.2. generic-package reference">Section 18.6.2, “<code class="literal">generic-package</code> reference”</a>).</p></div></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="customize-users"></a>9.6. Adding custom user accounts</h2></div></div></div><p>Sometimes it is needed to add specific users in the target system.
  1781. To cover this requirement, Buildroot provides support for so-called
  1782. <span class="emphasis"><em>users tables</em></span>. To use this feature, set config option
  1783. <code class="literal">BR2_ROOTFS_USERS_TABLES</code> to a space-separated list of users tables,
  1784. regular text files following the <a class="link" href="#makeuser-syntax" title="Chapter 26. Makeusers syntax documentation">makeusers syntax</a>.</p><p>As shown in <a class="xref" href="#customize-dir-structure" title="9.1. Recommended directory structure">Section 9.1, “Recommended directory structure”</a>, the recommended location for
  1785. such files is <code class="literal">board/&lt;company&gt;/&lt;boardname&gt;/</code>.</p><p>It should be noted that if the custom users are related to a specific
  1786. application, you should set variable <code class="literal">FOO_USERS</code> in the package’s <code class="literal">.mk</code>
  1787. file instead (see <a class="xref" href="#generic-package-reference" title="18.6.2. generic-package reference">Section 18.6.2, “<code class="literal">generic-package</code> reference”</a>).</p></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="_customization_emphasis_after_emphasis_the_images_have_been_created"></a>9.7. Customization <span class="emphasis"><em>after</em></span> the images have been created</h2></div></div></div><p>While post-build scripts (<a class="xref" href="#rootfs-custom" title="9.5. Customizing the generated target filesystem">Section 9.5, “Customizing the generated target filesystem”</a>) are run <span class="emphasis"><em>before</em></span>
  1788. building the filesystem image, kernel and bootloader, <span class="strong"><strong>post-image
  1789. scripts</strong></span> can be used to perform some specific actions <span class="emphasis"><em>after</em></span> all images
  1790. have been created.</p><p>Post-image scripts can for example be used to automatically extract your
  1791. root filesystem tarball in a location exported by your NFS server, or
  1792. to create a special firmware image that bundles your root filesystem and
  1793. kernel image, or any other custom action required for your project.</p><p>To enable this feature, specify a space-separated list of post-image
  1794. scripts in config option <code class="literal">BR2_ROOTFS_POST_IMAGE_SCRIPT</code> (in the <code class="literal">System
  1795. configuration</code> menu). If you specify a relative path, it will be
  1796. relative to the root of the Buildroot tree.</p><p>Just like post-build scripts, post-image scripts are run with the main
  1797. Buildroot tree as current working directory. The path to the <code class="literal">images</code>
  1798. output directory is passed as the first argument to each script. If the
  1799. config option <code class="literal">BR2_ROOTFS_POST_SCRIPT_ARGS</code> is not empty, these
  1800. arguments will be passed to the script too. All the scripts will be
  1801. passed the exact same set of arguments, it is not possible to pass
  1802. different sets of arguments to each script.</p><p>Again just like for the post-build scripts, the scripts have access to
  1803. the environment variables <code class="literal">BR2_CONFIG</code>, <code class="literal">HOST_DIR</code>, <code class="literal">STAGING_DIR</code>,
  1804. <code class="literal">TARGET_DIR</code>, <code class="literal">BUILD_DIR</code>, <code class="literal">BINARIES_DIR</code>, <code class="literal">CONFIG_DIR</code> and
  1805. <code class="literal">BASE_DIR</code>.</p><p>The post-image scripts will be executed as the user that executes
  1806. Buildroot, which should normally <span class="emphasis"><em>not</em></span> be the root user. Therefore, any
  1807. action requiring root permissions in one of these scripts will require
  1808. special handling (usage of fakeroot or sudo), which is left to the
  1809. script developer.</p></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="_adding_project_specific_patches_and_hashes"></a>9.8. Adding project-specific patches and hashes</h2></div></div></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a id="customize-patches"></a>9.8.1. Providing extra patches</h3></div></div></div><p>It is sometimes useful to apply <span class="emphasis"><em>extra</em></span> patches to packages - on top of
  1810. those provided in Buildroot. This might be used to support custom
  1811. features in a project, for example, or when working on a new
  1812. architecture.</p><p>The <code class="literal">BR2_GLOBAL_PATCH_DIR</code> configuration option can be used to specify
  1813. a space separated list of one or more directories containing package
  1814. patches.</p><p>For a specific version <code class="literal">&lt;packageversion&gt;</code> of a specific package
  1815. <code class="literal">&lt;packagename&gt;</code>, patches are applied from <code class="literal">BR2_GLOBAL_PATCH_DIR</code> as
  1816. follows:</p><div class="orderedlist"><ol class="orderedlist" type="1"><li class="listitem"><p class="simpara">
  1817. For every directory - <code class="literal">&lt;global-patch-dir&gt;</code> - that exists in
  1818. <code class="literal">BR2_GLOBAL_PATCH_DIR</code>, a <code class="literal">&lt;package-patch-dir&gt;</code> will be determined as
  1819. follows:
  1820. </p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
  1821. <code class="literal">&lt;global-patch-dir&gt;/&lt;packagename&gt;/&lt;packageversion&gt;/</code> if the
  1822. directory exists.
  1823. </li><li class="listitem">
  1824. Otherwise, <code class="literal">&lt;global-patch-dir&gt;/&lt;packagename&gt;</code> if the directory
  1825. exists.
  1826. </li></ul></div></li><li class="listitem"><p class="simpara">
  1827. Patches will then be applied from a <code class="literal">&lt;package-patch-dir&gt;</code> as
  1828. follows:
  1829. </p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
  1830. If a <code class="literal">series</code> file exists in the package directory, then patches are
  1831. applied according to the <code class="literal">series</code> file;
  1832. </li><li class="listitem">
  1833. Otherwise, patch files matching <code class="literal">*.patch</code> are applied in
  1834. alphabetical order. So, to ensure they are applied in the right
  1835. order, it is highly recommended to name the patch files like this:
  1836. <code class="literal">&lt;number&gt;-&lt;description&gt;.patch</code>, where <code class="literal">&lt;number&gt;</code> refers to the
  1837. <span class="emphasis"><em>apply order</em></span>.
  1838. </li></ul></div></li></ol></div><p>For information about how patches are applied for a package, see
  1839. <a class="xref" href="#patch-apply-order" title="19.2. How patches are applied">Section 19.2, “How patches are applied”</a></p><p>The <code class="literal">BR2_GLOBAL_PATCH_DIR</code> option is the preferred method for
  1840. specifying a custom patch directory for packages. It can be used to
  1841. specify a patch directory for any package in buildroot. It should also
  1842. be used in place of the custom patch directory options that are
  1843. available for packages such as U-Boot and Barebox. By doing this, it
  1844. will allow a user to manage their patches from one top-level
  1845. directory.</p><p>The exception to <code class="literal">BR2_GLOBAL_PATCH_DIR</code> being the preferred method for
  1846. specifying custom patches is <code class="literal">BR2_LINUX_KERNEL_PATCH</code>.
  1847. <code class="literal">BR2_LINUX_KERNEL_PATCH</code> should be used to specify kernel patches that
  1848. are available at a URL. <span class="strong"><strong>Note:</strong></span> <code class="literal">BR2_LINUX_KERNEL_PATCH</code> specifies kernel
  1849. patches that are applied after patches available in <code class="literal">BR2_GLOBAL_PATCH_DIR</code>,
  1850. as it is done from a post-patch hook of the Linux package.</p></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a id="customize-hashes"></a>9.8.2. Providing extra hashes</h3></div></div></div><p>Buildroot bundles a <a class="link" href="#adding-packages-hash" title="18.4. The .hash file">list of hashes</a> against
  1851. which it checks the integrity of the downloaded archives, or of those
  1852. it generates locally from VCS checkouts. However, it can only do so
  1853. for the known versions; for packages where it is possible to specify
  1854. a custom version (e.g. a custom version string, a remote tarball URL,
  1855. or a VCS repository location and changeset), Buildroot can’t carry
  1856. hashes for those.</p><p>For users concerned with the integrity of such downloads, it is possible
  1857. to provide a list of hashes that Buildroot can use to check arbitrary
  1858. downloaded files. Those extra hashes are looked up similarly to the
  1859. extra patches (above); for each directory in <code class="literal">BR2_GLOBAL_PATCH_DIR</code>,
  1860. the first file to exist is used to check a package download:</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
  1861. <code class="literal">&lt;global-patch-dir&gt;/&lt;packagename&gt;/&lt;packageversion&gt;/&lt;packagename&gt;.hash</code>
  1862. </li><li class="listitem">
  1863. <code class="literal">&lt;global-patch-dir&gt;/&lt;packagename&gt;/&lt;packagename&gt;.hash</code>
  1864. </li></ul></div><p>The <code class="literal">utils/add-custom-hashes</code> script can be used to generate these files.</p></div></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="customize-packages"></a>9.9. Adding project-specific packages</h2></div></div></div><p>In general, any new package should be added directly in the <code class="literal">package</code>
  1865. directory and submitted to the Buildroot upstream project. How to add
  1866. packages to Buildroot in general is explained in full detail in
  1867. <a class="xref" href="#adding-packages" title="Chapter 18. Adding new packages to Buildroot">Chapter 18, <em>Adding new packages to Buildroot</em></a> and will not be repeated here. However, your
  1868. project may need some proprietary packages that cannot be upstreamed.
  1869. This section will explain how you can keep such project-specific
  1870. packages in a project-specific directory.</p><p>As shown in <a class="xref" href="#customize-dir-structure" title="9.1. Recommended directory structure">Section 9.1, “Recommended directory structure”</a>, the recommended location for
  1871. project-specific packages is <code class="literal">package/&lt;company&gt;/</code>. If you are using the
  1872. br2-external tree feature (see <a class="xref" href="#outside-br-custom" title="9.2. Keeping customizations outside of Buildroot">Section 9.2, “Keeping customizations outside of Buildroot”</a>) the recommended
  1873. location is to put them in a sub-directory named <code class="literal">package/</code> in your
  1874. br2-external tree.</p><p>However, Buildroot will not be aware of the packages in this location,
  1875. unless we perform some additional steps. As explained in
  1876. <a class="xref" href="#adding-packages" title="Chapter 18. Adding new packages to Buildroot">Chapter 18, <em>Adding new packages to Buildroot</em></a>, a package in Buildroot basically consists of two
  1877. files: a <code class="literal">.mk</code> file (describing how to build the package) and a
  1878. <code class="literal">Config.in</code> file (describing the configuration options for this
  1879. package).</p><p>Buildroot will automatically include the <code class="literal">.mk</code> files in first-level
  1880. subdirectories of the <code class="literal">package</code> directory (using the pattern
  1881. <code class="literal">package/*/*.mk</code>). If we want Buildroot to include <code class="literal">.mk</code> files from
  1882. deeper subdirectories (like <code class="literal">package/&lt;company&gt;/package1/</code>) then we
  1883. simply have to add a <code class="literal">.mk</code> file in a first-level subdirectory that
  1884. includes these additional <code class="literal">.mk</code> files. Therefore, create a file
  1885. <code class="literal">package/&lt;company&gt;/&lt;company&gt;.mk</code> with following contents (assuming you
  1886. have only one extra directory level below <code class="literal">package/&lt;company&gt;/</code>):</p><pre class="screen">include $(sort $(wildcard package/&lt;company&gt;/*/*.mk))</pre><p>For the <code class="literal">Config.in</code> files, create a file <code class="literal">package/&lt;company&gt;/Config.in</code>
  1887. that includes the <code class="literal">Config.in</code> files of all your packages. An exhaustive
  1888. list has to be provided since wildcards are not supported in the source command of kconfig.
  1889. For example:</p><pre class="screen">source "package/&lt;company&gt;/package1/Config.in"
  1890. source "package/&lt;company&gt;/package2/Config.in"</pre><p>Include this new file <code class="literal">package/&lt;company&gt;/Config.in</code> from
  1891. <code class="literal">package/Config.in</code>, preferably in a company-specific menu to make
  1892. merges with future Buildroot versions easier.</p><p>If using a br2-external tree, refer to <a class="xref" href="#outside-br-custom" title="9.2. Keeping customizations outside of Buildroot">Section 9.2, “Keeping customizations outside of Buildroot”</a> for how
  1893. to fill in those files.</p></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="_quick_guide_to_storing_your_project_specific_customizations"></a>9.10. Quick guide to storing your project-specific customizations</h2></div></div></div><p>Earlier in this chapter, the different methods for making
  1894. project-specific customizations have been described. This section will
  1895. now summarize all this by providing step-by-step instructions to storing your
  1896. project-specific customizations. Clearly, the steps that are not relevant to
  1897. your project can be skipped.</p><div class="orderedlist"><ol class="orderedlist" type="1"><li class="listitem">
  1898. <code class="literal">make menuconfig</code> to configure toolchain, packages and kernel.
  1899. </li><li class="listitem">
  1900. <code class="literal">make linux-menuconfig</code> to update the kernel config, similar for
  1901. other configuration like busybox, uclibc, …
  1902. </li><li class="listitem">
  1903. <code class="literal">mkdir -p board/&lt;manufacturer&gt;/&lt;boardname&gt;</code>
  1904. </li><li class="listitem"><p class="simpara">
  1905. Set the following options to <code class="literal">board/&lt;manufacturer&gt;/&lt;boardname&gt;/&lt;package&gt;.config</code>
  1906. (as far as they are relevant):
  1907. </p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
  1908. <code class="literal">BR2_LINUX_KERNEL_CUSTOM_CONFIG_FILE</code>
  1909. </li><li class="listitem">
  1910. <code class="literal">BR2_PACKAGE_BUSYBOX_CONFIG</code>
  1911. </li><li class="listitem">
  1912. <code class="literal">BR2_UCLIBC_CONFIG</code>
  1913. </li><li class="listitem">
  1914. <code class="literal">BR2_TARGET_AT91BOOTSTRAP3_CUSTOM_CONFIG_FILE</code>
  1915. </li><li class="listitem">
  1916. <code class="literal">BR2_TARGET_BAREBOX_CUSTOM_CONFIG_FILE</code>
  1917. </li><li class="listitem">
  1918. <code class="literal">BR2_TARGET_UBOOT_CUSTOM_CONFIG_FILE</code>
  1919. </li></ul></div></li><li class="listitem"><p class="simpara">
  1920. Write the configuration files:
  1921. </p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
  1922. <code class="literal">make linux-update-defconfig</code>
  1923. </li><li class="listitem">
  1924. <code class="literal">make busybox-update-config</code>
  1925. </li><li class="listitem">
  1926. <code class="literal">make uclibc-update-config</code>
  1927. </li><li class="listitem">
  1928. <code class="literal">cp &lt;output&gt;/build/at91bootstrap3-*/.config
  1929. board/&lt;manufacturer&gt;/&lt;boardname&gt;/at91bootstrap3.config</code>
  1930. </li><li class="listitem">
  1931. <code class="literal">make barebox-update-defconfig</code>
  1932. </li><li class="listitem">
  1933. <code class="literal">make uboot-update-defconfig</code>
  1934. </li></ul></div></li><li class="listitem">
  1935. Create <code class="literal">board/&lt;manufacturer&gt;/&lt;boardname&gt;/rootfs-overlay/</code> and fill it
  1936. with additional files you need on your rootfs, e.g.
  1937. <code class="literal">board/&lt;manufacturer&gt;/&lt;boardname&gt;/rootfs-overlay/etc/inittab</code>.
  1938. Set <code class="literal">BR2_ROOTFS_OVERLAY</code>
  1939. to <code class="literal">board/&lt;manufacturer&gt;/&lt;boardname&gt;/rootfs-overlay</code>.
  1940. </li><li class="listitem">
  1941. Create a post-build script
  1942. <code class="literal">board/&lt;manufacturer&gt;/&lt;boardname&gt;/post_build.sh</code>. Set
  1943. <code class="literal">BR2_ROOTFS_POST_BUILD_SCRIPT</code> to
  1944. <code class="literal">board/&lt;manufacturer&gt;/&lt;boardname&gt;/post_build.sh</code>
  1945. </li><li class="listitem">
  1946. If additional setuid permissions have to be set or device nodes have
  1947. to be created, create <code class="literal">board/&lt;manufacturer&gt;/&lt;boardname&gt;/device_table.txt</code>
  1948. and add that path to <code class="literal">BR2_ROOTFS_DEVICE_TABLE</code>.
  1949. </li><li class="listitem">
  1950. If additional user accounts have to be created, create
  1951. <code class="literal">board/&lt;manufacturer&gt;/&lt;boardname&gt;/users_table.txt</code> and add that path
  1952. to <code class="literal">BR2_ROOTFS_USERS_TABLES</code>.
  1953. </li><li class="listitem">
  1954. To add custom patches to certain packages, set <code class="literal">BR2_GLOBAL_PATCH_DIR</code>
  1955. to <code class="literal">board/&lt;manufacturer&gt;/&lt;boardname&gt;/patches/</code> and add your patches
  1956. for each package in a subdirectory named after the package. Each
  1957. patch should be called <code class="literal">&lt;packagename&gt;-&lt;num&gt;-&lt;description&gt;.patch</code>.
  1958. </li><li class="listitem">
  1959. Specifically for the Linux kernel, there also exists the option
  1960. <code class="literal">BR2_LINUX_KERNEL_PATCH</code> with as main advantage that it can also
  1961. download patches from a URL. If you do not need this,
  1962. <code class="literal">BR2_GLOBAL_PATCH_DIR</code> is preferred. U-Boot, Barebox, at91bootstrap
  1963. and at91bootstrap3 also have separate options, but these do not
  1964. provide any advantage over <code class="literal">BR2_GLOBAL_PATCH_DIR</code> and will likely be
  1965. removed in the future.
  1966. </li><li class="listitem">
  1967. If you need to add project-specific packages, create
  1968. <code class="literal">package/&lt;manufacturer&gt;/</code> and place your packages in that
  1969. directory. Create an overall <code class="literal">&lt;manufacturer&gt;.mk</code> file that
  1970. includes the <code class="literal">.mk</code> files of all your packages. Create an overall
  1971. <code class="literal">Config.in</code> file that sources the <code class="literal">Config.in</code> files of all your
  1972. packages. Include this <code class="literal">Config.in</code> file from Buildroot’s
  1973. <code class="literal">package/Config.in</code> file.
  1974. </li><li class="listitem">
  1975. <code class="literal">make savedefconfig</code> to save the buildroot configuration.
  1976. </li><li class="listitem">
  1977. <code class="literal">cp defconfig configs/&lt;boardname&gt;_defconfig</code>
  1978. </li></ol></div></div></div><div class="chapter"><div class="titlepage"><div><div><h2 class="title"><a id="integration"></a>Chapter 10. Integration topics</h2></div></div></div><p>This chapter discusses how various things are integrated at system
  1979. level. Buildroot is highly configurable, almost everything discussed
  1980. here can be changed or overridden by <a class="link" href="#rootfs-custom" title="9.5. Customizing the generated target filesystem">rootfs overlay
  1981. or custom skeleton</a> configuration.</p><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="integration-systemd"></a>10.1. Systemd</h2></div></div></div><p>This chapter describes the decisions taken in Buildroot’s integration of
  1982. systemd, and how various use cases can be implemented.</p><div class="section"><div class="titlepage"><div><div><h3 class="title"><a id="_dbus_daemon"></a>10.1.1. DBus daemon</h3></div></div></div><p>Systemd requires a DBus daemon. There are two options for it: traditional dbus
  1983. (<code class="literal">BR2_PACKAGE_DBUS</code>) and bus1 dbus-broker (<code class="literal">BR2_PACKAGE_DBUS_BROKER</code>). At
  1984. least one of them must be chosen. If both are included in the configuration,
  1985. dbus-broker will be used as system bus, but the traditional dbus-daemon is
  1986. still installed as well and can be used as session bus. Also its tools (e.g.
  1987. <code class="literal">dbus-send</code>) can be used (systemd itself has <code class="literal">busctl</code> as an alternative). In
  1988. addition, the traditional dbus package is the only one that provides <code class="literal">libdbus</code>,
  1989. which is used by many packages as dbus integration library.</p><p>Both in the dbus and in the dbus-broker case, the daemon runs as user <code class="literal">dbus</code>.
  1990. The DBus configuration files are also identical for both.</p><p>To make sure that only one of the two daemons is started as system bus, the
  1991. systemd activation files of the dbus package (<code class="literal">dbus.socket</code> and the
  1992. <code class="literal">dbus.service</code> symlink in <code class="literal">multi-user.target.wants</code>) are removed when
  1993. dbus-broker is selected.</p></div></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="selinux"></a>10.2. Using SELinux in Buildroot</h2></div></div></div><p><a class="ulink" href="https://selinuxproject.org" target="_top">SELinux</a> is a Linux kernel security module
  1994. enforcing access control policies. In addition to the traditional file
  1995. permissions and access control lists, <code class="literal">SELinux</code> allows to write rules
  1996. for users or processes to access specific functions of resources
  1997. (files, sockets…).</p><p><span class="emphasis"><em>SELinux</em></span> has three modes of operation:</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
  1998. <span class="emphasis"><em>Disabled</em></span>: the policy is not applied
  1999. </li><li class="listitem">
  2000. <span class="emphasis"><em>Permissive</em></span>: the policy is applied, and non-authorized actions are
  2001. simply logged. This mode is often used for troubleshooting SELinux
  2002. issues.
  2003. </li><li class="listitem">
  2004. <span class="emphasis"><em>Enforcing</em></span>: the policy is applied, and non-authorized actions are
  2005. denied
  2006. </li></ul></div><p>In Buildroot the mode of operation is controlled by the
  2007. <code class="literal">BR2_PACKAGE_REFPOLICY_POLICY_STATE_*</code> configuration options. The
  2008. Linux kernel also has various configuration options that affect how
  2009. <code class="literal">SELinux</code> is enabled (see <code class="literal">security/selinux/Kconfig</code> in the Linux
  2010. kernel sources).</p><p>By default in Buildroot the <code class="literal">SELinux</code> policy is provided by the
  2011. upstream <a class="ulink" href="https://github.com/SELinuxProject/refpolicy" target="_top">refpolicy</a>
  2012. project, enabled with <code class="literal">BR2_PACKAGE_REFPOLICY</code>.</p><div class="section"><div class="titlepage"><div><div><h3 class="title"><a id="enabling-selinux"></a>10.2.1. Enabling SELinux support</h3></div></div></div><p>To have proper support for <code class="literal">SELinux</code> in a Buildroot generated system,
  2013. the following configuration options must be enabled:</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
  2014. <code class="literal">BR2_PACKAGE_LIBSELINUX</code>
  2015. </li><li class="listitem">
  2016. <code class="literal">BR2_PACKAGE_REFPOLICY</code>
  2017. </li></ul></div><p>In addition, your filesystem image format must support extended
  2018. attributes.</p></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a id="selinux-policy-tweaking"></a>10.2.2. SELinux policy tweaking</h3></div></div></div><p>The <code class="literal">SELinux refpolicy</code> contains modules that can be enabled or
  2019. disabled when being built. Each module provide a number of <code class="literal">SELinux</code>
  2020. rules. In Buildroot the non-base modules are disabled by default and
  2021. several ways to enable such modules are provided:</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
  2022. Packages can enable a list of <code class="literal">SELinux</code> modules within the <code class="literal">refpolicy</code> using
  2023. the <code class="literal">&lt;packagename&gt;_SELINUX_MODULES</code> variable.
  2024. </li><li class="listitem">
  2025. Packages can provide additional <code class="literal">SELinux</code> modules by putting them (.fc, .if
  2026. and .te files) in <code class="literal">package/&lt;packagename&gt;/selinux/</code>.
  2027. </li><li class="listitem">
  2028. Extra <code class="literal">SELinux</code> modules can be added in directories pointed by the
  2029. <code class="literal">BR2_REFPOLICY_EXTRA_MODULES_DIRS</code> configuration option.
  2030. </li><li class="listitem">
  2031. Additional modules in the <code class="literal">refpolicy</code> can be enabled if listed in the
  2032. <code class="literal">BR2_REFPOLICY_EXTRA_MODULES_DEPENDENCIES</code> configuration option.
  2033. </li></ul></div><p>Buildroot also allows to completely override the <code class="literal">refpolicy</code>. This
  2034. allows to provide a full custom policy designed specifically for a
  2035. given system. When going this way, all of the above mechanisms are
  2036. disabled: no extra <code class="literal">SElinux</code> module is added to the policy, and all
  2037. the available modules within the custom policy are enabled and built
  2038. into the final binary policy. The custom policy must be a fork of the
  2039. official <a class="ulink" href="https://github.com/SELinuxProject/refpolicy" target="_top">refpolicy</a>.</p><p>In order to fully override the <code class="literal">refpolicy</code> the following configuration
  2040. variables have to be set:</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
  2041. <code class="literal">BR2_PACKAGE_REFPOLICY_CUSTOM_GIT</code>
  2042. </li><li class="listitem">
  2043. <code class="literal">BR2_PACKAGE_REFPOLICY_CUSTOM_REPO_URL</code>
  2044. </li><li class="listitem">
  2045. <code class="literal">BR2_PACKAGE_REFPOLICY_CUSTOM_REPO_VERSION</code>
  2046. </li></ul></div></div></div></div><div class="chapter"><div class="titlepage"><div><div><h2 class="title"><a id="_frequently_asked_questions_amp_troubleshooting"></a>Chapter 11. Frequently Asked Questions &amp; Troubleshooting</h2></div></div></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="faq-boot-hang-after-starting"></a>11.1. The boot hangs after <span class="emphasis"><em>Starting network…</em></span></h2></div></div></div><p>If the boot process seems to hang after the following messages
  2047. (messages not necessarily exactly similar, depending on the list of
  2048. packages selected):</p><pre class="screen">Freeing init memory: 3972K
  2049. Initializing random number generator... done.
  2050. Starting network...
  2051. Starting dropbear sshd: generating rsa key... generating dsa key... OK</pre><p>then it means that your system is running, but didn’t start a shell on
  2052. the serial console. In order to have the system start a shell on your
  2053. serial console, you have to go into the Buildroot configuration, in
  2054. <code class="literal">System configuration</code>, modify <code class="literal">Run a getty (login prompt) after boot</code>
  2055. and set the appropriate port and baud rate in the <code class="literal">getty options</code>
  2056. submenu. This will automatically tune the <code class="literal">/etc/inittab</code> file of the
  2057. generated system so that a shell starts on the correct serial port.</p></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="faq-no-compiler-on-target"></a>11.2. Why is there no compiler on the target?</h2></div></div></div><p>It has been decided that support for the <span class="emphasis"><em>native compiler on the
  2058. target</em></span> would be stopped from the Buildroot-2012.11 release because:</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
  2059. this feature was neither maintained nor tested, and often broken;
  2060. </li><li class="listitem">
  2061. this feature was only available for Buildroot toolchains;
  2062. </li><li class="listitem">
  2063. Buildroot mostly targets <span class="emphasis"><em>small</em></span> or <span class="emphasis"><em>very small</em></span> target hardware
  2064. with limited resource onboard (CPU, ram, mass-storage), for which
  2065. compiling on the target does not make much sense;
  2066. </li><li class="listitem">
  2067. Buildroot aims at easing the cross-compilation, making native
  2068. compilation on the target unnecessary.
  2069. </li></ul></div><p>If you need a compiler on your target anyway, then Buildroot is not
  2070. suitable for your purpose. In such case, you need a <span class="emphasis"><em>real
  2071. distribution</em></span> and you should opt for something like:</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
  2072. <a class="ulink" href="http://www.openembedded.org" target="_top">openembedded</a>
  2073. </li><li class="listitem">
  2074. <a class="ulink" href="https://www.yoctoproject.org" target="_top">yocto</a>
  2075. </li><li class="listitem">
  2076. <a class="ulink" href="https://www.debian.org/ports/" target="_top">Debian</a>
  2077. </li><li class="listitem">
  2078. <a class="ulink" href="https://fedoraproject.org/wiki/Architectures" target="_top">Fedora</a>
  2079. </li><li class="listitem">
  2080. <a class="ulink" href="http://en.opensuse.org/Portal:ARM" target="_top">openSUSE ARM</a>
  2081. </li><li class="listitem">
  2082. <a class="ulink" href="http://archlinuxarm.org" target="_top">Arch Linux ARM</a>
  2083. </li><li class="listitem">
  2084. </li></ul></div></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="faq-no-dev-files-on-target"></a>11.3. Why are there no development files on the target?</h2></div></div></div><p>Since there is no compiler available on the target (see
  2085. <a class="xref" href="#faq-no-compiler-on-target" title="11.2. Why is there no compiler on the target?">Section 11.2, “Why is there no compiler on the target?”</a>), it does not make sense to waste
  2086. space with headers or static libraries.</p><p>Therefore, those files are always removed from the target since the
  2087. Buildroot-2012.11 release.</p></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="faq-no-doc-on-target"></a>11.4. Why is there no documentation on the target?</h2></div></div></div><p>Because Buildroot mostly targets <span class="emphasis"><em>small</em></span> or <span class="emphasis"><em>very small</em></span> target
  2088. hardware with limited resource onboard (CPU, ram, mass-storage), it
  2089. does not make sense to waste space with the documentation data.</p><p>If you need documentation data on your target anyway, then Buildroot
  2090. is not suitable for your purpose, and you should look for a <span class="emphasis"><em>real
  2091. distribution</em></span> (see: <a class="xref" href="#faq-no-compiler-on-target" title="11.2. Why is there no compiler on the target?">Section 11.2, “Why is there no compiler on the target?”</a>).</p></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="faq-why-not-visible-package"></a>11.5. Why are some packages not visible in the Buildroot config menu?</h2></div></div></div><p>If a package exists in the Buildroot tree and does not appear in the
  2092. config menu, this most likely means that some of the package’s
  2093. dependencies are not met.</p><p>To know more about the dependencies of a package, search for the
  2094. package symbol in the config menu (see <a class="xref" href="#make-tips" title="8.1. make tips">Section 8.1, “<span class="emphasis"><em>make</em></span> tips”</a>).</p><p>Then, you may have to recursively enable several options (which
  2095. correspond to the unmet dependencies) to finally be able to select
  2096. the package.</p><p>If the package is not visible due to some unmet toolchain options,
  2097. then you should certainly run a full rebuild (see <a class="xref" href="#make-tips" title="8.1. make tips">Section 8.1, “<span class="emphasis"><em>make</em></span> tips”</a> for
  2098. more explanations).</p></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="faq-why-not-use-target-as-chroot"></a>11.6. Why not use the target directory as a chroot directory?</h2></div></div></div><p>There are plenty of reasons to <span class="strong"><strong>not</strong></span> use the target directory a chroot
  2099. one, among these:</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
  2100. file ownerships, modes and permissions are not correctly set in the
  2101. target directory;
  2102. </li><li class="listitem">
  2103. device nodes are not created in the target directory.
  2104. </li></ul></div><p>For these reasons, commands run through chroot, using the target
  2105. directory as the new root, will most likely fail.</p><p>If you want to run the target filesystem inside a chroot, or as an NFS
  2106. root, then use the tarball image generated in <code class="literal">images/</code> and extract it
  2107. as root.</p></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="faq-no-binary-packages"></a>11.7. Why doesn’t Buildroot generate binary packages (.deb, .ipkg…)?</h2></div></div></div><p>One feature that is often discussed on the Buildroot list is the
  2108. general topic of "package management". To summarize, the idea
  2109. would be to add some tracking of which Buildroot package installs
  2110. what files, with the goals of:</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
  2111. being able to remove files installed by a package when this package
  2112. gets unselected from the menuconfig;
  2113. </li><li class="listitem">
  2114. being able to generate binary packages (ipk or other format) that
  2115. can be installed on the target without re-generating a new root
  2116. filesystem image.
  2117. </li></ul></div><p>In general, most people think it is easy to do: just track which package
  2118. installed what and remove it when the package is unselected. However, it
  2119. is much more complicated than that:</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
  2120. It is not only about the <code class="literal">target/</code> directory, but also the sysroot in
  2121. <code class="literal">host/&lt;tuple&gt;/sysroot</code> and the <code class="literal">host/</code> directory itself. All files
  2122. installed in those directories by various packages must be tracked.
  2123. </li><li class="listitem">
  2124. When a package is unselected from the configuration, it is not
  2125. sufficient to remove just the files it installed. One must also
  2126. remove all its reverse dependencies (i.e. packages relying on it)
  2127. and rebuild all those packages. For example, package A depends
  2128. optionally on the OpenSSL library. Both are selected, and Buildroot
  2129. is built. Package A is built with crypto support using OpenSSL.
  2130. Later on, OpenSSL gets unselected from the configuration, but
  2131. package A remains (since OpenSSL is an optional dependency, this
  2132. is possible.) If only OpenSSL files are removed, then the files
  2133. installed by package A are broken: they use a library that is no
  2134. longer present on the target. Although this is technically doable,
  2135. it adds a lot of complexity to Buildroot, which goes against the
  2136. simplicity we try to stick to.
  2137. </li><li class="listitem">
  2138. In addition to the previous problem, there is the case where the
  2139. optional dependency is not even known to Buildroot. For example,
  2140. package A in version 1.0 never used OpenSSL, but in version 2.0 it
  2141. automatically uses OpenSSL if available. If the Buildroot .mk file
  2142. hasn’t been updated to take this into account, then package A will
  2143. not be part of the reverse dependencies of OpenSSL and will not be
  2144. removed and rebuilt when OpenSSL is removed. For sure, the .mk file
  2145. of package A should be fixed to mention this optional dependency,
  2146. but in the mean time, you can have non-reproducible behaviors.
  2147. </li><li class="listitem">
  2148. The request is to also allow changes in the menuconfig to be
  2149. applied on the output directory without having to rebuild
  2150. everything from scratch. However, this is very difficult to achieve
  2151. in a reliable way: what happens when the suboptions of a package
  2152. are changed (we would have to detect this, and rebuild the package
  2153. from scratch and potentially all its reverse dependencies), what
  2154. happens if toolchain options are changed, etc. At the moment, what
  2155. Buildroot does is clear and simple so its behaviour is very
  2156. reliable and it is easy to support users. If configuration changes
  2157. done in menuconfig are applied after the next make, then it has to
  2158. work correctly and properly in all situations, and not have some
  2159. bizarre corner cases. The risk is to get bug reports like "I have
  2160. enabled package A, B and C, then ran make, then disabled package
  2161. C and enabled package D and ran make, then re-enabled package C
  2162. and enabled package E and then there is a build failure". Or worse
  2163. "I did some configuration, then built, then did some changes,
  2164. built, some more changes, built, some more changes, built, and now
  2165. it fails, but I don’t remember all the changes I did and in which
  2166. order". This will be impossible to support.
  2167. </li></ul></div><p>For all these reasons, the conclusion is that adding tracking of
  2168. installed files to remove them when the package is unselected, or to
  2169. generate a repository of binary packages, is something that is very
  2170. hard to achieve reliably and will add a lot of complexity.</p><p>On this matter, the Buildroot developers make this position statement:</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
  2171. Buildroot strives to make it easy to generate a root filesystem (hence
  2172. the name, by the way.) That is what we want to make Buildroot good at:
  2173. building root filesystems.
  2174. </li><li class="listitem">
  2175. Buildroot is not meant to be a distribution (or rather, a distribution
  2176. generator.) It is the opinion of most Buildroot developers that this
  2177. is not a goal we should pursue. We believe that there are other tools
  2178. better suited to generate a distro than Buildroot is. For example,
  2179. <a class="ulink" href="http://openembedded.org/" target="_top">Open Embedded</a>, or <a class="ulink" href="https://openwrt.org/" target="_top">openWRT</a>,
  2180. are such tools.
  2181. </li><li class="listitem">
  2182. We prefer to push Buildroot in a direction that makes it easy (or even
  2183. easier) to generate complete root filesystems. This is what makes
  2184. Buildroot stands out in the crowd (among other things, of course!)
  2185. </li><li class="listitem">
  2186. We believe that for most embedded Linux systems, binary packages are
  2187. not necessary, and potentially harmful. When binary packages are
  2188. used, it means that the system can be partially upgraded, which
  2189. creates an enormous number of possible combinations of package
  2190. versions that should be tested before doing the upgrade on the
  2191. embedded device. On the other hand, by doing complete system
  2192. upgrades by upgrading the entire root filesystem image at once,
  2193. the image deployed to the embedded system is guaranteed to really
  2194. be the one that has been tested and validated.
  2195. </li></ul></div></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="faq-speeding-up-build"></a>11.8. How to speed-up the build process?</h2></div></div></div><p>Since Buildroot often involves doing full rebuilds of the entire
  2196. system that can be quite long, we provide below a number of tips to
  2197. help reduce the build time:</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
  2198. Use a pre-built external toolchain instead of the default Buildroot
  2199. internal toolchain. By using a pre-built Linaro toolchain (on ARM)
  2200. or a Sourcery CodeBench toolchain (for ARM, x86, x86-64, MIPS,
  2201. etc.), you will save the build time of the toolchain at each
  2202. complete rebuild, approximately 15 to 20 minutes. Note that
  2203. temporarily using an external toolchain does not prevent you to
  2204. switch back to an internal toolchain (that may provide a higher
  2205. level of customization) once the rest of your system is working;
  2206. </li><li class="listitem">
  2207. Use the <code class="literal">ccache</code> compiler cache (see: <a class="xref" href="#ccache" title="8.13.3. Using ccache in Buildroot">Section 8.13.3, “Using <code class="literal">ccache</code> in Buildroot”</a>);
  2208. </li><li class="listitem">
  2209. Learn about rebuilding only the few packages you actually care
  2210. about (see <a class="xref" href="#rebuild-pkg" title="8.3. Understanding how to rebuild packages">Section 8.3, “Understanding how to rebuild packages”</a>), but beware that sometimes full
  2211. rebuilds are anyway necessary (see <a class="xref" href="#full-rebuild" title="8.2. Understanding when a full rebuild is necessary">Section 8.2, “Understanding when a full rebuild is necessary”</a>);
  2212. </li><li class="listitem">
  2213. Make sure you are not using a virtual machine for the Linux system
  2214. used to run Buildroot. Most of the virtual machine technologies are
  2215. known to cause a significant performance impact on I/O, which is
  2216. really important for building source code;
  2217. </li><li class="listitem">
  2218. Make sure that you’re using only local files: do not attempt to do
  2219. a build over NFS, which significantly slows down the build. Having
  2220. the Buildroot download folder available locally also helps a bit.
  2221. </li><li class="listitem">
  2222. Buy new hardware. SSDs and lots of RAM are key to speeding up the
  2223. builds.
  2224. </li><li class="listitem">
  2225. Experiment with top-level parallel build, see
  2226. <a class="xref" href="#top-level-parallel-build" title="8.12. Top-level parallel build">Section 8.12, “Top-level parallel build”</a>.
  2227. </li></ul></div></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="faq-2038"></a>11.9. How does Buildroot support Y2038?</h2></div></div></div><p>There are multiple situations to consider:</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
  2228. On 64-bit architectures, there is no problem, as <code class="literal">time_t</code> has
  2229. always been 64-bit.
  2230. </li><li class="listitem"><p class="simpara">
  2231. On 32-bit architectures, the situation depends on the C library:
  2232. </p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: circle; "><li class="listitem">
  2233. With <span class="emphasis"><em>uclibc-ng</em></span>, there is no support for 64-bit <code class="literal">time_t</code> on
  2234. 32-bit architectures, so systems using <span class="emphasis"><em>uclibc-ng</em></span> on 32-bit
  2235. platforms will not be Y2038 compatible.
  2236. </li><li class="listitem">
  2237. With <span class="emphasis"><em>musl</em></span>, 64-bit <code class="literal">time_t</code> has always been used on 32-bit
  2238. architectures, so systems using <span class="emphasis"><em>musl</em></span> on 32-bit platforms are
  2239. Y2038 compatible.
  2240. </li><li class="listitem">
  2241. With <span class="emphasis"><em>glibc</em></span>, 64-bit <code class="literal">time_t</code> on 32-bit architectures is enabled
  2242. by the Buildroot option <code class="literal">BR2_TIME_BITS_64</code>. With this option
  2243. enabled, systems using <span class="emphasis"><em>glibc</em></span> on 32-bit platforms are Y2038
  2244. compatible.
  2245. </li></ul></div></li></ul></div><p>Note that the above only comments about the capabilities of the C
  2246. library. Individual user-space libraries or applications, even when
  2247. built in a Y2038-compatible setup, can exhibit incorrect behavior if
  2248. they do not make correct use of the time APIs and types.</p></div></div><div class="chapter"><div class="titlepage"><div><div><h2 class="title"><a id="_known_issues"></a>Chapter 12. Known issues</h2></div></div></div><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
  2249. It is not possible to pass extra linker options via <code class="literal">BR2_TARGET_LDFLAGS</code>
  2250. if such options contain a <code class="literal">$</code> sign. For example, the following is known
  2251. to break: <code class="literal">BR2_TARGET_LDFLAGS="-Wl,-rpath='$ORIGIN/../lib'"</code>
  2252. </li><li class="listitem">
  2253. The <code class="literal">libffi</code> package is not supported on the SuperH 2 and ARMv7-M
  2254. architectures.
  2255. </li><li class="listitem">
  2256. The <code class="literal">prboom</code> package triggers a compiler failure with the SuperH 4
  2257. compiler from Sourcery CodeBench, version 2012.09.
  2258. </li></ul></div></div><div class="chapter"><div class="titlepage"><div><div><h2 class="title"><a id="legal-info"></a>Chapter 13. Legal notice and licensing</h2></div></div></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="_complying_with_open_source_licenses"></a>13.1. Complying with open source licenses</h2></div></div></div><p>All of the end products of Buildroot (toolchain, root filesystem, kernel,
  2259. bootloaders) contain open source software, released under various licenses.</p><p>Using open source software gives you the freedom to build rich embedded
  2260. systems, choosing from a wide range of packages, but also imposes some
  2261. obligations that you must know and honour.
  2262. Some licenses require you to publish the license text in the documentation of
  2263. your product. Others require you to redistribute the source code of the
  2264. software to those that receive your product.</p><p>The exact requirements of each license are documented in each package, and
  2265. it is your responsibility (or that of your legal office) to comply with those
  2266. requirements.
  2267. To make this easier for you, Buildroot can collect for you some material you
  2268. will probably need. To produce this material, after you have configured
  2269. Buildroot with <code class="literal">make menuconfig</code>, <code class="literal">make xconfig</code> or <code class="literal">make gconfig</code>, run:</p><pre class="screen">make legal-info</pre><p>Buildroot will collect legally-relevant material in your output directory,
  2270. under the <code class="literal">legal-info/</code> subdirectory.
  2271. There you will find:</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
  2272. A <code class="literal">README</code> file, that summarizes the produced material and contains warnings
  2273. about material that Buildroot could not produce.
  2274. </li><li class="listitem">
  2275. <code class="literal">buildroot.config</code>: this is the Buildroot configuration file that is usually
  2276. produced with <code class="literal">make menuconfig</code>, and which is necessary to reproduce the
  2277. build.
  2278. </li><li class="listitem">
  2279. The source code for all packages; this is saved in the <code class="literal">sources/</code> and
  2280. <code class="literal">host-sources/</code> subdirectories for target and host packages respectively.
  2281. The source code for packages that set <code class="literal">&lt;PKG&gt;_REDISTRIBUTE = NO</code> will not be
  2282. saved.
  2283. Patches that were applied are also saved, along with a file named <code class="literal">series</code>
  2284. that lists the patches in the order they were applied. Patches are under the
  2285. same license as the files that they modify.
  2286. Note: Buildroot applies additional patches to Libtool scripts of
  2287. autotools-based packages. These patches can be found under
  2288. <code class="literal">support/libtool</code> in the Buildroot source and, due to technical
  2289. limitations, are not saved with the package sources. You may need to
  2290. collect them manually.
  2291. </li><li class="listitem">
  2292. A manifest file (one for host and one for target packages) listing the
  2293. configured packages, their version, license and related information.
  2294. Some of this information might not be defined in Buildroot; such items are
  2295. marked as "unknown".
  2296. </li><li class="listitem">
  2297. The license texts of all packages, in the <code class="literal">licenses/</code> and <code class="literal">host-licenses/</code>
  2298. subdirectories for target and host packages respectively.
  2299. If the license file(s) are not defined in Buildroot, the file is not produced
  2300. and a warning in the <code class="literal">README</code> indicates this.
  2301. </li></ul></div><p>Please note that the aim of the <code class="literal">legal-info</code> feature of Buildroot is to
  2302. produce all the material that is somehow relevant for legal compliance with the
  2303. package licenses. Buildroot does not try to produce the exact material that
  2304. you must somehow make public. Certainly, more material is produced than is
  2305. needed for a strict legal compliance. For example, it produces the source code
  2306. for packages released under BSD-like licenses, that you are not required to
  2307. redistribute in source form.</p><p>Moreover, due to technical limitations, Buildroot does not produce some
  2308. material that you will or may need, such as the toolchain source code for
  2309. some of the external toolchains and the Buildroot source code itself.
  2310. When you run <code class="literal">make legal-info</code>, Buildroot produces warnings in the <code class="literal">README</code>
  2311. file to inform you of relevant material that could not be saved.</p><p>Finally, keep in mind that the output of <code class="literal">make legal-info</code> is based on
  2312. declarative statements in each of the packages recipes. The Buildroot
  2313. developers try to do their best to keep those declarative statements as
  2314. accurate as possible, to the best of their knowledge. However, it is very
  2315. well possible that those declarative statements are not all fully accurate
  2316. nor exhaustive. You (or your legal department) <span class="emphasis"><em>have</em></span> to check the output
  2317. of <code class="literal">make legal-info</code> before using it as your own compliance delivery. See
  2318. the <span class="emphasis"><em>NO WARRANTY</em></span> clauses (clauses 11 and 12) in the <code class="literal">COPYING</code> file at the
  2319. root of the Buildroot distribution.</p></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="legal-info-buildroot"></a>13.2. Complying with the Buildroot license</h2></div></div></div><p>Buildroot itself is an open source software, released under the
  2320. <a class="ulink" href="http://www.gnu.org/licenses/old-licenses/gpl-2.0.html" target="_top">GNU General
  2321. Public License, version 2</a> or (at your option) any later version, with
  2322. the exception of the package patches detailed below.
  2323. However, being a build system, it is not normally part of the end product:
  2324. if you develop the root filesystem, kernel, bootloader or toolchain for a
  2325. device, the code of Buildroot is only present on the development machine, not
  2326. in the device storage.</p><p>Nevertheless, the general view of the Buildroot developers is that you should
  2327. release the Buildroot source code along with the source code of other packages
  2328. when releasing a product that contains GPL-licensed software.
  2329. This is because the
  2330. <a class="ulink" href="http://www.gnu.org/licenses/old-licenses/gpl-2.0.html" target="_top">GNU GPL</a>
  2331. defines the "<span class="emphasis"><em>complete source code</em></span>" for an executable work as "<span class="emphasis"><em>all the
  2332. source code for all modules it contains, plus any associated interface
  2333. definition files, plus the scripts used to control compilation and installation
  2334. of the executable</em></span>".
  2335. Buildroot is part of the <span class="emphasis"><em>scripts used to control compilation and
  2336. installation of the executable</em></span>, and as such it is considered part of the
  2337. material that must be redistributed.</p><p>Keep in mind that this is only the Buildroot developers' opinion, and you
  2338. should consult your legal department or lawyer in case of any doubt.</p><div class="section"><div class="titlepage"><div><div><h3 class="title"><a id="_patches_to_packages"></a>13.2.1. Patches to packages</h3></div></div></div><p>Buildroot also bundles patch files, which are applied to the sources
  2339. of the various packages. Those patches are not covered by the license
  2340. of Buildroot. Instead, they are covered by the license of the software
  2341. to which the patches are applied. When said software is available
  2342. under multiple licenses, the Buildroot patches are only provided under
  2343. the publicly accessible licenses.</p><p>See <a class="xref" href="#patch-policy" title="Chapter 19. Patching a package">Chapter 19, <em>Patching a package</em></a> for the technical details.</p></div></div></div><div class="chapter"><div class="titlepage"><div><div><h2 class="title"><a id="_beyond_buildroot"></a>Chapter 14. Beyond Buildroot</h2></div></div></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="_boot_the_generated_images"></a>14.1. Boot the generated images</h2></div></div></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a id="_nfs_boot"></a>14.1.1. NFS boot</h3></div></div></div><p>To achieve NFS-boot, enable <span class="emphasis"><em>tar root filesystem</em></span> in the <span class="emphasis"><em>Filesystem
  2344. images</em></span> menu.</p><p>After a complete build, just run the following commands to setup the
  2345. NFS-root directory:</p><pre class="screen">sudo tar -xavf /path/to/output_dir/rootfs.tar -C /path/to/nfs_root_dir</pre><p>Remember to add this path to <code class="literal">/etc/exports</code>.</p><p>Then, you can execute a NFS-boot from your target.</p></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a id="_live_cd"></a>14.1.2. Live CD</h3></div></div></div><p>To build a live CD image, enable the <span class="emphasis"><em>iso image</em></span> option in the
  2346. <span class="emphasis"><em>Filesystem images</em></span> menu. Note that this option is only available on
  2347. the x86 and x86-64 architectures, and if you are building your kernel
  2348. with Buildroot.</p><p>You can build a live CD image with either IsoLinux, Grub or Grub 2 as
  2349. a bootloader, but only Isolinux supports making this image usable both
  2350. as a live CD and live USB (through the <span class="emphasis"><em>Build hybrid image</em></span> option).</p><p>You can test your live CD image using QEMU:</p><pre class="screen">qemu-system-i386 -cdrom output/images/rootfs.iso9660</pre><p>Or use it as a hard-drive image if it is a hybrid ISO:</p><pre class="screen">qemu-system-i386 -hda output/images/rootfs.iso9660</pre><p>It can be easily flashed to a USB drive with <code class="literal">dd</code>:</p><pre class="screen">dd if=output/images/rootfs.iso9660 of=/dev/sdb</pre></div></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="_chroot"></a>14.2. Chroot</h2></div></div></div><p>If you want to chroot in a generated image, then there are few thing
  2351. you should be aware of:</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
  2352. you should setup the new root from the <span class="emphasis"><em>tar root filesystem</em></span> image;
  2353. </li><li class="listitem">
  2354. either the selected target architecture is compatible with your host
  2355. machine, or you should use some <code class="literal">qemu-*</code> binary and correctly set it
  2356. within the <code class="literal">binfmt</code> properties to be able to run the binaries built
  2357. for the target on your host machine;
  2358. </li><li class="listitem">
  2359. Buildroot does not currently provide <code class="literal">host-qemu</code> and <code class="literal">binfmt</code>
  2360. correctly built and set for that kind of use.
  2361. </li></ul></div></div></div></div><div class="part"><div class="titlepage"><div><div><h1 class="title"><a id="_developer_guide"></a>Part III. Developer guide</h1></div></div></div><div class="chapter"><div class="titlepage"><div><div><h2 class="title"><a id="_how_buildroot_works"></a>Chapter 15. How Buildroot works</h2></div></div></div><p>As mentioned above, Buildroot is basically a set of Makefiles that
  2362. download, configure, and compile software with the correct options. It
  2363. also includes patches for various software packages - mainly the ones
  2364. involved in the cross-compilation toolchain (<code class="literal">gcc</code>, <code class="literal">binutils</code> and
  2365. <code class="literal">uClibc</code>).</p><p>There is basically one Makefile per software package, and they are
  2366. named with the <code class="literal">.mk</code> extension. Makefiles are split into many different
  2367. parts.</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
  2368. The <code class="literal">toolchain/</code> directory contains the Makefiles
  2369. and associated files for all software related to the
  2370. cross-compilation toolchain: <code class="literal">binutils</code>, <code class="literal">gcc</code>, <code class="literal">gdb</code>,
  2371. <code class="literal">kernel-headers</code> and <code class="literal">uClibc</code>.
  2372. </li><li class="listitem">
  2373. The <code class="literal">arch/</code> directory contains the definitions for all the processor
  2374. architectures that are supported by Buildroot.
  2375. </li><li class="listitem">
  2376. The <code class="literal">package/</code> directory contains the Makefiles and
  2377. associated files for all user-space tools and libraries that Buildroot
  2378. can compile and add to the target root filesystem. There is one
  2379. sub-directory per package.
  2380. </li><li class="listitem">
  2381. The <code class="literal">linux/</code> directory contains the Makefiles and associated files for
  2382. the Linux kernel.
  2383. </li><li class="listitem">
  2384. The <code class="literal">boot/</code> directory contains the Makefiles and associated files for
  2385. the bootloaders supported by Buildroot.
  2386. </li><li class="listitem">
  2387. The <code class="literal">system/</code> directory contains support for system integration, e.g.
  2388. the target filesystem skeleton and the selection of an init system.
  2389. </li><li class="listitem">
  2390. The <code class="literal">fs/</code> directory contains the Makefiles and
  2391. associated files for software related to the generation of the
  2392. target root filesystem image.
  2393. </li></ul></div><p>Each directory contains at least 2 files:</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
  2394. <code class="literal">something.mk</code> is the Makefile that downloads, configures,
  2395. compiles and installs the package <code class="literal">something</code>.
  2396. </li><li class="listitem">
  2397. <code class="literal">Config.in</code> is a part of the configuration tool
  2398. description file. It describes the options related to the
  2399. package.
  2400. </li></ul></div><p>The main Makefile performs the following steps (once the
  2401. configuration is done):</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
  2402. Create all the output directories: <code class="literal">staging</code>, <code class="literal">target</code>, <code class="literal">build</code>,
  2403. etc. in the output directory (<code class="literal">output/</code> by default,
  2404. another value can be specified using <code class="literal">O=</code>)
  2405. </li><li class="listitem">
  2406. Generate the toolchain target. When an internal toolchain is used, this
  2407. means generating the cross-compilation toolchain. When an external
  2408. toolchain is used, this means checking the features of the external
  2409. toolchain and importing it into the Buildroot environment.
  2410. </li><li class="listitem">
  2411. Generate all the targets listed in the <code class="literal">TARGETS</code> variable. This
  2412. variable is filled by all the individual components'
  2413. Makefiles. Generating these targets will trigger the compilation of
  2414. the userspace packages (libraries, programs), the kernel, the
  2415. bootloader and the generation of the root filesystem images,
  2416. depending on the configuration.
  2417. </li></ul></div></div><div class="chapter"><div class="titlepage"><div><div><h2 class="title"><a id="_coding_style"></a>Chapter 16. Coding style</h2></div></div></div><p>Overall, these coding style rules are here to help you to add new files in
  2418. Buildroot or refactor existing ones.</p><p>If you slightly modify some existing file, the important thing is
  2419. to keep the consistency of the whole file, so you can:</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
  2420. either follow the potentially deprecated coding style used in this
  2421. file,
  2422. </li><li class="listitem">
  2423. or entirely rework it in order to make it comply with these rules.
  2424. </li></ul></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="writing-rules-config-in"></a>16.1. <code class="literal">Config.in</code> file</h2></div></div></div><p><code class="literal">Config.in</code> files contain entries for almost anything configurable in
  2425. Buildroot.</p><p>An entry has the following pattern:</p><pre class="screen">config BR2_PACKAGE_LIBFOO
  2426. bool "libfoo"
  2427. depends on BR2_PACKAGE_LIBBAZ
  2428. select BR2_PACKAGE_LIBBAR
  2429. help
  2430. This is a comment that explains what libfoo is. The help text
  2431. should be wrapped.
  2432. http://foosoftware.org/libfoo/</pre><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
  2433. The <code class="literal">bool</code>, <code class="literal">depends on</code>, <code class="literal">select</code> and <code class="literal">help</code> lines are indented
  2434. with one tab.
  2435. </li><li class="listitem">
  2436. The help text itself should be indented with one tab and two
  2437. spaces.
  2438. </li><li class="listitem">
  2439. The help text should be wrapped to fit 72 columns, where tab counts
  2440. for 8, so 62 characters in the text itself.
  2441. </li></ul></div><p>The <code class="literal">Config.in</code> files are the input for the configuration tool
  2442. used in Buildroot, which is the regular <span class="emphasis"><em>Kconfig</em></span>. For further
  2443. details about the <span class="emphasis"><em>Kconfig</em></span> language, refer to
  2444. <a class="ulink" href="http://kernel.org/doc/Documentation/kbuild/kconfig-language.txt" target="_top">http://kernel.org/doc/Documentation/kbuild/kconfig-language.txt</a>.</p></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="writing-rules-mk"></a>16.2. The <code class="literal">.mk</code> file</h2></div></div></div><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p class="simpara">
  2445. Header: The file starts with a header. It contains the module name,
  2446. preferably in lowercase, enclosed between separators made of 80 hashes. A
  2447. blank line is mandatory after the header:
  2448. </p><pre class="screen">################################################################################
  2449. #
  2450. # libfoo
  2451. #
  2452. ################################################################################</pre></li><li class="listitem"><p class="simpara">
  2453. Assignment: use <code class="literal">=</code> preceded and followed by one space:
  2454. </p><pre class="screen">LIBFOO_VERSION = 1.0
  2455. LIBFOO_CONF_OPTS += --without-python-support</pre><p class="simpara">Do not align the <code class="literal">=</code> signs.</p></li><li class="listitem"><p class="simpara">
  2456. Indentation: use tab only:
  2457. </p><pre class="screen">define LIBFOO_REMOVE_DOC
  2458. $(RM) -r $(TARGET_DIR)/usr/share/libfoo/doc \
  2459. $(TARGET_DIR)/usr/share/man/man3/libfoo*
  2460. endef</pre><p class="simpara">Note that commands inside a <code class="literal">define</code> block should always start with a tab,
  2461. so <span class="emphasis"><em>make</em></span> recognizes them as commands.</p></li><li class="listitem"><p class="simpara">
  2462. Optional dependency:
  2463. </p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: circle; "><li class="listitem"><p class="simpara">
  2464. Prefer multi-line syntax.
  2465. </p><p class="simpara">YES:</p><pre class="screen">ifeq ($(BR2_PACKAGE_PYTHON3),y)
  2466. LIBFOO_CONF_OPTS += --with-python-support
  2467. LIBFOO_DEPENDENCIES += python3
  2468. else
  2469. LIBFOO_CONF_OPTS += --without-python-support
  2470. endif</pre><p class="simpara">NO:</p><pre class="screen">LIBFOO_CONF_OPTS += --with$(if $(BR2_PACKAGE_PYTHON3),,out)-python-support
  2471. LIBFOO_DEPENDENCIES += $(if $(BR2_PACKAGE_PYTHON3),python3,)</pre></li><li class="listitem">
  2472. Keep configure options and dependencies close together.
  2473. </li></ul></div></li><li class="listitem"><p class="simpara">
  2474. Optional hooks: keep hook definition and assignment together in one
  2475. if block.
  2476. </p><p class="simpara">YES:</p><pre class="screen">ifneq ($(BR2_LIBFOO_INSTALL_DATA),y)
  2477. define LIBFOO_REMOVE_DATA
  2478. $(RM) -r $(TARGET_DIR)/usr/share/libfoo/data
  2479. endef
  2480. LIBFOO_POST_INSTALL_TARGET_HOOKS += LIBFOO_REMOVE_DATA
  2481. endif</pre><p class="simpara">NO:</p><pre class="screen">define LIBFOO_REMOVE_DATA
  2482. $(RM) -r $(TARGET_DIR)/usr/share/libfoo/data
  2483. endef
  2484. ifneq ($(BR2_LIBFOO_INSTALL_DATA),y)
  2485. LIBFOO_POST_INSTALL_TARGET_HOOKS += LIBFOO_REMOVE_DATA
  2486. endif</pre></li></ul></div></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="writing-genimage-cfg"></a>16.3. The <code class="literal">genimage.cfg</code> file</h2></div></div></div><p><code class="literal">genimage.cfg</code> files contain the output image layout that genimage utility
  2487. uses to create final .img file.</p><p>An example follows:</p><pre class="screen">image efi-part.vfat {
  2488. vfat {
  2489. file EFI {
  2490. image = "efi-part/EFI"
  2491. }
  2492. file Image {
  2493. image = "Image"
  2494. }
  2495. }
  2496. size = 32M
  2497. }
  2498. image sdimage.img {
  2499. hdimage {
  2500. }
  2501. partition u-boot {
  2502. image = "efi-part.vfat"
  2503. offset = 8K
  2504. }
  2505. partition root {
  2506. image = "rootfs.ext2"
  2507. size = 512M
  2508. }
  2509. }</pre><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
  2510. Every <code class="literal">section</code>(i.e. hdimage, vfat etc.), <code class="literal">partition</code> must be indented
  2511. with one tab.
  2512. </li><li class="listitem">
  2513. Every <code class="literal">file</code> or other <code class="literal">subnode</code> must be indented with two tabs.
  2514. </li><li class="listitem">
  2515. Every node(<code class="literal">section</code>, <code class="literal">partition</code>, <code class="literal">file</code>, <code class="literal">subnode</code>) must have an open
  2516. curly bracket on the same line of the node’s name, while the closing one
  2517. must be on a newline and after it a newline must be added except for the
  2518. last one node. Same goes for its option, for example option <code class="literal">size</code> <code class="literal">=</code>.
  2519. </li><li class="listitem">
  2520. Every <code class="literal">option</code>(i.e. <code class="literal">image</code>, <code class="literal">offset</code>, <code class="literal">size</code>) must have the <code class="literal">=</code>
  2521. assignment one space from it and one space from the value specified.
  2522. </li><li class="listitem">
  2523. Filename must at least begin with genimage prefix and have the .cfg
  2524. extension to be easy to recognize.
  2525. </li><li class="listitem">
  2526. Allowed notations for <code class="literal">offset</code> and <code class="literal">size</code> options are: <code class="literal">G</code>, <code class="literal">M</code>, <code class="literal">K</code>
  2527. (not <code class="literal">k</code>). If it’s not possible to express a precise byte count
  2528. with notations above then use hexadecimal <code class="literal">0x</code> prefix or, as last
  2529. chance, the byte count. In comments instead use <code class="literal">GB</code>, <code class="literal">MB</code>, <code class="literal">KB</code>
  2530. (not <code class="literal">kb</code>) in place of <code class="literal">G</code>, <code class="literal">M</code>, <code class="literal">K</code>.
  2531. </li><li class="listitem">
  2532. For GPT partitions, the <code class="literal">partition-type-uuid</code> value must be <code class="literal">U</code> for
  2533. the EFI System Partition (expanded to
  2534. <code class="literal">c12a7328-f81f-11d2-ba4b-00a0c93ec93b</code> by <span class="emphasis"><em>genimage</em></span>), <code class="literal">F</code> for a FAT
  2535. partition (expanded to <code class="literal">ebd0a0a2-b9e5-4433-87c0-68b6b72699c7</code> by
  2536. <span class="emphasis"><em>genimage</em></span>) or <code class="literal">L</code> for the root filesystem or other filesystems
  2537. (expanded to <code class="literal">0fc63daf-8483-4772-8e79-3d69d8477de4</code> by
  2538. <span class="emphasis"><em>genimage</em></span>). Even though <code class="literal">L</code> is the default value of <span class="emphasis"><em>genimage</em></span>, we
  2539. prefer to have it explicitly specified in our <code class="literal">genimage.cfg</code>
  2540. files. Finally, these shortcuts should be used without double
  2541. quotes, e.g <code class="literal">partition-type-uuid = U</code>. If an explicit GUID is
  2542. specified, lower-case letters should be used.
  2543. </li></ul></div><p>The <code class="literal">genimage.cfg</code> files are the input for the genimage tool used in
  2544. Buildroot to generate the final image file(i.e. sdcard.img). For further
  2545. details about the <span class="emphasis"><em>genimage</em></span> language, refer to
  2546. <a class="ulink" href="https://github.com/pengutronix/genimage/blob/master/README.rst" target="_top">https://github.com/pengutronix/genimage/blob/master/README.rst</a>.</p></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="_the_documentation"></a>16.4. The documentation</h2></div></div></div><p>The documentation uses the
  2547. <a class="ulink" href="https://asciidoc-py.github.io/" target="_top">asciidoc</a> format.</p><p>For further details about the asciidoc syntax, refer to
  2548. <a class="ulink" href="https://asciidoc-py.github.io/userguide.html" target="_top">https://asciidoc-py.github.io/userguide.html</a>.</p></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="_support_scripts"></a>16.5. Support scripts</h2></div></div></div><p>Some scripts in the <code class="literal">support/</code> and <code class="literal">utils/</code> directories are written in
  2549. Python and should follow the
  2550. <a class="ulink" href="https://www.python.org/dev/peps/pep-0008/" target="_top">PEP8 Style Guide for Python Code</a>.</p></div></div><div class="chapter"><div class="titlepage"><div><div><h2 class="title"><a id="adding-board-support"></a>Chapter 17. Adding support for a particular board</h2></div></div></div><p>Buildroot contains basic configurations for several publicly available
  2551. hardware boards, so that users of such a board can easily build a system
  2552. that is known to work. You are welcome to add support for other boards
  2553. to Buildroot too.</p><p>To do so, you need to create a normal Buildroot configuration that
  2554. builds a basic system for the hardware: (internal) toolchain, kernel,
  2555. bootloader, filesystem and a simple BusyBox-only userspace. No specific
  2556. package should be selected: the configuration should be as minimal as
  2557. possible, and should only build a working basic BusyBox system for the
  2558. target platform. You can of course use more complicated configurations
  2559. for your internal projects, but the Buildroot project will only
  2560. integrate basic board configurations. This is because package
  2561. selections are highly application-specific.</p><p>Once you have a known working configuration, run <code class="literal">make
  2562. savedefconfig</code>. This will generate a minimal <code class="literal">defconfig</code> file at the
  2563. root of the Buildroot source tree. Move this file into the <code class="literal">configs/</code>
  2564. directory, and rename it <code class="literal">&lt;boardname&gt;_defconfig</code>.</p><p>Always use fixed versions or commit hashes for the different
  2565. components, not the "latest" version. For example, set
  2566. <code class="literal">BR2_LINUX_KERNEL_CUSTOM_VERSION=y</code> and
  2567. <code class="literal">BR2_LINUX_KERNEL_CUSTOM_VERSION_VALUE</code> to the kernel version you tested
  2568. with. If you are using the buildroot toolchain <code class="literal">BR2_TOOLCHAIN_BUILDROOT</code>
  2569. (which is the default), additionally ensure that the same kernel headers
  2570. are used (<code class="literal">BR2_KERNEL_HEADERS_AS_KERNEL</code>, which is also the default) and
  2571. set the custom kernel headers series to match your kernel version
  2572. (<code class="literal">BR2_PACKAGE_HOST_LINUX_HEADERS_CUSTOM_*</code>).</p><p>It is recommended to use as much as possible upstream versions of the
  2573. Linux kernel and bootloaders, and to use as much as possible default
  2574. kernel and bootloader configurations. If they are incorrect for your
  2575. board, or no default exists, we encourage you to send fixes to the
  2576. corresponding upstream projects.</p><p>However, in the mean time, you may want to store kernel or bootloader
  2577. configuration or patches specific to your target platform. To do so,
  2578. create a directory <code class="literal">board/&lt;manufacturer&gt;</code> and a subdirectory
  2579. <code class="literal">board/&lt;manufacturer&gt;/&lt;boardname&gt;</code>. You can then store your patches
  2580. and configurations in these directories, and reference them from the main
  2581. Buildroot configuration. Refer to <a class="xref" href="#customize" title="Chapter 9. Project-specific customization">Chapter 9, <em>Project-specific customization</em></a> for more details.</p><p>Before submitting patches for new boards it is recommended to test it by
  2582. building it using latest gitlab-CI docker container. To do this use
  2583. <code class="literal">utils/docker-run</code> script and inside it issue these commands:</p><pre class="screen"> $ make &lt;boardname&gt;_defconfig
  2584. $ make</pre><p>By default, Buildroot developers use the official image hosted on the
  2585. <a class="ulink" href="https://gitlab.com/buildroot.org/buildroot/container_registry/2395076" target="_top">gitlab.com
  2586. registry</a> and it should be convenient for most usage. If you still want
  2587. to build your own docker image, you can base it off the official image
  2588. as the <code class="literal">FROM</code> directive of your own <span class="emphasis"><em>Dockerfile</em></span>:</p><pre class="screen">FROM registry.gitlab.com/buildroot.org/buildroot/base:YYYYMMDD.HHMM
  2589. RUN ...
  2590. COPY ...</pre><p>The current version <span class="emphasis"><em>YYYYMMDD.HHMM</em></span> can be found in the <code class="literal">.gitlab-ci.yml</code>
  2591. file at the top of the Buildroot source tree; all past versions are
  2592. listed in the aforementioned registry as well.</p></div><div class="chapter"><div class="titlepage"><div><div><h2 class="title"><a id="adding-packages"></a>Chapter 18. Adding new packages to Buildroot</h2></div></div></div><p>This section covers how new packages (userspace libraries or
  2593. applications) can be integrated into Buildroot. It also shows how
  2594. existing packages are integrated, which is needed for fixing issues or
  2595. tuning their configuration.</p><p>When you add a new package, be sure to test it in various conditions
  2596. (see <a class="xref" href="#testing-package" title="18.25.3. How to test your package">Section 18.25.3, “How to test your package”</a>) and also check it for coding style (see
  2597. <a class="xref" href="#check-package" title="18.25.2. How to check the coding style">Section 18.25.2, “How to check the coding style”</a>).</p><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="_package_directory"></a>18.1. Package directory</h2></div></div></div><p>First of all, create a directory under the <code class="literal">package</code> directory for
  2598. your software, for example <code class="literal">libfoo</code>.</p><p>Some packages have been grouped by topic in a sub-directory:
  2599. <code class="literal">x11r7</code>, <code class="literal">qt5</code> and <code class="literal">gstreamer</code>. If your package fits in
  2600. one of these categories, then create your package directory in these.
  2601. New subdirectories are discouraged, however.</p></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="_config_files"></a>18.2. Config files</h2></div></div></div><p>For the package to be displayed in the configuration tool, you need to
  2602. create a Config file in your package directory. There are two types:
  2603. <code class="literal">Config.in</code> and <code class="literal">Config.in.host</code>.</p><div class="section"><div class="titlepage"><div><div><h3 class="title"><a id="_literal_config_in_literal_file"></a>18.2.1. <code class="literal">Config.in</code> file</h3></div></div></div><p>For packages used on the target, create a file named <code class="literal">Config.in</code>. This
  2604. file will contain the option descriptions related to our <code class="literal">libfoo</code> software
  2605. that will be used and displayed in the configuration tool. It should basically
  2606. contain:</p><pre class="screen">config BR2_PACKAGE_LIBFOO
  2607. bool "libfoo"
  2608. help
  2609. This is a comment that explains what libfoo is. The help text
  2610. should be wrapped.
  2611. http://foosoftware.org/libfoo/</pre><p>The <code class="literal">bool</code> line, <code class="literal">help</code> line and other metadata information about the
  2612. configuration option must be indented with one tab. The help text
  2613. itself should be indented with one tab and two spaces, lines should
  2614. be wrapped to fit 72 columns, where tab counts for 8, so 62 characters
  2615. in the text itself. The help text must mention the upstream URL of the
  2616. project after an empty line.</p><p>As a convention specific to Buildroot, the ordering of the attributes
  2617. is as follows:</p><div class="orderedlist"><ol class="orderedlist" type="1"><li class="listitem">
  2618. The type of option: <code class="literal">bool</code>, <code class="literal">string</code>… with the prompt
  2619. </li><li class="listitem">
  2620. If needed, the <code class="literal">default</code> value(s)
  2621. </li><li class="listitem">
  2622. Any dependencies on the target in <code class="literal">depends on</code> form
  2623. </li><li class="listitem">
  2624. Any dependencies on the toolchain in <code class="literal">depends on</code> form
  2625. </li><li class="listitem">
  2626. Any dependencies on other packages in <code class="literal">depends on</code> form
  2627. </li><li class="listitem">
  2628. Any dependency of the <code class="literal">select</code> form
  2629. </li><li class="listitem">
  2630. The help keyword and help text.
  2631. </li></ol></div><p>You can add other sub-options into a <code class="literal">if BR2_PACKAGE_LIBFOO…endif</code>
  2632. statement to configure particular things in your software. You can look at
  2633. examples in other packages. The syntax of the <code class="literal">Config.in</code> file is the same
  2634. as the one for the kernel Kconfig file. The documentation for this syntax is
  2635. available at <a class="ulink" href="http://kernel.org/doc/Documentation/kbuild/kconfig-language.txt" target="_top">http://kernel.org/doc/Documentation/kbuild/kconfig-language.txt</a></p><p>Finally you have to add your new <code class="literal">libfoo/Config.in</code> to
  2636. <code class="literal">package/Config.in</code> (or in a category subdirectory if you decided to
  2637. put your package in one of the existing categories). The files
  2638. included there are <span class="emphasis"><em>sorted alphabetically</em></span> per category and are <span class="emphasis"><em>NOT</em></span>
  2639. supposed to contain anything but the <span class="emphasis"><em>bare</em></span> name of the package.</p><pre class="screen">source "package/libfoo/Config.in"</pre></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a id="_literal_config_in_host_literal_file"></a>18.2.2. <code class="literal">Config.in.host</code> file</h3></div></div></div><p>Some packages also need to be built for the host system. There are two
  2640. options here:</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
  2641. The host package is only required to satisfy build-time
  2642. dependencies of one or more target packages. In this case, add
  2643. <code class="literal">host-foo</code> to the target package’s <code class="literal">BAR_DEPENDENCIES</code> variable. No
  2644. <code class="literal">Config.in.host</code> file should be created.
  2645. </li><li class="listitem"><p class="simpara">
  2646. The host package should be explicitly selectable by the user from
  2647. the configuration menu. In this case, create a <code class="literal">Config.in.host</code> file
  2648. for that host package:
  2649. </p><pre class="screen">config BR2_PACKAGE_HOST_FOO
  2650. bool "host foo"
  2651. help
  2652. This is a comment that explains what foo for the host is.
  2653. http://foosoftware.org/foo/</pre><p class="simpara">The same coding style and options as for the <code class="literal">Config.in</code> file are valid.</p><p class="simpara">Finally you have to add your new <code class="literal">libfoo/Config.in.host</code> to
  2654. <code class="literal">package/Config.in.host</code>. The files included there are <span class="emphasis"><em>sorted alphabetically</em></span>
  2655. and are <span class="emphasis"><em>NOT</em></span> supposed to contain anything but the <span class="emphasis"><em>bare</em></span> name of the package.</p><pre class="screen">source "package/foo/Config.in.host"</pre><p class="simpara">The host package will then be available from the <code class="literal">Host utilities</code> menu.</p></li></ul></div></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a id="depends-on-vs-select"></a>18.2.3. Choosing <code class="literal">depends on</code> or <code class="literal">select</code></h3></div></div></div><p>The <code class="literal">Config.in</code> file of your package must also ensure that
  2656. dependencies are enabled. Typically, Buildroot uses the following
  2657. rules:</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
  2658. Use a <code class="literal">select</code> type of dependency for dependencies on
  2659. libraries. These dependencies are generally not obvious and it
  2660. therefore make sense to have the kconfig system ensure that the
  2661. dependencies are selected. For example, the <span class="emphasis"><em>libgtk2</em></span> package uses
  2662. <code class="literal">select BR2_PACKAGE_LIBGLIB2</code> to make sure this library is also
  2663. enabled.
  2664. The <code class="literal">select</code> keyword expresses the dependency with a backward
  2665. semantic.
  2666. </li><li class="listitem">
  2667. Use a <code class="literal">depends on</code> type of dependency when the user really needs to
  2668. be aware of the dependency. Typically, Buildroot uses this type of
  2669. dependency for dependencies on target architecture, MMU support and
  2670. toolchain options (see <a class="xref" href="#dependencies-target-toolchain-options" title="18.2.4. Dependencies on target and toolchain options">Section 18.2.4, “Dependencies on target and toolchain options”</a>),
  2671. or for dependencies on "big" things, such as the X.org system.
  2672. The <code class="literal">depends on</code> keyword expresses the dependency with a forward
  2673. semantic.
  2674. </li></ul></div><p><strong>Note. </strong>The current problem with the <span class="emphasis"><em>kconfig</em></span> language is that these two
  2675. dependency semantics are not internally linked. Therefore, it may be
  2676. possible to select a package, whom one of its dependencies/requirement
  2677. is not met.</p><p>An example illustrates both the usage of <code class="literal">select</code> and <code class="literal">depends on</code>.</p><pre class="screen">config BR2_PACKAGE_RRDTOOL
  2678. bool "rrdtool"
  2679. depends on BR2_USE_WCHAR
  2680. select BR2_PACKAGE_FREETYPE
  2681. select BR2_PACKAGE_LIBART
  2682. select BR2_PACKAGE_LIBPNG
  2683. select BR2_PACKAGE_ZLIB
  2684. help
  2685. RRDtool is the OpenSource industry standard, high performance
  2686. data logging and graphing system for time series data.
  2687. http://oss.oetiker.ch/rrdtool/
  2688. comment "rrdtool needs a toolchain w/ wchar"
  2689. depends on !BR2_USE_WCHAR</pre><p>Note that these two dependency types are only transitive with the
  2690. dependencies of the same kind.</p><p>This means, in the following example:</p><pre class="screen">config BR2_PACKAGE_A
  2691. bool "Package A"
  2692. config BR2_PACKAGE_B
  2693. bool "Package B"
  2694. depends on BR2_PACKAGE_A
  2695. config BR2_PACKAGE_C
  2696. bool "Package C"
  2697. depends on BR2_PACKAGE_B
  2698. config BR2_PACKAGE_D
  2699. bool "Package D"
  2700. select BR2_PACKAGE_B
  2701. config BR2_PACKAGE_E
  2702. bool "Package E"
  2703. select BR2_PACKAGE_D</pre><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
  2704. Selecting <code class="literal">Package C</code> will be visible if <code class="literal">Package B</code> has been
  2705. selected, which in turn is only visible if <code class="literal">Package A</code> has been
  2706. selected.
  2707. </li><li class="listitem">
  2708. Selecting <code class="literal">Package E</code> will select <code class="literal">Package D</code>, which will select
  2709. <code class="literal">Package B</code>, it will not check for the dependencies of <code class="literal">Package B</code>,
  2710. so it will not select <code class="literal">Package A</code>.
  2711. </li><li class="listitem">
  2712. Since <code class="literal">Package B</code> is selected but <code class="literal">Package A</code> is not, this violates
  2713. the dependency of <code class="literal">Package B</code> on <code class="literal">Package A</code>. Therefore, in such a
  2714. situation, the transitive dependency has to be added explicitly:
  2715. </li></ul></div><pre class="screen">config BR2_PACKAGE_D
  2716. bool "Package D"
  2717. depends on BR2_PACKAGE_A
  2718. select BR2_PACKAGE_B
  2719. config BR2_PACKAGE_E
  2720. bool "Package E"
  2721. depends on BR2_PACKAGE_A
  2722. select BR2_PACKAGE_D</pre><p>Overall, for package library dependencies, <code class="literal">select</code> should be
  2723. preferred.</p><p>Note that such dependencies will ensure that the dependency option
  2724. is also enabled, but not necessarily built before your package. To do
  2725. so, the dependency also needs to be expressed in the <code class="literal">.mk</code> file of the
  2726. package.</p><p>Further formatting details: see <a class="link" href="#writing-rules-config-in" title="16.1. Config.in file">the
  2727. coding style</a>.</p></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a id="dependencies-target-toolchain-options"></a>18.2.4. Dependencies on target and toolchain options</h3></div></div></div><p>Many packages depend on certain options of the toolchain: the choice of
  2728. C library, C++ support, thread support, RPC support, wchar support,
  2729. or dynamic library support. Some packages can only be built on certain
  2730. target architectures, or if an MMU is available in the processor.</p><p>These dependencies have to be expressed with the appropriate <span class="emphasis"><em>depends
  2731. on</em></span> statements in the Config.in file. Additionally, for dependencies on
  2732. toolchain options, a <code class="literal">comment</code> should be displayed when the option is
  2733. not enabled, so that the user knows why the package is not available.
  2734. Dependencies on target architecture or MMU support should not be
  2735. made visible in a comment: since it is unlikely that the user can
  2736. freely choose another target, it makes little sense to show these
  2737. dependencies explicitly.</p><p>The <code class="literal">comment</code> should only be visible if the <code class="literal">config</code> option itself would
  2738. be visible when the toolchain option dependencies are met. This means
  2739. that all other dependencies of the package (including dependencies on
  2740. target architecture and MMU support) have to be repeated on the
  2741. <code class="literal">comment</code> definition. To keep it clear, the <code class="literal">depends on</code> statement for
  2742. these non-toolchain option should be kept separate from the <code class="literal">depends on</code>
  2743. statement for the toolchain options.
  2744. If there is a dependency on a config option in that same file (typically
  2745. the main package) it is preferable to have a global <code class="literal">if … endif</code>
  2746. construct rather than repeating the <code class="literal">depends on</code> statement on the
  2747. comment and other config options.</p><p>The general format of a dependency <code class="literal">comment</code> for package foo is:</p><pre class="screen">foo needs a toolchain w/ featA, featB, featC</pre><p>for example:</p><pre class="screen">mpd needs a toolchain w/ C++, threads, wchar</pre><p>or</p><pre class="screen">crda needs a toolchain w/ threads</pre><p>Note that this text is kept brief on purpose, so that it will fit on a
  2748. 80-character terminal.</p><p>The rest of this section enumerates the different target and toolchain
  2749. options, the corresponding config symbols to depend on, and the text to
  2750. use in the comment.</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p class="simpara">
  2751. Target architecture
  2752. </p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: circle; "><li class="listitem">
  2753. Dependency symbol: <code class="literal">BR2_powerpc</code>, <code class="literal">BR2_mips</code>, … (see <code class="literal">arch/Config.in</code>)
  2754. </li><li class="listitem">
  2755. Comment string: no comment to be added
  2756. </li></ul></div></li><li class="listitem"><p class="simpara">
  2757. MMU support
  2758. </p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: circle; "><li class="listitem">
  2759. Dependency symbol: <code class="literal">BR2_USE_MMU</code>
  2760. </li><li class="listitem">
  2761. Comment string: no comment to be added
  2762. </li></ul></div></li><li class="listitem"><p class="simpara">
  2763. Gcc <code class="literal"><span class="emphasis"><em>_sync</em></span>*</code> built-ins used for atomic operations. They are
  2764. available in variants operating on 1 byte, 2 bytes, 4 bytes and 8
  2765. bytes. Since different architectures support atomic operations on
  2766. different sizes, one dependency symbol is available for each size:
  2767. </p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: circle; "><li class="listitem">
  2768. Dependency symbol: <code class="literal">BR2_TOOLCHAIN_HAS_SYNC_1</code> for 1 byte,
  2769. <code class="literal">BR2_TOOLCHAIN_HAS_SYNC_2</code> for 2 bytes,
  2770. <code class="literal">BR2_TOOLCHAIN_HAS_SYNC_4</code> for 4 bytes, <code class="literal">BR2_TOOLCHAIN_HAS_SYNC_8</code>
  2771. for 8 bytes.
  2772. </li><li class="listitem">
  2773. Comment string: no comment to be added
  2774. </li></ul></div></li><li class="listitem"><p class="simpara">
  2775. Gcc <code class="literal"><span class="emphasis"><em>_atomic</em></span>*</code> built-ins used for atomic operations.
  2776. </p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: circle; "><li class="listitem">
  2777. Dependency symbol: <code class="literal">BR2_TOOLCHAIN_HAS_ATOMIC</code>.
  2778. </li><li class="listitem">
  2779. Comment string: no comment to be added
  2780. </li></ul></div></li><li class="listitem"><p class="simpara">
  2781. Kernel headers
  2782. </p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: circle; "><li class="listitem">
  2783. Dependency symbol: <code class="literal">BR2_TOOLCHAIN_HEADERS_AT_LEAST_X_Y</code>, (replace
  2784. <code class="literal">X_Y</code> with the proper version, see <code class="literal">toolchain/Config.in</code>)
  2785. </li><li class="listitem">
  2786. Comment string: <code class="literal">headers &gt;= X.Y</code> and/or <code class="literal">headers &lt;= X.Y</code> (replace
  2787. <code class="literal">X.Y</code> with the proper version)
  2788. </li></ul></div></li><li class="listitem"><p class="simpara">
  2789. GCC version
  2790. </p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: circle; "><li class="listitem">
  2791. Dependency symbol: <code class="literal">BR2_TOOLCHAIN_GCC_AT_LEAST_X_Y</code>, (replace
  2792. <code class="literal">X_Y</code> with the proper version, see <code class="literal">toolchain/Config.in</code>)
  2793. </li><li class="listitem">
  2794. Comment string: <code class="literal">gcc &gt;= X.Y</code> and/or <code class="literal">gcc &lt;= X.Y</code> (replace
  2795. <code class="literal">X.Y</code> with the proper version)
  2796. </li></ul></div></li><li class="listitem"><p class="simpara">
  2797. Host GCC version
  2798. </p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: circle; "><li class="listitem">
  2799. Dependency symbol: <code class="literal">BR2_HOST_GCC_AT_LEAST_X_Y</code>, (replace
  2800. <code class="literal">X_Y</code> with the proper version, see <code class="literal">Config.in</code>)
  2801. </li><li class="listitem">
  2802. Comment string: no comment to be added
  2803. </li><li class="listitem">
  2804. Note that it is usually not the package itself that has a minimum
  2805. host GCC version, but rather a host-package on which it depends.
  2806. </li></ul></div></li><li class="listitem"><p class="simpara">
  2807. C library
  2808. </p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: circle; "><li class="listitem">
  2809. Dependency symbol: <code class="literal">BR2_TOOLCHAIN_USES_GLIBC</code>,
  2810. <code class="literal">BR2_TOOLCHAIN_USES_MUSL</code>, <code class="literal">BR2_TOOLCHAIN_USES_UCLIBC</code>
  2811. </li><li class="listitem">
  2812. Comment string: for the C library, a slightly different comment text
  2813. is used: <code class="literal">foo needs a glibc toolchain</code>, or <code class="literal">foo needs a glibc
  2814. toolchain w/ C++</code>
  2815. </li></ul></div></li><li class="listitem"><p class="simpara">
  2816. C++ support
  2817. </p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: circle; "><li class="listitem">
  2818. Dependency symbol: <code class="literal">BR2_INSTALL_LIBSTDCPP</code>
  2819. </li><li class="listitem">
  2820. Comment string: <code class="literal">C++</code>
  2821. </li></ul></div></li><li class="listitem"><p class="simpara">
  2822. D support
  2823. </p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: circle; "><li class="listitem">
  2824. Dependency symbol: <code class="literal">BR2_TOOLCHAIN_HAS_DLANG</code>
  2825. </li><li class="listitem">
  2826. Comment string: <code class="literal">Dlang</code>
  2827. </li></ul></div></li><li class="listitem"><p class="simpara">
  2828. Fortran support
  2829. </p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: circle; "><li class="listitem">
  2830. Dependency symbol: <code class="literal">BR2_TOOLCHAIN_HAS_FORTRAN</code>
  2831. </li><li class="listitem">
  2832. Comment string: <code class="literal">fortran</code>
  2833. </li></ul></div></li><li class="listitem"><p class="simpara">
  2834. thread support
  2835. </p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: circle; "><li class="listitem">
  2836. Dependency symbol: <code class="literal">BR2_TOOLCHAIN_HAS_THREADS</code>
  2837. </li><li class="listitem">
  2838. Comment string: <code class="literal">threads</code> (unless <code class="literal">BR2_TOOLCHAIN_HAS_THREADS_NPTL</code>
  2839. is also needed, in which case, specifying only <code class="literal">NPTL</code> is sufficient)
  2840. </li></ul></div></li><li class="listitem"><p class="simpara">
  2841. NPTL thread support
  2842. </p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: circle; "><li class="listitem">
  2843. Dependency symbol: <code class="literal">BR2_TOOLCHAIN_HAS_THREADS_NPTL</code>
  2844. </li><li class="listitem">
  2845. Comment string: <code class="literal">NPTL</code>
  2846. </li></ul></div></li><li class="listitem"><p class="simpara">
  2847. RPC support
  2848. </p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: circle; "><li class="listitem">
  2849. Dependency symbol: <code class="literal">BR2_TOOLCHAIN_HAS_NATIVE_RPC</code>
  2850. </li><li class="listitem">
  2851. Comment string: <code class="literal">RPC</code>
  2852. </li></ul></div></li><li class="listitem"><p class="simpara">
  2853. wchar support
  2854. </p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: circle; "><li class="listitem">
  2855. Dependency symbol: <code class="literal">BR2_USE_WCHAR</code>
  2856. </li><li class="listitem">
  2857. Comment string: <code class="literal">wchar</code>
  2858. </li></ul></div></li><li class="listitem"><p class="simpara">
  2859. dynamic library
  2860. </p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: circle; "><li class="listitem">
  2861. Dependency symbol: <code class="literal">!BR2_STATIC_LIBS</code>
  2862. </li><li class="listitem">
  2863. Comment string: <code class="literal">dynamic library</code>
  2864. </li></ul></div></li></ul></div></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a id="_dependencies_on_a_linux_kernel_built_by_buildroot"></a>18.2.5. Dependencies on a Linux kernel built by buildroot</h3></div></div></div><p>Some packages need a Linux kernel to be built by buildroot. These are
  2865. typically kernel modules or firmware. A comment should be added in the
  2866. Config.in file to express this dependency, similar to dependencies on
  2867. toolchain options. The general format is:</p><pre class="screen">foo needs a Linux kernel to be built</pre><p>If there is a dependency on both toolchain options and the Linux
  2868. kernel, use this format:</p><pre class="screen">foo needs a toolchain w/ featA, featB, featC and a Linux kernel to be built</pre></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a id="_dependencies_on_udev_dev_management"></a>18.2.6. Dependencies on udev /dev management</h3></div></div></div><p>If a package needs udev /dev management, it should depend on symbol
  2869. <code class="literal">BR2_PACKAGE_HAS_UDEV</code>, and the following comment should be added:</p><pre class="screen">foo needs udev /dev management</pre><p>If there is a dependency on both toolchain options and udev /dev
  2870. management, use this format:</p><pre class="screen">foo needs udev /dev management and a toolchain w/ featA, featB, featC</pre></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a id="_dependencies_on_features_provided_by_virtual_packages"></a>18.2.7. Dependencies on features provided by virtual packages</h3></div></div></div><p>Some features can be provided by more than one package, such as the
  2871. openGL libraries.</p><p>See <a class="xref" href="#virtual-package-tutorial">Section 18.12, “Infrastructure for virtual packages”</a> for more on the virtual packages.</p></div></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="_the_literal_mk_literal_file"></a>18.3. The <code class="literal">.mk</code> file</h2></div></div></div><p><a id="adding-packages-mk"></a>Finally, here’s the hardest part. Create a file named <code class="literal">libfoo.mk</code>. It
  2872. describes how the package should be downloaded, configured, built,
  2873. installed, etc.</p><p>Depending on the package type, the <code class="literal">.mk</code> file must be written in a
  2874. different way, using different infrastructures:</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
  2875. <span class="strong"><strong>Makefiles for generic packages</strong></span> (not using autotools or CMake):
  2876. These are based on an infrastructure similar to the one used for
  2877. autotools-based packages, but require a little more work from the
  2878. developer. They specify what should be done for the configuration,
  2879. compilation and installation of the package. This
  2880. infrastructure must be used for all packages that do not use the
  2881. autotools as their build system. In the future, other specialized
  2882. infrastructures might be written for other build systems. We cover
  2883. them through in a <a class="link" href="#generic-package-tutorial" title="18.6.1. generic-package tutorial">tutorial</a> and a
  2884. <a class="link" href="#generic-package-reference" title="18.6.2. generic-package reference">reference</a>.
  2885. </li><li class="listitem">
  2886. <span class="strong"><strong>Makefiles for autotools-based software</strong></span> (autoconf, automake, etc.):
  2887. We provide a dedicated infrastructure for such packages, since
  2888. autotools is a very common build system. This infrastructure <span class="emphasis"><em>must</em></span>
  2889. be used for new packages that rely on the autotools as their build
  2890. system. We cover them through a <a class="link" href="#autotools-package-tutorial" title="18.7.1. autotools-package tutorial">tutorial</a>
  2891. and <a class="link" href="#autotools-package-reference" title="18.7.2. autotools-package reference">reference</a>.
  2892. </li><li class="listitem">
  2893. <span class="strong"><strong>Makefiles for cmake-based software</strong></span>: We provide a dedicated
  2894. infrastructure for such packages, as CMake is a more and more
  2895. commonly used build system and has a standardized behaviour. This
  2896. infrastructure <span class="emphasis"><em>must</em></span> be used for new packages that rely on
  2897. CMake. We cover them through a <a class="link" href="#cmake-package-tutorial" title="18.8.1. cmake-package tutorial">tutorial</a>
  2898. and <a class="link" href="#cmake-package-reference" title="18.8.2. cmake-package reference">reference</a>.
  2899. </li><li class="listitem">
  2900. <span class="strong"><strong>Makefiles for Python modules</strong></span>: We have a dedicated infrastructure
  2901. for Python modules that use the <code class="literal">flit</code>, <code class="literal">pep517</code>, <code class="literal">setuptools</code>,
  2902. <code class="literal">setuptools-rust</code> or <code class="literal">maturin</code> mechanisms. We cover them through a
  2903. <a class="link" href="#python-package-tutorial" title="18.9.1. python-package tutorial">tutorial</a> and a
  2904. <a class="link" href="#python-package-reference" title="18.9.2. python-package reference">reference</a>.
  2905. </li><li class="listitem">
  2906. <span class="strong"><strong>Makefiles for Lua modules</strong></span>: We have a dedicated infrastructure for
  2907. Lua modules available through the LuaRocks web site. We cover them
  2908. through a <a class="link" href="#luarocks-package-tutorial" title="18.10.1. luarocks-package tutorial">tutorial</a> and a
  2909. <a class="link" href="#luarocks-package-reference" title="18.10.2. luarocks-package reference">reference</a>.
  2910. </li></ul></div><p>Further formatting details: see <a class="link" href="#writing-rules-mk" title="16.2. The .mk file">the writing
  2911. rules</a>.</p></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="adding-packages-hash"></a>18.4. The <code class="literal">.hash</code> file</h2></div></div></div><p>When possible, you must add a third file, named <code class="literal">libfoo.hash</code>, that
  2912. contains the hashes of the downloaded files for the <code class="literal">libfoo</code>
  2913. package. The only reason for not adding a <code class="literal">.hash</code> file is when hash
  2914. checking is not possible due to how the package is downloaded.</p><p>When a package has a version selection choice, then the hash file may be
  2915. stored in a subdirectory named after the version, e.g.
  2916. <code class="literal">package/libfoo/1.2.3/libfoo.hash</code>. This is especially important if the
  2917. different versions have different licensing terms, but they are stored
  2918. in the same file. Otherwise, the hash file should stay in the package’s
  2919. directory.</p><p>The hashes stored in that file are used to validate the integrity of the
  2920. downloaded files and of the license files.</p><p>The format of this file is one line for each file for which to check the
  2921. hash, each line with the following three fields separated by two spaces:</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p class="simpara">
  2922. the type of hash, one of:
  2923. </p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: circle; "><li class="listitem">
  2924. <code class="literal">md5</code>, <code class="literal">sha1</code>, <code class="literal">sha224</code>, <code class="literal">sha256</code>, <code class="literal">sha384</code>, <code class="literal">sha512</code>
  2925. </li></ul></div></li><li class="listitem"><p class="simpara">
  2926. the hash of the file:
  2927. </p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: circle; "><li class="listitem">
  2928. for <code class="literal">md5</code>, 32 hexadecimal characters
  2929. </li><li class="listitem">
  2930. for <code class="literal">sha1</code>, 40 hexadecimal characters
  2931. </li><li class="listitem">
  2932. for <code class="literal">sha224</code>, 56 hexadecimal characters
  2933. </li><li class="listitem">
  2934. for <code class="literal">sha256</code>, 64 hexadecimal characters
  2935. </li><li class="listitem">
  2936. for <code class="literal">sha384</code>, 96 hexadecimal characters
  2937. </li><li class="listitem">
  2938. for <code class="literal">sha512</code>, 128 hexadecimal characters
  2939. </li></ul></div></li><li class="listitem"><p class="simpara">
  2940. the name of the file:
  2941. </p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: circle; "><li class="listitem">
  2942. for a source archive: the basename of the file, without any directory
  2943. component,
  2944. </li><li class="listitem">
  2945. for a license file: the path as it appears in <code class="literal">FOO_LICENSE_FILES</code>.
  2946. </li></ul></div></li></ul></div><p>Lines starting with a <code class="literal">#</code> sign are considered comments, and ignored. Empty
  2947. lines are ignored.</p><p>There can be more than one hash for a single file, each on its own line. In
  2948. this case, all hashes must match.</p><p><strong>Note. </strong>Ideally, the hashes stored in this file should match the hashes published by
  2949. upstream, e.g. on their website, in the e-mail announcement… If upstream
  2950. provides more than one type of hash (e.g. <code class="literal">sha1</code> and <code class="literal">sha512</code>), then it is
  2951. best to add all those hashes in the <code class="literal">.hash</code> file. If upstream does not
  2952. provide any hash, or only provides an <code class="literal">md5</code> hash, then compute at least one
  2953. strong hash yourself (preferably <code class="literal">sha256</code>, but not <code class="literal">md5</code>), and mention
  2954. this in a comment line above the hashes.</p><p><strong>Note. </strong>The hashes for license files are used to detect a license change when a
  2955. package version is bumped. The hashes are checked during the make legal-info
  2956. target run. For a package with multiple versions (like Qt5),
  2957. create the hash file in a subdirectory <code class="literal">&lt;packageversion&gt;</code> of that package
  2958. (see also <a class="xref" href="#patch-apply-order" title="19.2. How patches are applied">Section 19.2, “How patches are applied”</a>).</p><p>The example below defines a <code class="literal">sha1</code> and a <code class="literal">sha256</code> published by upstream for
  2959. the main <code class="literal">libfoo-1.2.3.tar.bz2</code> tarball, an <code class="literal">md5</code> from upstream and a
  2960. locally-computed <code class="literal">sha256</code> hashes for a binary blob, a <code class="literal">sha256</code> for a
  2961. downloaded patch, and an archive with no hash:</p><pre class="screen"># Hashes from: http://www.foosoftware.org/download/libfoo-1.2.3.tar.bz2.{sha1,sha256}:
  2962. sha1 486fb55c3efa71148fe07895fd713ea3a5ae343a libfoo-1.2.3.tar.bz2
  2963. sha256 efc8103cc3bcb06bda6a781532d12701eb081ad83e8f90004b39ab81b65d4369 libfoo-1.2.3.tar.bz2
  2964. # md5 from: http://www.foosoftware.org/download/libfoo-1.2.3.tar.bz2.md5, sha256 locally computed:
  2965. md5 2d608f3c318c6b7557d551a5a09314f03452f1a1 libfoo-data.bin
  2966. sha256 01ba4719c80b6fe911b091a7c05124b64eeece964e09c058ef8f9805daca546b libfoo-data.bin
  2967. # Locally computed:
  2968. sha256 ff52101fb90bbfc3fe9475e425688c660f46216d7e751c4bbdb1dc85cdccacb9 libfoo-fix-blabla.patch
  2969. # Hash for license files:
  2970. sha256 a45a845012742796534f7e91fe623262ccfb99460a2bd04015bd28d66fba95b8 COPYING
  2971. sha256 01b1f9f2c8ee648a7a596a1abe8aa4ed7899b1c9e5551bda06da6e422b04aa55 doc/COPYING.LGPL</pre><p>If the <code class="literal">.hash</code> file is present, and it contains one or more hashes for a
  2972. downloaded file, the hash(es) computed by Buildroot (after download) must
  2973. match the hash(es) stored in the <code class="literal">.hash</code> file. If one or more hashes do
  2974. not match, Buildroot considers this an error, deletes the downloaded file,
  2975. and aborts.</p><p>If the <code class="literal">.hash</code> file is present, but it does not contain a hash for a
  2976. downloaded file, Buildroot considers this an error and aborts. However,
  2977. the downloaded file is left in the download directory since this
  2978. typically indicates that the <code class="literal">.hash</code> file is wrong but the downloaded
  2979. file is probably OK.</p><p>Hashes are currently checked for files fetched from http/ftp servers,
  2980. Git or subversion repositories, files copied using scp and local files.
  2981. Hashes are not checked for other version control systems (such as CVS,
  2982. mercurial) because Buildroot currently does not generate reproducible
  2983. tarballs when source code is fetched from such version control
  2984. systems.</p><p>Additionally, for packages for which it is possible to specify a custom
  2985. version (e.g. a custom version string, a remote tarball URL, or a VCS
  2986. repository location and changeset), Buildroot can’t carry hashes for
  2987. those. It is however possible to <a class="link" href="#customize-hashes" title="9.8.2. Providing extra hashes">provide a list of
  2988. extra hashes</a> that can cover such cases.</p><p>Hashes should only be added in <code class="literal">.hash</code> files for files that are
  2989. guaranteed to be stable. For example, patches auto-generated by Github
  2990. are not guaranteed to be stable, and therefore their hashes can change
  2991. over time. Such patches should not be downloaded, and instead be added
  2992. locally to the package folder.</p><p>If the <code class="literal">.hash</code> file is missing, then no check is done at all.</p></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="adding-packages-start-script"></a>18.5. The <code class="literal">SNNfoo</code> start script</h2></div></div></div><p>Packages that provide a system daemon usually need to be started somehow
  2993. at boot. Buildroot comes with support for several init systems, some
  2994. are considered tier one (see <a class="xref" href="#init-system" title="6.3. init system">Section 6.3, “init system”</a>), while others are also
  2995. available but do not have the same level of integration. Ideally, all
  2996. packages providing a system daemon should provide a start script for
  2997. BusyBox/SysV init and a systemd unit file.</p><p>For consistency, the start script must follow the style and composition
  2998. as shown in the reference: <code class="literal">package/busybox/S01syslogd</code>. An annotated
  2999. example of this style is shown below. There is no specific coding style
  3000. for systemd unit files, but if a package comes with its own unit file,
  3001. that is preferred over a buildroot specific one, if it is compatible
  3002. with buildroot.</p><p>The name of the start script is composed of the <code class="literal">SNN</code> and the daemon
  3003. name. The <code class="literal">NN</code> is the start order number which needs to be carefully
  3004. chosen. For example, a program that requires networking to be up should
  3005. not start before <code class="literal">S40network</code>. The scripts are started in alphabetical
  3006. order, so <code class="literal">S01syslogd</code> starts before <code class="literal">S01watchdogd</code>, and <code class="literal">S02sysctl</code>
  3007. start thereafter.</p><pre class="screen">01: #!/bin/sh
  3008. 02:
  3009. 03: DAEMON="syslogd"
  3010. 04: PIDFILE="/var/run/$DAEMON.pid"
  3011. 05:
  3012. 06: SYSLOGD_ARGS=""
  3013. 07:
  3014. 08: # shellcheck source=/dev/null
  3015. 09: [ -r "/etc/default/$DAEMON" ] &amp;&amp; . "/etc/default/$DAEMON"
  3016. 10:
  3017. 11: # BusyBox' syslogd does not create a pidfile, so pass "-n" in the command line
  3018. 12: # and use "-m" to instruct start-stop-daemon to create one.
  3019. 13: start() {
  3020. 14: printf 'Starting %s: ' "$DAEMON"
  3021. 15: # shellcheck disable=SC2086 # we need the word splitting
  3022. 16: start-stop-daemon -b -m -S -q -p "$PIDFILE" -x "/sbin/$DAEMON" \
  3023. 17: -- -n $SYSLOGD_ARGS
  3024. 18: status=$?
  3025. 19: if [ "$status" -eq 0 ]; then
  3026. 20: echo "OK"
  3027. 21: else
  3028. 22: echo "FAIL"
  3029. 23: fi
  3030. 24: return "$status"
  3031. 25: }
  3032. 26:
  3033. 27: stop() {
  3034. 28: printf 'Stopping %s: ' "$DAEMON"
  3035. 29: start-stop-daemon -K -q -p "$PIDFILE"
  3036. 30: status=$?
  3037. 31: if [ "$status" -eq 0 ]; then
  3038. 32: rm -f "$PIDFILE"
  3039. 33: echo "OK"
  3040. 34: else
  3041. 35: echo "FAIL"
  3042. 36: fi
  3043. 37: return "$status"
  3044. 38: }
  3045. 39:
  3046. 40: restart() {
  3047. 41: stop
  3048. 42: sleep 1
  3049. 43: start
  3050. 44: }
  3051. 45:
  3052. 46: case "$1" in
  3053. 47: start|stop|restart)
  3054. 48: "$1";;
  3055. 49: reload)
  3056. 50: # Restart, since there is no true "reload" feature.
  3057. 51: restart;;
  3058. 52: *)
  3059. 53: echo "Usage: $0 {start|stop|restart|reload}"
  3060. 54: exit 1
  3061. 55: esac</pre><p><span class="strong"><strong>Note:</strong></span> programs that support reloading their configuration in some
  3062. fashion (<code class="literal">SIGHUP</code>) should provide a <code class="literal">reload()</code> function similar to
  3063. <code class="literal">stop()</code>. The <code class="literal">start-stop-daemon</code> supports <code class="literal">-K -s HUP</code> for this.
  3064. It is recommended to always append <code class="literal">-x "/sbin/$DAEMON"</code> to all the
  3065. <code class="literal">start-stop-daemon</code> commands to ensure signals are set to a PID that
  3066. matches <code class="literal">$DAEMON</code>.</p><p>Both start scripts and unit files can source command line arguments from
  3067. <code class="literal">/etc/default/foo</code>, in general, if such a file does not exist it should
  3068. not block the start of the daemon, unless there is some site specirfic
  3069. command line argument the daemon requires to start. For start scripts a
  3070. <code class="literal">FOO_ARGS="-s -o -m -e -args"</code> can be defined to a default value in and
  3071. the user can override this from <code class="literal">/etc/default/foo</code>.</p></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="_infrastructure_for_packages_with_specific_build_systems"></a>18.6. Infrastructure for packages with specific build systems</h2></div></div></div><p>By <span class="emphasis"><em>packages with specific build systems</em></span> we mean all the packages
  3072. whose build system is not one of the standard ones, such as
  3073. <span class="emphasis"><em>autotools</em></span> or <span class="emphasis"><em>CMake</em></span>. This typically includes packages whose build
  3074. system is based on hand-written Makefiles or shell scripts.</p><div class="section"><div class="titlepage"><div><div><h3 class="title"><a id="generic-package-tutorial"></a>18.6.1. <code class="literal">generic-package</code> tutorial</h3></div></div></div><pre class="screen">01: ################################################################################
  3075. 02: #
  3076. 03: # libfoo
  3077. 04: #
  3078. 05: ################################################################################
  3079. 06:
  3080. 07: LIBFOO_VERSION = 1.0
  3081. 08: LIBFOO_SOURCE = libfoo-$(LIBFOO_VERSION).tar.gz
  3082. 09: LIBFOO_SITE = http://www.foosoftware.org/download
  3083. 10: LIBFOO_LICENSE = GPL-3.0+
  3084. 11: LIBFOO_LICENSE_FILES = COPYING
  3085. 12: LIBFOO_INSTALL_STAGING = YES
  3086. 13: LIBFOO_CONFIG_SCRIPTS = libfoo-config
  3087. 14: LIBFOO_DEPENDENCIES = host-libaaa libbbb
  3088. 15:
  3089. 16: define LIBFOO_BUILD_CMDS
  3090. 17: $(MAKE) $(TARGET_CONFIGURE_OPTS) -C $(@D) all
  3091. 18: endef
  3092. 19:
  3093. 20: define LIBFOO_INSTALL_STAGING_CMDS
  3094. 21: $(INSTALL) -D -m 0755 $(@D)/libfoo.a $(STAGING_DIR)/usr/lib/libfoo.a
  3095. 22: $(INSTALL) -D -m 0644 $(@D)/foo.h $(STAGING_DIR)/usr/include/foo.h
  3096. 23: $(INSTALL) -D -m 0755 $(@D)/libfoo.so* $(STAGING_DIR)/usr/lib
  3097. 24: endef
  3098. 25:
  3099. 26: define LIBFOO_INSTALL_TARGET_CMDS
  3100. 27: $(INSTALL) -D -m 0755 $(@D)/libfoo.so* $(TARGET_DIR)/usr/lib
  3101. 28: $(INSTALL) -d -m 0755 $(TARGET_DIR)/etc/foo.d
  3102. 29: endef
  3103. 30:
  3104. 31: define LIBFOO_USERS
  3105. 32: foo -1 libfoo -1 * - - - LibFoo daemon
  3106. 33: endef
  3107. 34:
  3108. 35: define LIBFOO_DEVICES
  3109. 36: /dev/foo c 666 0 0 42 0 - - -
  3110. 37: endef
  3111. 38:
  3112. 39: define LIBFOO_PERMISSIONS
  3113. 40: /bin/foo f 4755 foo libfoo - - - - -
  3114. 41: endef
  3115. 42:
  3116. 43: $(eval $(generic-package))</pre><p>The Makefile begins on line 7 to 11 with metadata information: the
  3117. version of the package (<code class="literal">LIBFOO_VERSION</code>), the name of the
  3118. tarball containing the package (<code class="literal">LIBFOO_SOURCE</code>) (xz-ed tarball recommended)
  3119. the Internet location at which the tarball can be downloaded from
  3120. (<code class="literal">LIBFOO_SITE</code>), the license (<code class="literal">LIBFOO_LICENSE</code>) and file with the
  3121. license text (<code class="literal">LIBFOO_LICENSE_FILES</code>). All variables must start with
  3122. the same prefix, <code class="literal">LIBFOO_</code> in this case. This prefix is always the
  3123. uppercased version of the package name (see below to understand where
  3124. the package name is defined).</p><p>On line 12, we specify that this package wants to install something to
  3125. the staging space. This is often needed for libraries, since they must
  3126. install header files and other development files in the staging space.
  3127. This will ensure that the commands listed in the
  3128. <code class="literal">LIBFOO_INSTALL_STAGING_CMDS</code> variable will be executed.</p><p>On line 13, we specify that there is some fixing to be done to some
  3129. of the <span class="emphasis"><em>libfoo-config</em></span> files that were installed during
  3130. <code class="literal">LIBFOO_INSTALL_STAGING_CMDS</code> phase.
  3131. These *-config files are executable shell script files that are
  3132. located in <span class="emphasis"><em>$(STAGING_DIR)/usr/bin</em></span> directory and are executed
  3133. by other 3rd party packages to find out the location and the linking
  3134. flags of this particular package.</p><p>The problem is that all these *-config files by default give wrong,
  3135. host system linking flags that are unsuitable for cross-compiling.</p><p>For example: <span class="emphasis"><em>-I/usr/include</em></span> instead of <span class="emphasis"><em>-I$(STAGING_DIR)/usr/include</em></span>
  3136. or: <span class="emphasis"><em>-L/usr/lib</em></span> instead of <span class="emphasis"><em>-L$(STAGING_DIR)/usr/lib</em></span></p><p>So some sed magic is done to these scripts to make them give correct
  3137. flags.
  3138. The argument to be given to <code class="literal">LIBFOO_CONFIG_SCRIPTS</code> is the file name(s)
  3139. of the shell script(s) needing fixing. All these names are relative to
  3140. <span class="emphasis"><em>$(STAGING_DIR)/usr/bin</em></span> and if needed multiple names can be given.</p><p>In addition, the scripts listed in <code class="literal">LIBFOO_CONFIG_SCRIPTS</code> are removed
  3141. from <code class="literal">$(TARGET_DIR)/usr/bin</code>, since they are not needed on the target.</p><div class="example"><a id="idm3373"></a><p class="title"><strong>Example 18.1. Config script: <span class="emphasis"><em>divine</em></span> package</strong></p><div class="example-contents"><p>Package divine installs shell script <span class="emphasis"><em>$(STAGING_DIR)/usr/bin/divine-config</em></span>.</p><p>So its fixup would be:</p><pre class="screen">DIVINE_CONFIG_SCRIPTS = divine-config</pre></div></div><br class="example-break" /><div class="example"><a id="idm3380"></a><p class="title"><strong>Example 18.2. Config script: <span class="emphasis"><em>imagemagick</em></span> package:</strong></p><div class="example-contents"><p>Package imagemagick installs the following scripts:
  3142. <span class="emphasis"><em>$(STAGING_DIR)/usr/bin/{Magick,Magick++,MagickCore,MagickWand,Wand}-config</em></span></p><p>So it’s fixup would be:</p><pre class="screen">IMAGEMAGICK_CONFIG_SCRIPTS = \
  3143. Magick-config Magick++-config \
  3144. MagickCore-config MagickWand-config Wand-config</pre></div></div><br class="example-break" /><p>On line 14, we specify the list of dependencies this package relies
  3145. on. These dependencies are listed in terms of lower-case package names,
  3146. which can be packages for the target (without the <code class="literal">host-</code>
  3147. prefix) or packages for the host (with the <code class="literal">host-</code>) prefix).
  3148. Buildroot will ensure that all these packages are built and installed
  3149. <span class="emphasis"><em>before</em></span> the current package starts its configuration.</p><p>The rest of the Makefile, lines 16..29, defines what should be done
  3150. at the different steps of the package configuration, compilation and
  3151. installation.
  3152. <code class="literal">LIBFOO_BUILD_CMDS</code> tells what steps should be performed to
  3153. build the package. <code class="literal">LIBFOO_INSTALL_STAGING_CMDS</code> tells what
  3154. steps should be performed to install the package in the staging space.
  3155. <code class="literal">LIBFOO_INSTALL_TARGET_CMDS</code> tells what steps should be
  3156. performed to install the package in the target space.</p><p>All these steps rely on the <code class="literal">$(@D)</code> variable, which
  3157. contains the directory where the source code of the package has been
  3158. extracted.</p><p>On lines 31..33, we define a user that is used by this package (e.g.
  3159. to run a daemon as non-root) (<code class="literal">LIBFOO_USERS</code>).</p><p>On line 35..37, we define a device-node file used by this package
  3160. (<code class="literal">LIBFOO_DEVICES</code>).</p><p>On line 39..41, we define the permissions to set to specific files
  3161. installed by this package (<code class="literal">LIBFOO_PERMISSIONS</code>).</p><p>Finally, on line 43, we call the <code class="literal">generic-package</code> function, which
  3162. generates, according to the variables defined previously, all the
  3163. Makefile code necessary to make your package working.</p></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a id="generic-package-reference"></a>18.6.2. <code class="literal">generic-package</code> reference</h3></div></div></div><p>There are two variants of the generic target. The <code class="literal">generic-package</code> macro is
  3164. used for packages to be cross-compiled for the target. The
  3165. <code class="literal">host-generic-package</code> macro is used for host packages, natively compiled
  3166. for the host. It is possible to call both of them in a single <code class="literal">.mk</code>
  3167. file: once to create the rules to generate a target
  3168. package and once to create the rules to generate a host package:</p><pre class="screen">$(eval $(generic-package))
  3169. $(eval $(host-generic-package))</pre><p>This might be useful if the compilation of the target package requires
  3170. some tools to be installed on the host. If the package name is
  3171. <code class="literal">libfoo</code>, then the name of the package for the target is also
  3172. <code class="literal">libfoo</code>, while the name of the package for the host is
  3173. <code class="literal">host-libfoo</code>. These names should be used in the DEPENDENCIES
  3174. variables of other packages, if they depend on <code class="literal">libfoo</code> or
  3175. <code class="literal">host-libfoo</code>.</p><p>The call to the <code class="literal">generic-package</code> and/or <code class="literal">host-generic-package</code> macro
  3176. <span class="strong"><strong>must</strong></span> be at the end of the <code class="literal">.mk</code> file, after all variable definitions.
  3177. The call to <code class="literal">host-generic-package</code> <span class="strong"><strong>must</strong></span> be after the call to
  3178. <code class="literal">generic-package</code>, if any.</p><p>For the target package, the <code class="literal">generic-package</code> uses the variables defined by
  3179. the .mk file and prefixed by the uppercased package name:
  3180. <code class="literal">LIBFOO_*</code>. <code class="literal">host-generic-package</code> uses the <code class="literal">HOST_LIBFOO_*</code> variables. For
  3181. <span class="emphasis"><em>some</em></span> variables, if the <code class="literal">HOST_LIBFOO_</code> prefixed variable doesn’t
  3182. exist, the package infrastructure uses the corresponding variable
  3183. prefixed by <code class="literal">LIBFOO_</code>. This is done for variables that are likely to
  3184. have the same value for both the target and host packages. See below
  3185. for details.</p><p>The list of variables that can be set in a <code class="literal">.mk</code> file to give metadata
  3186. information is (assuming the package name is <code class="literal">libfoo</code>) :</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p class="simpara">
  3187. <code class="literal">LIBFOO_VERSION</code>, mandatory, must contain the version of the
  3188. package. Note that if <code class="literal">HOST_LIBFOO_VERSION</code> doesn’t exist, it is
  3189. assumed to be the same as <code class="literal">LIBFOO_VERSION</code>. It can also be a
  3190. revision number or a tag for packages that are fetched directly
  3191. from their version control system. Examples:
  3192. </p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: circle; "><li class="listitem">
  3193. a version for a release tarball: <code class="literal">LIBFOO_VERSION = 0.1.2</code>
  3194. </li><li class="listitem">
  3195. a sha1 for a git tree: <code class="literal">LIBFOO_VERSION = cb9d6aa9429e838f0e54faa3d455bcbab5eef057</code>
  3196. </li><li class="listitem"><p class="simpara">
  3197. a tag for a git tree <code class="literal">LIBFOO_VERSION = v0.1.2</code>
  3198. </p><p><strong>Note: </strong>Using a branch name as <code class="literal">FOO_VERSION</code> is not supported, because it does
  3199. not and can not work as people would expect it should:</p><div class="orderedlist"><ol class="orderedlist" type="1"><li class="listitem">
  3200. due to local caching, Buildroot will not re-fetch the repository,
  3201. so people who expect to be able to follow the remote repository
  3202. would be quite surprised and disappointed;
  3203. </li><li class="listitem">
  3204. because two builds can never be perfectly simultaneous, and because
  3205. the remote repository may get new commits on the branch anytime,
  3206. two users, using the same Buildroot tree and building the same
  3207. configuration, may get different source, thus rendering the build
  3208. non reproducible, and people would be quite surprised and
  3209. disappointed.
  3210. </li></ol></div></li></ul></div></li><li class="listitem">
  3211. <code class="literal">LIBFOO_SOURCE</code> may contain the name of the tarball of the package,
  3212. which Buildroot will use to download the tarball from
  3213. <code class="literal">LIBFOO_SITE</code>. If <code class="literal">HOST_LIBFOO_SOURCE</code> is not specified, it defaults
  3214. to <code class="literal">LIBFOO_SOURCE</code>. If none are specified, then the value is assumed
  3215. to be <code class="literal">libfoo-$(LIBFOO_VERSION).tar.gz</code>.
  3216. Example: <code class="literal">LIBFOO_SOURCE = foobar-$(LIBFOO_VERSION).tar.bz2</code>
  3217. </li><li class="listitem">
  3218. <code class="literal">LIBFOO_PATCH</code> may contain a space-separated list of patch file
  3219. names, that Buildroot will download and apply to the package source
  3220. code. If an entry contains <code class="literal">://</code>, then Buildroot will assume it is a
  3221. full URL and download the patch from this location. Otherwise,
  3222. Buildroot will assume that the patch should be downloaded from
  3223. <code class="literal">LIBFOO_SITE</code>. If <code class="literal">HOST_LIBFOO_PATCH</code> is not specified, it defaults
  3224. to <code class="literal">LIBFOO_PATCH</code>. Note that patches that are included in Buildroot
  3225. itself use a different mechanism: all files of the form
  3226. <code class="literal">*.patch</code> present in the package directory inside
  3227. Buildroot will be applied to the package after extraction (see
  3228. <a class="link" href="#patch-policy" title="Chapter 19. Patching a package">patching a package</a>). Finally, patches listed in
  3229. the <code class="literal">LIBFOO_PATCH</code> variable are applied <span class="emphasis"><em>before</em></span> the patches stored
  3230. in the Buildroot package directory.
  3231. </li><li class="listitem">
  3232. <code class="literal">LIBFOO_SITE</code> provides the location of the package, which can be a
  3233. URL or a local filesystem path. HTTP, FTP and SCP are supported URL
  3234. types for retrieving package tarballs. In these cases don’t include a
  3235. trailing slash: it will be added by Buildroot between the directory
  3236. and the filename as appropriate. Git, Subversion, Mercurial,
  3237. and Bazaar are supported URL types for retrieving packages directly
  3238. from source code management systems. There is a helper function to make
  3239. it easier to download source tarballs from GitHub (refer to
  3240. <a class="xref" href="#github-download-url" title="18.25.4. How to add a package from GitHub">Section 18.25.4, “How to add a package from GitHub”</a> for details). A filesystem path may be used
  3241. to specify either a tarball or a directory containing the package
  3242. source code. See <code class="literal">LIBFOO_SITE_METHOD</code> below for more details on how
  3243. retrieval works.
  3244. Note that SCP URLs should be of the form
  3245. <code class="literal">scp://[user@]host:filepath</code>, and that filepath is relative to the
  3246. user’s home directory, so you may want to prepend the path with a
  3247. slash for absolute paths:
  3248. <code class="literal">scp://[user@]host:/absolutepath</code>. The same goes for SFTP URLs.
  3249. If <code class="literal">HOST_LIBFOO_SITE</code> is not specified, it defaults to
  3250. <code class="literal">LIBFOO_SITE</code>.
  3251. Examples:
  3252. <code class="literal">LIBFOO_SITE=http://www.libfoosoftware.org/libfoo</code>
  3253. <code class="literal">LIBFOO_SITE=http://svn.xiph.org/trunk/Tremor</code>
  3254. <code class="literal">LIBFOO_SITE=/opt/software/libfoo.tar.gz</code>
  3255. <code class="literal">LIBFOO_SITE=$(TOPDIR)/../src/libfoo</code>
  3256. </li><li class="listitem">
  3257. <code class="literal">LIBFOO_DL_OPTS</code> is a space-separated list of additional options to
  3258. pass to the downloader. Useful for retrieving documents with
  3259. server-side checking for user logins and passwords, or to use a proxy.
  3260. All download methods valid for <code class="literal">LIBFOO_SITE_METHOD</code> are supported;
  3261. valid options depend on the download method (consult the man page
  3262. for the respective download utilities).
  3263. </li><li class="listitem">
  3264. <code class="literal">LIBFOO_EXTRA_DOWNLOADS</code> is a space-separated list of additional
  3265. files that Buildroot should download. If an entry contains <code class="literal">://</code>
  3266. then Buildroot will assume it is a complete URL and will download
  3267. the file using this URL. Otherwise, Buildroot will assume the file
  3268. to be downloaded is located at <code class="literal">LIBFOO_SITE</code>. Buildroot will not do
  3269. anything with those additional files, except download them: it will
  3270. be up to the package recipe to use them from <code class="literal">$(LIBFOO_DL_DIR)</code>.
  3271. </li><li class="listitem"><p class="simpara">
  3272. <code class="literal">LIBFOO_SITE_METHOD</code> determines the method used to fetch or copy the
  3273. package source code. In many cases, Buildroot guesses the method
  3274. from the contents of <code class="literal">LIBFOO_SITE</code> and setting <code class="literal">LIBFOO_SITE_METHOD</code>
  3275. is unnecessary. When <code class="literal">HOST_LIBFOO_SITE_METHOD</code> is not specified, it
  3276. defaults to the value of <code class="literal">LIBFOO_SITE_METHOD</code>.
  3277. The possible values of <code class="literal">LIBFOO_SITE_METHOD</code> are:
  3278. </p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: circle; "><li class="listitem">
  3279. <code class="literal">wget</code> for normal FTP/HTTP downloads of tarballs. Used by
  3280. default when <code class="literal">LIBFOO_SITE</code> begins with <code class="literal">http://</code>, <code class="literal">https://</code> or
  3281. <code class="literal">ftp://</code>.
  3282. </li><li class="listitem">
  3283. <code class="literal">scp</code> for downloads of tarballs over SSH with scp. Used by
  3284. default when <code class="literal">LIBFOO_SITE</code> begins with <code class="literal">scp://</code>.
  3285. </li><li class="listitem">
  3286. <code class="literal">sftp</code> for downloads of tarballs over SSH with sftp. Used by
  3287. default when <code class="literal">LIBFOO_SITE</code> begins with <code class="literal">sftp://</code>.
  3288. </li><li class="listitem">
  3289. <code class="literal">svn</code> for retrieving source code from a Subversion repository.
  3290. Used by default when <code class="literal">LIBFOO_SITE</code> begins with <code class="literal">svn://</code>. When a
  3291. <code class="literal">http://</code> Subversion repository URL is specified in
  3292. <code class="literal">LIBFOO_SITE</code>, one <span class="emphasis"><em>must</em></span> specify <code class="literal">LIBFOO_SITE_METHOD=svn</code>.
  3293. Buildroot performs a checkout which is preserved as a tarball in
  3294. the download cache; subsequent builds use the tarball instead of
  3295. performing another checkout.
  3296. </li><li class="listitem">
  3297. <code class="literal">cvs</code> for retrieving source code from a CVS repository.
  3298. Used by default when <code class="literal">LIBFOO_SITE</code> begins with <code class="literal">cvs://</code>.
  3299. The downloaded source code is cached as with the <code class="literal">svn</code> method.
  3300. Anonymous pserver mode is assumed otherwise explicitly defined
  3301. on <code class="literal">LIBFOO_SITE</code>. Both
  3302. <code class="literal">LIBFOO_SITE=cvs://libfoo.net:/cvsroot/libfoo</code> and
  3303. <code class="literal">LIBFOO_SITE=cvs://:ext:libfoo.net:/cvsroot/libfoo</code>
  3304. are accepted, on the former anonymous pserver access mode is
  3305. assumed.
  3306. <code class="literal">LIBFOO_SITE</code> <span class="emphasis"><em>must</em></span> contain the source URL as well as the remote
  3307. repository directory. The module is the package name.
  3308. <code class="literal">LIBFOO_VERSION</code> is <span class="emphasis"><em>mandatory</em></span> and <span class="emphasis"><em>must</em></span> be a tag, a branch, or
  3309. a date (e.g. "2014-10-20", "2014-10-20 13:45", "2014-10-20
  3310. 13:45+01" see "man cvs" for further details).
  3311. </li><li class="listitem">
  3312. <code class="literal">git</code> for retrieving source code from a Git repository. Used by
  3313. default when <code class="literal">LIBFOO_SITE</code> begins with <code class="literal">git://</code>. The downloaded
  3314. source code is cached as with the <code class="literal">svn</code> method.
  3315. </li><li class="listitem">
  3316. <code class="literal">hg</code> for retrieving source code from a Mercurial repository. One
  3317. <span class="emphasis"><em>must</em></span> specify <code class="literal">LIBFOO_SITE_METHOD=hg</code> when <code class="literal">LIBFOO_SITE</code>
  3318. contains a Mercurial repository URL. The downloaded source code
  3319. is cached as with the <code class="literal">svn</code> method.
  3320. </li><li class="listitem">
  3321. <code class="literal">bzr</code> for retrieving source code from a Bazaar repository. Used
  3322. by default when <code class="literal">LIBFOO_SITE</code> begins with <code class="literal">bzr://</code>. The
  3323. downloaded source code is cached as with the <code class="literal">svn</code> method.
  3324. </li><li class="listitem">
  3325. <code class="literal">file</code> for a local tarball. One should use this when
  3326. <code class="literal">LIBFOO_SITE</code> specifies a package tarball as a local filename.
  3327. Useful for software that isn’t available publicly or in version
  3328. control.
  3329. </li><li class="listitem">
  3330. <code class="literal">local</code> for a local source code directory. One should use this
  3331. when <code class="literal">LIBFOO_SITE</code> specifies a local directory path containing
  3332. the package source code. Buildroot copies the contents of the
  3333. source directory into the package’s build directory. Note that
  3334. for <code class="literal">local</code> packages, no patches are applied. If you need to
  3335. still patch the source code, use <code class="literal">LIBFOO_POST_RSYNC_HOOKS</code>, see
  3336. <a class="xref" href="#hooks-rsync" title="18.23.1. Using the POST_RSYNC hook">Section 18.23.1, “Using the <code class="literal">POST_RSYNC</code> hook”</a>.
  3337. </li></ul></div></li><li class="listitem">
  3338. <code class="literal">LIBFOO_GIT_SUBMODULES</code> can be set to <code class="literal">YES</code> to create an archive
  3339. with the git submodules in the repository. This is only available
  3340. for packages downloaded with git (i.e. when
  3341. <code class="literal">LIBFOO_SITE_METHOD=git</code>). Note that we try not to use such git
  3342. submodules when they contain bundled libraries, in which case we
  3343. prefer to use those libraries from their own package.
  3344. </li><li class="listitem">
  3345. <code class="literal">LIBFOO_GIT_LFS</code> should be set to <code class="literal">YES</code> if the Git repository uses
  3346. Git LFS to store large files out of band. This is only available for
  3347. packages downloaded with git (i.e. when <code class="literal">LIBFOO_SITE_METHOD=git</code>).
  3348. </li><li class="listitem">
  3349. <code class="literal">LIBFOO_SVN_EXTERNALS</code> can be set to <code class="literal">YES</code> to create an archive with
  3350. the svn external references. This is only available for packages
  3351. downloaded with subversion.
  3352. </li><li class="listitem">
  3353. <code class="literal">LIBFOO_STRIP_COMPONENTS</code> is the number of leading components
  3354. (directories) that tar must strip from file names on extraction.
  3355. The tarball for most packages has one leading component named
  3356. "&lt;pkg-name&gt;-&lt;pkg-version&gt;", thus Buildroot passes
  3357. --strip-components=1 to tar to remove it.
  3358. For non-standard packages that don’t have this component, or
  3359. that have more than one leading component to strip, set this
  3360. variable with the value to be passed to tar. Default: 1.
  3361. </li><li class="listitem">
  3362. <code class="literal">LIBFOO_EXCLUDES</code> is a space-separated list of patterns to exclude
  3363. when extracting the archive. Each item from that list is passed as
  3364. a tar’s <code class="literal">--exclude</code> option. By default, empty.
  3365. </li><li class="listitem">
  3366. <code class="literal">LIBFOO_DEPENDENCIES</code> lists the dependencies (in terms of package
  3367. name) that are required for the current target package to
  3368. compile. These dependencies are guaranteed to be compiled and
  3369. installed before the configuration of the current package starts.
  3370. However, modifications to configuration of these dependencies will
  3371. not force a rebuild of the current package. In a similar way,
  3372. <code class="literal">HOST_LIBFOO_DEPENDENCIES</code> lists the dependencies for the current
  3373. host package.
  3374. </li><li class="listitem">
  3375. <code class="literal">LIBFOO_EXTRACT_DEPENDENCIES</code> lists the dependencies (in terms of
  3376. package name) that are required for the current target package to be
  3377. extracted. These dependencies are guaranteed to be compiled and
  3378. installed before the extract step of the current package
  3379. starts. This is only used internally by the package infrastructure,
  3380. and should typically not be used directly by packages.
  3381. </li><li class="listitem">
  3382. <code class="literal">LIBFOO_PATCH_DEPENDENCIES</code> lists the dependencies (in terms of
  3383. package name) that are required for the current package to be
  3384. patched. These dependencies are guaranteed to be extracted and
  3385. patched (but not necessarily built) before the current package is
  3386. patched. In a similar way, <code class="literal">HOST_LIBFOO_PATCH_DEPENDENCIES</code> lists
  3387. the dependencies for the current host package.
  3388. This is seldom used; usually, <code class="literal">LIBFOO_DEPENDENCIES</code> is what you
  3389. really want to use.
  3390. </li><li class="listitem">
  3391. <code class="literal">LIBFOO_PROVIDES</code> lists all the virtual packages <code class="literal">libfoo</code> is an
  3392. implementation of. See <a class="xref" href="#virtual-package-tutorial">Section 18.12, “Infrastructure for virtual packages”</a>.
  3393. </li><li class="listitem">
  3394. <code class="literal">LIBFOO_INSTALL_STAGING</code> can be set to <code class="literal">YES</code> or <code class="literal">NO</code> (default). If
  3395. set to <code class="literal">YES</code>, then the commands in the <code class="literal">LIBFOO_INSTALL_STAGING_CMDS</code>
  3396. variables are executed to install the package into the staging
  3397. directory.
  3398. </li><li class="listitem">
  3399. <code class="literal">LIBFOO_INSTALL_TARGET</code> can be set to <code class="literal">YES</code> (default) or <code class="literal">NO</code>. If
  3400. set to <code class="literal">YES</code>, then the commands in the <code class="literal">LIBFOO_INSTALL_TARGET_CMDS</code>
  3401. variables are executed to install the package into the target
  3402. directory.
  3403. </li><li class="listitem">
  3404. <code class="literal">LIBFOO_INSTALL_IMAGES</code> can be set to <code class="literal">YES</code> or <code class="literal">NO</code> (default). If
  3405. set to <code class="literal">YES</code>, then the commands in the <code class="literal">LIBFOO_INSTALL_IMAGES_CMDS</code>
  3406. variable are executed to install the package into the images
  3407. directory.
  3408. </li><li class="listitem">
  3409. <code class="literal">LIBFOO_CONFIG_SCRIPTS</code> lists the names of the files in
  3410. <span class="emphasis"><em>$(STAGING_DIR)/usr/bin</em></span> that need some special fixing to make them
  3411. cross-compiling friendly. Multiple file names separated by space can
  3412. be given and all are relative to <span class="emphasis"><em>$(STAGING_DIR)/usr/bin</em></span>. The files
  3413. listed in <code class="literal">LIBFOO_CONFIG_SCRIPTS</code> are also removed from
  3414. <code class="literal">$(TARGET_DIR)/usr/bin</code> since they are not needed on the target.
  3415. </li><li class="listitem">
  3416. <code class="literal">LIBFOO_DEVICES</code> lists the device files to be created by Buildroot
  3417. when using the static device table. The syntax to use is the
  3418. makedevs one. You can find some documentation for this syntax in the
  3419. <a class="xref" href="#makedev-syntax" title="Chapter 25. Makedev syntax documentation">Chapter 25, <em>Makedev syntax documentation</em></a>. This variable is optional.
  3420. </li><li class="listitem">
  3421. <code class="literal">LIBFOO_PERMISSIONS</code> lists the changes of permissions to be done at
  3422. the end of the build process. The syntax is once again the makedevs one.
  3423. You can find some documentation for this syntax in the <a class="xref" href="#makedev-syntax" title="Chapter 25. Makedev syntax documentation">Chapter 25, <em>Makedev syntax documentation</em></a>.
  3424. This variable is optional.
  3425. </li><li class="listitem">
  3426. <code class="literal">LIBFOO_USERS</code> lists the users to create for this package, if it installs
  3427. a program you want to run as a specific user (e.g. as a daemon, or as a
  3428. cron-job). The syntax is similar in spirit to the makedevs one, and is
  3429. described in the <a class="xref" href="#makeuser-syntax" title="Chapter 26. Makeusers syntax documentation">Chapter 26, <em>Makeusers syntax documentation</em></a>. This variable is optional.
  3430. </li><li class="listitem"><p class="simpara">
  3431. <code class="literal">LIBFOO_LICENSE</code> defines the license (or licenses) under which the package
  3432. is released.
  3433. This name will appear in the manifest file produced by <code class="literal">make legal-info</code>.
  3434. If the license appears in <a class="ulink" href="https://spdx.org/licenses/" target="_top">the SPDX License List</a>,
  3435. use the SPDX short identifier to make the manifest file uniform.
  3436. Otherwise, describe the license in a precise and concise way, avoiding
  3437. ambiguous names such as <code class="literal">BSD</code> which actually name a family of licenses.
  3438. This variable is optional. If it is not defined, <code class="literal">unknown</code> will appear in
  3439. the <code class="literal">license</code> field of the manifest file for this package.
  3440. The expected format for this variable must comply with the following rules:
  3441. </p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: circle; "><li class="listitem">
  3442. If different parts of the package are released under different
  3443. licenses, then <code class="literal">comma</code> separate licenses (e.g. <code class="literal"><code class="literal">LIBFOO_LICENSE =
  3444. GPL-2.0+, LGPL-2.1+</code></code>). If there is clear distinction between which
  3445. component is licensed under what license, then annotate the license
  3446. with that component, between parenthesis (e.g. <code class="literal"><code class="literal">LIBFOO_LICENSE =
  3447. GPL-2.0+ (programs), LGPL-2.1+ (libraries)</code></code>).
  3448. </li><li class="listitem">
  3449. If some licenses are conditioned on a sub-option being enabled, append
  3450. the conditional licenses with a comma (e.g.: <code class="literal">FOO_LICENSE += , GPL-2.0+
  3451. (programs)</code>); the infrastructure will internally remove the space before
  3452. the comma.
  3453. </li><li class="listitem">
  3454. If the package is dual licensed, then separate licenses with the
  3455. <code class="literal">or</code> keyword (e.g. <code class="literal"><code class="literal">LIBFOO_LICENSE = AFL-2.1 or GPL-2.0+</code></code>).
  3456. </li></ul></div></li><li class="listitem">
  3457. <code class="literal">LIBFOO_LICENSE_FILES</code> is a space-separated list of files in the package
  3458. tarball that contain the license(s) under which the package is released.
  3459. <code class="literal">make legal-info</code> copies all of these files in the <code class="literal">legal-info</code> directory.
  3460. See <a class="xref" href="#legal-info" title="Chapter 13. Legal notice and licensing">Chapter 13, <em>Legal notice and licensing</em></a> for more information.
  3461. This variable is optional. If it is not defined, a warning will be produced
  3462. to let you know, and <code class="literal">not saved</code> will appear in the <code class="literal">license files</code> field
  3463. of the manifest file for this package.
  3464. </li><li class="listitem">
  3465. <code class="literal">LIBFOO_ACTUAL_SOURCE_TARBALL</code> only applies to packages whose
  3466. <code class="literal">LIBFOO_SITE</code> / <code class="literal">LIBFOO_SOURCE</code> pair points to an archive that does
  3467. not actually contain source code, but binary code. This a very
  3468. uncommon case, only known to apply to external toolchains which come
  3469. already compiled, although theoretically it might apply to other
  3470. packages. In such cases a separate tarball is usually available with
  3471. the actual source code. Set <code class="literal">LIBFOO_ACTUAL_SOURCE_TARBALL</code> to the
  3472. name of the actual source code archive and Buildroot will download
  3473. it and use it when you run <code class="literal">make legal-info</code> to collect
  3474. legally-relevant material. Note this file will not be downloaded
  3475. during regular builds nor by <code class="literal">make source</code>.
  3476. </li><li class="listitem">
  3477. <code class="literal">LIBFOO_ACTUAL_SOURCE_SITE</code> provides the location of the actual
  3478. source tarball. The default value is <code class="literal">LIBFOO_SITE</code>, so you don’t
  3479. need to set this variable if the binary and source archives are
  3480. hosted on the same directory. If <code class="literal">LIBFOO_ACTUAL_SOURCE_TARBALL</code> is
  3481. not set, it doesn’t make sense to define
  3482. <code class="literal">LIBFOO_ACTUAL_SOURCE_SITE</code>.
  3483. </li><li class="listitem">
  3484. <code class="literal">LIBFOO_REDISTRIBUTE</code> can be set to <code class="literal">YES</code> (default) or <code class="literal">NO</code> to indicate if
  3485. the package source code is allowed to be redistributed. Set it to <code class="literal">NO</code> for
  3486. non-opensource packages: Buildroot will not save the source code for this
  3487. package when collecting the <code class="literal">legal-info</code>.
  3488. </li><li class="listitem">
  3489. <code class="literal">LIBFOO_FLAT_STACKSIZE</code> defines the stack size of an application built into
  3490. the FLAT binary format. The application stack size on the NOMMU architecture
  3491. processors can’t be enlarged at run time. The default stack size for the
  3492. FLAT binary format is only 4k bytes. If the application consumes more stack,
  3493. append the required number here.
  3494. </li><li class="listitem">
  3495. <code class="literal">LIBFOO_BIN_ARCH_EXCLUDE</code> is a space-separated list of paths (relative
  3496. to the target directory) to ignore when checking that the package
  3497. installs correctly cross-compiled binaries. You seldom need to set this
  3498. variable, unless the package installs binary blobs outside the default
  3499. locations, <code class="literal">/lib/firmware</code>, <code class="literal">/usr/lib/firmware</code>, <code class="literal">/lib/modules</code>,
  3500. <code class="literal">/usr/lib/modules</code>, and <code class="literal">/usr/share</code>, which are automatically excluded.
  3501. </li><li class="listitem"><p class="simpara">
  3502. <code class="literal">LIBFOO_IGNORE_CVES</code> is a space-separated list of CVEs that tells
  3503. Buildroot CVE tracking tools which CVEs should be ignored for this
  3504. package. This is typically used when the CVE is fixed by a patch in
  3505. the package, or when the CVE for some reason does not affect the
  3506. Buildroot package. A Makefile comment must always precede the
  3507. addition of a CVE to this variable. Example:
  3508. </p><pre class="screen"># 0001-fix-cve-2020-12345.patch
  3509. LIBFOO_IGNORE_CVES += CVE-2020-12345
  3510. # only when built with libbaz, which Buildroot doesn't support
  3511. LIBFOO_IGNORE_CVES += CVE-2020-54321</pre></li><li class="listitem"><p class="simpara">
  3512. <a id="cpe-id"></a> <code class="literal">LIBFOO_CPE_ID_*</code> variables is a set of variables that allows the
  3513. package to define its <a class="ulink" href="https://nvd.nist.gov/products/cpe" target="_top">CPE
  3514. identifier</a>. The available variables are:
  3515. </p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: circle; "><li class="listitem">
  3516. <code class="literal">LIBFOO_CPE_ID_VALID</code>, if set to <code class="literal">YES</code>, specifies that the default
  3517. values for each of the following variables is appropriate, and
  3518. generates a valid CPE ID.
  3519. </li><li class="listitem">
  3520. <code class="literal">LIBFOO_CPE_ID_PREFIX</code>, specifies the prefix of the CPE identifier,
  3521. i.e the first three fields. When not defined, the default value is
  3522. <code class="literal">cpe:2.3:a</code>.
  3523. </li><li class="listitem">
  3524. <code class="literal">LIBFOO_CPE_ID_VENDOR</code>, specifies the vendor part of the CPE
  3525. identifier. When not defined, the default value is
  3526. <code class="literal">&lt;pkgname&gt;_project</code>.
  3527. </li><li class="listitem">
  3528. <code class="literal">LIBFOO_CPE_ID_PRODUCT</code>, specifies the product part of the CPE
  3529. identifier. When not defined, the default value is <code class="literal">&lt;pkgname&gt;</code>.
  3530. </li><li class="listitem">
  3531. <code class="literal">LIBFOO_CPE_ID_VERSION</code>, specifies the version part of the CPE
  3532. identifier. When not defined the default value is
  3533. <code class="literal">$(LIBFOO_VERSION)</code>.
  3534. </li><li class="listitem">
  3535. <code class="literal">LIBFOO_CPE_ID_UPDATE</code> specifies the <span class="emphasis"><em>update</em></span> part of the CPE
  3536. identifier. When not defined the default value is <code class="literal">*</code>.
  3537. </li></ul></div><p class="simpara">If any of those variables is defined, then the generic package
  3538. infrastructure assumes the package provides valid CPE information. In
  3539. this case, the generic package infrastructure will define
  3540. <code class="literal">LIBFOO_CPE_ID</code>.</p><p class="simpara">For a host package, if its <code class="literal">LIBFOO_CPE_ID_*</code> variables are not
  3541. defined, it inherits the value of those variables from the
  3542. corresponding target package.</p></li></ul></div><p>The recommended way to define these variables is to use the following
  3543. syntax:</p><pre class="screen">LIBFOO_VERSION = 2.32</pre><p>Now, the variables that define what should be performed at the
  3544. different steps of the build process.</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
  3545. <code class="literal">LIBFOO_EXTRACT_CMDS</code> lists the actions to be performed to extract
  3546. the package. This is generally not needed as tarballs are
  3547. automatically handled by Buildroot. However, if the package uses a
  3548. non-standard archive format, such as a ZIP or RAR file, or has a
  3549. tarball with a non-standard organization, this variable allows to
  3550. override the package infrastructure default behavior.
  3551. </li><li class="listitem">
  3552. <code class="literal">LIBFOO_CONFIGURE_CMDS</code> lists the actions to be performed to
  3553. configure the package before its compilation.
  3554. </li><li class="listitem">
  3555. <code class="literal">LIBFOO_BUILD_CMDS</code> lists the actions to be performed to
  3556. compile the package.
  3557. </li><li class="listitem">
  3558. <code class="literal">HOST_LIBFOO_INSTALL_CMDS</code> lists the actions to be performed
  3559. to install the package, when the package is a host package. The
  3560. package must install its files to the directory given by
  3561. <code class="literal">$(HOST_DIR)</code>. All files, including development files such as
  3562. headers should be installed, since other packages might be compiled
  3563. on top of this package.
  3564. </li><li class="listitem">
  3565. <code class="literal">LIBFOO_INSTALL_TARGET_CMDS</code> lists the actions to be
  3566. performed to install the package to the target directory, when the
  3567. package is a target package. The package must install its files to
  3568. the directory given by <code class="literal">$(TARGET_DIR)</code>. Only the files required for
  3569. <span class="emphasis"><em>execution</em></span> of the package have to be
  3570. installed. Header files, static libraries and documentation will be
  3571. removed again when the target filesystem is finalized.
  3572. </li><li class="listitem">
  3573. <code class="literal">LIBFOO_INSTALL_STAGING_CMDS</code> lists the actions to be
  3574. performed to install the package to the staging directory, when the
  3575. package is a target package. The package must install its files to
  3576. the directory given by <code class="literal">$(STAGING_DIR)</code>. All development files
  3577. should be installed, since they might be needed to compile other
  3578. packages.
  3579. </li><li class="listitem">
  3580. <code class="literal">LIBFOO_INSTALL_IMAGES_CMDS</code> lists the actions to be performed to
  3581. install the package to the images directory, when the package is a
  3582. target package. The package must install its files to the directory
  3583. given by <code class="literal">$(BINARIES_DIR)</code>. Only files that are binary images (aka
  3584. images) that do not belong in the <code class="literal">TARGET_DIR</code> but are necessary
  3585. for booting the board should be placed here. For example, a package
  3586. should utilize this step if it has binaries which would be similar
  3587. to the kernel image, bootloader or root filesystem images.
  3588. </li><li class="listitem">
  3589. <code class="literal">LIBFOO_INSTALL_INIT_SYSV</code>, <code class="literal">LIBFOO_INSTALL_INIT_OPENRC</code> and
  3590. <code class="literal">LIBFOO_INSTALL_INIT_SYSTEMD</code> list the actions to install init
  3591. scripts either for the systemV-like init systems (busybox,
  3592. sysvinit, etc.), openrc or for the systemd units. These commands
  3593. will be run only when the relevant init system is installed (i.e.
  3594. if systemd is selected as the init system in the configuration,
  3595. only <code class="literal">LIBFOO_INSTALL_INIT_SYSTEMD</code> will be run). The only exception
  3596. is when openrc is chosen as init system and <code class="literal">LIBFOO_INSTALL_INIT_OPENRC</code>
  3597. has not been set, in such situation <code class="literal">LIBFOO_INSTALL_INIT_SYSV</code> will
  3598. be called, since openrc supports sysv init scripts.
  3599. When systemd is used as the init system, buildroot will automatically enable
  3600. all services using the <code class="literal">systemctl preset-all</code> command in the final phase of
  3601. image building. You can add preset files to prevent a particular unit from
  3602. being automatically enabled by buildroot.
  3603. </li><li class="listitem">
  3604. <code class="literal">LIBFOO_HELP_CMDS</code> lists the actions to print the package help, which
  3605. is included to the main <code class="literal">make help</code> output. These commands can print
  3606. anything in any format.
  3607. This is seldom used, as packages rarely have custom rules. <span class="strong"><strong>Do not use
  3608. this variable</strong></span>, unless you really know that you need to print help.
  3609. </li><li class="listitem">
  3610. <code class="literal">LIBFOO_LINUX_CONFIG_FIXUPS</code> lists the Linux kernel configuration
  3611. options that are needed to build and use this package, and without
  3612. which the package is fundamentally broken. This shall be a set of
  3613. calls to one of the kconfig tweaking option: <code class="literal">KCONFIG_ENABLE_OPT</code>,
  3614. <code class="literal">KCONFIG_DISABLE_OPT</code>, or <code class="literal">KCONFIG_SET_OPT</code>.
  3615. This is seldom used, as package usually have no strict requirements on
  3616. the kernel options.
  3617. </li></ul></div><p>The preferred way to define these variables is:</p><pre class="screen">define LIBFOO_CONFIGURE_CMDS
  3618. action 1
  3619. action 2
  3620. action 3
  3621. endef</pre><p>In the action definitions, you can use the following variables:</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
  3622. <code class="literal">$(LIBFOO_PKGDIR)</code> contains the path to the directory containing the
  3623. <code class="literal">libfoo.mk</code> and <code class="literal">Config.in</code> files. This variable is useful when it is
  3624. necessary to install a file bundled in Buildroot, like a runtime
  3625. configuration file, a splashscreen image…
  3626. </li><li class="listitem">
  3627. <code class="literal">$(@D)</code>, which contains the directory in which the package source
  3628. code has been uncompressed.
  3629. </li><li class="listitem">
  3630. <code class="literal">$(LIBFOO_DL_DIR)</code> contains the path to the directory where all the downloads
  3631. made by Buildroot for <code class="literal">libfoo</code> are stored in.
  3632. </li><li class="listitem">
  3633. <code class="literal">$(TARGET_CC)</code>, <code class="literal">$(TARGET_LD)</code>, etc. to get the target
  3634. cross-compilation utilities
  3635. </li><li class="listitem">
  3636. <code class="literal">$(TARGET_CROSS)</code> to get the cross-compilation toolchain prefix
  3637. </li><li class="listitem">
  3638. Of course the <code class="literal">$(HOST_DIR)</code>, <code class="literal">$(STAGING_DIR)</code> and <code class="literal">$(TARGET_DIR)</code>
  3639. variables to install the packages properly. Those variables point to
  3640. the global <span class="emphasis"><em>host</em></span>, <span class="emphasis"><em>staging</em></span> and <span class="emphasis"><em>target</em></span> directories, unless
  3641. <span class="emphasis"><em>per-package directory</em></span> support is used, in which case they point to
  3642. the current package <span class="emphasis"><em>host</em></span>, <span class="emphasis"><em>staging</em></span> and <span class="emphasis"><em>target</em></span> directories. In
  3643. both cases, it doesn’t make any difference from the package point of
  3644. view: it should simply use <code class="literal">HOST_DIR</code>, <code class="literal">STAGING_DIR</code> and
  3645. <code class="literal">TARGET_DIR</code>. See <a class="xref" href="#top-level-parallel-build" title="8.12. Top-level parallel build">Section 8.12, “Top-level parallel build”</a> for more details
  3646. about <span class="emphasis"><em>per-package directory</em></span> support.
  3647. </li></ul></div><p>Finally, you can also use hooks. See <a class="xref" href="#hooks" title="18.23. Hooks available in the various build steps">Section 18.23, “Hooks available in the various build steps”</a> for more information.</p></div></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="_infrastructure_for_autotools_based_packages"></a>18.7. Infrastructure for autotools-based packages</h2></div></div></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a id="autotools-package-tutorial"></a>18.7.1. <code class="literal">autotools-package</code> tutorial</h3></div></div></div><p>First, let’s see how to write a <code class="literal">.mk</code> file for an autotools-based
  3648. package, with an example :</p><pre class="screen">01: ################################################################################
  3649. 02: #
  3650. 03: # libfoo
  3651. 04: #
  3652. 05: ################################################################################
  3653. 06:
  3654. 07: LIBFOO_VERSION = 1.0
  3655. 08: LIBFOO_SOURCE = libfoo-$(LIBFOO_VERSION).tar.gz
  3656. 09: LIBFOO_SITE = http://www.foosoftware.org/download
  3657. 10: LIBFOO_INSTALL_STAGING = YES
  3658. 11: LIBFOO_INSTALL_TARGET = NO
  3659. 12: LIBFOO_CONF_OPTS = --disable-shared
  3660. 13: LIBFOO_DEPENDENCIES = libglib2 host-pkgconf
  3661. 14:
  3662. 15: $(eval $(autotools-package))</pre><p>On line 7, we declare the version of the package.</p><p>On line 8 and 9, we declare the name of the tarball (xz-ed tarball recommended)
  3663. and the location of the tarball on the Web. Buildroot will automatically
  3664. download the tarball from this location.</p><p>On line 10, we tell Buildroot to install the package to the staging
  3665. directory. The staging directory, located in <code class="literal">output/staging/</code>
  3666. is the directory where all the packages are installed, including their
  3667. development files, etc. By default, packages are not installed to the
  3668. staging directory, since usually, only libraries need to be installed in
  3669. the staging directory: their development files are needed to compile
  3670. other libraries or applications depending on them. Also by default, when
  3671. staging installation is enabled, packages are installed in this location
  3672. using the <code class="literal">make install</code> command.</p><p>On line 11, we tell Buildroot to not install the package to the
  3673. target directory. This directory contains what will become the root
  3674. filesystem running on the target. For purely static libraries, it is
  3675. not necessary to install them in the target directory because they will
  3676. not be used at runtime. By default, target installation is enabled; setting
  3677. this variable to NO is almost never needed. Also by default, packages are
  3678. installed in this location using the <code class="literal">make install</code> command.</p><p>On line 12, we tell Buildroot to pass a custom configure option, that
  3679. will be passed to the <code class="literal">./configure</code> script before configuring
  3680. and building the package.</p><p>On line 13, we declare our dependencies, so that they are built
  3681. before the build process of our package starts.</p><p>Finally, on line line 15, we invoke the <code class="literal">autotools-package</code>
  3682. macro that generates all the Makefile rules that actually allows the
  3683. package to be built.</p></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a id="autotools-package-reference"></a>18.7.2. <code class="literal">autotools-package</code> reference</h3></div></div></div><p>The main macro of the autotools package infrastructure is
  3684. <code class="literal">autotools-package</code>. It is similar to the <code class="literal">generic-package</code> macro. The ability to
  3685. have target and host packages is also available, with the
  3686. <code class="literal">host-autotools-package</code> macro.</p><p>Just like the generic infrastructure, the autotools infrastructure
  3687. works by defining a number of variables before calling the
  3688. <code class="literal">autotools-package</code> macro.</p><p>All the package metadata information variables that exist in the
  3689. <a class="link" href="#generic-package-reference" title="18.6.2. generic-package reference">generic package infrastructure</a> also
  3690. exist in the autotools infrastructure.</p><p>A few additional variables, specific to the autotools infrastructure,
  3691. can also be defined. Many of them are only useful in very specific
  3692. cases, typical packages will therefore only use a few of them.</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
  3693. <code class="literal">LIBFOO_SUBDIR</code> may contain the name of a subdirectory
  3694. inside the package that contains the configure script. This is useful,
  3695. if for example, the main configure script is not at the root of the
  3696. tree extracted by the tarball. If <code class="literal">HOST_LIBFOO_SUBDIR</code> is
  3697. not specified, it defaults to <code class="literal">LIBFOO_SUBDIR</code>.
  3698. </li><li class="listitem">
  3699. <code class="literal">LIBFOO_CONF_ENV</code>, to specify additional environment
  3700. variables to pass to the configure script. By default, empty.
  3701. </li><li class="listitem">
  3702. <code class="literal">LIBFOO_CONF_OPTS</code>, to specify additional configure
  3703. options to pass to the configure script. By default, empty.
  3704. </li><li class="listitem">
  3705. <code class="literal">LIBFOO_MAKE</code>, to specify an alternate <code class="literal">make</code>
  3706. command. This is typically useful when parallel make is enabled in
  3707. the configuration (using <code class="literal">BR2_JLEVEL</code>) but that this
  3708. feature should be disabled for the given package, for one reason or
  3709. another. By default, set to <code class="literal">$(MAKE)</code>. If parallel building
  3710. is not supported by the package, then it should be set to
  3711. <code class="literal">LIBFOO_MAKE=$(MAKE1)</code>.
  3712. </li><li class="listitem">
  3713. <code class="literal">LIBFOO_MAKE_ENV</code>, to specify additional environment
  3714. variables to pass to make in the build step. These are passed before
  3715. the <code class="literal">make</code> command. By default, empty.
  3716. </li><li class="listitem">
  3717. <code class="literal">LIBFOO_MAKE_OPTS</code>, to specify additional variables to
  3718. pass to make in the build step. These are passed after the
  3719. <code class="literal">make</code> command. By default, empty.
  3720. </li><li class="listitem">
  3721. <code class="literal">LIBFOO_AUTORECONF</code>, tells whether the package should
  3722. be autoreconfigured or not (i.e. if the configure script and
  3723. Makefile.in files should be re-generated by re-running autoconf,
  3724. automake, libtool, etc.). Valid values are <code class="literal">YES</code> and
  3725. <code class="literal">NO</code>. By default, the value is <code class="literal">NO</code>
  3726. </li><li class="listitem">
  3727. <code class="literal">LIBFOO_AUTORECONF_ENV</code>, to specify additional environment
  3728. variables to pass to the <span class="emphasis"><em>autoreconf</em></span> program if
  3729. <code class="literal">LIBFOO_AUTORECONF=YES</code>. These are passed in the environment of
  3730. the <span class="emphasis"><em>autoreconf</em></span> command. By default, empty.
  3731. </li><li class="listitem">
  3732. <code class="literal">LIBFOO_AUTORECONF_OPTS</code> to specify additional options
  3733. passed to the <span class="emphasis"><em>autoreconf</em></span> program if
  3734. <code class="literal">LIBFOO_AUTORECONF=YES</code>. By default, empty.
  3735. </li><li class="listitem">
  3736. <code class="literal">LIBFOO_AUTOPOINT</code>, tells whether the package should be
  3737. autopointed or not (i.e. if the package needs I18N infrastructure
  3738. copied in.) Only valid when <code class="literal">LIBFOO_AUTORECONF=YES</code>. Valid
  3739. values are <code class="literal">YES</code> and <code class="literal">NO</code>. The default is <code class="literal">NO</code>.
  3740. </li><li class="listitem">
  3741. <code class="literal">LIBFOO_LIBTOOL_PATCH</code> tells whether the Buildroot
  3742. patch to fix libtool cross-compilation issues should be applied or
  3743. not. Valid values are <code class="literal">YES</code> and <code class="literal">NO</code>. By
  3744. default, the value is <code class="literal">YES</code>
  3745. </li><li class="listitem">
  3746. <code class="literal">LIBFOO_INSTALL_STAGING_OPTS</code> contains the make options
  3747. used to install the package to the staging directory. By default, the
  3748. value is <code class="literal">DESTDIR=$(STAGING_DIR) install</code>, which is
  3749. correct for most autotools packages. It is still possible to override
  3750. it.
  3751. </li><li class="listitem">
  3752. <code class="literal">LIBFOO_INSTALL_TARGET_OPTS</code> contains the make options
  3753. used to install the package to the target directory. By default, the
  3754. value is <code class="literal">DESTDIR=$(TARGET_DIR) install</code>. The default
  3755. value is correct for most autotools packages, but it is still possible
  3756. to override it if needed.
  3757. </li></ul></div><p>With the autotools infrastructure, all the steps required to build
  3758. and install the packages are already defined, and they generally work
  3759. well for most autotools-based packages. However, when required, it is
  3760. still possible to customize what is done in any particular step:</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
  3761. By adding a post-operation hook (after extract, patch, configure,
  3762. build or install). See <a class="xref" href="#hooks" title="18.23. Hooks available in the various build steps">Section 18.23, “Hooks available in the various build steps”</a> for details.
  3763. </li><li class="listitem">
  3764. By overriding one of the steps. For example, even if the autotools
  3765. infrastructure is used, if the package <code class="literal">.mk</code> file defines its
  3766. own <code class="literal">LIBFOO_CONFIGURE_CMDS</code> variable, it will be used
  3767. instead of the default autotools one. However, using this method
  3768. should be restricted to very specific cases. Do not use it in the
  3769. general case.
  3770. </li></ul></div></div></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="_infrastructure_for_cmake_based_packages"></a>18.8. Infrastructure for CMake-based packages</h2></div></div></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a id="cmake-package-tutorial"></a>18.8.1. <code class="literal">cmake-package</code> tutorial</h3></div></div></div><p>First, let’s see how to write a <code class="literal">.mk</code> file for a CMake-based package,
  3771. with an example :</p><pre class="screen">01: ################################################################################
  3772. 02: #
  3773. 03: # libfoo
  3774. 04: #
  3775. 05: ################################################################################
  3776. 06:
  3777. 07: LIBFOO_VERSION = 1.0
  3778. 08: LIBFOO_SOURCE = libfoo-$(LIBFOO_VERSION).tar.gz
  3779. 09: LIBFOO_SITE = http://www.foosoftware.org/download
  3780. 10: LIBFOO_INSTALL_STAGING = YES
  3781. 11: LIBFOO_INSTALL_TARGET = NO
  3782. 12: LIBFOO_CONF_OPTS = -DBUILD_DEMOS=ON
  3783. 13: LIBFOO_DEPENDENCIES = libglib2 host-pkgconf
  3784. 14:
  3785. 15: $(eval $(cmake-package))</pre><p>On line 7, we declare the version of the package.</p><p>On line 8 and 9, we declare the name of the tarball (xz-ed tarball recommended)
  3786. and the location of the tarball on the Web. Buildroot will automatically
  3787. download the tarball from this location.</p><p>On line 10, we tell Buildroot to install the package to the staging
  3788. directory. The staging directory, located in <code class="literal">output/staging/</code>
  3789. is the directory where all the packages are installed, including their
  3790. development files, etc. By default, packages are not installed to the
  3791. staging directory, since usually, only libraries need to be installed in
  3792. the staging directory: their development files are needed to compile
  3793. other libraries or applications depending on them. Also by default, when
  3794. staging installation is enabled, packages are installed in this location
  3795. using the <code class="literal">make install</code> command.</p><p>On line 11, we tell Buildroot to not install the package to the
  3796. target directory. This directory contains what will become the root
  3797. filesystem running on the target. For purely static libraries, it is
  3798. not necessary to install them in the target directory because they will
  3799. not be used at runtime. By default, target installation is enabled; setting
  3800. this variable to NO is almost never needed. Also by default, packages are
  3801. installed in this location using the <code class="literal">make install</code> command.</p><p>On line 12, we tell Buildroot to pass custom options to CMake when it is
  3802. configuring the package.</p><p>On line 13, we declare our dependencies, so that they are built
  3803. before the build process of our package starts.</p><p>Finally, on line line 15, we invoke the <code class="literal">cmake-package</code>
  3804. macro that generates all the Makefile rules that actually allows the
  3805. package to be built.</p></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a id="cmake-package-reference"></a>18.8.2. <code class="literal">cmake-package</code> reference</h3></div></div></div><p>The main macro of the CMake package infrastructure is
  3806. <code class="literal">cmake-package</code>. It is similar to the <code class="literal">generic-package</code> macro. The ability to
  3807. have target and host packages is also available, with the
  3808. <code class="literal">host-cmake-package</code> macro.</p><p>Just like the generic infrastructure, the CMake infrastructure works
  3809. by defining a number of variables before calling the <code class="literal">cmake-package</code>
  3810. macro.</p><p>All the package metadata information variables that exist in the
  3811. <a class="link" href="#generic-package-reference" title="18.6.2. generic-package reference">generic package infrastructure</a> also
  3812. exist in the CMake infrastructure.</p><p>A few additional variables, specific to the CMake infrastructure, can
  3813. also be defined. Many of them are only useful in very specific cases,
  3814. typical packages will therefore only use a few of them.</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
  3815. <code class="literal">LIBFOO_SUBDIR</code> may contain the name of a subdirectory inside the
  3816. package that contains the main CMakeLists.txt file. This is useful,
  3817. if for example, the main CMakeLists.txt file is not at the root of
  3818. the tree extracted by the tarball. If <code class="literal">HOST_LIBFOO_SUBDIR</code> is not
  3819. specified, it defaults to <code class="literal">LIBFOO_SUBDIR</code>.
  3820. </li><li class="listitem">
  3821. <code class="literal">LIBFOO_CMAKE_BACKEND</code> specifies the cmake backend to use, one of
  3822. <code class="literal">make</code> (to use the GNU Makefiles generator, the default) or <code class="literal">ninja</code>
  3823. (to use the Ninja generator).
  3824. </li><li class="listitem">
  3825. <code class="literal">LIBFOO_CONF_ENV</code>, to specify additional environment variables to
  3826. pass to CMake. By default, empty.
  3827. </li><li class="listitem"><p class="simpara">
  3828. <code class="literal">LIBFOO_CONF_OPTS</code>, to specify additional configure options to pass
  3829. to CMake. By default, empty. A number of common CMake options are
  3830. set by the <code class="literal">cmake-package</code> infrastructure; so it is normally not
  3831. necessary to set them in the package’s <code class="literal">*.mk</code> file unless you want
  3832. to override them:
  3833. </p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: circle; "><li class="listitem">
  3834. <code class="literal">CMAKE_BUILD_TYPE</code> is driven by <code class="literal">BR2_ENABLE_RUNTIME_DEBUG</code>;
  3835. </li><li class="listitem">
  3836. <code class="literal">CMAKE_INSTALL_PREFIX</code>;
  3837. </li><li class="listitem">
  3838. <code class="literal">BUILD_SHARED_LIBS</code> is driven by <code class="literal">BR2_STATIC_LIBS</code>;
  3839. </li><li class="listitem">
  3840. <code class="literal">BUILD_DOC</code>, <code class="literal">BUILD_DOCS</code> are disabled;
  3841. </li><li class="listitem">
  3842. <code class="literal">BUILD_EXAMPLE</code>, <code class="literal">BUILD_EXAMPLES</code> are disabled;
  3843. </li><li class="listitem">
  3844. <code class="literal">BUILD_TEST</code>, <code class="literal">BUILD_TESTS</code>, <code class="literal">BUILD_TESTING</code> are disabled.
  3845. </li></ul></div></li><li class="listitem">
  3846. <code class="literal">LIBFOO_BUILD_ENV</code> and <code class="literal">LIBFOO_BUILD_OPTS</code> to specify additional
  3847. environment variables, or command line options, to pass to the backend
  3848. at build time.
  3849. </li><li class="listitem">
  3850. <code class="literal">LIBFOO_SUPPORTS_IN_SOURCE_BUILD = NO</code> should be set when the package
  3851. cannot be built inside the source tree but needs a separate build
  3852. directory.
  3853. </li><li class="listitem">
  3854. <code class="literal">LIBFOO_MAKE</code>, to specify an alternate <code class="literal">make</code> command. This is
  3855. typically useful when parallel make is enabled in the configuration
  3856. (using <code class="literal">BR2_JLEVEL</code>) but that this feature should be disabled for
  3857. the given package, for one reason or another. By default, set to
  3858. <code class="literal">$(MAKE)</code>. If parallel building is not supported by the package,
  3859. then it should be set to <code class="literal">LIBFOO_MAKE=$(MAKE1)</code>.
  3860. </li><li class="listitem">
  3861. <code class="literal">LIBFOO_MAKE_ENV</code>, to specify additional environment variables to
  3862. pass to make in the build step. These are passed before the <code class="literal">make</code>
  3863. command. By default, empty.
  3864. </li><li class="listitem">
  3865. <code class="literal">LIBFOO_MAKE_OPTS</code>, to specify additional variables to pass to make
  3866. in the build step. These are passed after the <code class="literal">make</code> command. By
  3867. default, empty.
  3868. </li><li class="listitem">
  3869. <code class="literal">LIBFOO_INSTALL_OPTS</code> contains the make options used to
  3870. install the package to the host directory. By default, the value
  3871. is <code class="literal">install</code>, which is correct for most CMake packages. It is still
  3872. possible to override it.
  3873. </li><li class="listitem">
  3874. <code class="literal">LIBFOO_INSTALL_STAGING_OPTS</code> contains the make options used to
  3875. install the package to the staging directory. By default, the value
  3876. is <code class="literal">DESTDIR=$(STAGING_DIR) install/fast</code>, which is correct for most
  3877. CMake packages. It is still possible to override it.
  3878. </li><li class="listitem">
  3879. <code class="literal">LIBFOO_INSTALL_TARGET_OPTS</code> contains the make options used to
  3880. install the package to the target directory. By default, the value
  3881. is <code class="literal">DESTDIR=$(TARGET_DIR) install/fast</code>. The default value is correct
  3882. for most CMake packages, but it is still possible to override it if
  3883. needed.
  3884. </li></ul></div><p>With the CMake infrastructure, all the steps required to build and
  3885. install the packages are already defined, and they generally work well
  3886. for most CMake-based packages. However, when required, it is still
  3887. possible to customize what is done in any particular step:</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
  3888. By adding a post-operation hook (after extract, patch, configure,
  3889. build or install). See <a class="xref" href="#hooks" title="18.23. Hooks available in the various build steps">Section 18.23, “Hooks available in the various build steps”</a> for details.
  3890. </li><li class="listitem">
  3891. By overriding one of the steps. For example, even if the CMake
  3892. infrastructure is used, if the package <code class="literal">.mk</code> file defines its own
  3893. <code class="literal">LIBFOO_CONFIGURE_CMDS</code> variable, it will be used instead of the
  3894. default CMake one. However, using this method should be restricted
  3895. to very specific cases. Do not use it in the general case.
  3896. </li></ul></div></div></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="_infrastructure_for_python_packages"></a>18.9. Infrastructure for Python packages</h2></div></div></div><p>This infrastructure applies to Python packages that use the standard
  3897. Python setuptools, pep517, flit or maturin mechanisms as their build
  3898. system, generally recognizable by the usage of a <code class="literal">setup.py</code> script or
  3899. <code class="literal">pyproject.toml</code> file.</p><div class="section"><div class="titlepage"><div><div><h3 class="title"><a id="python-package-tutorial"></a>18.9.1. <code class="literal">python-package</code> tutorial</h3></div></div></div><p>First, let’s see how to write a <code class="literal">.mk</code> file for a Python package,
  3900. with an example :</p><pre class="screen">01: ################################################################################
  3901. 02: #
  3902. 03: # python-foo
  3903. 04: #
  3904. 05: ################################################################################
  3905. 06:
  3906. 07: PYTHON_FOO_VERSION = 1.0
  3907. 08: PYTHON_FOO_SOURCE = python-foo-$(PYTHON_FOO_VERSION).tar.xz
  3908. 09: PYTHON_FOO_SITE = http://www.foosoftware.org/download
  3909. 10: PYTHON_FOO_LICENSE = BSD-3-Clause
  3910. 11: PYTHON_FOO_LICENSE_FILES = LICENSE
  3911. 12: PYTHON_FOO_ENV = SOME_VAR=1
  3912. 13: PYTHON_FOO_DEPENDENCIES = libmad
  3913. 14: PYTHON_FOO_SETUP_TYPE = setuptools
  3914. 15:
  3915. 16: $(eval $(python-package))</pre><p>On line 7, we declare the version of the package.</p><p>On line 8 and 9, we declare the name of the tarball (xz-ed tarball
  3916. recommended) and the location of the tarball on the Web. Buildroot
  3917. will automatically download the tarball from this location.</p><p>On line 10 and 11, we give licensing details about the package (its
  3918. license on line 10, and the file containing the license text on line
  3919. 11).</p><p>On line 12, we tell Buildroot to pass custom options to the Python
  3920. <code class="literal">setup.py</code> script when it is configuring the package.</p><p>On line 13, we declare our dependencies, so that they are built
  3921. before the build process of our package starts.</p><p>On line 14, we declare the specific Python build system being used. In
  3922. this case the <code class="literal">setuptools</code> Python build system is used. The five
  3923. supported ones are <code class="literal">flit</code>, <code class="literal">pep517</code>, <code class="literal">setuptools</code>, <code class="literal">setuptools-rust</code>
  3924. and <code class="literal">maturin</code>.</p><p>Finally, on line 16, we invoke the <code class="literal">python-package</code> macro that
  3925. generates all the Makefile rules that actually allow the package to be
  3926. built.</p></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a id="python-package-reference"></a>18.9.2. <code class="literal">python-package</code> reference</h3></div></div></div><p>As a policy, packages that merely provide Python modules should all be
  3927. named <code class="literal">python-&lt;something&gt;</code> in Buildroot. Other packages that use the
  3928. Python build system, but are not Python modules, can freely choose
  3929. their name (existing examples in Buildroot are <code class="literal">scons</code> and
  3930. <code class="literal">supervisor</code>).</p><p>The main macro of the Python package infrastructure is
  3931. <code class="literal">python-package</code>. It is similar to the <code class="literal">generic-package</code> macro. It is
  3932. also possible to create Python host packages with the
  3933. <code class="literal">host-python-package</code> macro.</p><p>Just like the generic infrastructure, the Python infrastructure works
  3934. by defining a number of variables before calling the <code class="literal">python-package</code>
  3935. or <code class="literal">host-python-package</code> macros.</p><p>All the package metadata information variables that exist in the
  3936. <a class="link" href="#generic-package-reference" title="18.6.2. generic-package reference">generic package infrastructure</a> also
  3937. exist in the Python infrastructure.</p><p>Note that:</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
  3938. It is not necessary to add <code class="literal">python</code> or <code class="literal">host-python</code> in the
  3939. <code class="literal">PYTHON_FOO_DEPENDENCIES</code> variable of a package, since these basic
  3940. dependencies are automatically added as needed by the Python
  3941. package infrastructure.
  3942. </li><li class="listitem">
  3943. Similarly, it is not needed to add <code class="literal">host-python-setuptools</code> to
  3944. <code class="literal">PYTHON_FOO_DEPENDENCIES</code> for setuptools-based packages, since it’s
  3945. automatically added by the Python infrastructure as needed.
  3946. </li></ul></div><p>One variable specific to the Python infrastructure is mandatory:</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
  3947. <code class="literal">PYTHON_FOO_SETUP_TYPE</code>, to define which Python build system is used
  3948. by the package. The five supported values are <code class="literal">flit</code>, <code class="literal">pep517</code> and
  3949. <code class="literal">setuptools</code>, <code class="literal">setuptools-rust</code> and <code class="literal">maturin</code>. If you don’t know
  3950. which one is used in your package, look at the <code class="literal">setup.py</code> or
  3951. <code class="literal">pyproject.toml</code> file in your package source code, and see whether
  3952. it imports things from the <code class="literal">flit</code> module or the <code class="literal">setuptools</code>
  3953. module. If the package is using a <code class="literal">pyproject.toml</code> file without any
  3954. build-system requires and with a local in-tree backend-path one
  3955. should use <code class="literal">pep517</code>.
  3956. </li></ul></div><p>A few additional variables, specific to the Python infrastructure, can
  3957. optionally be defined, depending on the package’s needs. Many of them
  3958. are only useful in very specific cases, typical packages will
  3959. therefore only use a few of them, or none.</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
  3960. <code class="literal">PYTHON_FOO_SUBDIR</code> may contain the name of a subdirectory inside the
  3961. package that contains the main <code class="literal">setup.py</code> or <code class="literal">pyproject.toml</code> file.
  3962. This is useful, if for example, the main <code class="literal">setup.py</code> or <code class="literal">pyproject.toml</code>
  3963. file is not at the root of the tree extracted by the tarball. If
  3964. <code class="literal">HOST_PYTHON_FOO_SUBDIR</code> is not specified, it defaults to
  3965. <code class="literal">PYTHON_FOO_SUBDIR</code>.
  3966. </li><li class="listitem">
  3967. <code class="literal">PYTHON_FOO_ENV</code>, to specify additional environment variables to
  3968. pass to the Python <code class="literal">setup.py</code> script (for setuptools packages) or
  3969. the <code class="literal">support/scripts/pyinstaller.py</code> script (for flit/pep517
  3970. packages) for both the build and install steps. Note that the
  3971. infrastructure is automatically passing several standard variables,
  3972. defined in <code class="literal">PKG_PYTHON_SETUPTOOLS_ENV</code> (for setuptools target
  3973. packages), <code class="literal">HOST_PKG_PYTHON_SETUPTOOLS_ENV</code> (for setuptools host
  3974. packages), <code class="literal">PKG_PYTHON_PEP517_ENV</code> (for flit/pep517 target packages)
  3975. and <code class="literal">HOST_PKG_PYTHON_PEP517_ENV</code> (for flit/pep517 host packages).
  3976. </li><li class="listitem">
  3977. <code class="literal">PYTHON_FOO_BUILD_OPTS</code>, to specify additional options to pass to
  3978. the Python <code class="literal">setup.py</code> script during the build step, this generally
  3979. only makes sense to use for setuptools based packages as flit/pep517
  3980. based packages do not pass these options to a <code class="literal">setup.py</code> script but
  3981. instead pass them to <code class="literal">support/scripts/pyinstaller.py</code>.
  3982. </li><li class="listitem">
  3983. <code class="literal">PYTHON_FOO_INSTALL_TARGET_OPTS</code>, <code class="literal">PYTHON_FOO_INSTALL_STAGING_OPTS</code>,
  3984. <code class="literal">HOST_PYTHON_FOO_INSTALL_OPTS</code> to specify additional options to pass
  3985. to the Python <code class="literal">setup.py</code> script (for setuptools packages) or
  3986. <code class="literal">support/scripts/pyinstaller.py</code> (for flit/pep517 packages) during
  3987. the target installation step, the staging installation step or the
  3988. host installation, respectively.
  3989. </li></ul></div><p>With the Python infrastructure, all the steps required to build and
  3990. install the packages are already defined, and they generally work well
  3991. for most Python-based packages. However, when required, it is still
  3992. possible to customize what is done in any particular step:</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
  3993. By adding a post-operation hook (after extract, patch, configure,
  3994. build or install). See <a class="xref" href="#hooks" title="18.23. Hooks available in the various build steps">Section 18.23, “Hooks available in the various build steps”</a> for details.
  3995. </li><li class="listitem">
  3996. By overriding one of the steps. For example, even if the Python
  3997. infrastructure is used, if the package <code class="literal">.mk</code> file defines its own
  3998. <code class="literal">PYTHON_FOO_BUILD_CMDS</code> variable, it will be used instead of the
  3999. default Python one. However, using this method should be restricted
  4000. to very specific cases. Do not use it in the general case.
  4001. </li></ul></div></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a id="scanpypi"></a>18.9.3. Generating a <code class="literal">python-package</code> from a PyPI repository</h3></div></div></div><p>If the Python package for which you would like to create a Buildroot
  4002. package is available on PyPI, you may want to use the <code class="literal">scanpypi</code> tool
  4003. located in <code class="literal">utils/</code> to automate the process.</p><p>You can find the list of existing PyPI packages
  4004. <a class="ulink" href="https://pypi.python.org" target="_top">here</a>.</p><p><code class="literal">scanpypi</code> requires Python’s <code class="literal">setuptools</code> package to be installed on
  4005. your host.</p><p>When at the root of your buildroot directory just do :</p><pre class="screen">utils/scanpypi foo bar -o package</pre><p>This will generate packages <code class="literal">python-foo</code> and <code class="literal">python-bar</code> in the package
  4006. folder if they exist on <a class="ulink" href="https://pypi.python.org" target="_top">https://pypi.python.org</a>.</p><p>Find the <code class="literal">external python modules</code> menu and insert your package inside.
  4007. Keep in mind that the items inside a menu should be in alphabetical order.</p><p>Please keep in mind that you’ll most likely have to manually check the
  4008. package for any mistakes as there are things that cannot be guessed by
  4009. the generator (e.g. dependencies on any of the python core modules
  4010. such as BR2_PACKAGE_PYTHON_ZLIB). Also, please take note that the
  4011. license and license files are guessed and must be checked. You also
  4012. need to manually add the package to the <code class="literal">package/Config.in</code> file.</p><p>If your Buildroot package is not in the official Buildroot tree but in
  4013. a br2-external tree, use the -o flag as follows:</p><pre class="screen">utils/scanpypi foo bar -o other_package_dir</pre><p>This will generate packages <code class="literal">python-foo</code> and <code class="literal">python-bar</code> in the
  4014. <code class="literal">other_package_directory</code> instead of <code class="literal">package</code>.</p><p>Option <code class="literal">-h</code> will list the available options:</p><pre class="screen">utils/scanpypi -h</pre></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a id="python-package-cffi-backend"></a>18.9.4. <code class="literal">python-package</code> CFFI backend</h3></div></div></div><p>C Foreign Function Interface for Python (CFFI) provides a convenient
  4015. and reliable way to call compiled C code from Python using interface
  4016. declarations written in C. Python packages relying on this backend can
  4017. be identified by the appearance of a <code class="literal">cffi</code> dependency in the
  4018. <code class="literal">install_requires</code> field of their <code class="literal">setup.py</code> file.</p><p>Such a package should:</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
  4019. add <code class="literal">python-cffi</code> as a runtime dependency in order to install the
  4020. compiled C library wrapper on the target. This is achieved by adding
  4021. <code class="literal">select BR2_PACKAGE_PYTHON_CFFI</code> to the package <code class="literal">Config.in</code>.
  4022. </li></ul></div><pre class="screen">config BR2_PACKAGE_PYTHON_FOO
  4023. bool "python-foo"
  4024. select BR2_PACKAGE_PYTHON_CFFI # runtime</pre><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
  4025. add <code class="literal">host-python-cffi</code> as a build-time dependency in order to
  4026. cross-compile the C wrapper. This is achieved by adding
  4027. <code class="literal">host-python-cffi</code> to the <code class="literal">PYTHON_FOO_DEPENDENCIES</code> variable.
  4028. </li></ul></div><pre class="screen">################################################################################
  4029. #
  4030. # python-foo
  4031. #
  4032. ################################################################################
  4033. ...
  4034. PYTHON_FOO_DEPENDENCIES = host-python-cffi
  4035. $(eval $(python-package))</pre></div></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="_infrastructure_for_luarocks_based_packages"></a>18.10. Infrastructure for LuaRocks-based packages</h2></div></div></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a id="luarocks-package-tutorial"></a>18.10.1. <code class="literal">luarocks-package</code> tutorial</h3></div></div></div><p>First, let’s see how to write a <code class="literal">.mk</code> file for a LuaRocks-based package,
  4036. with an example :</p><pre class="screen">01: ################################################################################
  4037. 02: #
  4038. 03: # lua-foo
  4039. 04: #
  4040. 05: ################################################################################
  4041. 06:
  4042. 07: LUA_FOO_VERSION = 1.0.2-1
  4043. 08: LUA_FOO_NAME_UPSTREAM = foo
  4044. 09: LUA_FOO_DEPENDENCIES = bar
  4045. 10:
  4046. 11: LUA_FOO_BUILD_OPTS += BAR_INCDIR=$(STAGING_DIR)/usr/include
  4047. 12: LUA_FOO_BUILD_OPTS += BAR_LIBDIR=$(STAGING_DIR)/usr/lib
  4048. 13: LUA_FOO_LICENSE = luaFoo license
  4049. 14: LUA_FOO_LICENSE_FILES = $(LUA_FOO_SUBDIR)/COPYING
  4050. 15:
  4051. 16: $(eval $(luarocks-package))</pre><p>On line 7, we declare the version of the package (the same as in the rockspec,
  4052. which is the concatenation of the upstream version and the rockspec revision,
  4053. separated by a hyphen <span class="emphasis"><em>-</em></span>).</p><p>On line 8, we declare that the package is called "foo" on LuaRocks. In
  4054. Buildroot, we give Lua-related packages a name that starts with "lua", so the
  4055. Buildroot name is different from the upstream name. <code class="literal">LUA_FOO_NAME_UPSTREAM</code>
  4056. makes the link between the two names.</p><p>On line 9, we declare our dependencies against native libraries, so that they
  4057. are built before the build process of our package starts.</p><p>On lines 11-12, we tell Buildroot to pass custom options to LuaRocks when it is
  4058. building the package.</p><p>On lines 13-14, we specify the licensing terms for the package.</p><p>Finally, on line 16, we invoke the <code class="literal">luarocks-package</code>
  4059. macro that generates all the Makefile rules that actually allows the
  4060. package to be built.</p><p>Most of these details can be retrieved from the <code class="literal">rock</code> and <code class="literal">rockspec</code>.
  4061. So, this file and the Config.in file can be generated by running the
  4062. command <code class="literal">luarocks buildroot foo lua-foo</code> in the Buildroot
  4063. directory. This command runs a specific Buildroot addon of <code class="literal">luarocks</code>
  4064. that will automatically generate a Buildroot package. The result must
  4065. still be manually inspected and possibly modified.</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
  4066. The <code class="literal">package/Config.in</code> file has to be updated manually to include the
  4067. generated Config.in files.
  4068. </li></ul></div></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a id="luarocks-package-reference"></a>18.10.2. <code class="literal">luarocks-package</code> reference</h3></div></div></div><p>LuaRocks is a deployment and management system for Lua modules, and supports
  4069. various <code class="literal">build.type</code>: <code class="literal">builtin</code>, <code class="literal">make</code> and <code class="literal">cmake</code>. In the context of
  4070. Buildroot, the <code class="literal">luarocks-package</code> infrastructure only supports the <code class="literal">builtin</code>
  4071. mode. LuaRocks packages that use the <code class="literal">make</code> or <code class="literal">cmake</code> build mechanisms
  4072. should instead be packaged using the <code class="literal">generic-package</code> and <code class="literal">cmake-package</code>
  4073. infrastructures in Buildroot, respectively.</p><p>The main macro of the LuaRocks package infrastructure is <code class="literal">luarocks-package</code>:
  4074. like <code class="literal">generic-package</code> it works by defining a number of variables providing
  4075. metadata information about the package, and then calling the <code class="literal">luarocks-package</code>
  4076. macro.</p><p>Just like the generic infrastructure, the LuaRocks infrastructure works
  4077. by defining a number of variables before calling the <code class="literal">luarocks-package</code>
  4078. macro.</p><p>All the package metadata information variables that exist in the
  4079. <a class="link" href="#generic-package-reference" title="18.6.2. generic-package reference">generic package infrastructure</a> also
  4080. exist in the LuaRocks infrastructure.</p><p>Two of them are populated by the LuaRocks infrastructure (for the
  4081. <code class="literal">download</code> step). If your package is not hosted on the LuaRocks mirror
  4082. <code class="literal">$(BR2_LUAROCKS_MIRROR)</code>, you can override them:</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
  4083. <code class="literal">LUA_FOO_SITE</code>, which defaults to <code class="literal">$(BR2_LUAROCKS_MIRROR)</code>
  4084. </li><li class="listitem">
  4085. <code class="literal">LUA_FOO_SOURCE</code>, which defaults to
  4086. <code class="literal">$(lowercase LUA_FOO_NAME_UPSTREAM)-$(LUA_FOO_VERSION).src.rock</code>
  4087. </li></ul></div><p>A few additional variables, specific to the LuaRocks infrastructure, are
  4088. also defined. They can be overridden in specific cases.</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
  4089. <code class="literal">LUA_FOO_NAME_UPSTREAM</code>, which defaults to <code class="literal">lua-foo</code>, i.e. the Buildroot
  4090. package name
  4091. </li><li class="listitem">
  4092. <code class="literal">LUA_FOO_ROCKSPEC</code>, which defaults to
  4093. <code class="literal">$(lowercase LUA_FOO_NAME_UPSTREAM)-$(LUA_FOO_VERSION).rockspec</code>
  4094. </li><li class="listitem">
  4095. <code class="literal">LUA_FOO_SUBDIR</code>, which defaults to
  4096. <code class="literal">$(LUA_FOO_NAME_UPSTREAM)-$(LUA_FOO_VERSION_WITHOUT_ROCKSPEC_REVISION)</code>
  4097. </li><li class="listitem">
  4098. <code class="literal">LUA_FOO_BUILD_OPTS</code> contains additional build options for the
  4099. <code class="literal">luarocks build</code> call.
  4100. </li></ul></div></div></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="_infrastructure_for_perl_cpan_packages"></a>18.11. Infrastructure for Perl/CPAN packages</h2></div></div></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a id="perl-package-tutorial"></a>18.11.1. <code class="literal">perl-package</code> tutorial</h3></div></div></div><p>First, let’s see how to write a <code class="literal">.mk</code> file for a Perl/CPAN package,
  4101. with an example :</p><pre class="screen">01: ################################################################################
  4102. 02: #
  4103. 03: # perl-foo-bar
  4104. 04: #
  4105. 05: ################################################################################
  4106. 06:
  4107. 07: PERL_FOO_BAR_VERSION = 0.02
  4108. 08: PERL_FOO_BAR_SOURCE = Foo-Bar-$(PERL_FOO_BAR_VERSION).tar.gz
  4109. 09: PERL_FOO_BAR_SITE = $(BR2_CPAN_MIRROR)/authors/id/M/MO/MONGER
  4110. 10: PERL_FOO_BAR_DEPENDENCIES = perl-strictures
  4111. 11: PERL_FOO_BAR_LICENSE = Artistic or GPL-1.0+
  4112. 12: PERL_FOO_BAR_LICENSE_FILES = LICENSE
  4113. 13: PERL_FOO_BAR_DISTNAME = Foo-Bar
  4114. 14:
  4115. 15: $(eval $(perl-package))</pre><p>On line 7, we declare the version of the package.</p><p>On line 8 and 9, we declare the name of the tarball and the location
  4116. of the tarball on a CPAN server. Buildroot will automatically download
  4117. the tarball from this location.</p><p>On line 10, we declare our dependencies, so that they are built
  4118. before the build process of our package starts.</p><p>On line 11 and 12, we give licensing details about the package (its
  4119. license on line 11, and the file containing the license text on line
  4120. 12).</p><p>On line 13, the name of the distribution as needed by the script
  4121. <code class="literal">utils/scancpan</code> (in order to regenerate/upgrade these package files).</p><p>Finally, on line 15, we invoke the <code class="literal">perl-package</code> macro that
  4122. generates all the Makefile rules that actually allow the package to be
  4123. built.</p><p>Most of these data can be retrieved from <a class="ulink" href="https://metacpan.org/" target="_top">https://metacpan.org/</a>.
  4124. So, this file and the Config.in can be generated by running
  4125. the script <code class="literal">utils/scancpan Foo-Bar</code> in the Buildroot directory
  4126. (or in a br2-external tree).
  4127. This script creates a Config.in file and foo-bar.mk file for the
  4128. requested package, and also recursively for all dependencies specified by
  4129. CPAN. You should still manually edit the result. In particular, the
  4130. following things should be checked.</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
  4131. If the perl module links with a shared library that is provided by
  4132. another (non-perl) package, this dependency is not added automatically.
  4133. It has to be added manually to <code class="literal">PERL_FOO_BAR_DEPENDENCIES</code>.
  4134. </li><li class="listitem">
  4135. The <code class="literal">package/Config.in</code> file has to be updated manually to include the
  4136. generated Config.in files. As a hint, the <code class="literal">scancpan</code> script prints out
  4137. the required <code class="literal">source "…"</code> statements, sorted alphabetically.
  4138. </li></ul></div></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a id="perl-package-reference"></a>18.11.2. <code class="literal">perl-package</code> reference</h3></div></div></div><p>As a policy, packages that provide Perl/CPAN modules should all be
  4139. named <code class="literal">perl-&lt;something&gt;</code> in Buildroot.</p><p>This infrastructure handles various Perl build systems :
  4140. <code class="literal">ExtUtils-MakeMaker</code> (EUMM), <code class="literal">Module-Build</code> (MB) and <code class="literal">Module-Build-Tiny</code>.
  4141. <code class="literal">Build.PL</code> is preferred by default when a package provides a <code class="literal">Makefile.PL</code>
  4142. and a <code class="literal">Build.PL</code>.</p><p>The main macro of the Perl/CPAN package infrastructure is
  4143. <code class="literal">perl-package</code>. It is similar to the <code class="literal">generic-package</code> macro. The ability to
  4144. have target and host packages is also available, with the
  4145. <code class="literal">host-perl-package</code> macro.</p><p>Just like the generic infrastructure, the Perl/CPAN infrastructure
  4146. works by defining a number of variables before calling the
  4147. <code class="literal">perl-package</code> macro.</p><p>All the package metadata information variables that exist in the
  4148. <a class="link" href="#generic-package-reference" title="18.6.2. generic-package reference">generic package infrastructure</a> also
  4149. exist in the Perl/CPAN infrastructure.</p><p>Note that setting <code class="literal">PERL_FOO_INSTALL_STAGING</code> to <code class="literal">YES</code> has no effect
  4150. unless a <code class="literal">PERL_FOO_INSTALL_STAGING_CMDS</code> variable is defined. The perl
  4151. infrastructure doesn’t define these commands since Perl modules generally
  4152. don’t need to be installed to the <code class="literal">staging</code> directory.</p><p>A few additional variables, specific to the Perl/CPAN infrastructure,
  4153. can also be defined. Many of them are only useful in very specific
  4154. cases, typical packages will therefore only use a few of them.</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
  4155. <code class="literal">PERL_FOO_PREFER_INSTALLER</code>/<code class="literal">HOST_PERL_FOO_PREFER_INSTALLER</code>,
  4156. specifies the preferred installation method. Possible values are
  4157. <code class="literal">EUMM</code> (for <code class="literal">Makefile.PL</code> based installation using
  4158. <code class="literal">ExtUtils-MakeMaker</code>) and <code class="literal">MB</code> (for <code class="literal">Build.PL</code> based installation
  4159. using <code class="literal">Module-Build</code>). This variable is only used when the package
  4160. provides both installation methods.
  4161. </li><li class="listitem">
  4162. <code class="literal">PERL_FOO_CONF_ENV</code>/<code class="literal">HOST_PERL_FOO_CONF_ENV</code>, to specify additional
  4163. environment variables to pass to the <code class="literal">perl Makefile.PL</code> or <code class="literal">perl Build.PL</code>.
  4164. By default, empty.
  4165. </li><li class="listitem">
  4166. <code class="literal">PERL_FOO_CONF_OPTS</code>/<code class="literal">HOST_PERL_FOO_CONF_OPTS</code>, to specify additional
  4167. configure options to pass to the <code class="literal">perl Makefile.PL</code> or <code class="literal">perl Build.PL</code>.
  4168. By default, empty.
  4169. </li><li class="listitem">
  4170. <code class="literal">PERL_FOO_BUILD_OPTS</code>/<code class="literal">HOST_PERL_FOO_BUILD_OPTS</code>, to specify additional
  4171. options to pass to <code class="literal">make pure_all</code> or <code class="literal">perl Build build</code> in the build step.
  4172. By default, empty.
  4173. </li><li class="listitem">
  4174. <code class="literal">PERL_FOO_INSTALL_TARGET_OPTS</code>, to specify additional options to
  4175. pass to <code class="literal">make pure_install</code> or <code class="literal">perl Build install</code> in the install step.
  4176. By default, empty.
  4177. </li><li class="listitem">
  4178. <code class="literal">HOST_PERL_FOO_INSTALL_OPTS</code>, to specify additional options to
  4179. pass to <code class="literal">make pure_install</code> or <code class="literal">perl Build install</code> in the install step.
  4180. By default, empty.
  4181. </li></ul></div></div></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="_infrastructure_for_virtual_packages"></a>18.12. Infrastructure for virtual packages</h2></div></div></div><p><a id="virtual-package-tutorial"></a>In Buildroot, a virtual package is a package whose functionalities are
  4182. provided by one or more packages, referred to as <span class="emphasis"><em>providers</em></span>. The virtual
  4183. package management is an extensible mechanism allowing the user to choose
  4184. the provider used in the rootfs.</p><p>For example, <span class="emphasis"><em>OpenGL ES</em></span> is an API for 2D and 3D graphics on embedded systems.
  4185. The implementation of this API is different for the <span class="emphasis"><em>Allwinner Tech Sunxi</em></span> and
  4186. the <span class="emphasis"><em>Texas Instruments OMAP35xx</em></span> platforms. So <code class="literal">libgles</code> will be a virtual
  4187. package and <code class="literal">sunxi-mali-utgard</code> and <code class="literal">ti-gfx</code> will be the providers.</p><div class="section"><div class="titlepage"><div><div><h3 class="title"><a id="_literal_virtual_package_literal_tutorial"></a>18.12.1. <code class="literal">virtual-package</code> tutorial</h3></div></div></div><p>In the following example, we will explain how to add a new virtual package
  4188. (<span class="emphasis"><em>something-virtual</em></span>) and a provider for it (<span class="emphasis"><em>some-provider</em></span>).</p><p>First, let’s create the virtual package.</p></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a id="_virtual_package_8217_s_literal_config_in_literal_file"></a>18.12.2. Virtual package’s <code class="literal">Config.in</code> file</h3></div></div></div><p>The <code class="literal">Config.in</code> file of virtual package <span class="emphasis"><em>something-virtual</em></span> should contain:</p><pre class="screen">01: config BR2_PACKAGE_HAS_SOMETHING_VIRTUAL
  4189. 02: bool
  4190. 03:
  4191. 04: config BR2_PACKAGE_PROVIDES_SOMETHING_VIRTUAL
  4192. 05: depends on BR2_PACKAGE_HAS_SOMETHING_VIRTUAL
  4193. 06: string</pre><p>In this file, we declare two options, <code class="literal">BR2_PACKAGE_HAS_SOMETHING_VIRTUAL</code> and
  4194. <code class="literal">BR2_PACKAGE_PROVIDES_SOMETHING_VIRTUAL</code>, whose values will be used by the
  4195. providers.</p></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a id="_virtual_package_8217_s_literal_mk_literal_file"></a>18.12.3. Virtual package’s <code class="literal">.mk</code> file</h3></div></div></div><p>The <code class="literal">.mk</code> for the virtual package should just evaluate the <code class="literal">virtual-package</code> macro:</p><pre class="screen">01: ################################################################################
  4196. 02: #
  4197. 03: # something-virtual
  4198. 04: #
  4199. 05: ################################################################################
  4200. 06:
  4201. 07: $(eval $(virtual-package))</pre><p>The ability to have target and host packages is also available, with the
  4202. <code class="literal">host-virtual-package</code> macro.</p></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a id="_provider_8217_s_literal_config_in_literal_file"></a>18.12.4. Provider’s <code class="literal">Config.in</code> file</h3></div></div></div><p>When adding a package as a provider, only the <code class="literal">Config.in</code> file requires some
  4203. modifications.</p><p>The <code class="literal">Config.in</code> file of the package <span class="emphasis"><em>some-provider</em></span>, which provides the
  4204. functionalities of <span class="emphasis"><em>something-virtual</em></span>, should contain:</p><pre class="screen">01: config BR2_PACKAGE_SOME_PROVIDER
  4205. 02: bool "some-provider"
  4206. 03: select BR2_PACKAGE_HAS_SOMETHING_VIRTUAL
  4207. 04: help
  4208. 05: This is a comment that explains what some-provider is.
  4209. 06:
  4210. 07: http://foosoftware.org/some-provider/
  4211. 08:
  4212. 09: if BR2_PACKAGE_SOME_PROVIDER
  4213. 10: config BR2_PACKAGE_PROVIDES_SOMETHING_VIRTUAL
  4214. 11: default "some-provider"
  4215. 12: endif</pre><p>On line 3, we select <code class="literal">BR2_PACKAGE_HAS_SOMETHING_VIRTUAL</code>, and on line 11, we
  4216. set the value of <code class="literal">BR2_PACKAGE_PROVIDES_SOMETHING_VIRTUAL</code> to the name of the
  4217. provider, but only if it is selected.</p></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a id="_provider_8217_s_literal_mk_literal_file"></a>18.12.5. Provider’s <code class="literal">.mk</code> file</h3></div></div></div><p>The <code class="literal">.mk</code> file should also declare an additional variable
  4218. <code class="literal">SOME_PROVIDER_PROVIDES</code> to contain the names of all the virtual
  4219. packages it is an implementation of:</p><pre class="screen">01: SOME_PROVIDER_PROVIDES = something-virtual</pre><p>Of course, do not forget to add the proper build and runtime dependencies for
  4220. this package!</p></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a id="_notes_on_depending_on_a_virtual_package"></a>18.12.6. Notes on depending on a virtual package</h3></div></div></div><p>When adding a package that requires a certain <code class="literal">FEATURE</code> provided by a virtual
  4221. package, you have to use <code class="literal">depends on BR2_PACKAGE_HAS_FEATURE</code>, like so:</p><pre class="screen">config BR2_PACKAGE_HAS_FEATURE
  4222. bool
  4223. config BR2_PACKAGE_FOO
  4224. bool "foo"
  4225. depends on BR2_PACKAGE_HAS_FEATURE</pre></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a id="_notes_on_depending_on_a_specific_provider"></a>18.12.7. Notes on depending on a specific provider</h3></div></div></div><p>If your package really requires a specific provider, then you’ll have to
  4226. make your package <code class="literal">depends on</code> this provider; you can <span class="emphasis"><em>not</em></span> <code class="literal">select</code> a
  4227. provider.</p><p>Let’s take an example with two providers for a <code class="literal">FEATURE</code>:</p><pre class="screen">config BR2_PACKAGE_HAS_FEATURE
  4228. bool
  4229. config BR2_PACKAGE_FOO
  4230. bool "foo"
  4231. select BR2_PACKAGE_HAS_FEATURE
  4232. config BR2_PACKAGE_BAR
  4233. bool "bar"
  4234. select BR2_PACKAGE_HAS_FEATURE</pre><p>And you are adding a package that needs <code class="literal">FEATURE</code> as provided by <code class="literal">foo</code>,
  4235. but not as provided by <code class="literal">bar</code>.</p><p>If you were to use <code class="literal">select BR2_PACKAGE_FOO</code>, then the user would still
  4236. be able to select <code class="literal">BR2_PACKAGE_BAR</code> in the menuconfig. This would create
  4237. a configuration inconsistency, whereby two providers of the same <code class="literal">FEATURE</code>
  4238. would be enabled at once, one explicitly set by the user, the other
  4239. implicitly by your <code class="literal">select</code>.</p><p>Instead, you have to use <code class="literal">depends on BR2_PACKAGE_FOO</code>, which avoids any
  4240. implicit configuration inconsistency.</p></div></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="_infrastructure_for_packages_using_kconfig_for_configuration_files"></a>18.13. Infrastructure for packages using kconfig for configuration files</h2></div></div></div><p>A popular way for a software package to handle user-specified
  4241. configuration is <code class="literal">kconfig</code>. Among others, it is used by the Linux
  4242. kernel, Busybox, and Buildroot itself. The presence of a .config file
  4243. and a <code class="literal">menuconfig</code> target are two well-known symptoms of kconfig being
  4244. used.</p><p>Buildroot features an infrastructure for packages that use kconfig for
  4245. their configuration. This infrastructure provides the necessary logic to
  4246. expose the package’s <code class="literal">menuconfig</code> target as <code class="literal">foo-menuconfig</code> in
  4247. Buildroot, and to handle the copying back and forth of the configuration
  4248. file in a correct way.</p><p>The main macro of the kconfig package infrastructure is
  4249. <code class="literal">kconfig-package</code>. It is similar to the <code class="literal">generic-package</code> macro.</p><p>Just like the generic infrastructure, the kconfig infrastructure works
  4250. by defining a number of variables before calling the <code class="literal">kconfig-package</code>
  4251. macro.</p><p>All the package metadata information variables that exist in the
  4252. <a class="link" href="#generic-package-reference" title="18.6.2. generic-package reference">generic package infrastructure</a> also
  4253. exist in the kconfig infrastructure.</p><p>In order to use the <code class="literal">kconfig-package</code> infrastructure for a Buildroot
  4254. package, the minimally required lines in the <code class="literal">.mk</code> file, in addition to
  4255. the variables required by the <code class="literal">generic-package</code> infrastructure, are:</p><pre class="screen">FOO_KCONFIG_FILE = reference-to-source-configuration-file
  4256. $(eval $(kconfig-package))</pre><p>This snippet creates the following make targets:</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
  4257. <code class="literal">foo-menuconfig</code>, which calls the package’s <code class="literal">menuconfig</code> target
  4258. </li><li class="listitem">
  4259. <code class="literal">foo-update-config</code>, which copies the configuration back to the
  4260. source configuration file. It is not possible to use this target
  4261. when fragment files are set.
  4262. </li><li class="listitem">
  4263. <code class="literal">foo-update-defconfig</code>, which copies the configuration back to the
  4264. source configuration file. The configuration file will only list the
  4265. options that differ from the default values. It is not possible to
  4266. use this target when fragment files are set.
  4267. </li><li class="listitem">
  4268. <code class="literal">foo-diff-config</code>, which outputs the differences between the current
  4269. configuration and the one defined in the Buildroot configuration for
  4270. this kconfig package. The output is useful to identify the
  4271. configuration changes that may have to be propagated to
  4272. configuration fragments for example.
  4273. </li></ul></div><p>and ensures that the source configuration file is copied to the build
  4274. directory at the right moment.</p><p>There are two options to specify a configuration file to use, either
  4275. <code class="literal">FOO_KCONFIG_FILE</code> (as in the example, above) or <code class="literal">FOO_KCONFIG_DEFCONFIG</code>.
  4276. It is mandatory to provide either, but not both:</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
  4277. <code class="literal">FOO_KCONFIG_FILE</code> specifies the path to a defconfig or full-config file
  4278. to be used to configure the package.
  4279. </li><li class="listitem">
  4280. <code class="literal">FOO_KCONFIG_DEFCONFIG</code> specifies the defconfig <span class="emphasis"><em>make</em></span> rule to call to
  4281. configure the package.
  4282. </li></ul></div><p>In addition to these minimally required lines, several optional variables can
  4283. be set to suit the needs of the package under consideration:</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
  4284. <code class="literal">FOO_KCONFIG_EDITORS</code>: a space-separated list of kconfig editors to
  4285. support, for example <span class="emphasis"><em>menuconfig xconfig</em></span>. By default, <span class="emphasis"><em>menuconfig</em></span>.
  4286. </li><li class="listitem">
  4287. <code class="literal">FOO_KCONFIG_FRAGMENT_FILES</code>: a space-separated list of configuration
  4288. fragment files that are merged to the main configuration file.
  4289. Fragment files are typically used when there is a desire to stay in sync
  4290. with an upstream (def)config file, with some minor modifications.
  4291. </li><li class="listitem">
  4292. <code class="literal">FOO_KCONFIG_OPTS</code>: extra options to pass when calling the kconfig
  4293. editors. This may need to include <span class="emphasis"><em>$(FOO_MAKE_OPTS)</em></span>, for example. By
  4294. default, empty.
  4295. </li><li class="listitem">
  4296. <code class="literal">FOO_KCONFIG_FIXUP_CMDS</code>: a list of shell commands needed to fixup the
  4297. configuration file after copying it or running a kconfig editor. Such
  4298. commands may be needed to ensure a configuration consistent with other
  4299. configuration of Buildroot, for example. By default, empty.
  4300. </li><li class="listitem">
  4301. <code class="literal">FOO_KCONFIG_DOTCONFIG</code>: path (with filename) of the <code class="literal">.config</code> file,
  4302. relative to the package source tree. The default, <code class="literal">.config</code>, should
  4303. be well suited for all packages that use the standard kconfig
  4304. infrastructure as inherited from the Linux kernel; some packages use
  4305. a derivative of kconfig that use a different location.
  4306. </li><li class="listitem">
  4307. <code class="literal">FOO_KCONFIG_DEPENDENCIES</code>: the list of packages (most probably, host
  4308. packages) that need to be built before this package’s kconfig is
  4309. interpreted. Seldom used. By default, empty.
  4310. </li><li class="listitem">
  4311. <code class="literal">FOO_KCONFIG_SUPPORTS_DEFCONFIG</code>: whether the package’s kconfig system
  4312. supports using defconfig files; few packages do not. By default, <span class="emphasis"><em>YES</em></span>.
  4313. </li></ul></div></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="_infrastructure_for_rebar_based_packages"></a>18.14. Infrastructure for rebar-based packages</h2></div></div></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a id="rebar-package-tutorial"></a>18.14.1. <code class="literal">rebar-package</code> tutorial</h3></div></div></div><p>First, let’s see how to write a <code class="literal">.mk</code> file for a rebar-based package,
  4314. with an example :</p><pre class="screen">01: ################################################################################
  4315. 02: #
  4316. 03: # erlang-foobar
  4317. 04: #
  4318. 05: ################################################################################
  4319. 06:
  4320. 07: ERLANG_FOOBAR_VERSION = 1.0
  4321. 08: ERLANG_FOOBAR_SOURCE = erlang-foobar-$(ERLANG_FOOBAR_VERSION).tar.xz
  4322. 09: ERLANG_FOOBAR_SITE = http://www.foosoftware.org/download
  4323. 10: ERLANG_FOOBAR_DEPENDENCIES = host-libaaa libbbb
  4324. 11:
  4325. 12: $(eval $(rebar-package))</pre><p>On line 7, we declare the version of the package.</p><p>On line 8 and 9, we declare the name of the tarball (xz-ed tarball
  4326. recommended) and the location of the tarball on the Web. Buildroot
  4327. will automatically download the tarball from this location.</p><p>On line 10, we declare our dependencies, so that they are built
  4328. before the build process of our package starts.</p><p>Finally, on line 12, we invoke the <code class="literal">rebar-package</code> macro that
  4329. generates all the Makefile rules that actually allows the package to
  4330. be built.</p></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a id="rebar-package-reference"></a>18.14.2. <code class="literal">rebar-package</code> reference</h3></div></div></div><p>The main macro of the <code class="literal">rebar</code> package infrastructure is
  4331. <code class="literal">rebar-package</code>. It is similar to the <code class="literal">generic-package</code> macro. The
  4332. ability to have host packages is also available, with the
  4333. <code class="literal">host-rebar-package</code> macro.</p><p>Just like the generic infrastructure, the <code class="literal">rebar</code> infrastructure works
  4334. by defining a number of variables before calling the <code class="literal">rebar-package</code>
  4335. macro.</p><p>All the package metadata information variables that exist in the
  4336. <a class="link" href="#generic-package-reference" title="18.6.2. generic-package reference">generic package infrastructure</a> also
  4337. exist in the <code class="literal">rebar</code> infrastructure.</p><p>A few additional variables, specific to the <code class="literal">rebar</code> infrastructure,
  4338. can also be defined. Many of them are only useful in very specific
  4339. cases, typical packages will therefore only use a few of them.</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p class="simpara">
  4340. <code class="literal">ERLANG_FOOBAR_USE_AUTOCONF</code>, to specify that the package uses
  4341. <span class="emphasis"><em>autoconf</em></span> at the configuration step. When a package sets this
  4342. variable to <code class="literal">YES</code>, the <code class="literal">autotools</code> infrastructure is used.
  4343. </p><p><strong>Note. </strong>You can also use some of the variables from the <code class="literal">autotools</code>
  4344. infrastructure: <code class="literal">ERLANG_FOOBAR_CONF_ENV</code>, <code class="literal">ERLANG_FOOBAR_CONF_OPTS</code>,
  4345. <code class="literal">ERLANG_FOOBAR_AUTORECONF</code>, <code class="literal">ERLANG_FOOBAR_AUTORECONF_ENV</code> and
  4346. <code class="literal">ERLANG_FOOBAR_AUTORECONF_OPTS</code>.</p></li><li class="listitem"><p class="simpara">
  4347. <code class="literal">ERLANG_FOOBAR_USE_BUNDLED_REBAR</code>, to specify that the package has
  4348. a bundled version of <span class="emphasis"><em>rebar</em></span> <span class="strong"><strong>and</strong></span> that it shall be used. Valid
  4349. values are <code class="literal">YES</code> or <code class="literal">NO</code> (the default).
  4350. </p><p><strong>Note. </strong>If the package bundles a <span class="emphasis"><em>rebar</em></span> utility, but can use the generic
  4351. one that Buildroot provides, just say <code class="literal">NO</code> (i.e., do not specify
  4352. this variable). Only set if it is mandatory to use the <span class="emphasis"><em>rebar</em></span>
  4353. utility bundled in this package.</p></li><li class="listitem">
  4354. <code class="literal">ERLANG_FOOBAR_REBAR_ENV</code>, to specify additional environment
  4355. variables to pass to the <span class="emphasis"><em>rebar</em></span> utility.
  4356. </li><li class="listitem">
  4357. <code class="literal">ERLANG_FOOBAR_KEEP_DEPENDENCIES</code>, to keep the dependencies
  4358. described in the rebar.config file. Valid values are <code class="literal">YES</code> or <code class="literal">NO</code>
  4359. (the default). Unless this variable is set to <code class="literal">YES</code>, the <span class="emphasis"><em>rebar</em></span>
  4360. infrastructure removes such dependencies in a post-patch hook to
  4361. ensure rebar does not download nor compile them.
  4362. </li></ul></div><p>With the rebar infrastructure, all the steps required to build
  4363. and install the packages are already defined, and they generally work
  4364. well for most rebar-based packages. However, when required, it is
  4365. still possible to customize what is done in any particular step:</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
  4366. By adding a post-operation hook (after extract, patch, configure,
  4367. build or install). See <a class="xref" href="#hooks" title="18.23. Hooks available in the various build steps">Section 18.23, “Hooks available in the various build steps”</a> for details.
  4368. </li><li class="listitem">
  4369. By overriding one of the steps. For example, even if the rebar
  4370. infrastructure is used, if the package <code class="literal">.mk</code> file defines its
  4371. own <code class="literal">ERLANG_FOOBAR_BUILD_CMDS</code> variable, it will be used instead
  4372. of the default rebar one. However, using this method should be
  4373. restricted to very specific cases. Do not use it in the general
  4374. case.
  4375. </li></ul></div></div></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="_infrastructure_for_waf_based_packages"></a>18.15. Infrastructure for Waf-based packages</h2></div></div></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a id="waf-package-tutorial"></a>18.15.1. <code class="literal">waf-package</code> tutorial</h3></div></div></div><p>First, let’s see how to write a <code class="literal">.mk</code> file for a Waf-based package, with
  4376. an example :</p><pre class="screen">01: ################################################################################
  4377. 02: #
  4378. 03: # libfoo
  4379. 04: #
  4380. 05: ################################################################################
  4381. 06:
  4382. 07: LIBFOO_VERSION = 1.0
  4383. 08: LIBFOO_SOURCE = libfoo-$(LIBFOO_VERSION).tar.gz
  4384. 09: LIBFOO_SITE = http://www.foosoftware.org/download
  4385. 10: LIBFOO_CONF_OPTS = --enable-bar --disable-baz
  4386. 11: LIBFOO_DEPENDENCIES = bar
  4387. 12:
  4388. 13: $(eval $(waf-package))</pre><p>On line 7, we declare the version of the package.</p><p>On line 8 and 9, we declare the name of the tarball (xz-ed tarball
  4389. recommended) and the location of the tarball on the Web. Buildroot
  4390. will automatically download the tarball from this location.</p><p>On line 10, we tell Buildroot what options to enable for libfoo.</p><p>On line 11, we tell Buildroot the dependencies of libfoo.</p><p>Finally, on line line 13, we invoke the <code class="literal">waf-package</code>
  4391. macro that generates all the Makefile rules that actually allows the
  4392. package to be built.</p></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a id="waf-package-reference"></a>18.15.2. <code class="literal">waf-package</code> reference</h3></div></div></div><p>The main macro of the Waf package infrastructure is <code class="literal">waf-package</code>.
  4393. It is similar to the <code class="literal">generic-package</code> macro.</p><p>Just like the generic infrastructure, the Waf infrastructure works
  4394. by defining a number of variables before calling the <code class="literal">waf-package</code>
  4395. macro.</p><p>All the package metadata information variables that exist in the
  4396. <a class="link" href="#generic-package-reference" title="18.6.2. generic-package reference">generic package infrastructure</a> also
  4397. exist in the Waf infrastructure.</p><p>A few additional variables, specific to the Waf infrastructure, can
  4398. also be defined.</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
  4399. <code class="literal">LIBFOO_SUBDIR</code> may contain the name of a subdirectory inside the
  4400. package that contains the main wscript file. This is useful,
  4401. if for example, the main wscript file is not at the root of
  4402. the tree extracted by the tarball. If <code class="literal">HOST_LIBFOO_SUBDIR</code> is not
  4403. specified, it defaults to <code class="literal">LIBFOO_SUBDIR</code>.
  4404. </li><li class="listitem">
  4405. <code class="literal">LIBFOO_NEEDS_EXTERNAL_WAF</code> can be set to <code class="literal">YES</code> or <code class="literal">NO</code> to tell
  4406. Buildroot to use the bundled <code class="literal">waf</code> executable. If set to <code class="literal">NO</code>, the
  4407. default, then Buildroot will use the waf executable provided in the
  4408. package source tree; if set to <code class="literal">YES</code>, then Buildroot will download,
  4409. install waf as a host tool and use it to build the package.
  4410. </li><li class="listitem">
  4411. <code class="literal">LIBFOO_WAF_OPTS</code>, to specify additional options to pass to the
  4412. <code class="literal">waf</code> script at every step of the package build process: configure,
  4413. build and installation. By default, empty.
  4414. </li><li class="listitem">
  4415. <code class="literal">LIBFOO_CONF_OPTS</code>, to specify additional options to pass to the
  4416. <code class="literal">waf</code> script for the configuration step. By default, empty.
  4417. </li><li class="listitem">
  4418. <code class="literal">LIBFOO_BUILD_OPTS</code>, to specify additional options to pass to the
  4419. <code class="literal">waf</code> script during the build step. By default, empty.
  4420. </li><li class="listitem">
  4421. <code class="literal">LIBFOO_INSTALL_STAGING_OPTS</code>, to specify additional options to pass
  4422. to the <code class="literal">waf</code> script during the staging installation step. By default,
  4423. empty.
  4424. </li><li class="listitem">
  4425. <code class="literal">LIBFOO_INSTALL_TARGET_OPTS</code>, to specify additional options to pass
  4426. to the <code class="literal">waf</code> script during the target installation step. By default,
  4427. empty.
  4428. </li></ul></div></div></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="_infrastructure_for_meson_based_packages"></a>18.16. Infrastructure for Meson-based packages</h2></div></div></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a id="meson-package-tutorial"></a>18.16.1. <code class="literal">meson-package</code> tutorial</h3></div></div></div><p><a class="ulink" href="http://mesonbuild.com" target="_top">Meson</a> is an open source build system meant to be both
  4429. extremely fast, and, even more importantly, as user friendly as possible. It
  4430. uses <a class="ulink" href="https://ninja-build.org" target="_top">Ninja</a> as a companion tool to perform the actual
  4431. build operations.</p><p>Let’s see how to write a <code class="literal">.mk</code> file for a Meson-based package, with an example:</p><pre class="screen">01: ################################################################################
  4432. 02: #
  4433. 03: # foo
  4434. 04: #
  4435. 05: ################################################################################
  4436. 06:
  4437. 07: FOO_VERSION = 1.0
  4438. 08: FOO_SOURCE = foo-$(FOO_VERSION).tar.gz
  4439. 09: FOO_SITE = http://www.foosoftware.org/download
  4440. 10: FOO_LICENSE = GPL-3.0+
  4441. 11: FOO_LICENSE_FILES = COPYING
  4442. 12: FOO_INSTALL_STAGING = YES
  4443. 13:
  4444. 14: FOO_DEPENDENCIES = host-pkgconf bar
  4445. 15:
  4446. 16: ifeq ($(BR2_PACKAGE_BAZ),y)
  4447. 17: FOO_CONF_OPTS += -Dbaz=true
  4448. 18: FOO_DEPENDENCIES += baz
  4449. 19: else
  4450. 20: FOO_CONF_OPTS += -Dbaz=false
  4451. 21: endif
  4452. 22:
  4453. 23: $(eval $(meson-package))</pre><p>The Makefile starts with the definition of the standard variables for package
  4454. declaration (lines 7 to 11).</p><p>On line line 23, we invoke the <code class="literal">meson-package</code> macro that generates all the
  4455. Makefile rules that actually allows the package to be built.</p><p>In the example, <code class="literal">host-pkgconf</code> and <code class="literal">bar</code> are declared as dependencies in
  4456. <code class="literal">FOO_DEPENDENCIES</code> at line 14 because the Meson build file of <code class="literal">foo</code> uses
  4457. <code class="literal">pkg-config</code> to determine the compilation flags and libraries of package <code class="literal">bar</code>.</p><p>Note that it is not necessary to add <code class="literal">host-meson</code> in the <code class="literal">FOO_DEPENDENCIES</code>
  4458. variable of a package, since this basic dependency is automatically added as
  4459. needed by the Meson package infrastructure.</p><p>If the "baz" package is selected, then support for the "baz" feature in "foo" is
  4460. activated by adding <code class="literal">-Dbaz=true</code> to <code class="literal">FOO_CONF_OPTS</code> at line 17, as specified in
  4461. the <code class="literal">meson_options.txt</code> file in "foo" source tree. The "baz" package is also
  4462. added to <code class="literal">FOO_DEPENDENCIES</code>. Note that the support for <code class="literal">baz</code> is explicitly
  4463. disabled at line 20, if the package is not selected.</p><p>To sum it up, to add a new meson-based package, the Makefile example can be
  4464. copied verbatim then edited to replace all occurrences of <code class="literal">FOO</code> with the
  4465. uppercase name of the new package and update the values of the standard
  4466. variables.</p></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a id="meson-package-reference"></a>18.16.2. <code class="literal">meson-package</code> reference</h3></div></div></div><p>The main macro of the Meson package infrastructure is <code class="literal">meson-package</code>. It is
  4467. similar to the <code class="literal">generic-package</code> macro. The ability to have target and host
  4468. packages is also available, with the <code class="literal">host-meson-package</code> macro.</p><p>Just like the generic infrastructure, the Meson infrastructure works by defining
  4469. a number of variables before calling the <code class="literal">meson-package</code> macro.</p><p>All the package metadata information variables that exist in the
  4470. <a class="link" href="#generic-package-reference" title="18.6.2. generic-package reference">generic package infrastructure</a> also
  4471. exist in the Meson infrastructure.</p><p>A few additional variables, specific to the Meson infrastructure, can also be
  4472. defined. Many of them are only useful in very specific cases, typical packages
  4473. will therefore only use a few of them.</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
  4474. <code class="literal">FOO_SUBDIR</code> may contain the name of a subdirectory inside the
  4475. package that contains the main meson.build file. This is useful,
  4476. if for example, the main meson.build file is not at the root of
  4477. the tree extracted by the tarball. If <code class="literal">HOST_FOO_SUBDIR</code> is not
  4478. specified, it defaults to <code class="literal">FOO_SUBDIR</code>.
  4479. </li><li class="listitem">
  4480. <code class="literal">FOO_CONF_ENV</code>, to specify additional environment variables to pass to
  4481. <code class="literal">meson</code> for the configuration step. By default, empty.
  4482. </li><li class="listitem">
  4483. <code class="literal">FOO_CONF_OPTS</code>, to specify additional options to pass to <code class="literal">meson</code> for the
  4484. configuration step. By default, empty.
  4485. </li><li class="listitem">
  4486. <code class="literal">FOO_CFLAGS</code>, to specify compiler arguments added to the package specific
  4487. <code class="literal">cross-compile.conf</code> file <code class="literal">c_args</code> property. By default, the value of
  4488. <code class="literal">TARGET_CFLAGS</code>.
  4489. </li><li class="listitem">
  4490. <code class="literal">FOO_CXXFLAGS</code>, to specify compiler arguments added to the package specific
  4491. <code class="literal">cross-compile.conf</code> file <code class="literal">cpp_args</code> property. By default, the value of
  4492. <code class="literal">TARGET_CXXFLAGS</code>.
  4493. </li><li class="listitem">
  4494. <code class="literal">FOO_LDFLAGS</code>, to specify compiler arguments added to the package specific
  4495. <code class="literal">cross-compile.conf</code> file <code class="literal">c_link_args</code> and <code class="literal">cpp_link_args</code> properties. By
  4496. default, the value of <code class="literal">TARGET_LDFLAGS</code>.
  4497. </li><li class="listitem">
  4498. <code class="literal">FOO_MESON_EXTRA_BINARIES</code>, to specify a space-separated list of programs
  4499. to add to the <code class="literal">[binaries]</code> section of the meson <code class="literal">cross-compilation.conf</code>
  4500. configuration file. The format is <code class="literal">program-name='/path/to/program'</code>, with
  4501. no space around the <code class="literal">=</code> sign, and with the path of the program between
  4502. single quotes. By default, empty. Note that Buildroot already sets the
  4503. correct values for <code class="literal">c</code>, <code class="literal">cpp</code>, <code class="literal">ar</code>, <code class="literal">strip</code>, and <code class="literal">pkgconfig</code>.
  4504. </li><li class="listitem">
  4505. <code class="literal">FOO_MESON_EXTRA_PROPERTIES</code>, to specify a space-separated list of
  4506. properties to add to the <code class="literal">[properties]</code> section of the meson
  4507. <code class="literal">cross-compilation.conf</code> configuration file. The format is
  4508. <code class="literal">property-name=&lt;value&gt;</code> with no space around the <code class="literal">=</code> sign, and with
  4509. single quotes around string values. By default, empty. Note that
  4510. Buildroot already sets values for <code class="literal">needs_exe_wrapper</code>, <code class="literal">c_args</code>,
  4511. <code class="literal">c_link_args</code>, <code class="literal">cpp_args</code>, <code class="literal">cpp_link_args</code>, <code class="literal">sys_root</code>, and
  4512. <code class="literal">pkg_config_libdir</code>.
  4513. </li><li class="listitem">
  4514. <code class="literal">FOO_NINJA_ENV</code>, to specify additional environment variables to pass to
  4515. <code class="literal">ninja</code>, meson companion tool in charge of the build operations. By default,
  4516. empty.
  4517. </li><li class="listitem">
  4518. <code class="literal">FOO_NINJA_OPTS</code>, to specify a space-separated list of targets to build. By
  4519. default, empty, to build the default target(s).
  4520. </li></ul></div></div></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="_infrastructure_for_cargo_based_packages"></a>18.17. Infrastructure for Cargo-based packages</h2></div></div></div><p>Cargo is the package manager for the Rust programming language. It allows the
  4521. user to build programs or libraries written in Rust, but it also downloads and
  4522. manages their dependencies, to ensure repeatable builds. Cargo packages are
  4523. called "crates".</p><div class="section"><div class="titlepage"><div><div><h3 class="title"><a id="cargo-package-tutorial"></a>18.17.1. <code class="literal">cargo-package</code> tutorial</h3></div></div></div><p>The <code class="literal">Config.in</code> file of Cargo-based package <span class="emphasis"><em>foo</em></span> should contain:</p><pre class="screen">01: config BR2_PACKAGE_FOO
  4524. 02: bool "foo"
  4525. 03: depends on BR2_PACKAGE_HOST_RUSTC_TARGET_ARCH_SUPPORTS
  4526. 04: select BR2_PACKAGE_HOST_RUSTC
  4527. 05: help
  4528. 06: This is a comment that explains what foo is.
  4529. 07:
  4530. 08: http://foosoftware.org/foo/</pre><p>And the <code class="literal">.mk</code> file for this package should contain:</p><pre class="screen">01: ################################################################################
  4531. 02: #
  4532. 03: # foo
  4533. 04: #
  4534. 05: ################################################################################
  4535. 06:
  4536. 07: FOO_VERSION = 1.0
  4537. 08: FOO_SOURCE = foo-$(FOO_VERSION).tar.gz
  4538. 09: FOO_SITE = http://www.foosoftware.org/download
  4539. 10: FOO_LICENSE = GPL-3.0+
  4540. 11: FOO_LICENSE_FILES = COPYING
  4541. 12:
  4542. 13: $(eval $(cargo-package))</pre><p>The Makefile starts with the definition of the standard variables for
  4543. package declaration (lines 7 to 11).</p><p>As seen in line 13, it is based on the <code class="literal">cargo-package</code>
  4544. infrastructure. Cargo will be invoked automatically by this
  4545. infrastructure to build and install the package.</p><p>It is still possible to define custom build commands or install
  4546. commands (i.e. with FOO_BUILD_CMDS and FOO_INSTALL_TARGET_CMDS).
  4547. Those will then replace the commands from the cargo infrastructure.</p></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a id="_literal_cargo_package_literal_reference"></a>18.17.2. <code class="literal">cargo-package</code> reference</h3></div></div></div><p>The main macros for the Cargo package infrastructure are
  4548. <code class="literal">cargo-package</code> for target packages and <code class="literal">host-cargo-package</code> for host
  4549. packages.</p><p>Just like the generic infrastructure, the Cargo infrastructure works
  4550. by defining a number of variables before calling the <code class="literal">cargo-package</code>
  4551. or <code class="literal">host-cargo-package</code> macros.</p><p>All the package metadata information variables that exist in the
  4552. <a class="link" href="#generic-package-reference" title="18.6.2. generic-package reference">generic package infrastructure</a> also
  4553. exist in the Cargo infrastructure.</p><p>A few additional variables, specific to the Cargo infrastructure, can
  4554. also be defined. Many of them are only useful in very specific cases,
  4555. typical packages will therefore only use a few of them.</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
  4556. <code class="literal">FOO_SUBDIR</code> may contain the name of a subdirectory inside the package
  4557. that contains the Cargo.toml file. This is useful, if for example, it
  4558. is not at the root of the tree extracted by the tarball. If
  4559. <code class="literal">HOST_FOO_SUBDIR</code> is not specified, it defaults to <code class="literal">FOO_SUBDIR</code>.
  4560. </li><li class="listitem">
  4561. <code class="literal">FOO_CARGO_ENV</code> can be used to pass additional variables in the
  4562. environment of <code class="literal">cargo</code> invocations. It used at both build and
  4563. installation time
  4564. </li><li class="listitem">
  4565. <code class="literal">FOO_CARGO_BUILD_OPTS</code> can be used to pass additional options to
  4566. <code class="literal">cargo</code> at build time.
  4567. </li><li class="listitem">
  4568. <code class="literal">FOO_CARGO_INSTALL_OPTS</code> can be used to pass additional options to
  4569. <code class="literal">cargo</code> at install time.
  4570. </li></ul></div><p>A crate can depend on other libraries from crates.io or git
  4571. repositories, listed in its <code class="literal">Cargo.toml</code> file. Buildroot automatically
  4572. takes care of downloading such dependencies as part of the download
  4573. step of packages that use the <code class="literal">cargo-package</code> infrastructure. Such
  4574. dependencies are then kept together with the package source code in
  4575. the tarball cached in Buildroot’s <code class="literal">DL_DIR</code>, and therefore the hash of
  4576. the package’s tarball includes such dependencies.</p><p>This mechanism ensures that any change in the dependencies will be
  4577. detected, and allows the build to be performed completely offline.</p></div></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="_infrastructure_for_go_packages"></a>18.18. Infrastructure for Go packages</h2></div></div></div><p>This infrastructure applies to Go packages that use the standard
  4578. build system and use bundled dependencies.</p><div class="section"><div class="titlepage"><div><div><h3 class="title"><a id="golang-package-tutorial"></a>18.18.1. <code class="literal">golang-package</code> tutorial</h3></div></div></div><p>First, let’s see how to write a <code class="literal">.mk</code> file for a go package,
  4579. with an example :</p><pre class="screen">01: ################################################################################
  4580. 02: #
  4581. 03: # foo
  4582. 04: #
  4583. 05: ################################################################################
  4584. 06:
  4585. 07: FOO_VERSION = 1.0
  4586. 08: FOO_SITE = $(call github,bar,foo,$(FOO_VERSION))
  4587. 09: FOO_LICENSE = BSD-3-Clause
  4588. 10: FOO_LICENSE_FILES = LICENSE
  4589. 11:
  4590. 12: $(eval $(golang-package))</pre><p>On line 7, we declare the version of the package.</p><p>On line 8, we declare the upstream location of the package, here
  4591. fetched from Github, since a large number of Go packages are hosted on
  4592. Github.</p><p>On line 9 and 10, we give licensing details about the package.</p><p>Finally, on line 12, we invoke the <code class="literal">golang-package</code> macro that
  4593. generates all the Makefile rules that actually allow the package to be
  4594. built.</p></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a id="golang-package-reference"></a>18.18.2. <code class="literal">golang-package</code> reference</h3></div></div></div><p>In their <code class="literal">Config.in</code> file, packages using the <code class="literal">golang-package</code>
  4595. infrastructure should depend on <code class="literal">BR2_PACKAGE_HOST_GO_TARGET_ARCH_SUPPORTS</code>
  4596. because Buildroot will automatically add a dependency on <code class="literal">host-go</code>
  4597. to such packages.
  4598. If you need CGO support in your package, you must add a dependency on
  4599. <code class="literal">BR2_PACKAGE_HOST_GO_TARGET_CGO_LINKING_SUPPORTS</code>.</p><p>The main macro of the Go package infrastructure is
  4600. <code class="literal">golang-package</code>. It is similar to the <code class="literal">generic-package</code> macro. The
  4601. ability to build host packages is also available, with the
  4602. <code class="literal">host-golang-package</code> macro.
  4603. Host packages built by <code class="literal">host-golang-package</code> macro should depend on
  4604. <code class="literal">BR2_PACKAGE_HOST_GO_HOST_ARCH_SUPPORTS</code>.</p><p>Just like the generic infrastructure, the Go infrastructure works
  4605. by defining a number of variables before calling the <code class="literal">golang-package</code>
  4606. macro.</p><p>All the package metadata information variables that exist in the
  4607. <a class="link" href="#generic-package-reference" title="18.6.2. generic-package reference">generic package infrastructure</a> also
  4608. exist in the Go infrastructure.</p><p>Note that it is not necessary to add <code class="literal">host-go</code> in the
  4609. <code class="literal">FOO_DEPENDENCIES</code> variable of a package, since this basic dependency
  4610. is automatically added as needed by the Go package infrastructure.</p><p>A few additional variables, specific to the Go infrastructure, can
  4611. optionally be defined, depending on the package’s needs. Many of them
  4612. are only useful in very specific cases, typical packages will
  4613. therefore only use a few of them, or none.</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
  4614. The package must specify its Go module name in the <code class="literal">FOO_GOMOD</code>
  4615. variable. If not specified, it defaults to
  4616. <code class="literal">URL-domain/1st-part-of-URL/2nd-part-of-URL</code>, e.g <code class="literal">FOO_GOMOD</code> will
  4617. take the value <code class="literal">github.com/bar/foo</code> for a package that specifies
  4618. <code class="literal">FOO_SITE = $(call github,bar,foo,$(FOO_VERSION))</code>. The Go package
  4619. infrastructure will automatically generate a minimal <code class="literal">go.mod</code> file
  4620. in the package source tree if it doesn’t exist.
  4621. </li><li class="listitem">
  4622. <code class="literal">FOO_LDFLAGS</code> and <code class="literal">FOO_TAGS</code> can be used to pass respectively the
  4623. <code class="literal">LDFLAGS</code> or the <code class="literal">TAGS</code> to the <code class="literal">go</code> build command.
  4624. </li><li class="listitem"><p class="simpara">
  4625. <code class="literal">FOO_BUILD_TARGETS</code> can be used to pass the list of targets that
  4626. should be built. If <code class="literal">FOO_BUILD_TARGETS</code> is not specified, it
  4627. defaults to <code class="literal">.</code>. We then have two cases:
  4628. </p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: circle; "><li class="listitem">
  4629. <code class="literal">FOO_BUILD_TARGETS</code> is <code class="literal">.</code>. In this case, we assume only one binary
  4630. will be produced, and that by default we name it after the package
  4631. name. If that is not appropriate, the name of the produced binary
  4632. can be overridden using <code class="literal">FOO_BIN_NAME</code>.
  4633. </li><li class="listitem">
  4634. <code class="literal">FOO_BUILD_TARGETS</code> is not <code class="literal">.</code>. In this case, we iterate over the
  4635. values to build each target, and for each produced a binary that is
  4636. the non-directory component of the target. For example if
  4637. <code class="literal">FOO_BUILD_TARGETS = cmd/docker cmd/dockerd</code> the binaries produced
  4638. are <code class="literal">docker</code> and <code class="literal">dockerd</code>.
  4639. </li></ul></div></li><li class="listitem">
  4640. <code class="literal">FOO_INSTALL_BINS</code> can be used to pass the list of binaries that
  4641. should be installed in <code class="literal">/usr/bin</code> on the target. If
  4642. <code class="literal">FOO_INSTALL_BINS</code> is not specified, it defaults to the lower-case
  4643. name of package.
  4644. </li></ul></div><p>With the Go infrastructure, all the steps required to build and
  4645. install the packages are already defined, and they generally work well
  4646. for most Go-based packages. However, when required, it is still
  4647. possible to customize what is done in any particular step:</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
  4648. By adding a post-operation hook (after extract, patch, configure,
  4649. build or install). See <a class="xref" href="#hooks" title="18.23. Hooks available in the various build steps">Section 18.23, “Hooks available in the various build steps”</a> for details.
  4650. </li><li class="listitem">
  4651. By overriding one of the steps. For example, even if the Go
  4652. infrastructure is used, if the package <code class="literal">.mk</code> file defines its own
  4653. <code class="literal">FOO_BUILD_CMDS</code> variable, it will be used instead of the default Go
  4654. one. However, using this method should be restricted to very
  4655. specific cases. Do not use it in the general case.
  4656. </li></ul></div><p>A Go package can depend on other Go modules, listed in its <code class="literal">go.mod</code>
  4657. file. Buildroot automatically takes care of downloading such
  4658. dependencies as part of the download step of packages that use the
  4659. <code class="literal">golang-package</code> infrastructure. Such dependencies are then kept
  4660. together with the package source code in the tarball cached in
  4661. Buildroot’s <code class="literal">DL_DIR</code>, and therefore the hash of the package’s tarball
  4662. includes such dependencies.</p><p>This mechanism ensures that any change in the dependencies will be
  4663. detected, and allows the build to be performed completely offline.</p></div></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="_infrastructure_for_qmake_based_packages"></a>18.19. Infrastructure for QMake-based packages</h2></div></div></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a id="qmake-package-tutorial"></a>18.19.1. <code class="literal">qmake-package</code> tutorial</h3></div></div></div><p>First, let’s see how to write a <code class="literal">.mk</code> file for a QMake-based package, with
  4664. an example :</p><pre class="screen">01: ################################################################################
  4665. 02: #
  4666. 03: # libfoo
  4667. 04: #
  4668. 05: ################################################################################
  4669. 06:
  4670. 07: LIBFOO_VERSION = 1.0
  4671. 08: LIBFOO_SOURCE = libfoo-$(LIBFOO_VERSION).tar.gz
  4672. 09: LIBFOO_SITE = http://www.foosoftware.org/download
  4673. 10: LIBFOO_CONF_OPTS = QT_CONFIG+=bar QT_CONFIG-=baz
  4674. 11: LIBFOO_DEPENDENCIES = bar
  4675. 12:
  4676. 13: $(eval $(qmake-package))</pre><p>On line 7, we declare the version of the package.</p><p>On line 8 and 9, we declare the name of the tarball (xz-ed tarball
  4677. recommended) and the location of the tarball on the Web. Buildroot
  4678. will automatically download the tarball from this location.</p><p>On line 10, we tell Buildroot what options to enable for libfoo.</p><p>On line 11, we tell Buildroot the dependencies of libfoo.</p><p>Finally, on line line 13, we invoke the <code class="literal">qmake-package</code>
  4679. macro that generates all the Makefile rules that actually allows the
  4680. package to be built.</p></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a id="qmake-package-reference"></a>18.19.2. <code class="literal">qmake-package</code> reference</h3></div></div></div><p>The main macro of the QMake package infrastructure is <code class="literal">qmake-package</code>.
  4681. It is similar to the <code class="literal">generic-package</code> macro.</p><p>Just like the generic infrastructure, the QMake infrastructure works
  4682. by defining a number of variables before calling the <code class="literal">qmake-package</code>
  4683. macro.</p><p>All the package metadata information variables that exist in the
  4684. <a class="link" href="#generic-package-reference" title="18.6.2. generic-package reference">generic package infrastructure</a> also
  4685. exist in the QMake infrastructure.</p><p>A few additional variables, specific to the QMake infrastructure, can
  4686. also be defined.</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
  4687. <code class="literal">LIBFOO_CONF_ENV</code>, to specify additional environment variables to
  4688. pass to the <code class="literal">qmake</code> script for the configuration step. By default, empty.
  4689. </li><li class="listitem">
  4690. <code class="literal">LIBFOO_CONF_OPTS</code>, to specify additional options to pass to the
  4691. <code class="literal">qmake</code> script for the configuration step. By default, empty.
  4692. </li><li class="listitem">
  4693. <code class="literal">LIBFOO_MAKE_ENV</code>, to specify additional environment variables to the
  4694. <code class="literal">make</code> command during the build and install steps. By default, empty.
  4695. </li><li class="listitem">
  4696. <code class="literal">LIBFOO_MAKE_OPTS</code>, to specify additional targets to pass to the
  4697. <code class="literal">make</code> command during the build step. By default, empty.
  4698. </li><li class="listitem">
  4699. <code class="literal">LIBFOO_INSTALL_STAGING_OPTS</code>, to specify additional targets to pass
  4700. to the <code class="literal">make</code> command during the staging installation step. By default,
  4701. <code class="literal">install</code>.
  4702. </li><li class="listitem">
  4703. <code class="literal">LIBFOO_INSTALL_TARGET_OPTS</code>, to specify additional targets to pass
  4704. to the <code class="literal">make</code> command during the target installation step. By default,
  4705. <code class="literal">install</code>.
  4706. </li><li class="listitem">
  4707. <code class="literal">LIBFOO_SYNC_QT_HEADERS</code>, to run syncqt.pl before qmake. Some packages
  4708. need this to have a properly populated include directory before
  4709. running the build.
  4710. </li></ul></div></div></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="_infrastructure_for_packages_building_kernel_modules"></a>18.20. Infrastructure for packages building kernel modules</h2></div></div></div><p>Buildroot offers a helper infrastructure to make it easy to write packages that
  4711. build and install Linux kernel modules. Some packages only contain a kernel
  4712. module, other packages contain programs and libraries in addition to kernel
  4713. modules. Buildroot’s helper infrastructure supports either case.</p><div class="section"><div class="titlepage"><div><div><h3 class="title"><a id="kernel-module-tutorial"></a>18.20.1. <code class="literal">kernel-module</code> tutorial</h3></div></div></div><p>Let’s start with an example on how to prepare a simple package that only
  4714. builds a kernel module, and no other component:</p><pre class="screen">01: ################################################################################
  4715. 02: #
  4716. 03: # foo
  4717. 04: #
  4718. 05: ################################################################################
  4719. 06:
  4720. 07: FOO_VERSION = 1.2.3
  4721. 08: FOO_SOURCE = foo-$(FOO_VERSION).tar.xz
  4722. 09: FOO_SITE = http://www.foosoftware.org/download
  4723. 10: FOO_LICENSE = GPL-2.0
  4724. 11: FOO_LICENSE_FILES = COPYING
  4725. 12:
  4726. 13: $(eval $(kernel-module))
  4727. 14: $(eval $(generic-package))</pre><p>Lines 7-11 define the usual meta-data to specify the version, archive name,
  4728. remote URI where to find the package source, licensing information.</p><p>On line 13, we invoke the <code class="literal">kernel-module</code> helper infrastructure, that
  4729. generates all the appropriate Makefile rules and variables to build
  4730. that kernel module.</p><p>Finally, on line 14, we invoke the
  4731. <a class="link" href="#generic-package-tutorial" title="18.6.1. generic-package tutorial"><code class="literal">generic-package</code> infrastructure</a>.</p><p>The dependency on <code class="literal">linux</code> is automatically added, so it is not needed to
  4732. specify it in <code class="literal">FOO_DEPENDENCIES</code>.</p><p>What you may have noticed is that, unlike other package infrastructures,
  4733. we explicitly invoke a second infrastructure. This allows a package to
  4734. build a kernel module, but also, if needed, use any one of other package
  4735. infrastructures to build normal userland components (libraries,
  4736. executables…). Using the <code class="literal">kernel-module</code> infrastructure on its own is
  4737. not sufficient; another package infrastructure <span class="strong"><strong>must</strong></span> be used.</p><p>Let’s look at a more complex example:</p><pre class="screen">01: ################################################################################
  4738. 02: #
  4739. 03: # foo
  4740. 04: #
  4741. 05: ################################################################################
  4742. 06:
  4743. 07: FOO_VERSION = 1.2.3
  4744. 08: FOO_SOURCE = foo-$(FOO_VERSION).tar.xz
  4745. 09: FOO_SITE = http://www.foosoftware.org/download
  4746. 10: FOO_LICENSE = GPL-2.0
  4747. 11: FOO_LICENSE_FILES = COPYING
  4748. 12:
  4749. 13: FOO_MODULE_SUBDIRS = driver/base
  4750. 14: FOO_MODULE_MAKE_OPTS = KVERSION=$(LINUX_VERSION_PROBED)
  4751. 15:
  4752. 16: ifeq ($(BR2_PACKAGE_LIBBAR),y)
  4753. 17: FOO_DEPENDENCIES += libbar
  4754. 18: FOO_CONF_OPTS += --enable-bar
  4755. 19: FOO_MODULE_SUBDIRS += driver/bar
  4756. 20: else
  4757. 21: FOO_CONF_OPTS += --disable-bar
  4758. 22: endif
  4759. 23:
  4760. 24: $(eval $(kernel-module))
  4761. 26: $(eval $(autotools-package))</pre><p>Here, we see that we have an autotools-based package, that also builds
  4762. the kernel module located in sub-directory <code class="literal">driver/base</code> and, if libbar
  4763. is enabled, the kernel module located in sub-directory <code class="literal">driver/bar</code>, and
  4764. defines the variable <code class="literal">KVERSION</code> to be passed to the Linux buildsystem
  4765. when building the module(s).</p></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a id="kernel-module-reference"></a>18.20.2. <code class="literal">kernel-module</code> reference</h3></div></div></div><p>The main macro for the kernel module infrastructure is <code class="literal">kernel-module</code>.
  4766. Unlike other package infrastructures, it is not stand-alone, and requires
  4767. any of the other <code class="literal">*-package</code> macros be called after it.</p><p>The <code class="literal">kernel-module</code> macro defines post-build and post-target-install
  4768. hooks to build the kernel modules. If the package’s <code class="literal">.mk</code> needs access
  4769. to the built kernel modules, it should do so in a post-build hook,
  4770. <span class="strong"><strong>registered after</strong></span> the call to <code class="literal">kernel-module</code>. Similarly, if the
  4771. package’s <code class="literal">.mk</code> needs access to the kernel module after it has been
  4772. installed, it should do so in a post-install hook, <span class="strong"><strong>registered after</strong></span>
  4773. the call to <code class="literal">kernel-module</code>. Here’s an example:</p><pre class="screen">$(eval $(kernel-module))
  4774. define FOO_DO_STUFF_WITH_KERNEL_MODULE
  4775. # Do something with it...
  4776. endef
  4777. FOO_POST_BUILD_HOOKS += FOO_DO_STUFF_WITH_KERNEL_MODULE
  4778. $(eval $(generic-package))</pre><p>Finally, unlike the other package infrastructures, there is no
  4779. <code class="literal">host-kernel-module</code> variant to build a host kernel module.</p><p>The following additional variables can optionally be defined to further
  4780. configure the build of the kernel module:</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
  4781. <code class="literal">FOO_MODULE_SUBDIRS</code> may be set to one or more sub-directories (relative
  4782. to the package source top-directory) where the kernel module sources are.
  4783. If empty or not set, the sources for the kernel module(s) are considered
  4784. to be located at the top of the package source tree.
  4785. </li><li class="listitem">
  4786. <code class="literal">FOO_MODULE_MAKE_OPTS</code> may be set to contain extra variable definitions
  4787. to pass to the Linux buildsystem.
  4788. </li></ul></div><p><a id="kernel-variables"></a>You may also reference (but you may <span class="strong"><strong>not</strong></span> set!) those variables:</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
  4789. <code class="literal">LINUX_DIR</code> contains the path to where the Linux kernel has been
  4790. extracted and built.
  4791. </li><li class="listitem">
  4792. <code class="literal">LINUX_VERSION</code> contains the version string as configured by the user.
  4793. </li><li class="listitem">
  4794. <code class="literal">LINUX_VERSION_PROBED</code> contains the real version string of the kernel,
  4795. retrieved with running <code class="literal">make -C $(LINUX_DIR) kernelrelease</code>
  4796. </li><li class="listitem">
  4797. <code class="literal">KERNEL_ARCH</code> contains the name of the current architecture, like <code class="literal">arm</code>,
  4798. <code class="literal">mips</code>…
  4799. </li></ul></div></div></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="_infrastructure_for_asciidoc_documents"></a>18.21. Infrastructure for asciidoc documents</h2></div></div></div><p><a id="asciidoc-documents-tutorial"></a>The Buildroot manual, which you are currently reading, is entirely written
  4800. using the <a class="ulink" href="http://asciidoc.org/" target="_top">AsciiDoc</a> mark-up syntax. The manual is then
  4801. rendered to many formats:</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
  4802. html
  4803. </li><li class="listitem">
  4804. split-html
  4805. </li><li class="listitem">
  4806. pdf
  4807. </li><li class="listitem">
  4808. epub
  4809. </li><li class="listitem">
  4810. text
  4811. </li></ul></div><p>Although Buildroot only contains one document written in AsciiDoc, there
  4812. is, as for packages, an infrastructure for rendering documents using the
  4813. AsciiDoc syntax.</p><p>Also as for packages, the AsciiDoc infrastructure is available from a
  4814. <a class="link" href="#outside-br-custom" title="9.2. Keeping customizations outside of Buildroot">br2-external tree</a>. This allows documentation for
  4815. a br2-external tree to match the Buildroot documentation, as it will be
  4816. rendered to the same formats and use the same layout and theme.</p><div class="section"><div class="titlepage"><div><div><h3 class="title"><a id="_literal_asciidoc_document_literal_tutorial"></a>18.21.1. <code class="literal">asciidoc-document</code> tutorial</h3></div></div></div><p>Whereas package infrastructures are suffixed with <code class="literal">-package</code>, the document
  4817. infrastructures are suffixed with <code class="literal">-document</code>. So, the AsciiDoc infrastructure
  4818. is named <code class="literal">asciidoc-document</code>.</p><p>Here is an example to render a simple AsciiDoc document.</p><pre class="screen">01: ################################################################################
  4819. 02: #
  4820. 03: # foo-document
  4821. 04: #
  4822. 05: ################################################################################
  4823. 06:
  4824. 07: FOO_SOURCES = $(sort $(wildcard $(FOO_DOCDIR)/*))
  4825. 08: $(eval $(call asciidoc-document))</pre><p>On line 7, the Makefile declares what the sources of the document are.
  4826. Currently, it is expected that the document’s sources are only local;
  4827. Buildroot will not attempt to download anything to render a document.
  4828. Thus, you must indicate where the sources are. Usually, the string
  4829. above is sufficient for a document with no sub-directory structure.</p><p>On line 8, we call the <code class="literal">asciidoc-document</code> function, which generates all
  4830. the Makefile code necessary to render the document.</p></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a id="_literal_asciidoc_document_literal_reference"></a>18.21.2. <code class="literal">asciidoc-document</code> reference</h3></div></div></div><p>The list of variables that can be set in a <code class="literal">.mk</code> file to give metadata
  4831. information is (assuming the document name is <code class="literal">foo</code>) :</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
  4832. <code class="literal">FOO_SOURCES</code>, mandatory, defines the source files for the document.
  4833. </li><li class="listitem">
  4834. <code class="literal">FOO_RESOURCES</code>, optional, may contain a space-separated list of paths
  4835. to one or more directories containing so-called resources (like CSS or
  4836. images). By default, empty.
  4837. </li><li class="listitem">
  4838. <code class="literal">FOO_DEPENDENCIES</code>, optional, the list of packages (most probably,
  4839. host-packages) that must be built before building this document.
  4840. </li><li class="listitem">
  4841. <code class="literal">FOO_TOC_DEPTH</code>, <code class="literal">FOO_TOC_DEPTH_&lt;FMT&gt;</code>, optionals, the depth of the
  4842. table of content for this document, which can be overridden for the
  4843. specified format <code class="literal">&lt;FMT&gt;</code> (see the list of rendered formats, above,
  4844. but in uppercase, and with dash replaced by underscore; see example,
  4845. below). By default: <code class="literal">1</code>.
  4846. </li></ul></div><p>There are also additional hooks (see <a class="xref" href="#hooks" title="18.23. Hooks available in the various build steps">Section 18.23, “Hooks available in the various build steps”</a> for general information
  4847. on hooks), that a document may set to define extra actions to be done at
  4848. various steps:</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
  4849. <code class="literal">FOO_POST_RSYNC_HOOKS</code> to run additional commands after the sources
  4850. have been copied by Buildroot. This can for example be used to
  4851. generate part of the manual with information extracted from the
  4852. tree. As an example, Buildroot uses this hook to generate the tables
  4853. in the appendices.
  4854. </li><li class="listitem">
  4855. <code class="literal">FOO_CHECK_DEPENDENCIES_HOOKS</code> to run additional tests on required
  4856. components to generate the document. In AsciiDoc, it is possible to
  4857. call filters, that is, programs that will parse an AsciiDoc block and
  4858. render it appropriately (e.g. <a class="ulink" href="http://ditaa.sourceforge.net/" target="_top">ditaa</a> or
  4859. <a class="ulink" href="https://pythonhosted.org/aafigure/" target="_top">aafigure</a>).
  4860. </li><li class="listitem">
  4861. <code class="literal">FOO_CHECK_DEPENDENCIES_&lt;FMT&gt;_HOOKS</code>, to run additional tests for
  4862. the specified format <code class="literal">&lt;FMT&gt;</code> (see the list of rendered formats, above).
  4863. </li></ul></div><p>Buildroot sets the following variable that can be used in the definitions
  4864. above:</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
  4865. <code class="literal">$(FOO_DOCDIR)</code>, similar to <code class="literal">$(FOO_PKGDIR)</code>, contains the path to the
  4866. directory containing <code class="literal">foo.mk</code>. It can be used to refer to the document
  4867. sources, and can be used in the hooks, especially the post-rsync hook
  4868. if parts of the documentation needs to be generated.
  4869. </li><li class="listitem">
  4870. <code class="literal">$(@D)</code>, as for traditional packages, contains the path to the directory
  4871. where the document will be copied and built.
  4872. </li></ul></div><p>Here is a complete example that uses all variables and all hooks:</p><pre class="screen">01: ################################################################################
  4873. 02: #
  4874. 03: # foo-document
  4875. 04: #
  4876. 05: ################################################################################
  4877. 06:
  4878. 07: FOO_SOURCES = $(sort $(wildcard $(FOO_DOCDIR)/*))
  4879. 08: FOO_RESOURCES = $(sort $(wildcard $(FOO_DOCDIR)/resources))
  4880. 09:
  4881. 10: FOO_TOC_DEPTH = 2
  4882. 11: FOO_TOC_DEPTH_HTML = 1
  4883. 12: FOO_TOC_DEPTH_SPLIT_HTML = 3
  4884. 13:
  4885. 14: define FOO_GEN_EXTRA_DOC
  4886. 15: /path/to/generate-script --outdir=$(@D)
  4887. 16: endef
  4888. 17: FOO_POST_RSYNC_HOOKS += FOO_GEN_EXTRA_DOC
  4889. 18:
  4890. 19: define FOO_CHECK_MY_PROG
  4891. 20: if ! which my-prog &gt;/dev/null 2&gt;&amp;1; then \
  4892. 21: echo "You need my-prog to generate the foo document"; \
  4893. 22: exit 1; \
  4894. 23: fi
  4895. 24: endef
  4896. 25: FOO_CHECK_DEPENDENCIES_HOOKS += FOO_CHECK_MY_PROG
  4897. 26:
  4898. 27: define FOO_CHECK_MY_OTHER_PROG
  4899. 28: if ! which my-other-prog &gt;/dev/null 2&gt;&amp;1; then \
  4900. 29: echo "You need my-other-prog to generate the foo document as PDF"; \
  4901. 30: exit 1; \
  4902. 31: fi
  4903. 32: endef
  4904. 33: FOO_CHECK_DEPENDENCIES_PDF_HOOKS += FOO_CHECK_MY_OTHER_PROG
  4905. 34:
  4906. 35: $(eval $(call asciidoc-document))</pre></div></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="linux-kernel-specific-infra"></a>18.22. Infrastructure specific to the Linux kernel package</h2></div></div></div><p>The Linux kernel package can use some specific infrastructures based on package
  4907. hooks for building Linux kernel tools or/and building Linux kernel extensions.</p><div class="section"><div class="titlepage"><div><div><h3 class="title"><a id="linux-kernel-tools"></a>18.22.1. linux-kernel-tools</h3></div></div></div><p>Buildroot offers a helper infrastructure to build some userspace tools
  4908. for the target available within the Linux kernel sources. Since their
  4909. source code is part of the kernel source code, a special package,
  4910. <code class="literal">linux-tools</code>, exists and re-uses the sources of the Linux kernel that
  4911. runs on the target.</p><p>Let’s look at an example of a Linux tool. For a new Linux tool named
  4912. <code class="literal">foo</code>, create a new menu entry in the existing
  4913. <code class="literal">package/linux-tools/Config.in</code>. This file will contain the option
  4914. descriptions related to each kernel tool that will be used and
  4915. displayed in the configuration tool. It would basically look like:</p><pre class="screen">01: config BR2_PACKAGE_LINUX_TOOLS_FOO
  4916. 02: bool "foo"
  4917. 03: select BR2_PACKAGE_LINUX_TOOLS
  4918. 04: help
  4919. 05: This is a comment that explains what foo kernel tool is.
  4920. 06:
  4921. 07: http://foosoftware.org/foo/</pre><p>The name of the option starts with the prefix <code class="literal">BR2_PACKAGE_LINUX_TOOLS_</code>,
  4922. followed by the uppercase name of the tool (like is done for packages).</p><p><strong>Note. </strong>Unlike other packages, the <code class="literal">linux-tools</code> package options appear in the
  4923. <code class="literal">linux</code> kernel menu, under the <code class="literal">Linux Kernel Tools</code> sub-menu, not under
  4924. the <code class="literal">Target packages</code> main menu.</p><p>Then for each linux tool, add a new <code class="literal">.mk.in</code> file named
  4925. <code class="literal">package/linux-tools/linux-tool-foo.mk.in</code>. It would basically look like:</p><pre class="screen">01: ################################################################################
  4926. 02: #
  4927. 03: # foo
  4928. 04: #
  4929. 05: ################################################################################
  4930. 06:
  4931. 07: LINUX_TOOLS += foo
  4932. 08:
  4933. 09: FOO_DEPENDENCIES = libbbb
  4934. 10:
  4935. 11: define FOO_BUILD_CMDS
  4936. 12: $(TARGET_MAKE_ENV) $(MAKE) -C $(LINUX_DIR)/tools foo
  4937. 13: endef
  4938. 14:
  4939. 15: define FOO_INSTALL_STAGING_CMDS
  4940. 16: $(TARGET_MAKE_ENV) $(MAKE) -C $(LINUX_DIR)/tools \
  4941. 17: DESTDIR=$(STAGING_DIR) \
  4942. 18: foo_install
  4943. 19: endef
  4944. 20:
  4945. 21: define FOO_INSTALL_TARGET_CMDS
  4946. 22: $(TARGET_MAKE_ENV) $(MAKE) -C $(LINUX_DIR)/tools \
  4947. 23: DESTDIR=$(TARGET_DIR) \
  4948. 24: foo_install
  4949. 25: endef</pre><p>On line 7, we register the Linux tool <code class="literal">foo</code> to the list of available
  4950. Linux tools.</p><p>On line 9, we specify the list of dependencies this tool relies on. These
  4951. dependencies are added to the Linux package dependencies list only when the
  4952. <code class="literal">foo</code> tool is selected.</p><p>The rest of the Makefile, lines 11-25 defines what should be done at the
  4953. different steps of the Linux tool build process like for a
  4954. <a class="link" href="#generic-package-tutorial" title="18.6.1. generic-package tutorial"><code class="literal">generic package</code></a>. They will actually be
  4955. used only when the <code class="literal">foo</code> tool is selected. The only supported commands are
  4956. <code class="literal">_BUILD_CMDS</code>, <code class="literal">_INSTALL_STAGING_CMDS</code> and <code class="literal">_INSTALL_TARGET_CMDS</code>.</p><p><strong>Note. </strong>One <span class="strong"><strong>must not</strong></span> call <code class="literal">$(eval $(generic-package))</code> or any other
  4957. package infrastructure! Linux tools are not packages by themselves,
  4958. they are part of the <code class="literal">linux-tools</code> package.</p></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a id="linux-kernel-ext"></a>18.22.2. linux-kernel-extensions</h3></div></div></div><p>Some packages provide new features that require the Linux kernel tree
  4959. to be modified. This can be in the form of patches to be applied on
  4960. the kernel tree, or in the form of new files to be added to the
  4961. tree. The Buildroot’s Linux kernel extensions infrastructure provides
  4962. a simple solution to automatically do this, just after the kernel
  4963. sources are extracted and before the kernel patches are
  4964. applied. Examples of extensions packaged using this mechanism are the
  4965. real-time extensions Xenomai and RTAI, as well as the set of
  4966. out-of-tree LCD screens drivers <code class="literal">fbtft</code>.</p><p>Let’s look at an example on how to add a new Linux extension <code class="literal">foo</code>.</p><p>First, create the package <code class="literal">foo</code> that provides the extension: this
  4967. package is a standard package; see the previous chapters on how to
  4968. create such a package. This package is in charge of downloading the
  4969. sources archive, checking the hash, defining the licence information
  4970. and building user space tools if any.</p><p>Then create the <span class="emphasis"><em>Linux extension</em></span> proper: create a new menu entry in
  4971. the existing <code class="literal">linux/Config.ext.in</code>. This file contains the option
  4972. descriptions related to each kernel extension that will be used and
  4973. displayed in the configuration tool. It would basically look like:</p><pre class="screen">01: config BR2_LINUX_KERNEL_EXT_FOO
  4974. 02: bool "foo"
  4975. 03: help
  4976. 04: This is a comment that explains what foo kernel extension is.
  4977. 05:
  4978. 06: http://foosoftware.org/foo/</pre><p>Then for each linux extension, add a new <code class="literal">.mk</code> file named
  4979. <code class="literal">linux/linux-ext-foo.mk</code>. It should basically contain:</p><pre class="screen">01: ################################################################################
  4980. 02: #
  4981. 03: # foo
  4982. 04: #
  4983. 05: ################################################################################
  4984. 06:
  4985. 07: LINUX_EXTENSIONS += foo
  4986. 08:
  4987. 09: define FOO_PREPARE_KERNEL
  4988. 10: $(FOO_DIR)/prepare-kernel-tree.sh --linux-dir=$(@D)
  4989. 11: endef</pre><p>On line 7, we add the Linux extension <code class="literal">foo</code> to the list of available
  4990. Linux extensions.</p><p>On line 9-11, we define what should be done by the extension to modify
  4991. the Linux kernel tree; this is specific to the linux extension and can
  4992. use the variables defined by the <code class="literal">foo</code> package, like: <code class="literal">$(FOO_DIR)</code> or
  4993. <code class="literal">$(FOO_VERSION)</code>… as well as all the Linux variables, like:
  4994. <code class="literal">$(LINUX_VERSION)</code> or <code class="literal">$(LINUX_VERSION_PROBED)</code>, <code class="literal">$(KERNEL_ARCH)</code>…
  4995. See the <a class="link" href="#kernel-variables">definition of those kernel variables</a>.</p></div></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="hooks"></a>18.23. Hooks available in the various build steps</h2></div></div></div><p>The generic infrastructure (and as a result also the derived autotools
  4996. and cmake infrastructures) allow packages to specify hooks.
  4997. These define further actions to perform after existing steps.
  4998. Most hooks aren’t really useful for generic packages, since the <code class="literal">.mk</code>
  4999. file already has full control over the actions performed in each step
  5000. of the package construction.</p><p>The following hook points are available:</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
  5001. <code class="literal">LIBFOO_PRE_DOWNLOAD_HOOKS</code>
  5002. </li><li class="listitem">
  5003. <code class="literal">LIBFOO_POST_DOWNLOAD_HOOKS</code>
  5004. </li><li class="listitem">
  5005. <code class="literal">LIBFOO_PRE_EXTRACT_HOOKS</code>
  5006. </li><li class="listitem">
  5007. <code class="literal">LIBFOO_POST_EXTRACT_HOOKS</code>
  5008. </li><li class="listitem">
  5009. <code class="literal">LIBFOO_PRE_RSYNC_HOOKS</code>
  5010. </li><li class="listitem">
  5011. <code class="literal">LIBFOO_POST_RSYNC_HOOKS</code>
  5012. </li><li class="listitem">
  5013. <code class="literal">LIBFOO_PRE_PATCH_HOOKS</code>
  5014. </li><li class="listitem">
  5015. <code class="literal">LIBFOO_POST_PATCH_HOOKS</code>
  5016. </li><li class="listitem">
  5017. <code class="literal">LIBFOO_PRE_CONFIGURE_HOOKS</code>
  5018. </li><li class="listitem">
  5019. <code class="literal">LIBFOO_POST_CONFIGURE_HOOKS</code>
  5020. </li><li class="listitem">
  5021. <code class="literal">LIBFOO_PRE_BUILD_HOOKS</code>
  5022. </li><li class="listitem">
  5023. <code class="literal">LIBFOO_POST_BUILD_HOOKS</code>
  5024. </li><li class="listitem">
  5025. <code class="literal">LIBFOO_PRE_INSTALL_HOOKS</code> (for host packages only)
  5026. </li><li class="listitem">
  5027. <code class="literal">LIBFOO_POST_INSTALL_HOOKS</code> (for host packages only)
  5028. </li><li class="listitem">
  5029. <code class="literal">LIBFOO_PRE_INSTALL_STAGING_HOOKS</code> (for target packages only)
  5030. </li><li class="listitem">
  5031. <code class="literal">LIBFOO_POST_INSTALL_STAGING_HOOKS</code> (for target packages only)
  5032. </li><li class="listitem">
  5033. <code class="literal">LIBFOO_PRE_INSTALL_TARGET_HOOKS</code> (for target packages only)
  5034. </li><li class="listitem">
  5035. <code class="literal">LIBFOO_POST_INSTALL_TARGET_HOOKS</code> (for target packages only)
  5036. </li><li class="listitem">
  5037. <code class="literal">LIBFOO_PRE_INSTALL_IMAGES_HOOKS</code>
  5038. </li><li class="listitem">
  5039. <code class="literal">LIBFOO_POST_INSTALL_IMAGES_HOOKS</code>
  5040. </li><li class="listitem">
  5041. <code class="literal">LIBFOO_PRE_LEGAL_INFO_HOOKS</code>
  5042. </li><li class="listitem">
  5043. <code class="literal">LIBFOO_POST_LEGAL_INFO_HOOKS</code>
  5044. </li><li class="listitem">
  5045. <code class="literal">LIBFOO_TARGET_FINALIZE_HOOKS</code>
  5046. </li></ul></div><p>These variables are <span class="emphasis"><em>lists</em></span> of variable names containing actions to be
  5047. performed at this hook point. This allows several hooks to be
  5048. registered at a given hook point. Here is an example:</p><pre class="screen">define LIBFOO_POST_PATCH_FIXUP
  5049. action1
  5050. action2
  5051. endef
  5052. LIBFOO_POST_PATCH_HOOKS += LIBFOO_POST_PATCH_FIXUP</pre><div class="section"><div class="titlepage"><div><div><h3 class="title"><a id="hooks-rsync"></a>18.23.1. Using the <code class="literal">POST_RSYNC</code> hook</h3></div></div></div><p>The <code class="literal">POST_RSYNC</code> hook is run only for packages that use a local source,
  5053. either through the <code class="literal">local</code> site method or the <code class="literal">OVERRIDE_SRCDIR</code>
  5054. mechanism. In this case, package sources are copied using <code class="literal">rsync</code> from
  5055. the local location into the buildroot build directory. The <code class="literal">rsync</code>
  5056. command does not copy all files from the source directory, though.
  5057. Files belonging to a version control system, like the directories
  5058. <code class="literal">.git</code>, <code class="literal">.hg</code>, etc. are not copied. For most packages this is
  5059. sufficient, but a given package can perform additional actions using
  5060. the <code class="literal">POST_RSYNC</code> hook.</p><p>In principle, the hook can contain any command you want. One specific
  5061. use case, though, is the intentional copying of the version control
  5062. directory using <code class="literal">rsync</code>. The <code class="literal">rsync</code> command you use in the hook can, among
  5063. others, use the following variables:</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
  5064. <code class="literal">$(SRCDIR)</code>: the path to the overridden source directory
  5065. </li><li class="listitem">
  5066. <code class="literal">$(@D)</code>: the path to the build directory
  5067. </li></ul></div></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a id="_target_finalize_hook"></a>18.23.2. Target-finalize hook</h3></div></div></div><p>Packages may also register hooks in <code class="literal">LIBFOO_TARGET_FINALIZE_HOOKS</code>.
  5068. These hooks are run after all packages are built, but before the
  5069. filesystem images are generated. They are seldom used, and your
  5070. package probably do not need them.</p></div></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="_gettext_integration_and_interaction_with_packages"></a>18.24. Gettext integration and interaction with packages</h2></div></div></div><p>Many packages that support internationalization use the gettext
  5071. library. Dependencies for this library are fairly complicated and
  5072. therefore, deserve some explanation.</p><p>The <span class="emphasis"><em>glibc</em></span> C library integrates a full-blown implementation of
  5073. <span class="emphasis"><em>gettext</em></span>, supporting translation. Native Language Support is
  5074. therefore built-in in <span class="emphasis"><em>glibc</em></span>.</p><p>On the other hand, the <span class="emphasis"><em>uClibc</em></span> and <span class="emphasis"><em>musl</em></span> C libraries only provide a
  5075. stub implementation of the gettext functionality, which allows to
  5076. compile libraries and programs using gettext functions, but without
  5077. providing the translation capabilities of a full-blown gettext
  5078. implementation. With such C libraries, if real Native Language Support
  5079. is necessary, it can be provided by the <code class="literal">libintl</code> library of the
  5080. <code class="literal">gettext</code> package.</p><p>Due to this, and in order to make sure that Native Language Support is
  5081. properly handled, packages in Buildroot that can use NLS support
  5082. should:</p><div class="orderedlist"><ol class="orderedlist" type="1"><li class="listitem">
  5083. Ensure NLS support is enabled when <code class="literal">BR2_SYSTEM_ENABLE_NLS=y</code>. This
  5084. is done automatically for <span class="emphasis"><em>autotools</em></span> packages and therefore should
  5085. only be done for packages using other package infrastructures.
  5086. </li><li class="listitem">
  5087. Add <code class="literal">$(TARGET_NLS_DEPENDENCIES)</code> to the package
  5088. <code class="literal">&lt;pkg&gt;_DEPENDENCIES</code> variable. This addition should be done
  5089. unconditionally: the value of this variable is automatically
  5090. adjusted by the core infrastructure to contain the relevant list of
  5091. packages. If NLS support is disabled, this variable is empty. If
  5092. NLS support is enabled, this variable contains <code class="literal">host-gettext</code> so
  5093. that tools needed to compile translation files are available on the
  5094. host. In addition, if <span class="emphasis"><em>uClibc</em></span> or <span class="emphasis"><em>musl</em></span> are used, this variable
  5095. also contains <code class="literal">gettext</code> in order to get the full-blown <span class="emphasis"><em>gettext</em></span>
  5096. implementation.
  5097. </li><li class="listitem">
  5098. If needed, add <code class="literal">$(TARGET_NLS_LIBS)</code> to the linker flags, so that
  5099. the package gets linked with <code class="literal">libintl</code>. This is generally not
  5100. needed with <span class="emphasis"><em>autotools</em></span> packages as they usually detect
  5101. automatically that they should link with <code class="literal">libintl</code>. However,
  5102. packages using other build systems, or problematic autotools-based
  5103. packages may need this. <code class="literal">$(TARGET_NLS_LIBS)</code> should be added
  5104. unconditionally to the linker flags, as the core automatically
  5105. makes it empty or defined to <code class="literal">-lintl</code> depending on the
  5106. configuration.
  5107. </li></ol></div><p>No changes should be made to the <code class="literal">Config.in</code> file to support NLS.</p><p>Finally, certain packages need some gettext utilities on the target,
  5108. such as the <code class="literal">gettext</code> program itself, which allows to retrieve
  5109. translated strings, from the command line. In such a case, the package
  5110. should:</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
  5111. use <code class="literal">select BR2_PACKAGE_GETTEXT</code> in their <code class="literal">Config.in</code> file,
  5112. indicating in a comment above that it’s a runtime dependency only.
  5113. </li><li class="listitem">
  5114. not add any <code class="literal">gettext</code> dependency in the <code class="literal">DEPENDENCIES</code> variable of
  5115. their <code class="literal">.mk</code> file.
  5116. </li></ul></div></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="_tips_and_tricks"></a>18.25. Tips and tricks</h2></div></div></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a id="package-name-variable-relation"></a>18.25.1. Package name, config entry name and makefile variable relationship</h3></div></div></div><p>In Buildroot, there is some relationship between:</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
  5117. the <span class="emphasis"><em>package name</em></span>, which is the package directory name (and the
  5118. name of the <code class="literal">*.mk</code> file);
  5119. </li><li class="listitem">
  5120. the config entry name that is declared in the <code class="literal">Config.in</code> file;
  5121. </li><li class="listitem">
  5122. the makefile variable prefix.
  5123. </li></ul></div><p>It is mandatory to maintain consistency between these elements,
  5124. using the following rules:</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
  5125. the package directory and the <code class="literal">*.mk</code> name are the <span class="emphasis"><em>package name</em></span>
  5126. itself (e.g.: <code class="literal">package/foo-bar_boo/foo-bar_boo.mk</code>);
  5127. </li><li class="listitem">
  5128. the <span class="emphasis"><em>make</em></span> target name is the <span class="emphasis"><em>package name</em></span> itself (e.g.:
  5129. <code class="literal">foo-bar_boo</code>);
  5130. </li><li class="listitem">
  5131. the config entry is the upper case <span class="emphasis"><em>package name</em></span> with <code class="literal">.</code> and <code class="literal">-</code>
  5132. characters substituted with <code class="literal">_</code>, prefixed with <code class="literal">BR2_PACKAGE_</code> (e.g.:
  5133. <code class="literal">BR2_PACKAGE_FOO_BAR_BOO</code>);
  5134. </li><li class="listitem">
  5135. the <code class="literal">*.mk</code> file variable prefix is the upper case <span class="emphasis"><em>package name</em></span>
  5136. with <code class="literal">.</code> and <code class="literal">-</code> characters substituted with <code class="literal">_</code> (e.g.:
  5137. <code class="literal">FOO_BAR_BOO_VERSION</code>).
  5138. </li></ul></div></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a id="check-package"></a>18.25.2. How to check the coding style</h3></div></div></div><p>Buildroot provides a script in <code class="literal">utils/check-package</code> that checks new or
  5139. changed files for coding style. It is not a complete language validator,
  5140. but it catches many common mistakes. It is meant to run in the actual
  5141. files you created or modified, before creating the patch for submission.</p><p>This script can be used for packages, filesystem makefiles, Config.in
  5142. files, etc. It does not check the files defining the package
  5143. infrastructures and some other files containing similar common code.</p><p>To use it, run the <code class="literal">check-package</code> script, by telling which files you
  5144. created or changed:</p><pre class="screen">$ ./utils/check-package package/new-package/*</pre><p>If you have the <code class="literal">utils</code> directory in your path you can also run:</p><pre class="screen">$ cd package/new-package/
  5145. $ check-package *</pre><p>The tool can also be used for packages in a br2-external:</p><pre class="screen">$ check-package -b /path/to/br2-ext-tree/package/my-package/*</pre><p>The <code class="literal">check-package</code> script requires you install <code class="literal">shellcheck</code> and the
  5146. Python PyPi packages <code class="literal">flake8</code> and <code class="literal">python-magic</code>. The Buildroot code
  5147. base is currently tested against version 0.7.1 of ShellCheck. If you
  5148. use a different version of ShellCheck, you may see additional,
  5149. unfixed, warnings.</p><p>If you have Docker or Podman you can run <code class="literal">check-package</code> without
  5150. installing dependencies:</p><pre class="screen">$ ./utils/docker-run ./utils/check-package</pre></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a id="testing-package"></a>18.25.3. How to test your package</h3></div></div></div><p>Once you have added your new package, it is important that you test it
  5151. under various conditions: does it build for all architectures? Does it
  5152. build with the different C libraries? Does it need threads, NPTL? And
  5153. so on…</p><p>Buildroot runs <a class="ulink" href="http://autobuild.buildroot.org/" target="_top">autobuilders</a> which
  5154. continuously test random configurations. However, these only build the
  5155. <code class="literal">master</code> branch of the git tree, and your new fancy package is not yet
  5156. there.</p><p>Buildroot provides a script in <code class="literal">utils/test-pkg</code> that uses the same base
  5157. configurations as used by the autobuilders so you can test your package
  5158. in the same conditions.</p><p>First, create a config snippet that contains all the necessary options
  5159. needed to enable your package, but without any architecture or toolchain
  5160. option. For example, let’s create a config snippet that just enables
  5161. <code class="literal">libcurl</code>, without any TLS backend:</p><pre class="screen">$ cat libcurl.config
  5162. BR2_PACKAGE_LIBCURL=y</pre><p>If your package needs more configuration options, you can add them to the
  5163. config snippet. For example, here’s how you would test <code class="literal">libcurl</code> with
  5164. <code class="literal">openssl</code> as a TLS backend and the <code class="literal">curl</code> program:</p><pre class="screen">$ cat libcurl.config
  5165. BR2_PACKAGE_LIBCURL=y
  5166. BR2_PACKAGE_LIBCURL_CURL=y
  5167. BR2_PACKAGE_OPENSSL=y</pre><p>Then run the <code class="literal">test-pkg</code> script, by telling it what config snippet to use
  5168. and what package to test:</p><pre class="screen">$ ./utils/test-pkg -c libcurl.config -p libcurl</pre><p>By default, <code class="literal">test-pkg</code> will build your package against a subset of the
  5169. toolchains used by the autobuilders, which has been selected by the
  5170. Buildroot developers as being the most useful and representative
  5171. subset. If you want to test all toolchains, pass the <code class="literal">-a</code> option. Note
  5172. that in any case, internal toolchains are excluded as they take too
  5173. long to build.</p><p>The output lists all toolchains that are tested and the corresponding
  5174. result (excerpt, results are fake):</p><pre class="screen">$ ./utils/test-pkg -c libcurl.config -p libcurl
  5175. armv5-ctng-linux-gnueabi [ 1/11]: OK
  5176. armv7-ctng-linux-gnueabihf [ 2/11]: OK
  5177. br-aarch64-glibc [ 3/11]: SKIPPED
  5178. br-arcle-hs38 [ 4/11]: SKIPPED
  5179. br-arm-basic [ 5/11]: FAILED
  5180. br-arm-cortex-a9-glibc [ 6/11]: OK
  5181. br-arm-cortex-a9-musl [ 7/11]: FAILED
  5182. br-arm-cortex-m4-full [ 8/11]: OK
  5183. br-arm-full [ 9/11]: OK
  5184. br-arm-full-nothread [10/11]: FAILED
  5185. br-arm-full-static [11/11]: OK
  5186. 11 builds, 2 skipped, 2 build failed, 1 legal-info failed</pre><p>The results mean:</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
  5187. <code class="literal">OK</code>: the build was successful.
  5188. </li><li class="listitem">
  5189. <code class="literal">SKIPPED</code>: one or more configuration options listed in the config
  5190. snippet were not present in the final configuration. This is due to
  5191. options having dependencies not satisfied by the toolchain, such as
  5192. for example a package that <code class="literal">depends on BR2_USE_MMU</code> with a noMMU
  5193. toolchain. The missing options are reported in <code class="literal">missing.config</code> in
  5194. the output build directory (<code class="literal">~/br-test-pkg/TOOLCHAIN_NAME/</code> by
  5195. default).
  5196. </li><li class="listitem"><p class="simpara">
  5197. <code class="literal">FAILED</code>: the build failed. Inspect the <code class="literal">logfile</code> file in the output
  5198. build directory to see what went wrong:
  5199. </p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: circle; "><li class="listitem">
  5200. the actual build failed,
  5201. </li><li class="listitem">
  5202. the legal-info failed,
  5203. </li><li class="listitem">
  5204. one of the preliminary steps (downloading the config file, applying
  5205. the configuration, running <code class="literal">dirclean</code> for the package) failed.
  5206. </li></ul></div></li></ul></div><p>When there are failures, you can just re-run the script with the same
  5207. options (after you fixed your package); the script will attempt to
  5208. re-build the package specified with <code class="literal">-p</code> for all toolchains, without
  5209. the need to re-build all the dependencies of that package.</p><p>The <code class="literal">test-pkg</code> script accepts a few options, for which you can get some
  5210. help by running:</p><pre class="screen">$ ./utils/test-pkg -h</pre></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a id="github-download-url"></a>18.25.4. How to add a package from GitHub</h3></div></div></div><p>Packages on GitHub often don’t have a download area with release tarballs.
  5211. However, it is possible to download tarballs directly from the repository
  5212. on GitHub. As GitHub is known to have changed download mechanisms in the
  5213. past, the <span class="emphasis"><em>github</em></span> helper function should be used as shown below.</p><pre class="screen"># Use a tag or a full commit ID
  5214. FOO_VERSION = 1.0
  5215. FOO_SITE = $(call github,&lt;user&gt;,&lt;package&gt;,v$(FOO_VERSION))</pre><div class="itemizedlist"><p class="title"><strong>Notes</strong></p><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
  5216. The FOO_VERSION can either be a tag or a commit ID.
  5217. </li><li class="listitem">
  5218. The tarball name generated by github matches the default one from
  5219. Buildroot (e.g.: <code class="literal">foo-f6fb6654af62045239caed5950bc6c7971965e60.tar.gz</code>),
  5220. so it is not necessary to specify it in the <code class="literal">.mk</code> file.
  5221. </li><li class="listitem">
  5222. When using a commit ID as version, you should use the full 40 hex characters.
  5223. </li><li class="listitem">
  5224. When the tag contains a prefix such as <code class="literal">v</code> in <code class="literal">v1.0</code>, then the
  5225. <code class="literal">VERSION</code> variable should contain just <code class="literal">1.0</code>, and the <code class="literal">v</code> should be
  5226. added directly in the <code class="literal">SITE</code> variable, as illustrated above. This
  5227. ensures that the <code class="literal">VERSION</code> variable value can be used to match
  5228. against <a class="ulink" href="http://www.release-monitoring.org/" target="_top">release-monitoring.org</a>
  5229. results.
  5230. </li></ul></div><p>If the package you wish to add does have a release section on GitHub, the
  5231. maintainer may have uploaded a release tarball, or the release may just point
  5232. to the automatically generated tarball from the git tag. If there is a
  5233. release tarball uploaded by the maintainer, we prefer to use that since it
  5234. may be slightly different (e.g. it contains a configure script so we don’t
  5235. need to do AUTORECONF).</p><p>You can see on the release page if it’s an uploaded tarball or a git tag:</p><div class="informalfigure"><div class="mediaobject"><img src="github_hash_mongrel2.png" alt="github_hash_mongrel2.png" /></div></div><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
  5236. If it looks like the image above then it was uploaded by the
  5237. maintainer and you should use that link (in that example:
  5238. <span class="emphasis"><em>mongrel2-v1.9.2.tar.bz2</em></span>) to specify <code class="literal">FOO_SITE</code>, and not use the
  5239. <span class="emphasis"><em>github</em></span> helper.
  5240. </li><li class="listitem">
  5241. On the other hand, if there’s is <span class="strong"><strong>only</strong></span> the "Source code" link, then
  5242. it’s an automatically generated tarball and you should use the
  5243. <span class="emphasis"><em>github</em></span> helper function.
  5244. </li></ul></div></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a id="gitlab-download-url"></a>18.25.5. How to add a package from Gitlab</h3></div></div></div><p>In a similar way to the <code class="literal">github</code> macro described in
  5245. <a class="xref" href="#github-download-url" title="18.25.4. How to add a package from GitHub">Section 18.25.4, “How to add a package from GitHub”</a>, Buildroot also provides the <code class="literal">gitlab</code> macro
  5246. to download from Gitlab repositories. It can be used to download
  5247. auto-generated tarballs produced by Gitlab, either for specific tags
  5248. or commits:</p><pre class="screen"># Use a tag or a full commit ID
  5249. FOO_VERSION = 1.0
  5250. FOO_SITE = $(call gitlab,&lt;user&gt;,&lt;package&gt;,v$(FOO_VERSION))</pre><p>By default, it will use a <code class="literal">.tar.gz</code> tarball, but Gitlab also provides
  5251. <code class="literal">.tar.bz2</code> tarballs, so by adding a <code class="literal">&lt;pkg&gt;_SOURCE</code> variable, this
  5252. <code class="literal">.tar.bz2</code> tarball can be used:</p><pre class="screen"># Use a tag or a full commit ID
  5253. FOO_VERSION = 1.0
  5254. FOO_SITE = $(call gitlab,&lt;user&gt;,&lt;package&gt;,v$(FOO_VERSION))
  5255. FOO_SOURCE = foo-$(FOO_VERSION).tar.bz2</pre><p>If there is a specific tarball uploaded by the upstream developers in
  5256. <code class="literal">https://gitlab.com/&lt;project&gt;/releases/</code>, do not use this macro, but
  5257. rather use directly the link to the tarball.</p></div></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="_conclusion"></a>18.26. Conclusion</h2></div></div></div><p>As you can see, adding a software package to Buildroot is simply a
  5258. matter of writing a Makefile using an existing example and modifying it
  5259. according to the compilation process required by the package.</p><p>If you package software that might be useful for other people, don’t
  5260. forget to send a patch to the Buildroot mailing list (see
  5261. <a class="xref" href="#submitting-patches" title="22.5. Submitting patches">Section 22.5, “Submitting patches”</a>)!</p></div></div><div class="chapter"><div class="titlepage"><div><div><h2 class="title"><a id="patch-policy"></a>Chapter 19. Patching a package</h2></div></div></div><p>While integrating a new package or updating an existing one, it may be
  5262. necessary to patch the source of the software to get it cross-built within
  5263. Buildroot.</p><p>Buildroot offers an infrastructure to automatically handle this during
  5264. the builds. It supports three ways of applying patch sets: downloaded patches,
  5265. patches supplied within buildroot and patches located in a user-defined
  5266. global patch directory.</p><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="_providing_patches"></a>19.1. Providing patches</h2></div></div></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a id="_downloaded"></a>19.1.1. Downloaded</h3></div></div></div><p>If it is necessary to apply a patch that is available for download, then add it
  5267. to the <code class="literal">&lt;packagename&gt;_PATCH</code> variable. If an entry contains <code class="literal">://</code>,
  5268. then Buildroot will assume it is a full URL and download the patch
  5269. from this location. Otherwise, Buildroot will assume that the patch should be
  5270. downloaded from <code class="literal">&lt;packagename&gt;_SITE</code>. It can be a single patch,
  5271. or a tarball containing a patch series.</p><p>Like for all downloads, a hash should be added to the <code class="literal">&lt;packagename&gt;.hash</code>
  5272. file.</p><p>This method is typically used for packages from Debian.</p></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a id="_within_buildroot"></a>19.1.2. Within Buildroot</h3></div></div></div><p>Most patches are provided within Buildroot, in the package
  5273. directory; these typically aim to fix cross-compilation, libc support,
  5274. or other such issues.</p><p>These patch files should be named <code class="literal">&lt;number&gt;-&lt;description&gt;.patch</code>.</p><div class="itemizedlist"><p class="title"><strong>Notes</strong></p><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
  5275. The patch files coming with Buildroot should not contain any package version
  5276. reference in their filename.
  5277. </li><li class="listitem">
  5278. The field <code class="literal">&lt;number&gt;</code> in the patch file name refers to the <span class="emphasis"><em>apply order</em></span>,
  5279. and shall start at 1; It is preferred to pad the number with zeros up to 4
  5280. digits, like <span class="emphasis"><em>git-format-patch</em></span> does. E.g.: <code class="literal">0001-foobar-the-buz.patch</code>
  5281. </li><li class="listitem">
  5282. The patch email subject prefix shall not be numbered. Patches shall
  5283. be generated with the <code class="literal">git format-patch -N</code> command, since this
  5284. numbering is automatically added for series. For example, the patch
  5285. subject line should look like <code class="literal">Subject: [PATCH] foobar the buz</code> rather
  5286. than <code class="literal">Subject: [PATCH n/m] foobar the buz</code>.
  5287. </li><li class="listitem">
  5288. Previously, it was mandatory for patches to be prefixed with the name of
  5289. the package, like <code class="literal">&lt;package&gt;-&lt;number&gt;-&lt;description&gt;.patch</code>, but that is
  5290. no longer the case. Existing packages will be fixed as time passes. <span class="emphasis"><em>Do
  5291. not prefix patches with the package name.</em></span>
  5292. </li><li class="listitem">
  5293. Previously, a <code class="literal">series</code> file, as used by <code class="literal">quilt</code>, could also be added in
  5294. the package directory. In that case, the <code class="literal">series</code> file defines the patch
  5295. application order. This is deprecated, and will be removed in the future.
  5296. <span class="emphasis"><em>Do not use a series file.</em></span>
  5297. </li></ul></div></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a id="_global_patch_directory"></a>19.1.3. Global patch directory</h3></div></div></div><p>The <code class="literal">BR2_GLOBAL_PATCH_DIR</code> configuration file option can be
  5298. used to specify a space separated list of one or more directories
  5299. containing global package patches. See <a class="xref" href="#customize-patches" title="9.8.1. Providing extra patches">Section 9.8.1, “Providing extra patches”</a> for
  5300. details.</p></div></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="patch-apply-order"></a>19.2. How patches are applied</h2></div></div></div><div class="orderedlist"><ol class="orderedlist" type="1"><li class="listitem">
  5301. Run the <code class="literal">&lt;packagename&gt;_PRE_PATCH_HOOKS</code> commands if defined;
  5302. </li><li class="listitem">
  5303. Cleanup the build directory, removing any existing <code class="literal">*.rej</code> files;
  5304. </li><li class="listitem">
  5305. If <code class="literal">&lt;packagename&gt;_PATCH</code> is defined, then patches from these
  5306. tarballs are applied;
  5307. </li><li class="listitem"><p class="simpara">
  5308. If there are some <code class="literal">*.patch</code> files in the package’s Buildroot
  5309. directory or in a package subdirectory named <code class="literal">&lt;packageversion&gt;</code>,
  5310. then:
  5311. </p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
  5312. If a <code class="literal">series</code> file exists in the package directory, then patches are
  5313. applied according to the <code class="literal">series</code> file;
  5314. </li><li class="listitem">
  5315. Otherwise, patch files matching <code class="literal">*.patch</code> are applied in alphabetical
  5316. order.
  5317. So, to ensure they are applied in the right order, it is highly
  5318. recommended to name the patch files like this:
  5319. <code class="literal">&lt;number&gt;-&lt;description&gt;.patch</code>, where <code class="literal">&lt;number&gt;</code> refers to the
  5320. <span class="emphasis"><em>apply order</em></span>.
  5321. </li></ul></div></li><li class="listitem">
  5322. If <code class="literal">BR2_GLOBAL_PATCH_DIR</code> is defined, the directories will be
  5323. enumerated in the order they are specified. The patches are applied
  5324. as described in the previous step.
  5325. </li><li class="listitem">
  5326. Run the <code class="literal">&lt;packagename&gt;_POST_PATCH_HOOKS</code> commands if defined.
  5327. </li></ol></div><p>If something goes wrong in the steps <span class="emphasis"><em>3</em></span> or <span class="emphasis"><em>4</em></span>, then the build fails.</p></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="_format_and_licensing_of_the_package_patches"></a>19.3. Format and licensing of the package patches</h2></div></div></div><p>Patches are released under the same license as the software they apply
  5328. to (see <a class="xref" href="#legal-info-buildroot" title="13.2. Complying with the Buildroot license">Section 13.2, “Complying with the Buildroot license”</a>).</p><p>A message explaining what the patch does, and why it is needed, should
  5329. be added in the header commentary of the patch.</p><p>You should add a <code class="literal">Signed-off-by</code> statement in the header of the each
  5330. patch to help with keeping track of the changes and to certify that the
  5331. patch is released under the same license as the software that is modified.</p><p>If the software is under version control, it is recommended to use the
  5332. upstream SCM software to generate the patch set.</p><p>Otherwise, concatenate the header with the output of the
  5333. <code class="literal">diff -purN package-version.orig/ package-version/</code> command.</p><p>If you update an existing patch (e.g. when bumping the package version),
  5334. make sure the existing From header and Signed-off-by tags are not
  5335. removed, but do update the rest of the patch comment when appropriate.</p><p>At the end, the patch should look like:</p><pre class="screen">configure.ac: add C++ support test
  5336. Signed-off-by: John Doe &lt;john.doe@noname.org&gt;
  5337. --- configure.ac.orig
  5338. +++ configure.ac
  5339. @@ -40,2 +40,12 @@
  5340. AC_PROG_MAKE_SET
  5341. +
  5342. +AC_CACHE_CHECK([whether the C++ compiler works],
  5343. + [rw_cv_prog_cxx_works],
  5344. + [AC_LANG_PUSH([C++])
  5345. + AC_LINK_IFELSE([AC_LANG_PROGRAM([], [])],
  5346. + [rw_cv_prog_cxx_works=yes],
  5347. + [rw_cv_prog_cxx_works=no])
  5348. + AC_LANG_POP([C++])])
  5349. +
  5350. +AM_CONDITIONAL([CXX_WORKS], [test "x$rw_cv_prog_cxx_works" = "xyes"])</pre></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="_additional_patch_documentation"></a>19.4. Additional patch documentation</h2></div></div></div><p>Ideally, all patches should document an upstream patch or patch submission, when
  5351. applicable, via the <code class="literal">Upstream</code> trailer.</p><p>When backporting an upstream patch that has been accepted into mainline, it is
  5352. preferred that the URL to the commit is referenced:</p><pre class="screen">Upstream: &lt;URL to upstream commit&gt;</pre><p>If a new issue is identified in Buildroot and upstream is generally affected by
  5353. the issue (it’s not a Buildroot specific issue), users should submit the patch
  5354. upstream and provide a link to that submission when possible:</p><pre class="screen">Upstream: &lt;URL to upstream mailing list submission or merge request&gt;</pre><p>Patches that have been submitted but were denied upstream should note that and
  5355. include comments about why the patch is being used despite the upstream status.</p><p>Note: in any of the above scenarios, it is also sensible to add a few words
  5356. about any changes to the patch that may have been necessary.</p><p>If a patch does not apply upstream then this should be noted with a comment:</p><pre class="screen">Upstream: N/A &lt;additional information about why patch is Buildroot specific&gt;</pre><p>Adding this documentation helps streamline the patch review process during
  5357. package version updates.</p></div></div><div class="chapter"><div class="titlepage"><div><div><h2 class="title"><a id="download-infra"></a>Chapter 20. Download infrastructure</h2></div></div></div><p>TODO</p></div><div class="chapter"><div class="titlepage"><div><div><h2 class="title"><a id="debugging-buildroot"></a>Chapter 21. Debugging Buildroot</h2></div></div></div><p>It is possible to instrument the steps <code class="literal">Buildroot</code> does when building
  5358. packages. Define the variable <code class="literal">BR2_INSTRUMENTATION_SCRIPTS</code> to contain
  5359. the path of one or more scripts (or other executables), in a
  5360. space-separated list, you want called before and after each step. The
  5361. scripts are called in sequence, with three parameters:</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
  5362. <code class="literal">start</code> or <code class="literal">end</code> to denote the start (resp. the end) of a step;
  5363. </li><li class="listitem">
  5364. the name of the step about to be started, or which just ended;
  5365. </li><li class="listitem">
  5366. the name of the package.
  5367. </li></ul></div><p>For example :</p><pre class="screen">make BR2_INSTRUMENTATION_SCRIPTS="/path/to/my/script1 /path/to/my/script2"</pre><p>The list of steps is:</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
  5368. <code class="literal">extract</code>
  5369. </li><li class="listitem">
  5370. <code class="literal">patch</code>
  5371. </li><li class="listitem">
  5372. <code class="literal">configure</code>
  5373. </li><li class="listitem">
  5374. <code class="literal">build</code>
  5375. </li><li class="listitem">
  5376. <code class="literal">install-host</code>, when a host-package is installed in <code class="literal">$(HOST_DIR)</code>
  5377. </li><li class="listitem">
  5378. <code class="literal">install-target</code>, when a target-package is installed in <code class="literal">$(TARGET_DIR)</code>
  5379. </li><li class="listitem">
  5380. <code class="literal">install-staging</code>, when a target-package is installed in <code class="literal">$(STAGING_DIR)</code>
  5381. </li><li class="listitem">
  5382. <code class="literal">install-image</code>, when a target-package installs files in <code class="literal">$(BINARIES_DIR)</code>
  5383. </li></ul></div><p>The script has access to the following variables:</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
  5384. <code class="literal">BR2_CONFIG</code>: the path to the Buildroot .config file
  5385. </li><li class="listitem">
  5386. <code class="literal">HOST_DIR</code>, <code class="literal">STAGING_DIR</code>, <code class="literal">TARGET_DIR</code>: see
  5387. <a class="xref" href="#generic-package-reference" title="18.6.2. generic-package reference">Section 18.6.2, “<code class="literal">generic-package</code> reference”</a>
  5388. </li><li class="listitem">
  5389. <code class="literal">BUILD_DIR</code>: the directory where packages are extracted and built
  5390. </li><li class="listitem">
  5391. <code class="literal">BINARIES_DIR</code>: the place where all binary files (aka images) are
  5392. stored
  5393. </li><li class="listitem">
  5394. <code class="literal">BASE_DIR</code>: the base output directory
  5395. </li></ul></div></div><div class="chapter"><div class="titlepage"><div><div><h2 class="title"><a id="_contributing_to_buildroot"></a>Chapter 22. Contributing to Buildroot</h2></div></div></div><p>There are many ways in which you can contribute to Buildroot: analyzing
  5396. and fixing bugs, analyzing and fixing package build failures detected by
  5397. the autobuilders, testing and reviewing patches sent by other
  5398. developers, working on the items in our TODO list and sending your own
  5399. improvements to Buildroot or its manual. The following sections give a
  5400. little more detail on each of these items.</p><p>If you are interested in contributing to Buildroot, the first thing you
  5401. should do is to subscribe to the Buildroot mailing list. This list is
  5402. the main way of interacting with other Buildroot developers and to send
  5403. contributions to. If you aren’t subscribed yet, then refer to
  5404. <a class="xref" href="#community-resources" title="Chapter 5. Community resources">Chapter 5, <em>Community resources</em></a> for the subscription link.</p><p>If you are going to touch the code, it is highly recommended to use a
  5405. git repository of Buildroot, rather than starting from an extracted
  5406. source code tarball. Git is the easiest way to develop from and directly
  5407. send your patches to the mailing list. Refer to <a class="xref" href="#getting-buildroot" title="Chapter 3. Getting Buildroot">Chapter 3, <em>Getting Buildroot</em></a>
  5408. for more information on obtaining a Buildroot git tree.</p><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="_reproducing_analyzing_and_fixing_bugs"></a>22.1. Reproducing, analyzing and fixing bugs</h2></div></div></div><p>A first way of contributing is to have a look at the open bug reports in
  5409. the <a class="ulink" href="https://bugs.buildroot.org/buglist.cgi?product=buildroot" target="_top">Buildroot bug
  5410. tracker</a>. As we strive to keep the bug count as small as possible, all
  5411. help in reproducing, analyzing and fixing reported bugs is more than
  5412. welcome. Don’t hesitate to add a comment to bug reports reporting your
  5413. findings, even if you don’t yet see the full picture.</p></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="_analyzing_and_fixing_autobuild_failures"></a>22.2. Analyzing and fixing autobuild failures</h2></div></div></div><p>The Buildroot autobuilders are a set of build machines that continuously
  5414. run Buildroot builds based on random configurations. This is done for
  5415. all architectures supported by Buildroot, with various toolchains, and
  5416. with a random selection of packages. With the large commit activity on
  5417. Buildroot, these autobuilders are a great help in detecting problems
  5418. very early after commit.</p><p>All build results are available at <a class="ulink" href="http://autobuild.buildroot.org" target="_top">http://autobuild.buildroot.org</a>,
  5419. statistics are at <a class="ulink" href="http://autobuild.buildroot.org/stats.php" target="_top">http://autobuild.buildroot.org/stats.php</a>. Every day,
  5420. an overview of all failed packages is sent to the mailing list.</p><p>Detecting problems is great, but obviously these problems have to be
  5421. fixed as well. Your contribution is very welcome here! There are
  5422. basically two things that can be done:</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
  5423. Analyzing the problems. The daily summary mails do not contain details
  5424. about the actual failures: in order to see what’s going on you have to
  5425. open the build log and check the last output. Having someone doing
  5426. this for all packages in the mail is very useful for other developers,
  5427. as they can make a quick initial analysis based on this output alone.
  5428. </li><li class="listitem"><p class="simpara">
  5429. Fixing a problem. When fixing autobuild failures, you should follow
  5430. these steps:
  5431. </p><div class="orderedlist"><ol class="orderedlist" type="1"><li class="listitem">
  5432. Check if you can reproduce the problem by building with the same
  5433. configuration. You can do this manually, or use the
  5434. <a class="ulink" href="http://git.buildroot.org/buildroot-test/tree/utils/br-reproduce-build" target="_top">br-reproduce-build</a>
  5435. script that will automatically clone a Buildroot git repository,
  5436. checkout the correct revision, download and set the right
  5437. configuration, and start the build.
  5438. </li><li class="listitem">
  5439. Analyze the problem and create a fix.
  5440. </li><li class="listitem">
  5441. Verify that the problem is really fixed by starting from a clean
  5442. Buildroot tree and only applying your fix.
  5443. </li><li class="listitem">
  5444. Send the fix to the Buildroot mailing list (see
  5445. <a class="xref" href="#submitting-patches" title="22.5. Submitting patches">Section 22.5, “Submitting patches”</a>). In case you created a patch against the
  5446. package sources, you should also send the patch upstream so that the
  5447. problem will be fixed in a later release, and the patch in Buildroot
  5448. can be removed.
  5449. In the commit message of a patch fixing an autobuild failure, add a
  5450. reference to the build result directory, as follows:
  5451. </li></ol></div></li></ul></div><pre class="screen">Fixes: http://autobuild.buildroot.org/results/51000a9d4656afe9e0ea6f07b9f8ed374c2e4069</pre></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="_reviewing_and_testing_patches"></a>22.3. Reviewing and testing patches</h2></div></div></div><p>With the amount of patches sent to the mailing list each day, the
  5452. maintainer has a very hard job to judge which patches are ready to apply
  5453. and which ones aren’t. Contributors can greatly help here by reviewing
  5454. and testing these patches.</p><p>In the review process, do not hesitate to respond to patch submissions
  5455. for remarks, suggestions or anything that will help everyone to
  5456. understand the patches and make them better. Please use internet
  5457. style replies in plain text emails when responding to patch
  5458. submissions.</p><p>To indicate approval of a patch, there are three formal tags that keep
  5459. track of this approval. To add your tag to a patch, reply to it with the
  5460. approval tag below the original author’s Signed-off-by line. These tags
  5461. will be picked up automatically by patchwork (see
  5462. <a class="xref" href="#apply-patches-patchwork" title="22.3.1. Applying Patches from Patchwork">Section 22.3.1, “Applying Patches from Patchwork”</a>) and will be part of the commit log when
  5463. the patch is accepted.</p><div class="variablelist"><dl class="variablelist"><dt><span class="term">
  5464. Tested-by
  5465. </span></dt><dd>
  5466. Indicates that the patch has been tested successfully.
  5467. You are encouraged to specify what kind of testing you performed
  5468. (compile-test on architecture X and Y, runtime test on target A,
  5469. …). This additional information helps other testers and the
  5470. maintainer.
  5471. </dd><dt><span class="term">
  5472. Reviewed-by
  5473. </span></dt><dd>
  5474. Indicates that you code-reviewed the patch and did your
  5475. best in spotting problems, but you are not sufficiently familiar with
  5476. the area touched to provide an Acked-by tag. This means that there
  5477. may be remaining problems in the patch that would be spotted by
  5478. someone with more experience in that area. Should such problems be
  5479. detected, your Reviewed-by tag remains appropriate and you cannot
  5480. be blamed.
  5481. </dd><dt><span class="term">
  5482. Acked-by
  5483. </span></dt><dd>
  5484. Indicates that you code-reviewed the patch and you are
  5485. familiar enough with the area touched to feel that the patch can be
  5486. committed as-is (no additional changes required). In case it later
  5487. turns out that something is wrong with the patch, your Acked-by could
  5488. be considered inappropriate. The difference between Acked-by and
  5489. Reviewed-by is thus mainly that you are prepared to take the blame on
  5490. Acked patches, but not on Reviewed ones.
  5491. </dd></dl></div><p>If you reviewed a patch and have comments on it, you should simply reply
  5492. to the patch stating these comments, without providing a Reviewed-by or
  5493. Acked-by tag. These tags should only be provided if you judge the patch
  5494. to be good as it is.</p><p>It is important to note that neither Reviewed-by nor Acked-by imply
  5495. that testing has been performed. To indicate that you both reviewed and
  5496. tested the patch, provide two separate tags (Reviewed/Acked-by and
  5497. Tested-by).</p><p>Note also that <span class="emphasis"><em>any developer</em></span> can provide Tested/Reviewed/Acked-by
  5498. tags, without exception, and we encourage everyone to do this. Buildroot
  5499. does not have a defined group of <span class="emphasis"><em>core</em></span> developers, it just so happens
  5500. that some developers are more active than others. The maintainer will
  5501. value tags according to the track record of their submitter. Tags
  5502. provided by a regular contributor will naturally be trusted more than
  5503. tags provided by a newcomer. As you provide tags more regularly, your
  5504. <span class="emphasis"><em>trustworthiness</em></span> (in the eyes of the maintainer) will go up, but <span class="emphasis"><em>any</em></span>
  5505. tag provided is valuable.</p><p>Buildroot’s Patchwork website can be used to pull in patches for testing
  5506. purposes. Please see <a class="xref" href="#apply-patches-patchwork" title="22.3.1. Applying Patches from Patchwork">Section 22.3.1, “Applying Patches from Patchwork”</a> for more
  5507. information on using Buildroot’s Patchwork website to apply patches.</p><div class="section"><div class="titlepage"><div><div><h3 class="title"><a id="apply-patches-patchwork"></a>22.3.1. Applying Patches from Patchwork</h3></div></div></div><p>The main use of Buildroot’s Patchwork website for a developer is for
  5508. pulling in patches into their local git repository for testing
  5509. purposes.</p><p>When browsing patches in the patchwork management interface, an <code class="literal">mbox</code>
  5510. link is provided at the top of the page. Copy this link address and
  5511. run the following commands:</p><pre class="screen">$ git checkout -b &lt;test-branch-name&gt;
  5512. $ wget -O - &lt;mbox-url&gt; | git am</pre><p>Another option for applying patches is to create a bundle. A bundle is
  5513. a set of patches that you can group together using the patchwork
  5514. interface. Once the bundle is created and the bundle is made public,
  5515. you can copy the <code class="literal">mbox</code> link for the bundle and apply the bundle
  5516. using the above commands.</p></div></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="_work_on_items_from_the_todo_list"></a>22.4. Work on items from the TODO list</h2></div></div></div><p>If you want to contribute to Buildroot but don’t know where to start,
  5517. and you don’t like any of the above topics, you can always work on items
  5518. from the <a class="ulink" href="http://elinux.org/Buildroot#Todo_list" target="_top">Buildroot TODO list</a>.
  5519. Don’t hesitate to discuss an item first on the mailing list or on IRC.
  5520. Do edit the wiki to indicate when you start working on an item, so we
  5521. avoid duplicate efforts.</p></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="submitting-patches"></a>22.5. Submitting patches</h2></div></div></div><div class="note" style="margin-left: 0; margin-right: 10%;"><h3 class="title">Note</h3><p><span class="emphasis"><em>Please, do not attach patches to bugs, send them to the mailing list
  5522. instead</em></span>.</p></div><p>If you made some changes to Buildroot and you would like to contribute
  5523. them to the Buildroot project, proceed as follows.</p><div class="section"><div class="titlepage"><div><div><h3 class="title"><a id="_the_formatting_of_a_patch"></a>22.5.1. The formatting of a patch</h3></div></div></div><p>We expect patches to be formatted in a specific way. This is necessary
  5524. to make it easy to review patches, to be able to apply them easily to
  5525. the git repository, to make it easy to find back in the history how
  5526. and why things have changed, and to make it possible to use <code class="literal">git
  5527. bisect</code> to locate the origin of a problem.</p><p>First of all, it is essential that the patch has a good commit
  5528. message. The commit message should start with a separate line with a
  5529. brief summary of the change, prefixed by the area touched by the
  5530. patch. A few examples of good commit titles:</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
  5531. <code class="literal">package/linuxptp: bump version to 2.0</code>
  5532. </li><li class="listitem">
  5533. <code class="literal">configs/imx23evk: bump Linux version to 4.19</code>
  5534. </li><li class="listitem">
  5535. <code class="literal">package/pkg-generic: postpone evaluation of dependency conditions</code>
  5536. </li><li class="listitem">
  5537. <code class="literal">boot/uboot: needs host-{flex,bison}</code>
  5538. </li><li class="listitem">
  5539. <code class="literal">support/testing: add python-ubjson tests</code>
  5540. </li></ul></div><p>The description that follows the prefix should start with a lower case
  5541. letter (i.e "bump", "needs", "postpone", "add" in the above examples).</p><p>Second, the body of the commit message should describe <span class="emphasis"><em>why</em></span> this
  5542. change is needed, and if necessary also give details about <span class="emphasis"><em>how</em></span> it
  5543. was done. When writing the commit message, think of how the reviewers
  5544. will read it, but also think about how you will read it when you look
  5545. at this change again a few years down the line.</p><p>Third, the patch itself should do only one change, but do it
  5546. completely. Two unrelated or weakly related changes should usually be
  5547. done in two separate patches. This usually means that a patch affects
  5548. only a single package. If several changes are related, it is often
  5549. still possible to split them up in small patches and apply them in a
  5550. specific order. Small patches make it easier to review, and often
  5551. make it easier to understand afterwards why a change was done.
  5552. However, each patch must be complete. It is not allowed that the
  5553. build is broken when only the first but not the second patch is
  5554. applied. This is necessary to be able to use <code class="literal">git bisect</code> afterwards.</p><p>Of course, while you’re doing your development, you’re probably going
  5555. back and forth between packages, and certainly not committing things
  5556. immediately in a way that is clean enough for submission. So most
  5557. developers rewrite the history of commits to produce a clean set of
  5558. commits that is appropriate for submission. To do this, you need to
  5559. use <span class="emphasis"><em>interactive rebasing</em></span>. You can learn about it
  5560. <a class="ulink" href="https://git-scm.com/book/en/v2/Git-Tools-Rewriting-History" target="_top">in the Pro
  5561. Git book</a>. Sometimes, it is even easier to discard you history with
  5562. <code class="literal">git reset --soft origin/master</code> and select individual changes with
  5563. <code class="literal">git add -i</code> or <code class="literal">git add -p</code>.</p><p>Finally, the patch should be signed off. This is done by adding
  5564. <code class="literal">Signed-off-by: Your Real Name &lt;<a class="ulink" href="mailto:your@email.address" target="_top">your@email.address</a>&gt;</code> at the end of the
  5565. commit message. <code class="literal">git commit -s</code> does that for you, if configured
  5566. properly. The <code class="literal">Signed-off-by</code> tag means that you publish the patch
  5567. under the Buildroot license (i.e. GPL-2.0+, except for package patches,
  5568. which have the upstream license), and that you are allowed to do so.
  5569. See <a class="ulink" href="http://developercertificate.org/" target="_top">the Developer Certificate of
  5570. Origin</a> for details.</p><p>To give credits to who sponsored the creation of a patch or the process of
  5571. upstreaming it, you may use
  5572. <a class="ulink" href="https://datatracker.ietf.org/doc/html/rfc5233" target="_top">email subaddressing</a> for
  5573. your git identity (i.e. what is used as commit author and email <code class="literal">From:</code>
  5574. field, as well as your Signed-off-by tag); add suffix to the local part,
  5575. separated from it by a plus <code class="literal">+</code> sign. E.g.:</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p class="simpara">
  5576. for a company which sponsored the submitted work, use the company name
  5577. as the detail (suffix) part:
  5578. </p><p class="simpara"><code class="literal">Your-Name Your-Surname &lt;your-name.your-surname+companyname@mail.com&gt;</code></p></li><li class="listitem"><p class="simpara">
  5579. for an individual who sponsored the submitted work, use
  5580. their name and surname:
  5581. </p><p class="simpara"><code class="literal">Your-Name Your-Surname &lt;your-name.your-surname+their-name.their-surname@mail.com&gt;</code></p></li></ul></div><p>When adding new packages, you should submit every package in a
  5582. separate patch. This patch should have the update to
  5583. <code class="literal">package/Config.in</code>, the package <code class="literal">Config.in</code> file, the <code class="literal">.mk</code> file, the
  5584. <code class="literal">.hash</code> file, any init script, and all package patches. If the package
  5585. has many sub-options, these are sometimes better added as separate
  5586. follow-up patches. The summary line should be something like
  5587. <code class="literal">&lt;packagename&gt;: new package</code>. The body of the commit message can be
  5588. empty for simple packages, or it can contain the description of the
  5589. package (like the Config.in help text). If anything special has to be
  5590. done to build the package, this should also be explained explicitly in
  5591. the commit message body.</p><p>When you bump a package to a new version, you should also submit a
  5592. separate patch for each package. Don’t forget to update the <code class="literal">.hash</code>
  5593. file, or add it if it doesn’t exist yet. Also don’t forget to check if
  5594. the <code class="literal">_LICENSE</code> and <code class="literal">_LICENSE_FILES</code> are still valid. The summary line
  5595. should be something like <code class="literal">&lt;packagename&gt;: bump to version &lt;new
  5596. version&gt;</code>. If the new version only contains security updates compared
  5597. to the existing one, the summary should be <code class="literal">&lt;packagename&gt;: security
  5598. bump to version &lt;new version&gt;</code> and the commit message body should show
  5599. the CVE numbers that are fixed. If some package patches can be removed
  5600. in the new version, it should be explained explicitly why they can be
  5601. removed, preferably with the upstream commit ID. Also any other
  5602. required changes should be explained explicitly, like configure
  5603. options that no longer exist or are no longer needed.</p><p>If you are interested in getting notified of build failures and of
  5604. further changes in the packages you added or modified, please add
  5605. yourself to the DEVELOPERS file. This should be done in the same patch
  5606. creating or modifying the package. See <a class="link" href="#DEVELOPERS" title="Chapter 23. DEVELOPERS file and get-developers">the DEVELOPERS file</a>
  5607. for more information.</p><p>Buildroot provides a handy tool to check for common coding style
  5608. mistakes on files you created or modified, called <code class="literal">check-package</code> (see
  5609. <a class="xref" href="#check-package" title="18.25.2. How to check the coding style">Section 18.25.2, “How to check the coding style”</a> for more information).</p></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a id="_preparing_a_patch_series"></a>22.5.2. Preparing a patch series</h3></div></div></div><p>Starting from the changes committed in your local git view, <span class="emphasis"><em>rebase</em></span>
  5610. your development branch on top of the upstream tree before generating
  5611. a patch set. To do so, run:</p><pre class="screen">$ git fetch --all --tags
  5612. $ git rebase origin/master</pre><p>Now check the coding style for the changes you committed:</p><pre class="screen">$ utils/docker-run make check-package</pre><p>Now, you are ready to generate then submit your patch set.</p><p>To generate it, run:</p><pre class="screen">$ git format-patch -M -n -s -o outgoing origin/master</pre><p>This will generate patch files in the <code class="literal">outgoing</code> subdirectory,
  5613. automatically adding the <code class="literal">Signed-off-by</code> line.</p><p>Once patch files are generated, you can review/edit the commit message
  5614. before submitting them, using your favorite text editor.</p><p>Buildroot provides a handy tool to know to whom your patches should be
  5615. sent, called <code class="literal">get-developers</code> (see <a class="xref" href="#DEVELOPERS" title="Chapter 23. DEVELOPERS file and get-developers">Chapter 23, <em>DEVELOPERS file and get-developers</em></a> for more
  5616. information). This tool reads your patches and outputs the appropriate
  5617. <code class="literal">git send-email</code> command to use:</p><pre class="screen">$ ./utils/get-developers outgoing/*</pre><p>Use the output of <code class="literal">get-developers</code> to send your patches:</p><pre class="screen">$ git send-email --to buildroot@buildroot.org --cc bob --cc alice outgoing/*</pre><p>Alternatively, <code class="literal">get-developers -e</code> can be used directly with the
  5618. <code class="literal">--cc-cmd</code> argument to <code class="literal">git send-email</code> to automatically CC the
  5619. affected developers:</p><pre class="screen">$ git send-email --to buildroot@buildroot.org \
  5620. --cc-cmd './utils/get-developers -e' origin/master</pre><p><code class="literal">git</code> can be configured to automatically do this out of the box with:</p><pre class="screen">$ git config sendemail.to buildroot@buildroot.org
  5621. $ git config sendemail.ccCmd "$(pwd)/utils/get-developers -e"</pre><p>And then just do:</p><pre class="screen">$ git send-email origin/master</pre><p>Note that <code class="literal">git</code> should be configured to use your mail account.
  5622. To configure <code class="literal">git</code>, see <code class="literal">man git-send-email</code> or <a class="ulink" href="https://git-send-email.io/" target="_top">https://git-send-email.io/</a>.</p><p>If you do not use <code class="literal">git send-email</code>, make sure posted <span class="strong"><strong>patches are not
  5623. line-wrapped</strong></span>, otherwise they cannot easily be applied. In such a case,
  5624. fix your e-mail client, or better yet, learn to use <code class="literal">git send-email</code>.</p><p><a class="ulink" href="https://sr.ht" target="_top">https://sr.ht</a> also has a light-weight UI for
  5625. <a class="ulink" href="https://man.sr.ht/git.sr.ht/#sending-patches-upstream" target="_top">preparing patchseries</a>
  5626. and can also send out the patches for you. There are a few drawbacks to
  5627. this, as you cannot edit your patches' status in Patchwork and you
  5628. currently can’t edit your display name with which the match emails are
  5629. sent out but it is an option if you cannot get git send-email to work
  5630. with your mail provider (i.e. O365); it shall not be considered the
  5631. official way of sending patches, but just a fallback.</p></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a id="_cover_letter"></a>22.5.3. Cover letter</h3></div></div></div><p>If you want to present the whole patch set in a separate mail, add
  5632. <code class="literal">--cover-letter</code> to the <code class="literal">git format-patch</code> command (see <code class="literal">man
  5633. git-format-patch</code> for further information). This will generate a
  5634. template for an introduction e-mail to your patch series.</p><p>A <span class="emphasis"><em>cover letter</em></span> may be useful to introduce the changes you propose
  5635. in the following cases:</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
  5636. large number of commits in the series;
  5637. </li><li class="listitem">
  5638. deep impact of the changes in the rest of the project;
  5639. </li><li class="listitem">
  5640. RFC <a href="#ftn.idm5958" class="footnote" id="idm5958"><sup class="footnote">[4]</sup></a>;
  5641. </li><li class="listitem">
  5642. whenever you feel it will help presenting your work, your choices,
  5643. the review process, etc.
  5644. </li></ul></div></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a id="_patches_for_maintenance_branches"></a>22.5.4. Patches for maintenance branches</h3></div></div></div><p>When fixing bugs on a maintenance branch, bugs should be fixed on the
  5645. master branch first. The commit log for such a patch may then contain a
  5646. post-commit note specifying what branches are affected:</p><pre class="screen">package/foo: fix stuff
  5647. Signed-off-by: Your Real Name &lt;your@email.address&gt;
  5648. ---
  5649. Backport to: 2020.02.x, 2020.05.x
  5650. (2020.08.x not affected as the version was bumped)</pre><p>Those changes will then be backported by a maintainer to the affected
  5651. branches.</p><p>However, some bugs may apply only to a specific release, for example
  5652. because it is using an older version of a package. In that case, patches
  5653. should be based off the maintenance branch, and the patch subject prefix
  5654. must include the maintenance branch name (for example "[PATCH 2020.02.x]").
  5655. This can be done with the <code class="literal">git format-patch</code> flag <code class="literal">--subject-prefix</code>:</p><pre class="screen">$ git format-patch --subject-prefix "PATCH 2020.02.x" \
  5656. -M -s -o outgoing origin/2020.02.x</pre><p>Then send the patches with <code class="literal">git send-email</code>, as described above.</p></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a id="_patch_revision_changelog"></a>22.5.5. Patch revision changelog</h3></div></div></div><p>When improvements are requested, the new revision of each commit
  5657. should include a changelog of the modifications between each
  5658. submission. Note that when your patch series is introduced by a cover
  5659. letter, an overall changelog may be added to the cover letter in
  5660. addition to the changelog in the individual commits.
  5661. The best thing to rework a patch series is by interactive rebasing:
  5662. <code class="literal">git rebase -i origin/master</code>. Consult the git manual for more
  5663. information.</p><p>When added to the individual commits, this changelog is added when
  5664. editing the commit message. Below the <code class="literal">Signed-off-by</code> section, add
  5665. <code class="literal">---</code> and your changelog.</p><p>Although the changelog will be visible for the reviewers in the mail
  5666. thread, as well as in
  5667. <a class="ulink" href="https://patchwork.ozlabs.org/project/buildroot/list/" target="_top">patchwork</a>, <code class="literal">git</code>
  5668. will automatically ignores lines below <code class="literal">---</code> when the patch will be
  5669. merged. This is the intended behavior: the changelog is not meant to
  5670. be preserved forever in the <code class="literal">git</code> history of the project.</p><p>Hereafter the recommended layout:</p><pre class="screen">Patch title: short explanation, max 72 chars
  5671. A paragraph that explains the problem, and how it manifests itself. If
  5672. the problem is complex, it is OK to add more paragraphs. All paragraphs
  5673. should be wrapped at 72 characters.
  5674. A paragraph that explains the root cause of the problem. Again, more
  5675. than one paragraph is OK.
  5676. Finally, one or more paragraphs that explain how the problem is solved.
  5677. Don't hesitate to explain complex solutions in detail.
  5678. Signed-off-by: John DOE &lt;john.doe@example.net&gt;
  5679. ---
  5680. Changes v2 -&gt; v3:
  5681. - foo bar (suggested by Jane)
  5682. - bar buz
  5683. Changes v1 -&gt; v2:
  5684. - alpha bravo (suggested by John)
  5685. - charly delta</pre><p>Any patch revision should include the version number. The version number
  5686. is simply composed of the letter <code class="literal">v</code> followed by an <code class="literal">integer</code> greater or
  5687. equal to two (i.e. "PATCH v2", "PATCH v3" …).</p><p>This can be easily handled with <code class="literal">git format-patch</code> by using the option
  5688. <code class="literal">--subject-prefix</code>:</p><pre class="screen">$ git format-patch --subject-prefix "PATCH v4" \
  5689. -M -s -o outgoing origin/master</pre><p>Since git version 1.8.1, you can also use <code class="literal">-v &lt;n&gt;</code> (where &lt;n&gt; is the
  5690. version number):</p><pre class="screen">$ git format-patch -v4 -M -s -o outgoing origin/master</pre><p>When you provide a new version of a patch, please mark the old one as
  5691. superseded in
  5692. <a class="ulink" href="https://patchwork.ozlabs.org/project/buildroot/list/" target="_top">patchwork</a>. You
  5693. need to create an account on
  5694. <a class="ulink" href="https://patchwork.ozlabs.org/project/buildroot/list/" target="_top">patchwork</a> to be
  5695. able to modify the status of your patches. Note that you can only change
  5696. the status of patches you submitted yourself, which means the email
  5697. address you register in
  5698. <a class="ulink" href="https://patchwork.ozlabs.org/project/buildroot/list/" target="_top">patchwork</a> should
  5699. match the one you use for sending patches to the mailing list.</p><p>You can also add the <code class="literal">--in-reply-to=&lt;message-id&gt;</code> option when
  5700. submitting a patch to the mailing list. The id of the mail to reply to
  5701. can be found under the "Message Id" tag on
  5702. <a class="ulink" href="https://patchwork.ozlabs.org/project/buildroot/list/" target="_top">patchwork</a>. The
  5703. advantage of <span class="strong"><strong>in-reply-to</strong></span> is that patchwork will automatically mark
  5704. the previous version of the patch as superseded.</p></div></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="reporting-bugs"></a>22.6. Reporting issues/bugs or getting help</h2></div></div></div><p>Before reporting any issue, please check in
  5705. <a class="link" href="#community-resources" title="Chapter 5. Community resources">the mailing list archive</a> whether someone has
  5706. already reported and/or fixed a similar problem.</p><p>However you choose to report bugs or get help, either by
  5707. opening a bug in the <a class="link" href="#community-resources" title="Chapter 5. Community resources">bug tracker</a> or by
  5708. <a class="link" href="#community-resources" title="Chapter 5. Community resources">sending a mail to the mailing list</a>, there are
  5709. a number of details to provide in order to help people reproduce and
  5710. find a solution to the issue.</p><p>Try to think as if you were trying to help someone else; in
  5711. that case, what would you need?</p><p>Here is a short list of details to provide in such case:</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
  5712. host machine (OS/release)
  5713. </li><li class="listitem">
  5714. version of Buildroot
  5715. </li><li class="listitem">
  5716. target for which the build fails
  5717. </li><li class="listitem">
  5718. package(s) for which the build fails
  5719. </li><li class="listitem">
  5720. the command that fails and its output
  5721. </li><li class="listitem">
  5722. any information you think that may be relevant
  5723. </li></ul></div><p>Additionally, you should add the <code class="literal">.config</code> file (or if you know how, a
  5724. <code class="literal">defconfig</code>; see <a class="xref" href="#customize-store-buildroot-config" title="9.3. Storing the Buildroot configuration">Section 9.3, “Storing the Buildroot configuration”</a>).</p><p>If some of these details are too large, do not hesitate to use a
  5725. pastebin service. Note that not all available pastebin services will
  5726. preserve Unix-style line terminators when downloading raw pastes.
  5727. Following pastebin services are known to work correctly:
  5728. - <a class="ulink" href="https://gist.github.com/" target="_top">https://gist.github.com/</a>
  5729. - <a class="ulink" href="http://code.bulix.org/" target="_top">http://code.bulix.org/</a></p></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="_using_the_runtime_tests_framework"></a>22.7. Using the runtime tests framework</h2></div></div></div><p>Buildroot includes a run-time testing framework built upon Python
  5730. scripting and QEMU runtime execution. The goals of the framework are
  5731. the following:</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
  5732. build a well defined Buildroot configuration
  5733. </li><li class="listitem">
  5734. optionally, verify some properties of the build output
  5735. </li><li class="listitem">
  5736. optionally, boot the build results under Qemu, and verify that a
  5737. given feature is working as expected
  5738. </li></ul></div><p>The entry point to use the runtime tests framework is the
  5739. <code class="literal">support/testing/run-tests</code> tool, which has a series of options
  5740. documented in the tool’s help <span class="emphasis"><em>-h</em></span> description. Some common options
  5741. include setting the download folder, the output folder, keeping build
  5742. output, and for multiple test cases, you can set the JLEVEL for each.</p><p>Here is an example walk through of running a test case.</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
  5743. For a first step, let us see what all the test case options are. The test
  5744. cases can be listed by executing <code class="literal">support/testing/run-tests -l</code>. These tests
  5745. can all be run individually during test development from the console. Both
  5746. one at a time and selectively as a group of a subset of tests.
  5747. </li></ul></div><pre class="screen">$ support/testing/run-tests -l
  5748. List of tests
  5749. test_run (tests.utils.test_check_package.TestCheckPackage)
  5750. test_run (tests.toolchain.test_external.TestExternalToolchainBuildrootMusl) ... ok
  5751. test_run (tests.toolchain.test_external.TestExternalToolchainBuildrootuClibc) ... ok
  5752. test_run (tests.toolchain.test_external.TestExternalToolchainCCache) ... ok
  5753. test_run (tests.toolchain.test_external.TestExternalToolchainCtngMusl) ... ok
  5754. test_run (tests.toolchain.test_external.TestExternalToolchainLinaroArm) ... ok
  5755. test_run (tests.toolchain.test_external.TestExternalToolchainSourceryArmv4) ... ok
  5756. test_run (tests.toolchain.test_external.TestExternalToolchainSourceryArmv5) ... ok
  5757. test_run (tests.toolchain.test_external.TestExternalToolchainSourceryArmv7) ... ok
  5758. [snip]
  5759. test_run (tests.init.test_systemd.TestInitSystemSystemdRoFull) ... ok
  5760. test_run (tests.init.test_systemd.TestInitSystemSystemdRoIfupdown) ... ok
  5761. test_run (tests.init.test_systemd.TestInitSystemSystemdRoNetworkd) ... ok
  5762. test_run (tests.init.test_systemd.TestInitSystemSystemdRwFull) ... ok
  5763. test_run (tests.init.test_systemd.TestInitSystemSystemdRwIfupdown) ... ok
  5764. test_run (tests.init.test_systemd.TestInitSystemSystemdRwNetworkd) ... ok
  5765. test_run (tests.init.test_busybox.TestInitSystemBusyboxRo) ... ok
  5766. test_run (tests.init.test_busybox.TestInitSystemBusyboxRoNet) ... ok
  5767. test_run (tests.init.test_busybox.TestInitSystemBusyboxRw) ... ok
  5768. test_run (tests.init.test_busybox.TestInitSystemBusyboxRwNet) ... ok
  5769. Ran 157 tests in 0.021s
  5770. OK</pre><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
  5771. Then, to run one test case:
  5772. </li></ul></div><pre class="screen">$ support/testing/run-tests -d dl -o output_folder -k tests.init.test_busybox.TestInitSystemBusyboxRw
  5773. 15:03:26 TestInitSystemBusyboxRw Starting
  5774. 15:03:28 TestInitSystemBusyboxRw Building
  5775. 15:08:18 TestInitSystemBusyboxRw Building done
  5776. 15:08:27 TestInitSystemBusyboxRw Cleaning up
  5777. .
  5778. Ran 1 test in 301.140s
  5779. OK</pre><p>The standard output indicates if the test is successful or not. By
  5780. default, the output folder for the test is deleted automatically
  5781. unless the option <code class="literal">-k</code> is passed to <span class="strong"><strong>keep</strong></span> the output directory.</p><div class="section"><div class="titlepage"><div><div><h3 class="title"><a id="_creating_a_test_case"></a>22.7.1. Creating a test case</h3></div></div></div><p>Within the Buildroot repository, the testing framework is organized at the
  5782. top level in <code class="literal">support/testing/</code> by folders of <code class="literal">conf</code>, <code class="literal">infra</code> and <code class="literal">tests</code>.
  5783. All the test cases live under the <code class="literal">tests</code> folder and are organized in various
  5784. folders representing the category of test.</p><p>The best way to get familiar with how to create a test case is to look
  5785. at a few of the basic file system <code class="literal">support/testing/tests/fs/</code> and init
  5786. <code class="literal">support/testing/tests/init/</code> test scripts. Those tests give good
  5787. examples of a basic tests that include both checking the build
  5788. results, and doing runtime tests. There are other more advanced cases
  5789. that use things like nested <code class="literal">br2-external</code> folders to provide
  5790. skeletons and additional packages.</p><p>Creating a basic test case involves:</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
  5791. Defining a test class that inherits from <code class="literal">infra.basetest.BRTest</code>
  5792. </li><li class="listitem">
  5793. Defining the <code class="literal">config</code> member of the test class, to the Buildroot
  5794. configuration to build for this test case. It can optionally rely on
  5795. configuration snippets provided by the runtime test infrastructure:
  5796. <code class="literal">infra.basetest.BASIC_TOOLCHAIN_CONFIG</code> to get a basic
  5797. architecture/toolchain configuration, and
  5798. <code class="literal">infra.basetest.MINIMAL_CONFIG</code> to not build any filesystem. The
  5799. advantage of using <code class="literal">infra.basetest.BASIC_TOOLCHAIN_CONFIG</code> is that a
  5800. matching Linux kernel image is provided, which allows to boot the
  5801. resulting image in Qemu without having to build a Linux kernel image
  5802. as part of the test case, therefore significant decreasing the build
  5803. time required for the test case.
  5804. </li><li class="listitem">
  5805. Implementing a <code class="literal">def test_run(self):</code> function to implement the
  5806. actual tests to run after the build has completed. They may be tests
  5807. that verify the build output, by running command on the host using
  5808. the <code class="literal">run_cmd_on_host()</code> helper function. Or they may boot the
  5809. generated system in Qemu using the <code class="literal">Emulator</code> object available as
  5810. <code class="literal">self.emulator</code> in the test case. For example <code class="literal">self.emulator.boot()</code>
  5811. allows to boot the system in Qemu, <code class="literal">self.emulator.login()</code> allows to
  5812. login, <code class="literal">self.emulator.run()</code> allows to run shell commands inside
  5813. Qemu.
  5814. </li></ul></div><p>After creating the test script, add yourself to the <code class="literal">DEVELOPERS</code> file to
  5815. be the maintainer of that test case.</p></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a id="_debugging_a_test_case"></a>22.7.2. Debugging a test case</h3></div></div></div><p>When a test case runs, the <code class="literal">output_folder</code> will contain the following:</p><pre class="screen">$ ls output_folder/
  5816. TestInitSystemBusyboxRw/
  5817. TestInitSystemBusyboxRw-build.log
  5818. TestInitSystemBusyboxRw-run.log</pre><p><code class="literal">TestInitSystemBusyboxRw/</code> is the Buildroot output directory, and it
  5819. is preserved only if the <code class="literal">-k</code> option is passed.</p><p><code class="literal">TestInitSystemBusyboxRw-build.log</code> is the log of the Buildroot build.</p><p><code class="literal">TestInitSystemBusyboxRw-run.log</code> is the log of the Qemu boot and
  5820. test. This file will only exist if the build was successful and the
  5821. test case involves booting under Qemu.</p><p>If you want to manually run Qemu to do manual tests of the build
  5822. result, the first few lines of <code class="literal">TestInitSystemBusyboxRw-run.log</code>
  5823. contain the Qemu command line to use.</p><p>You can also make modifications to the current sources inside the
  5824. <code class="literal">output_folder</code> (e.g. for debug purposes) and rerun the standard
  5825. Buildroot make targets (in order to regenerate the complete image with
  5826. the new modifications) and then rerun the test.</p></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a id="_runtime_tests_and_gitlab_ci"></a>22.7.3. Runtime tests and Gitlab CI</h3></div></div></div><p>All runtime tests are regularly executed by Buildroot Gitlab CI
  5827. infrastructure, see .gitlab.yml and
  5828. <a class="ulink" href="https://gitlab.com/buildroot.org/buildroot/-/jobs" target="_top">https://gitlab.com/buildroot.org/buildroot/-/jobs</a>.</p><p>You can also use Gitlab CI to test your new test cases, or verify that
  5829. existing tests continue to work after making changes in Buildroot.</p><p>In order to achieve this, you need to create a fork of the Buildroot
  5830. project on Gitlab, and be able to push branches to your Buildroot fork
  5831. on Gitlab.</p><p>The name of the branch that you push will determine if a Gitlab CI
  5832. pipeline will be triggered or not, and for which test cases.</p><p>In the examples below, the &lt;name&gt; component of the branch name is an
  5833. arbitrary string you choose.</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
  5834. To trigger all run-test test case jobs, push a branch that ends with
  5835. <code class="literal">-runtime-tests</code>:
  5836. </li></ul></div><pre class="screen"> $ git push gitlab HEAD:&lt;name&gt;-runtime-tests</pre><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
  5837. To trigger one or several test case jobs, push a branch that ends
  5838. with the complete test case name
  5839. (<code class="literal">tests.init.test_busybox.TestInitSystemBusyboxRo</code>) or with the name
  5840. of a category of tests (<code class="literal">tests.init.test_busybox</code>):
  5841. </li></ul></div><pre class="screen"> $ git push gitlab HEAD:&lt;name&gt;-&lt;test case name&gt;</pre><p>Example to run one test:</p><pre class="screen"> $ git push gitlab HEAD:foo-tests.init.test_busybox.TestInitSystemBusyboxRo</pre><p>Examples to run several tests part of the same group:</p><pre class="screen"> $ git push gitlab HEAD:foo-tests.init.test_busybox
  5842. $ git push gitlab HEAD:foo-tests.init</pre></div></div><div class="footnotes"><br /><hr style="width:100; text-align:left;margin-left: 0" /><div id="ftn.idm5958" class="footnote"><p><a href="#idm5958" class="simpara"><sup class="simpara">[4] </sup></a>RFC: (Request for comments) change proposal</p></div></div></div><div class="chapter"><div class="titlepage"><div><div><h2 class="title"><a id="DEVELOPERS"></a>Chapter 23. DEVELOPERS file and get-developers</h2></div></div></div><p>The main Buildroot directory contains a file named <code class="literal">DEVELOPERS</code> that
  5843. lists the developers involved with various areas of Buildroot. Thanks
  5844. to this file, the <code class="literal">get-developers</code> tool allows to:</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
  5845. Calculate the list of developers to whom patches should be sent, by
  5846. parsing the patches and matching the modified files with the
  5847. relevant developers. See <a class="xref" href="#submitting-patches" title="22.5. Submitting patches">Section 22.5, “Submitting patches”</a> for details.
  5848. </li><li class="listitem">
  5849. Find which developers are taking care of a given architecture or
  5850. package, so that they can be notified when a build failure occurs on
  5851. this architecture or package. This is done in interaction with
  5852. Buildroot’s autobuild infrastructure.
  5853. </li></ul></div><p>We ask developers adding new packages, new boards, or generally new
  5854. functionality in Buildroot, to register themselves in the <code class="literal">DEVELOPERS</code>
  5855. file. As an example, we expect a developer contributing a new package
  5856. to include in his patch the appropriate modification to the
  5857. <code class="literal">DEVELOPERS</code> file.</p><p>The <code class="literal">DEVELOPERS</code> file format is documented in detail inside the file
  5858. itself.</p><p>The <code class="literal">get-developers</code> tool, located in <code class="literal">utils/</code> allows to use
  5859. the <code class="literal">DEVELOPERS</code> file for various tasks:</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
  5860. When passing one or several patches as command line argument,
  5861. <code class="literal">get-developers</code> will return the appropriate <code class="literal">git send-email</code>
  5862. command. If the <code class="literal">-e</code> option is passed, only the email addresses are
  5863. printed in a format suitable for <code class="literal">git send-email --cc-cmd</code>.
  5864. </li><li class="listitem">
  5865. When using the <code class="literal">-a &lt;arch&gt;</code> command line option, <code class="literal">get-developers</code> will
  5866. return the list of developers in charge of the given architecture.
  5867. </li><li class="listitem">
  5868. When using the <code class="literal">-p &lt;package&gt;</code> command line option, <code class="literal">get-developers</code>
  5869. will return the list of developers in charge of the given package.
  5870. </li><li class="listitem">
  5871. When using the <code class="literal">-c</code> command line option, <code class="literal">get-developers</code> will look
  5872. at all files under version control in the Buildroot repository, and
  5873. list the ones that are not handled by any developer. The purpose of
  5874. this option is to help completing the <code class="literal">DEVELOPERS</code> file.
  5875. </li><li class="listitem">
  5876. When using the <code class="literal">-v</code> command line option, it validates the integrity
  5877. of the DEVELOPERS file and will note WARNINGS for items that don’t
  5878. match.
  5879. </li></ul></div></div><div class="chapter"><div class="titlepage"><div><div><h2 class="title"><a id="RELENG"></a>Chapter 24. Release Engineering</h2></div></div></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="_releases"></a>24.1. Releases</h2></div></div></div><p>The Buildroot project makes quarterly releases with monthly bugfix
  5880. releases. The first release of each year is a long term support
  5881. release, LTS.</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
  5882. Quarterly releases: 2020.02, 2020.05, 2020.08, and 2020.11
  5883. </li><li class="listitem">
  5884. Bugfix releases: 2020.02.1, 2020.02.2, …
  5885. </li><li class="listitem">
  5886. LTS releases: 2020.02, 2021.02, …
  5887. </li></ul></div><p>Releases are supported until the first bugfix release of the next
  5888. release, e.g., 2020.05.x is EOL when 2020.08.1 is released.</p><p>LTS releases are supported until the first bugfix release of the next
  5889. LTS, e.g., 2020.02.x is supported until 2021.02.1 is released.</p></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="_development"></a>24.2. Development</h2></div></div></div><p>Each release cycle consist of two months of development on the <code class="literal">master</code>
  5890. branch and one month stabilization before the release is made. During
  5891. this phase no new features are added to <code class="literal">master</code>, only bugfixes.</p><p>The stabilization phase starts with tagging <code class="literal">-rc1</code>, and every week until
  5892. the release, another release candidate is tagged.</p><p>To handle new features and version bumps during the stabilization phase,
  5893. a <code class="literal">next</code> branch may be created for these features. Once the current
  5894. release has been made, the <code class="literal">next</code> branch is merged into <code class="literal">master</code> and
  5895. the development cycle for the next release continues there.</p></div></div></div><div class="part"><div class="titlepage"><div><div><h1 class="title"><a id="_appendix"></a>Part IV. Appendix</h1></div></div></div><div class="chapter"><div class="titlepage"><div><div><h2 class="title"><a id="makedev-syntax"></a>Chapter 25. Makedev syntax documentation</h2></div></div></div><p>The makedev syntax is used in several places in Buildroot to
  5896. define changes to be made for permissions, or which device files to
  5897. create and how to create them, in order to avoid calls to mknod.</p><p>This syntax is derived from the makedev utility, and more complete
  5898. documentation can be found in the <code class="literal">package/makedevs/README</code> file.</p><p>It takes the form of a space separated list of fields, one file per
  5899. line; the fields are:</p><div class="informaltable"><table class="informaltable" cellpadding="4px" style="border-collapse: collapse;border-top: 3px solid #527bbd; border-bottom: 3px solid #527bbd; border-left: 3px solid #527bbd; border-right: 3px solid #527bbd; "><colgroup><col class="col_1" /><col class="col_2" /><col class="col_3" /><col class="col_4" /><col class="col_5" /><col class="col_6" /><col class="col_7" /><col class="col_8" /><col class="col_9" /><col class="col_10" /></colgroup><tbody><tr><td style="border-right: 1px solid #527bbd; " align="left" valign="top"><p>name</p></td><td style="border-right: 1px solid #527bbd; " align="left" valign="top"><p>type</p></td><td style="border-right: 1px solid #527bbd; " align="left" valign="top"><p>mode</p></td><td style="border-right: 1px solid #527bbd; " align="left" valign="top"><p>uid</p></td><td style="border-right: 1px solid #527bbd; " align="left" valign="top"><p>gid</p></td><td style="border-right: 1px solid #527bbd; " align="left" valign="top"><p>major</p></td><td style="border-right: 1px solid #527bbd; " align="left" valign="top"><p>minor</p></td><td style="border-right: 1px solid #527bbd; " align="left" valign="top"><p>start</p></td><td style="border-right: 1px solid #527bbd; " align="left" valign="top"><p>inc</p></td><td style="" align="left" valign="top"><p>count</p></td></tr></tbody></table></div><p>There are a few non-trivial blocks:</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
  5900. <code class="literal">name</code> is the path to the file you want to create/modify
  5901. </li><li class="listitem"><p class="simpara">
  5902. <code class="literal">type</code> is the type of the file, being one of:
  5903. </p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: circle; "><li class="listitem">
  5904. <code class="literal">f</code>: a regular file, which must already exist
  5905. </li><li class="listitem">
  5906. <code class="literal">F</code>: a regular file, which is ignored and not created if missing
  5907. </li><li class="listitem">
  5908. <code class="literal">d</code>: a directory, which is created, as well as its parents, if missing
  5909. </li><li class="listitem">
  5910. <code class="literal">r</code>: a directory recursively, which must already exist
  5911. </li><li class="listitem">
  5912. <code class="literal">c</code>: a character device file, which parent directory must exist
  5913. </li><li class="listitem">
  5914. <code class="literal">b</code>: a block device file, which parent directory must exist
  5915. </li><li class="listitem">
  5916. <code class="literal">p</code>: a named pipe, which parent directory must exist
  5917. </li></ul></div></li><li class="listitem">
  5918. <code class="literal">mode</code> are the usual permissions settings (only numerical values
  5919. are allowed);
  5920. for type <code class="literal">d</code>, the mode of existing parents is not changed, but the mode
  5921. of created parents is set;
  5922. for types <code class="literal">f</code>, <code class="literal">F</code>, and <code class="literal">r</code>, <code class="literal">mode</code> can also be set to <code class="literal">-1</code> to not
  5923. change the mode (and only change uid and gid)
  5924. </li><li class="listitem">
  5925. <code class="literal">uid</code> and <code class="literal">gid</code> are the UID and GID to set on this file; can be
  5926. either numerical values or actual names
  5927. </li><li class="listitem">
  5928. <code class="literal">major</code> and <code class="literal">minor</code> are here for device files, set to <code class="literal">-</code> for other
  5929. files
  5930. </li><li class="listitem">
  5931. <code class="literal">start</code>, <code class="literal">inc</code> and <code class="literal">count</code> are for when you want to create a batch
  5932. of files, and can be reduced to a loop, beginning at <code class="literal">start</code>,
  5933. incrementing its counter by <code class="literal">inc</code> until it reaches <code class="literal">count</code>
  5934. </li></ul></div><p>Let’s say you want to change the ownership and permissions of a given
  5935. file; using this syntax, you will need to write:</p><pre class="screen">/usr/bin/foo f 755 0 0 - - - - -
  5936. /usr/bin/bar f 755 root root - - - - -
  5937. /data/buz f 644 buz-user buz-group - - - - -
  5938. /data/baz f -1 baz-user baz-group - - - - -</pre><p>Alternatively, if you want to change owner of a directory recursively,
  5939. you can write (to set UID to <code class="literal">foo</code> and GID to <code class="literal">bar</code> for the directory
  5940. <code class="literal">/usr/share/myapp</code> and all files and directories below it):</p><pre class="screen">/usr/share/myapp r -1 foo bar - - - - -</pre><p>On the other hand, if you want to create the device file <code class="literal">/dev/hda</code>
  5941. and the corresponding 15 files for the partitions, you will need for
  5942. <code class="literal">/dev/hda</code>:</p><pre class="screen">/dev/hda b 640 root root 3 0 0 0 -</pre><p>and then for device files corresponding to the partitions of
  5943. <code class="literal">/dev/hda</code>, <code class="literal">/dev/hdaX</code>, <code class="literal">X</code> ranging from 1 to 15:</p><pre class="screen">/dev/hda b 640 root root 3 1 1 1 15</pre><p>Extended attributes are supported if
  5944. <code class="literal">BR2_ROOTFS_DEVICE_TABLE_SUPPORTS_EXTENDED_ATTRIBUTES</code> is enabled.
  5945. This is done by adding a line starting with <code class="literal">|xattr</code> after
  5946. the line describing the file. Right now, only capability
  5947. is supported as extended attribute.</p><div class="informaltable"><table class="informaltable" cellpadding="4px" style="border-collapse: collapse;border-top: 3px solid #527bbd; border-bottom: 3px solid #527bbd; border-left: 3px solid #527bbd; border-right: 3px solid #527bbd; "><colgroup><col class="col_1" /><col class="col_2" /></colgroup><tbody><tr><td style="border-right: 1px solid #527bbd; " align="left" valign="top"><p>|xattr</p></td><td style="" align="left" valign="top"><p>capability</p></td></tr></tbody></table></div><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
  5948. <code class="literal">|xattr</code> is a "flag" that indicate an extended attribute
  5949. </li><li class="listitem">
  5950. <code class="literal">capability</code> is a capability to add to the previous file
  5951. </li></ul></div><p>If you want to add the capability cap_sys_admin to the binary foo,
  5952. you will write :</p><pre class="screen">/usr/bin/foo f 755 root root - - - - -
  5953. |xattr cap_sys_admin+eip</pre><p>You can add several capabilities to a file by using several <code class="literal">|xattr</code> lines.
  5954. If you want to add the capability cap_sys_admin and cap_net_admin to the
  5955. binary foo, you will write :</p><pre class="screen">/usr/bin/foo f 755 root root - - - - -
  5956. |xattr cap_sys_admin+eip
  5957. |xattr cap_net_admin+eip</pre></div><div class="chapter"><div class="titlepage"><div><div><h2 class="title"><a id="makeuser-syntax"></a>Chapter 26. Makeusers syntax documentation</h2></div></div></div><p>The syntax to create users is inspired by the makedev syntax, above, but
  5958. is specific to Buildroot.</p><p>The syntax for adding a user is a space-separated list of fields, one
  5959. user per line; the fields are:</p><div class="informaltable"><table class="informaltable" cellpadding="4px" style="border-collapse: collapse;border-top: 3px solid #527bbd; border-bottom: 3px solid #527bbd; border-left: 3px solid #527bbd; border-right: 3px solid #527bbd; "><colgroup><col class="col_1" /><col class="col_2" /><col class="col_3" /><col class="col_4" /><col class="col_5" /><col class="col_6" /><col class="col_7" /><col class="col_8" /><col class="col_9" /></colgroup><tbody><tr><td style="border-right: 1px solid #527bbd; " align="left" valign="top"><p>username</p></td><td style="border-right: 1px solid #527bbd; " align="left" valign="top"><p>uid</p></td><td style="border-right: 1px solid #527bbd; " align="left" valign="top"><p>group</p></td><td style="border-right: 1px solid #527bbd; " align="left" valign="top"><p>gid</p></td><td style="border-right: 1px solid #527bbd; " align="left" valign="top"><p>password</p></td><td style="border-right: 1px solid #527bbd; " align="left" valign="top"><p>home</p></td><td style="border-right: 1px solid #527bbd; " align="left" valign="top"><p>shell</p></td><td style="border-right: 1px solid #527bbd; " align="left" valign="top"><p>groups</p></td><td style="" align="left" valign="top"><p>comment</p></td></tr></tbody></table></div><p>Where:</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
  5960. <code class="literal">username</code> is the desired user name (aka login name) for the user.
  5961. It can not be <code class="literal">root</code>, and must be unique. If set to <code class="literal">-</code>, then just a
  5962. group will be created.
  5963. </li><li class="listitem">
  5964. <code class="literal">uid</code> is the desired UID for the user. It must be unique, and not
  5965. <code class="literal">0</code>. If set to <code class="literal">-1</code> or <code class="literal">-2</code>, then a unique UID will be computed by
  5966. Buildroot, with <code class="literal">-1</code> denoting a system UID from [100…999] and <code class="literal">-2</code>
  5967. denoting a user UID from [1000…1999].
  5968. </li><li class="listitem">
  5969. <code class="literal">group</code> is the desired name for the user’s main group. It can not
  5970. be <code class="literal">root</code>. If the group does not exist, it will be created.
  5971. </li><li class="listitem">
  5972. <code class="literal">gid</code> is the desired GID for the user’s main group. It must be unique,
  5973. and not <code class="literal">0</code>. If set to <code class="literal">-1</code> or <code class="literal">-2</code>, and the group does not already
  5974. exist, then a unique GID will be computed by Buildroot, with <code class="literal">-1</code>
  5975. denoting a system GID from [100…999] and <code class="literal">-2</code> denoting a user GID
  5976. from [1000…1999].
  5977. </li><li class="listitem">
  5978. <code class="literal">password</code> is the crypt(3)-encoded password. If prefixed with <code class="literal">!</code>,
  5979. then login is disabled. If prefixed with <code class="literal">=</code>, then it is interpreted
  5980. as clear-text, and will be crypt-encoded (using MD5). If prefixed with
  5981. <code class="literal">!=</code>, then the password will be crypt-encoded (using MD5) and login
  5982. will be disabled. If set to <code class="literal">*</code>, then login is not allowed. If set to
  5983. <code class="literal">-</code>, then no password value will be set.
  5984. </li><li class="listitem">
  5985. <code class="literal">home</code> is the desired home directory for the user. If set to <span class="emphasis"><em>-</em></span>, no
  5986. home directory will be created, and the user’s home will be <code class="literal">/</code>.
  5987. Explicitly setting <code class="literal">home</code> to <code class="literal">/</code> is not allowed.
  5988. </li><li class="listitem">
  5989. <code class="literal">shell</code> is the desired shell for the user. If set to <code class="literal">-</code>, then
  5990. <code class="literal">/bin/false</code> is set as the user’s shell.
  5991. </li><li class="listitem">
  5992. <code class="literal">groups</code> is the comma-separated list of additional groups the user
  5993. should be part of. If set to <code class="literal">-</code>, then the user will be a member of
  5994. no additional group. Missing groups will be created with an arbitrary
  5995. <code class="literal">gid</code>.
  5996. </li><li class="listitem">
  5997. <code class="literal">comment</code> (aka <a class="ulink" href="https://en.wikipedia.org/wiki/Gecos_field" target="_top">GECOS</a>
  5998. field) is an almost-free-form text.
  5999. </li></ul></div><p>There are a few restrictions on the content of each field:</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
  6000. except for <code class="literal">comment</code>, all fields are mandatory.
  6001. </li><li class="listitem">
  6002. except for <code class="literal">comment</code>, fields may not contain spaces.
  6003. </li><li class="listitem">
  6004. no field may contain a colon (<code class="literal">:</code>).
  6005. </li></ul></div><p>If <code class="literal">home</code> is not <code class="literal">-</code>, then the home directory, and all files below,
  6006. will belong to the user and its main group.</p><p>Examples:</p><pre class="screen">foo -1 bar -1 !=blabla /home/foo /bin/sh alpha,bravo Foo user</pre><p>This will create this user:</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
  6007. <code class="literal">username</code> (aka login name) is: <code class="literal">foo</code>
  6008. </li><li class="listitem">
  6009. <code class="literal">uid</code> is computed by Buildroot
  6010. </li><li class="listitem">
  6011. main <code class="literal">group</code> is: <code class="literal">bar</code>
  6012. </li><li class="listitem">
  6013. main group <code class="literal">gid</code> is computed by Buildroot
  6014. </li><li class="listitem">
  6015. clear-text <code class="literal">password</code> is: <code class="literal">blabla</code>, will be crypt(3)-encoded, and login is disabled.
  6016. </li><li class="listitem">
  6017. <code class="literal">home</code> is: <code class="literal">/home/foo</code>
  6018. </li><li class="listitem">
  6019. <code class="literal">shell</code> is: <code class="literal">/bin/sh</code>
  6020. </li><li class="listitem">
  6021. <code class="literal">foo</code> is also a member of <code class="literal">groups</code>: <code class="literal">alpha</code> and <code class="literal">bravo</code>
  6022. </li><li class="listitem">
  6023. <code class="literal">comment</code> is: <code class="literal">Foo user</code>
  6024. </li></ul></div><pre class="screen">test 8000 wheel -1 = - /bin/sh - Test user</pre><p>This will create this user:</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
  6025. <code class="literal">username</code> (aka login name) is: <code class="literal">test</code>
  6026. </li><li class="listitem">
  6027. <code class="literal">uid</code> is : <code class="literal">8000</code>
  6028. </li><li class="listitem">
  6029. main <code class="literal">group</code> is: <code class="literal">wheel</code>
  6030. </li><li class="listitem">
  6031. main group <code class="literal">gid</code> is computed by Buildroot, and will use the value defined in the rootfs skeleton
  6032. </li><li class="listitem">
  6033. <code class="literal">password</code> is empty (aka no password).
  6034. </li><li class="listitem">
  6035. <code class="literal">home</code> is <code class="literal">/</code> but will not belong to <code class="literal">test</code>
  6036. </li><li class="listitem">
  6037. <code class="literal">shell</code> is: <code class="literal">/bin/sh</code>
  6038. </li><li class="listitem">
  6039. <code class="literal">test</code> is not a member of any additional <code class="literal">groups</code>
  6040. </li><li class="listitem">
  6041. <code class="literal">comment</code> is: <code class="literal">Test user</code>
  6042. </li></ul></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="_caveat_with_automatic_uids_and_gids"></a>26.1. Caveat with automatic UIDs and GIDs</h2></div></div></div><p>When updating buildroot or when packages are added or removed to/from
  6043. the configuration, it is possible that the automatic UIDs and GIDs are
  6044. changed. This can be a problem if persistent files were created with
  6045. that user or group: after upgrade, they will suddenly have a different
  6046. owner.</p><p>Therefore, it is advisable to perpetuate the automatic IDs. This can be
  6047. done by adding a users table with the generated IDs. It is only needed
  6048. to do this for UIDs that actually create persistent files, e.g. database.</p></div></div><div class="chapter"><div class="titlepage"><div><div><h2 class="title"><a id="migrating-from-ol-versions"></a>Chapter 27. Migrating from older Buildroot versions</h2></div></div></div><p>Some versions have introduced backward incompatibilities. This section
  6049. explains those incompatibilities, and for each explains what to do to
  6050. complete the migration.</p><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="migrating-approach"></a>27.1. General approach</h2></div></div></div><p>To migrate from an older Buildroot version, take the following steps.</p><div class="orderedlist"><ol class="orderedlist" type="1"><li class="listitem">
  6051. For all your configurations, do a build in the old Buildroot
  6052. environment. Run <code class="literal">make graph-size</code>. Save
  6053. <code class="literal">graphs/file-size-stats.csv</code> in a different location. Run <code class="literal">make
  6054. clean</code> to remove the rest.
  6055. </li><li class="listitem">
  6056. Review the specific migration notes below and make the required
  6057. adaptations to external packages and custom build scripts.
  6058. </li><li class="listitem">
  6059. Update Buildroot.
  6060. </li><li class="listitem">
  6061. Run <code class="literal">make menuconfig</code> starting from the existing <code class="literal">.config</code>.
  6062. </li><li class="listitem">
  6063. If anything is enabled in the Legacy menu, check its help text,
  6064. unselect it, and save the configuration.
  6065. </li><li class="listitem">
  6066. For more details, review the git commit messages for the packages that
  6067. you need. Change into the <code class="literal">packages</code> directory and run
  6068. <code class="literal">git log &lt;old version&gt;.. — &lt;your packages&gt;</code>.
  6069. </li><li class="listitem">
  6070. Build in the new Buildroot environment.
  6071. </li><li class="listitem">
  6072. Fix build issues in external packages (usually due to updated
  6073. dependencies).
  6074. </li><li class="listitem">
  6075. Run <code class="literal">make graph-size</code>.
  6076. </li><li class="listitem">
  6077. Compare the new <code class="literal">file-size-stats.csv</code> with the original one, to
  6078. check if no required files have disappeared and if no new big unneeded
  6079. files have appeared.
  6080. </li><li class="listitem">
  6081. For configuration (and other) files in a custom overlay that overwrite
  6082. files created by Buildroot, check if there are changes in the
  6083. Buildroot-generated file that need to be propagated to your custom
  6084. file.
  6085. </li></ol></div></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="br2-external-converting"></a>27.2. Migrating to 2016.11</h2></div></div></div><p>Before Buildroot 2016.11, it was possible to use only one br2-external
  6086. tree at once. With Buildroot 2016.11 came the possibility to use more
  6087. than one simultaneously (for details, see <a class="xref" href="#outside-br-custom" title="9.2. Keeping customizations outside of Buildroot">Section 9.2, “Keeping customizations outside of Buildroot”</a>).</p><p>This however means that older br2-external trees are not usable as-is.
  6088. A minor change has to be made: adding a name to your br2-external tree.</p><p>This can be done very easily in just a few steps:</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p class="simpara">
  6089. First, create a new file named <code class="literal">external.desc</code>, at the root of your
  6090. br2-external tree, with a single line defining the name of your
  6091. br2-external tree:
  6092. </p><pre class="screen">$ echo 'name: NAME_OF_YOUR_TREE' &gt;external.desc</pre><p><strong>Note. </strong>Be careful when choosing a name: It has to be unique and be made
  6093. with only ASCII characters from the set <code class="literal">[A-Za-z0-9_]</code>.</p></li><li class="listitem"><p class="simpara">
  6094. Then, change every occurrence of <code class="literal">BR2_EXTERNAL</code> in your br2-external
  6095. tree with the new variable:
  6096. </p><pre class="screen">$ find . -type f | xargs sed -i 's/BR2_EXTERNAL/BR2_EXTERNAL_NAME_OF_YOUR_TREE_PATH/g'</pre></li></ul></div><p>Now, your br2-external tree can be used with Buildroot 2016.11 onward.</p><p><strong>Note: </strong>This change makes your br2-external tree incompatible with Buildroot
  6097. before 2016.11.</p></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="migrating-host-usr"></a>27.3. Migrating to 2017.08</h2></div></div></div><p>Before Buildroot 2017.08, host packages were installed in <code class="literal">$(HOST_DIR)/usr</code>
  6098. (with e.g. the autotools' <code class="literal">--prefix=$(HOST_DIR)/usr</code>). With Buildroot
  6099. 2017.08, they are now installed directly in <code class="literal">$(HOST_DIR)</code>.</p><p>Whenever a package installs an executable that is linked with a library
  6100. in <code class="literal">$(HOST_DIR)/lib</code>, it must have an RPATH pointing to that directory.</p><p>An RPATH pointing to <code class="literal">$(HOST_DIR)/usr/lib</code> is no longer accepted.</p></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="migrating-svn-externals"></a>27.4. Migrating to 2023.11</h2></div></div></div><p>Before Buildroot 2023.11, the subversion download backend unconditionally
  6101. retrieved the external references (objects with an <code class="literal">svn:externals</code>
  6102. property). Starting with 2023.11, externals are no longer retrieved by
  6103. default; if you need them, set <code class="literal">LIBFOO_SVN_EXTERNALS</code> to <code class="literal">YES</code>. This
  6104. change implies that:</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
  6105. the generated archive content may change, and thus the hashes may need
  6106. to be updated appropriately;
  6107. </li><li class="listitem">
  6108. the archive version suffix has been updated to <code class="literal">-br3</code>, so the hash
  6109. files must be updated appropriately.
  6110. </li></ul></div><p>Before Buildroot 2023.11, it was possible (but undocumented and unused)
  6111. to apply architecture-specific patches, by prefixing the patch filename
  6112. with the architecture, e.g. <code class="literal">0001-some-changes.patch.arm</code> and such a
  6113. patch would only be applied for that architecture. With Buildroot 2023.11,
  6114. this is no longer supported, and such patches are no longer applied at
  6115. all.</p><p>If you still need per-architecture patches, then you may provide a
  6116. <a class="link" href="#hooks" title="18.23. Hooks available in the various build steps">pre-patch hook</a> that copies the patches applicable to the
  6117. configured architecture, e.g.:</p><pre class="screen">define LIBFOO_ARCH_PATCHES
  6118. $(foreach p,$(wildcard $(LIBFOO_PKGDIR)/*.patch.$(ARCH)), \
  6119. cp -f $(p) $(patsubst %.$(ARCH),%,$(p))
  6120. )
  6121. endef
  6122. LIBFOO_PRE_PATCH_HOOKS += LIBFOO_ARCH_PATCHES</pre><p>Note that no package in Buildroot has architecture-specific patches, and
  6123. that such patches will most probably not be accepted.</p></div></div></div></div></body></html>