options.pas 148 KB

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