options.pas 171 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048
  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. {$if FPC_FULLVERSION<20700}ccharset{$else}charset{$endif},
  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. paratargetasm:=find_asm_by_string(More);
  1277. if paratargetasm=as_none then
  1278. IllegalPara(opt);
  1279. end;
  1280. 'b' :
  1281. begin
  1282. // Message1(option_obsolete_switch,'-b');
  1283. if UnsetBool(More,0,opt,false) then
  1284. begin
  1285. init_settings.moduleswitches:=init_settings.moduleswitches-[cs_browser];
  1286. init_settings.moduleswitches:=init_settings.moduleswitches-[cs_local_browser];
  1287. end
  1288. else
  1289. begin
  1290. init_settings.moduleswitches:=init_settings.moduleswitches+[cs_browser];
  1291. end;
  1292. if More<>'' then
  1293. if (More='l') or (More='l+') then
  1294. init_settings.moduleswitches:=init_settings.moduleswitches+[cs_local_browser]
  1295. else if More='l-' then
  1296. init_settings.moduleswitches:=init_settings.moduleswitches-[cs_local_browser]
  1297. else
  1298. IllegalPara(opt);
  1299. end;
  1300. 'B' :
  1301. do_build:=not UnSetBool(more,0,opt,true);
  1302. 'C' :
  1303. begin
  1304. j:=1;
  1305. while j<=length(more) do
  1306. begin
  1307. case more[j] of
  1308. '3' :
  1309. If UnsetBool(More, j, opt, false) then
  1310. exclude(init_settings.localswitches,cs_ieee_errors)
  1311. Else
  1312. include(init_settings.localswitches,cs_ieee_errors);
  1313. 'a' :
  1314. begin
  1315. s:=upper(copy(more,j+1,length(more)-j));
  1316. if not(SetAbiType(s,target_info.abi)) then
  1317. IllegalPara(opt);
  1318. ABISetExplicitly:=true;
  1319. break;
  1320. end;
  1321. 'b' :
  1322. begin
  1323. if UnsetBool(More, j, opt, false) then
  1324. target_info.endian:=endian_little
  1325. else
  1326. target_info.endian:=endian_big;
  1327. end;
  1328. 'c' :
  1329. begin
  1330. if not SetAktProcCall(upper(copy(more,j+1,length(more)-j)),init_settings.defproccall) then
  1331. IllegalPara(opt);
  1332. break;
  1333. end;
  1334. {$ifdef cpufpemu}
  1335. 'e' :
  1336. begin
  1337. If UnsetBool(More, j, opt, false) then
  1338. exclude(init_settings.moduleswitches,cs_fp_emulation)
  1339. Else
  1340. include(init_settings.moduleswitches,cs_fp_emulation);
  1341. end;
  1342. {$endif cpufpemu}
  1343. 'E' :
  1344. If UnsetBool(More, j, opt, false) then
  1345. exclude(init_settings.localswitches,cs_check_fpu_exceptions)
  1346. Else
  1347. include(init_settings.localswitches,cs_check_fpu_exceptions);
  1348. 'f' :
  1349. begin
  1350. s:=upper(copy(more,j+1,length(more)-j));
  1351. if not(SetFpuType(s,init_settings.fputype)) then
  1352. IllegalPara(opt);
  1353. FPUSetExplicitly:=True;
  1354. break;
  1355. end;
  1356. 'F' :
  1357. begin
  1358. if not SetMinFPConstPrec(copy(more,j+1,length(more)-j),init_settings.minfpconstprec) then
  1359. IllegalPara(opt);
  1360. break;
  1361. end;
  1362. 'g' :
  1363. begin
  1364. if tf_no_pic_supported in target_info.flags then
  1365. begin
  1366. { consume a possible '-' coming after it }
  1367. UnsetBool(More, j, opt, false);
  1368. message(scan_w_pic_ignored);
  1369. end
  1370. else if UnsetBool(More, j, opt, false) then
  1371. exclude(init_settings.moduleswitches,cs_create_pic)
  1372. else
  1373. include(init_settings.moduleswitches,cs_create_pic);
  1374. end;
  1375. 'h' :
  1376. begin
  1377. l:=pos(',',copy(more,j+1,length(more)-j));
  1378. if l=0 then
  1379. l:=length(more)-j+1;
  1380. val(copy(more,j+1,l-1),heapsize,code);
  1381. if (code<>0)
  1382. {$ifdef AVR}
  1383. or (heapsize<32)
  1384. {$else AVR}
  1385. or (heapsize<1024)
  1386. {$endif AVR}
  1387. then
  1388. IllegalPara(opt)
  1389. else if l<=length(more)-j then
  1390. begin
  1391. val(copy(more,j+l+1,length(more)),maxheapsize,code);
  1392. if code<>0 then
  1393. IllegalPara(opt)
  1394. else if (maxheapsize<heapsize) then
  1395. begin
  1396. message(scan_w_heapmax_lessthan_heapmin);
  1397. maxheapsize:=heapsize;
  1398. end;
  1399. end;
  1400. break;
  1401. end;
  1402. 'i' :
  1403. If UnsetBool(More, j, opt, false) then
  1404. exclude(init_settings.localswitches,cs_check_io)
  1405. else
  1406. include(init_settings.localswitches,cs_check_io);
  1407. {$ifdef arm}
  1408. 'I' :
  1409. begin
  1410. if (upper(copy(more,j+1,length(more)-j))='THUMB') and
  1411. { does selected CPU really understand thumb? }
  1412. (init_settings.cputype in cpu_has_thumb) then
  1413. init_settings.instructionset:=is_thumb
  1414. else if upper(copy(more,j+1,length(more)-j))='ARM' then
  1415. init_settings.instructionset:=is_arm
  1416. else
  1417. IllegalPara(opt);
  1418. break;
  1419. end;
  1420. {$endif arm}
  1421. {$ifdef llvm}
  1422. 'l':
  1423. begin
  1424. l:=j+1;
  1425. while l<=length(More) do
  1426. begin
  1427. case More[l] of
  1428. 'f':
  1429. begin
  1430. More:=copy(More,l+1,length(More));
  1431. disable:=Unsetbool(More,length(More)-1,opt,false);
  1432. case More of
  1433. 'lto':
  1434. begin
  1435. if not disable then
  1436. begin
  1437. include(init_settings.moduleswitches,cs_lto);
  1438. LTOExt:='.bc';
  1439. end
  1440. else
  1441. exclude(init_settings.moduleswitches,cs_lto);
  1442. end;
  1443. 'ltonosystem':
  1444. begin
  1445. if not disable then
  1446. begin
  1447. include(init_settings.globalswitches,cs_lto_nosystem);
  1448. end
  1449. else
  1450. exclude(init_settings.globalswitches,cs_lto_nosystem);
  1451. end;
  1452. else
  1453. begin
  1454. IllegalPara(opt);
  1455. end;
  1456. end;
  1457. l:=length(more)+1;
  1458. end;
  1459. 'v':
  1460. begin
  1461. init_settings.llvmversion:=llvmversion2enum(copy(More,l+1,length(More)));
  1462. if init_settings.llvmversion=llvmver_invalid then
  1463. begin
  1464. IllegalPara(opt);
  1465. end;
  1466. l:=length(More)+1;
  1467. end
  1468. else
  1469. begin
  1470. IllegalPara(opt);
  1471. end;
  1472. end;
  1473. end;
  1474. j:=l;
  1475. end;
  1476. {$endif llvm}
  1477. 'n' :
  1478. If UnsetBool(More, j, opt, false) then
  1479. exclude(init_settings.globalswitches,cs_link_nolink)
  1480. Else
  1481. include(init_settings.globalswitches,cs_link_nolink);
  1482. 'N' :
  1483. If UnsetBool(More, j, opt, false) then
  1484. exclude(init_settings.localswitches,cs_check_low_addr_load)
  1485. Else
  1486. include(init_settings.localswitches,cs_check_low_addr_load);
  1487. 'o' :
  1488. If UnsetBool(More, j, opt, false) then
  1489. exclude(init_settings.localswitches,cs_check_overflow)
  1490. Else
  1491. include(init_settings.localswitches,cs_check_overflow);
  1492. 'O' :
  1493. If UnsetBool(More, j, opt, false) then
  1494. exclude(init_settings.localswitches,cs_check_ordinal_size)
  1495. Else
  1496. include(init_settings.localswitches,cs_check_ordinal_size);
  1497. 'p' :
  1498. begin
  1499. s:=upper(copy(more,j+1,length(more)-j));
  1500. if not(Setcputype(s,init_settings)) then
  1501. IllegalPara(opt);
  1502. CPUSetExplicitly:=true;
  1503. break;
  1504. end;
  1505. 'P':
  1506. begin
  1507. delete(more,1,1);
  1508. case upper(copy(more,1,pos('=',more)-1)) of
  1509. 'PACKSET':
  1510. begin
  1511. delete(more,1,pos('=',more));
  1512. case more of
  1513. '0','DEFAULT','NORMAL':
  1514. init_settings.setalloc:=0;
  1515. '1','2','4','8':
  1516. init_settings.setalloc:=StrToInt(more);
  1517. else
  1518. IllegalPara(opt);
  1519. end
  1520. end;
  1521. 'PACKENUM':
  1522. begin
  1523. delete(more,1,pos('=',more));
  1524. case more of
  1525. '0','DEFAULT','NORMAL':
  1526. init_settings.packenum:=4;
  1527. '1','2','4':
  1528. init_settings.packenum:=StrToInt(more);
  1529. else
  1530. IllegalPara(opt);
  1531. end;
  1532. end;
  1533. 'PACKRECORD':
  1534. begin
  1535. delete(more,1,pos('=',more));
  1536. case more of
  1537. '0','DEFAULT','NORMAL':
  1538. init_settings.packrecords:=default_settings.packrecords;
  1539. '1','2','4','8','16','32':
  1540. init_settings.packrecords:=StrToInt(more);
  1541. else
  1542. IllegalPara(opt);
  1543. end;
  1544. end
  1545. else
  1546. IllegalPara(opt);
  1547. end;
  1548. end;
  1549. 'r' :
  1550. If UnsetBool(More, j, opt, false) then
  1551. exclude(init_settings.localswitches,cs_check_range)
  1552. Else
  1553. include(init_settings.localswitches,cs_check_range);
  1554. 'R' :
  1555. If UnsetBool(More, j, opt, false) then
  1556. begin
  1557. exclude(init_settings.localswitches,cs_check_range);
  1558. exclude(init_settings.localswitches,cs_check_object);
  1559. end
  1560. Else
  1561. begin
  1562. include(init_settings.localswitches,cs_check_range);
  1563. include(init_settings.localswitches,cs_check_object);
  1564. end;
  1565. 's' :
  1566. begin
  1567. val(copy(more,j+1,length(more)-j),stacksize,code);
  1568. if (code<>0)
  1569. {$ifdef cpu16bitaddr}
  1570. or (stacksize>=65521)
  1571. {$else cpu16bitaddr}
  1572. or (stacksize>=67107840)
  1573. {$endif cpu16bitaddr}
  1574. or (stacksize<1024) then
  1575. IllegalPara(opt);
  1576. break;
  1577. end;
  1578. 't' :
  1579. If UnsetBool(More, j, opt, false) then
  1580. exclude(init_settings.localswitches,cs_check_stack)
  1581. Else
  1582. include(init_settings.localswitches,cs_check_stack);
  1583. 'D' :
  1584. If UnsetBool(More, j, opt, false) then
  1585. exclude(init_settings.moduleswitches,cs_create_dynamic)
  1586. Else
  1587. include(init_settings.moduleswitches,cs_create_dynamic);
  1588. 'X' :
  1589. If UnsetBool(More, j, opt, false) then
  1590. exclude(init_settings.moduleswitches,cs_create_smart)
  1591. Else
  1592. include(init_settings.moduleswitches,cs_create_smart);
  1593. 'T' :
  1594. begin
  1595. if not UpdateTargetSwitchStr(copy(more,j+1,length(more)),init_settings.targetswitches,true) then
  1596. IllegalPara(opt);
  1597. break;
  1598. end;
  1599. 'v' :
  1600. If target_info.system in systems_jvm then
  1601. If UnsetBool(More, j, opt, false) then
  1602. exclude(init_settings.localswitches,cs_check_var_copyout)
  1603. Else
  1604. include(init_settings.localswitches,cs_check_var_copyout)
  1605. else
  1606. IllegalPara(opt);
  1607. 'V':
  1608. begin
  1609. s:=upper(copy(more,j+1,length(more)-j));
  1610. if s='GLOBAL-DYNAMIC' then
  1611. init_settings.tlsmodel:=tlsm_global_dynamic
  1612. else if s='LOCAL-EXEC' then
  1613. init_settings.tlsmodel:=tlsm_local_exec
  1614. else
  1615. IllegalPara(opt);
  1616. break;
  1617. end;
  1618. else
  1619. IllegalPara(opt);
  1620. end;
  1621. inc(j);
  1622. end;
  1623. end;
  1624. 'd' :
  1625. begin
  1626. l:=Pos(':=',more);
  1627. if l>0 then
  1628. hs:=copy(more,1,l-1)
  1629. else
  1630. hs:=more;
  1631. if (not is_identifier(hs)) then
  1632. begin
  1633. if hs='' then
  1634. Message1(option_missing_arg,'-d')
  1635. else
  1636. Message1(option_malformed_para,opt);
  1637. StopOptions(1);
  1638. end;
  1639. if l>0 then
  1640. begin
  1641. if cs_support_macro in init_settings.moduleswitches then
  1642. set_system_macro(hs,Copy(more,l+2,255))
  1643. else
  1644. set_system_compvar(hs,Copy(more,l+2,255));
  1645. end
  1646. else
  1647. def_system_macro(hs);
  1648. end;
  1649. 'D' :
  1650. begin
  1651. include(init_settings.globalswitches,cs_link_deffile);
  1652. j:=1;
  1653. while j<=length(more) do
  1654. begin
  1655. case more[j] of
  1656. 'd' :
  1657. begin
  1658. description:=Copy(more,j+1,255);
  1659. break;
  1660. end;
  1661. 'D' :
  1662. begin
  1663. datestr:=Copy(more,j+1,255);
  1664. break;
  1665. end;
  1666. 'T' :
  1667. begin
  1668. timestr:=Copy(more,j+1,255);
  1669. break;
  1670. end;
  1671. 'v' :
  1672. begin
  1673. dllversion:=Copy(more,j+1,255);
  1674. l:=pos('.',dllversion);
  1675. dllminor:=0;
  1676. error:=0;
  1677. if l>0 then
  1678. begin
  1679. val(copy(dllversion,l+1,255),minor,error);
  1680. if (error=0) and
  1681. (minor>=0) and (minor<=$ffff) then
  1682. dllminor:=minor
  1683. else
  1684. if error=0 then
  1685. error:=1;
  1686. end;
  1687. if l=0 then
  1688. l:=256;
  1689. dllmajor:=1;
  1690. major:=0;
  1691. if error=0 then
  1692. val(copy(dllversion,1,l-1),major,error);
  1693. if (error=0) and (major>=0) and (major<=$ffff) then
  1694. dllmajor:=major
  1695. else
  1696. if error=0 then
  1697. error:=1;
  1698. if error<>0 then
  1699. Message1(scan_w_wrong_version_ignored,dllversion);
  1700. break;
  1701. end;
  1702. 'w' :
  1703. usewindowapi:=true;
  1704. '-' :
  1705. begin
  1706. exclude(init_settings.globalswitches,cs_link_deffile);
  1707. usewindowapi:=false;
  1708. end;
  1709. else
  1710. IllegalPara(opt);
  1711. end;
  1712. inc(j);
  1713. end;
  1714. end;
  1715. 'e' :
  1716. exepath:=FixPath(More,true);
  1717. 'E' :
  1718. begin
  1719. if UnsetBool(More, 0, opt, true) then
  1720. exclude(init_settings.globalswitches,cs_link_nolink)
  1721. else
  1722. include(init_settings.globalswitches,cs_link_nolink);
  1723. end;
  1724. 'f' :
  1725. begin
  1726. if more='PIC' then
  1727. begin
  1728. if tf_no_pic_supported in target_info.flags then
  1729. message(scan_w_pic_ignored)
  1730. else
  1731. include(init_settings.moduleswitches,cs_create_pic)
  1732. end
  1733. else
  1734. IllegalPara(opt);
  1735. end;
  1736. 'F' :
  1737. begin
  1738. if more='' then
  1739. IllegalPara(opt);
  1740. c:=more[1];
  1741. Delete(more,1,1);
  1742. DefaultReplacements(More);
  1743. case c of
  1744. 'a' :
  1745. autoloadunits:=more;
  1746. 'c' :
  1747. begin
  1748. { if we first specify that the system code page should be
  1749. used and then explicitly specify a code page, unset the
  1750. flag that we're using the system code page again }
  1751. SetCompileModeSwitch('SYSTEMCODEPAGE-',true);
  1752. if (upper(more)='UTF8') or (upper(more)='UTF-8') then
  1753. init_settings.sourcecodepage:=CP_UTF8
  1754. else if not(cpavailable(more)) then
  1755. Message1(option_code_page_not_available,more)
  1756. else
  1757. init_settings.sourcecodepage:=codepagebyname(more);
  1758. include(init_settings.moduleswitches,cs_explicit_codepage);
  1759. end;
  1760. 'C' :
  1761. RCCompiler:=More;
  1762. 'd' :
  1763. if UnsetBool(more, 0, opt, true) then
  1764. init_settings.disabledircache:=false
  1765. else
  1766. init_settings.disabledircache:=true;
  1767. 'D' :
  1768. utilsdirectory:=FixPath(More,true);
  1769. 'e' :
  1770. SetRedirectFile(More);
  1771. 'E' :
  1772. OutputExeDir:=FixPath(More,true);
  1773. 'f' :
  1774. if (target_info.system in systems_darwin) then
  1775. if ispara then
  1776. ParaFrameworkPath.AddPath(More,false)
  1777. else
  1778. frameworksearchpath.AddPath(More,true)
  1779. {$ifdef XTENSA}
  1780. else if (target_info.system=system_xtensa_freertos) then
  1781. idfpath:=FixPath(More,true)
  1782. {$endif XTENSA}
  1783. else
  1784. IllegalPara(opt);
  1785. 'F' :
  1786. RCForceFPCRes:=true;
  1787. 'i' :
  1788. begin
  1789. if ispara then
  1790. ParaIncludePath.AddPath(More,false)
  1791. else
  1792. includesearchpath.AddPath(More,true);
  1793. end;
  1794. 'm' :
  1795. begin
  1796. s:=ExtractFileDir(more);
  1797. if TryStrToInt(ExtractFileName(more),j) then
  1798. begin
  1799. unicodemapping:=loadunicodemapping(More,More+'.txt',j);
  1800. if assigned(unicodemapping) then
  1801. registermapping(unicodemapping)
  1802. else
  1803. IllegalPara(opt);
  1804. end
  1805. else
  1806. IllegalPara(opt);
  1807. end;
  1808. 'M' :
  1809. unicodepath:=FixPath(More,true);
  1810. 'g' :
  1811. Message2(option_obsolete_switch_use_new,'-Fg','-Fl');
  1812. 'l' :
  1813. begin
  1814. if ispara then
  1815. ParaLibraryPath.AddLibraryPath(sysrootpath,More,false)
  1816. else
  1817. LibrarySearchPath.AddLibraryPath(sysrootpath,More,true)
  1818. end;
  1819. 'L' :
  1820. begin
  1821. if More<>'' then
  1822. ParaDynamicLinker:=More
  1823. else
  1824. IllegalPara(opt);
  1825. end;
  1826. 'N' :
  1827. begin
  1828. if more<>'' then
  1829. paranamespaces.insert(more)
  1830. else
  1831. illegalpara(opt);
  1832. end;
  1833. 'o' :
  1834. begin
  1835. if ispara then
  1836. ParaObjectPath.AddPath(More,false)
  1837. else
  1838. ObjectSearchPath.AddPath(More,true);
  1839. end;
  1840. 'P' :
  1841. begin
  1842. if ispara then
  1843. parapackages.add(more,nil)
  1844. else
  1845. add_package(more,true,true);
  1846. end;
  1847. 'p' :
  1848. begin
  1849. if ispara then
  1850. parapackagepath.AddPath(More,false)
  1851. else
  1852. packagesearchpath.AddPath(More,true);
  1853. end;
  1854. 'r' :
  1855. Msgfilename:=More;
  1856. 'R' :
  1857. ResCompiler:=More;
  1858. 'u' :
  1859. begin
  1860. if ispara then
  1861. ParaUnitPath.AddPath(More,false)
  1862. else
  1863. unitsearchpath.AddPath(More,true);
  1864. end;
  1865. 'U' :
  1866. OutputUnitDir:=FixPath(More,true);
  1867. 'W',
  1868. 'w':
  1869. begin
  1870. if More<>'' then
  1871. begin
  1872. DefaultReplacements(More);
  1873. D:=ExtractFilePath(More);
  1874. if (D<>'') then
  1875. D:=FixPath(D,True);
  1876. D:=D+ExtractFileName(More);
  1877. if (c='W') then
  1878. WpoFeedbackOutput:=D
  1879. else
  1880. WpoFeedbackInput:=D;
  1881. end
  1882. else
  1883. IllegalPara(opt);
  1884. end;
  1885. else
  1886. IllegalPara(opt);
  1887. end;
  1888. end;
  1889. 'g' :
  1890. begin
  1891. if UnsetBool(More, 0, opt, false) then
  1892. begin
  1893. exclude(init_settings.moduleswitches,cs_debuginfo);
  1894. exclude(init_settings.globalswitches,cs_use_heaptrc);
  1895. exclude(init_settings.globalswitches,cs_use_lineinfo);
  1896. exclude(init_settings.localswitches,cs_checkpointer);
  1897. paratargetdbg:=dbg_none;
  1898. localvartrashing := -1;
  1899. end
  1900. else
  1901. begin
  1902. include(init_settings.moduleswitches,cs_debuginfo);
  1903. if paratargetdbg=dbg_none then
  1904. paratargetdbg:=target_info.dbg;
  1905. end;
  1906. if not RelocSectionSetExplicitly then
  1907. RelocSection:=false;
  1908. j:=1;
  1909. while j<=length(more) do
  1910. begin
  1911. case more[j] of
  1912. 'c' :
  1913. begin
  1914. if UnsetBool(More, j, opt, false) then
  1915. exclude(init_settings.localswitches,cs_checkpointer)
  1916. else if (target_info.system in systems_support_checkpointer) then
  1917. begin
  1918. if do_release then
  1919. Message(option_gc_incompatible_with_release_flag)
  1920. else
  1921. include(init_settings.localswitches,cs_checkpointer);
  1922. end
  1923. else
  1924. UnsupportedPara('-gc');
  1925. end;
  1926. 'h' :
  1927. begin
  1928. if UnsetBool(More, j, opt, false) then
  1929. exclude(init_settings.globalswitches,cs_use_heaptrc)
  1930. else
  1931. begin
  1932. if cs_gdb_valgrind in init_settings.globalswitches then
  1933. Message2(option_valgrind_heaptrc_mismatch,'-gh', '-gv');
  1934. include(init_settings.globalswitches,cs_use_heaptrc);
  1935. end;
  1936. end;
  1937. 'l' :
  1938. begin
  1939. if UnsetBool(More, j, opt, false) then
  1940. exclude(init_settings.globalswitches,cs_use_lineinfo)
  1941. else
  1942. include(init_settings.globalswitches,cs_use_lineinfo);
  1943. end;
  1944. 'm' :
  1945. begin
  1946. paratargetdbg:=dbg_codeview;
  1947. end;
  1948. 'o' :
  1949. begin
  1950. if not UpdateDebugStr(copy(more,j+1,length(more)),init_settings.debugswitches) then
  1951. IllegalPara(opt);
  1952. break;
  1953. end;
  1954. 'p' :
  1955. begin
  1956. if UnsetBool(More, j, opt, false) then
  1957. exclude(init_settings.globalswitches,cs_stabs_preservecase)
  1958. else
  1959. include(init_settings.globalswitches,cs_stabs_preservecase);
  1960. end;
  1961. 's' :
  1962. begin
  1963. paratargetdbg:=dbg_stabs;
  1964. end;
  1965. 't' :
  1966. begin
  1967. if UnsetBool(More, j, opt, false) then
  1968. localvartrashing := -1
  1969. else
  1970. localvartrashing := (localvartrashing + 1) mod nroftrashvalues;
  1971. end;
  1972. 'v' :
  1973. begin
  1974. if UnsetBool(More, j, opt, false) then
  1975. exclude(init_settings.globalswitches,cs_gdb_valgrind)
  1976. else
  1977. begin
  1978. if cs_use_heaptrc in init_settings.globalswitches then
  1979. Message2(option_valgrind_heaptrc_mismatch,'-gh', '-gv');
  1980. include(init_settings.globalswitches,cs_gdb_valgrind);
  1981. end;
  1982. end;
  1983. 'w' :
  1984. begin
  1985. if (j<length(more)) and (more[j+1] in ['2','3','4']) then
  1986. begin
  1987. case more[j+1] of
  1988. '2': paratargetdbg:=dbg_dwarf2;
  1989. '3': paratargetdbg:=dbg_dwarf3;
  1990. '4': paratargetdbg:=dbg_dwarf4;
  1991. end;
  1992. inc(j);
  1993. end
  1994. else
  1995. paratargetdbg:=dbg_dwarf2;
  1996. end;
  1997. else
  1998. IllegalPara(opt);
  1999. end;
  2000. inc(j);
  2001. end;
  2002. end;
  2003. 'h' :
  2004. begin
  2005. NoPressEnter:=true;
  2006. if (More <> '') and (More [1] = 'F') then
  2007. begin
  2008. FPCHelpLines := true;
  2009. Delete (More, 1, 1);
  2010. FPCBinaryPath := More;
  2011. end;
  2012. WriteHelpPages;
  2013. end;
  2014. 'i' :
  2015. begin
  2016. if (More='') or
  2017. (More [1] in ['a', 'b', 'c', 'f', 'i', 'm', 'o', 'r', 't', 'u', 'w', 'x']) then
  2018. WriteInfo (More)
  2019. else
  2020. QuickInfo:=QuickInfo+More;
  2021. end;
  2022. 'I' :
  2023. begin
  2024. if ispara then
  2025. ParaIncludePath.AddPath(More,false)
  2026. else
  2027. includesearchpath.AddPath(More,false);
  2028. end;
  2029. 'k' :
  2030. begin
  2031. if more<>'' then
  2032. ParaLinkOptions:=ParaLinkOptions+' '+More
  2033. else
  2034. IllegalPara(opt);
  2035. end;
  2036. 'l' :
  2037. ParaLogo:=not UnSetBool(more,0,opt,true);
  2038. {$ifdef PREPROCWRITE}
  2039. 'm' :
  2040. parapreprocess:=not UnSetBool(more,0,opt,true);
  2041. {$endif PREPROCWRITE}
  2042. 'M' :
  2043. begin
  2044. more:=Upper(more);
  2045. if not SetCompileMode(more, true) then
  2046. if not SetCompileModeSwitch(more, true) then
  2047. IllegalPara(opt);
  2048. end;
  2049. 'n' :
  2050. begin
  2051. if More='' then
  2052. disable_configfile:=true
  2053. else
  2054. IllegalPara(opt);
  2055. end;
  2056. 'o' :
  2057. begin
  2058. if More<>'' then
  2059. begin
  2060. DefaultReplacements(More);
  2061. D:=ExtractFilePath(More);
  2062. if (D<>'') then
  2063. OutputExeDir:=FixPath(D,True);
  2064. OutputFileName:=ExtractFileName(More);
  2065. end
  2066. else
  2067. IllegalPara(opt);
  2068. end;
  2069. 'O' :
  2070. begin
  2071. j:=1;
  2072. while j<=length(more) do
  2073. begin
  2074. case more[j] of
  2075. '1' :
  2076. init_settings.optimizerswitches:=init_settings.optimizerswitches+level1optimizerswitches;
  2077. '2' :
  2078. init_settings.optimizerswitches:=init_settings.optimizerswitches+level2optimizerswitches;
  2079. '3' :
  2080. init_settings.optimizerswitches:=init_settings.optimizerswitches+level3optimizerswitches;
  2081. '4' :
  2082. init_settings.optimizerswitches:=init_settings.optimizerswitches+level4optimizerswitches;
  2083. 'a' :
  2084. begin
  2085. if not(UpdateAlignmentStr(Copy(Opt,j+3,255),ParaAlignment)) then
  2086. IllegalPara(opt);
  2087. break;
  2088. end;
  2089. 's' :
  2090. include(init_settings.optimizerswitches,cs_opt_size);
  2091. 'p' :
  2092. begin
  2093. if not Setoptimizecputype(copy(more,j+1,length(more)),init_settings.optimizecputype) then
  2094. begin
  2095. OptCPUSetExplicitly:=true;
  2096. { Give warning for old i386 switches }
  2097. if (Length(More)-j=1) and
  2098. (More[j+1]>='1') and (More[j+1]<='5')then
  2099. Message2(option_obsolete_switch_use_new,'-Op<nr>','-Op<name>')
  2100. else
  2101. IllegalPara(opt);
  2102. end;
  2103. break;
  2104. end;
  2105. 'o' :
  2106. begin
  2107. if not UpdateOptimizerStr(copy(more,j+1,length(more)),init_settings.optimizerswitches) then
  2108. IllegalPara(opt);
  2109. break;
  2110. end;
  2111. '-' :
  2112. begin
  2113. init_settings.optimizerswitches:=[];
  2114. FillChar(ParaAlignment,sizeof(ParaAlignment),0);
  2115. end;
  2116. { Obsolete switches }
  2117. 'g' :
  2118. Message2(option_obsolete_switch_use_new,'-Og','-Os');
  2119. 'G' :
  2120. Message1(option_obsolete_switch,'-OG');
  2121. 'r' :
  2122. Message2(option_obsolete_switch_use_new,'-Or','-O2 or -Ooregvar');
  2123. 'u' :
  2124. Message2(option_obsolete_switch_use_new,'-Ou','-Oouncertain');
  2125. 'w' :
  2126. begin
  2127. if not UpdateWpoStr(copy(more,j+1,length(more)),init_settings.dowpoptimizerswitches) then
  2128. IllegalPara(opt);
  2129. break;
  2130. end;
  2131. 'W' :
  2132. begin
  2133. if not UpdateWpoStr(copy(more,j+1,length(more)),init_settings.genwpoptimizerswitches) then
  2134. IllegalPara(opt);
  2135. break;
  2136. end;
  2137. else
  2138. IllegalPara(opt);
  2139. end;
  2140. inc(j);
  2141. end;
  2142. end;
  2143. 'p' :
  2144. begin
  2145. if UnsetBool(More, 0, opt, false) then
  2146. begin
  2147. init_settings.moduleswitches:=init_settings.moduleswitches-[cs_profile];
  2148. undef_system_macro('FPC_PROFILE');
  2149. end
  2150. else
  2151. if Length(More)=0 then
  2152. IllegalPara(opt)
  2153. else
  2154. case more[1] of
  2155. 'g' : if UnsetBool(more, 1, opt, false) then
  2156. begin
  2157. exclude(init_settings.moduleswitches,cs_profile);
  2158. undef_system_macro('FPC_PROFILE');
  2159. end
  2160. else if (target_info.system in supported_targets_pg) then
  2161. begin
  2162. include(init_settings.moduleswitches,cs_profile);
  2163. def_system_macro('FPC_PROFILE');
  2164. end
  2165. else
  2166. UnsupportedPara('-pg');
  2167. else
  2168. IllegalPara(opt);
  2169. end;
  2170. end;
  2171. 'P' :
  2172. begin
  2173. { used to select the target processor with the "fpc" binary;
  2174. give an error if it's not the target architecture supported by
  2175. this compiler binary (will be verified after the target_info
  2176. is set) }
  2177. processorstr:=More;
  2178. end;
  2179. 'R' :
  2180. begin
  2181. if not SetAsmReadMode(More,init_settings.asmmode) then
  2182. IllegalPara(opt);
  2183. end;
  2184. 's' :
  2185. begin
  2186. if UnsetBool(More, 0, opt, false) then
  2187. begin
  2188. init_settings.globalswitches:=init_settings.globalswitches-[cs_asm_extern,cs_link_extern,cs_link_nolink];
  2189. if more<>'' then
  2190. IllegalPara(opt);
  2191. end
  2192. else
  2193. begin
  2194. init_settings.globalswitches:=init_settings.globalswitches+[cs_asm_extern,cs_link_extern,cs_link_nolink];
  2195. if more='h' then
  2196. init_settings.globalswitches:=init_settings.globalswitches-[cs_link_on_target,cs_assemble_on_target]
  2197. else if more='t' then
  2198. init_settings.globalswitches:=init_settings.globalswitches+[cs_link_on_target,cs_assemble_on_target]
  2199. else if more='T' then
  2200. init_settings.globalswitches:=init_settings.globalswitches+[cs_link_on_target]-[cs_asm_extern]
  2201. else if more='r' then
  2202. init_settings.globalswitches:=init_settings.globalswitches+[cs_asm_leave,cs_no_regalloc]
  2203. else if more<>'' then
  2204. IllegalPara(opt);
  2205. end;
  2206. end;
  2207. 'S' :
  2208. begin
  2209. if more='' then
  2210. IllegalPara(opt);
  2211. if more[1]='I' then
  2212. begin
  2213. {$ifdef jvm}
  2214. UnsupportedPara('-SI');
  2215. {$endif}
  2216. if upper(more)='ICOM' then
  2217. init_settings.interfacetype:=it_interfacecom
  2218. else if upper(more)='ICORBA' then
  2219. init_settings.interfacetype:=it_interfacecorba
  2220. else
  2221. IllegalPara(opt);
  2222. end
  2223. else
  2224. begin
  2225. j:=1;
  2226. while j<=length(more) do
  2227. begin
  2228. case more[j] of
  2229. '2' : //an alternative to -Mobjfpc
  2230. SetCompileMode('OBJFPC',true);
  2231. 'a' :
  2232. If UnsetBool(More, j, opt, false) then
  2233. exclude(init_settings.localswitches,cs_do_assertion)
  2234. else
  2235. include(init_settings.localswitches,cs_do_assertion);
  2236. 'c' :
  2237. If UnsetBool(More, j, opt, false) then
  2238. exclude(init_settings.moduleswitches,cs_support_c_operators)
  2239. else
  2240. include(init_settings.moduleswitches,cs_support_c_operators);
  2241. 'C':
  2242. If UnsetBool(More, j, opt, false) then
  2243. exclude(init_settings.localswitches,cs_check_all_case_coverage)
  2244. else
  2245. include(init_settings.localswitches,cs_check_all_case_coverage);
  2246. 'd' : //an alternative to -Mdelphi
  2247. SetCompileMode('DELPHI',true);
  2248. 'e' :
  2249. begin
  2250. SetErrorFlags(copy(more,j+1,length(more)));
  2251. break;
  2252. end;
  2253. 'f' :
  2254. begin
  2255. if not(cs_compilesystem in init_settings.moduleswitches) then
  2256. Message(option_features_only_for_system_unit);
  2257. inc(j);
  2258. if more[j]='-' then
  2259. begin
  2260. if length(more)>j then
  2261. IllegalPara(opt)
  2262. else
  2263. features:=[];
  2264. end
  2265. else
  2266. begin
  2267. if (HandleFeature(upper(copy(more,j,length(more)-j+1)))) then
  2268. j:=length(more)
  2269. else
  2270. IllegalPara(opt);
  2271. end;
  2272. end;
  2273. 'g' :
  2274. If UnsetBool(More, j, opt, false) then
  2275. exclude(init_settings.moduleswitches,cs_support_goto)
  2276. else
  2277. include(init_settings.moduleswitches,cs_support_goto);
  2278. 'h' :
  2279. If UnsetBool(More, j, opt, false) then
  2280. exclude(init_settings.localswitches,cs_refcountedstrings)
  2281. else
  2282. include(init_settings.localswitches,cs_refcountedstrings);
  2283. 'i' :
  2284. If UnsetBool(More, j, opt, false) then
  2285. exclude(init_settings.localswitches,cs_do_inline)
  2286. else
  2287. include(init_settings.localswitches,cs_do_inline);
  2288. 'j' :
  2289. If UnsetBool(More, j, opt, false) then
  2290. exclude(init_settings.localswitches,cs_typed_const_writable)
  2291. else
  2292. include(init_settings.localswitches,cs_typed_const_writable);
  2293. 'k' :
  2294. If UnsetBool(More, j, opt, false) then
  2295. exclude(init_settings.globalswitches,cs_load_fpcylix_unit)
  2296. else
  2297. include(init_settings.globalswitches,cs_load_fpcylix_unit);
  2298. 'm' :
  2299. If UnsetBool(More, j, opt, false) then
  2300. exclude(init_settings.moduleswitches,cs_support_macro)
  2301. else
  2302. include(init_settings.moduleswitches,cs_support_macro);
  2303. 'o' : //an alternative to -Mtp
  2304. SetCompileMode('TP',true);
  2305. 'r' :
  2306. If UnsetBool(More, j, opt, false) then
  2307. exclude(init_settings.globalswitches,cs_transparent_file_names)
  2308. else
  2309. include(init_settings.globalswitches,cs_transparent_file_names);
  2310. {$ifdef gpc_mode}
  2311. 'p' : //an alternative to -Mgpc
  2312. SetCompileMode('GPC',true);
  2313. {$endif}
  2314. 's' :
  2315. If UnsetBool(More, j, opt, false) then
  2316. exclude(init_settings.globalswitches,cs_constructor_name)
  2317. else
  2318. include(init_settings.globalswitches,cs_constructor_name);
  2319. 't' :
  2320. Message1(option_obsolete_switch,'-St');
  2321. 'v' :
  2322. If UnsetBool(More, j, opt, false) then
  2323. exclude(init_settings.globalswitches,cs_support_vectors)
  2324. else
  2325. include(init_settings.globalswitches,cs_support_vectors);
  2326. 'x' :
  2327. If UnsetBool(More, j, opt, false) then
  2328. SetCompileModeSwitch('EXCEPTIONS-',true)
  2329. else
  2330. SetCompileModeSwitch('EXCEPTIONS',true);
  2331. 'y' :
  2332. If UnsetBool(More, j, opt, false) then
  2333. exclude(init_settings.localswitches,cs_typed_addresses)
  2334. else
  2335. include(init_settings.localswitches,cs_typed_addresses);
  2336. '-' :
  2337. begin
  2338. init_settings.globalswitches:=init_settings.globalswitches - [cs_constructor_name,cs_support_exceptions,
  2339. cs_support_vectors,cs_load_fpcylix_unit];
  2340. init_settings.localswitches:=init_settings.localswitches - [cs_do_assertion,cs_do_inline, cs_refcountedstrings,
  2341. cs_typed_addresses];
  2342. init_settings.moduleswitches:=init_settings.moduleswitches - [cs_support_c_operators, cs_support_goto,
  2343. cs_support_macro];
  2344. end;
  2345. else
  2346. IllegalPara(opt);
  2347. end;
  2348. inc(j);
  2349. end;
  2350. end;
  2351. end;
  2352. 'T' :
  2353. begin
  2354. more:=Upper(More);
  2355. if paratarget=system_none then
  2356. begin
  2357. { remove old target define }
  2358. TargetOptions(false);
  2359. { load new target }
  2360. paratarget:=find_system_by_string(More);
  2361. if paratarget<>system_none then
  2362. set_target(paratarget)
  2363. else
  2364. IllegalPara(opt);
  2365. { set new define }
  2366. TargetOptions(true);
  2367. end
  2368. else
  2369. if More<>upper(target_info.shortname) then
  2370. Message1(option_target_is_already_set,target_info.shortname);
  2371. end;
  2372. 'u' :
  2373. if is_identifier(more) then
  2374. undef_system_macro(more)
  2375. else
  2376. begin
  2377. if (more='') then
  2378. Message1(option_missing_arg,'-u')
  2379. else
  2380. Message1(option_malformed_para,opt);
  2381. StopOptions(1);
  2382. end;
  2383. 'U' :
  2384. begin
  2385. j:=1;
  2386. while j<=length(more) do
  2387. begin
  2388. case more[j] of
  2389. {$ifdef UNITALIASES}
  2390. 'a' :
  2391. begin
  2392. AddUnitAlias(Copy(More,j+1,255));
  2393. break;
  2394. end;
  2395. {$endif UNITALIASES}
  2396. 'n' :
  2397. exclude(init_settings.globalswitches,cs_check_unit_name);
  2398. 'p' :
  2399. begin
  2400. Message2(option_obsolete_switch_use_new,'-Up','-Fu');
  2401. break;
  2402. end;
  2403. 'r' :
  2404. begin
  2405. do_release:=true;
  2406. if (cs_checkpointer in init_settings.localswitches) then
  2407. begin
  2408. Message(option_gc_incompatible_with_release_flag);
  2409. exclude(init_settings.localswitches,cs_checkpointer);
  2410. end;
  2411. end;
  2412. 's' :
  2413. include(init_settings.moduleswitches,cs_compilesystem);
  2414. '-' :
  2415. begin
  2416. exclude(init_settings.moduleswitches,cs_compilesystem);
  2417. exclude(init_settings.globalswitches,cs_check_unit_name);
  2418. end;
  2419. else
  2420. IllegalPara(opt);
  2421. end;
  2422. inc(j);
  2423. end;
  2424. end;
  2425. 'v' :
  2426. begin
  2427. if not setverbosity(More) then
  2428. IllegalPara(opt);
  2429. end;
  2430. 'V' : ; { Ignore used by fpc }
  2431. 'W' :
  2432. begin
  2433. j:=1;
  2434. while j<=length(More) do
  2435. begin
  2436. case More[j] of
  2437. 'A':
  2438. begin
  2439. if target_info.system in systems_all_windows then
  2440. begin
  2441. if UnsetBool(More, j, opt, false) then
  2442. SetApptype(app_cui)
  2443. else
  2444. SetApptype(app_native);
  2445. end
  2446. else
  2447. IllegalPara(opt);
  2448. end;
  2449. 'b':
  2450. begin
  2451. if target_info.system in systems_darwin then
  2452. begin
  2453. if UnsetBool(More, j, opt, false) then
  2454. SetApptype(app_cui)
  2455. else
  2456. SetApptype(app_bundle)
  2457. end
  2458. else
  2459. IllegalPara(opt);
  2460. end;
  2461. 'B':
  2462. begin
  2463. if target_info.system in systems_all_windows+systems_symbian+[system_z80_zxspectrum] then
  2464. begin
  2465. { -WB200000 means set trefered base address
  2466. to $200000, but does not change relocsection boolean
  2467. this way we can create both relocatble and
  2468. non relocatable DLL at a specific base address PM }
  2469. if (length(More)>j) then
  2470. begin
  2471. val('$'+Copy(More,j+1,255),imagebase,code);
  2472. if code<>0 then
  2473. IllegalPara(opt);
  2474. ImageBaseSetExplicity:=true;
  2475. end
  2476. else
  2477. begin
  2478. RelocSection:=true;
  2479. RelocSectionSetExplicitly:=true;
  2480. end;
  2481. break;
  2482. end
  2483. else
  2484. IllegalPara(opt);
  2485. end;
  2486. 'C':
  2487. begin
  2488. if target_info.system in systems_all_windows+systems_os2+systems_macos then
  2489. begin
  2490. if UnsetBool(More, j, opt, false) then
  2491. SetApptype(app_gui)
  2492. else
  2493. SetApptype(app_cui);
  2494. end
  2495. else
  2496. IllegalPara(opt);
  2497. end;
  2498. 'D':
  2499. begin
  2500. if target_info.system in systems_all_windows then
  2501. begin
  2502. UseDeffileForExports:=not UnsetBool(More, j, opt, false);
  2503. UseDeffileForExportsSetExplicitly:=true;
  2504. end
  2505. else
  2506. IllegalPara(opt);
  2507. end;
  2508. 'e':
  2509. begin
  2510. if (target_info.system in systems_darwin) then
  2511. begin
  2512. set_target_res(res_ext);
  2513. target_info.resobjext:='.fpcres';
  2514. end
  2515. else
  2516. IllegalPara(opt);
  2517. end;
  2518. 'F':
  2519. begin
  2520. if target_info.system in systems_os2 then
  2521. begin
  2522. if UnsetBool(More, j, opt, false) then
  2523. SetApptype(app_cui)
  2524. else
  2525. SetApptype(app_fs);
  2526. end
  2527. else
  2528. IllegalPara(opt);
  2529. end;
  2530. 'G':
  2531. begin
  2532. if target_info.system in systems_all_windows+systems_os2+systems_macos then
  2533. begin
  2534. if UnsetBool(More, j, opt, false) then
  2535. SetApptype(app_cui)
  2536. else
  2537. SetApptype(app_gui);
  2538. end
  2539. else
  2540. IllegalPara(opt);
  2541. end;
  2542. {$if defined(i8086)}
  2543. 'h':
  2544. begin
  2545. if UnsetBool(More, j, opt, false) then
  2546. exclude(init_settings.moduleswitches,cs_huge_code)
  2547. else
  2548. include(init_settings.moduleswitches,cs_huge_code);
  2549. end;
  2550. {$endif defined(i8086)}
  2551. 'I':
  2552. begin
  2553. if target_info.system in systems_all_windows then
  2554. begin
  2555. GenerateImportSection:=not UnsetBool(More,j,opt,false);
  2556. GenerateImportSectionSetExplicitly:=true;
  2557. end
  2558. else
  2559. IllegalPara(opt);
  2560. end;
  2561. 'i':
  2562. begin
  2563. if (target_info.system in systems_darwin) then
  2564. begin
  2565. set_target_res(res_macho);
  2566. target_info.resobjext:=
  2567. targetinfos[target_info.system]^.resobjext;
  2568. end
  2569. else
  2570. IllegalPara(opt);
  2571. end;
  2572. 'm':
  2573. begin
  2574. {$if defined(i8086)}
  2575. if (target_info.system in [system_i8086_msdos,system_i8086_win16,system_i8086_embedded]) then
  2576. begin
  2577. case Upper(Copy(More,j+1,255)) of
  2578. 'TINY': init_settings.x86memorymodel:=mm_tiny;
  2579. 'SMALL': init_settings.x86memorymodel:=mm_small;
  2580. 'MEDIUM': init_settings.x86memorymodel:=mm_medium;
  2581. 'COMPACT': init_settings.x86memorymodel:=mm_compact;
  2582. 'LARGE': init_settings.x86memorymodel:=mm_large;
  2583. 'HUGE': init_settings.x86memorymodel:=mm_huge;
  2584. else
  2585. IllegalPara(opt);
  2586. end;
  2587. break;
  2588. end
  2589. else
  2590. {$endif defined(i8086)}
  2591. IllegalPara(opt);
  2592. end;
  2593. 'M':
  2594. begin
  2595. if (target_info.system in (systems_darwin-[system_i386_iphonesim,system_arm_ios,system_aarch64_ios,system_x86_64_iphonesim])) and
  2596. ParseMacVersionMin(MacOSXVersionMin,iPhoneOSVersionMin,'MAC_OS_X_VERSION_MIN_REQUIRED',copy(More,2,255),false) then
  2597. begin
  2598. break;
  2599. end
  2600. else
  2601. IllegalPara(opt);
  2602. end;
  2603. 'N':
  2604. begin
  2605. if target_info.system in systems_all_windows then
  2606. begin
  2607. RelocSection:=UnsetBool(More,j,opt,false);
  2608. RelocSectionSetExplicitly:=true;
  2609. end
  2610. else
  2611. IllegalPara(opt);
  2612. end;
  2613. 'p':
  2614. begin
  2615. {$push}
  2616. {$warn 6018 off} { Unreachable code due to compile time evaluation }
  2617. if ((target_info.system in systems_embedded) or (target_info.system in systems_freertos)) and
  2618. ControllerSupport then
  2619. begin
  2620. s:=upper(copy(more,j+1,length(more)-j));
  2621. if not(SetControllerType(s,init_settings.controllertype)) then
  2622. IllegalPara(opt)
  2623. else
  2624. begin
  2625. if init_settings.cputype<>embedded_controllers[init_settings.controllertype].cputype then
  2626. begin
  2627. Message(scan_n_changecputype);
  2628. init_settings.cputype:=embedded_controllers[init_settings.controllertype].cputype;
  2629. end;
  2630. end;
  2631. break;
  2632. end
  2633. else
  2634. IllegalPara(opt);
  2635. {$pop}
  2636. end;
  2637. 'P':
  2638. begin
  2639. if (target_info.system in [system_i386_iphonesim,system_arm_ios,system_aarch64_ios,system_x86_64_iphonesim]) and
  2640. ParseMacVersionMin(iPhoneOSVersionMin,MacOSXVersionMin,'IPHONE_OS_VERSION_MIN_REQUIRED',copy(More,2,255),true) then
  2641. begin
  2642. break;
  2643. end
  2644. else
  2645. IllegalPara(opt);
  2646. end;
  2647. {$if defined(m68k)}
  2648. 'L':
  2649. begin
  2650. if (target_info.system in [system_m68k_sinclairql]) then
  2651. sinclairql_vlink_experimental:=false
  2652. else
  2653. IllegalPara(opt);
  2654. end;
  2655. 'Q':
  2656. begin
  2657. if (target_info.system in [system_m68k_sinclairql]) then
  2658. begin
  2659. sinclairql_metadata_format:=Upper(Copy(More,j+1,255));
  2660. case sinclairql_metadata_format of
  2661. 'QHDR', 'XTCC': ; { allowed formats }
  2662. else
  2663. IllegalPara(opt);
  2664. end;
  2665. break;
  2666. end
  2667. else
  2668. IllegalPara(opt);
  2669. end;
  2670. {$endif defined(m68k)}
  2671. 'R':
  2672. begin
  2673. if target_info.system in systems_all_windows then
  2674. begin
  2675. { support -WR+ / -WR- as synonyms to -WR / -WN }
  2676. RelocSection:=not UnsetBool(More,j,opt,false);
  2677. RelocSectionSetExplicitly:=true;
  2678. end
  2679. else
  2680. IllegalPara(opt);
  2681. end;
  2682. 't':
  2683. begin
  2684. {$if defined(i8086)}
  2685. if (target_info.system in [system_i8086_msdos,system_i8086_embedded]) then
  2686. begin
  2687. case Upper(Copy(More,j+1,255)) of
  2688. 'EXE': SetAppType(app_cui);
  2689. 'COM': SetAppType(app_com);
  2690. else
  2691. IllegalPara(opt);
  2692. end;
  2693. break;
  2694. end
  2695. else
  2696. {$endif defined(i8086)}
  2697. IllegalPara(opt);
  2698. end;
  2699. 'T':
  2700. begin
  2701. if target_info.system in systems_macos then
  2702. begin
  2703. if UnsetBool(More, j, opt, false) then
  2704. SetApptype(app_cui)
  2705. else
  2706. SetApptype(app_tool);
  2707. end
  2708. else
  2709. IllegalPara(opt);
  2710. end;
  2711. 'X':
  2712. begin
  2713. if (target_info.system in systems_linux) then
  2714. begin
  2715. if UnsetBool(More, j, opt, false) then
  2716. exclude(init_settings.moduleswitches,cs_executable_stack)
  2717. else
  2718. include(init_settings.moduleswitches,cs_executable_stack)
  2719. end
  2720. else
  2721. IllegalPara(opt);
  2722. end;
  2723. else
  2724. IllegalPara(opt);
  2725. end;
  2726. inc(j);
  2727. end;
  2728. end;
  2729. 'X' :
  2730. begin
  2731. j:=1;
  2732. while j<=length(more) do
  2733. begin
  2734. case More[j] of
  2735. '9' :
  2736. begin
  2737. if target_info.system in systems_linux then
  2738. begin
  2739. if UnsetBool(More, j, opt, false) then
  2740. exclude(init_settings.globalswitches,cs_link_pre_binutils_2_19)
  2741. else
  2742. include(init_settings.globalswitches,cs_link_pre_binutils_2_19);
  2743. end
  2744. else
  2745. IllegalPara(opt);
  2746. end;
  2747. 'a' :
  2748. begin
  2749. If UnsetBool(More, j, opt, false) then
  2750. exclude(init_settings.globalswitches,cs_large)
  2751. else
  2752. include(init_settings.globalswitches,cs_large);
  2753. end;
  2754. 'c' : Cshared:=TRUE;
  2755. 'd' : Dontlinkstdlibpath:=TRUE;
  2756. 'e' :
  2757. begin
  2758. If UnsetBool(More, j, opt, false) then
  2759. exclude(init_settings.globalswitches,cs_link_extern)
  2760. else
  2761. include(init_settings.globalswitches,cs_link_extern);
  2762. end;
  2763. 'f' :
  2764. include(init_settings.globalswitches,cs_link_pthread);
  2765. 'g' :
  2766. begin
  2767. If UnsetBool(More, j, opt, false) then
  2768. exclude(init_settings.globalswitches,cs_link_separate_dbg_file)
  2769. else
  2770. include(init_settings.globalswitches,cs_link_separate_dbg_file);
  2771. end;
  2772. 'i' :
  2773. begin
  2774. If UnsetBool(More, j, opt, false) then
  2775. include(init_settings.globalswitches,cs_link_extern)
  2776. else
  2777. exclude(init_settings.globalswitches,cs_link_extern);
  2778. end;
  2779. 'n' :
  2780. begin
  2781. If UnsetBool(More, j, opt, false) then
  2782. exclude(init_settings.globalswitches,cs_link_native)
  2783. else
  2784. include(init_settings.globalswitches,cs_link_native);
  2785. end;
  2786. {$ifdef llvm}
  2787. 'l' :
  2788. begin
  2789. if j=length(more) then
  2790. IllegalPara(opt)
  2791. else
  2792. begin
  2793. case more[j+1] of
  2794. 'S':
  2795. begin
  2796. llvmutilssuffix:=copy(more,j+2,length(more));
  2797. j:=length(more);
  2798. end
  2799. else
  2800. IllegalPara(opt);
  2801. end;
  2802. end;
  2803. end;
  2804. {$endif}
  2805. 'm' :
  2806. begin
  2807. If UnsetBool(More, j, opt, false) then
  2808. exclude(init_settings.globalswitches,cs_link_map)
  2809. else
  2810. include(init_settings.globalswitches,cs_link_map);
  2811. end;
  2812. 'p' : ; { Ignore used by fpc.pp }
  2813. 'r' :
  2814. begin
  2815. if (target_info.system in suppported_targets_x_smallr) then
  2816. begin
  2817. rlinkpath:=Copy(more,2,length(More)-1);
  2818. DefaultReplacements(rlinkpath);
  2819. end
  2820. else
  2821. IgnoredPara('-Xr');
  2822. more:='';
  2823. end;
  2824. 'R' :
  2825. begin
  2826. sysrootpath:=copy(more,2,length(more)-1);
  2827. defaultreplacements(sysrootpath);
  2828. more:='';
  2829. end;
  2830. 's' :
  2831. begin
  2832. If UnsetBool(More, j, opt, false) then
  2833. exclude(init_settings.globalswitches,cs_link_strip)
  2834. else
  2835. include(init_settings.globalswitches,cs_link_strip);
  2836. end;
  2837. 't' :
  2838. include(init_settings.globalswitches,cs_link_staticflag);
  2839. 'u' :
  2840. begin
  2841. if target_info.system in systems_support_uf2 then
  2842. begin
  2843. if UnsetBool(More, j, opt, false) then
  2844. exclude(init_settings.globalswitches,cs_generate_uf2)
  2845. else
  2846. include(init_settings.globalswitches,cs_generate_uf2);
  2847. end
  2848. else
  2849. IgnoredPara('-Xu');
  2850. end;
  2851. 'v' :
  2852. begin
  2853. If UnsetBool(More, j, opt, false) then
  2854. exclude(init_settings.globalswitches,cs_link_opt_vtable)
  2855. else
  2856. include(init_settings.globalswitches,cs_link_opt_vtable);
  2857. end;
  2858. 'D' :
  2859. begin
  2860. def_system_macro('FPC_LINK_DYNAMIC');
  2861. undef_system_macro('FPC_LINK_SMART');
  2862. undef_system_macro('FPC_LINK_STATIC');
  2863. exclude(init_settings.globalswitches,cs_link_static);
  2864. exclude(init_settings.globalswitches,cs_link_smart);
  2865. include(init_settings.globalswitches,cs_link_shared);
  2866. LinkTypeSetExplicitly:=true;
  2867. end;
  2868. 'M' :
  2869. begin
  2870. mainaliasname:=Copy(more,2,length(More)-1);
  2871. More:='';
  2872. end;
  2873. 'P' :
  2874. begin
  2875. utilsprefix:=Copy(more,2,length(More)-1);
  2876. DefaultReplacements(utilsprefix);
  2877. More:='';
  2878. end;
  2879. 'L' : begin // -XLO is link order -XLA is link alias. -XLD avoids load defaults.
  2880. // these are not aggregable.
  2881. if (j=length(more)) or not (more[j+1] in ['O','A','D']) then
  2882. IllegalPara(opt)
  2883. else
  2884. begin
  2885. case more[j+1] of
  2886. 'A' : begin
  2887. s:=Copy(more,3,length(More)-2);
  2888. if not LinkLibraryAliases.AddDep(s) Then
  2889. IllegalPara(opt);
  2890. end;
  2891. 'O' : begin
  2892. s:=Copy(more,3,length(More)-2);
  2893. if not LinkLibraryOrder.AddWeight(s) Then
  2894. IllegalPara(opt);
  2895. end;
  2896. 'D' : include(init_settings.globalswitches,cs_link_no_default_lib_order)
  2897. else
  2898. IllegalPara(opt);
  2899. end; {case}
  2900. j:=length(more);
  2901. end; {else begin}
  2902. end;
  2903. 'S' :
  2904. begin
  2905. ForceStaticLinking;
  2906. end;
  2907. 'V' :
  2908. begin
  2909. if UnsetBool(More, j, opt, false) then
  2910. exclude(init_settings.globalswitches,cs_link_vlink)
  2911. else
  2912. begin
  2913. include(init_settings.globalswitches,cs_link_vlink);
  2914. include(init_settings.globalswitches,cs_link_extern);
  2915. end;
  2916. LinkerSetExplicitly:=true;
  2917. end;
  2918. 'X' :
  2919. begin
  2920. def_system_macro('FPC_LINK_SMART');
  2921. undef_system_macro('FPC_LINK_STATIC');
  2922. undef_system_macro('FPC_LINK_DYNAMIC');
  2923. exclude(init_settings.globalswitches,cs_link_static);
  2924. include(init_settings.globalswitches,cs_link_smart);
  2925. exclude(init_settings.globalswitches,cs_link_shared);
  2926. LinkTypeSetExplicitly:=true;
  2927. end;
  2928. '-' :
  2929. begin
  2930. exclude(init_settings.globalswitches,cs_link_staticflag);
  2931. exclude(init_settings.globalswitches,cs_link_strip);
  2932. exclude(init_settings.globalswitches,cs_link_map);
  2933. set_default_link_type;
  2934. end;
  2935. else
  2936. IllegalPara(opt);
  2937. end;
  2938. inc(j);
  2939. end;
  2940. end;
  2941. else
  2942. IllegalPara(opt);
  2943. end;
  2944. end;
  2945. '@' :
  2946. begin
  2947. Message(option_no_nested_response_file);
  2948. StopOptions(1);
  2949. end;
  2950. else
  2951. begin
  2952. if (length(param_file)<>0) then
  2953. Message2(option_only_one_source_support,param_file,opt);
  2954. param_file:=opt;
  2955. Message1(option_found_file,opt);
  2956. end;
  2957. end;
  2958. end;
  2959. procedure Toption.Interpret_file(const filename : TPathStr);
  2960. procedure RemoveSep(var fn:TPathStr);
  2961. var
  2962. i : longint;
  2963. begin
  2964. i:=0;
  2965. while (i<length(fn)) and (fn[i+1] in [',',' ',#9]) do
  2966. inc(i);
  2967. Delete(fn,1,i);
  2968. i:=length(fn);
  2969. while (i>0) and (fn[i] in [',',' ',#9]) do
  2970. dec(i);
  2971. fn:=copy(fn,1,i);
  2972. end;
  2973. function GetName(var fn:TPathStr):TPathStr;
  2974. var
  2975. i : longint;
  2976. begin
  2977. i:=0;
  2978. while (i<length(fn)) and (fn[i+1] in ['a'..'z','A'..'Z','0'..'9','_','-']) do
  2979. inc(i);
  2980. GetName:=Copy(fn,1,i);
  2981. Delete(fn,1,i);
  2982. end;
  2983. const
  2984. maxlevel = 15;
  2985. var
  2986. f : text;
  2987. s, tmp,
  2988. opts : TCmdStr;
  2989. skip : array[0..maxlevel] of boolean;
  2990. line,
  2991. level : longint;
  2992. option_read : boolean;
  2993. oldfilemode : byte;
  2994. ConfigFile: TPathStr;
  2995. begin
  2996. { avoid infinite loop }
  2997. Inc(FileLevel);
  2998. Option_read:=false;
  2999. If FileLevel>MaxLevel then
  3000. Message(option_too_many_cfg_files);
  3001. if not ParaIncludeCfgPath.FindFile(fileName,true,ConfigFile) then
  3002. ConfigFile := ExpandFileName(filename);
  3003. { Maybe It's Directory ?} //Jaro Change:
  3004. if PathExists(ConfigFile,false) then
  3005. begin
  3006. Message1(option_config_is_dir,filename);
  3007. exit;
  3008. end;
  3009. { open file }
  3010. Message1(option_using_file,filename);
  3011. oldfilemode:=filemode;
  3012. filemode:=0;
  3013. assign(f,ConfigFile);
  3014. {$push}{$I-}
  3015. reset(f);
  3016. {$pop}
  3017. filemode:=oldfilemode;
  3018. if ioresult<>0 then
  3019. begin
  3020. Message1(option_unable_open_file,filename);
  3021. exit;
  3022. end;
  3023. Message1(option_start_reading_configfile,filename);
  3024. fillchar(skip,sizeof(skip),0);
  3025. level:=0;
  3026. line:=0;
  3027. while not eof(f) do
  3028. begin
  3029. readln(f,opts);
  3030. inc(line);
  3031. RemoveSep(opts);
  3032. if (opts<>'') and (opts[1]<>';') then
  3033. begin
  3034. if opts[1]='#' then
  3035. begin
  3036. Message1(option_interpreting_file_option,opts);
  3037. Delete(opts,1,1);
  3038. s:=upper(GetName(opts));
  3039. if (s='SECTION') then
  3040. begin
  3041. RemoveSep(opts);
  3042. s:=upper(GetName(opts));
  3043. if level=0 then
  3044. skip[level]:=not defined_macro(s) or (s='COMMON');
  3045. end
  3046. else
  3047. if (s='IFDEF') then
  3048. begin
  3049. RemoveSep(opts);
  3050. if Level>=maxlevel then
  3051. begin
  3052. Message2(option_too_many_ifdef,filename,tostr(line));
  3053. stopOptions(1);
  3054. end;
  3055. inc(Level);
  3056. skip[level]:=(skip[level-1] or not defined_macro(upper(GetName(opts))));
  3057. end
  3058. else
  3059. if (s='IFNDEF') then
  3060. begin
  3061. RemoveSep(opts);
  3062. if Level>=maxlevel then
  3063. begin
  3064. Message2(option_too_many_ifdef,filename,tostr(line));
  3065. stopOptions(1);
  3066. end;
  3067. inc(Level);
  3068. skip[level]:=(skip[level-1] or defined_macro(upper(GetName(opts))));
  3069. end
  3070. else
  3071. if (s='ELSE') then
  3072. begin
  3073. if Level=0 then
  3074. begin
  3075. Message2(option_else_without_if,filename,tostr(line));
  3076. stopOptions(1);
  3077. end
  3078. else
  3079. skip[level]:=skip[level-1] or (not skip[level])
  3080. end
  3081. else
  3082. if (s='ENDIF') then
  3083. begin
  3084. skip[level]:=false;
  3085. if Level=0 then
  3086. begin
  3087. Message2(option_too_many_endif,filename,tostr(line));
  3088. stopOptions(1);
  3089. end;
  3090. dec(level);
  3091. end
  3092. else
  3093. if (not skip[level]) then
  3094. begin
  3095. if (s='DEFINE') then
  3096. begin
  3097. RemoveSep(opts);
  3098. tmp:= GetName(opts);
  3099. if tmp <> '' then
  3100. def_system_macro(tmp);
  3101. Option_read:=true;
  3102. end
  3103. else
  3104. if (s='UNDEF') then
  3105. begin
  3106. RemoveSep(opts);
  3107. tmp:= GetName(opts);
  3108. if tmp <> '' then
  3109. undef_system_macro(tmp);
  3110. Option_read:=true;
  3111. end
  3112. else
  3113. if (s='WRITE') then
  3114. begin
  3115. Delete(opts,1,1);
  3116. DefaultReplacements(opts);
  3117. WriteLn(opts);
  3118. Option_read:=true;
  3119. end
  3120. else
  3121. if (s='INCLUDE') then
  3122. begin
  3123. Delete(opts,1,1);
  3124. DefaultReplacements(opts);
  3125. Interpret_file(opts);
  3126. Option_read:=true;
  3127. end
  3128. else
  3129. if (s='CFGDIR') then
  3130. begin
  3131. Delete(opts,1,1);
  3132. DefaultReplacements(opts);
  3133. ParaIncludeCfgPath.AddPath(opts,false);
  3134. Option_read:=true;
  3135. end;
  3136. end;
  3137. end
  3138. else
  3139. begin
  3140. if (opts[1]='-') or (opts[1]='@') then
  3141. begin
  3142. if (not skip[level]) then
  3143. interpret_option(opts,false);
  3144. Option_read:=true;
  3145. end
  3146. else
  3147. Message1(option_illegal_para,opts);
  3148. end;
  3149. end;
  3150. end;
  3151. if Level>0 then
  3152. Message(option_too_less_endif);
  3153. if Not Option_read then
  3154. Message1(option_no_option_found,filename)
  3155. else
  3156. Message1(option_end_reading_configfile,filename);
  3157. Close(f);
  3158. Dec(FileLevel);
  3159. end;
  3160. procedure Toption.Interpret_envvar(const envname : TCmdStr);
  3161. var
  3162. argstart,
  3163. env,
  3164. pc : pchar;
  3165. arglen : longint;
  3166. quote : set of char;
  3167. hs : TCmdStr;
  3168. begin
  3169. Message1(option_using_env,envname);
  3170. env:=GetEnvPChar(envname);
  3171. pc:=env;
  3172. hs:='';
  3173. if assigned(pc) then
  3174. begin
  3175. repeat
  3176. { skip leading spaces }
  3177. while pc^ in [' ',#9,#13] do
  3178. inc(pc);
  3179. case pc^ of
  3180. #0 :
  3181. break;
  3182. '"' :
  3183. begin
  3184. quote:=['"'];
  3185. inc(pc);
  3186. end;
  3187. '''' :
  3188. begin
  3189. quote:=[''''];
  3190. inc(pc);
  3191. end;
  3192. else
  3193. quote:=[' ',#9,#13];
  3194. end;
  3195. { scan until the end of the argument }
  3196. argstart:=pc;
  3197. while (pc^<>#0) and not(pc^ in quote) do
  3198. inc(pc);
  3199. { create argument }
  3200. arglen:=pc-argstart;
  3201. { TODO: FIXME: silent truncation of environment parameters }
  3202. if (arglen > 255) then
  3203. arglen := 255;
  3204. setlength(hs,arglen);
  3205. move(argstart^,hs[1],arglen);
  3206. interpret_option(hs,true);
  3207. { skip quote }
  3208. if pc^ in quote then
  3209. inc(pc);
  3210. until false;
  3211. end
  3212. else
  3213. Message1(option_no_option_found,'(env) '+envname);
  3214. FreeEnvPChar(env);
  3215. end;
  3216. procedure toption.read_parameters;
  3217. var
  3218. opts : TCmdStr;
  3219. paramindex : longint;
  3220. begin
  3221. paramindex:=0;
  3222. while paramindex<paramcount do
  3223. begin
  3224. inc(paramindex);
  3225. opts:=objpas.paramstr(paramindex);
  3226. if length(opts)>0 then
  3227. case opts[1] of
  3228. '@' :
  3229. if not firstpass then
  3230. begin
  3231. Delete(opts,1,1);
  3232. Message1(option_reading_further_from,opts);
  3233. interpret_file(opts);
  3234. end;
  3235. '!' :
  3236. if not firstpass then
  3237. begin
  3238. Delete(opts,1,1);
  3239. Message1(option_reading_further_from,'(env) '+opts);
  3240. interpret_envvar(opts);
  3241. end;
  3242. else
  3243. interpret_option(opts,true);
  3244. end;
  3245. end;
  3246. end;
  3247. procedure toption.parsecmd(cmd:TCmdStr);
  3248. var
  3249. i,ps : longint;
  3250. opts : TCmdStr;
  3251. begin
  3252. while (cmd<>'') do
  3253. begin
  3254. while cmd[1]=' ' do
  3255. delete(cmd,1,1);
  3256. i:=pos(' ',cmd);
  3257. if i=0 then
  3258. i:=2147483647;
  3259. opts:=Copy(cmd,1,i-1);
  3260. Delete(cmd,1,i);
  3261. case opts[1] of
  3262. '@' :
  3263. if not firstpass then
  3264. begin
  3265. Delete(opts,1,1);
  3266. Message1(option_reading_further_from,opts);
  3267. interpret_file(opts);
  3268. end;
  3269. '!' :
  3270. if not firstpass then
  3271. begin
  3272. Delete(opts,1,1);
  3273. Message1(option_reading_further_from,'(env) '+opts);
  3274. interpret_envvar(opts);
  3275. end;
  3276. '"' :
  3277. begin
  3278. Delete(opts,1,1);
  3279. ps:=pos('"',cmd);
  3280. if (i<>256) and (ps>0) then
  3281. begin
  3282. opts:=opts + ' '+ copy(cmd,1,ps-1);
  3283. cmd:=copy(cmd,ps+1,255);
  3284. end;
  3285. interpret_option(opts,true);
  3286. end;
  3287. else
  3288. interpret_option(opts,true);
  3289. end;
  3290. end;
  3291. end;
  3292. procedure toption.writequickinfo;
  3293. var
  3294. s : string;
  3295. i : longint;
  3296. procedure addinfo(const hs:string);
  3297. begin
  3298. if s<>'' then
  3299. s:=s+' '+hs
  3300. else
  3301. s:=hs;
  3302. end;
  3303. begin
  3304. s:='';
  3305. i:=0;
  3306. while (i<length(quickinfo)) do
  3307. begin
  3308. inc(i);
  3309. case quickinfo[i] of
  3310. 'S' :
  3311. begin
  3312. inc(i);
  3313. case quickinfo[i] of
  3314. 'O' :
  3315. addinfo(lower(source_info.shortname));
  3316. 'P' :
  3317. addinfo(source_cpu_string);
  3318. else
  3319. IllegalPara('-i'+QuickInfo);
  3320. end;
  3321. end;
  3322. 'T' :
  3323. begin
  3324. inc(i);
  3325. case quickinfo[i] of
  3326. 'O' :
  3327. addinfo(lower(target_info.shortname));
  3328. 'P' :
  3329. AddInfo(target_cpu_string);
  3330. else
  3331. IllegalPara('-i'+QuickInfo);
  3332. end;
  3333. end;
  3334. 'V' :
  3335. AddInfo(version_string);
  3336. 'W' :
  3337. AddInfo(full_version_string);
  3338. 'D' :
  3339. AddInfo(date_string);
  3340. '_' :
  3341. ;
  3342. else
  3343. IllegalPara('-i'+QuickInfo);
  3344. end;
  3345. end;
  3346. if s<>'' then
  3347. begin
  3348. writeln(s);
  3349. stopoptions(0);
  3350. end;
  3351. end;
  3352. procedure TOption.TargetOptions(def:boolean);
  3353. var
  3354. s : string;
  3355. i : integer;
  3356. target_unsup_features : tfeatures;
  3357. begin
  3358. if def then
  3359. def_system_macro(target_info.shortname)
  3360. else
  3361. undef_system_macro(target_info.shortname);
  3362. s:=target_info.extradefines;
  3363. while (s<>'') do
  3364. begin
  3365. i:=pos(';',s);
  3366. if i=0 then
  3367. i:=length(s)+1;
  3368. if def then
  3369. def_system_macro(Copy(s,1,i-1))
  3370. else
  3371. undef_system_macro(Copy(s,1,i-1));
  3372. delete(s,1,i);
  3373. end;
  3374. if (tf_winlikewidestring in target_info.flags) then
  3375. if def then
  3376. def_system_macro('FPC_WINLIKEWIDESTRING')
  3377. else
  3378. undef_system_macro('FPC_WINLIKEWIDESTRING');
  3379. if (tf_requires_proper_alignment in target_info.flags) then
  3380. if def then
  3381. def_system_macro('FPC_REQUIRES_PROPER_ALIGNMENT')
  3382. else
  3383. undef_system_macro('FPC_REQUIRES_PROPER_ALIGNMENT');
  3384. if (tf_init_final_units_by_calls in target_info.flags) then
  3385. if def then
  3386. def_system_macro('FPC_INIT_FINAL_UNITS_BY_CALLS')
  3387. else
  3388. undef_system_macro('FPC_INIT_FINAL_UNITS_BY_CALLS');
  3389. if source_info.system<>target_info.system then
  3390. if def then
  3391. def_system_macro('FPC_CROSSCOMPILING')
  3392. else
  3393. undef_system_macro('FPC_CROSSCOMPILING');
  3394. if source_info.cpu<>target_info.cpu then
  3395. if def then
  3396. def_system_macro('FPC_CPUCROSSCOMPILING')
  3397. else
  3398. def_system_macro('FPC_CPUCROSSCOMPILING');
  3399. if (tf_no_generic_stackcheck in target_info.flags) then
  3400. if def then
  3401. def_system_macro('FPC_NO_GENERIC_STACK_CHECK')
  3402. else
  3403. undef_system_macro('FPC_NO_GENERIC_STACK_CHECK');
  3404. if (tf_section_threadvars in target_info.flags) then
  3405. if def then
  3406. def_system_macro('FPC_SECTION_THREADVARS')
  3407. else
  3408. undef_system_macro('FPC_SECTION_THREADVARS');
  3409. if (tf_use_psabieh in target_info.flags) then
  3410. if def then
  3411. def_system_macro('FPC_USE_PSABIEH')
  3412. else
  3413. undef_system_macro('FPC_USE_PSABIEH');
  3414. { Code generation flags }
  3415. if (tf_pic_default in target_info.flags) then
  3416. if def then
  3417. include(init_settings.moduleswitches,cs_create_pic)
  3418. else
  3419. exclude(init_settings.moduleswitches,cs_create_pic);
  3420. { Resources support }
  3421. if (tf_has_winlike_resources in target_info.flags) then
  3422. if def then
  3423. def_system_macro('FPC_HAS_WINLIKERESOURCES')
  3424. else
  3425. undef_system_macro('FPC_HAS_WINLIKERESOURCES');
  3426. { Features }
  3427. case target_info.system of
  3428. system_arm_gba:
  3429. target_unsup_features:=[f_dynlibs];
  3430. system_arm_nds:
  3431. target_unsup_features:=[f_threading,f_commandargs,f_fileio,f_textio,f_consoleio,f_dynlibs];
  3432. system_i386_nativent:
  3433. // until these features are implemented, they are disabled in the compiler
  3434. target_unsup_features:=[f_stackcheck];
  3435. system_i8086_msdos:
  3436. target_unsup_features:=[f_threading,f_dynlibs];
  3437. system_i8086_win16:
  3438. target_unsup_features:=[f_threading];
  3439. system_jvm_java32,
  3440. system_jvm_android32:
  3441. target_unsup_features:=[f_heap,f_textio,f_consoleio,f_fileio,
  3442. f_variants,f_objects,f_commandargs,
  3443. f_processes,f_stackcheck,f_dynlibs,f_softfpu,f_objectivec1,f_resources];
  3444. system_arm_palmos,
  3445. system_m68k_palmos:
  3446. target_unsup_features:=[f_threading];
  3447. system_m68k_atari:
  3448. target_unsup_features:=[f_threading];
  3449. { classic amiga has dynamic libraries, but they cannot be integrated in the
  3450. normal dynlibs infrastructure due to architectural differences, so therefore
  3451. lets disable the feature. }
  3452. system_m68k_amiga:
  3453. target_unsup_features:=[f_dynlibs];
  3454. system_m68k_sinclairql:
  3455. target_unsup_features:=[f_threading,f_dynlibs];
  3456. system_z80_zxspectrum:
  3457. target_unsup_features:=[f_threading,f_dynlibs{,f_fileio,f_textio},f_commandargs,f_exitcode];
  3458. system_z80_msxdos:
  3459. target_unsup_features:=[f_threading,f_dynlibs];
  3460. else
  3461. target_unsup_features:=[];
  3462. end;
  3463. if def then
  3464. features:=features-target_unsup_features
  3465. else
  3466. features:=features+target_unsup_features;
  3467. {$if defined(atari) or defined(hasamiga)}
  3468. { enable vlink as default linker on Atari and Amiga but not for cross compilers (for now) }
  3469. if (target_info.system in [system_m68k_amiga,system_m68k_atari,system_powerpc_amiga]) and
  3470. not LinkerSetExplicitly then
  3471. include(init_settings.globalswitches,cs_link_vlink);
  3472. {$endif}
  3473. {$ifdef m68k}
  3474. if (target_info.system in [system_m68k_sinclairql]) and
  3475. not LinkerSetExplicitly then
  3476. include(init_settings.globalswitches,cs_link_vlink);
  3477. {$endif m68k}
  3478. end;
  3479. procedure TOption.checkoptionscompatibility;
  3480. begin
  3481. {$ifdef i8086}
  3482. if (apptype=app_com) and (init_settings.x86memorymodel<>mm_tiny) then
  3483. begin
  3484. Message(option_com_files_require_tiny_model);
  3485. StopOptions(1);
  3486. end;
  3487. {$endif i8086}
  3488. {$ifndef i8086_link_intern_debuginfo}
  3489. if (cs_debuginfo in init_settings.moduleswitches) and
  3490. (target_info.system in [system_i8086_msdos,system_i8086_win16,system_i8086_embedded]) and
  3491. not (cs_link_extern in init_settings.globalswitches) then
  3492. begin
  3493. Message(option_debug_info_requires_external_linker);
  3494. include(init_settings.globalswitches,cs_link_extern);
  3495. end;
  3496. {$endif i8086_link_intern_debuginfo}
  3497. if (paratargetdbg in [dbg_dwarf2,dbg_dwarf3]) and
  3498. not(target_info.system in (systems_darwin+[system_i8086_msdos,system_i8086_embedded])) then
  3499. begin
  3500. { smartlink creation does not yet work with DWARF
  3501. debug info on most targets, but it works in internal assembler }
  3502. if (cs_create_smart in init_settings.moduleswitches) and
  3503. not (af_outputbinary in target_asm.flags) then
  3504. begin
  3505. Message(option_dwarf_smartlink_creation);
  3506. exclude(init_settings.moduleswitches,cs_create_smart);
  3507. end;
  3508. { smart linking does not yet work with DWARF debug info on most targets }
  3509. if (cs_link_smart in init_settings.globalswitches) then
  3510. begin
  3511. Message(option_dwarf_smart_linking);
  3512. ForceStaticLinking;
  3513. end;
  3514. end;
  3515. { external debug info is only supported for DWARF on darwin }
  3516. if (target_info.system in systems_darwin) and
  3517. (cs_link_separate_dbg_file in init_settings.globalswitches) and
  3518. not(paratargetdbg in [dbg_dwarf2,dbg_dwarf3]) then
  3519. begin
  3520. Message(option_debug_external_unsupported);
  3521. exclude(init_settings.globalswitches,cs_link_separate_dbg_file);
  3522. end;
  3523. { Also create a smartlinked version, on an assembler that
  3524. does not support smartlink sections like nasm?
  3525. This is not compatible with using internal linker. }
  3526. if ((cs_link_smart in init_settings.globalswitches) or
  3527. (cs_create_smart in init_settings.moduleswitches)) and
  3528. (af_needar in target_asm.flags) and
  3529. not (af_smartlink_sections in target_asm.flags) and
  3530. not (cs_link_extern in init_settings.globalswitches) and
  3531. (target_info.link<>ld_none) and
  3532. not (cs_link_nolink in init_settings.globalswitches) then
  3533. begin
  3534. Message(option_smart_link_requires_external_linker);
  3535. include(init_settings.globalswitches,cs_link_extern);
  3536. end;
  3537. end;
  3538. constructor TOption.create;
  3539. begin
  3540. LogoWritten:=false;
  3541. NoPressEnter:=false;
  3542. FirstPass:=false;
  3543. ABISetExplicitly:=false;
  3544. FPUSetExplicitly:=false;
  3545. CPUSetExplicitly:=false;
  3546. OptCPUSetExplicitly:=false;
  3547. FileLevel:=0;
  3548. Quickinfo:='';
  3549. ParaIncludeCfgPath:=TSearchPathList.Create;
  3550. ParaIncludePath:=TSearchPathList.Create;
  3551. ParaObjectPath:=TSearchPathList.Create;
  3552. ParaUnitPath:=TSearchPathList.Create;
  3553. ParaLibraryPath:=TSearchPathList.Create;
  3554. ParaFrameworkPath:=TSearchPathList.Create;
  3555. parapackagepath:=TSearchPathList.Create;
  3556. parapackages:=TFPHashObjectList.Create;
  3557. paranamespaces:=TCmdStrList.Create;
  3558. FillChar(ParaAlignment,sizeof(ParaAlignment),0);
  3559. MacVersionSet:=false;
  3560. paratarget:=system_none;
  3561. paratargetasm:=as_none;
  3562. paratargetdbg:=dbg_none;
  3563. LinkTypeSetExplicitly:=false;
  3564. LinkerSetExplicitly:=false;
  3565. end;
  3566. destructor TOption.destroy;
  3567. begin
  3568. ParaIncludeCfgPath.Free;
  3569. ParaIncludePath.Free;
  3570. ParaObjectPath.Free;
  3571. ParaUnitPath.Free;
  3572. ParaLibraryPath.Free;
  3573. ParaFrameworkPath.Free;
  3574. parapackagepath.Free;
  3575. ParaPackages.Free;
  3576. paranamespaces.free;
  3577. end;
  3578. {****************************************************************************
  3579. Callable Routines
  3580. ****************************************************************************}
  3581. function check_configfile(fn:string; var foundfn:string):boolean;
  3582. function CfgFileExists(const fn:string):boolean;
  3583. begin
  3584. Comment(V_Tried,'Configfile search: '+fn);
  3585. CfgFileExists:=FileExists(fn);
  3586. end;
  3587. var
  3588. {$ifdef Unix}
  3589. hs,
  3590. {$endif Unix}
  3591. configpath : string;
  3592. begin
  3593. foundfn:=fn;
  3594. check_configfile:=true;
  3595. { retrieve configpath }
  3596. configpath:=FixPath(GetEnvironmentVariable('PPC_CONFIG_PATH'),false);
  3597. {$ifdef Unix}
  3598. if configpath='' then
  3599. configpath:=ExpandFileName(FixPath(exepath+'../etc/',false));
  3600. {$endif}
  3601. {
  3602. Order to read configuration file :
  3603. try reading fpc.cfg in :
  3604. 1 - current dir
  3605. 2 - configpath
  3606. 3 - compiler path
  3607. }
  3608. if not FileExists(fn) then
  3609. begin
  3610. {$ifdef Unix}
  3611. hs:=GetEnvironmentVariable('HOME');
  3612. if (hs<>'') and CfgFileExists(FixPath(hs,false)+'.'+fn) then
  3613. foundfn:=FixPath(hs,false)+'.'+fn
  3614. else
  3615. {$endif}
  3616. if CfgFileExists(configpath+fn) then
  3617. foundfn:=configpath+fn
  3618. else
  3619. {$ifdef WINDOWS}
  3620. if (GetEnvironmentVariable('USERPROFILE')<>'') and CfgFileExists(FixPath(GetEnvironmentVariable('USERPROFILE'),false)+fn) then
  3621. foundfn:=FixPath(GetEnvironmentVariable('USERPROFILE'),false)+fn
  3622. else
  3623. if (GetEnvironmentVariable('ALLUSERSPROFILE')<>'') and CfgFileExists(FixPath(GetEnvironmentVariable('ALLUSERSPROFILE'),false)+fn) then
  3624. foundfn:=FixPath(GetEnvironmentVariable('ALLUSERSPROFILE'),false)+fn
  3625. else
  3626. {$endif WINDOWS}
  3627. {$ifndef Unix}
  3628. if CfgFileExists(exepath+fn) then
  3629. foundfn:=exepath+fn
  3630. else
  3631. {$else}
  3632. if CfgFileExists('/etc/'+fn) then
  3633. foundfn:='/etc/'+fn
  3634. else
  3635. {$endif}
  3636. check_configfile:=false;
  3637. end;
  3638. end;
  3639. procedure read_arguments(cmd:TCmdStr);
  3640. procedure def_cpu_macros;
  3641. var
  3642. abi : tabi;
  3643. fputype : tfputype;
  3644. cputype : tcputype;
  3645. controller: tcontrollertype;
  3646. s: string;
  3647. begin
  3648. {$ifdef llvm}
  3649. def_system_macro('CPULLVM');
  3650. {$endif}
  3651. for cputype:=low(tcputype) to high(tcputype) do
  3652. undef_system_macro('CPU'+Cputypestr[cputype]);
  3653. def_system_macro('CPU'+Cputypestr[init_settings.cputype]);
  3654. for fputype:=low(tfputype) to high(tfputype) do
  3655. undef_system_macro('FPU'+fputypestr[fputype]);
  3656. def_system_macro('FPU'+fputypestr[init_settings.fputype]);
  3657. {$PUSH}
  3658. {$WARN 6018 OFF} { Unreachable code due to compile time evaluation }
  3659. if ControllerSupport then
  3660. begin
  3661. for controller:=low(tcontrollertype) to high(tcontrollertype) do
  3662. begin
  3663. s:=embedded_controllers[controller].controllertypestr;
  3664. if s<>'' then
  3665. undef_system_macro('FPC_MCU_'+s);
  3666. end;
  3667. s:=embedded_controllers[init_settings.controllertype].controllertypestr;
  3668. if s<>'' then
  3669. def_system_macro('FPC_MCU_'+s);
  3670. end;
  3671. {$POP}
  3672. { define abi }
  3673. for abi:=low(tabi) to high(tabi) do
  3674. undef_system_macro('FPC_ABI_'+abiinfo[abi].name);
  3675. def_system_macro('FPC_ABI_'+abiinfo[target_info.abi].name);
  3676. { Define FPC_ABI_EABI in addition to FPC_ABI_EABIHF on EABI VFP hardfloat
  3677. systems since most code needs to behave the same on both}
  3678. if target_info.abi = abi_eabihf then
  3679. def_system_macro('FPC_ABI_EABI');
  3680. { using a case is pretty useless here (FK) }
  3681. { some stuff for TP compatibility }
  3682. {$ifdef i386}
  3683. def_system_macro('CPU86');
  3684. def_system_macro('CPU87');
  3685. def_system_macro('CPU386');
  3686. {$endif}
  3687. { new processor stuff }
  3688. {$ifdef i386}
  3689. def_system_macro('CPUI386');
  3690. def_system_macro('CPU32');
  3691. def_system_macro('CPUX86');
  3692. def_system_macro('FPC_HAS_TYPE_EXTENDED');
  3693. def_system_macro('FPC_HAS_TYPE_DOUBLE');
  3694. def_system_macro('FPC_HAS_TYPE_SINGLE');
  3695. {$endif}
  3696. {$ifdef m68k}
  3697. def_system_macro('CPU68');
  3698. def_system_macro('CPU68K');
  3699. def_system_macro('CPUM68K');
  3700. def_system_macro('CPU32');
  3701. def_system_macro('FPC_CURRENCY_IS_INT64');
  3702. def_system_macro('FPC_COMP_IS_INT64');
  3703. {$endif}
  3704. {$ifdef powerpc}
  3705. def_system_macro('CPUPOWERPC');
  3706. def_system_macro('CPUPOWERPC32');
  3707. def_system_macro('CPU32');
  3708. def_system_macro('FPC_CURRENCY_IS_INT64');
  3709. def_system_macro('FPC_COMP_IS_INT64');
  3710. {$endif}
  3711. {$ifdef POWERPC64}
  3712. def_system_macro('CPUPOWERPC');
  3713. def_system_macro('CPUPOWERPC64');
  3714. def_system_macro('CPU64');
  3715. def_system_macro('FPC_CURRENCY_IS_INT64');
  3716. def_system_macro('FPC_COMP_IS_INT64');
  3717. {$endif}
  3718. {$ifdef x86_64}
  3719. def_system_macro('CPUX86_64');
  3720. def_system_macro('CPUAMD64');
  3721. def_system_macro('CPU64');
  3722. def_system_macro('CPUX64');
  3723. { not supported for now, afaik (FK)
  3724. def_system_macro('FPC_HAS_TYPE_FLOAT128'); }
  3725. {$ifndef FPC_SUPPORT_X87_TYPES_ON_WIN64}
  3726. { normally, win64 doesn't support the legacy fpu }
  3727. if target_info.system=system_x86_64_win64 then
  3728. begin
  3729. def_system_macro('FPC_CURRENCY_IS_INT64');
  3730. def_system_macro('FPC_COMP_IS_INT64');
  3731. end;
  3732. {$endif FPC_SUPPORT_X87_TYPES_ON_WIN64}
  3733. {$endif}
  3734. {$ifdef sparc}
  3735. def_system_macro('CPUSPARCGEN');
  3736. def_system_macro('CPUSPARC');
  3737. def_system_macro('CPUSPARC32');
  3738. def_system_macro('CPU32');
  3739. def_system_macro('FPC_CURRENCY_IS_INT64');
  3740. def_system_macro('FPC_COMP_IS_INT64');
  3741. {$endif}
  3742. {$ifdef sparc64}
  3743. def_system_macro('CPUSPARCGEN');
  3744. def_system_macro('CPUSPARC64');
  3745. def_system_macro('CPU64');
  3746. def_system_macro('FPC_CURRENCY_IS_INT64');
  3747. def_system_macro('FPC_COMP_IS_INT64');
  3748. {$endif}
  3749. {$ifdef arm}
  3750. def_system_macro('CPUARM');
  3751. def_system_macro('CPU32');
  3752. def_system_macro('FPC_CURRENCY_IS_INT64');
  3753. def_system_macro('FPC_COMP_IS_INT64');
  3754. {$endif arm}
  3755. {$ifdef avr}
  3756. def_system_macro('CPUAVR');
  3757. def_system_macro('CPU16');
  3758. def_system_macro('FPC_CURRENCY_IS_INT64');
  3759. def_system_macro('FPC_COMP_IS_INT64');
  3760. {$endif avr}
  3761. {$ifdef jvm}
  3762. def_system_macro('CPUJVM');
  3763. def_system_macro('CPU32');
  3764. def_system_macro('FPC_CURRENCY_IS_INT64');
  3765. def_system_macro('FPC_COMP_IS_INT64');
  3766. {$endif jvm}
  3767. {$ifdef mipsel}
  3768. def_system_macro('CPUMIPS');
  3769. def_system_macro('CPUMIPS32');
  3770. def_system_macro('CPUMIPSEL');
  3771. def_system_macro('CPUMIPSEL32');
  3772. def_system_macro('CPU32');
  3773. def_system_macro('FPC_HAS_TYPE_DOUBLE');
  3774. def_system_macro('FPC_HAS_TYPE_SINGLE');
  3775. def_system_macro('FPC_INCLUDE_SOFTWARE_INT64_TO_DOUBLE');
  3776. def_system_macro('FPC_CURRENCY_IS_INT64');
  3777. def_system_macro('FPC_COMP_IS_INT64');
  3778. def_system_macro('FPC_REQUIRES_PROPER_ALIGNMENT');
  3779. { On most systems, locals are accessed relative to base pointer,
  3780. but for MIPS cpu, they are accessed relative to stack pointer.
  3781. This needs adaptation for so low level routines,
  3782. like MethodPointerLocal and related objects unit functions. }
  3783. def_system_macro('FPC_LOCALS_ARE_STACK_REG_RELATIVE');
  3784. {$endif mipsel}
  3785. {$ifdef mipseb}
  3786. def_system_macro('CPUMIPS');
  3787. def_system_macro('CPUMIPS32');
  3788. def_system_macro('CPUMIPSEB');
  3789. def_system_macro('CPUMIPSEB32');
  3790. def_system_macro('CPU32');
  3791. def_system_macro('FPC_HAS_TYPE_DOUBLE');
  3792. def_system_macro('FPC_HAS_TYPE_SINGLE');
  3793. def_system_macro('FPC_INCLUDE_SOFTWARE_INT64_TO_DOUBLE');
  3794. def_system_macro('FPC_CURRENCY_IS_INT64');
  3795. def_system_macro('FPC_COMP_IS_INT64');
  3796. def_system_macro('FPC_REQUIRES_PROPER_ALIGNMENT');
  3797. { See comment above for mipsel }
  3798. def_system_macro('FPC_LOCALS_ARE_STACK_REG_RELATIVE');
  3799. {$endif}
  3800. {$ifdef i8086}
  3801. def_system_macro('CPU86'); { Borland compatibility }
  3802. def_system_macro('CPU87'); { Borland compatibility }
  3803. def_system_macro('CPUI8086');
  3804. def_system_macro('CPU16');
  3805. def_system_macro('FPC_HAS_TYPE_EXTENDED');
  3806. def_system_macro('FPC_HAS_TYPE_DOUBLE');
  3807. def_system_macro('FPC_HAS_TYPE_SINGLE');
  3808. case init_settings.x86memorymodel of
  3809. mm_tiny: def_system_macro('FPC_MM_TINY');
  3810. mm_small: def_system_macro('FPC_MM_SMALL');
  3811. mm_medium: def_system_macro('FPC_MM_MEDIUM');
  3812. mm_compact: def_system_macro('FPC_MM_COMPACT');
  3813. mm_large: def_system_macro('FPC_MM_LARGE');
  3814. mm_huge: def_system_macro('FPC_MM_HUGE');
  3815. end;
  3816. {$endif i8086}
  3817. {$ifdef aarch64}
  3818. def_system_macro('CPUAARCH64');
  3819. def_system_macro('CPU64');
  3820. def_system_macro('FPC_CURRENCY_IS_INT64');
  3821. def_system_macro('FPC_COMP_IS_INT64');
  3822. {$endif aarch64}
  3823. {$ifdef riscv32}
  3824. def_system_macro('CPURISCV');
  3825. def_system_macro('CPURISCV32');
  3826. def_system_macro('CPU32');
  3827. def_system_macro('FPC_CURRENCY_IS_INT64');
  3828. def_system_macro('FPC_COMP_IS_INT64');
  3829. def_system_macro('FPC_REQUIRES_PROPER_ALIGNMENT');
  3830. {$endif riscv32}
  3831. {$ifdef riscv64}
  3832. def_system_macro('CPURISCV');
  3833. def_system_macro('CPURISCV64');
  3834. def_system_macro('CPU64');
  3835. def_system_macro('FPC_CURRENCY_IS_INT64');
  3836. def_system_macro('FPC_COMP_IS_INT64');
  3837. def_system_macro('FPC_REQUIRES_PROPER_ALIGNMENT');
  3838. {$endif riscv64}
  3839. {$ifdef xtensa}
  3840. def_system_macro('CPUXTENSA');
  3841. def_system_macro('CPU32');
  3842. def_system_macro('FPC_CURRENCY_IS_INT64');
  3843. def_system_macro('FPC_COMP_IS_INT64');
  3844. def_system_macro('FPC_REQUIRES_PROPER_ALIGNMENT');
  3845. {$endif xtensa}
  3846. {$ifdef z80}
  3847. def_system_macro('CPUZ80');
  3848. def_system_macro('CPU16');
  3849. def_system_macro('FPC_CURRENCY_IS_INT64');
  3850. def_system_macro('FPC_COMP_IS_INT64');
  3851. {$endif z80}
  3852. {$ifdef wasm32}
  3853. def_system_macro('CPUWASM');
  3854. def_system_macro('CPUWASM32');
  3855. def_system_macro('CPU32');
  3856. def_system_macro('FPC_CURRENCY_IS_INT64');
  3857. def_system_macro('FPC_COMP_IS_INT64');
  3858. {$endif wasm32}
  3859. {$if defined(cpu8bitalu)}
  3860. def_system_macro('CPUINT8');
  3861. {$elseif defined(cpu16bitalu)}
  3862. def_system_macro('CPUINT16');
  3863. {$elseif defined(cpu32bitalu)}
  3864. def_system_macro('CPUINT32');
  3865. {$elseif defined(cpu64bitalu)}
  3866. def_system_macro('CPUINT64');
  3867. {$endif defined(cpu64bitalu)}
  3868. {$if defined(avr)}
  3869. def_system_macro('FPC_HAS_INTERNAL_ABS_SHORTINT');
  3870. {$endif}
  3871. {$if defined(i8086) or defined(avr)}
  3872. def_system_macro('FPC_HAS_INTERNAL_ABS_SMALLINT');
  3873. {$endif i8086 or avr}
  3874. { abs(long) is handled internally on all CPUs }
  3875. def_system_macro('FPC_HAS_INTERNAL_ABS_LONG');
  3876. {$if defined(i8086) or defined(i386) or defined(x86_64) or defined(powerpc64) or defined(aarch64)}
  3877. def_system_macro('FPC_HAS_INTERNAL_ABS_INT64');
  3878. {$endif i8086 or i386 or x86_64 or powerpc64 or aarch64}
  3879. def_system_macro('FPC_HAS_UNICODESTRING');
  3880. def_system_macro('FPC_RTTI_PACKSET1');
  3881. def_system_macro('FPC_HAS_CPSTRING');
  3882. {$ifdef x86_64}
  3883. def_system_macro('FPC_HAS_RIP_RELATIVE');
  3884. {$endif x86_64}
  3885. def_system_macro('FPC_HAS_CEXTENDED');
  3886. def_system_macro('FPC_HAS_RESSTRINITS');
  3887. { these cpus have an inline rol/ror implementaion }
  3888. {$ifdef cpurox}
  3889. {$ifdef m68k}
  3890. if CPUM68K_HAS_ROLROR in cpu_capabilities[init_settings.cputype] then
  3891. def_system_macro('FPC_HAS_INTERNAL_ROX');
  3892. {$else}
  3893. def_system_macro('FPC_HAS_INTERNAL_ROX');
  3894. {$endif}
  3895. {$endif}
  3896. {$ifdef powerpc64}
  3897. def_system_macro('FPC_HAS_LWSYNC');
  3898. {$endif}
  3899. { currently, all supported CPUs have an internal sar implementation }
  3900. def_system_macro('FPC_HAS_INTERNAL_SAR');
  3901. {$ifdef SUPPORT_GET_FRAME}
  3902. def_system_macro('INTERNAL_BACKTRACE');
  3903. {$endif SUPPORT_GET_FRAME}
  3904. def_system_macro('STR_CONCAT_PROCS');
  3905. {$warnings off}
  3906. if pocall_default = pocall_register then
  3907. def_system_macro('REGCALL');
  3908. {$warnings on}
  3909. end;
  3910. var
  3911. env: ansistring;
  3912. i : tfeature;
  3913. j : longint;
  3914. tmplist : TCmdStrList;
  3915. cmditem,
  3916. tmpcmditem : TCmdStrListItem;
  3917. cmdstr : TCmdStr;
  3918. {$if defined(cpucapabilities)}
  3919. cpuflag : tcpuflags;
  3920. {$endif defined(cpucapabilities)}
  3921. {$if defined(fpucapabilities)}
  3922. fpuflag : tfpuflags;
  3923. {$endif defined(fpucapabilities)}
  3924. {$if defined(cpucapabilities) or defined(fpucapabilities)}
  3925. hs : string;
  3926. {$endif defined(cpucapabilities) or defined(fpucapabilities)}
  3927. begin
  3928. option:=coption.create;
  3929. disable_configfile:=false;
  3930. { Non-core target defines }
  3931. Option.TargetOptions(true);
  3932. { get default messagefile }
  3933. msgfilename:=GetEnvironmentVariable('PPC_ERROR_FILE');
  3934. { default configfile can be specified on the commandline,
  3935. remove it first }
  3936. if (cmd<>'') and (cmd[1]='[') then
  3937. begin
  3938. ppccfg:=Copy(cmd,2,pos(']',cmd)-2);
  3939. Delete(cmd,1,pos(']',cmd));
  3940. end
  3941. else
  3942. ppccfg:='fpc.cfg';
  3943. { first pass reading of parameters, only -i -v -T etc.}
  3944. option.firstpass:=true;
  3945. if cmd<>'' then
  3946. option.parsecmd(cmd)
  3947. else
  3948. begin
  3949. option.read_parameters;
  3950. { Write only quickinfo }
  3951. if option.quickinfo<>'' then
  3952. option.writequickinfo;
  3953. end;
  3954. option.firstpass:=false;
  3955. { redefine target options so all defines are written even if no -Txxx is passed on the command line }
  3956. Option.TargetOptions(true);
  3957. { target is set here, for wince the default app type is gui }
  3958. if target_info.system in systems_wince then
  3959. SetApptype(app_gui)
  3960. else
  3961. SetApptype(apptype);
  3962. { default defines }
  3963. def_system_macro(target_info.shortname);
  3964. def_system_macro('FPC');
  3965. def_system_macro('VER'+version_nr);
  3966. def_system_macro('VER'+version_nr+'_'+release_nr);
  3967. def_system_macro('VER'+version_nr+'_'+release_nr+'_'+patch_nr);
  3968. { Temporary defines, until things settle down }
  3969. def_system_macro('FPC_HAS_OPERATOR_ENUMERATOR');
  3970. def_system_macro('FPC_HAS_CONSTREF');
  3971. def_system_macro('FPC_STATICRIPFIXED');
  3972. def_system_macro('FPC_VARIANTCOPY_FIXED');
  3973. def_system_macro('FPC_DYNARRAYCOPY_FIXED');
  3974. def_system_macro('FPC_HAS_MEMBAR');
  3975. def_system_macro('FPC_SETBASE_USED');
  3976. def_system_macro('FPC_ALIGNED_THREADVARTABLES');
  3977. { don't remove this, it's also for fpdoc necessary (FK) }
  3978. def_system_macro('FPC_HAS_FEATURE_SUPPORT');
  3979. { make cpu makros available when reading the config files the second time }
  3980. def_cpu_macros;
  3981. if tf_cld in target_info.flags then
  3982. if not UpdateTargetSwitchStr('CLD', init_settings.targetswitches, true) then
  3983. InternalError(2013092801);
  3984. if tf_x86_far_procs_push_odd_bp in target_info.flags then
  3985. if not UpdateTargetSwitchStr('FARPROCSPUSHODDBP', init_settings.targetswitches, true) then
  3986. InternalError(2013092802);
  3987. { Use standard Android NDK prefixes when cross-compiling }
  3988. if (source_info.system<>target_info.system) and (target_info.system in systems_android) then
  3989. case target_info.system of
  3990. system_arm_android:
  3991. utilsprefix:='arm-linux-androideabi-';
  3992. system_i386_android:
  3993. utilsprefix:='i686-linux-android-';
  3994. else
  3995. utilsprefix:=target_cpu_string + '-linux-android-';
  3996. end;
  3997. { Set up default value for the heap }
  3998. if target_info.system in (systems_embedded+systems_freertos+[system_z80_zxspectrum,system_z80_msxdos]) then
  3999. begin
  4000. case target_info.system of
  4001. {$ifdef AVR}
  4002. system_avr_embedded:
  4003. if init_settings.controllertype=ct_avrsim then
  4004. heapsize:=8192
  4005. else
  4006. heapsize:=128;
  4007. {$endif AVR}
  4008. system_arm_freertos:
  4009. heapsize:=8192;
  4010. system_xtensa_freertos:
  4011. { keep default value }
  4012. ;
  4013. system_arm_embedded:
  4014. heapsize:=256;
  4015. system_mipsel_embedded:
  4016. heapsize:=256;
  4017. else
  4018. heapsize:=256;
  4019. end;
  4020. end;
  4021. { read configuration file }
  4022. if (not disable_configfile) and
  4023. (ppccfg<>'') then
  4024. read_configfile:=check_configfile(ppccfg,ppccfg)
  4025. else
  4026. read_configfile := false;
  4027. { Read commandline and configfile }
  4028. param_file:='';
  4029. { read configfile }
  4030. if read_configfile then
  4031. option.interpret_file(ppccfg);
  4032. { read parameters again to override config file }
  4033. if cmd<>'' then
  4034. option.parsecmd(cmd)
  4035. else
  4036. begin
  4037. { Write help pages if no parameters are passed }
  4038. if (paramcount=0) then
  4039. Option.WriteHelpPages;
  4040. option.read_parameters;
  4041. { Write only quickinfo }
  4042. if option.quickinfo<>'' then
  4043. option.writequickinfo;
  4044. end;
  4045. { check the compatibility of different options and adjust them if necessary
  4046. (and print possible errors)
  4047. }
  4048. option.checkoptionscompatibility;
  4049. { uses the CPUXXX-defines and target_info to determine whether the selected
  4050. target processor, if any, is supported }
  4051. Option.VerifyTargetProcessor;
  4052. { Stop if errors in options }
  4053. if ErrorCount>0 then
  4054. StopOptions(1);
  4055. { endian define }
  4056. case target_info.endian of
  4057. endian_little :
  4058. begin
  4059. def_system_macro('ENDIAN_LITTLE');
  4060. def_system_macro('FPC_LITTLE_ENDIAN');
  4061. end;
  4062. endian_big :
  4063. begin
  4064. def_system_macro('ENDIAN_BIG');
  4065. def_system_macro('FPC_BIG_ENDIAN');
  4066. end;
  4067. end;
  4068. { Write logo }
  4069. if option.ParaLogo then
  4070. option.writelogo;
  4071. { Check file to compile }
  4072. if param_file='' then
  4073. begin
  4074. Message(option_no_source_found);
  4075. StopOptions(1);
  4076. end;
  4077. {$ifndef Unix}
  4078. param_file:=FixFileName(param_file);
  4079. {$endif not unix}
  4080. inputfilepath:=ExtractFilePath(param_file);
  4081. inputfilename:=ExtractFileName(param_file);
  4082. if ExtractFileExt(inputfilename)='' then
  4083. begin
  4084. if FileExists(inputfilepath+ChangeFileExt(inputfilename,sourceext)) then
  4085. inputfilename:=ChangeFileExt(inputfilename,sourceext)
  4086. else if FileExists(inputfilepath+ChangeFileExt(inputfilename,pasext)) then
  4087. inputfilename:=ChangeFileExt(inputfilename,pasext)
  4088. else if ((m_mac in current_settings.modeswitches) or
  4089. (tf_p_ext_support in target_info.flags))
  4090. and FileExists(inputfilepath+ChangeFileExt(inputfilename,pext)) then
  4091. inputfilename:=ChangeFileExt(inputfilename,pext);
  4092. end;
  4093. { Check output dir }
  4094. if (OutputExeDir<>'') and
  4095. not PathExists(OutputExeDir,false) then
  4096. begin
  4097. Message1(general_e_path_does_not_exist,OutputExeDir);
  4098. StopOptions(1);
  4099. end;
  4100. { Add paths specified with parameters to the searchpaths }
  4101. UnitSearchPath.AddList(option.ParaUnitPath,true);
  4102. ObjectSearchPath.AddList(option.ParaObjectPath,true);
  4103. IncludeSearchPath.AddList(option.ParaIncludePath,true);
  4104. LibrarySearchPath.AddList(option.ParaLibraryPath,true);
  4105. FrameworkSearchPath.AddList(option.ParaFrameworkPath,true);
  4106. packagesearchpath.addlist(option.parapackagepath,true);
  4107. for j:=0 to option.parapackages.count-1 do
  4108. add_package(option.parapackages.NameOfIndex(j),true,true);
  4109. { add default namespaces }
  4110. tmplist:=TCmdStrList.Create;
  4111. cmditem:=TCmdStrListItem(option.paranamespaces.First);
  4112. while assigned(cmditem) do
  4113. begin
  4114. { use a temporary list cause if ";" are involved we need to reverse the
  4115. order due to how TCmdStrList behaves }
  4116. cmdstr:=cmditem.str;
  4117. repeat
  4118. j:=Pos(';',cmdstr);
  4119. if j>0 then
  4120. begin
  4121. tmplist.insert(copy(cmdstr,1,j-1));
  4122. delete(cmdstr,1,j);
  4123. end
  4124. else
  4125. tmplist.insert(cmdstr);
  4126. until j=0;
  4127. tmpcmditem:=TCmdStrListItem(tmplist.First);
  4128. while assigned(tmpcmditem) do
  4129. begin
  4130. namespacelist.insert(tmpcmditem.Str);
  4131. tmpcmditem:=TCmdStrListItem(tmpcmditem.Next);
  4132. end;
  4133. tmplist.clear;
  4134. cmditem:=TCmdStrListItem(cmditem.Next);
  4135. end;
  4136. tmplist.Free;
  4137. { add unit environment and exepath to the unit search path }
  4138. if inputfilepath<>'' then
  4139. Unitsearchpath.AddPath(inputfilepath,true);
  4140. if not disable_configfile then
  4141. begin
  4142. env:=GetEnvironmentVariable(target_info.unit_env);
  4143. if env<>'' then
  4144. UnitSearchPath.AddPath(GetEnvironmentVariable(target_info.unit_env),false);
  4145. end;
  4146. {$ifdef Unix}
  4147. fpcdir:=FixPath(GetEnvironmentVariable('FPCDIR'),false);
  4148. if fpcdir='' then
  4149. begin
  4150. if PathExists('/usr/local/lib/fpc/'+version_string,true) then
  4151. fpcdir:='/usr/local/lib/fpc/'+version_string+'/'
  4152. else
  4153. fpcdir:='/usr/lib/fpc/'+version_string+'/';
  4154. end;
  4155. {$else unix}
  4156. fpcdir:=FixPath(GetEnvironmentVariable('FPCDIR'),false);
  4157. if fpcdir='' then
  4158. begin
  4159. fpcdir:=ExePath+'../';
  4160. if not(PathExists(fpcdir+'units',true)) and
  4161. not(PathExists(fpcdir+'rtl',true)) then
  4162. fpcdir:=fpcdir+'../';
  4163. end;
  4164. {$endif unix}
  4165. { first try development RTL, else use the default installation path }
  4166. if not disable_configfile then
  4167. begin
  4168. if PathExists(FpcDir+'rtl',true) then
  4169. if (tf_use_8_3 in Source_Info.Flags) or
  4170. (tf_use_8_3 in Target_Info.Flags) then
  4171. UnitSearchPath.AddPath(FpcDir+'rtl/'+target_os_string,false)
  4172. else
  4173. UnitSearchPath.AddPath(FpcDir+'rtl/'+target_full_string,false)
  4174. else
  4175. if (tf_use_8_3 in Source_Info.Flags) or
  4176. (tf_use_8_3 in Target_Info.Flags) then
  4177. UnitSearchPath.AddPath(FpcDir+'units/'+target_os_string+'/rtl',false)
  4178. else
  4179. UnitSearchPath.AddPath(FpcDir+'units/'+target_full_string+'/rtl',false);
  4180. end;
  4181. { Add exepath if the exe is not in the current dir, because that is always searched already.
  4182. Do not add it when linking on the target because then we can maybe already find
  4183. .o files that are not for the target }
  4184. if (ExePath<>cfileutl.GetCurrentDir) and
  4185. not(cs_link_on_target in init_settings.globalswitches) then
  4186. UnitSearchPath.AddPath(ExePath,false);
  4187. { Add unit dir to the object and library path }
  4188. objectsearchpath.AddList(unitsearchpath,false);
  4189. librarysearchpath.AddList(unitsearchpath,false);
  4190. {$ifdef llvm}
  4191. { default to clang }
  4192. if (option.paratargetasm=as_none) then
  4193. begin
  4194. option.paratargetasm:=as_clang_llvm;
  4195. end;
  4196. {$endif llvm}
  4197. { maybe override assembler }
  4198. if (option.paratargetasm<>as_none) then
  4199. begin
  4200. if not set_target_asm(option.paratargetasm) then
  4201. begin
  4202. if assigned(asminfos[option.paratargetasm]) then
  4203. Message2(option_incompatible_asm,asminfos[option.paratargetasm]^.idtxt,target_info.name)
  4204. else
  4205. Message2(option_incompatible_asm,'<invalid assembler>',target_info.name);
  4206. set_target_asm(target_info.assemextern);
  4207. Message1(option_asm_forced,target_asm.idtxt);
  4208. end;
  4209. if (af_no_debug in asminfos[option.paratargetasm]^.flags) and
  4210. (option.paratargetdbg<>dbg_none) then
  4211. begin
  4212. Message1(option_confict_asm_debug,
  4213. asminfos[option.paratargetasm]^.idtxt);
  4214. option.paratargetdbg:=dbg_none;
  4215. exclude(init_settings.moduleswitches,cs_debuginfo);
  4216. end;
  4217. { Some assemblers, like clang, do not support
  4218. stabs debugging format, switch to dwardé in that case }
  4219. if (af_no_stabs in asminfos[option.paratargetasm]^.flags) and
  4220. (option.paratargetdbg=dbg_stabs) then
  4221. begin
  4222. option.paratargetdbg:=dbg_dwarf2;
  4223. end;
  4224. end;
  4225. {TOptionheck a second time as we might have changed assembler just above }
  4226. option.checkoptionscompatibility;
  4227. { maybe override debug info format }
  4228. if (option.paratargetdbg<>dbg_none) then
  4229. if not set_target_dbg(option.paratargetdbg) then
  4230. Message(option_w_unsupported_debug_format);
  4231. { switch assembler if it's binary and we got -a on the cmdline }
  4232. if (af_outputbinary in target_asm.flags) and
  4233. ((cs_asm_leave in init_settings.globalswitches) or
  4234. { if -s is passed, we shouldn't call the internal assembler }
  4235. (cs_asm_extern in init_settings.globalswitches)) then
  4236. begin
  4237. Message(option_switch_bin_to_src_assembler);
  4238. {$ifdef llvm}
  4239. set_target_asm(as_clang_llvm);
  4240. {$else}
  4241. set_target_asm(target_info.assemextern);
  4242. {$endif}
  4243. { At least i8086 needs that for nasm and -CX
  4244. which is incompatible with internal linker }
  4245. option.checkoptionscompatibility;
  4246. end;
  4247. { Force use of external linker if there is no
  4248. internal linker or the linking is skipped }
  4249. if not(cs_link_extern in init_settings.globalswitches) and
  4250. ((target_info.link=ld_none) or
  4251. (cs_link_nolink in init_settings.globalswitches)) then
  4252. begin
  4253. include(init_settings.globalswitches,cs_link_extern);
  4254. end;
  4255. { turn off stripping if compiling with debuginfo or profile }
  4256. if (
  4257. (cs_debuginfo in init_settings.moduleswitches) or
  4258. (cs_profile in init_settings.moduleswitches)
  4259. ) and
  4260. not(cs_link_separate_dbg_file in init_settings.globalswitches) then
  4261. exclude(init_settings.globalswitches,cs_link_strip);
  4262. { choose a reasonable tls model }
  4263. if (tf_section_threadvars in target_info.flags) and (init_settings.tlsmodel=tlsm_none) then
  4264. begin
  4265. if cs_create_pic in init_settings.moduleswitches then
  4266. init_settings.tlsmodel:=tlsm_global_dynamic
  4267. else
  4268. init_settings.tlsmodel:=tlsm_local_exec;
  4269. end;
  4270. { set Mac OS X version default macros if not specified explicitly }
  4271. option.MaybeSetDefaultMacVersionMacro;
  4272. {$ifdef cpufpemu}
  4273. { force fpu emulation on arm/wince, arm/gba, arm/embedded and arm/nds
  4274. if fpu type not explicitly set }
  4275. if not(option.FPUSetExplicitly) and
  4276. ((target_info.system in [system_arm_wince,system_arm_gba,
  4277. system_m68k_amiga,system_m68k_atari,
  4278. system_arm_nds,system_arm_embedded,system_arm_freertos,
  4279. system_riscv32_embedded,system_riscv64_embedded,system_xtensa_linux,
  4280. system_z80_embedded,system_z80_zxspectrum])
  4281. {$ifdef arm}
  4282. or (target_info.abi=abi_eabi)
  4283. {$endif arm}
  4284. )
  4285. or (init_settings.fputype=fpu_soft)
  4286. then
  4287. begin
  4288. include(init_settings.moduleswitches,cs_fp_emulation);
  4289. { cs_fp_emulation and fpu_soft are equal on arm and m68k }
  4290. init_settings.fputype:=fpu_soft;
  4291. end;
  4292. {$endif cpufpemu}
  4293. {$ifdef i386}
  4294. if target_info.system in systems_i386_default_486 then
  4295. begin
  4296. { Avoid use of MMX/CMOVcc instructions on older systems.
  4297. Some systems might not handle these instructions correctly,
  4298. Used emulators might also be problematic. PM }
  4299. if not option.CPUSetExplicitly then
  4300. init_settings.cputype:=cpu_486;
  4301. end;
  4302. case target_info.system of
  4303. system_i386_android:
  4304. begin
  4305. { set default cpu type to PentiumM for Android unless specified otherwise }
  4306. if not option.CPUSetExplicitly then
  4307. init_settings.cputype:=cpu_PentiumM;
  4308. if not option.OptCPUSetExplicitly then
  4309. init_settings.optimizecputype:=cpu_PentiumM;
  4310. { set default fpu type to SSSE3 for Android unless specified otherwise }
  4311. if not option.FPUSetExplicitly then
  4312. init_settings.fputype:=fpu_ssse3;
  4313. end;
  4314. else
  4315. ;
  4316. end;
  4317. {$endif i386}
  4318. {$ifdef xtensa}
  4319. { xtensa-linux target does not support controller setting option -Wp }
  4320. if not(option.FPUSetExplicitly) and not(target_info.system = system_xtensa_linux) then
  4321. begin
  4322. init_settings.fputype:=embedded_controllers[init_settings.controllertype].fputype;
  4323. if (init_settings.fputype=fpu_soft) then
  4324. include(init_settings.moduleswitches,cs_fp_emulation);
  4325. end;
  4326. if not(option.CPUSetExplicitly) and (target_info.system=system_xtensa_linux) then
  4327. init_settings.cputype:=cpu_lx6;
  4328. if (target_info.system in [system_xtensa_embedded,system_xtensa_freertos]) and not(option.ABISetExplicitly) then
  4329. begin
  4330. if CPUXTENSA_REGWINDOW in cpu_capabilities[init_settings.cputype] then
  4331. target_info.abi:=abi_xtensa_windowed
  4332. else
  4333. target_info.abi:=abi_xtensa_call0;
  4334. end;
  4335. {$endif xtensa}
  4336. {$ifdef arm}
  4337. case target_info.system of
  4338. system_arm_ios:
  4339. begin
  4340. { set default cpu type to ARMv7 for Darwin unless specified otherwise, and fpu
  4341. to VFPv3 (that's what all 32 bit ARM iOS devices use nowadays)
  4342. }
  4343. if not option.CPUSetExplicitly then
  4344. init_settings.cputype:=cpu_armv7;
  4345. if not option.OptCPUSetExplicitly then
  4346. init_settings.optimizecputype:=cpu_armv7;
  4347. if not option.FPUSetExplicitly then
  4348. init_settings.fputype:=fpu_vfpv3;
  4349. end;
  4350. system_arm_android:
  4351. begin
  4352. { set default cpu type to ARMv5T for Android unless specified otherwise }
  4353. if not option.CPUSetExplicitly then
  4354. init_settings.cputype:=cpu_armv5t;
  4355. if not option.OptCPUSetExplicitly then
  4356. init_settings.optimizecputype:=cpu_armv5t;
  4357. end;
  4358. else
  4359. ;
  4360. end;
  4361. { set ABI defaults }
  4362. case target_info.abi of
  4363. abi_eabihf:
  4364. { set default cpu type to ARMv7a for ARMHF unless specified otherwise }
  4365. begin
  4366. {$ifdef CPUARMV6}
  4367. { if the compiler is built for armv6, then
  4368. inherit this setting, e.g. Raspian is armhf but
  4369. only armv6, this makes rebuilds of the compiler
  4370. easier }
  4371. if not option.CPUSetExplicitly then
  4372. init_settings.cputype:=cpu_armv6;
  4373. if not option.OptCPUSetExplicitly then
  4374. init_settings.optimizecputype:=cpu_armv6;
  4375. {$else CPUARMV6}
  4376. if not option.CPUSetExplicitly then
  4377. init_settings.cputype:=cpu_armv7a;
  4378. if not option.OptCPUSetExplicitly then
  4379. init_settings.optimizecputype:=cpu_armv7a;
  4380. {$endif CPUARMV6}
  4381. { Set FPU type }
  4382. if not(option.FPUSetExplicitly) then
  4383. begin
  4384. if init_settings.cputype < cpu_armv7 then
  4385. init_settings.fputype:=fpu_vfpv2
  4386. else
  4387. init_settings.fputype:=fpu_vfpv3_d16;
  4388. end
  4389. else
  4390. begin
  4391. if (not(FPUARM_HAS_VFP_EXTENSION in fpu_capabilities[init_settings.fputype]))
  4392. or (target_info.system = system_arm_ios) then
  4393. begin
  4394. Message(option_illegal_fpu_eabihf);
  4395. StopOptions(1);
  4396. end;
  4397. end;
  4398. end;
  4399. abi_eabi:
  4400. begin
  4401. if target_info.system=system_arm_linux then
  4402. begin
  4403. { this is what Debian uses }
  4404. if not option.CPUSetExplicitly then
  4405. init_settings.cputype:=cpu_armv4t;
  4406. if not option.OptCPUSetExplicitly then
  4407. init_settings.optimizecputype:=cpu_armv4t;
  4408. if not(option.FPUSetExplicitly) then
  4409. init_settings.fputype:=fpu_soft;
  4410. end;
  4411. end;
  4412. else
  4413. ;
  4414. end;
  4415. if (init_settings.instructionset=is_thumb) and not(CPUARM_HAS_THUMB2 in cpu_capabilities[init_settings.cputype]) then
  4416. begin
  4417. def_system_macro('CPUTHUMB');
  4418. if not option.FPUSetExplicitly then
  4419. init_settings.fputype:=fpu_soft;
  4420. if not(init_settings.fputype in [fpu_none,fpu_soft,fpu_libgcc]) then
  4421. Message2(option_unsupported_fpu,fputypestr[init_settings.fputype],'Thumb');
  4422. {$if defined(FPC_ARMEL) or defined(FPC_ARMHF)}
  4423. 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';
  4424. {$else FPC_ARMAL or FPC_ARMHF}
  4425. if target_info.endian=endian_little then
  4426. 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';
  4427. {$endif FPC_ARMAL or FPC_ARMHF}
  4428. end;
  4429. if (init_settings.instructionset=is_thumb) and (CPUARM_HAS_THUMB2 in cpu_capabilities[init_settings.cputype]) then
  4430. def_system_macro('CPUTHUMB2');
  4431. {$endif arm}
  4432. {$ifdef aarch64}
  4433. case target_info.system of
  4434. system_aarch64_darwin:
  4435. begin
  4436. if not option.CPUSetExplicitly then
  4437. init_settings.cputype:=cpu_armv84a;
  4438. if not option.OptCPUSetExplicitly then
  4439. init_settings.optimizecputype:=cpu_armv84a;
  4440. end;
  4441. else
  4442. ;
  4443. end;
  4444. {$endif aarch64}
  4445. {$if defined(riscv32) or defined(riscv64)}
  4446. { RISC-V defaults }
  4447. if (target_info.abi = abi_riscv_hf) then
  4448. begin
  4449. {$ifdef riscv32}
  4450. if not option.CPUSetExplicitly then
  4451. init_settings.cputype:=cpu_rv32ima;
  4452. if not option.OptCPUSetExplicitly then
  4453. init_settings.optimizecputype:=cpu_rv32ima;
  4454. {$else}
  4455. if not option.CPUSetExplicitly then
  4456. init_settings.cputype:=cpu_rv64imac;
  4457. if not option.OptCPUSetExplicitly then
  4458. init_settings.optimizecputype:=cpu_rv64imac;
  4459. {$endif}
  4460. { Set FPU type }
  4461. if not(option.FPUSetExplicitly) then
  4462. init_settings.fputype:=fpu_fd
  4463. else
  4464. begin
  4465. if not (init_settings.fputype in [fpu_fd]) then
  4466. begin
  4467. Message(option_illegal_fpu_eabihf);
  4468. StopOptions(1);
  4469. end;
  4470. end;
  4471. end;
  4472. {$endif defined(riscv32) or defined(riscv64)}
  4473. {$ifdef jvm}
  4474. { set default CPU type to Dalvik when targeting Android }
  4475. if target_info.system=system_jvm_android32 then
  4476. begin
  4477. if not option.CPUSetExplicitly then
  4478. init_settings.cputype:=cpu_dalvik;
  4479. end;
  4480. {$endif jvm}
  4481. {$ifdef llvm}
  4482. { standard extension for llvm bitcode files }
  4483. target_info.asmext:='.ll';
  4484. { don't generate dwarf cfi, llvm will do that }
  4485. exclude(target_info.flags,tf_needs_dwarf_cfi);
  4486. {$endif llvm}
  4487. {$ifdef mipsel}
  4488. case target_info.system of
  4489. system_mipsel_android:
  4490. begin
  4491. { set default cpu type to MIPS32 rev. 1 and hard float for MIPS-Android unless specified otherwise }
  4492. if not option.CPUSetExplicitly then
  4493. init_settings.cputype:=cpu_mips32;
  4494. if not option.OptCPUSetExplicitly then
  4495. init_settings.optimizecputype:=cpu_mips32;
  4496. if not option.FPUSetExplicitly then
  4497. init_settings.fputype:=fpu_mips2;
  4498. end;
  4499. system_mipsel_embedded:
  4500. begin
  4501. { set default cpu type to PIC32MX and softfloat for MIPSEL-EMBEDDED target unless specified otherwise }
  4502. if not option.CPUSetExplicitly then
  4503. init_settings.cputype:=cpu_pic32mx;
  4504. if not option.OptCPUSetExplicitly then
  4505. init_settings.optimizecputype:=cpu_pic32mx;
  4506. if not option.FPUSetExplicitly then
  4507. init_settings.fputype:=fpu_soft;
  4508. end;
  4509. else
  4510. ;
  4511. end;
  4512. {$endif mipsel}
  4513. {$ifdef m68k}
  4514. if init_settings.cputype in cpu_coldfire then
  4515. def_system_macro('CPUCOLDFIRE');
  4516. case target_info.system of
  4517. system_m68k_linux,
  4518. system_m68k_netbsd:
  4519. begin
  4520. if not (option.FPUSetExplicitly) and
  4521. not (init_settings.cputype in cpu_coldfire) then
  4522. begin
  4523. { enable HW FPU for UNIX by default, but only for
  4524. original 68k, not Coldfire }
  4525. exclude(init_settings.moduleswitches,cs_fp_emulation);
  4526. init_settings.fputype:=fpu_68881;
  4527. end;
  4528. end;
  4529. system_m68k_sinclairql:
  4530. begin
  4531. if not option.CPUSetExplicitly then
  4532. init_settings.cputype:=cpu_mc68000;
  4533. end;
  4534. system_m68k_palmos:
  4535. begin
  4536. if not option.CPUSetExplicitly then
  4537. init_settings.cputype:=cpu_mc68000;
  4538. if not (option.FPUSetExplicitly) then
  4539. begin
  4540. { No FPU for PalmOS by default }
  4541. exclude(init_settings.moduleswitches,cs_fp_emulation);
  4542. init_settings.fputype:=fpu_none;
  4543. end;
  4544. end;
  4545. else
  4546. ;
  4547. end;
  4548. {$endif m68k}
  4549. { now we can define cpu and fpu type }
  4550. def_cpu_macros;
  4551. { Use init_settings cpu type for asm cpu type,
  4552. if asmcputype is cpu_none,
  4553. at least as long as there is no explicit
  4554. option to set it on command line PM }
  4555. if init_settings.asmcputype = cpu_none then
  4556. init_settings.asmcputype:=init_settings.cputype;
  4557. {$ifdef llvm}
  4558. def_system_macro('CPULLVM');
  4559. {$endif llvm}
  4560. {$if defined(cpucapabilities)}
  4561. for cpuflag:=low(cpuflag) to high(cpuflag) do
  4562. begin
  4563. str(cpuflag,hs);
  4564. if cpuflag in cpu_capabilities[init_settings.cputype] then
  4565. def_system_macro(hs)
  4566. else
  4567. undef_system_macro(hs);
  4568. end;
  4569. {$endif defined(cpucapabilities)}
  4570. {$if defined(fpucapabilities)}
  4571. for fpuflag:=low(fpuflag) to high(fpuflag) do
  4572. begin
  4573. str(fpuflag,hs);
  4574. if fpuflag in fpu_capabilities[init_settings.fputype] then
  4575. def_system_macro(hs)
  4576. else
  4577. undef_system_macro(hs);
  4578. end;
  4579. {$endif defined(fpucapabilities)}
  4580. if init_settings.fputype<>fpu_none then
  4581. begin
  4582. {$if defined(i386) or defined(i8086)}
  4583. def_system_macro('FPC_HAS_TYPE_EXTENDED');
  4584. {$endif}
  4585. def_system_macro('FPC_HAS_TYPE_SINGLE');
  4586. def_system_macro('FPC_HAS_TYPE_DOUBLE');
  4587. {$if not defined(i386) and not defined(x86_64) and not defined(i8086) and not defined(aarch64)}
  4588. def_system_macro('FPC_INCLUDE_SOFTWARE_INT64_TO_DOUBLE');
  4589. {$endif}
  4590. {$if defined(m68k)}
  4591. def_system_macro('FPC_INCLUDE_SOFTWARE_LONGWORD_TO_DOUBLE');
  4592. {$endif}
  4593. {$ifdef x86_64}
  4594. {$ifndef FPC_SUPPORT_X87_TYPES_ON_WIN64}
  4595. { normally, win64 doesn't support the legacy fpu }
  4596. if target_info.system=system_x86_64_win64 then
  4597. undef_system_macro('FPC_HAS_TYPE_EXTENDED')
  4598. else
  4599. {$endif FPC_SUPPORT_X87_TYPES_ON_WIN64}
  4600. def_system_macro('FPC_HAS_TYPE_EXTENDED');
  4601. {$endif}
  4602. end;
  4603. { Enable now for testing }
  4604. {$ifndef DISABLE_TLS_DIRECTORY}
  4605. if target_info.system in systems_windows then
  4606. def_system_macro('FPC_USE_TLS_DIRECTORY');
  4607. {$endif not DISABLE_TLS_DIRECTORY}
  4608. {$ifndef DISABLE_WIN64_SEH}
  4609. if target_info.system=system_x86_64_win64 then
  4610. def_system_macro('FPC_USE_WIN64_SEH');
  4611. {$endif DISABLE_WIN64_SEH}
  4612. {$ifndef DISABLE_WIN32_SEH}
  4613. if target_info.system=system_i386_win32 then
  4614. def_system_macro('FPC_USE_WIN32_SEH');
  4615. {$endif not DISABLE_WIN32_SEH}
  4616. {$ifdef ARM}
  4617. { define FPC_DOUBLE_HILO_SWAPPED if needed to properly handle doubles in RTL }
  4618. if (init_settings.fputype in [fpu_fpa,fpu_fpa10,fpu_fpa11]) and
  4619. not(cs_fp_emulation in init_settings.moduleswitches) then
  4620. def_system_macro('FPC_DOUBLE_HILO_SWAPPED');
  4621. {$endif ARM}
  4622. { inline bsf/bsr implementation }
  4623. {$if defined(i386) or defined(x86_64) or defined(aarch64) or defined(powerpc) or defined(powerpc64)}
  4624. def_system_macro('FPC_HAS_INTERNAL_BSF');
  4625. def_system_macro('FPC_HAS_INTERNAL_BSR');
  4626. {$endif}
  4627. { hardware FMA support }
  4628. {$if defined(i386) or defined(x86_64)}
  4629. if (fpu_capabilities[current_settings.fputype]*[FPUX86_HAS_FMA,FPUX86_HAS_FMA4])<>[] then
  4630. begin
  4631. def_system_macro('FPC_HAS_FAST_FMA_SINGLE');
  4632. def_system_macro('FPC_HAS_FAST_FMA_DOUBLE');
  4633. end;
  4634. {$endif defined(i386) or defined(x86_64)}
  4635. {$if defined(arm)}
  4636. { it is determined during system unit compilation if clz is used for bsf or not,
  4637. this is not perfect but the current implementation bsf/bsr does not allow another
  4638. solution }
  4639. if (CPUARM_HAS_CLZ in cpu_capabilities[init_settings.cputype]) and
  4640. ((init_settings.instructionset=is_arm) or
  4641. (CPUARM_HAS_THUMB2 in cpu_capabilities[init_settings.cputype])) then
  4642. begin
  4643. def_system_macro('FPC_HAS_INTERNAL_BSR');
  4644. if CPUARM_HAS_RBIT in cpu_capabilities[init_settings.cputype] then
  4645. def_system_macro('FPC_HAS_INTERNAL_BSF');
  4646. end;
  4647. {$endif}
  4648. {$if defined(xtensa)}
  4649. { it is determined during system unit compilation if nsau is used for bsr or not,
  4650. this is not perfect but the current implementation bsf/bsr does not allow another
  4651. solution }
  4652. if CPUXTENSA_HAS_NSAx in cpu_capabilities[init_settings.cputype] then
  4653. begin
  4654. def_system_macro('FPC_HAS_INTERNAL_BSR');
  4655. end;
  4656. {$endif}
  4657. {$if defined(powerpc64)}
  4658. { on sysv targets, default to elfv2 for little endian and to elfv1 for
  4659. big endian (unless specified otherwise). As the gcc man page says:
  4660. "Overriding the default ABI requires special system support and is
  4661. likely to fail in spectacular ways" }
  4662. if not option.ABISetExplicitly then
  4663. begin
  4664. if (target_info.abi=abi_powerpc_sysv) and
  4665. (target_info.endian=endian_little) then
  4666. target_info.abi:=abi_powerpc_elfv2
  4667. else
  4668. if (target_info.abi=abi_powerpc_elfv2) and
  4669. (target_info.endian=endian_big) then
  4670. target_info.abi:=abi_powerpc_sysv
  4671. end;
  4672. {$endif}
  4673. {$if defined(powerpc) or defined(powerpc64)}
  4674. { define _CALL_ELF symbol like gcc }
  4675. case target_info.abi of
  4676. abi_powerpc_sysv:
  4677. set_system_compvar('_CALL_ELF','1');
  4678. abi_powerpc_elfv2:
  4679. set_system_compvar('_CALL_ELF','2');
  4680. else
  4681. ;
  4682. end;
  4683. {$endif}
  4684. { Section smartlinking conflicts with import sections on Windows }
  4685. if GenerateImportSection and
  4686. (target_info.system in [system_i386_win32,system_x86_64_win64,system_aarch64_win64]) then
  4687. exclude(target_info.flags,tf_smartlink_sections);
  4688. if not option.LinkTypeSetExplicitly then
  4689. set_default_link_type;
  4690. { Default alignment settings,
  4691. 1. load the defaults for the target
  4692. 2. adapt defaults specifically for the target
  4693. 3. override with generic optimizer setting (little size)
  4694. 4. override with the user specified -Oa }
  4695. UpdateAlignment(init_settings.alignment,target_info.alignment);
  4696. {$ifdef arm}
  4697. if (init_settings.instructionset=is_thumb) and not(CPUARM_HAS_THUMB2 in cpu_capabilities[init_settings.cputype]) then
  4698. begin
  4699. init_settings.alignment.procalign:=2;
  4700. init_settings.alignment.jumpalign:=2;
  4701. init_settings.alignment.coalescealign:=2;
  4702. init_settings.alignment.loopalign:=2;
  4703. end;
  4704. {$endif arm}
  4705. if (cs_opt_size in init_settings.optimizerswitches) then
  4706. begin
  4707. init_settings.alignment.procalign:=1;
  4708. init_settings.alignment.jumpalign:=1;
  4709. init_settings.alignment.coalescealign:=1;
  4710. init_settings.alignment.loopalign:=1;
  4711. {$ifdef x86}
  4712. { constalignmax=1 keeps the executable and thus the memory foot print small but
  4713. all processors except x86 are really hurt by this or might even crash }
  4714. init_settings.alignment.constalignmax:=1;
  4715. {$endif x86}
  4716. end;
  4717. UpdateAlignment(init_settings.alignment,option.paraalignment);
  4718. set_system_macro('FPC_VERSION',version_nr);
  4719. set_system_macro('FPC_RELEASE',release_nr);
  4720. set_system_macro('FPC_PATCH',patch_nr);
  4721. set_system_macro('FPC_FULLVERSION',Format('%d%.02d%.02d',[StrToInt(version_nr),StrToInt(release_nr),StrToInt(patch_nr)]));
  4722. if target_info.system in systems_indirect_entry_information then
  4723. def_system_macro('FPC_HAS_INDIRECT_ENTRY_INFORMATION');
  4724. if not (tf_winlikewidestring in target_info.flags) then
  4725. def_system_macro('FPC_WIDESTRING_EQUAL_UNICODESTRING');
  4726. if tf_supports_packages in target_info.flags then
  4727. def_system_macro('FPC_HAS_DYNAMIC_PACKAGES');
  4728. if target_info.system in systems_indirect_var_imports then
  4729. def_system_macro('FPC_HAS_INDIRECT_VAR_ACCESS');
  4730. if cs_compilesystem in init_settings.moduleswitches then
  4731. for i:=low(tfeature) to high(tfeature) do
  4732. if i in features then
  4733. def_system_macro('FPC_HAS_FEATURE_'+featurestr[i]);
  4734. {$push}
  4735. {$warn 6018 off} { Unreachable code due to compile time evaluation }
  4736. if ControllerSupport and (target_info.system in (systems_embedded+systems_freertos)) and
  4737. (init_settings.controllertype<>ct_none) then
  4738. begin
  4739. with embedded_controllers[init_settings.controllertype] do
  4740. begin
  4741. set_system_macro('FPC_FLASHBASE',tostr(flashbase));
  4742. set_system_macro('FPC_FLASHSIZE',tostr(flashsize));
  4743. set_system_macro('FPC_SRAMBASE',tostr(srambase));
  4744. set_system_macro('FPC_SRAMSIZE',tostr(sramsize));
  4745. set_system_macro('FPC_EEPROMBASE',tostr(eeprombase));
  4746. set_system_macro('FPC_EEPROMSIZE',tostr(eepromsize));
  4747. set_system_macro('FPC_BOOTBASE',tostr(bootbase));
  4748. set_system_macro('FPC_BOOTSIZE',tostr(bootsize));
  4749. end;
  4750. end;
  4751. {$pop}
  4752. { as stackalign is not part of the alignment record, we do not need to define the others alignments for symmetry yet }
  4753. set_system_macro('FPC_STACKALIGNMENT',tostr(target_info.stackalign));
  4754. option.free;
  4755. Option:=nil;
  4756. clearstack_pocalls := [pocall_cdecl,pocall_cppdecl,pocall_syscall,pocall_mwpascal,pocall_sysv_abi_cdecl,pocall_ms_abi_cdecl{$ifdef z80},pocall_stdcall{$endif}];
  4757. cdecl_pocalls := [pocall_cdecl, pocall_cppdecl, pocall_mwpascal, pocall_sysv_abi_cdecl, pocall_ms_abi_cdecl];
  4758. if (tf_safecall_clearstack in target_info.flags) then
  4759. begin
  4760. include (cdecl_pocalls, pocall_safecall);
  4761. include (clearstack_pocalls, pocall_safecall)
  4762. end;
  4763. end;
  4764. initialization
  4765. coption:=toption;
  4766. finalization
  4767. if assigned(option) then
  4768. option.free;
  4769. end.