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