options.pas 186 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480
  1. {
  2. Copyright (c) 1998-2008 by Florian Klaempfl and Peter Vreman
  3. Reads command line options and config files
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  15. ****************************************************************************
  16. }
  17. unit options;
  18. {$i fpcdefs.inc}
  19. interface
  20. uses
  21. cfileutl,cclasses,versioncmp,
  22. globtype,globals,verbose,systems,cpuinfo,comprsrc;
  23. Type
  24. TOption=class
  25. FirstPass,
  26. ParaLogo,
  27. NoPressEnter,
  28. FPCHelpLines,
  29. LogoWritten,
  30. ABISetExplicitly,
  31. FPUSetExplicitly,
  32. CPUSetExplicitly,
  33. OptCPUSetExplicitly: boolean;
  34. FileLevel : longint;
  35. QuickInfo : string;
  36. FPCBinaryPath: string;
  37. ParaIncludeCfgPath,
  38. ParaIncludePath,
  39. ParaUnitPath,
  40. ParaObjectPath,
  41. ParaLibraryPath,
  42. ParaFrameworkPath,
  43. parapackagepath : TSearchPathList;
  44. paranamespaces : TCmdStrList;
  45. ParaAlignment : TAlignmentInfo;
  46. parapackages : tfphashobjectlist;
  47. paratarget : tsystem;
  48. paratargetasm : tasm;
  49. paratargetdbg : tdbg;
  50. parasubtarget : string;
  51. LinkTypeSetExplicitly : boolean;
  52. LinkerSetExplicitly : boolean;
  53. Constructor Create;
  54. Destructor Destroy;override;
  55. procedure WriteLogo;
  56. procedure WriteInfo (More: string);
  57. procedure WriteHelpPages;
  58. procedure WriteQuickInfo;
  59. procedure IllegalPara(const opt:TCmdStr);
  60. procedure UnsupportedPara(const opt:TCmdStr);
  61. procedure IgnoredPara(const opt:TCmdStr);
  62. function Unsetbool(var Opts:TCmdStr; Pos: Longint; const FullPara: TCmdStr; RequireBoolPara: Boolean):boolean;
  63. procedure interpret_option(const opt :TCmdStr;ispara:boolean);
  64. procedure Interpret_envvar(const envname : TCmdStr);
  65. procedure Interpret_file(const filename : TPathStr);
  66. procedure Read_Parameters;
  67. procedure parsecmd(cmd:TCmdStr);
  68. procedure TargetOptions(def:boolean);
  69. procedure CheckOptionsCompatibility;
  70. procedure ForceStaticLinking;
  71. protected
  72. MacVersionSet: boolean;
  73. IdfVersionSet: boolean;
  74. processorstr: TCmdStr;
  75. function ParseMacVersionMin(out minversion, invalidateversion: tversion; const compvarname, value: string; ios: boolean): boolean;
  76. procedure MaybeSetDefaultMacVersionMacro;
  77. {$ifdef XTENSA}
  78. function ParseVersionStr(out ver: longint; const compvarname, value: string): boolean;
  79. procedure MaybeSetIdfVersionMacro;
  80. {$endif}
  81. {$ifdef llvm}
  82. procedure LLVMEnableSanitizers(sanitizers: TCmdStr);
  83. {$endif llvm}
  84. procedure VerifyTargetProcessor;
  85. end;
  86. TOptionClass=class of toption;
  87. var
  88. coption : TOptionClass;
  89. procedure read_arguments(cmd:TCmdStr);
  90. implementation
  91. uses
  92. widestr,
  93. charset,
  94. SysUtils,
  95. version,
  96. cutils,cmsgs,
  97. comphook,
  98. symtable,scanner,rabase,
  99. symconst,
  100. {$ifdef llvm}
  101. { override supported optimizer transformations at the compiler level }
  102. llvminfo,
  103. {$endif llvm}
  104. dirparse,
  105. pkgutil;
  106. const
  107. page_size = 24;
  108. page_width = 80;
  109. var
  110. option : toption;
  111. read_subfile, { read subtarget config file, set when a cfgfile is found }
  112. read_configfile, { read config file, set when a cfgfile is found }
  113. disable_configfile : boolean;
  114. subcfg,
  115. fpcdir,
  116. ppccfg,
  117. param_file : string; { file to compile specified on the commandline }
  118. {****************************************************************************
  119. Options not supported on all platforms
  120. ****************************************************************************}
  121. const
  122. { gprof (requires implementation of g_profilecode in the code generator) }
  123. supported_targets_pg = [system_i386_linux,system_x86_64_linux,system_mipseb_linux,system_mipsel_linux,system_arm_linux]
  124. + [system_i386_win32]
  125. + [system_powerpc_darwin,system_x86_64_darwin]
  126. + [system_i386_GO32V2]
  127. + [system_i386_freebsd]
  128. + [system_i386_netbsd]
  129. + [system_i386_wdosx]
  130. + [system_riscv32_linux,system_riscv64_linux]
  131. + [system_aarch64_linux];
  132. suppported_targets_x_smallr = systems_linux + systems_solaris + systems_android
  133. + systems_openbsd
  134. + [system_i386_haiku,system_x86_64_haiku]
  135. + [system_i386_beos]
  136. + [system_m68k_amiga];
  137. {****************************************************************************
  138. Defines
  139. ****************************************************************************}
  140. procedure set_default_link_type;
  141. begin
  142. undef_system_macro('FPC_LINK_SMART');
  143. def_system_macro('FPC_LINK_STATIC');
  144. undef_system_macro('FPC_LINK_DYNAMIC');
  145. init_settings.globalswitches:=init_settings.globalswitches+[cs_link_static];
  146. init_settings.globalswitches:=init_settings.globalswitches-[cs_link_shared,cs_link_smart];
  147. {$ifdef AIX}
  148. init_settings.globalswitches:=init_settings.globalswitches+[cs_link_native];
  149. {$endif}
  150. end;
  151. {****************************************************************************
  152. Toption
  153. ****************************************************************************}
  154. procedure StopOptions(err:longint);
  155. begin
  156. if assigned(Option) then
  157. begin
  158. Option.free;
  159. Option:=nil;
  160. end;
  161. raise ECompilerAbortSilent.Create;
  162. end;
  163. function is_identifier(const s: TCmdStr): boolean;
  164. var
  165. i: longint;
  166. begin
  167. result:=false;
  168. if (s='') or not (s[1] in ['A'..'Z','a'..'z','_']) then
  169. exit;
  170. for i:=2 to length(s) do
  171. if not (s[I] in ['A'..'Z','a'..'z','0'..'9','_']) then
  172. exit;
  173. result:=true;
  174. end;
  175. procedure Toption.WriteLogo;
  176. var
  177. msg : TMsgStr;
  178. p : pchar;
  179. begin
  180. if not LogoWritten then
  181. begin
  182. msg:=MessageStr(option_logo);
  183. p:=pchar(msg);
  184. while assigned(p) do
  185. Comment(V_Normal,GetMsgLine(p));
  186. LogoWritten:= true;
  187. end;
  188. end;
  189. procedure Toption.WriteInfo (More: string);
  190. var
  191. msg_str: TMsgStr;
  192. p : pchar;
  193. hs,hs1,hs3,s : TCmdStr;
  194. J: longint;
  195. xmloutput: Text;
  196. const
  197. NewLineStr = '$\n';
  198. OSTargetsPlaceholder = '$OSTARGETS';
  199. CPUListPlaceholder = '$INSTRUCTIONSETS';
  200. FPUListPlaceholder = '$FPUINSTRUCTIONSETS';
  201. ABIListPlaceholder = '$ABITARGETS';
  202. OptListPlaceholder = '$OPTIMIZATIONS';
  203. WPOListPlaceholder = '$WPOPTIMIZATIONS';
  204. AsmModeListPlaceholder = '$ASMMODES';
  205. ControllerListPlaceholder = '$CONTROLLERTYPES';
  206. FeatureListPlaceholder = '$FEATURELIST';
  207. ModeSwitchListPlaceholder = '$MODESWITCHES';
  208. CodeGenerationBackendPlaceholder = '$CODEGENERATIONBACKEND';
  209. LLVMVersionPlaceholder = '$LLVMVERSIONS';
  210. procedure SplitLine (var OrigString: TCmdStr; const Placeholder: TCmdStr;
  211. out RemainderString: TCmdStr);
  212. var
  213. I: longint;
  214. HS2: TCmdStr;
  215. begin
  216. RemainderString := '';
  217. if OrigString = '' then
  218. Exit;
  219. repeat
  220. I := Pos (NewLineStr, OrigString);
  221. if I > 0 then
  222. begin
  223. HS2 := Copy (OrigString, 1, Pred (I));
  224. { Stop if this line contains the placeholder for list replacement }
  225. if Pos (Placeholder, HS2) > 0 then
  226. begin
  227. RemainderString := Copy (OrigString, I + Length (NewLineStr),
  228. Length (OrigString) - I - Length (NewLineStr));
  229. { Special case - NewLineStr at the end of the line }
  230. if RemainderString = '' then
  231. RemainderString := NewLineStr;
  232. OrigString := HS2;
  233. Exit;
  234. end;
  235. Comment (V_Normal, HS2);
  236. Delete (OrigString, 1, Pred (I) + Length (NewLineStr));
  237. end;
  238. until I = 0;
  239. if (OrigString <> '') and (Pos (Placeholder, OrigString) = 0) then
  240. Comment (V_Normal, OrigString);
  241. end;
  242. procedure ListOSTargets (OrigString: TCmdStr);
  243. var
  244. target : tsystem;
  245. begin
  246. SplitLine (OrigString, OSTargetsPlaceholder, HS3);
  247. for target:=low(tsystem) to high(tsystem) do
  248. if assigned(targetinfos[target]) then
  249. begin
  250. hs1:=targetinfos[target]^.shortname;
  251. if OrigString = '' then
  252. Comment (V_Normal, hs1)
  253. else
  254. begin
  255. hs := OrigString;
  256. hs1:=hs1 + ': ' + targetinfos[target]^.name;
  257. if tf_under_development in targetinfos[target]^.flags then
  258. hs1:=hs1+' {*}';
  259. Replace(hs,OSTargetsPlaceholder,hs1);
  260. Comment(V_Normal,hs);
  261. end;
  262. end;
  263. end;
  264. procedure ListOSTargetsXML;
  265. var
  266. target : tsystem;
  267. begin
  268. WriteLn(xmloutput,' <ostargets>');
  269. for target:=low(tsystem) to high(tsystem) do
  270. if assigned(targetinfos[target]) then
  271. begin
  272. Write(xmloutput,' <ostarget shortname="',targetinfos[target]^.shortname,'" name="',targetinfos[target]^.name,'"');
  273. if tf_under_development in targetinfos[target]^.flags then
  274. Write(' experimental="1"');
  275. WriteLn('/>');
  276. end;
  277. WriteLn(xmloutput,' </ostargets>');
  278. end;
  279. procedure ListCPUInstructionSets (OrigString: TCmdStr);
  280. var
  281. cpu : tcputype;
  282. begin
  283. SplitLine (OrigString, CPUListPlaceholder, HS3);
  284. hs1:='';
  285. for cpu:=low(tcputype) to high(tcputype) do
  286. begin
  287. if (OrigString = '') then
  288. begin
  289. if CPUTypeStr [CPU] <> '' then
  290. Comment (V_Normal, CPUTypeStr [CPU]);
  291. end
  292. else
  293. begin
  294. if length(hs1+cputypestr[cpu])>70 then
  295. begin
  296. hs:=OrigString;
  297. HS1 := HS1 + ',';
  298. Replace(hs,CPUListPlaceholder,hs1);
  299. Comment(V_Normal,hs);
  300. hs1:=''
  301. end
  302. else if hs1<>'' then
  303. hs1:=hs1+',';
  304. if cputypestr[cpu]<>'' then
  305. hs1:=hs1+cputypestr[cpu];
  306. end;
  307. end;
  308. if (OrigString <> '') and (hs1 <> '') then
  309. begin
  310. hs:=OrigString;
  311. Replace(hs,CPUListPlaceholder,hs1);
  312. Comment(V_Normal,hs);
  313. hs1:=''
  314. end;
  315. end;
  316. procedure ListCPUInstructionSetsXML;
  317. var
  318. cpu : tcputype;
  319. begin
  320. WriteLn(xmloutput,' <cpuinstructionsets>');
  321. for cpu:=low(tcputype) to high(tcputype) do
  322. if CPUTypeStr [CPU] <> '' then
  323. WriteLn(xmloutput,' <cpuinstructionset name="',CPUTypeStr [CPU], '"/>');
  324. WriteLn(xmloutput,' </cpuinstructionsets>');
  325. end;
  326. procedure ListFPUInstructionSets (OrigString: TCmdStr);
  327. var
  328. fpu : tfputype;
  329. begin
  330. SplitLine (OrigString, FPUListPlaceholder, HS3);
  331. hs1:='';
  332. for fpu:=low(tfputype) to high(tfputype) do
  333. begin
  334. if (OrigString = '') then
  335. begin
  336. if FPUTypeStr [FPU] <> '' then
  337. Comment (V_Normal, FPUTypeStr [FPU]);
  338. end
  339. else
  340. begin
  341. if length(hs1+fputypestr[fpu])>70 then
  342. begin
  343. hs:=OrigString;
  344. HS1 := HS1 + ',';
  345. Replace(hs,FPUListPlaceholder,hs1);
  346. Comment(V_Normal,hs);
  347. hs1:=''
  348. end
  349. else if hs1<>'' then
  350. hs1:=hs1+',';
  351. if fputypestr[fpu]<>'' then
  352. hs1:=hs1+fputypestr[fpu];
  353. end;
  354. end;
  355. if (OrigString <> '') and (hs1 <> '') then
  356. begin
  357. hs:=OrigString;
  358. Replace(hs,FPUListPlaceholder,hs1);
  359. Comment(V_Normal,hs);
  360. hs1:=''
  361. end;
  362. end;
  363. procedure ListFPUInstructionSetsXML;
  364. var
  365. fpu : tfputype;
  366. begin
  367. WriteLn(xmloutput,' <fpuinstructionsets>');
  368. for fpu:=low(tfputype) to high(tfputype) do
  369. if FPUTypeStr [fpu] <> '' then
  370. WriteLn(xmloutput,' <cpuinstructionset name="',FPUTypeStr [fpu], '"/>');
  371. WriteLn(xmloutput,' </fpuinstructionsets>');
  372. end;
  373. procedure ListABITargets (OrigString: TCmdStr);
  374. var
  375. abi : tabi;
  376. begin
  377. SplitLine (OrigString, ABIListPlaceholder, HS3);
  378. for abi:=low(abi) to high(abi) do
  379. begin
  380. if not abiinfo[abi].supported then
  381. continue;
  382. hs1:=abiinfo[abi].name;
  383. if hs1<>'' then
  384. begin
  385. if OrigString = '' then
  386. Comment (V_Normal, HS1)
  387. else
  388. begin
  389. hs:=OrigString;
  390. Replace(hs,ABIListPlaceholder,hs1);
  391. Comment(V_Normal,hs);
  392. end;
  393. end;
  394. end;
  395. end;
  396. procedure ListABITargetsXML;
  397. var
  398. abi : tabi;
  399. begin
  400. WriteLn(xmloutput,' <abis>');
  401. for abi:=low(abi) to high(abi) do
  402. begin
  403. if not abiinfo[abi].supported then
  404. continue;
  405. if abiinfo[abi].name<>'' then;
  406. WriteLn(xmloutput,' <abi name="',abiinfo[abi].name, '"/>');
  407. end;
  408. WriteLn(xmloutput,' </abis>');
  409. end;
  410. procedure ListOptimizations (OrigString: TCmdStr);
  411. var
  412. opt : toptimizerswitch;
  413. begin
  414. SplitLine (OrigString, OptListPlaceholder, HS3);
  415. for opt:=low(toptimizerswitch) to high(toptimizerswitch) do
  416. begin
  417. if opt in supported_optimizerswitches then
  418. begin
  419. hs1:=OptimizerSwitchStr[opt];
  420. if hs1<>'' then
  421. begin
  422. if OrigString = '' then
  423. Comment (V_Normal, hs1)
  424. else
  425. begin
  426. hs:=OrigString;
  427. Replace(hs,OptListPlaceholder,hs1);
  428. Comment(V_Normal,hs);
  429. end;
  430. end;
  431. end;
  432. end;
  433. end;
  434. procedure ListOptimizationsXML;
  435. var
  436. opt: toptimizerswitch;
  437. begin
  438. WriteLn(xmloutput,' <optimizations>');
  439. for opt:=low(toptimizerswitch) to high(toptimizerswitch) do
  440. if OptimizerSwitchStr[opt]<>'' then
  441. WriteLn(xmloutput,' <optimization name="',OptimizerSwitchStr[opt],'"/>');
  442. WriteLn(xmloutput,' </optimizations>');
  443. end;
  444. procedure ListWPOptimizations (OrigString: TCmdStr);
  445. var
  446. wpopt: twpoptimizerswitch;
  447. begin
  448. SplitLine (OrigString, WPOListPlaceholder, HS3);
  449. for wpopt:=low(twpoptimizerswitch) to high(twpoptimizerswitch) do
  450. begin
  451. { currently all whole program optimizations are platform-independent
  452. if opt in supported_wpoptimizerswitches then
  453. }
  454. begin
  455. hs1:=WPOptimizerSwitchStr[wpopt];
  456. if hs1<>'' then
  457. begin
  458. if OrigString = '' then
  459. Comment (V_Normal, hs1)
  460. else
  461. begin
  462. hs:=OrigString;
  463. Replace(hs,WPOListPlaceholder,hs1);
  464. Comment(V_Normal,hs);
  465. end;
  466. end;
  467. end;
  468. end;
  469. end;
  470. procedure ListWPOptimizationsXML;
  471. var
  472. wpopt: twpoptimizerswitch;
  473. begin
  474. WriteLn(xmloutput,' <wpoptimizations>');
  475. for wpopt:=low(twpoptimizerswitch) to high(twpoptimizerswitch) do
  476. if WPOptimizerSwitchStr[wpopt]<>'' then
  477. WriteLn(xmloutput,' <wpoptimization name="',WPOptimizerSwitchStr[wpopt],'"/>');
  478. WriteLn(xmloutput,' </wpoptimizations>');
  479. end;
  480. procedure ListAsmModes (OrigString: TCmdStr);
  481. var
  482. asmmode : tasmmode;
  483. begin
  484. SplitLine (OrigString, AsmModeListPlaceholder, HS3);
  485. for asmmode:=low(tasmmode) to high(tasmmode) do
  486. if assigned(asmmodeinfos[asmmode]) then
  487. begin
  488. hs1:=asmmodeinfos[asmmode]^.idtxt;
  489. if hs1<>'' then
  490. begin
  491. if OrigString = '' then
  492. Comment (V_Normal, hs1)
  493. else
  494. begin
  495. hs:=OrigString;
  496. Replace(hs,AsmModeListPlaceholder,hs1);
  497. Comment(V_Normal,hs);
  498. end;
  499. end;
  500. end;
  501. end;
  502. procedure ListAsmModesXML;
  503. var
  504. asmmode : tasmmode;
  505. begin
  506. WriteLn(xmloutput,' <asmmodes>');
  507. for asmmode:=low(tasmmode) to high(tasmmode) do
  508. if assigned(asmmodeinfos[asmmode]) then
  509. WriteLn(xmloutput,' <asmmode name="',asmmodeinfos[asmmode]^.idtxt,'"/>');
  510. WriteLn(xmloutput,' </asmmodes>');
  511. end;
  512. procedure ListControllerTypes (OrigString: TCmdStr);
  513. var
  514. controllertype : tcontrollertype;
  515. begin
  516. {$PUSH}
  517. {$WARN 6018 OFF} (* Unreachable code due to compile time evaluation *)
  518. if (ControllerSupport) then
  519. begin
  520. SplitLine (OrigString, ControllerListPlaceholder, HS3);
  521. hs1:='';
  522. for controllertype:=low(tcontrollertype) to high(tcontrollertype) do
  523. begin
  524. if (OrigString = '') then
  525. begin
  526. if Embedded_Controllers [ControllerType].ControllerTypeStr <> '' then
  527. Comment (V_Normal, Embedded_Controllers [ControllerType].ControllerTypeStr);
  528. end
  529. else
  530. begin
  531. if length(hs1+embedded_controllers[controllertype].ControllerTypeStr)
  532. >70 then
  533. begin
  534. hs:=OrigString;
  535. HS1 := HS1 + ',';
  536. Replace(hs,ControllerListPlaceholder,hs1);
  537. Comment(V_Normal,hs);
  538. hs1:=''
  539. end
  540. else if hs1<>'' then
  541. hs1:=hs1+',';
  542. if embedded_controllers[controllertype].ControllerTypeStr<>'' then
  543. hs1:=hs1+embedded_controllers[controllertype].ControllerTypeStr;
  544. end;
  545. end;
  546. if (OrigString <> '') and (hs1<>'') then
  547. begin
  548. hs:=OrigString;
  549. Replace(hs,ControllerListPlaceholder,hs1);
  550. Comment(V_Normal,hs);
  551. hs1:=''
  552. end;
  553. end;
  554. {$POP}
  555. end;
  556. procedure ListControllerTypesXML;
  557. var
  558. controllertype : tcontrollertype;
  559. begin
  560. {$PUSH}
  561. {$WARN 6018 OFF} (* Unreachable code due to compile time evaluation *)
  562. if (ControllerSupport) then
  563. begin
  564. WriteLn(xmloutput,' <controllertypes>');
  565. for controllertype:=low(tcontrollertype) to high(tcontrollertype) do
  566. if embedded_controllers[controllertype].ControllerTypeStr<>'' then
  567. WriteLn(xmloutput,' <controllertype name="',embedded_controllers[controllertype].ControllerTypeStr,
  568. '" controllerunit="',embedded_controllers[controllertype].controllerunitstr, '"/>');
  569. WriteLn(xmloutput,' </controllertypes>');
  570. end;
  571. {$POP}
  572. end;
  573. procedure ListFeatures (OrigString: TCmdStr);
  574. var
  575. Feature: TFeature;
  576. begin
  577. SplitLine (OrigString, FeatureListPlaceholder, HS3);
  578. HS1 := '';
  579. for Feature := Low (TFeature) to High (TFeature) do
  580. begin
  581. if (OrigString = '') then
  582. begin
  583. if FeatureStr [Feature] <> '' then
  584. Comment (V_Normal, FeatureStr [Feature]);
  585. end
  586. else
  587. begin
  588. if Length (HS1 + FeatureStr [Feature]) > 70 then
  589. begin
  590. HS := OrigString;
  591. HS1 := HS1 + ',';
  592. Replace (HS, FeatureListPlaceholder, HS1);
  593. Comment (V_Normal, HS);
  594. HS1 := ''
  595. end
  596. else if HS1 <> '' then
  597. HS1 := HS1 + ',';
  598. if FeatureStr [Feature] <> '' then
  599. HS1 := HS1 + FeatureStr [Feature];
  600. end;
  601. end;
  602. if (OrigString <> '') and (HS1 <> '') then
  603. begin
  604. HS := OrigString;
  605. Replace (HS, FeatureListPlaceholder, HS1);
  606. Comment (V_Normal, HS);
  607. HS1 := ''
  608. end;
  609. end;
  610. procedure ListFeaturesXML;
  611. var
  612. Feature: TFeature;
  613. begin
  614. WriteLn(xmloutput,' <features>');
  615. for Feature := Low (TFeature) to High (TFeature) do
  616. if FeatureStr [Feature] <> '' then
  617. WriteLn(xmloutput,' <feature name="',FeatureStr [Feature],'"/>');
  618. WriteLn(xmloutput,' </features>');
  619. end;
  620. procedure ListModeswitches (OrigString: TCmdStr);
  621. var
  622. Modeswitch: TModeswitch;
  623. begin
  624. SplitLine (OrigString, ModeswitchListPlaceholder, HS3);
  625. HS1 := '';
  626. for Modeswitch := Low (TModeswitch) to High (TModeswitch) do
  627. begin
  628. if (OrigString = '') then
  629. begin
  630. if ModeswitchStr [Modeswitch] <> '' then
  631. Comment (V_Normal, ModeswitchStr [Modeswitch]);
  632. end
  633. else
  634. begin
  635. if Length (HS1 + ModeswitchStr [Modeswitch]) > 60 then
  636. begin
  637. HS := OrigString;
  638. HS1 := HS1 + ',';
  639. Replace (HS, ModeswitchListPlaceholder, HS1);
  640. Comment (V_Normal, HS);
  641. HS1 := ''
  642. end
  643. else if HS1 <> '' then
  644. HS1 := HS1 + ',';
  645. if ModeswitchStr [Modeswitch] <> '' then
  646. HS1 := HS1 + ModeswitchStr [Modeswitch];
  647. end;
  648. end;
  649. if (OrigString <> '') and (HS1 <> '') then
  650. begin
  651. HS := OrigString;
  652. Replace (HS, ModeswitchListPlaceholder, HS1);
  653. Comment (V_Normal, HS);
  654. HS1 := ''
  655. end;
  656. end;
  657. procedure ListModeswitchesXML;
  658. var
  659. Modeswitch: TModeswitch;
  660. begin
  661. WriteLn(xmloutput,' <modeswitches>');
  662. for Modeswitch:=Low(TModeswitch) to High(TModeswitch) do
  663. if ModeswitchStr [Modeswitch]<>'' then
  664. WriteLn(xmloutput,' <modeswitch name="',ModeswitchStr [Modeswitch],'"/>');
  665. WriteLn(xmloutput,' </modeswitches>');
  666. end;
  667. procedure ListCodeGenerationBackend (OrigString: TCmdStr);
  668. begin
  669. SplitLine (OrigString, CodeGenerationBackendPlaceholder, HS3);
  670. hs1:=cgbackend2str[cgbackend];
  671. if OrigString = '' then
  672. Comment (V_Normal, hs1)
  673. else
  674. begin
  675. hs:=OrigString;
  676. Replace(hs,CodeGenerationBackendPlaceholder,hs1);
  677. Comment(V_Normal,hs);
  678. end;
  679. end;
  680. procedure ListCodeGenerationBackendXML;
  681. begin
  682. WriteLn(xmloutput,' <codegeneratorbackend>',cgbackend2str[cgbackend],'</codegeneratorbackend>');
  683. end;
  684. procedure ListLLVMVersions (OrigString: TCmdStr);
  685. {$ifdef LLVM}
  686. var
  687. llvmversion : tllvmversion;
  688. {$endif LLVM}
  689. begin
  690. {$ifdef LLVM}
  691. SplitLine (OrigString, LLVMVersionPlaceholder, HS3);
  692. for llvmversion:=low(llvmversion) to high(llvmversion) do
  693. begin
  694. hs1:=llvmversionstr[llvmversion];
  695. if hs1<>'' then
  696. begin
  697. if OrigString = '' then
  698. Comment (V_Normal, hs1)
  699. else
  700. begin
  701. hs:=OrigString;
  702. Replace(hs,LLVMVersionPlaceholder,hs1);
  703. Comment(V_Normal,hs);
  704. end;
  705. end;
  706. end;
  707. {$else LLVM}
  708. Comment (V_Normal, '')
  709. {$endif LLVM}
  710. end;
  711. procedure ListLLVMVersionsXML;
  712. {$ifdef LLVM}
  713. var
  714. llvmversion : tllvmversion;
  715. {$endif LLVM}
  716. begin
  717. {$ifdef LLVM}
  718. WriteLn(xmloutput,' <llvmversions>');
  719. for llvmversion:=Low(tllvmversion) to High(tllvmversion) do
  720. if llvmversionstr[llvmversion]<>'' then
  721. WriteLn(xmloutput,' <llvmversion name="',llvmversionstr[llvmversion],'"/>');
  722. WriteLn(xmloutput,' </llvmversions>');
  723. {$endif LLVM}
  724. end;
  725. begin
  726. if More = '' then
  727. begin
  728. msg_str:=MessageStr(option_info);
  729. p:=pchar(msg_str);
  730. while assigned(p) do
  731. begin
  732. s:=GetMsgLine(p);
  733. { list permitted values for certain options }
  734. if pos(OSTargetsPlaceholder,s)>0 then
  735. ListOSTargets (S)
  736. else if pos(CPUListPlaceholder,s)>0 then
  737. ListCPUInstructionSets (S)
  738. else if pos(FPUListPlaceholder,s)>0 then
  739. ListFPUInstructionSets (S)
  740. else if pos(ABIListPlaceholder,s)>0 then
  741. ListABITargets (S)
  742. else if pos(OptListPlaceholder,s)>0 then
  743. ListOptimizations (S)
  744. else if pos(WPOListPlaceholder,s)>0 then
  745. ListWPOptimizations (S)
  746. else if Pos (ModeswitchListPlaceholder, S) > 0 then
  747. ListModeswitches (S)
  748. else if pos(AsmModeListPlaceholder,s)>0 then
  749. ListAsmModes (S)
  750. else if pos(ControllerListPlaceholder,s)>0 then
  751. ListControllerTypes (S)
  752. else if pos(FeatureListPlaceholder,s)>0 then
  753. ListFeatures (S)
  754. else if pos(CodeGenerationBackendPlaceholder,s)>0 then
  755. ListCodeGenerationBackend (S)
  756. else if pos(LLVMVersionPlaceholder,s)>0 then
  757. ListLLVMVersions (s)
  758. else
  759. Comment(V_Normal,s);
  760. end;
  761. end
  762. else if Copy(More,1,1) = 'x' then
  763. begin
  764. Assign(xmloutput,Copy(More,2,length(More)-1));
  765. Rewrite(xmloutput);
  766. WriteLn(xmloutput,'<?xml version="1.0" encoding="utf-8"?>');
  767. WriteLn(xmloutput,'<fpcoutput>');
  768. WriteLn(xmloutput,' <info>');
  769. ListOSTargetsXML;
  770. ListCPUInstructionSetsXML;
  771. ListFPUInstructionSetsXML;
  772. ListABITargetsXML;
  773. ListOptimizationsXML;
  774. ListWPOptimizationsXML;
  775. ListModeswitchesXML;
  776. ListAsmModesXML;
  777. ListControllerTypesXML;
  778. ListFeaturesXML;
  779. ListCodeGenerationBackendXML;
  780. ListLLVMVersionsXML;
  781. WriteLn(xmloutput,' </info>');
  782. WriteLn(xmloutput,'</fpcoutput>');
  783. Close(xmloutput);
  784. end
  785. else
  786. begin
  787. J := 1;
  788. while J <= Length (More) do
  789. begin
  790. if J > 1 then
  791. Comment(V_Normal,''); (* Put empty line between multiple sections *)
  792. case More [J] of
  793. 'a': ListABITargets ('');
  794. 'b': Comment(V_Normal, cgbackend2str[cgbackend]);
  795. 'c': ListCPUInstructionSets ('');
  796. 'f': ListFPUInstructionSets ('');
  797. 'i': ListAsmModes ('');
  798. {$ifdef LLVM}
  799. 'l': ListLLVMVersions ('');
  800. {$endif LLVM}
  801. 'm': ListModeswitches ('');
  802. 'o': ListOptimizations ('');
  803. 'r': ListFeatures ('');
  804. 't': ListOSTargets ('');
  805. 'u': ListControllerTypes ('');
  806. 'w': ListWPOptimizations ('');
  807. else
  808. IllegalPara ('-i' + More);
  809. end;
  810. Inc (J);
  811. end;
  812. end;
  813. StopOptions(0);
  814. end;
  815. procedure Toption.WriteHelpPages;
  816. function PadEnd(s:string;i:longint):string;
  817. begin
  818. if length(s) >= i then
  819. S := S + ' '
  820. else
  821. while (length(s)<i) do
  822. s:=s+' ';
  823. PadEnd:=s;
  824. end;
  825. var
  826. lastident,
  827. j,outline,
  828. ident,
  829. HelpLineHeight,
  830. lines : longint;
  831. show : boolean;
  832. opt : string[32];
  833. input,
  834. HelpLine,
  835. s : string;
  836. p : pchar;
  837. msg_str: TMsgStr;
  838. begin
  839. WriteLogo;
  840. Lines:=4;
  841. if FPCHelpLines then
  842. Message1(option_usage,FixFileName(FPCBinaryPath))
  843. else
  844. Message1(option_usage,FixFileName(system.paramstr(0)));
  845. lastident:=0;
  846. msg_str:=MessageStr(option_help_pages);
  847. p:=pchar(msg_str);
  848. while assigned(p) do
  849. begin
  850. { get a line and reset }
  851. s:=GetMsgLine(p);
  852. ident:=0;
  853. show:=false;
  854. { parse options }
  855. case s[1] of
  856. 'F': if FPCHelpLines then
  857. Show := true;
  858. {$ifdef UNITALIASES}
  859. 'a',
  860. {$endif}
  861. {$ifdef EXTDEBUG}
  862. 'e',
  863. {$endif EXTDEBUG}
  864. {$ifdef i386}
  865. '3',
  866. {$endif}
  867. {$ifdef x86_64}
  868. '4',
  869. {$endif}
  870. {$ifdef m68k}
  871. '6',
  872. {$endif}
  873. {$ifdef i8086}
  874. '8',
  875. {$endif}
  876. {$ifdef aarch64}
  877. 'a',
  878. {$endif}
  879. {$ifdef arm}
  880. 'A',
  881. {$endif}
  882. {$ifdef mipsel}
  883. 'm',
  884. {$endif}
  885. {$ifdef mipseb}
  886. 'M',
  887. {$endif}
  888. {$ifdef powerpc}
  889. 'P',
  890. {$endif}
  891. {$ifdef powerpc64}
  892. 'p',
  893. {$endif}
  894. {$ifdef sparc}
  895. 'S',
  896. {$endif}
  897. {$ifdef sparc64}
  898. 's',
  899. {$endif}
  900. {$ifdef riscv32}
  901. 'R',
  902. {$endif}
  903. {$ifdef riscv64}
  904. 'r',
  905. {$endif}
  906. {$ifdef avr}
  907. 'V',
  908. {$endif}
  909. {$ifdef jvm}
  910. 'J',
  911. {$endif}
  912. {$ifdef llvm}
  913. 'L',
  914. {$endif}
  915. {$ifdef xtensa}
  916. 'x',
  917. {$endif}
  918. {$ifdef z80}
  919. 'Z',
  920. {$endif}
  921. {$ifdef wasm32}
  922. 'W',
  923. {$endif}
  924. '*' : show:=true;
  925. end;
  926. if show then
  927. begin
  928. case s[2] of
  929. 'g',
  930. {$ifdef Unix}
  931. 'L',
  932. {$endif}
  933. {$ifdef os2}
  934. 'O',
  935. {$endif}
  936. '*' : show:=true;
  937. else
  938. show:=false;
  939. end;
  940. end;
  941. { now we may show the message or not }
  942. if show then
  943. begin
  944. case s[3] of
  945. '0' : begin
  946. ident:=0;
  947. outline:=0;
  948. end;
  949. '1' : begin
  950. ident:=2;
  951. outline:=7;
  952. end;
  953. '2' : begin
  954. ident:=6;
  955. outline:=11;
  956. end;
  957. '3' : begin
  958. ident:=9;
  959. outline:=11;
  960. end;
  961. else
  962. internalerror(2013112906);
  963. end;
  964. j:=pos('_',s);
  965. opt:=Copy(s,4,j-4);
  966. if opt='*' then
  967. opt:=''
  968. else
  969. if (opt=' ') or (opt[1]='@') then
  970. opt:=PadEnd(opt,outline)
  971. else
  972. opt:=PadEnd('-'+opt,outline);
  973. if (ident=0) and (lastident<>0) then
  974. begin
  975. Comment(V_Normal,'');
  976. inc(Lines);
  977. end;
  978. HelpLine := PadEnd('',ident)+opt+Copy(s,j+1,255);
  979. if HelpLine = '' then
  980. HelpLineHeight := 1
  981. else
  982. HelpLineHeight := Succ (CharLength (HelpLine) div Page_Width);
  983. { page full ? }
  984. if (lines + HelpLineHeight >= page_size - 1) then
  985. begin
  986. if not NoPressEnter then
  987. begin
  988. Message(option_help_press_enter);
  989. readln(input);
  990. if upper(input)='Q' then
  991. StopOptions(0);
  992. end;
  993. lines:=0;
  994. end;
  995. Comment(V_Normal,HelpLine);
  996. LastIdent:=Ident;
  997. Inc (Lines, HelpLineHeight);
  998. end;
  999. end;
  1000. StopOptions(0);
  1001. end;
  1002. procedure Toption.IllegalPara(const opt:TCmdStr);
  1003. begin
  1004. Message1(option_illegal_para,opt);
  1005. Message(option_help_pages_para);
  1006. StopOptions(1);
  1007. end;
  1008. procedure toption.UnsupportedPara(const opt: TCmdStr);
  1009. begin
  1010. Message1(option_unsupported_target,opt);
  1011. StopOptions(1);
  1012. end;
  1013. procedure toption.IgnoredPara(const opt: TCmdStr);
  1014. begin
  1015. Message1(option_ignored_target,opt);
  1016. end;
  1017. procedure toption.ForceStaticLinking;
  1018. begin
  1019. def_system_macro('FPC_LINK_STATIC');
  1020. undef_system_macro('FPC_LINK_SMART');
  1021. undef_system_macro('FPC_LINK_DYNAMIC');
  1022. include(init_settings.globalswitches,cs_link_static);
  1023. exclude(init_settings.globalswitches,cs_link_smart);
  1024. exclude(init_settings.globalswitches,cs_link_shared);
  1025. LinkTypeSetExplicitly:=true;
  1026. end;
  1027. function toption.ParseMacVersionMin(out minversion, invalidateversion: tversion; const compvarname, value: string; ios: boolean): boolean;
  1028. function subval(start,maxlen: longint; out stop: longint): string;
  1029. var
  1030. i: longint;
  1031. begin
  1032. result:='';
  1033. i:=start;
  1034. while (i<=length(value)) and
  1035. (value[i] in ['0'..'9']) do
  1036. inc(i);
  1037. { sufficient amount of digits? }
  1038. if (i=start) or
  1039. (i-start>maxlen) then
  1040. exit;
  1041. result:=copy(value,start,i-start);
  1042. stop:=i;
  1043. end;
  1044. var
  1045. temp,
  1046. compvarvalue,
  1047. versionstr: string[15];
  1048. major, minor, patch: cardinal;
  1049. i, err: longint;
  1050. osx_minor_two_digits: boolean;
  1051. begin
  1052. invalidateversion.invalidate;
  1053. versionstr:=value;
  1054. MacVersionSet:=false;
  1055. { check whether the value is a valid version number }
  1056. if value='' then
  1057. begin
  1058. undef_system_macro(compvarname);
  1059. exit(true);
  1060. end;
  1061. { major version number }
  1062. compvarvalue:=subval(1,2,i);
  1063. { not enough digits -> invalid }
  1064. if compvarvalue='' then
  1065. exit(false);
  1066. { already end of string -> invalid }
  1067. if (i>=length(value)) or
  1068. (value[i]<>'.') then
  1069. exit(false);
  1070. val(compvarvalue,major,err);
  1071. if err<>0 then
  1072. exit(false);
  1073. { minor version number }
  1074. temp:=subval(i+1,2,i);
  1075. if temp='' then
  1076. exit(false);
  1077. val(temp,minor,err);
  1078. if err<>0 then
  1079. exit(false);
  1080. { on Mac OS X, the minor version number was originally limited to 1 digit;
  1081. with 10.10 the format changed and two digits were also supported; on iOS,
  1082. the minor version number always takes up two digits }
  1083. osx_minor_two_digits:=false;
  1084. if not ios then
  1085. begin
  1086. { if the minor version number is two digits on OS X (the case since
  1087. OS X 10.10), we also have to add two digits for the patch level}
  1088. if length(temp)=2 then
  1089. osx_minor_two_digits:=true;
  1090. end
  1091. { the minor version number always takes up two digits on iOS }
  1092. else if length(temp)=1 then
  1093. temp:='0'+temp;
  1094. compvarvalue:=compvarvalue+temp;
  1095. { optional patch level }
  1096. patch:=0;
  1097. if i<=length(value) then
  1098. begin
  1099. if value[i]<>'.' then
  1100. exit(false);
  1101. temp:=subval(i+1,2,i);
  1102. if temp='' then
  1103. exit(false);
  1104. { there's only room for a single digit patch level in the version macro
  1105. for Mac OS X. gcc sets it to zero if there are more digits, but that
  1106. seems worse than clamping to 9 (don't declare as invalid like with
  1107. minor version number, because there is a precedent like 10.4.11).
  1108. As of OS X 10.10 there are two digits for the patch level
  1109. }
  1110. if not ios and
  1111. not osx_minor_two_digits then
  1112. begin
  1113. if length(temp)<>1 then
  1114. temp:='9';
  1115. end
  1116. else
  1117. begin
  1118. { on iOS, the patch level is always two digits }
  1119. if length(temp)=1 then
  1120. temp:='0'+temp;
  1121. end;
  1122. compvarvalue:=compvarvalue+temp;
  1123. { must be the end }
  1124. if i<=length(value) then
  1125. exit(false);
  1126. val(temp,patch,err);
  1127. if err<>0 then
  1128. exit(false);
  1129. end
  1130. else if not ios and
  1131. not osx_minor_two_digits then
  1132. begin
  1133. compvarvalue:=compvarvalue+'0';
  1134. versionstr:=versionstr+'.0'
  1135. end
  1136. else
  1137. begin
  1138. compvarvalue:=compvarvalue+'00';
  1139. { command line versions still only use one 0 though }
  1140. versionstr:=versionstr+'.0'
  1141. end;
  1142. minversion.init(versionstr,major,minor,patch);
  1143. set_system_compvar(compvarname,compvarvalue);
  1144. MacVersionSet:=true;
  1145. result:=true;
  1146. end;
  1147. {$ifdef XTENSA}
  1148. function TOption.ParseVersionStr(out ver: longint;
  1149. const compvarname, value: string): boolean;
  1150. function subval(start,maxlen: longint; out stop: longint): string;
  1151. var
  1152. i: longint;
  1153. begin
  1154. result:='';
  1155. i:=start;
  1156. while (i<=length(value)) and
  1157. (value[i] in ['0'..'9']) do
  1158. inc(i);
  1159. { sufficient amount of digits? }
  1160. if (i=start) or
  1161. (i-start>maxlen) then
  1162. exit;
  1163. result:=copy(value,start,i-start);
  1164. stop:=i;
  1165. end;
  1166. var
  1167. temp,
  1168. compvarvalue: string[15];
  1169. i: longint;
  1170. begin
  1171. Result:=false;
  1172. IdfVersionSet:=false;
  1173. emptystr:='';
  1174. { check whether the value is a valid version number }
  1175. if value='' then
  1176. begin
  1177. undef_system_macro(compvarname);
  1178. exit(true);
  1179. end;
  1180. { major version number }
  1181. compvarvalue:=subval(1,2,i);
  1182. { not enough digits -> invalid }
  1183. if compvarvalue='' then
  1184. exit(false);
  1185. { already end of string -> invalid }
  1186. if (i>=length(value)) or
  1187. (value[i]<>'.') then
  1188. exit(false);
  1189. { minor version number }
  1190. temp:=subval(i+1,2,i);
  1191. if temp='' then
  1192. exit(false);
  1193. if length(temp)=1 then
  1194. temp:='0'+temp;
  1195. compvarvalue:=compvarvalue+temp;
  1196. { patch level }
  1197. if i<=length(value) then
  1198. begin
  1199. if value[i]<>'.' then
  1200. exit(false);
  1201. temp:=subval(i+1,2,i);
  1202. if temp='' then
  1203. exit(false);
  1204. if length(temp)=1 then
  1205. temp:='0'+temp;
  1206. compvarvalue:=compvarvalue+temp;
  1207. { must be the end }
  1208. if i<=length(value) then
  1209. exit(false);
  1210. end
  1211. else
  1212. begin
  1213. compvarvalue:=compvarvalue+'00';
  1214. end;
  1215. val(compvarvalue,idf_version,i);
  1216. if i=0 then
  1217. begin
  1218. set_system_compvar(compvarname,compvarvalue);
  1219. IdfVersionSet:=true;
  1220. result:=true;
  1221. end;
  1222. end;
  1223. {$endif XTENSA}
  1224. procedure TOption.MaybeSetDefaultMacVersionMacro;
  1225. var
  1226. envstr: ansistring;
  1227. begin
  1228. if not(target_info.system in systems_darwin) then
  1229. exit;
  1230. if MacVersionSet then
  1231. exit;
  1232. { check for deployment target set via environment variable }
  1233. if not(target_info.system in [system_i386_iphonesim,system_arm_ios,system_aarch64_ios,system_x86_64_iphonesim]) then
  1234. begin
  1235. envstr:=GetEnvironmentVariable('MACOSX_DEPLOYMENT_TARGET');
  1236. if envstr<>'' then
  1237. if not ParseMacVersionMin(MacOSXVersionMin,iPhoneOSVersionMin,'MAC_OS_X_VERSION_MIN_REQUIRED',envstr,false) then
  1238. Message1(option_invalid_macosx_deployment_target,envstr)
  1239. else
  1240. begin
  1241. {$ifdef llvm}
  1242. { We only support libunwind as part of libsystem, which happened in Mac OS X 10.6 }
  1243. if MacOSXVersionMin.relationto(10,6,0)<0 then
  1244. Message1(option_invalid_macosx_deployment_target,envstr);
  1245. {$endif}
  1246. exit;
  1247. end;
  1248. end
  1249. else
  1250. begin
  1251. envstr:=GetEnvironmentVariable('IPHONEOS_DEPLOYMENT_TARGET');
  1252. if envstr<>'' then
  1253. if not ParseMacVersionMin(iPhoneOSVersionMin,MacOSXVersionMin,'IPHONE_OS_VERSION_MIN_REQUIRED',envstr,true) then
  1254. Message1(option_invalid_iphoneos_deployment_target,envstr)
  1255. else
  1256. exit;
  1257. end;
  1258. { nothing specified -> defaults }
  1259. case target_info.system of
  1260. system_powerpc_darwin:
  1261. begin
  1262. if not ParseMacVersionMin(MacOSXVersionMin,iPhoneOSVersionMin,'MAC_OS_X_VERSION_MIN_REQUIRED','10.3.0',false) then
  1263. internalerror(2022090910);
  1264. end;
  1265. system_powerpc64_darwin:
  1266. begin
  1267. if not ParseMacVersionMin(MacOSXVersionMin,iPhoneOSVersionMin,'MAC_OS_X_VERSION_MIN_REQUIRED','10.4.0',false) then
  1268. internalerror(2022090911);
  1269. end;
  1270. system_i386_darwin,
  1271. system_x86_64_darwin:
  1272. begin
  1273. if not ParseMacVersionMin(MacOSXVersionMin,iPhoneOSVersionMin,'MAC_OS_X_VERSION_MIN_REQUIRED','10.8.0',false) then
  1274. internalerror(2022090912);
  1275. end;
  1276. system_arm_ios,
  1277. system_i386_iphonesim:
  1278. begin
  1279. if not ParseMacVersionMin(iPhoneOSVersionMin,MacOSXVersionMin,'IPHONE_OS_VERSION_MIN_REQUIRED','9.0.0',false) then
  1280. internalerror(2022090913);
  1281. end;
  1282. system_aarch64_ios,
  1283. system_x86_64_iphonesim:
  1284. begin
  1285. if not ParseMacVersionMin(iPhoneOSVersionMin,MacOSXVersionMin,'IPHONE_OS_VERSION_MIN_REQUIRED','9.0.0',false) then
  1286. internalerror(2022090914);
  1287. end;
  1288. system_aarch64_darwin:
  1289. begin
  1290. if not ParseMacVersionMin(MacOSXVersionMin,iPhoneOSVersionMin,'MAC_OS_X_VERSION_MIN_REQUIRED','11.0.0',false) then
  1291. internalerror(2022090915);
  1292. end
  1293. else
  1294. internalerror(2012031001);
  1295. end;
  1296. end;
  1297. {$ifdef llvm}
  1298. procedure TOption.LLVMEnableSanitizers(sanitizers: TCmdStr);
  1299. var
  1300. sanitizer: TCMdStr;
  1301. begin
  1302. sanitizer:=GetToken(sanitizers,',');
  1303. repeat
  1304. case sanitizer of
  1305. 'address':
  1306. include(init_settings.moduleswitches,cs_sanitize_address);
  1307. else
  1308. IllegalPara(sanitizer);
  1309. end;
  1310. sanitizer:=GetToken(sanitizers,',');
  1311. until sanitizer='';
  1312. end;
  1313. {$endif}
  1314. {$ifdef XTENSA}
  1315. procedure TOption.MaybeSetIdfVersionMacro;
  1316. begin
  1317. if not(target_info.system=system_xtensa_freertos) then
  1318. exit;
  1319. if IdfVersionSet then
  1320. exit;
  1321. { nothing specified -> defaults }
  1322. case current_settings.controllertype of
  1323. ct_esp8266:
  1324. begin
  1325. set_system_compvar('IDF_VERSION','30300');
  1326. idf_version:=30300;
  1327. end;
  1328. ct_esp32:
  1329. begin
  1330. set_system_compvar('IDF_VERSION','40200');
  1331. idf_version:=40200;
  1332. end;
  1333. else
  1334. begin
  1335. set_system_compvar('IDF_VERSION','00000');
  1336. idf_version:=0;
  1337. end;
  1338. end;
  1339. end;
  1340. {$endif XTENSA}
  1341. procedure TOption.VerifyTargetProcessor;
  1342. begin
  1343. { no custom target processor specified -> ok }
  1344. if processorstr='' then
  1345. exit;
  1346. { custom target processor specified -> verify it's the one we support }
  1347. if upcase(processorstr)<>upcase(target_cpu_string) then
  1348. Message1(option_invalid_target_architecture,processorstr);
  1349. end;
  1350. function Toption.Unsetbool(var Opts:TCmdStr; Pos: Longint; const FullPara: TCmdStr; RequireBoolPara: boolean):boolean;
  1351. { checks if the character after pos in Opts is a + or a - and returns resp.
  1352. false or true. If it is another character (or none), it also returns false }
  1353. begin
  1354. UnsetBool := false;
  1355. if Length(Opts)>Pos then
  1356. begin
  1357. inc(Pos);
  1358. UnsetBool := Opts[Pos] = '-';
  1359. if Opts[Pos] in ['-','+']then
  1360. delete(Opts,Pos,1)
  1361. else if RequireBoolPara then
  1362. IllegalPara(FullPara);
  1363. end;
  1364. end;
  1365. procedure TOption.interpret_option(const opt:TCmdStr;ispara:boolean);
  1366. var
  1367. code : integer;
  1368. c : char;
  1369. {$ifdef cpucapabilities}
  1370. cf : tcpuflags;
  1371. cpuflagsstr,
  1372. extrasettings,
  1373. {$endif cpucapabilities}
  1374. more : TCmdStr;
  1375. major,minor : longint;
  1376. error : integer;
  1377. j,l , deletepos: longint;
  1378. d,s : TCmdStr;
  1379. hs : TCmdStr;
  1380. unicodemapping : punicodemap;
  1381. includecapability: Boolean;
  1382. {$ifdef llvm}
  1383. disable: boolean;
  1384. {$endif}
  1385. begin
  1386. if opt='' then
  1387. exit;
  1388. { only parse define,undef,target,verbosity,link etc options the firsttime
  1389. -Us must now also be first-passed to avoid rejection of -Sf options
  1390. earlier in command line }
  1391. if firstpass and
  1392. not(
  1393. (opt[1]='-') and
  1394. (
  1395. ((length(opt)>1) and (opt[2] in ['i','d','v','T','t','u','n','x','X','l','U'])) or
  1396. ((length(opt)>3) and (opt[2]='F') and (opt[3]='e')) or
  1397. ((length(opt)>3) and (opt[2]='C') and (opt[3] in ['a','f','p'])) or
  1398. ((length(opt)>3) and (opt[2]='W') and (opt[3] in ['m','p']))
  1399. )
  1400. ) then
  1401. exit;
  1402. Message1(option_handling_option,opt);
  1403. case opt[1] of
  1404. '-' :
  1405. begin
  1406. more:=Copy(opt,3,2147483647);
  1407. if firstpass then
  1408. Message1(option_interpreting_firstpass_option,opt)
  1409. else
  1410. Message1(option_interpreting_option,opt);
  1411. case opt[2] of
  1412. '?' :
  1413. begin
  1414. if (More <> '') and (More [1] = 'F') then
  1415. begin
  1416. FPCHelpLines := true;
  1417. Delete (More, 1, 1);
  1418. FPCBinaryPath := More;
  1419. end;
  1420. WriteHelpPages;
  1421. end;
  1422. 'a' :
  1423. begin
  1424. include(init_settings.globalswitches,cs_asm_leave);
  1425. j:=1;
  1426. while j<=length(more) do
  1427. begin
  1428. case more[j] of
  1429. '5' :
  1430. if (target_info.system in systems_all_windows+systems_nativent-[system_i8086_win16])
  1431. or (target_info.cpu in [cpu_mipseb, cpu_mipsel]) then
  1432. begin
  1433. if UnsetBool(More, j, opt, false) then
  1434. exclude(init_settings.globalswitches,cs_asm_pre_binutils_2_25)
  1435. else
  1436. include(init_settings.globalswitches,cs_asm_pre_binutils_2_25);
  1437. end
  1438. else
  1439. IllegalPara(opt);
  1440. 'l' :
  1441. include(init_settings.globalswitches,cs_asm_source);
  1442. 'r' :
  1443. include(init_settings.globalswitches,cs_asm_regalloc);
  1444. 't' :
  1445. include(init_settings.globalswitches,cs_asm_tempalloc);
  1446. 'n' :
  1447. include(init_settings.globalswitches,cs_asm_nodes);
  1448. { -ao option must be the last, everything behind it is passed directly to
  1449. external assembler, it is ignored if internal assembler is used. }
  1450. 'o' :
  1451. begin
  1452. asmextraopt:=copy(more,j+1,length(more)-j);
  1453. break;
  1454. end;
  1455. 'p' :
  1456. begin
  1457. exclude(init_settings.globalswitches,cs_asm_leave);
  1458. if UnsetBool(More, 0, opt, false) then
  1459. exclude(init_settings.globalswitches,cs_asm_pipe)
  1460. else
  1461. include(init_settings.globalswitches,cs_asm_pipe);
  1462. end;
  1463. '-' :
  1464. init_settings.globalswitches:=init_settings.globalswitches -
  1465. [cs_asm_leave, cs_asm_source,cs_asm_regalloc, cs_asm_tempalloc,
  1466. cs_asm_nodes, cs_asm_pipe];
  1467. else
  1468. IllegalPara(opt);
  1469. end;
  1470. inc(j);
  1471. end;
  1472. end;
  1473. 'A' :
  1474. begin
  1475. if CompareText(More,'DEFAULT') = 0 then
  1476. paratargetasm:=as_default
  1477. else
  1478. paratargetasm:=find_asm_by_string(More);
  1479. if paratargetasm=as_none then
  1480. IllegalPara(opt);
  1481. end;
  1482. 'b' :
  1483. begin
  1484. // Message1(option_obsolete_switch,'-b');
  1485. if UnsetBool(More,0,opt,false) then
  1486. begin
  1487. init_settings.moduleswitches:=init_settings.moduleswitches-[cs_browser];
  1488. init_settings.moduleswitches:=init_settings.moduleswitches-[cs_local_browser];
  1489. end
  1490. else
  1491. begin
  1492. init_settings.moduleswitches:=init_settings.moduleswitches+[cs_browser];
  1493. end;
  1494. if More<>'' then
  1495. if (More='l') or (More='l+') then
  1496. init_settings.moduleswitches:=init_settings.moduleswitches+[cs_local_browser]
  1497. else if More='l-' then
  1498. init_settings.moduleswitches:=init_settings.moduleswitches-[cs_local_browser]
  1499. else
  1500. IllegalPara(opt);
  1501. end;
  1502. 'B' :
  1503. do_build:=not UnSetBool(more,0,opt,true);
  1504. 'C' :
  1505. begin
  1506. j:=1;
  1507. while j<=length(more) do
  1508. begin
  1509. case more[j] of
  1510. '3' :
  1511. If UnsetBool(More, j, opt, false) then
  1512. exclude(init_settings.localswitches,cs_ieee_errors)
  1513. Else
  1514. include(init_settings.localswitches,cs_ieee_errors);
  1515. 'a' :
  1516. begin
  1517. s:=upper(copy(more,j+1,length(more)-j));
  1518. if not(SetAbiType(s,target_info.abi)) then
  1519. IllegalPara(opt);
  1520. ABISetExplicitly:=true;
  1521. break;
  1522. end;
  1523. 'b' :
  1524. begin
  1525. if UnsetBool(More, j, opt, false) then
  1526. target_info.endian:=endian_little
  1527. else
  1528. target_info.endian:=endian_big;
  1529. end;
  1530. 'c' :
  1531. begin
  1532. if not SetAktProcCall(upper(copy(more,j+1,length(more)-j)),init_settings.defproccall) then
  1533. IllegalPara(opt);
  1534. break;
  1535. end;
  1536. {$ifdef cpufpemu}
  1537. 'e' :
  1538. begin
  1539. If UnsetBool(More, j, opt, false) then
  1540. exclude(init_settings.moduleswitches,cs_fp_emulation)
  1541. Else
  1542. include(init_settings.moduleswitches,cs_fp_emulation);
  1543. end;
  1544. {$endif cpufpemu}
  1545. 'E' :
  1546. If UnsetBool(More, j, opt, false) then
  1547. exclude(init_settings.localswitches,cs_check_fpu_exceptions)
  1548. Else
  1549. include(init_settings.localswitches,cs_check_fpu_exceptions);
  1550. 'f' :
  1551. begin
  1552. s:=upper(copy(more,j+1,length(more)-j));
  1553. if not(SetFpuType(s,init_settings.fputype)) then
  1554. IllegalPara(opt);
  1555. FPUSetExplicitly:=True;
  1556. break;
  1557. end;
  1558. 'F' :
  1559. begin
  1560. if not SetMinFPConstPrec(copy(more,j+1,length(more)-j),init_settings.minfpconstprec) then
  1561. IllegalPara(opt);
  1562. break;
  1563. end;
  1564. 'g' :
  1565. begin
  1566. if tf_no_pic_supported in target_info.flags then
  1567. begin
  1568. { consume a possible '-' coming after it }
  1569. UnsetBool(More, j, opt, false);
  1570. message(scan_w_pic_ignored);
  1571. end
  1572. else if UnsetBool(More, j, opt, false) then
  1573. exclude(init_settings.moduleswitches,cs_create_pic)
  1574. else
  1575. include(init_settings.moduleswitches,cs_create_pic);
  1576. end;
  1577. 'h' :
  1578. begin
  1579. l:=pos(',',copy(more,j+1,length(more)-j));
  1580. if l=0 then
  1581. l:=length(more)-j+1;
  1582. val(copy(more,j+1,l-1),heapsize,code);
  1583. if (code<>0)
  1584. {$ifdef AVR}
  1585. or (heapsize<32)
  1586. {$else AVR}
  1587. or (heapsize<1024)
  1588. {$endif AVR}
  1589. then
  1590. IllegalPara(opt)
  1591. else if l<=length(more)-j then
  1592. begin
  1593. val(copy(more,j+l+1,length(more)),maxheapsize,code);
  1594. if code<>0 then
  1595. IllegalPara(opt)
  1596. else if (maxheapsize<heapsize) then
  1597. begin
  1598. message(scan_w_heapmax_lessthan_heapmin);
  1599. maxheapsize:=heapsize;
  1600. end;
  1601. end;
  1602. break;
  1603. end;
  1604. 'i' :
  1605. If UnsetBool(More, j, opt, false) then
  1606. exclude(init_settings.localswitches,cs_check_io)
  1607. else
  1608. include(init_settings.localswitches,cs_check_io);
  1609. {$ifdef arm}
  1610. 'I' :
  1611. begin
  1612. if (upper(copy(more,j+1,length(more)-j))='THUMB') and
  1613. { does selected CPU really understand thumb? }
  1614. (init_settings.cputype in cpu_has_thumb) then
  1615. init_settings.instructionset:=is_thumb
  1616. else if upper(copy(more,j+1,length(more)-j))='ARM' then
  1617. init_settings.instructionset:=is_arm
  1618. else
  1619. IllegalPara(opt);
  1620. break;
  1621. end;
  1622. {$endif arm}
  1623. {$ifdef llvm}
  1624. 'l':
  1625. begin
  1626. l:=j+1;
  1627. while l<=length(More) do
  1628. begin
  1629. case More[l] of
  1630. 'f':
  1631. begin
  1632. delete(More,1,l);
  1633. disable:=Unsetbool(More,length(More)-1,opt,false);
  1634. case More of
  1635. 'lto':
  1636. begin
  1637. if not disable then
  1638. begin
  1639. include(init_settings.moduleswitches,cs_lto);
  1640. LTOExt:='.bc';
  1641. end
  1642. else
  1643. exclude(init_settings.moduleswitches,cs_lto);
  1644. end;
  1645. 'ltonosystem':
  1646. begin
  1647. if not disable then
  1648. begin
  1649. include(init_settings.globalswitches,cs_lto_nosystem);
  1650. end
  1651. else
  1652. exclude(init_settings.globalswitches,cs_lto_nosystem);
  1653. end;
  1654. else if More.StartsWith('sanitize=') then
  1655. begin
  1656. delete(More,1,length('sanitize='));
  1657. LLVMEnableSanitizers(more);
  1658. end
  1659. else
  1660. begin
  1661. IllegalPara(opt);
  1662. end;
  1663. end;
  1664. l:=length(more)+1;
  1665. end;
  1666. 'v':
  1667. begin
  1668. init_settings.llvmversion:=llvmversion2enum(copy(More,l+1,length(More)));
  1669. if init_settings.llvmversion=llvmver_invalid then
  1670. begin
  1671. IllegalPara(opt);
  1672. end;
  1673. l:=length(More)+1;
  1674. end
  1675. else
  1676. begin
  1677. IllegalPara(opt);
  1678. end;
  1679. end;
  1680. end;
  1681. j:=l;
  1682. end;
  1683. {$endif llvm}
  1684. 'n' :
  1685. If UnsetBool(More, j, opt, false) then
  1686. exclude(init_settings.globalswitches,cs_link_nolink)
  1687. Else
  1688. include(init_settings.globalswitches,cs_link_nolink);
  1689. 'N' :
  1690. If UnsetBool(More, j, opt, false) then
  1691. exclude(init_settings.localswitches,cs_check_low_addr_load)
  1692. Else
  1693. include(init_settings.localswitches,cs_check_low_addr_load);
  1694. 'o' :
  1695. If UnsetBool(More, j, opt, false) then
  1696. exclude(init_settings.localswitches,cs_check_overflow)
  1697. Else
  1698. include(init_settings.localswitches,cs_check_overflow);
  1699. 'O' :
  1700. If UnsetBool(More, j, opt, false) then
  1701. exclude(init_settings.localswitches,cs_check_ordinal_size)
  1702. Else
  1703. include(init_settings.localswitches,cs_check_ordinal_size);
  1704. 'p' :
  1705. begin
  1706. s:=upper(copy(more,j+1,length(more)-j));
  1707. {$ifdef cpucapabilities}
  1708. { find first occurrence of + or - }
  1709. deletepos:=PosCharset(['+','-'],s);
  1710. if deletepos<>0 then
  1711. begin
  1712. extrasettings:=Copy(s,deletepos,Length(s));
  1713. Delete(s,deletepos,Length(s));
  1714. end
  1715. else
  1716. extrasettings:='';
  1717. {$endif cpucapabilities}
  1718. if not(Setcputype(s,init_settings)) then
  1719. IllegalPara(opt);
  1720. {$ifdef cpucapabilities}
  1721. while extrasettings<>'' do
  1722. begin
  1723. Delete(extrasettings,1,1);
  1724. includecapability:=true;
  1725. deletepos:=PosCharset(['+','-'],extrasettings);
  1726. if deletepos<>0 then
  1727. begin
  1728. includecapability:=extrasettings[deletepos]='+';
  1729. s:=Copy(extrasettings,1,deletepos-1);
  1730. Delete(extrasettings,1,deletepos-1);
  1731. end
  1732. else
  1733. begin
  1734. s:=extrasettings;
  1735. extrasettings:='';
  1736. end;
  1737. for cf in tcpuflags do
  1738. begin
  1739. Str(cf,cpuflagsstr);
  1740. { expect that the cpuflagsstr i.e. the enum as well contains _HAS_ }
  1741. if Pos('_HAS_',cpuflagsstr)<>0 then
  1742. { get rid of prefix including _HAS_ }
  1743. Delete(cpuflagsstr,1,Pos('_HAS_',cpuflagsstr)+4)
  1744. else
  1745. Internalerror(2021110601);
  1746. if s=cpuflagsstr then
  1747. begin
  1748. if includecapability then
  1749. Include(cpu_capabilities[init_settings.cputype],cf)
  1750. else
  1751. Exclude(cpu_capabilities[init_settings.cputype],cf);
  1752. s:='';
  1753. break;
  1754. end;
  1755. end;
  1756. if s<>'' then
  1757. IllegalPara(opt);
  1758. end;
  1759. {$endif cpucapabilities}
  1760. CPUSetExplicitly:=true;
  1761. break;
  1762. end;
  1763. 'P':
  1764. begin
  1765. delete(more,1,1);
  1766. case upper(copy(more,1,pos('=',more)-1)) of
  1767. 'PACKSET':
  1768. begin
  1769. delete(more,1,pos('=',more));
  1770. case more of
  1771. '0','DEFAULT','NORMAL':
  1772. init_settings.setalloc:=0;
  1773. '1','2','4','8':
  1774. init_settings.setalloc:=StrToInt(more);
  1775. else
  1776. IllegalPara(opt);
  1777. end
  1778. end;
  1779. 'PACKENUM':
  1780. begin
  1781. delete(more,1,pos('=',more));
  1782. case more of
  1783. '0','DEFAULT','NORMAL':
  1784. init_settings.packenum:=4;
  1785. '1','2','4':
  1786. init_settings.packenum:=StrToInt(more);
  1787. else
  1788. IllegalPara(opt);
  1789. end;
  1790. end;
  1791. 'PACKRECORD':
  1792. begin
  1793. delete(more,1,pos('=',more));
  1794. case more of
  1795. '0','DEFAULT','NORMAL':
  1796. init_settings.packrecords:=default_settings.packrecords;
  1797. '1','2','4','8','16','32':
  1798. init_settings.packrecords:=StrToInt(more);
  1799. else
  1800. IllegalPara(opt);
  1801. end;
  1802. end
  1803. else
  1804. IllegalPara(opt);
  1805. end;
  1806. end;
  1807. 'r' :
  1808. If UnsetBool(More, j, opt, false) then
  1809. exclude(init_settings.localswitches,cs_check_range)
  1810. Else
  1811. include(init_settings.localswitches,cs_check_range);
  1812. 'R' :
  1813. If UnsetBool(More, j, opt, false) then
  1814. begin
  1815. exclude(init_settings.localswitches,cs_check_range);
  1816. exclude(init_settings.localswitches,cs_check_object);
  1817. end
  1818. Else
  1819. begin
  1820. include(init_settings.localswitches,cs_check_range);
  1821. include(init_settings.localswitches,cs_check_object);
  1822. end;
  1823. 's' :
  1824. begin
  1825. val(copy(more,j+1,length(more)-j),stacksize,code);
  1826. if (code<>0)
  1827. {$ifdef cpu16bitaddr}
  1828. or (stacksize>=65521)
  1829. {$else cpu16bitaddr}
  1830. or (stacksize>=67107840)
  1831. {$endif cpu16bitaddr}
  1832. or (stacksize<1024) then
  1833. IllegalPara(opt);
  1834. break;
  1835. end;
  1836. 't' :
  1837. If UnsetBool(More, j, opt, false) then
  1838. exclude(init_settings.localswitches,cs_check_stack)
  1839. Else
  1840. include(init_settings.localswitches,cs_check_stack);
  1841. 'D' :
  1842. If UnsetBool(More, j, opt, false) then
  1843. exclude(init_settings.moduleswitches,cs_create_dynamic)
  1844. Else
  1845. include(init_settings.moduleswitches,cs_create_dynamic);
  1846. 'X' :
  1847. If UnsetBool(More, j, opt, false) then
  1848. exclude(init_settings.moduleswitches,cs_create_smart)
  1849. Else
  1850. include(init_settings.moduleswitches,cs_create_smart);
  1851. 'T' :
  1852. begin
  1853. if not UpdateTargetSwitchStr(copy(more,j+1,length(more)),init_settings.targetswitches,true) then
  1854. IllegalPara(opt);
  1855. break;
  1856. end;
  1857. 'v' :
  1858. If target_info.system in systems_jvm then
  1859. If UnsetBool(More, j, opt, false) then
  1860. exclude(init_settings.localswitches,cs_check_var_copyout)
  1861. Else
  1862. include(init_settings.localswitches,cs_check_var_copyout)
  1863. else
  1864. IllegalPara(opt);
  1865. 'V':
  1866. begin
  1867. s:=upper(copy(more,j+1,length(more)-j));
  1868. if s='GLOBAL-DYNAMIC' then
  1869. init_settings.tlsmodel:=tlsm_global_dynamic
  1870. else if s='LOCAL-EXEC' then
  1871. init_settings.tlsmodel:=tlsm_local_exec
  1872. else
  1873. IllegalPara(opt);
  1874. break;
  1875. end;
  1876. else
  1877. IllegalPara(opt);
  1878. end;
  1879. inc(j);
  1880. end;
  1881. end;
  1882. 'd' :
  1883. begin
  1884. l:=Pos(':=',more);
  1885. DefaultReplacements(more);
  1886. if l>0 then
  1887. hs:=copy(more,1,l-1)
  1888. else
  1889. hs:=more;
  1890. if (not is_identifier(hs)) then
  1891. begin
  1892. if hs='' then
  1893. Message1(option_missing_arg,'-d')
  1894. else
  1895. Message1(option_malformed_para,opt);
  1896. StopOptions(1);
  1897. end;
  1898. if l>0 then
  1899. begin
  1900. if cs_support_macro in init_settings.moduleswitches then
  1901. set_system_macro(hs,Copy(more,l+2,255))
  1902. else
  1903. set_system_compvar(hs,Copy(more,l+2,255));
  1904. end
  1905. else
  1906. def_system_macro(hs);
  1907. end;
  1908. 'D' :
  1909. begin
  1910. j:=1;
  1911. while j<=length(more) do
  1912. begin
  1913. case more[j] of
  1914. 'd' :
  1915. begin
  1916. include(init_settings.globalswitches,cs_link_deffile);
  1917. description:=Copy(more,j+1,255);
  1918. break;
  1919. end;
  1920. 'D' :
  1921. begin
  1922. datestr:=Copy(more,j+1,255);
  1923. break;
  1924. end;
  1925. 'T' :
  1926. begin
  1927. timestr:=Copy(more,j+1,255);
  1928. break;
  1929. end;
  1930. 'v' :
  1931. begin
  1932. include(init_settings.globalswitches,cs_link_deffile);
  1933. dllversion:=Copy(more,j+1,255);
  1934. l:=pos('.',dllversion);
  1935. dllminor:=0;
  1936. error:=0;
  1937. if l>0 then
  1938. begin
  1939. val(copy(dllversion,l+1,255),minor,error);
  1940. if (error=0) and
  1941. (minor>=0) and (minor<=$ffff) then
  1942. dllminor:=minor
  1943. else
  1944. if error=0 then
  1945. error:=1;
  1946. end;
  1947. if l=0 then
  1948. l:=256;
  1949. dllmajor:=1;
  1950. major:=0;
  1951. if error=0 then
  1952. val(copy(dllversion,1,l-1),major,error);
  1953. if (error=0) and (major>=0) and (major<=$ffff) then
  1954. dllmajor:=major
  1955. else
  1956. if error=0 then
  1957. error:=1;
  1958. if error<>0 then
  1959. Message1(scan_w_wrong_version_ignored,dllversion);
  1960. break;
  1961. end;
  1962. 'w' :
  1963. begin
  1964. include(init_settings.globalswitches,cs_link_deffile);
  1965. usewindowapi:=true;
  1966. end;
  1967. '-' :
  1968. begin
  1969. exclude(init_settings.globalswitches,cs_link_deffile);
  1970. usewindowapi:=false;
  1971. end;
  1972. else
  1973. IllegalPara(opt);
  1974. end;
  1975. inc(j);
  1976. end;
  1977. end;
  1978. 'e' :
  1979. exepath:=FixPath(More,true);
  1980. 'E' :
  1981. begin
  1982. if UnsetBool(More, 0, opt, true) then
  1983. exclude(init_settings.globalswitches,cs_link_nolink)
  1984. else
  1985. include(init_settings.globalswitches,cs_link_nolink);
  1986. end;
  1987. 'f' :
  1988. begin
  1989. if more='PIC' then
  1990. begin
  1991. if tf_no_pic_supported in target_info.flags then
  1992. message(scan_w_pic_ignored)
  1993. else
  1994. include(init_settings.moduleswitches,cs_create_pic)
  1995. end
  1996. else
  1997. IllegalPara(opt);
  1998. end;
  1999. 'F' :
  2000. begin
  2001. if more='' then
  2002. IllegalPara(opt);
  2003. c:=more[1];
  2004. Delete(more,1,1);
  2005. DefaultReplacements(More);
  2006. case c of
  2007. 'a' :
  2008. autoloadunits:=more;
  2009. 'c' :
  2010. begin
  2011. { if we first specify that the system code page should be
  2012. used and then explicitly specify a code page, unset the
  2013. flag that we're using the system code page again }
  2014. SetCompileModeSwitch('SYSTEMCODEPAGE-',true);
  2015. if (upper(more)='UTF8') or (upper(more)='UTF-8') then
  2016. init_settings.sourcecodepage:=CP_UTF8
  2017. else if not(cpavailable(more)) then
  2018. Message1(option_code_page_not_available,more)
  2019. else
  2020. init_settings.sourcecodepage:=codepagebyname(more);
  2021. include(init_settings.moduleswitches,cs_explicit_codepage);
  2022. end;
  2023. 'C' :
  2024. RCCompiler:=More;
  2025. 'd' :
  2026. if UnsetBool(more, 0, opt, true) then
  2027. init_settings.disabledircache:=false
  2028. else
  2029. init_settings.disabledircache:=true;
  2030. 'D' :
  2031. utilsdirectory:=FixPath(More,true);
  2032. 'e' :
  2033. SetRedirectFile(More);
  2034. 'E' :
  2035. OutputExeDir:=FixPath(More,true);
  2036. 'f' :
  2037. if (target_info.system in systems_darwin) then
  2038. if ispara then
  2039. ParaFrameworkPath.AddPath(More,false)
  2040. else
  2041. frameworksearchpath.AddPath(More,true)
  2042. {$ifdef XTENSA}
  2043. else if (target_info.system=system_xtensa_freertos) then
  2044. idfpath:=FixPath(More,true)
  2045. {$endif XTENSA}
  2046. else
  2047. IllegalPara(opt);
  2048. 'F' :
  2049. RCForceFPCRes:=true;
  2050. 'i' :
  2051. begin
  2052. if ispara then
  2053. ParaIncludePath.AddPath(More,false)
  2054. else
  2055. includesearchpath.AddPath(More,true);
  2056. end;
  2057. 'm' :
  2058. begin
  2059. s:=ExtractFileDir(more);
  2060. if TryStrToInt(ExtractFileName(more),j) then
  2061. begin
  2062. unicodemapping:=loadunicodemapping(More,More+'.txt',j);
  2063. if assigned(unicodemapping) then
  2064. registermapping(unicodemapping)
  2065. else
  2066. IllegalPara(opt);
  2067. end
  2068. else
  2069. IllegalPara(opt);
  2070. end;
  2071. 'M' :
  2072. unicodepath:=FixPath(More,true);
  2073. 'g' :
  2074. Message2(option_obsolete_switch_use_new,'-Fg','-Fl');
  2075. 'l' :
  2076. begin
  2077. if ispara then
  2078. ParaLibraryPath.AddLibraryPath(sysrootpath,More,false)
  2079. else
  2080. LibrarySearchPath.AddLibraryPath(sysrootpath,More,true)
  2081. end;
  2082. 'L' :
  2083. begin
  2084. if More<>'' then
  2085. ParaDynamicLinker:=More
  2086. else
  2087. IllegalPara(opt);
  2088. end;
  2089. 'N' :
  2090. begin
  2091. if more<>'' then
  2092. paranamespaces.insert(more)
  2093. else
  2094. illegalpara(opt);
  2095. end;
  2096. 'o' :
  2097. begin
  2098. if ispara then
  2099. ParaObjectPath.AddPath(More,false)
  2100. else
  2101. ObjectSearchPath.AddPath(More,true);
  2102. end;
  2103. 'P' :
  2104. begin
  2105. if ispara then
  2106. parapackages.add(more,nil)
  2107. else
  2108. add_package(more,true,true);
  2109. end;
  2110. 'p' :
  2111. begin
  2112. if ispara then
  2113. parapackagepath.AddPath(More,false)
  2114. else
  2115. packagesearchpath.AddPath(More,true);
  2116. end;
  2117. 'r' :
  2118. Msgfilename:=More;
  2119. 'R' :
  2120. ResCompiler:=More;
  2121. 'u' :
  2122. begin
  2123. if ispara then
  2124. ParaUnitPath.AddPath(More,false)
  2125. else
  2126. unitsearchpath.AddPath(More,true);
  2127. end;
  2128. 'U' :
  2129. OutputUnitDir:=FixPath(More,true);
  2130. 'W',
  2131. 'w':
  2132. begin
  2133. if More<>'' then
  2134. begin
  2135. DefaultReplacements(More);
  2136. D:=ExtractFilePath(More);
  2137. if (D<>'') then
  2138. D:=FixPath(D,True);
  2139. D:=D+ExtractFileName(More);
  2140. if (c='W') then
  2141. WpoFeedbackOutput:=D
  2142. else
  2143. WpoFeedbackInput:=D;
  2144. end
  2145. else
  2146. IllegalPara(opt);
  2147. end;
  2148. else
  2149. IllegalPara(opt);
  2150. end;
  2151. end;
  2152. 'g' :
  2153. begin
  2154. if UnsetBool(More, 0, opt, false) then
  2155. begin
  2156. exclude(init_settings.moduleswitches,cs_debuginfo);
  2157. exclude(init_settings.globalswitches,cs_use_heaptrc);
  2158. exclude(init_settings.globalswitches,cs_use_lineinfo);
  2159. exclude(init_settings.localswitches,cs_checkpointer);
  2160. paratargetdbg:=dbg_none;
  2161. localvartrashing := -1;
  2162. end
  2163. else
  2164. begin
  2165. include(init_settings.moduleswitches,cs_debuginfo);
  2166. if paratargetdbg=dbg_none then
  2167. paratargetdbg:=target_info.dbg;
  2168. end;
  2169. if not RelocSectionSetExplicitly then
  2170. RelocSection:=false;
  2171. j:=1;
  2172. while j<=length(more) do
  2173. begin
  2174. case more[j] of
  2175. 'c' :
  2176. begin
  2177. if UnsetBool(More, j, opt, false) then
  2178. exclude(init_settings.localswitches,cs_checkpointer)
  2179. else if (target_info.system in systems_support_checkpointer) then
  2180. begin
  2181. if do_release then
  2182. Message(option_gc_incompatible_with_release_flag)
  2183. else
  2184. include(init_settings.localswitches,cs_checkpointer);
  2185. end
  2186. else
  2187. UnsupportedPara('-gc');
  2188. end;
  2189. 'h' :
  2190. begin
  2191. if UnsetBool(More, j, opt, false) then
  2192. exclude(init_settings.globalswitches,cs_use_heaptrc)
  2193. else
  2194. begin
  2195. if cs_gdb_valgrind in init_settings.globalswitches then
  2196. Message2(option_valgrind_heaptrc_mismatch,'-gh', '-gv');
  2197. include(init_settings.globalswitches,cs_use_heaptrc);
  2198. end;
  2199. end;
  2200. 'l' :
  2201. begin
  2202. if UnsetBool(More, j, opt, false) then
  2203. exclude(init_settings.globalswitches,cs_use_lineinfo)
  2204. else
  2205. include(init_settings.globalswitches,cs_use_lineinfo);
  2206. end;
  2207. 'm' :
  2208. begin
  2209. paratargetdbg:=dbg_codeview;
  2210. end;
  2211. 'o' :
  2212. begin
  2213. if not UpdateDebugStr(copy(more,j+1,length(more)),init_settings.debugswitches) then
  2214. IllegalPara(opt);
  2215. break;
  2216. end;
  2217. 'p' :
  2218. begin
  2219. if UnsetBool(More, j, opt, false) then
  2220. exclude(init_settings.globalswitches,cs_stabs_preservecase)
  2221. else
  2222. include(init_settings.globalswitches,cs_stabs_preservecase);
  2223. end;
  2224. 's' :
  2225. begin
  2226. paratargetdbg:=dbg_stabs;
  2227. end;
  2228. 't' :
  2229. begin
  2230. if UnsetBool(More, j, opt, false) then
  2231. localvartrashing := -1
  2232. else
  2233. localvartrashing := (localvartrashing + 1) mod nroftrashvalues;
  2234. end;
  2235. 'v' :
  2236. begin
  2237. if UnsetBool(More, j, opt, false) then
  2238. exclude(init_settings.globalswitches,cs_gdb_valgrind)
  2239. else
  2240. begin
  2241. if cs_use_heaptrc in init_settings.globalswitches then
  2242. Message2(option_valgrind_heaptrc_mismatch,'-gh', '-gv');
  2243. include(init_settings.globalswitches,cs_gdb_valgrind);
  2244. end;
  2245. end;
  2246. 'w' :
  2247. begin
  2248. if (j<length(more)) and (more[j+1] in ['2','3','4']) then
  2249. begin
  2250. case more[j+1] of
  2251. '2': paratargetdbg:=dbg_dwarf2;
  2252. '3': paratargetdbg:=dbg_dwarf3;
  2253. '4': paratargetdbg:=dbg_dwarf4;
  2254. end;
  2255. inc(j);
  2256. end
  2257. else
  2258. paratargetdbg:=dbg_dwarf2;
  2259. end;
  2260. else
  2261. IllegalPara(opt);
  2262. end;
  2263. inc(j);
  2264. end;
  2265. end;
  2266. 'h' :
  2267. begin
  2268. NoPressEnter:=true;
  2269. if (More <> '') and (More [1] = 'F') then
  2270. begin
  2271. FPCHelpLines := true;
  2272. Delete (More, 1, 1);
  2273. FPCBinaryPath := More;
  2274. end;
  2275. WriteHelpPages;
  2276. end;
  2277. 'i' :
  2278. begin
  2279. if (More='') or
  2280. (More [1] in ['a', 'b', 'c', 'f', 'i', {$ifdef LLVM}'l',{$endif} 'm', 'o', 'r', 't', 'u', 'w', 'x']) then
  2281. WriteInfo (More)
  2282. else
  2283. QuickInfo:=QuickInfo+More;
  2284. end;
  2285. 'I' :
  2286. begin
  2287. if ispara then
  2288. ParaIncludePath.AddPath(More,false)
  2289. else
  2290. includesearchpath.AddPath(More,false);
  2291. end;
  2292. 'k' :
  2293. begin
  2294. if more<>'' then
  2295. ParaLinkOptions:=ParaLinkOptions+' '+More
  2296. else
  2297. IllegalPara(opt);
  2298. end;
  2299. 'l' :
  2300. ParaLogo:=not UnSetBool(more,0,opt,true);
  2301. {$ifdef PREPROCWRITE}
  2302. 'm' :
  2303. parapreprocess:=not UnSetBool(more,0,opt,true);
  2304. {$endif PREPROCWRITE}
  2305. 'M' :
  2306. begin
  2307. more:=Upper(more);
  2308. if not SetCompileMode(more, true) then
  2309. if not SetCompileModeSwitch(more, true) then
  2310. IllegalPara(opt);
  2311. end;
  2312. 'n' :
  2313. begin
  2314. if More='' then
  2315. disable_configfile:=true
  2316. else
  2317. IllegalPara(opt);
  2318. end;
  2319. 'o' :
  2320. begin
  2321. if More<>'' then
  2322. begin
  2323. DefaultReplacements(More);
  2324. D:=ExtractFilePath(More);
  2325. if (D<>'') then
  2326. OutputExeDir:=FixPath(D,True);
  2327. OutputFileName:=ExtractFileName(More);
  2328. end
  2329. else
  2330. IllegalPara(opt);
  2331. end;
  2332. 'O' :
  2333. begin
  2334. j:=1;
  2335. while j<=length(more) do
  2336. begin
  2337. case more[j] of
  2338. '1' :
  2339. init_settings.optimizerswitches:=init_settings.optimizerswitches+level1optimizerswitches;
  2340. '2' :
  2341. init_settings.optimizerswitches:=init_settings.optimizerswitches+level2optimizerswitches;
  2342. '3' :
  2343. init_settings.optimizerswitches:=init_settings.optimizerswitches+level3optimizerswitches;
  2344. '4' :
  2345. init_settings.optimizerswitches:=init_settings.optimizerswitches+level4optimizerswitches;
  2346. 'a' :
  2347. begin
  2348. if not(UpdateAlignmentStr(Copy(Opt,j+3,255),ParaAlignment)) then
  2349. IllegalPara(opt);
  2350. break;
  2351. end;
  2352. 's' :
  2353. include(init_settings.optimizerswitches,cs_opt_size);
  2354. 'p' :
  2355. begin
  2356. if not Setoptimizecputype(copy(more,j+1,length(more)),init_settings.optimizecputype) then
  2357. begin
  2358. OptCPUSetExplicitly:=true;
  2359. { Give warning for old i386 switches }
  2360. if (Length(More)-j=1) and
  2361. (More[j+1]>='1') and (More[j+1]<='5')then
  2362. Message2(option_obsolete_switch_use_new,'-Op<nr>','-Op<name>')
  2363. else
  2364. IllegalPara(opt);
  2365. end;
  2366. break;
  2367. end;
  2368. 'o' :
  2369. begin
  2370. if not UpdateOptimizerStr(copy(more,j+1,length(more)),init_settings.optimizerswitches) then
  2371. IllegalPara(opt);
  2372. break;
  2373. end;
  2374. '-' :
  2375. begin
  2376. init_settings.optimizerswitches:=[];
  2377. FillChar(ParaAlignment,sizeof(ParaAlignment),0);
  2378. end;
  2379. { Obsolete switches }
  2380. 'g' :
  2381. Message2(option_obsolete_switch_use_new,'-Og','-Os');
  2382. 'G' :
  2383. Message1(option_obsolete_switch,'-OG');
  2384. 'r' :
  2385. Message2(option_obsolete_switch_use_new,'-Or','-O2 or -Ooregvar');
  2386. 'u' :
  2387. Message2(option_obsolete_switch_use_new,'-Ou','-Oouncertain');
  2388. 'w' :
  2389. begin
  2390. if not UpdateWpoStr(copy(more,j+1,length(more)),init_settings.dowpoptimizerswitches) then
  2391. IllegalPara(opt);
  2392. break;
  2393. end;
  2394. 'W' :
  2395. begin
  2396. if not UpdateWpoStr(copy(more,j+1,length(more)),init_settings.genwpoptimizerswitches) then
  2397. IllegalPara(opt);
  2398. break;
  2399. end;
  2400. else
  2401. IllegalPara(opt);
  2402. end;
  2403. inc(j);
  2404. end;
  2405. end;
  2406. 'p' :
  2407. begin
  2408. if UnsetBool(More, 0, opt, false) then
  2409. begin
  2410. init_settings.moduleswitches:=init_settings.moduleswitches-[cs_profile];
  2411. undef_system_macro('FPC_PROFILE');
  2412. end
  2413. else
  2414. if Length(More)=0 then
  2415. IllegalPara(opt)
  2416. else
  2417. case more[1] of
  2418. 'g' : if UnsetBool(more, 1, opt, false) then
  2419. begin
  2420. exclude(init_settings.moduleswitches,cs_profile);
  2421. undef_system_macro('FPC_PROFILE');
  2422. end
  2423. else if (target_info.system in supported_targets_pg) then
  2424. begin
  2425. include(init_settings.moduleswitches,cs_profile);
  2426. def_system_macro('FPC_PROFILE');
  2427. end
  2428. else
  2429. UnsupportedPara('-pg');
  2430. else
  2431. IllegalPara(opt);
  2432. end;
  2433. end;
  2434. 'P' :
  2435. begin
  2436. { used to select the target processor with the "fpc" binary;
  2437. give an error if it's not the target architecture supported by
  2438. this compiler binary (will be verified after the target_info
  2439. is set) }
  2440. processorstr:=More;
  2441. end;
  2442. 'R' :
  2443. begin
  2444. if not SetAsmReadMode(More,init_settings.asmmode) then
  2445. IllegalPara(opt);
  2446. end;
  2447. 's' :
  2448. begin
  2449. if UnsetBool(More, 0, opt, false) then
  2450. begin
  2451. init_settings.globalswitches:=init_settings.globalswitches-[cs_asm_extern,cs_link_extern,cs_link_nolink];
  2452. if more<>'' then
  2453. IllegalPara(opt);
  2454. end
  2455. else
  2456. begin
  2457. init_settings.globalswitches:=init_settings.globalswitches+[cs_asm_extern,cs_link_extern,cs_link_nolink];
  2458. if more='h' then
  2459. init_settings.globalswitches:=init_settings.globalswitches-[cs_link_on_target,cs_assemble_on_target]
  2460. else if more='t' then
  2461. init_settings.globalswitches:=init_settings.globalswitches+[cs_link_on_target,cs_assemble_on_target]
  2462. else if more='T' then
  2463. init_settings.globalswitches:=init_settings.globalswitches+[cs_link_on_target]-[cs_asm_extern]
  2464. else if more='r' then
  2465. init_settings.globalswitches:=init_settings.globalswitches+[cs_asm_leave,cs_no_regalloc]
  2466. else if more<>'' then
  2467. IllegalPara(opt);
  2468. end;
  2469. end;
  2470. 'S' :
  2471. begin
  2472. if more='' then
  2473. IllegalPara(opt);
  2474. if more[1]='I' then
  2475. begin
  2476. {$ifdef jvm}
  2477. UnsupportedPara('-SI');
  2478. {$endif}
  2479. if upper(more)='ICOM' then
  2480. init_settings.interfacetype:=it_interfacecom
  2481. else if upper(more)='ICORBA' then
  2482. init_settings.interfacetype:=it_interfacecorba
  2483. else
  2484. IllegalPara(opt);
  2485. end
  2486. else
  2487. begin
  2488. j:=1;
  2489. while j<=length(more) do
  2490. begin
  2491. case more[j] of
  2492. '2' : //an alternative to -Mobjfpc
  2493. SetCompileMode('OBJFPC',true);
  2494. 'a' :
  2495. If UnsetBool(More, j, opt, false) then
  2496. exclude(init_settings.localswitches,cs_do_assertion)
  2497. else
  2498. include(init_settings.localswitches,cs_do_assertion);
  2499. 'c' :
  2500. If UnsetBool(More, j, opt, false) then
  2501. exclude(init_settings.moduleswitches,cs_support_c_operators)
  2502. else
  2503. include(init_settings.moduleswitches,cs_support_c_operators);
  2504. 'C':
  2505. If UnsetBool(More, j, opt, false) then
  2506. exclude(init_settings.localswitches,cs_check_all_case_coverage)
  2507. else
  2508. include(init_settings.localswitches,cs_check_all_case_coverage);
  2509. 'd' : //an alternative to -Mdelphi
  2510. SetCompileMode('DELPHI',true);
  2511. 'e' :
  2512. begin
  2513. SetErrorFlags(copy(more,j+1,length(more)));
  2514. break;
  2515. end;
  2516. 'f' :
  2517. begin
  2518. if not(cs_compilesystem in init_settings.moduleswitches) then
  2519. Message(option_features_only_for_system_unit);
  2520. inc(j);
  2521. if more[j]='-' then
  2522. begin
  2523. if length(more)>j then
  2524. IllegalPara(opt)
  2525. else
  2526. features:=[];
  2527. end
  2528. else
  2529. begin
  2530. if (HandleFeature(upper(copy(more,j,length(more)-j+1)))) then
  2531. j:=length(more)
  2532. else
  2533. IllegalPara(opt);
  2534. end;
  2535. end;
  2536. 'g' :
  2537. If UnsetBool(More, j, opt, false) then
  2538. exclude(init_settings.moduleswitches,cs_support_goto)
  2539. else
  2540. include(init_settings.moduleswitches,cs_support_goto);
  2541. 'h' :
  2542. If UnsetBool(More, j, opt, false) then
  2543. exclude(init_settings.localswitches,cs_refcountedstrings)
  2544. else
  2545. include(init_settings.localswitches,cs_refcountedstrings);
  2546. 'i' :
  2547. If UnsetBool(More, j, opt, false) then
  2548. exclude(init_settings.localswitches,cs_do_inline)
  2549. else
  2550. include(init_settings.localswitches,cs_do_inline);
  2551. 'j' :
  2552. If UnsetBool(More, j, opt, false) then
  2553. exclude(init_settings.localswitches,cs_typed_const_writable)
  2554. else
  2555. include(init_settings.localswitches,cs_typed_const_writable);
  2556. 'k' :
  2557. If UnsetBool(More, j, opt, false) then
  2558. exclude(init_settings.globalswitches,cs_load_fpcylix_unit)
  2559. else
  2560. include(init_settings.globalswitches,cs_load_fpcylix_unit);
  2561. 'm' :
  2562. If UnsetBool(More, j, opt, false) then
  2563. exclude(init_settings.moduleswitches,cs_support_macro)
  2564. else
  2565. include(init_settings.moduleswitches,cs_support_macro);
  2566. 'o' : //an alternative to -Mtp
  2567. SetCompileMode('TP',true);
  2568. 'r' :
  2569. If UnsetBool(More, j, opt, false) then
  2570. exclude(init_settings.globalswitches,cs_transparent_file_names)
  2571. else
  2572. include(init_settings.globalswitches,cs_transparent_file_names);
  2573. {$ifdef gpc_mode}
  2574. 'p' : //an alternative to -Mgpc
  2575. SetCompileMode('GPC',true);
  2576. {$endif}
  2577. 's' :
  2578. If UnsetBool(More, j, opt, false) then
  2579. exclude(init_settings.globalswitches,cs_constructor_name)
  2580. else
  2581. include(init_settings.globalswitches,cs_constructor_name);
  2582. 't' :
  2583. Message1(option_obsolete_switch,'-St');
  2584. 'v' :
  2585. If UnsetBool(More, j, opt, false) then
  2586. exclude(init_settings.globalswitches,cs_support_vectors)
  2587. else
  2588. include(init_settings.globalswitches,cs_support_vectors);
  2589. 'x' :
  2590. If UnsetBool(More, j, opt, false) then
  2591. SetCompileModeSwitch('EXCEPTIONS-',true)
  2592. else
  2593. SetCompileModeSwitch('EXCEPTIONS',true);
  2594. 'y' :
  2595. If UnsetBool(More, j, opt, false) then
  2596. exclude(init_settings.localswitches,cs_typed_addresses)
  2597. else
  2598. include(init_settings.localswitches,cs_typed_addresses);
  2599. '-' :
  2600. begin
  2601. init_settings.globalswitches:=init_settings.globalswitches - [cs_constructor_name,cs_support_exceptions,
  2602. cs_support_vectors,cs_load_fpcylix_unit];
  2603. init_settings.localswitches:=init_settings.localswitches - [cs_do_assertion,cs_do_inline, cs_refcountedstrings,
  2604. cs_typed_addresses];
  2605. init_settings.moduleswitches:=init_settings.moduleswitches - [cs_support_c_operators, cs_support_goto,
  2606. cs_support_macro];
  2607. end;
  2608. else
  2609. IllegalPara(opt);
  2610. end;
  2611. inc(j);
  2612. end;
  2613. end;
  2614. end;
  2615. 'T' :
  2616. begin
  2617. more:=Upper(More);
  2618. if paratarget=system_none then
  2619. begin
  2620. { remove old target define }
  2621. TargetOptions(false);
  2622. { load new target }
  2623. paratarget:=find_system_by_string(More);
  2624. if paratarget<>system_none then
  2625. set_target(paratarget)
  2626. else
  2627. IllegalPara(opt);
  2628. { set new define }
  2629. TargetOptions(true);
  2630. end
  2631. else
  2632. if More<>upper(target_info.shortname) then
  2633. Message1(option_target_is_already_set,target_info.shortname);
  2634. end;
  2635. 't' :
  2636. begin
  2637. more:=Upper(More);
  2638. if (more='') then
  2639. Message1(option_missing_arg,'-t')
  2640. else
  2641. begin
  2642. if (self.parasubtarget<>'') and (More<>upper(self.parasubtarget)) then
  2643. Message1(option_subtarget_is_already_set,self.parasubtarget)
  2644. else
  2645. self.parasubtarget:=more;
  2646. end;
  2647. end;
  2648. 'u' :
  2649. if is_identifier(more) then
  2650. undef_system_macro(more)
  2651. else
  2652. begin
  2653. if (more='') then
  2654. Message1(option_missing_arg,'-u')
  2655. else
  2656. Message1(option_malformed_para,opt);
  2657. StopOptions(1);
  2658. end;
  2659. 'U' :
  2660. begin
  2661. j:=1;
  2662. while j<=length(more) do
  2663. begin
  2664. case more[j] of
  2665. {$ifdef UNITALIASES}
  2666. 'a' :
  2667. begin
  2668. AddUnitAlias(Copy(More,j+1,255));
  2669. break;
  2670. end;
  2671. {$endif UNITALIASES}
  2672. 'n' :
  2673. exclude(init_settings.globalswitches,cs_check_unit_name);
  2674. 'p' :
  2675. begin
  2676. Message2(option_obsolete_switch_use_new,'-Up','-Fu');
  2677. break;
  2678. end;
  2679. 'r' :
  2680. begin
  2681. do_release:=true;
  2682. if (cs_checkpointer in init_settings.localswitches) then
  2683. begin
  2684. Message(option_gc_incompatible_with_release_flag);
  2685. exclude(init_settings.localswitches,cs_checkpointer);
  2686. end;
  2687. end;
  2688. 's' :
  2689. include(init_settings.moduleswitches,cs_compilesystem);
  2690. '-' :
  2691. begin
  2692. exclude(init_settings.moduleswitches,cs_compilesystem);
  2693. exclude(init_settings.globalswitches,cs_check_unit_name);
  2694. end;
  2695. else
  2696. IllegalPara(opt);
  2697. end;
  2698. inc(j);
  2699. end;
  2700. end;
  2701. 'v' :
  2702. begin
  2703. if not setverbosity(More) then
  2704. IllegalPara(opt);
  2705. end;
  2706. 'V' : ; { Ignore used by fpc }
  2707. 'W' :
  2708. begin
  2709. j:=1;
  2710. while j<=length(More) do
  2711. begin
  2712. case More[j] of
  2713. 'A':
  2714. begin
  2715. if target_info.system in systems_all_windows then
  2716. begin
  2717. if UnsetBool(More, j, opt, false) then
  2718. SetApptype(app_cui)
  2719. else
  2720. SetApptype(app_native);
  2721. end
  2722. else
  2723. IllegalPara(opt);
  2724. end;
  2725. 'b':
  2726. begin
  2727. if target_info.system in systems_darwin then
  2728. begin
  2729. if UnsetBool(More, j, opt, false) then
  2730. SetApptype(app_cui)
  2731. else
  2732. SetApptype(app_bundle)
  2733. end
  2734. else
  2735. IllegalPara(opt);
  2736. end;
  2737. 'B':
  2738. begin
  2739. if target_info.system in systems_all_windows+systems_symbian+[system_z80_zxspectrum] then
  2740. begin
  2741. { -WB200000 means set trefered base address
  2742. to $200000, but does not change relocsection boolean
  2743. this way we can create both relocatble and
  2744. non relocatable DLL at a specific base address PM }
  2745. if (length(More)>j) then
  2746. begin
  2747. val('$'+Copy(More,j+1,255),imagebase,code);
  2748. if code<>0 then
  2749. IllegalPara(opt);
  2750. ImageBaseSetExplicity:=true;
  2751. end
  2752. else
  2753. begin
  2754. RelocSection:=true;
  2755. RelocSectionSetExplicitly:=true;
  2756. end;
  2757. break;
  2758. end
  2759. else
  2760. IllegalPara(opt);
  2761. end;
  2762. 'C':
  2763. begin
  2764. if target_info.system in systems_all_windows+systems_os2+systems_macos then
  2765. begin
  2766. if UnsetBool(More, j, opt, false) then
  2767. SetApptype(app_gui)
  2768. else
  2769. SetApptype(app_cui);
  2770. end
  2771. else
  2772. IllegalPara(opt);
  2773. end;
  2774. 'D':
  2775. begin
  2776. if target_info.system in systems_all_windows then
  2777. begin
  2778. UseDeffileForExports:=not UnsetBool(More, j, opt, false);
  2779. UseDeffileForExportsSetExplicitly:=true;
  2780. end
  2781. else
  2782. IllegalPara(opt);
  2783. end;
  2784. 'e':
  2785. begin
  2786. if (target_info.system in systems_darwin) then
  2787. begin
  2788. set_target_res(res_ext);
  2789. target_info.resobjext:='.fpcres';
  2790. end
  2791. else
  2792. IllegalPara(opt);
  2793. end;
  2794. 'F':
  2795. begin
  2796. {$if defined(m68k)}
  2797. if target_info.system in [system_m68k_atari] then
  2798. begin
  2799. if (length(More)>j) then
  2800. begin
  2801. val(Copy(More,j+1,255),ataritos_exe_flags,code);
  2802. if code<>0 then
  2803. IllegalPara(opt);
  2804. end
  2805. else
  2806. IllegalPara(opt);
  2807. break;
  2808. end;
  2809. {$endif defined(m68k)}
  2810. if target_info.system in systems_os2 then
  2811. begin
  2812. if UnsetBool(More, j, opt, false) then
  2813. SetApptype(app_cui)
  2814. else
  2815. SetApptype(app_fs);
  2816. end
  2817. else
  2818. IllegalPara(opt);
  2819. end;
  2820. 'G':
  2821. begin
  2822. if target_info.system in systems_all_windows+systems_os2+systems_macos then
  2823. begin
  2824. if UnsetBool(More, j, opt, false) then
  2825. SetApptype(app_cui)
  2826. else
  2827. SetApptype(app_gui);
  2828. end
  2829. else
  2830. IllegalPara(opt);
  2831. end;
  2832. {$if defined(i8086)}
  2833. 'h':
  2834. begin
  2835. if UnsetBool(More, j, opt, false) then
  2836. exclude(init_settings.moduleswitches,cs_huge_code)
  2837. else
  2838. include(init_settings.moduleswitches,cs_huge_code);
  2839. end;
  2840. {$endif defined(i8086)}
  2841. 'I':
  2842. begin
  2843. if target_info.system in systems_all_windows then
  2844. begin
  2845. GenerateImportSection:=not UnsetBool(More,j,opt,false);
  2846. GenerateImportSectionSetExplicitly:=true;
  2847. end
  2848. else
  2849. IllegalPara(opt);
  2850. end;
  2851. 'i':
  2852. begin
  2853. if (target_info.system in systems_darwin) then
  2854. begin
  2855. set_target_res(res_macho);
  2856. target_info.resobjext:=
  2857. targetinfos[target_info.system]^.resobjext;
  2858. end
  2859. else
  2860. IllegalPara(opt);
  2861. end;
  2862. 'm':
  2863. begin
  2864. {$if defined(i8086)}
  2865. if (target_info.system in [system_i8086_msdos,system_i8086_win16,system_i8086_embedded]) then
  2866. begin
  2867. case Upper(Copy(More,j+1,255)) of
  2868. 'TINY': init_settings.x86memorymodel:=mm_tiny;
  2869. 'SMALL': init_settings.x86memorymodel:=mm_small;
  2870. 'MEDIUM': init_settings.x86memorymodel:=mm_medium;
  2871. 'COMPACT': init_settings.x86memorymodel:=mm_compact;
  2872. 'LARGE': init_settings.x86memorymodel:=mm_large;
  2873. 'HUGE': init_settings.x86memorymodel:=mm_huge;
  2874. else
  2875. IllegalPara(opt);
  2876. end;
  2877. break;
  2878. end
  2879. else
  2880. {$endif defined(i8086)}
  2881. IllegalPara(opt);
  2882. end;
  2883. 'M':
  2884. begin
  2885. if (target_info.system in (systems_darwin-[system_i386_iphonesim,system_arm_ios,system_aarch64_ios,system_x86_64_iphonesim])) and
  2886. ParseMacVersionMin(MacOSXVersionMin,iPhoneOSVersionMin,'MAC_OS_X_VERSION_MIN_REQUIRED',copy(More,2,255),false) then
  2887. begin
  2888. break;
  2889. end
  2890. else
  2891. IllegalPara(opt);
  2892. end;
  2893. 'N':
  2894. begin
  2895. if target_info.system in systems_all_windows then
  2896. begin
  2897. RelocSection:=UnsetBool(More,j,opt,false);
  2898. RelocSectionSetExplicitly:=true;
  2899. end
  2900. else
  2901. IllegalPara(opt);
  2902. end;
  2903. 'p':
  2904. begin
  2905. {$push}
  2906. {$warn 6018 off} { Unreachable code due to compile time evaluation }
  2907. if ((target_info.system in systems_embedded) or (target_info.system in systems_freertos)) and
  2908. ControllerSupport then
  2909. begin
  2910. s:=upper(copy(more,j+1,length(more)-j));
  2911. if not(SetControllerType(s,init_settings.controllertype)) then
  2912. IllegalPara(opt)
  2913. else
  2914. begin
  2915. if init_settings.cputype<>embedded_controllers[init_settings.controllertype].cputype then
  2916. begin
  2917. Message(scan_n_changecputype);
  2918. init_settings.cputype:=embedded_controllers[init_settings.controllertype].cputype;
  2919. end;
  2920. end;
  2921. break;
  2922. end
  2923. else
  2924. IllegalPara(opt);
  2925. {$pop}
  2926. end;
  2927. 'P':
  2928. begin
  2929. if (target_info.system in [system_i386_iphonesim,system_arm_ios,system_aarch64_ios,system_x86_64_iphonesim]) and
  2930. ParseMacVersionMin(iPhoneOSVersionMin,MacOSXVersionMin,'IPHONE_OS_VERSION_MIN_REQUIRED',copy(More,2,255),true) then
  2931. begin
  2932. break;
  2933. end
  2934. {$ifdef XTENSA}
  2935. else if (target_info.system in [system_xtensa_freertos]) and
  2936. ParseVersionStr(idf_version,'IDF_VERSION',copy(More,2,255)) then
  2937. begin
  2938. break;
  2939. end
  2940. {$endif XTENSA}
  2941. else
  2942. IllegalPara(opt);
  2943. end;
  2944. {$if defined(m68k)}
  2945. 'L':
  2946. begin
  2947. if (target_info.system in [system_m68k_sinclairql]) then
  2948. sinclairql_vlink_experimental:=false
  2949. else
  2950. IllegalPara(opt);
  2951. end;
  2952. 'Q':
  2953. begin
  2954. if (target_info.system in [system_m68k_sinclairql]) then
  2955. begin
  2956. sinclairql_metadata_format:=Upper(Copy(More,j+1,255));
  2957. case sinclairql_metadata_format of
  2958. 'QHDR', 'XTCC': ; { allowed formats }
  2959. else
  2960. IllegalPara(opt);
  2961. end;
  2962. break;
  2963. end
  2964. else
  2965. IllegalPara(opt);
  2966. end;
  2967. {$endif defined(m68k)}
  2968. 'R':
  2969. begin
  2970. if target_info.system in systems_all_windows then
  2971. begin
  2972. { support -WR+ / -WR- as synonyms to -WR / -WN }
  2973. RelocSection:=not UnsetBool(More,j,opt,false);
  2974. RelocSectionSetExplicitly:=true;
  2975. end
  2976. else
  2977. IllegalPara(opt);
  2978. end;
  2979. 't':
  2980. begin
  2981. {$if defined(i8086)}
  2982. if (target_info.system in [system_i8086_msdos,system_i8086_embedded]) then
  2983. begin
  2984. case Upper(Copy(More,j+1,255)) of
  2985. 'EXE': SetAppType(app_cui);
  2986. 'COM': SetAppType(app_com);
  2987. else
  2988. IllegalPara(opt);
  2989. end;
  2990. break;
  2991. end
  2992. else
  2993. {$endif defined(i8086)}
  2994. {$if defined(m68k)}
  2995. if (target_info.system in [system_m68k_atari]) then
  2996. begin
  2997. case Upper(Copy(More,j+1,255)) of
  2998. 'TOS': ataritos_exe_format := 'ataritos';
  2999. 'MINT': ataritos_exe_format := 'aoutmint';
  3000. else
  3001. IllegalPara(opt);
  3002. end;
  3003. break;
  3004. end
  3005. else
  3006. {$endif defined(m68k)}
  3007. IllegalPara(opt);
  3008. end;
  3009. 'T':
  3010. begin
  3011. if target_info.system in systems_macos then
  3012. begin
  3013. if UnsetBool(More, j, opt, false) then
  3014. SetApptype(app_cui)
  3015. else
  3016. SetApptype(app_tool);
  3017. end
  3018. else
  3019. IllegalPara(opt);
  3020. end;
  3021. 'X':
  3022. begin
  3023. if (target_info.system in systems_linux) then
  3024. begin
  3025. if UnsetBool(More, j, opt, false) then
  3026. exclude(init_settings.moduleswitches,cs_executable_stack)
  3027. else
  3028. include(init_settings.moduleswitches,cs_executable_stack)
  3029. end
  3030. else
  3031. IllegalPara(opt);
  3032. end;
  3033. else
  3034. IllegalPara(opt);
  3035. end;
  3036. inc(j);
  3037. end;
  3038. end;
  3039. 'x' :
  3040. message1(option_x_ignored,more);
  3041. 'X' :
  3042. begin
  3043. j:=1;
  3044. while j<=length(more) do
  3045. begin
  3046. case More[j] of
  3047. '9' :
  3048. begin
  3049. if target_info.system in systems_linux then
  3050. begin
  3051. if UnsetBool(More, j, opt, false) then
  3052. exclude(init_settings.globalswitches,cs_link_pre_binutils_2_19)
  3053. else
  3054. include(init_settings.globalswitches,cs_link_pre_binutils_2_19);
  3055. end
  3056. else
  3057. IllegalPara(opt);
  3058. end;
  3059. 'a' :
  3060. begin
  3061. If UnsetBool(More, j, opt, false) then
  3062. exclude(init_settings.globalswitches,cs_large)
  3063. else
  3064. include(init_settings.globalswitches,cs_large);
  3065. end;
  3066. 'c' : Cshared:=TRUE;
  3067. 'd' : Dontlinkstdlibpath:=TRUE;
  3068. 'e' :
  3069. begin
  3070. If UnsetBool(More, j, opt, false) then
  3071. exclude(init_settings.globalswitches,cs_link_extern)
  3072. else
  3073. include(init_settings.globalswitches,cs_link_extern);
  3074. end;
  3075. 'f' :
  3076. include(init_settings.globalswitches,cs_link_pthread);
  3077. 'g' :
  3078. begin
  3079. If UnsetBool(More, j, opt, false) then
  3080. exclude(init_settings.globalswitches,cs_link_separate_dbg_file)
  3081. else
  3082. include(init_settings.globalswitches,cs_link_separate_dbg_file);
  3083. end;
  3084. 'i' :
  3085. begin
  3086. If UnsetBool(More, j, opt, false) then
  3087. include(init_settings.globalswitches,cs_link_extern)
  3088. else
  3089. exclude(init_settings.globalswitches,cs_link_extern);
  3090. end;
  3091. 'n' :
  3092. begin
  3093. If UnsetBool(More, j, opt, false) then
  3094. exclude(init_settings.globalswitches,cs_link_native)
  3095. else
  3096. include(init_settings.globalswitches,cs_link_native);
  3097. end;
  3098. {$ifdef llvm}
  3099. 'l' :
  3100. begin
  3101. if j=length(more) then
  3102. IllegalPara(opt)
  3103. else
  3104. begin
  3105. case more[j+1] of
  3106. 'S':
  3107. begin
  3108. llvmutilssuffix:=copy(more,j+2,length(more));
  3109. j:=length(more);
  3110. end
  3111. else
  3112. IllegalPara(opt);
  3113. end;
  3114. end;
  3115. end;
  3116. {$endif}
  3117. 'm' :
  3118. begin
  3119. If UnsetBool(More, j, opt, false) then
  3120. exclude(init_settings.globalswitches,cs_link_map)
  3121. else
  3122. include(init_settings.globalswitches,cs_link_map);
  3123. end;
  3124. 'p' : ; { Ignore used by fpc.pp }
  3125. 'r' :
  3126. begin
  3127. if (target_info.system in suppported_targets_x_smallr) then
  3128. begin
  3129. rlinkpath:=Copy(more,2,length(More)-1);
  3130. DefaultReplacements(rlinkpath);
  3131. end
  3132. else
  3133. IgnoredPara('-Xr');
  3134. more:='';
  3135. end;
  3136. 'R' :
  3137. begin
  3138. sysrootpath:=copy(more,2,length(more)-1);
  3139. defaultreplacements(sysrootpath);
  3140. more:='';
  3141. end;
  3142. 's' :
  3143. begin
  3144. If UnsetBool(More, j, opt, false) then
  3145. exclude(init_settings.globalswitches,cs_link_strip)
  3146. else
  3147. include(init_settings.globalswitches,cs_link_strip);
  3148. end;
  3149. 't' :
  3150. include(init_settings.globalswitches,cs_link_staticflag);
  3151. 'u' :
  3152. begin
  3153. if target_info.system in systems_support_uf2 then
  3154. begin
  3155. if UnsetBool(More, j, opt, false) then
  3156. exclude(init_settings.globalswitches,cs_generate_uf2)
  3157. else
  3158. include(init_settings.globalswitches,cs_generate_uf2);
  3159. end
  3160. else
  3161. IgnoredPara('-Xu');
  3162. end;
  3163. 'v' :
  3164. begin
  3165. If UnsetBool(More, j, opt, false) then
  3166. exclude(init_settings.globalswitches,cs_link_opt_vtable)
  3167. else
  3168. include(init_settings.globalswitches,cs_link_opt_vtable);
  3169. end;
  3170. 'D' :
  3171. begin
  3172. def_system_macro('FPC_LINK_DYNAMIC');
  3173. undef_system_macro('FPC_LINK_SMART');
  3174. undef_system_macro('FPC_LINK_STATIC');
  3175. exclude(init_settings.globalswitches,cs_link_static);
  3176. exclude(init_settings.globalswitches,cs_link_smart);
  3177. include(init_settings.globalswitches,cs_link_shared);
  3178. LinkTypeSetExplicitly:=true;
  3179. end;
  3180. 'M' :
  3181. begin
  3182. mainaliasname:=Copy(more,2,length(More)-1);
  3183. More:='';
  3184. end;
  3185. 'P' :
  3186. begin
  3187. utilsprefix:=Copy(more,2,length(More)-1);
  3188. DefaultReplacements(utilsprefix);
  3189. More:='';
  3190. end;
  3191. 'L' : begin // -XLO is link order -XLA is link alias. -XLD avoids load defaults.
  3192. // these are not aggregable.
  3193. if (j=length(more)) or not (more[j+1] in ['O','A','D']) then
  3194. IllegalPara(opt)
  3195. else
  3196. begin
  3197. case more[j+1] of
  3198. 'A' : begin
  3199. s:=Copy(more,3,length(More)-2);
  3200. if not LinkLibraryAliases.AddDep(s) Then
  3201. IllegalPara(opt);
  3202. end;
  3203. 'O' : begin
  3204. s:=Copy(more,3,length(More)-2);
  3205. if not LinkLibraryOrder.AddWeight(s) Then
  3206. IllegalPara(opt);
  3207. end;
  3208. 'D' : include(init_settings.globalswitches,cs_link_no_default_lib_order)
  3209. else
  3210. IllegalPara(opt);
  3211. end; {case}
  3212. j:=length(more);
  3213. end; {else begin}
  3214. end;
  3215. 'S' :
  3216. begin
  3217. ForceStaticLinking;
  3218. end;
  3219. 'V' :
  3220. begin
  3221. if UnsetBool(More, j, opt, false) then
  3222. exclude(init_settings.globalswitches,cs_link_vlink)
  3223. else
  3224. begin
  3225. include(init_settings.globalswitches,cs_link_vlink);
  3226. include(init_settings.globalswitches,cs_link_extern);
  3227. end;
  3228. LinkerSetExplicitly:=true;
  3229. end;
  3230. 'X' :
  3231. begin
  3232. def_system_macro('FPC_LINK_SMART');
  3233. undef_system_macro('FPC_LINK_STATIC');
  3234. undef_system_macro('FPC_LINK_DYNAMIC');
  3235. exclude(init_settings.globalswitches,cs_link_static);
  3236. include(init_settings.globalswitches,cs_link_smart);
  3237. exclude(init_settings.globalswitches,cs_link_shared);
  3238. LinkTypeSetExplicitly:=true;
  3239. end;
  3240. '-' :
  3241. begin
  3242. exclude(init_settings.globalswitches,cs_link_staticflag);
  3243. exclude(init_settings.globalswitches,cs_link_strip);
  3244. exclude(init_settings.globalswitches,cs_link_map);
  3245. set_default_link_type;
  3246. end;
  3247. else
  3248. IllegalPara(opt);
  3249. end;
  3250. inc(j);
  3251. end;
  3252. end;
  3253. else
  3254. IllegalPara(opt);
  3255. end;
  3256. end;
  3257. '@' :
  3258. begin
  3259. Message(option_no_nested_response_file);
  3260. StopOptions(1);
  3261. end;
  3262. else
  3263. begin
  3264. if (length(param_file)<>0) then
  3265. Message2(option_only_one_source_support,param_file,opt);
  3266. param_file:=opt;
  3267. Message1(option_found_file,opt);
  3268. end;
  3269. end;
  3270. end;
  3271. procedure Toption.Interpret_file(const filename : TPathStr);
  3272. procedure RemoveSep(var fn:TPathStr);
  3273. var
  3274. i : longint;
  3275. begin
  3276. i:=0;
  3277. while (i<length(fn)) and (fn[i+1] in [',',' ',#9]) do
  3278. inc(i);
  3279. Delete(fn,1,i);
  3280. i:=length(fn);
  3281. while (i>0) and (fn[i] in [',',' ',#9]) do
  3282. dec(i);
  3283. fn:=copy(fn,1,i);
  3284. end;
  3285. function GetName(var fn:TPathStr):TPathStr;
  3286. var
  3287. i : longint;
  3288. begin
  3289. i:=0;
  3290. while (i<length(fn)) and (fn[i+1] in ['a'..'z','A'..'Z','0'..'9','_','-']) do
  3291. inc(i);
  3292. GetName:=Copy(fn,1,i);
  3293. Delete(fn,1,i);
  3294. end;
  3295. const
  3296. maxlevel = 15;
  3297. var
  3298. f : text;
  3299. s, tmp,
  3300. opts : TCmdStr;
  3301. skip : array[0..maxlevel] of boolean;
  3302. line,
  3303. level : longint;
  3304. option_read : boolean;
  3305. oldfilemode : byte;
  3306. ConfigFile: TPathStr;
  3307. begin
  3308. { avoid infinite loop }
  3309. Inc(FileLevel);
  3310. Option_read:=false;
  3311. If FileLevel>MaxLevel then
  3312. Message(option_too_many_cfg_files);
  3313. if not ParaIncludeCfgPath.FindFile(fileName,true,ConfigFile) then
  3314. ConfigFile := ExpandFileName(filename);
  3315. { Maybe It's Directory ?} //Jaro Change:
  3316. if PathExists(ConfigFile,false) then
  3317. begin
  3318. Message1(option_config_is_dir,filename);
  3319. exit;
  3320. end;
  3321. { open file }
  3322. Message1(option_using_file,filename);
  3323. oldfilemode:=filemode;
  3324. filemode:=0;
  3325. assign(f,ConfigFile);
  3326. {$push}{$I-}
  3327. reset(f);
  3328. {$pop}
  3329. filemode:=oldfilemode;
  3330. if ioresult<>0 then
  3331. begin
  3332. Message1(option_unable_open_file,filename);
  3333. exit;
  3334. end;
  3335. Message1(option_start_reading_configfile,filename);
  3336. fillchar(skip,sizeof(skip),0);
  3337. level:=0;
  3338. line:=0;
  3339. while not eof(f) do
  3340. begin
  3341. readln(f,opts);
  3342. inc(line);
  3343. RemoveSep(opts);
  3344. if (opts<>'') and (opts[1]<>';') then
  3345. begin
  3346. if opts[1]='#' then
  3347. begin
  3348. Message1(option_interpreting_file_option,opts);
  3349. Delete(opts,1,1);
  3350. s:=upper(GetName(opts));
  3351. if (s='SECTION') then
  3352. begin
  3353. RemoveSep(opts);
  3354. s:=upper(GetName(opts));
  3355. if level=0 then
  3356. skip[level]:=not defined_macro(s) or (s='COMMON');
  3357. end
  3358. else
  3359. if (s='IFDEF') then
  3360. begin
  3361. RemoveSep(opts);
  3362. if Level>=maxlevel then
  3363. begin
  3364. Message2(option_too_many_ifdef,filename,tostr(line));
  3365. stopOptions(1);
  3366. end;
  3367. inc(Level);
  3368. skip[level]:=(skip[level-1] or not defined_macro(upper(GetName(opts))));
  3369. end
  3370. else
  3371. if (s='IFNDEF') then
  3372. begin
  3373. RemoveSep(opts);
  3374. if Level>=maxlevel then
  3375. begin
  3376. Message2(option_too_many_ifdef,filename,tostr(line));
  3377. stopOptions(1);
  3378. end;
  3379. inc(Level);
  3380. skip[level]:=(skip[level-1] or defined_macro(upper(GetName(opts))));
  3381. end
  3382. else
  3383. if (s='ELSE') then
  3384. begin
  3385. if Level=0 then
  3386. begin
  3387. Message2(option_else_without_if,filename,tostr(line));
  3388. stopOptions(1);
  3389. end
  3390. else
  3391. skip[level]:=skip[level-1] or (not skip[level])
  3392. end
  3393. else
  3394. if (s='ENDIF') then
  3395. begin
  3396. skip[level]:=false;
  3397. if Level=0 then
  3398. begin
  3399. Message2(option_too_many_endif,filename,tostr(line));
  3400. stopOptions(1);
  3401. end;
  3402. dec(level);
  3403. end
  3404. else
  3405. if (not skip[level]) then
  3406. begin
  3407. if (s='DEFINE') then
  3408. begin
  3409. RemoveSep(opts);
  3410. tmp:= GetName(opts);
  3411. if tmp <> '' then
  3412. def_system_macro(tmp);
  3413. Option_read:=true;
  3414. end
  3415. else
  3416. if (s='UNDEF') then
  3417. begin
  3418. RemoveSep(opts);
  3419. tmp:= GetName(opts);
  3420. if tmp <> '' then
  3421. undef_system_macro(tmp);
  3422. Option_read:=true;
  3423. end
  3424. else
  3425. if (s='WRITE') then
  3426. begin
  3427. Delete(opts,1,1);
  3428. DefaultReplacements(opts);
  3429. WriteLn(opts);
  3430. Option_read:=true;
  3431. end
  3432. else
  3433. if (s='INCLUDE') then
  3434. begin
  3435. Delete(opts,1,1);
  3436. DefaultReplacements(opts);
  3437. Interpret_file(opts);
  3438. Option_read:=true;
  3439. end
  3440. else
  3441. if (s='CFGDIR') then
  3442. begin
  3443. Delete(opts,1,1);
  3444. DefaultReplacements(opts);
  3445. ParaIncludeCfgPath.AddPath(opts,false);
  3446. Option_read:=true;
  3447. end;
  3448. end;
  3449. end
  3450. else
  3451. begin
  3452. if (opts[1]='-') or (opts[1]='@') then
  3453. begin
  3454. if (not skip[level]) then
  3455. interpret_option(opts,false);
  3456. Option_read:=true;
  3457. end
  3458. else
  3459. Message1(option_illegal_para,opts);
  3460. end;
  3461. end;
  3462. end;
  3463. if Level>0 then
  3464. Message(option_too_less_endif);
  3465. if Not Option_read then
  3466. Message1(option_no_option_found,filename)
  3467. else
  3468. Message1(option_end_reading_configfile,filename);
  3469. Close(f);
  3470. Dec(FileLevel);
  3471. end;
  3472. procedure Toption.Interpret_envvar(const envname : TCmdStr);
  3473. var
  3474. argstart,
  3475. env,
  3476. pc : pchar;
  3477. arglen : longint;
  3478. quote : set of char;
  3479. hs : TCmdStr;
  3480. begin
  3481. Message1(option_using_env,envname);
  3482. env:=GetEnvPChar(envname);
  3483. pc:=env;
  3484. hs:='';
  3485. if assigned(pc) then
  3486. begin
  3487. repeat
  3488. { skip leading spaces }
  3489. while pc^ in [' ',#9,#13] do
  3490. inc(pc);
  3491. case pc^ of
  3492. #0 :
  3493. break;
  3494. '"' :
  3495. begin
  3496. quote:=['"'];
  3497. inc(pc);
  3498. end;
  3499. '''' :
  3500. begin
  3501. quote:=[''''];
  3502. inc(pc);
  3503. end;
  3504. else
  3505. quote:=[' ',#9,#13];
  3506. end;
  3507. { scan until the end of the argument }
  3508. argstart:=pc;
  3509. while (pc^<>#0) and not(pc^ in quote) do
  3510. inc(pc);
  3511. { create argument }
  3512. arglen:=pc-argstart;
  3513. { TODO: FIXME: silent truncation of environment parameters }
  3514. if (arglen > 255) then
  3515. arglen := 255;
  3516. setlength(hs,arglen);
  3517. move(argstart^,hs[1],arglen);
  3518. interpret_option(hs,true);
  3519. { skip quote }
  3520. if pc^ in quote then
  3521. inc(pc);
  3522. until false;
  3523. end
  3524. else
  3525. Message1(option_no_option_found,'(env) '+envname);
  3526. FreeEnvPChar(env);
  3527. end;
  3528. procedure toption.read_parameters;
  3529. var
  3530. opts : TCmdStr;
  3531. paramindex : longint;
  3532. begin
  3533. paramindex:=0;
  3534. while paramindex<paramcount do
  3535. begin
  3536. inc(paramindex);
  3537. opts:=objpas.paramstr(paramindex);
  3538. if length(opts)>0 then
  3539. case opts[1] of
  3540. '@' :
  3541. if not firstpass then
  3542. begin
  3543. Delete(opts,1,1);
  3544. Message1(option_reading_further_from,opts);
  3545. interpret_file(opts);
  3546. end;
  3547. '!' :
  3548. if not firstpass then
  3549. begin
  3550. Delete(opts,1,1);
  3551. Message1(option_reading_further_from,'(env) '+opts);
  3552. interpret_envvar(opts);
  3553. end;
  3554. else
  3555. interpret_option(opts,true);
  3556. end;
  3557. end;
  3558. end;
  3559. procedure toption.parsecmd(cmd:TCmdStr);
  3560. var
  3561. i,ps : longint;
  3562. opts : TCmdStr;
  3563. begin
  3564. while (cmd<>'') do
  3565. begin
  3566. while cmd[1]=' ' do
  3567. delete(cmd,1,1);
  3568. i:=pos(' ',cmd);
  3569. if i=0 then
  3570. i:=2147483647;
  3571. opts:=Copy(cmd,1,i-1);
  3572. Delete(cmd,1,i);
  3573. case opts[1] of
  3574. '@' :
  3575. if not firstpass then
  3576. begin
  3577. Delete(opts,1,1);
  3578. Message1(option_reading_further_from,opts);
  3579. interpret_file(opts);
  3580. end;
  3581. '!' :
  3582. if not firstpass then
  3583. begin
  3584. Delete(opts,1,1);
  3585. Message1(option_reading_further_from,'(env) '+opts);
  3586. interpret_envvar(opts);
  3587. end;
  3588. '"' :
  3589. begin
  3590. Delete(opts,1,1);
  3591. ps:=pos('"',cmd);
  3592. if (i<>256) and (ps>0) then
  3593. begin
  3594. opts:=opts + ' '+ copy(cmd,1,ps-1);
  3595. cmd:=copy(cmd,ps+1,255);
  3596. end;
  3597. interpret_option(opts,true);
  3598. end;
  3599. else
  3600. interpret_option(opts,true);
  3601. end;
  3602. end;
  3603. end;
  3604. procedure toption.writequickinfo;
  3605. var
  3606. s : string;
  3607. i : longint;
  3608. emptyOK : Boolean;
  3609. procedure addinfo(const hs:string);
  3610. begin
  3611. if s<>'' then
  3612. s:=s+' '+hs
  3613. else
  3614. s:=hs;
  3615. end;
  3616. begin
  3617. emptyOK:=False;
  3618. s:='';
  3619. i:=0;
  3620. while (i<length(quickinfo)) do
  3621. begin
  3622. inc(i);
  3623. case quickinfo[i] of
  3624. 'S' :
  3625. begin
  3626. inc(i);
  3627. case quickinfo[i] of
  3628. 'O' :
  3629. addinfo(lower(source_info.shortname));
  3630. 'P' :
  3631. addinfo(source_cpu_string);
  3632. else
  3633. IllegalPara('-i'+QuickInfo);
  3634. end;
  3635. end;
  3636. 'T' :
  3637. begin
  3638. inc(i);
  3639. case quickinfo[i] of
  3640. 'O' :
  3641. addinfo(lower(target_info.shortname));
  3642. 'P' :
  3643. AddInfo(target_cpu_string);
  3644. 'T' :
  3645. begin
  3646. addinfo(lower(self.parasubtarget));
  3647. emptyOK:=True;
  3648. end
  3649. else
  3650. IllegalPara('-i'+QuickInfo);
  3651. end;
  3652. end;
  3653. 'V' :
  3654. AddInfo(version_string);
  3655. 'W' :
  3656. AddInfo(full_version_string);
  3657. 'D' :
  3658. AddInfo(date_string);
  3659. '_' :
  3660. ;
  3661. else
  3662. IllegalPara('-i'+QuickInfo);
  3663. end;
  3664. end;
  3665. if (s<>'') or EmptyOK then
  3666. begin
  3667. writeln(s);
  3668. stopoptions(0);
  3669. end;
  3670. end;
  3671. procedure TOption.TargetOptions(def:boolean);
  3672. var
  3673. s : string;
  3674. i : integer;
  3675. target_unsup_features : tfeatures;
  3676. begin
  3677. if def then
  3678. def_system_macro(target_info.shortname)
  3679. else
  3680. undef_system_macro(target_info.shortname);
  3681. s:=target_info.extradefines;
  3682. while (s<>'') do
  3683. begin
  3684. i:=pos(';',s);
  3685. if i=0 then
  3686. i:=length(s)+1;
  3687. if def then
  3688. def_system_macro(Copy(s,1,i-1))
  3689. else
  3690. undef_system_macro(Copy(s,1,i-1));
  3691. delete(s,1,i);
  3692. end;
  3693. if (tf_winlikewidestring in target_info.flags) then
  3694. if def then
  3695. def_system_macro('FPC_WINLIKEWIDESTRING')
  3696. else
  3697. undef_system_macro('FPC_WINLIKEWIDESTRING');
  3698. if (tf_requires_proper_alignment in target_info.flags) then
  3699. if def then
  3700. def_system_macro('FPC_REQUIRES_PROPER_ALIGNMENT')
  3701. else
  3702. undef_system_macro('FPC_REQUIRES_PROPER_ALIGNMENT');
  3703. if (tf_init_final_units_by_calls in target_info.flags) then
  3704. if def then
  3705. def_system_macro('FPC_INIT_FINAL_UNITS_BY_CALLS')
  3706. else
  3707. undef_system_macro('FPC_INIT_FINAL_UNITS_BY_CALLS');
  3708. if source_info.system<>target_info.system then
  3709. if def then
  3710. def_system_macro('FPC_CROSSCOMPILING')
  3711. else
  3712. undef_system_macro('FPC_CROSSCOMPILING');
  3713. if source_info.cpu<>target_info.cpu then
  3714. if def then
  3715. def_system_macro('FPC_CPUCROSSCOMPILING')
  3716. else
  3717. def_system_macro('FPC_CPUCROSSCOMPILING');
  3718. if (tf_no_generic_stackcheck in target_info.flags) then
  3719. if def then
  3720. def_system_macro('FPC_NO_GENERIC_STACK_CHECK')
  3721. else
  3722. undef_system_macro('FPC_NO_GENERIC_STACK_CHECK');
  3723. if (tf_section_threadvars in target_info.flags) then
  3724. if def then
  3725. def_system_macro('FPC_SECTION_THREADVARS')
  3726. else
  3727. undef_system_macro('FPC_SECTION_THREADVARS');
  3728. if (tf_use_psabieh in target_info.flags) then
  3729. if def then
  3730. def_system_macro('FPC_USE_PSABIEH')
  3731. else
  3732. undef_system_macro('FPC_USE_PSABIEH');
  3733. { Code generation flags }
  3734. if (tf_pic_default in target_info.flags) then
  3735. if def then
  3736. include(init_settings.moduleswitches,cs_create_pic)
  3737. else
  3738. exclude(init_settings.moduleswitches,cs_create_pic);
  3739. { Resources support }
  3740. if (tf_has_winlike_resources in target_info.flags) then
  3741. if def then
  3742. def_system_macro('FPC_HAS_WINLIKERESOURCES')
  3743. else
  3744. undef_system_macro('FPC_HAS_WINLIKERESOURCES');
  3745. { Features }
  3746. case target_info.system of
  3747. system_arm_gba:
  3748. target_unsup_features:=[f_dynlibs];
  3749. system_arm_nds:
  3750. target_unsup_features:=[f_threading,f_commandargs,f_fileio,f_textio,f_consoleio,f_dynlibs];
  3751. system_i386_nativent:
  3752. // until these features are implemented, they are disabled in the compiler
  3753. target_unsup_features:=[f_stackcheck];
  3754. system_i8086_msdos:
  3755. target_unsup_features:=[f_threading,f_dynlibs];
  3756. system_i8086_win16:
  3757. target_unsup_features:=[f_threading];
  3758. system_jvm_java32,
  3759. system_jvm_android32:
  3760. target_unsup_features:=[f_heap,f_textio,f_consoleio,f_fileio,
  3761. f_variants,f_objects,f_commandargs,
  3762. f_processes,f_stackcheck,f_dynlibs,f_softfpu,f_objectivec1,f_resources];
  3763. system_arm_palmos,
  3764. system_m68k_palmos:
  3765. target_unsup_features:=[f_threading];
  3766. system_m68k_atari:
  3767. target_unsup_features:=[f_threading];
  3768. { classic amiga has dynamic libraries, but they cannot be integrated in the
  3769. normal dynlibs infrastructure due to architectural differences, so therefore
  3770. lets disable the feature. }
  3771. system_m68k_amiga:
  3772. target_unsup_features:=[f_dynlibs];
  3773. system_m68k_sinclairql:
  3774. target_unsup_features:=[f_threading,f_dynlibs];
  3775. system_z80_zxspectrum:
  3776. target_unsup_features:=[f_threading,f_dynlibs{,f_fileio,f_textio},f_commandargs,f_exitcode];
  3777. system_z80_msxdos:
  3778. target_unsup_features:=[f_threading,f_dynlibs];
  3779. else
  3780. target_unsup_features:=[];
  3781. end;
  3782. if def then
  3783. features:=features-target_unsup_features
  3784. else
  3785. features:=features+target_unsup_features;
  3786. {$if defined(hasamiga)}
  3787. { enable vlink as default linker on Amiga but not for cross compilers (for now) }
  3788. if (target_info.system in [system_m68k_amiga,system_powerpc_amiga]) and
  3789. not LinkerSetExplicitly then
  3790. include(init_settings.globalswitches,cs_link_vlink);
  3791. {$endif}
  3792. {$ifdef m68k}
  3793. { always enable vlink as default linker for the Sinclair QL and Atari }
  3794. if (target_info.system in [system_m68k_sinclairql,system_m68k_atari]) and
  3795. not LinkerSetExplicitly then
  3796. include(init_settings.globalswitches,cs_link_vlink);
  3797. {$endif m68k}
  3798. end;
  3799. procedure TOption.checkoptionscompatibility;
  3800. begin
  3801. {$ifdef wasm}
  3802. if (Ord(ts_wasm_no_exceptions in init_settings.targetswitches)+
  3803. Ord(ts_wasm_js_exceptions in init_settings.targetswitches)+
  3804. Ord(ts_wasm_native_exceptions in init_settings.targetswitches)+
  3805. Ord(ts_wasm_bf_exceptions in init_settings.targetswitches))>1 then
  3806. begin
  3807. Message(option_too_many_exception_modes);
  3808. StopOptions(1);
  3809. end;
  3810. {$endif}
  3811. {$ifdef i8086}
  3812. if (apptype=app_com) and (init_settings.x86memorymodel<>mm_tiny) then
  3813. begin
  3814. Message(option_com_files_require_tiny_model);
  3815. StopOptions(1);
  3816. end;
  3817. {$endif i8086}
  3818. {$ifndef i8086_link_intern_debuginfo}
  3819. if (cs_debuginfo in init_settings.moduleswitches) and
  3820. (target_info.system in [system_i8086_msdos,system_i8086_win16,system_i8086_embedded]) and
  3821. not (cs_link_extern in init_settings.globalswitches) then
  3822. begin
  3823. Message(option_debug_info_requires_external_linker);
  3824. include(init_settings.globalswitches,cs_link_extern);
  3825. end;
  3826. {$endif i8086_link_intern_debuginfo}
  3827. if (paratargetdbg in [dbg_dwarf2,dbg_dwarf3,dbg_dwarf4]) and
  3828. not(target_info.system in (systems_darwin+[system_i8086_msdos,system_i8086_embedded])) then
  3829. begin
  3830. { smartlink creation does not yet work with DWARF
  3831. debug info on most targets, but it works in internal assembler }
  3832. if (cs_create_smart in init_settings.moduleswitches) and
  3833. not (af_outputbinary in target_asm.flags) then
  3834. begin
  3835. Message(option_dwarf_smartlink_creation);
  3836. exclude(init_settings.moduleswitches,cs_create_smart);
  3837. end;
  3838. { smart linking does not yet work with DWARF debug info on most targets }
  3839. if (cs_link_smart in init_settings.globalswitches) then
  3840. begin
  3841. Message(option_dwarf_smart_linking);
  3842. ForceStaticLinking;
  3843. end;
  3844. end;
  3845. { external debug info is only supported for DWARF on darwin }
  3846. if (target_info.system in systems_darwin) and
  3847. (cs_link_separate_dbg_file in init_settings.globalswitches) and
  3848. not(paratargetdbg in [dbg_dwarf2,dbg_dwarf3,dbg_dwarf4]) then
  3849. begin
  3850. Message(option_debug_external_unsupported);
  3851. exclude(init_settings.globalswitches,cs_link_separate_dbg_file);
  3852. end;
  3853. { Also create a smartlinked version, on an assembler that
  3854. does not support smartlink sections like nasm?
  3855. This is not compatible with using internal linker. }
  3856. if ((cs_link_smart in init_settings.globalswitches) or
  3857. (cs_create_smart in init_settings.moduleswitches)) and
  3858. (af_needar in target_asm.flags) and
  3859. not (af_smartlink_sections in target_asm.flags) and
  3860. not (cs_link_extern in init_settings.globalswitches) and
  3861. (target_info.link<>ld_none) and
  3862. not (cs_link_nolink in init_settings.globalswitches) then
  3863. begin
  3864. Message(option_smart_link_requires_external_linker);
  3865. include(init_settings.globalswitches,cs_link_extern);
  3866. end;
  3867. end;
  3868. constructor TOption.create;
  3869. begin
  3870. LogoWritten:=false;
  3871. NoPressEnter:=false;
  3872. FirstPass:=false;
  3873. ABISetExplicitly:=false;
  3874. FPUSetExplicitly:=false;
  3875. CPUSetExplicitly:=false;
  3876. OptCPUSetExplicitly:=false;
  3877. FileLevel:=0;
  3878. Quickinfo:='';
  3879. ParaIncludeCfgPath:=TSearchPathList.Create;
  3880. ParaIncludePath:=TSearchPathList.Create;
  3881. ParaObjectPath:=TSearchPathList.Create;
  3882. ParaUnitPath:=TSearchPathList.Create;
  3883. ParaLibraryPath:=TSearchPathList.Create;
  3884. ParaFrameworkPath:=TSearchPathList.Create;
  3885. parapackagepath:=TSearchPathList.Create;
  3886. parapackages:=TFPHashObjectList.Create;
  3887. paranamespaces:=TCmdStrList.Create;
  3888. FillChar(ParaAlignment,sizeof(ParaAlignment),0);
  3889. MacVersionSet:=false;
  3890. paratarget:=system_none;
  3891. paratargetasm:=as_none;
  3892. paratargetdbg:=dbg_none;
  3893. LinkTypeSetExplicitly:=false;
  3894. LinkerSetExplicitly:=false;
  3895. end;
  3896. destructor TOption.destroy;
  3897. begin
  3898. ParaIncludeCfgPath.Free;
  3899. ParaIncludePath.Free;
  3900. ParaObjectPath.Free;
  3901. ParaUnitPath.Free;
  3902. ParaLibraryPath.Free;
  3903. ParaFrameworkPath.Free;
  3904. parapackagepath.Free;
  3905. ParaPackages.Free;
  3906. paranamespaces.free;
  3907. end;
  3908. {****************************************************************************
  3909. Callable Routines
  3910. ****************************************************************************}
  3911. function check_configfile(fn:string; var foundfn:string):boolean;
  3912. function CfgFileExists(const fn:string):boolean;
  3913. begin
  3914. Comment(V_Tried,'Configfile search: '+fn);
  3915. CfgFileExists:=FileExists(fn);
  3916. end;
  3917. var
  3918. {$ifdef Unix}
  3919. hs,
  3920. {$endif Unix}
  3921. configpath : string;
  3922. begin
  3923. foundfn:=fn;
  3924. check_configfile:=true;
  3925. { retrieve configpath }
  3926. configpath:=FixPath(GetEnvironmentVariable('PPC_CONFIG_PATH'),false);
  3927. {$ifdef Unix}
  3928. if configpath='' then
  3929. configpath:=ExpandFileName(FixPath(exepath+'../etc/',false));
  3930. {$endif}
  3931. {
  3932. Order to read configuration file :
  3933. try reading fpc.cfg in :
  3934. 1 - current dir
  3935. 2 - configpath
  3936. 3 - compiler path
  3937. }
  3938. if not FileExists(fn) then
  3939. begin
  3940. {$ifdef Unix}
  3941. hs:=GetEnvironmentVariable('HOME');
  3942. if (hs<>'') and CfgFileExists(FixPath(hs,false)+'.'+fn) then
  3943. foundfn:=FixPath(hs,false)+'.'+fn
  3944. else
  3945. {$endif}
  3946. if CfgFileExists(configpath+fn) then
  3947. foundfn:=configpath+fn
  3948. else
  3949. {$ifdef WINDOWS}
  3950. if (GetEnvironmentVariable('USERPROFILE')<>'') and CfgFileExists(FixPath(GetEnvironmentVariable('USERPROFILE'),false)+fn) then
  3951. foundfn:=FixPath(GetEnvironmentVariable('USERPROFILE'),false)+fn
  3952. else
  3953. if (GetEnvironmentVariable('ALLUSERSPROFILE')<>'') and CfgFileExists(FixPath(GetEnvironmentVariable('ALLUSERSPROFILE'),false)+fn) then
  3954. foundfn:=FixPath(GetEnvironmentVariable('ALLUSERSPROFILE'),false)+fn
  3955. else
  3956. {$endif WINDOWS}
  3957. {$ifndef Unix}
  3958. if CfgFileExists(exepath+fn) then
  3959. foundfn:=exepath+fn
  3960. else
  3961. {$else}
  3962. if CfgFileExists('/etc/'+fn) then
  3963. foundfn:='/etc/'+fn
  3964. else
  3965. {$endif}
  3966. check_configfile:=false;
  3967. end;
  3968. end;
  3969. procedure read_arguments(cmd:TCmdStr);
  3970. procedure def_cpu_macros;
  3971. var
  3972. abi : tabi;
  3973. fputype : tfputype;
  3974. cputype : tcputype;
  3975. controller: tcontrollertype;
  3976. s: string;
  3977. begin
  3978. {$ifdef llvm}
  3979. def_system_macro('CPULLVM');
  3980. {$endif}
  3981. for cputype:=low(tcputype) to high(tcputype) do
  3982. undef_system_macro('CPU'+Cputypestr[cputype]);
  3983. def_system_macro('CPU'+Cputypestr[init_settings.cputype]);
  3984. for fputype:=low(tfputype) to high(tfputype) do
  3985. undef_system_macro('FPU'+fputypestr[fputype]);
  3986. def_system_macro('FPU'+fputypestr[init_settings.fputype]);
  3987. {$PUSH}
  3988. {$WARN 6018 OFF} { Unreachable code due to compile time evaluation }
  3989. if ControllerSupport then
  3990. begin
  3991. for controller:=low(tcontrollertype) to high(tcontrollertype) do
  3992. begin
  3993. s:=embedded_controllers[controller].controllertypestr;
  3994. if s<>'' then
  3995. undef_system_macro('FPC_MCU_'+s);
  3996. end;
  3997. s:=embedded_controllers[init_settings.controllertype].controllertypestr;
  3998. if s<>'' then
  3999. def_system_macro('FPC_MCU_'+s);
  4000. end;
  4001. {$POP}
  4002. { define abi }
  4003. for abi:=low(tabi) to high(tabi) do
  4004. undef_system_macro('FPC_ABI_'+abiinfo[abi].name);
  4005. def_system_macro('FPC_ABI_'+abiinfo[target_info.abi].name);
  4006. { Define FPC_ABI_EABI in addition to FPC_ABI_EABIHF on EABI VFP hardfloat
  4007. systems since most code needs to behave the same on both}
  4008. if target_info.abi = abi_eabihf then
  4009. def_system_macro('FPC_ABI_EABI');
  4010. { using a case is pretty useless here (FK) }
  4011. { some stuff for TP compatibility }
  4012. {$ifdef i386}
  4013. def_system_macro('CPU86');
  4014. def_system_macro('CPU87');
  4015. def_system_macro('CPU386');
  4016. {$endif}
  4017. { new processor stuff }
  4018. {$ifdef i386}
  4019. def_system_macro('CPUI386');
  4020. def_system_macro('CPU32');
  4021. def_system_macro('CPUX86');
  4022. def_system_macro('FPC_HAS_TYPE_EXTENDED');
  4023. def_system_macro('FPC_HAS_TYPE_DOUBLE');
  4024. def_system_macro('FPC_HAS_TYPE_SINGLE');
  4025. {$endif}
  4026. {$ifdef m68k}
  4027. def_system_macro('CPU68');
  4028. def_system_macro('CPU68K');
  4029. def_system_macro('CPUM68K');
  4030. def_system_macro('CPU32');
  4031. def_system_macro('FPC_CURRENCY_IS_INT64');
  4032. def_system_macro('FPC_COMP_IS_INT64');
  4033. {$endif}
  4034. {$ifdef powerpc}
  4035. def_system_macro('CPUPOWERPC');
  4036. def_system_macro('CPUPOWERPC32');
  4037. def_system_macro('CPU32');
  4038. def_system_macro('FPC_CURRENCY_IS_INT64');
  4039. def_system_macro('FPC_COMP_IS_INT64');
  4040. {$endif}
  4041. {$ifdef POWERPC64}
  4042. def_system_macro('CPUPOWERPC');
  4043. def_system_macro('CPUPOWERPC64');
  4044. def_system_macro('CPU64');
  4045. def_system_macro('FPC_CURRENCY_IS_INT64');
  4046. def_system_macro('FPC_COMP_IS_INT64');
  4047. {$endif}
  4048. {$ifdef x86_64}
  4049. def_system_macro('CPUX86_64');
  4050. def_system_macro('CPUAMD64');
  4051. def_system_macro('CPU64');
  4052. def_system_macro('CPUX64');
  4053. { not supported for now, afaik (FK)
  4054. def_system_macro('FPC_HAS_TYPE_FLOAT128'); }
  4055. {$ifndef FPC_SUPPORT_X87_TYPES_ON_WIN64}
  4056. { normally, win64 doesn't support the legacy fpu }
  4057. if target_info.system=system_x86_64_win64 then
  4058. begin
  4059. def_system_macro('FPC_CURRENCY_IS_INT64');
  4060. def_system_macro('FPC_COMP_IS_INT64');
  4061. end;
  4062. {$endif FPC_SUPPORT_X87_TYPES_ON_WIN64}
  4063. {$endif}
  4064. {$ifdef sparc}
  4065. def_system_macro('CPUSPARCGEN');
  4066. def_system_macro('CPUSPARC');
  4067. def_system_macro('CPUSPARC32');
  4068. def_system_macro('CPU32');
  4069. def_system_macro('FPC_CURRENCY_IS_INT64');
  4070. def_system_macro('FPC_COMP_IS_INT64');
  4071. {$endif}
  4072. {$ifdef sparc64}
  4073. def_system_macro('CPUSPARCGEN');
  4074. def_system_macro('CPUSPARC64');
  4075. def_system_macro('CPU64');
  4076. def_system_macro('FPC_CURRENCY_IS_INT64');
  4077. def_system_macro('FPC_COMP_IS_INT64');
  4078. {$endif}
  4079. {$ifdef arm}
  4080. def_system_macro('CPUARM');
  4081. def_system_macro('CPU32');
  4082. def_system_macro('FPC_CURRENCY_IS_INT64');
  4083. def_system_macro('FPC_COMP_IS_INT64');
  4084. {$endif arm}
  4085. {$ifdef avr}
  4086. def_system_macro('CPUAVR');
  4087. def_system_macro('CPU16');
  4088. def_system_macro('FPC_CURRENCY_IS_INT64');
  4089. def_system_macro('FPC_COMP_IS_INT64');
  4090. {$endif avr}
  4091. {$ifdef jvm}
  4092. def_system_macro('CPUJVM');
  4093. def_system_macro('CPU32');
  4094. def_system_macro('FPC_CURRENCY_IS_INT64');
  4095. def_system_macro('FPC_COMP_IS_INT64');
  4096. {$endif jvm}
  4097. {$ifdef mipsel}
  4098. def_system_macro('CPUMIPS');
  4099. def_system_macro('CPUMIPSEL');
  4100. def_system_macro('CPUMIPS32');
  4101. def_system_macro('CPUMIPSEL32');
  4102. def_system_macro('CPU32');
  4103. def_system_macro('FPC_HAS_TYPE_DOUBLE');
  4104. def_system_macro('FPC_HAS_TYPE_SINGLE');
  4105. def_system_macro('FPC_INCLUDE_SOFTWARE_INT64_TO_DOUBLE');
  4106. def_system_macro('FPC_CURRENCY_IS_INT64');
  4107. def_system_macro('FPC_COMP_IS_INT64');
  4108. def_system_macro('FPC_REQUIRES_PROPER_ALIGNMENT');
  4109. { On most systems, locals are accessed relative to base pointer,
  4110. but for MIPS cpu, they are accessed relative to stack pointer.
  4111. This needs adaptation for so low level routines,
  4112. like MethodPointerLocal and related objects unit functions. }
  4113. def_system_macro('FPC_LOCALS_ARE_STACK_REG_RELATIVE');
  4114. {$endif mipsel}
  4115. {$ifdef mipseb}
  4116. def_system_macro('CPUMIPS');
  4117. def_system_macro('CPUMIPSEB');
  4118. def_system_macro('CPUMIPS32');
  4119. def_system_macro('CPUMIPSEB32');
  4120. def_system_macro('CPU32');
  4121. def_system_macro('FPC_HAS_TYPE_DOUBLE');
  4122. def_system_macro('FPC_HAS_TYPE_SINGLE');
  4123. def_system_macro('FPC_INCLUDE_SOFTWARE_INT64_TO_DOUBLE');
  4124. def_system_macro('FPC_CURRENCY_IS_INT64');
  4125. def_system_macro('FPC_COMP_IS_INT64');
  4126. def_system_macro('FPC_REQUIRES_PROPER_ALIGNMENT');
  4127. { See comment above for mipsel }
  4128. def_system_macro('FPC_LOCALS_ARE_STACK_REG_RELATIVE');
  4129. {$endif mipseb}
  4130. {$ifdef mips64eb}
  4131. def_system_macro('CPUMIPS');
  4132. def_system_macro('CPUMIPS64');
  4133. def_system_macro('CPUMIPSEB64');
  4134. def_system_macro('CPUMIPS64EB');
  4135. def_system_macro('CPU64');
  4136. def_system_macro('FPC_INCLUDE_SOFTWARE_INT64_TO_DOUBLE');
  4137. def_system_macro('FPC_CURRENCY_IS_INT64');
  4138. def_system_macro('FPC_COMP_IS_INT64');
  4139. def_system_macro('FPC_REQUIRES_PROPER_ALIGNMENT');
  4140. { See comment above for mipsel }
  4141. def_system_macro('FPC_LOCALS_ARE_STACK_REG_RELATIVE');
  4142. {$endif mips64eb}
  4143. {$ifdef mips64el}
  4144. def_system_macro('CPUMIPS');
  4145. def_system_macro('CPUMIPS64');
  4146. def_system_macro('CPUMIPSEL64');
  4147. def_system_macro('CPUMIPS64EL');
  4148. def_system_macro('CPU64');
  4149. def_system_macro('FPC_HAS_TYPE_DOUBLE');
  4150. def_system_macro('FPC_HAS_TYPE_SINGLE');
  4151. def_system_macro('FPC_INCLUDE_SOFTWARE_INT64_TO_DOUBLE');
  4152. def_system_macro('FPC_CURRENCY_IS_INT64');
  4153. def_system_macro('FPC_COMP_IS_INT64');
  4154. def_system_macro('FPC_REQUIRES_PROPER_ALIGNMENT');
  4155. { On most systems, locals are accessed relative to base pointer,
  4156. but for MIPS cpu, they are accessed relative to stack pointer.
  4157. This needs adaptation for so low level routines,
  4158. like MethodPointerLocal and related objects unit functions. }
  4159. def_system_macro('FPC_LOCALS_ARE_STACK_REG_RELATIVE');
  4160. {$endif mips64el}
  4161. {$ifdef i8086}
  4162. def_system_macro('CPU86'); { Borland compatibility }
  4163. def_system_macro('CPU87'); { Borland compatibility }
  4164. def_system_macro('CPUI8086');
  4165. def_system_macro('CPU16');
  4166. def_system_macro('FPC_HAS_TYPE_EXTENDED');
  4167. def_system_macro('FPC_HAS_TYPE_DOUBLE');
  4168. def_system_macro('FPC_HAS_TYPE_SINGLE');
  4169. case init_settings.x86memorymodel of
  4170. mm_tiny: def_system_macro('FPC_MM_TINY');
  4171. mm_small: def_system_macro('FPC_MM_SMALL');
  4172. mm_medium: def_system_macro('FPC_MM_MEDIUM');
  4173. mm_compact: def_system_macro('FPC_MM_COMPACT');
  4174. mm_large: def_system_macro('FPC_MM_LARGE');
  4175. mm_huge: def_system_macro('FPC_MM_HUGE');
  4176. end;
  4177. {$endif i8086}
  4178. {$ifdef aarch64}
  4179. def_system_macro('CPUAARCH64');
  4180. def_system_macro('CPU64');
  4181. def_system_macro('FPC_CURRENCY_IS_INT64');
  4182. def_system_macro('FPC_COMP_IS_INT64');
  4183. {$endif aarch64}
  4184. {$ifdef riscv32}
  4185. def_system_macro('CPURISCV');
  4186. def_system_macro('CPURISCV32');
  4187. def_system_macro('CPU32');
  4188. def_system_macro('FPC_CURRENCY_IS_INT64');
  4189. def_system_macro('FPC_COMP_IS_INT64');
  4190. def_system_macro('FPC_REQUIRES_PROPER_ALIGNMENT');
  4191. {$endif riscv32}
  4192. {$ifdef riscv64}
  4193. def_system_macro('CPURISCV');
  4194. def_system_macro('CPURISCV64');
  4195. def_system_macro('CPU64');
  4196. def_system_macro('FPC_CURRENCY_IS_INT64');
  4197. def_system_macro('FPC_COMP_IS_INT64');
  4198. def_system_macro('FPC_REQUIRES_PROPER_ALIGNMENT');
  4199. {$endif riscv64}
  4200. {$ifdef xtensa}
  4201. def_system_macro('CPUXTENSA');
  4202. def_system_macro('CPU32');
  4203. def_system_macro('FPC_CURRENCY_IS_INT64');
  4204. def_system_macro('FPC_COMP_IS_INT64');
  4205. def_system_macro('FPC_REQUIRES_PROPER_ALIGNMENT');
  4206. {$endif xtensa}
  4207. {$ifdef z80}
  4208. def_system_macro('CPUZ80');
  4209. def_system_macro('CPU16');
  4210. def_system_macro('FPC_CURRENCY_IS_INT64');
  4211. def_system_macro('FPC_COMP_IS_INT64');
  4212. {$endif z80}
  4213. {$ifdef wasm32}
  4214. def_system_macro('CPUWASM');
  4215. def_system_macro('CPUWASM32');
  4216. def_system_macro('CPU32');
  4217. def_system_macro('FPC_CURRENCY_IS_INT64');
  4218. def_system_macro('FPC_COMP_IS_INT64');
  4219. {$endif wasm32}
  4220. {$if defined(cpu8bitalu)}
  4221. def_system_macro('CPUINT8');
  4222. {$elseif defined(cpu16bitalu)}
  4223. def_system_macro('CPUINT16');
  4224. {$elseif defined(cpu32bitalu)}
  4225. def_system_macro('CPUINT32');
  4226. {$elseif defined(cpu64bitalu)}
  4227. def_system_macro('CPUINT64');
  4228. {$endif defined(cpu64bitalu)}
  4229. {$if defined(avr)}
  4230. def_system_macro('FPC_HAS_INTERNAL_ABS_SHORTINT');
  4231. {$endif}
  4232. {$if defined(i8086) or defined(avr)}
  4233. def_system_macro('FPC_HAS_INTERNAL_ABS_SMALLINT');
  4234. {$endif i8086 or avr}
  4235. { abs(long) is handled internally on all CPUs }
  4236. def_system_macro('FPC_HAS_INTERNAL_ABS_LONG');
  4237. {$if defined(i8086) or defined(i386) or defined(x86_64) or defined(powerpc64) or defined(aarch64)}
  4238. def_system_macro('FPC_HAS_INTERNAL_ABS_INT64');
  4239. {$endif i8086 or i386 or x86_64 or powerpc64 or aarch64}
  4240. def_system_macro('FPC_HAS_UNICODESTRING');
  4241. def_system_macro('FPC_RTTI_PACKSET1');
  4242. def_system_macro('FPC_HAS_CPSTRING');
  4243. {$ifdef x86_64}
  4244. def_system_macro('FPC_HAS_RIP_RELATIVE');
  4245. {$endif x86_64}
  4246. def_system_macro('FPC_HAS_CEXTENDED');
  4247. def_system_macro('FPC_HAS_RESSTRINITS');
  4248. { these cpus have an inline rol/ror implementaion }
  4249. {$ifdef cpurox}
  4250. {$ifdef m68k}
  4251. if CPUM68K_HAS_ROLROR in cpu_capabilities[init_settings.cputype] then
  4252. def_system_macro('FPC_HAS_INTERNAL_ROX');
  4253. {$else}
  4254. def_system_macro('FPC_HAS_INTERNAL_ROX');
  4255. {$endif}
  4256. {$endif}
  4257. {$ifdef powerpc64}
  4258. def_system_macro('FPC_HAS_LWSYNC');
  4259. {$endif}
  4260. { currently, all supported CPUs have an internal sar implementation }
  4261. def_system_macro('FPC_HAS_INTERNAL_SAR');
  4262. {$ifdef SUPPORT_GET_FRAME}
  4263. def_system_macro('INTERNAL_BACKTRACE');
  4264. {$endif SUPPORT_GET_FRAME}
  4265. def_system_macro('STR_CONCAT_PROCS');
  4266. {$warnings off}
  4267. if pocall_default = pocall_register then
  4268. def_system_macro('REGCALL');
  4269. {$warnings on}
  4270. end;
  4271. var
  4272. env: ansistring;
  4273. i : tfeature;
  4274. j : longint;
  4275. tmplist : TCmdStrList;
  4276. cmditem,
  4277. tmpcmditem : TCmdStrListItem;
  4278. cmdstr : TCmdStr;
  4279. {$if defined(cpucapabilities)}
  4280. cpuflag : tcpuflags;
  4281. {$endif defined(cpucapabilities)}
  4282. {$if defined(fpucapabilities)}
  4283. fpuflag : tfpuflags;
  4284. {$endif defined(fpucapabilities)}
  4285. {$if defined(cpucapabilities) or defined(fpucapabilities)}
  4286. hs : string;
  4287. {$endif defined(cpucapabilities) or defined(fpucapabilities)}
  4288. begin
  4289. option:=coption.create;
  4290. disable_configfile:=false;
  4291. { Non-core target defines }
  4292. Option.TargetOptions(true);
  4293. { get default messagefile }
  4294. msgfilename:=GetEnvironmentVariable('PPC_ERROR_FILE');
  4295. { default configfile can be specified on the commandline,
  4296. remove it first }
  4297. if (cmd<>'') and (cmd[1]='[') then
  4298. begin
  4299. ppccfg:=Copy(cmd,2,pos(']',cmd)-2);
  4300. Delete(cmd,1,pos(']',cmd));
  4301. end
  4302. else
  4303. ppccfg:='fpc.cfg';
  4304. { first pass reading of parameters, only -i -v -T etc.}
  4305. option.firstpass:=true;
  4306. if cmd<>'' then
  4307. option.parsecmd(cmd)
  4308. else
  4309. begin
  4310. option.read_parameters;
  4311. { Write only quickinfo }
  4312. if option.quickinfo<>'' then
  4313. option.writequickinfo;
  4314. end;
  4315. option.firstpass:=false;
  4316. { redefine target options so all defines are written even if no -Txxx is passed on the command line }
  4317. Option.TargetOptions(true);
  4318. { target is set here, for wince the default app type is gui }
  4319. if target_info.system in systems_wince then
  4320. SetApptype(app_gui)
  4321. else
  4322. SetApptype(apptype);
  4323. { default defines }
  4324. def_system_macro(target_info.shortname);
  4325. def_system_macro('FPC');
  4326. def_system_macro('VER'+version_nr);
  4327. def_system_macro('VER'+version_nr+'_'+release_nr);
  4328. def_system_macro('VER'+version_nr+'_'+release_nr+'_'+patch_nr);
  4329. { Temporary defines, until things settle down }
  4330. def_system_macro('FPC_HAS_OPERATOR_ENUMERATOR');
  4331. def_system_macro('FPC_HAS_CONSTREF');
  4332. def_system_macro('FPC_STATICRIPFIXED');
  4333. def_system_macro('FPC_VARIANTCOPY_FIXED');
  4334. def_system_macro('FPC_DYNARRAYCOPY_FIXED');
  4335. def_system_macro('FPC_HAS_MEMBAR');
  4336. def_system_macro('FPC_SETBASE_USED');
  4337. def_system_macro('FPC_ALIGNED_THREADVARTABLES');
  4338. { don't remove this, it's also for fpdoc necessary (FK) }
  4339. def_system_macro('FPC_HAS_FEATURE_SUPPORT');
  4340. if (Option.parasubtarget<>'') then
  4341. begin
  4342. def_system_macro('FPC_SUBTARGET_'+Option.parasubtarget);
  4343. if cs_support_macro in init_settings.moduleswitches then
  4344. set_system_macro('FPC_SUBTARGET',Option.parasubtarget)
  4345. else
  4346. set_system_compvar('FPC_SUBTARGET',Option.parasubtarget);
  4347. end;
  4348. { make cpu makros available when reading the config files the second time }
  4349. def_cpu_macros;
  4350. if tf_cld in target_info.flags then
  4351. if not UpdateTargetSwitchStr('CLD', init_settings.targetswitches, true) then
  4352. InternalError(2013092801);
  4353. if tf_x86_far_procs_push_odd_bp in target_info.flags then
  4354. if not UpdateTargetSwitchStr('FARPROCSPUSHODDBP', init_settings.targetswitches, true) then
  4355. InternalError(2013092802);
  4356. { Use standard Android NDK prefixes when cross-compiling }
  4357. if (source_info.system<>target_info.system) and (target_info.system in systems_android) then
  4358. case target_info.system of
  4359. system_arm_android:
  4360. utilsprefix:='arm-linux-androideabi-';
  4361. system_i386_android:
  4362. utilsprefix:='i686-linux-android-';
  4363. else
  4364. utilsprefix:=target_cpu_string + '-linux-android-';
  4365. end;
  4366. { Set up default value for the heap on Amiga-likes (values only apply if the OSHeap allocator is used) }
  4367. if target_info.system in systems_amigalike then
  4368. begin
  4369. case target_info.system of
  4370. system_m68k_amiga:
  4371. heapsize:=256*1024;
  4372. system_powerpc_amiga,
  4373. system_powerpc_morphos,
  4374. system_arm_aros,
  4375. system_i386_aros,
  4376. system_x86_64_aros:
  4377. heapsize:=1024*1024;
  4378. else
  4379. heapsize:=256*1024;
  4380. end;
  4381. end;
  4382. if target_info.system in (systems_embedded+systems_freertos+[system_z80_zxspectrum,system_z80_msxdos]) then
  4383. begin
  4384. case target_info.system of
  4385. {$ifdef AVR}
  4386. system_avr_embedded:
  4387. if init_settings.controllertype=ct_avrsim then
  4388. heapsize:=8192
  4389. else
  4390. heapsize:=128;
  4391. {$endif AVR}
  4392. system_arm_freertos:
  4393. heapsize:=8192;
  4394. system_xtensa_freertos:
  4395. { keep default value }
  4396. ;
  4397. system_arm_embedded:
  4398. heapsize:=256;
  4399. system_mipsel_embedded:
  4400. heapsize:=256;
  4401. else
  4402. heapsize:=256;
  4403. end;
  4404. end;
  4405. { read configuration file }
  4406. if (not disable_configfile) and
  4407. (ppccfg<>'') then
  4408. read_configfile:=check_configfile(ppccfg,ppccfg)
  4409. else
  4410. read_configfile := false;
  4411. if (option.parasubtarget<>'') then
  4412. begin
  4413. subcfg:='fpc-'+lower(option.parasubtarget)+'.cfg';
  4414. read_subfile:=check_configfile(subcfg,subcfg);
  4415. // Warn if we didn't find an architecture-specific file
  4416. if not read_subfile then
  4417. message2(option_subtarget_config_not_found,option.parasubtarget,subcfg);
  4418. end;
  4419. { Read commandline and configfile }
  4420. param_file:='';
  4421. { read configfile }
  4422. if read_configfile then
  4423. option.interpret_file(ppccfg);
  4424. if read_subfile then
  4425. option.interpret_file(subcfg);
  4426. { read parameters again to override config file }
  4427. if cmd<>'' then
  4428. option.parsecmd(cmd)
  4429. else
  4430. begin
  4431. { Write help pages if no parameters are passed }
  4432. if (paramcount=0) then
  4433. Option.WriteHelpPages;
  4434. option.read_parameters;
  4435. { Write only quickinfo }
  4436. if option.quickinfo<>'' then
  4437. option.writequickinfo;
  4438. end;
  4439. { check the compatibility of different options and adjust them if necessary
  4440. (and print possible errors)
  4441. }
  4442. option.checkoptionscompatibility;
  4443. { uses the CPUXXX-defines and target_info to determine whether the selected
  4444. target processor, if any, is supported }
  4445. Option.VerifyTargetProcessor;
  4446. { Stop if errors in options }
  4447. if ErrorCount>0 then
  4448. StopOptions(1);
  4449. { endian define }
  4450. case target_info.endian of
  4451. endian_little :
  4452. begin
  4453. def_system_macro('ENDIAN_LITTLE');
  4454. def_system_macro('FPC_LITTLE_ENDIAN');
  4455. end;
  4456. endian_big :
  4457. begin
  4458. def_system_macro('ENDIAN_BIG');
  4459. def_system_macro('FPC_BIG_ENDIAN');
  4460. end;
  4461. end;
  4462. { Write logo }
  4463. if option.ParaLogo then
  4464. option.writelogo;
  4465. { Check file to compile }
  4466. if param_file='' then
  4467. begin
  4468. Message(option_no_source_found);
  4469. StopOptions(1);
  4470. end;
  4471. {$ifndef Unix}
  4472. param_file:=FixFileName(param_file);
  4473. {$endif not unix}
  4474. inputfilepath:=ExtractFilePath(param_file);
  4475. inputfilename:=ExtractFileName(param_file);
  4476. if ExtractFileExt(inputfilename)='' then
  4477. begin
  4478. if FileExists(inputfilepath+ChangeFileExt(inputfilename,sourceext)) then
  4479. inputfilename:=ChangeFileExt(inputfilename,sourceext)
  4480. else if FileExists(inputfilepath+ChangeFileExt(inputfilename,pasext)) then
  4481. inputfilename:=ChangeFileExt(inputfilename,pasext)
  4482. else if ((m_mac in current_settings.modeswitches) or
  4483. (tf_p_ext_support in target_info.flags))
  4484. and FileExists(inputfilepath+ChangeFileExt(inputfilename,pext)) then
  4485. inputfilename:=ChangeFileExt(inputfilename,pext);
  4486. end;
  4487. { Check output dir }
  4488. if (OutputExeDir<>'') and
  4489. not PathExists(OutputExeDir,false) then
  4490. begin
  4491. Message1(general_e_path_does_not_exist,OutputExeDir);
  4492. StopOptions(1);
  4493. end;
  4494. { Add paths specified with parameters to the searchpaths }
  4495. UnitSearchPath.AddList(option.ParaUnitPath,true);
  4496. ObjectSearchPath.AddList(option.ParaObjectPath,true);
  4497. IncludeSearchPath.AddList(option.ParaIncludePath,true);
  4498. LibrarySearchPath.AddList(option.ParaLibraryPath,true);
  4499. FrameworkSearchPath.AddList(option.ParaFrameworkPath,true);
  4500. packagesearchpath.addlist(option.parapackagepath,true);
  4501. for j:=0 to option.parapackages.count-1 do
  4502. add_package(option.parapackages.NameOfIndex(j),true,true);
  4503. { add default namespaces }
  4504. tmplist:=TCmdStrList.Create;
  4505. cmditem:=TCmdStrListItem(option.paranamespaces.First);
  4506. while assigned(cmditem) do
  4507. begin
  4508. { use a temporary list cause if ";" are involved we need to reverse the
  4509. order due to how TCmdStrList behaves }
  4510. cmdstr:=cmditem.str;
  4511. repeat
  4512. j:=Pos(';',cmdstr);
  4513. if j>0 then
  4514. begin
  4515. tmplist.insert(copy(cmdstr,1,j-1));
  4516. delete(cmdstr,1,j);
  4517. end
  4518. else
  4519. tmplist.insert(cmdstr);
  4520. until j=0;
  4521. tmpcmditem:=TCmdStrListItem(tmplist.First);
  4522. while assigned(tmpcmditem) do
  4523. begin
  4524. namespacelist.insert(tmpcmditem.Str);
  4525. tmpcmditem:=TCmdStrListItem(tmpcmditem.Next);
  4526. end;
  4527. tmplist.clear;
  4528. cmditem:=TCmdStrListItem(cmditem.Next);
  4529. end;
  4530. tmplist.Free;
  4531. { add unit environment and exepath to the unit search path }
  4532. if inputfilepath<>'' then
  4533. Unitsearchpath.AddPath(inputfilepath,true);
  4534. if not disable_configfile then
  4535. begin
  4536. env:=GetEnvironmentVariable(target_info.unit_env);
  4537. if env<>'' then
  4538. UnitSearchPath.AddPath(GetEnvironmentVariable(target_info.unit_env),false);
  4539. end;
  4540. {$ifdef Unix}
  4541. fpcdir:=FixPath(GetEnvironmentVariable('FPCDIR'),false);
  4542. if fpcdir='' then
  4543. begin
  4544. if PathExists('/usr/local/lib/fpc/'+version_string,true) then
  4545. fpcdir:='/usr/local/lib/fpc/'+version_string+'/'
  4546. else
  4547. fpcdir:='/usr/lib/fpc/'+version_string+'/';
  4548. end;
  4549. {$else unix}
  4550. fpcdir:=FixPath(GetEnvironmentVariable('FPCDIR'),false);
  4551. if fpcdir='' then
  4552. begin
  4553. fpcdir:=ExePath+'../';
  4554. if not(PathExists(fpcdir+'units',true)) and
  4555. not(PathExists(fpcdir+'rtl',true)) then
  4556. fpcdir:=fpcdir+'../';
  4557. end;
  4558. {$endif unix}
  4559. { first try development RTL, else use the default installation path }
  4560. if not disable_configfile then
  4561. begin
  4562. if PathExists(FpcDir+'rtl',true) then
  4563. if (tf_use_8_3 in Source_Info.Flags) or
  4564. (tf_use_8_3 in Target_Info.Flags) then
  4565. UnitSearchPath.AddPath(FpcDir+'rtl/'+target_os_string,false)
  4566. else
  4567. UnitSearchPath.AddPath(FpcDir+'rtl/'+target_full_string,false)
  4568. else
  4569. if (tf_use_8_3 in Source_Info.Flags) or
  4570. (tf_use_8_3 in Target_Info.Flags) then
  4571. UnitSearchPath.AddPath(FpcDir+'units/'+target_os_string+'/rtl',false)
  4572. else
  4573. UnitSearchPath.AddPath(FpcDir+'units/'+target_full_string+'/rtl',false);
  4574. end;
  4575. { Add exepath if the exe is not in the current dir, because that is always searched already.
  4576. Do not add it when linking on the target because then we can maybe already find
  4577. .o files that are not for the target }
  4578. if (ExePath<>cfileutl.GetCurrentDir) and
  4579. not(cs_link_on_target in init_settings.globalswitches) then
  4580. UnitSearchPath.AddPath(ExePath,false);
  4581. { Add unit dir to the object and library path }
  4582. objectsearchpath.AddList(unitsearchpath,false);
  4583. librarysearchpath.AddList(unitsearchpath,false);
  4584. {$ifdef llvm}
  4585. { default to clang }
  4586. if (option.paratargetasm=as_none) then
  4587. begin
  4588. if not(target_info.system in systems_darwin) then
  4589. option.paratargetasm:=as_clang_llvm
  4590. else
  4591. option.paratargetasm:=as_clang_llvm_darwin;
  4592. end;
  4593. {$endif llvm}
  4594. { maybe override assembler }
  4595. if (option.paratargetasm<>as_none) then
  4596. begin
  4597. if (option.paratargetasm=as_default) then
  4598. begin
  4599. option.paratargetasm:=target_info.assem;
  4600. end;
  4601. if not set_target_asm(option.paratargetasm) then
  4602. begin
  4603. if assigned(asminfos[option.paratargetasm]) then
  4604. Message2(option_incompatible_asm,asminfos[option.paratargetasm]^.idtxt,target_info.name)
  4605. else
  4606. Message2(option_incompatible_asm,'<invalid assembler>',target_info.name);
  4607. set_target_asm(target_info.assemextern);
  4608. Message1(option_asm_forced,target_asm.idtxt);
  4609. end;
  4610. if (af_no_debug in asminfos[option.paratargetasm]^.flags) and
  4611. (option.paratargetdbg<>dbg_none) then
  4612. begin
  4613. Message1(option_confict_asm_debug,
  4614. asminfos[option.paratargetasm]^.idtxt);
  4615. option.paratargetdbg:=dbg_none;
  4616. exclude(init_settings.moduleswitches,cs_debuginfo);
  4617. end;
  4618. { Some assemblers, like clang, do not support
  4619. stabs debugging format, switch to dwardé in that case }
  4620. if (af_no_stabs in asminfos[option.paratargetasm]^.flags) and
  4621. (option.paratargetdbg=dbg_stabs) then
  4622. begin
  4623. option.paratargetdbg:=dbg_dwarf2;
  4624. end;
  4625. end;
  4626. {TOptionheck a second time as we might have changed assembler just above }
  4627. option.checkoptionscompatibility;
  4628. { maybe override debug info format }
  4629. if (option.paratargetdbg<>dbg_none) then
  4630. if not set_target_dbg(option.paratargetdbg) then
  4631. Message(option_w_unsupported_debug_format);
  4632. { switch assembler if it's binary and we got -a on the cmdline }
  4633. if (af_outputbinary in target_asm.flags) and
  4634. ((cs_asm_leave in init_settings.globalswitches) or
  4635. { if -s is passed, we shouldn't call the internal assembler }
  4636. (cs_asm_extern in init_settings.globalswitches)) then
  4637. begin
  4638. Message(option_switch_bin_to_src_assembler);
  4639. {$ifdef llvm}
  4640. if not(target_info.system in systems_darwin) then
  4641. set_target_asm(as_clang_llvm)
  4642. else
  4643. set_target_asm(as_clang_llvm_darwin);
  4644. {$else}
  4645. set_target_asm(target_info.assemextern);
  4646. {$endif}
  4647. { At least i8086 needs that for nasm and -CX
  4648. which is incompatible with internal linker }
  4649. option.checkoptionscompatibility;
  4650. end;
  4651. { Force use of external linker if there is no
  4652. internal linker or the linking is skipped }
  4653. if not(cs_link_extern in init_settings.globalswitches) and
  4654. ((target_info.link=ld_none) or
  4655. (cs_link_nolink in init_settings.globalswitches)) then
  4656. begin
  4657. include(init_settings.globalswitches,cs_link_extern);
  4658. end;
  4659. { turn off stripping if compiling with debuginfo or profile }
  4660. if (
  4661. (cs_debuginfo in init_settings.moduleswitches) or
  4662. (cs_profile in init_settings.moduleswitches)
  4663. ) and
  4664. not(cs_link_separate_dbg_file in init_settings.globalswitches) then
  4665. exclude(init_settings.globalswitches,cs_link_strip);
  4666. { choose a reasonable tls model }
  4667. if (tf_section_threadvars in target_info.flags) and (init_settings.tlsmodel=tlsm_none) then
  4668. begin
  4669. if cs_create_pic in init_settings.moduleswitches then
  4670. init_settings.tlsmodel:=tlsm_global_dynamic
  4671. else
  4672. init_settings.tlsmodel:=tlsm_local_exec;
  4673. end;
  4674. { set Mac OS X version default macros if not specified explicitly }
  4675. option.MaybeSetDefaultMacVersionMacro;
  4676. {$ifdef XTENSA}
  4677. { set ESP32 or ESP8266 default SDK versions }
  4678. option.MaybeSetIdfVersionMacro;
  4679. {$endif XTENSA}
  4680. {$ifdef cpufpemu}
  4681. { force fpu emulation on arm/wince, arm/gba, arm/embedded and arm/nds
  4682. if fpu type not explicitly set }
  4683. if not(option.FPUSetExplicitly) and
  4684. ((target_info.system in [system_arm_wince,system_arm_gba,
  4685. system_m68k_amiga,system_m68k_atari,
  4686. system_arm_nds,system_arm_embedded,system_arm_freertos,
  4687. system_riscv32_embedded,system_riscv64_embedded,system_xtensa_linux,
  4688. system_z80_embedded,system_z80_zxspectrum])
  4689. {$ifdef arm}
  4690. or (target_info.abi=abi_eabi)
  4691. {$endif arm}
  4692. )
  4693. or (init_settings.fputype=fpu_soft)
  4694. then
  4695. begin
  4696. include(init_settings.moduleswitches,cs_fp_emulation);
  4697. { cs_fp_emulation and fpu_soft are equal on arm and m68k }
  4698. init_settings.fputype:=fpu_soft;
  4699. end;
  4700. {$endif cpufpemu}
  4701. {$ifdef i386}
  4702. if target_info.system in systems_i386_default_486 then
  4703. begin
  4704. { Avoid use of MMX/CMOVcc instructions on older systems.
  4705. Some systems might not handle these instructions correctly,
  4706. Used emulators might also be problematic. PM }
  4707. if not option.CPUSetExplicitly then
  4708. init_settings.cputype:=cpu_486;
  4709. end;
  4710. case target_info.system of
  4711. system_i386_android:
  4712. begin
  4713. { set default cpu type to PentiumM for Android unless specified otherwise }
  4714. if not option.CPUSetExplicitly then
  4715. init_settings.cputype:=cpu_PentiumM;
  4716. if not option.OptCPUSetExplicitly then
  4717. init_settings.optimizecputype:=cpu_PentiumM;
  4718. { set default fpu type to SSSE3 for Android unless specified otherwise }
  4719. if not option.FPUSetExplicitly then
  4720. init_settings.fputype:=fpu_ssse3;
  4721. end;
  4722. else
  4723. ;
  4724. end;
  4725. {$endif i386}
  4726. {$ifdef xtensa}
  4727. { xtensa-linux target does not support controller setting option -Wp }
  4728. if not(option.FPUSetExplicitly) and not(target_info.system = system_xtensa_linux) then
  4729. begin
  4730. init_settings.fputype:=embedded_controllers[init_settings.controllertype].fputype;
  4731. if (init_settings.fputype=fpu_soft) then
  4732. include(init_settings.moduleswitches,cs_fp_emulation);
  4733. end;
  4734. if not(option.CPUSetExplicitly) and (target_info.system=system_xtensa_linux) then
  4735. init_settings.cputype:=cpu_lx6;
  4736. if (target_info.system in [system_xtensa_embedded,system_xtensa_freertos]) and not(option.ABISetExplicitly) then
  4737. begin
  4738. if CPUXTENSA_REGWINDOW in cpu_capabilities[init_settings.cputype] then
  4739. target_info.abi:=abi_xtensa_windowed
  4740. else
  4741. target_info.abi:=abi_xtensa_call0;
  4742. end;
  4743. {$endif xtensa}
  4744. {$ifdef arm}
  4745. case target_info.system of
  4746. system_arm_ios:
  4747. begin
  4748. { set default cpu type to ARMv7 for Darwin unless specified otherwise, and fpu
  4749. to VFPv3 (that's what all 32 bit ARM iOS devices use nowadays)
  4750. }
  4751. if not option.CPUSetExplicitly then
  4752. init_settings.cputype:=cpu_armv7;
  4753. if not option.OptCPUSetExplicitly then
  4754. init_settings.optimizecputype:=cpu_armv7;
  4755. if not option.FPUSetExplicitly then
  4756. init_settings.fputype:=fpu_vfpv3;
  4757. end;
  4758. system_arm_android:
  4759. begin
  4760. { set default cpu type to ARMv5T for Android unless specified otherwise }
  4761. if not option.CPUSetExplicitly then
  4762. init_settings.cputype:=cpu_armv5t;
  4763. if not option.OptCPUSetExplicitly then
  4764. init_settings.optimizecputype:=cpu_armv5t;
  4765. end;
  4766. else
  4767. ;
  4768. end;
  4769. { set ABI defaults }
  4770. case target_info.abi of
  4771. abi_eabihf:
  4772. { set default cpu type to ARMv7a for ARMHF unless specified otherwise }
  4773. begin
  4774. {$ifdef CPUARMV6}
  4775. { if the compiler is built for armv6, then
  4776. inherit this setting, e.g. Raspian is armhf but
  4777. only armv6, this makes rebuilds of the compiler
  4778. easier }
  4779. if not option.CPUSetExplicitly then
  4780. init_settings.cputype:=cpu_armv6;
  4781. if not option.OptCPUSetExplicitly then
  4782. init_settings.optimizecputype:=cpu_armv6;
  4783. {$else CPUARMV6}
  4784. if not option.CPUSetExplicitly then
  4785. init_settings.cputype:=cpu_armv7a;
  4786. if not option.OptCPUSetExplicitly then
  4787. init_settings.optimizecputype:=cpu_armv7a;
  4788. {$endif CPUARMV6}
  4789. { Set FPU type }
  4790. if not(option.FPUSetExplicitly) then
  4791. begin
  4792. if init_settings.cputype < cpu_armv7 then
  4793. init_settings.fputype:=fpu_vfpv2
  4794. else
  4795. init_settings.fputype:=fpu_vfpv3_d16;
  4796. end
  4797. else
  4798. begin
  4799. if (not(FPUARM_HAS_VFP_EXTENSION in fpu_capabilities[init_settings.fputype]))
  4800. or (target_info.system = system_arm_ios) then
  4801. begin
  4802. Message(option_illegal_fpu_eabihf);
  4803. StopOptions(1);
  4804. end;
  4805. end;
  4806. end;
  4807. abi_eabi:
  4808. begin
  4809. if target_info.system=system_arm_linux then
  4810. begin
  4811. { this is what Debian uses }
  4812. if not option.CPUSetExplicitly then
  4813. init_settings.cputype:=cpu_armv4t;
  4814. if not option.OptCPUSetExplicitly then
  4815. init_settings.optimizecputype:=cpu_armv4t;
  4816. if not(option.FPUSetExplicitly) then
  4817. init_settings.fputype:=fpu_soft;
  4818. end;
  4819. end;
  4820. else
  4821. ;
  4822. end;
  4823. if (init_settings.instructionset=is_thumb) and not(CPUARM_HAS_THUMB2 in cpu_capabilities[init_settings.cputype]) then
  4824. begin
  4825. def_system_macro('CPUTHUMB');
  4826. if not option.FPUSetExplicitly then
  4827. init_settings.fputype:=fpu_soft;
  4828. if not(init_settings.fputype in [fpu_none,fpu_soft,fpu_libgcc]) then
  4829. Message2(option_unsupported_fpu,fputypestr[init_settings.fputype],'Thumb');
  4830. {$if defined(FPC_ARMEL) or defined(FPC_ARMHF)}
  4831. target_info.llvmdatalayout:='e-p:32:32:32-i1:8:32-i8:8:32-i16:16:32-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:64:128-a0:0:32-n32-S64';
  4832. {$else FPC_ARMAL or FPC_ARMHF}
  4833. if target_info.endian=endian_little then
  4834. target_info.llvmdatalayout:='e-p:32:32:32-i1:8:32-i8:8:32-i16:16:32-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:32:64-v128:32:128-a0:0:32-n32-S32';
  4835. {$endif FPC_ARMAL or FPC_ARMHF}
  4836. end;
  4837. if (init_settings.instructionset=is_thumb) and (CPUARM_HAS_THUMB2 in cpu_capabilities[init_settings.cputype]) then
  4838. def_system_macro('CPUTHUMB2');
  4839. {$endif arm}
  4840. {$ifdef aarch64}
  4841. case target_info.system of
  4842. system_aarch64_darwin:
  4843. begin
  4844. if not option.CPUSetExplicitly then
  4845. init_settings.cputype:=cpu_armv84a;
  4846. if not option.OptCPUSetExplicitly then
  4847. init_settings.optimizecputype:=cpu_armv84a;
  4848. end;
  4849. else
  4850. ;
  4851. end;
  4852. {$endif aarch64}
  4853. {$if defined(riscv32) or defined(riscv64)}
  4854. { RISC-V defaults }
  4855. if (target_info.abi = abi_riscv_hf) then
  4856. begin
  4857. {$ifdef riscv32}
  4858. if not option.CPUSetExplicitly then
  4859. init_settings.cputype:=cpu_rv32ima;
  4860. if not option.OptCPUSetExplicitly then
  4861. init_settings.optimizecputype:=cpu_rv32ima;
  4862. {$else}
  4863. if not option.CPUSetExplicitly then
  4864. init_settings.cputype:=cpu_rv64imac;
  4865. if not option.OptCPUSetExplicitly then
  4866. init_settings.optimizecputype:=cpu_rv64imac;
  4867. {$endif}
  4868. { Set FPU type }
  4869. if not(option.FPUSetExplicitly) then
  4870. init_settings.fputype:=fpu_fd
  4871. else
  4872. begin
  4873. if not (init_settings.fputype in [fpu_fd]) then
  4874. begin
  4875. Message(option_illegal_fpu_eabihf);
  4876. StopOptions(1);
  4877. end;
  4878. end;
  4879. end;
  4880. {$endif defined(riscv32) or defined(riscv64)}
  4881. {$ifdef jvm}
  4882. { set default CPU type to Dalvik when targeting Android }
  4883. if target_info.system=system_jvm_android32 then
  4884. begin
  4885. if not option.CPUSetExplicitly then
  4886. init_settings.cputype:=cpu_dalvik;
  4887. end;
  4888. {$endif jvm}
  4889. {$ifdef llvm}
  4890. { standard extension for llvm bitcode files }
  4891. target_info.asmext:='.ll';
  4892. { don't generate dwarf cfi, llvm will do that }
  4893. exclude(target_info.flags,tf_needs_dwarf_cfi);
  4894. {$endif llvm}
  4895. {$ifdef mipsel}
  4896. case target_info.system of
  4897. system_mipsel_android:
  4898. begin
  4899. { set default cpu type to MIPS32 rev. 1 and hard float for MIPS-Android unless specified otherwise }
  4900. if not option.CPUSetExplicitly then
  4901. init_settings.cputype:=cpu_mips32;
  4902. if not option.OptCPUSetExplicitly then
  4903. init_settings.optimizecputype:=cpu_mips32;
  4904. if not option.FPUSetExplicitly then
  4905. init_settings.fputype:=fpu_mips2;
  4906. end;
  4907. system_mipsel_embedded:
  4908. begin
  4909. { set default cpu type to PIC32MX and softfloat for MIPSEL-EMBEDDED target unless specified otherwise }
  4910. if not option.CPUSetExplicitly then
  4911. init_settings.cputype:=cpu_pic32mx;
  4912. if not option.OptCPUSetExplicitly then
  4913. init_settings.optimizecputype:=cpu_pic32mx;
  4914. if not option.FPUSetExplicitly then
  4915. init_settings.fputype:=fpu_soft;
  4916. end;
  4917. else
  4918. ;
  4919. end;
  4920. {$endif mipsel}
  4921. {$ifdef m68k}
  4922. if init_settings.cputype in cpu_coldfire then
  4923. def_system_macro('CPUCOLDFIRE');
  4924. case target_info.system of
  4925. system_m68k_linux,
  4926. system_m68k_netbsd:
  4927. begin
  4928. if not (option.FPUSetExplicitly) and
  4929. not (init_settings.cputype in cpu_coldfire) then
  4930. begin
  4931. { enable HW FPU for UNIX by default, but only for
  4932. original 68k, not Coldfire }
  4933. exclude(init_settings.moduleswitches,cs_fp_emulation);
  4934. init_settings.fputype:=fpu_68881;
  4935. end;
  4936. end;
  4937. system_m68k_atari,
  4938. system_m68k_sinclairql:
  4939. begin
  4940. if not option.CPUSetExplicitly then
  4941. init_settings.cputype:=cpu_mc68000;
  4942. end;
  4943. system_m68k_palmos:
  4944. begin
  4945. if not option.CPUSetExplicitly then
  4946. init_settings.cputype:=cpu_mc68000;
  4947. if not (option.FPUSetExplicitly) then
  4948. begin
  4949. { No FPU for PalmOS by default }
  4950. exclude(init_settings.moduleswitches,cs_fp_emulation);
  4951. init_settings.fputype:=fpu_none;
  4952. end;
  4953. end;
  4954. else
  4955. ;
  4956. end;
  4957. {$endif m68k}
  4958. {$ifdef wasm}
  4959. { if no explicit exception handling mode is set for WebAssembly, assume no exceptions }
  4960. if init_settings.targetswitches*[ts_wasm_no_exceptions,ts_wasm_js_exceptions,ts_wasm_native_exceptions,ts_wasm_bf_exceptions]=[] then
  4961. begin
  4962. def_system_macro(TargetSwitchStr[ts_wasm_no_exceptions].define);
  4963. include(init_settings.targetswitches,ts_wasm_no_exceptions);
  4964. end;
  4965. {$endif wasm}
  4966. { now we can define cpu and fpu type }
  4967. def_cpu_macros;
  4968. { Use init_settings cpu type for asm cpu type,
  4969. if asmcputype is cpu_none,
  4970. at least as long as there is no explicit
  4971. option to set it on command line PM }
  4972. if init_settings.asmcputype = cpu_none then
  4973. init_settings.asmcputype:=init_settings.cputype;
  4974. {$ifdef llvm}
  4975. def_system_macro('CPULLVM');
  4976. {$endif llvm}
  4977. {$if defined(cpucapabilities)}
  4978. for cpuflag:=low(cpuflag) to high(cpuflag) do
  4979. begin
  4980. str(cpuflag,hs);
  4981. if cpuflag in cpu_capabilities[init_settings.cputype] then
  4982. def_system_macro(hs)
  4983. else
  4984. undef_system_macro(hs);
  4985. end;
  4986. {$endif defined(cpucapabilities)}
  4987. {$if defined(fpucapabilities)}
  4988. for fpuflag:=low(fpuflag) to high(fpuflag) do
  4989. begin
  4990. str(fpuflag,hs);
  4991. if fpuflag in fpu_capabilities[init_settings.fputype] then
  4992. def_system_macro(hs)
  4993. else
  4994. undef_system_macro(hs);
  4995. end;
  4996. {$endif defined(fpucapabilities)}
  4997. if init_settings.fputype<>fpu_none then
  4998. begin
  4999. {$if defined(i386) or defined(i8086)}
  5000. def_system_macro('FPC_HAS_TYPE_EXTENDED');
  5001. {$endif}
  5002. def_system_macro('FPC_HAS_TYPE_SINGLE');
  5003. def_system_macro('FPC_HAS_TYPE_DOUBLE');
  5004. {$if not defined(i386) and not defined(x86_64) and not defined(i8086) and not defined(aarch64)}
  5005. def_system_macro('FPC_INCLUDE_SOFTWARE_INT64_TO_DOUBLE');
  5006. {$endif}
  5007. {$if defined(m68k)}
  5008. def_system_macro('FPC_INCLUDE_SOFTWARE_LONGWORD_TO_DOUBLE');
  5009. {$endif}
  5010. {$ifdef x86_64}
  5011. {$ifndef FPC_SUPPORT_X87_TYPES_ON_WIN64}
  5012. { normally, win64 doesn't support the legacy fpu }
  5013. if target_info.system=system_x86_64_win64 then
  5014. undef_system_macro('FPC_HAS_TYPE_EXTENDED')
  5015. else
  5016. {$endif FPC_SUPPORT_X87_TYPES_ON_WIN64}
  5017. def_system_macro('FPC_HAS_TYPE_EXTENDED');
  5018. {$endif}
  5019. end;
  5020. { Enable now for testing }
  5021. {$ifndef DISABLE_TLS_DIRECTORY}
  5022. if target_info.system in systems_windows then
  5023. def_system_macro('FPC_USE_TLS_DIRECTORY');
  5024. {$endif not DISABLE_TLS_DIRECTORY}
  5025. {$ifndef DISABLE_WIN64_SEH}
  5026. if target_info.system=system_x86_64_win64 then
  5027. def_system_macro('FPC_USE_WIN64_SEH');
  5028. {$endif DISABLE_WIN64_SEH}
  5029. {$ifndef DISABLE_WIN32_SEH}
  5030. if target_info.system=system_i386_win32 then
  5031. def_system_macro('FPC_USE_WIN32_SEH');
  5032. {$endif not DISABLE_WIN32_SEH}
  5033. {$ifdef ARM}
  5034. { define FPC_DOUBLE_HILO_SWAPPED if needed to properly handle doubles in RTL }
  5035. if (init_settings.fputype in [fpu_fpa,fpu_fpa10,fpu_fpa11]) and
  5036. not(cs_fp_emulation in init_settings.moduleswitches) then
  5037. def_system_macro('FPC_DOUBLE_HILO_SWAPPED');
  5038. {$endif ARM}
  5039. { inline bsf/bsr implementation }
  5040. {$if defined(i386) or defined(x86_64) or defined(aarch64) or defined(powerpc) or defined(powerpc64)}
  5041. def_system_macro('FPC_HAS_INTERNAL_BSF');
  5042. def_system_macro('FPC_HAS_INTERNAL_BSR');
  5043. {$endif}
  5044. { hardware FMA support }
  5045. {$if defined(i386) or defined(x86_64)}
  5046. if (fpu_capabilities[current_settings.fputype]*[FPUX86_HAS_FMA,FPUX86_HAS_FMA4])<>[] then
  5047. begin
  5048. def_system_macro('FPC_HAS_FAST_FMA_SINGLE');
  5049. def_system_macro('FPC_HAS_FAST_FMA_DOUBLE');
  5050. end;
  5051. {$endif defined(i386) or defined(x86_64)}
  5052. {$if defined(arm)}
  5053. { it is determined during system unit compilation if clz is used for bsf or not,
  5054. this is not perfect but the current implementation bsf/bsr does not allow another
  5055. solution }
  5056. if (CPUARM_HAS_CLZ in cpu_capabilities[init_settings.cputype]) and
  5057. ((init_settings.instructionset=is_arm) or
  5058. (CPUARM_HAS_THUMB2 in cpu_capabilities[init_settings.cputype])) then
  5059. begin
  5060. def_system_macro('FPC_HAS_INTERNAL_BSR');
  5061. if CPUARM_HAS_RBIT in cpu_capabilities[init_settings.cputype] then
  5062. def_system_macro('FPC_HAS_INTERNAL_BSF');
  5063. end;
  5064. {$endif}
  5065. {$if defined(xtensa)}
  5066. { it is determined during system unit compilation if nsau is used for bsr or not,
  5067. this is not perfect but the current implementation bsf/bsr does not allow another
  5068. solution }
  5069. if CPUXTENSA_HAS_NSAx in cpu_capabilities[init_settings.cputype] then
  5070. begin
  5071. def_system_macro('FPC_HAS_INTERNAL_BSR');
  5072. end;
  5073. {$endif}
  5074. {$if defined(powerpc64)}
  5075. { on sysv targets, default to elfv2 for little endian and to elfv1 for
  5076. big endian (unless specified otherwise). As the gcc man page says:
  5077. "Overriding the default ABI requires special system support and is
  5078. likely to fail in spectacular ways" }
  5079. if not option.ABISetExplicitly then
  5080. begin
  5081. if (target_info.abi=abi_powerpc_sysv) and
  5082. (target_info.endian=endian_little) then
  5083. target_info.abi:=abi_powerpc_elfv2
  5084. else
  5085. if (target_info.abi=abi_powerpc_elfv2) and
  5086. (target_info.endian=endian_big) then
  5087. target_info.abi:=abi_powerpc_sysv
  5088. end;
  5089. {$endif}
  5090. {$if defined(powerpc) or defined(powerpc64)}
  5091. { define _CALL_ELF symbol like gcc }
  5092. case target_info.abi of
  5093. abi_powerpc_sysv:
  5094. set_system_compvar('_CALL_ELF','1');
  5095. abi_powerpc_elfv2:
  5096. set_system_compvar('_CALL_ELF','2');
  5097. else
  5098. ;
  5099. end;
  5100. {$endif}
  5101. { Section smartlinking conflicts with import sections on Windows }
  5102. if GenerateImportSection and
  5103. (target_info.system in [system_i386_win32,system_x86_64_win64,system_aarch64_win64]) then
  5104. exclude(target_info.flags,tf_smartlink_sections);
  5105. if not option.LinkTypeSetExplicitly then
  5106. set_default_link_type;
  5107. { Default alignment settings,
  5108. 1. load the defaults for the target
  5109. 2. adapt defaults specifically for the target
  5110. 3. override with generic optimizer setting (little size)
  5111. 4. override with the user specified -Oa }
  5112. UpdateAlignment(init_settings.alignment,target_info.alignment);
  5113. {$ifdef arm}
  5114. if (init_settings.instructionset=is_thumb) and not(CPUARM_HAS_THUMB2 in cpu_capabilities[init_settings.cputype]) then
  5115. begin
  5116. init_settings.alignment.procalign:=2;
  5117. init_settings.alignment.jumpalign:=2;
  5118. init_settings.alignment.coalescealign:=2;
  5119. init_settings.alignment.loopalign:=2;
  5120. end;
  5121. {$endif arm}
  5122. if (cs_opt_size in init_settings.optimizerswitches) then
  5123. begin
  5124. init_settings.alignment.procalign:=1;
  5125. init_settings.alignment.jumpalign:=1;
  5126. init_settings.alignment.coalescealign:=1;
  5127. init_settings.alignment.loopalign:=1;
  5128. {$ifdef x86}
  5129. { constalignmax=1 keeps the executable and thus the memory foot print small but
  5130. all processors except x86 are really hurt by this or might even crash }
  5131. init_settings.alignment.constalignmax:=1;
  5132. {$endif x86}
  5133. end;
  5134. UpdateAlignment(init_settings.alignment,option.paraalignment);
  5135. set_system_macro('FPC_VERSION',version_nr);
  5136. set_system_macro('FPC_RELEASE',release_nr);
  5137. set_system_macro('FPC_PATCH',patch_nr);
  5138. set_system_macro('FPC_FULLVERSION',Format('%d%.02d%.02d',[StrToInt(version_nr),StrToInt(release_nr),StrToInt(patch_nr)]));
  5139. if target_info.system in systems_indirect_entry_information then
  5140. def_system_macro('FPC_HAS_INDIRECT_ENTRY_INFORMATION');
  5141. if not (tf_winlikewidestring in target_info.flags) then
  5142. def_system_macro('FPC_WIDESTRING_EQUAL_UNICODESTRING');
  5143. if tf_supports_packages in target_info.flags then
  5144. def_system_macro('FPC_HAS_DYNAMIC_PACKAGES');
  5145. if target_info.system in systems_indirect_var_imports then
  5146. def_system_macro('FPC_HAS_INDIRECT_VAR_ACCESS');
  5147. if cs_compilesystem in init_settings.moduleswitches then
  5148. for i:=low(tfeature) to high(tfeature) do
  5149. if i in features then
  5150. def_system_macro('FPC_HAS_FEATURE_'+featurestr[i]);
  5151. {$push}
  5152. {$warn 6018 off} { Unreachable code due to compile time evaluation }
  5153. if ControllerSupport and (target_info.system in (systems_embedded+systems_freertos)) and
  5154. (init_settings.controllertype<>ct_none) then
  5155. begin
  5156. with embedded_controllers[init_settings.controllertype] do
  5157. begin
  5158. set_system_macro('FPC_FLASHBASE',tostr(flashbase));
  5159. set_system_macro('FPC_FLASHSIZE',tostr(flashsize));
  5160. set_system_macro('FPC_SRAMBASE',tostr(srambase));
  5161. set_system_macro('FPC_SRAMSIZE',tostr(sramsize));
  5162. set_system_macro('FPC_EEPROMBASE',tostr(eeprombase));
  5163. set_system_macro('FPC_EEPROMSIZE',tostr(eepromsize));
  5164. set_system_macro('FPC_BOOTBASE',tostr(bootbase));
  5165. set_system_macro('FPC_BOOTSIZE',tostr(bootsize));
  5166. end;
  5167. end;
  5168. {$pop}
  5169. { as stackalign is not part of the alignment record, we do not need to define the others alignments for symmetry yet }
  5170. set_system_macro('FPC_STACKALIGNMENT',tostr(target_info.stackalign));
  5171. option.free;
  5172. Option:=nil;
  5173. clearstack_pocalls := [pocall_cdecl,pocall_cppdecl,pocall_syscall,pocall_mwpascal,pocall_sysv_abi_cdecl,pocall_ms_abi_cdecl{$ifdef z80},pocall_stdcall{$endif}];
  5174. cdecl_pocalls := [pocall_cdecl, pocall_cppdecl, pocall_mwpascal, pocall_sysv_abi_cdecl, pocall_ms_abi_cdecl];
  5175. if (tf_safecall_clearstack in target_info.flags) then
  5176. begin
  5177. include (cdecl_pocalls, pocall_safecall);
  5178. include (clearstack_pocalls, pocall_safecall)
  5179. end;
  5180. end;
  5181. initialization
  5182. coption:=toption;
  5183. finalization
  5184. if assigned(option) then
  5185. option.free;
  5186. end.