options.pas 172 KB

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