options.pas 152 KB

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