options.pas 152 KB

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