options.pas 162 KB

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