2
0

options.pas 185 KB

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