options.pas 149 KB

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