options.pas 156 KB

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