options.pas 187 KB

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