options.pas 152 KB

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