options.pas 121 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624
  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,
  22. globtype,globals,verbose,systems,cpuinfo,comprsrc;
  23. Type
  24. TOption=class
  25. FirstPass,
  26. ParaLogo,
  27. NoPressEnter,
  28. FPCHelpLines,
  29. LogoWritten,
  30. FPUSetExplicitly,
  31. CPUSetExplicitly,
  32. OptCPUSetExplicitly: boolean;
  33. FileLevel : longint;
  34. QuickInfo : string;
  35. FPCBinaryPath: string;
  36. ParaIncludeCfgPath,
  37. ParaIncludePath,
  38. ParaUnitPath,
  39. ParaObjectPath,
  40. ParaLibraryPath,
  41. ParaFrameworkPath : TSearchPathList;
  42. ParaAlignment : TAlignmentInfo;
  43. Constructor Create;
  44. Destructor Destroy;override;
  45. procedure WriteLogo;
  46. procedure WriteInfo;
  47. procedure WriteHelpPages;
  48. procedure WriteQuickInfo;
  49. procedure IllegalPara(const opt:TCmdStr);
  50. procedure UnsupportedPara(const opt:TCmdStr);
  51. procedure IgnoredPara(const opt:TCmdStr);
  52. function Unsetbool(var Opts:TCmdStr; Pos: Longint; const FullPara: TCmdStr; RequireBoolPara: Boolean):boolean;
  53. procedure interpret_option(const opt :TCmdStr;ispara:boolean);
  54. procedure Interpret_envvar(const envname : TCmdStr);
  55. procedure Interpret_file(const filename : TPathStr);
  56. procedure Read_Parameters;
  57. procedure parsecmd(cmd:TCmdStr);
  58. procedure TargetOptions(def:boolean);
  59. procedure CheckOptionsCompatibility;
  60. procedure ForceStaticLinking;
  61. protected
  62. MacVersionSet: boolean;
  63. function ParseMacVersionMin(out minstr, emptystr: string; const compvarname, value: string; ios: boolean): boolean;
  64. procedure MaybeSetDefaultMacVersionMacro;
  65. end;
  66. TOptionClass=class of toption;
  67. var
  68. coption : TOptionClass;
  69. procedure read_arguments(cmd:TCmdStr);
  70. implementation
  71. uses
  72. widestr,
  73. {$if FPC_FULLVERSION<20700}ccharset{$else}charset{$endif},
  74. SysUtils,
  75. version,
  76. cutils,cmsgs,
  77. comphook,
  78. symtable,scanner,rabase,
  79. symconst,
  80. {$ifdef llvm}
  81. { override supported optimizer transformations at the compiler level }
  82. llvminfo,
  83. {$endif llvm}
  84. dirparse,
  85. i_bsd;
  86. const
  87. page_size = 24;
  88. var
  89. option : toption;
  90. read_configfile, { read config file, set when a cfgfile is found }
  91. disable_configfile : boolean;
  92. fpcdir,
  93. ppccfg,
  94. param_file : string; { file to compile specified on the commandline }
  95. {****************************************************************************
  96. Options not supported on all platforms
  97. ****************************************************************************}
  98. const
  99. { pointer checking (requires special code in FPC_CHECKPOINTER,
  100. and can never work for libc-based targets or any other program
  101. linking to an external library)
  102. }
  103. supported_targets_gc = [system_i386_linux,system_powerpc_linux]
  104. + [system_i386_win32]
  105. + [system_i386_GO32V2]
  106. + [system_i386_os2]
  107. + [system_i386_beos,system_i386_haiku]
  108. + [system_powerpc_morphos];
  109. { gprof (requires implementation of g_profilecode in the code generator) }
  110. supported_targets_pg = [system_i386_linux,system_x86_64_linux,system_mipseb_linux,system_mipsel_linux]
  111. + [system_i386_win32]
  112. + [system_powerpc_darwin,system_x86_64_darwin]
  113. + [system_i386_GO32V2]
  114. + [system_i386_freebsd]
  115. + [system_i386_netbsd]
  116. + [system_i386_wdosx];
  117. suppported_targets_x_smallr = systems_linux + systems_solaris
  118. + [system_i386_haiku]
  119. + [system_i386_beos]
  120. + [system_m68k_amiga];
  121. {****************************************************************************
  122. Defines
  123. ****************************************************************************}
  124. procedure set_default_link_type;
  125. begin
  126. undef_system_macro('FPC_LINK_SMART');
  127. def_system_macro('FPC_LINK_STATIC');
  128. undef_system_macro('FPC_LINK_DYNAMIC');
  129. init_settings.globalswitches:=init_settings.globalswitches+[cs_link_static];
  130. init_settings.globalswitches:=init_settings.globalswitches-[cs_link_shared,cs_link_smart];
  131. end;
  132. {****************************************************************************
  133. Toption
  134. ****************************************************************************}
  135. procedure StopOptions(err:longint);
  136. begin
  137. if assigned(Option) then
  138. begin
  139. Option.free;
  140. Option:=nil;
  141. end;
  142. raise ECompilerAbortSilent.Create;
  143. end;
  144. function is_identifier(const s: TCmdStr): boolean;
  145. var
  146. i: longint;
  147. begin
  148. result:=false;
  149. if (s='') or not (s[1] in ['A'..'Z','a'..'z','_']) then
  150. exit;
  151. for i:=2 to length(s) do
  152. if not (s[I] in ['A'..'Z','a'..'z','0'..'9','_']) then
  153. exit;
  154. result:=true;
  155. end;
  156. procedure Toption.WriteLogo;
  157. var
  158. p : pchar;
  159. begin
  160. if not LogoWritten then
  161. begin
  162. p:=MessagePchar(option_logo);
  163. while assigned(p) do
  164. Comment(V_Normal,GetMsgLine(p));
  165. LogoWritten:= true;
  166. end;
  167. end;
  168. procedure Toption.WriteInfo;
  169. var
  170. p : pchar;
  171. hs,hs1,s : TCmdStr;
  172. target : tsystem;
  173. cpu : tcputype;
  174. fpu : tfputype;
  175. opt : toptimizerswitch;
  176. wpopt: twpoptimizerswitch;
  177. abi : tabi;
  178. asmmode : tasmmode;
  179. {$if defined(arm) or defined(avr)}
  180. controllertype : tcontrollertype;
  181. {$endif defined(arm) or defined(avr)}
  182. begin
  183. p:=MessagePchar(option_info);
  184. while assigned(p) do
  185. begin
  186. s:=GetMsgLine(p);
  187. { list OS Targets }
  188. if pos('$OSTARGETS',s)>0 then
  189. begin
  190. for target:=low(tsystem) to high(tsystem) do
  191. if assigned(targetinfos[target]) then
  192. begin
  193. hs:=s;
  194. hs1:=targetinfos[target]^.name;
  195. if tf_under_development in targetinfos[target]^.flags then
  196. hs1:=hs1+' (under development)';
  197. Replace(hs,'$OSTARGETS',hs1);
  198. Comment(V_Normal,hs);
  199. end;
  200. end
  201. else if pos('$INSTRUCTIONSETS',s)>0 then
  202. begin
  203. hs1:='';
  204. for cpu:=low(tcputype) to high(tcputype) do
  205. begin
  206. if length(hs1+cputypestr[cpu])>70 then
  207. begin
  208. hs:=s;
  209. Replace(hs,'$INSTRUCTIONSETS',hs1);
  210. Comment(V_Normal,hs);
  211. hs1:=''
  212. end
  213. else
  214. if hs1<>'' then
  215. hs1:=hs1+',';
  216. if cputypestr[cpu]<>'' then
  217. hs1:=hs1+cputypestr[cpu];
  218. end;
  219. if hs1<>'' then
  220. begin
  221. hs:=s;
  222. Replace(hs,'$INSTRUCTIONSETS',hs1);
  223. Comment(V_Normal,hs);
  224. hs1:=''
  225. end;
  226. end
  227. else if pos('$FPUINSTRUCTIONSETS',s)>0 then
  228. begin
  229. hs1:='';
  230. for fpu:=low(tfputype) to high(tfputype) do
  231. begin
  232. if length(hs1+fputypestr[fpu])>70 then
  233. begin
  234. hs:=s;
  235. Replace(hs,'$FPUINSTRUCTIONSETS',hs1);
  236. Comment(V_Normal,hs);
  237. hs1:=''
  238. end
  239. else
  240. if hs1<>'' then
  241. hs1:=hs1+',';
  242. if fputypestr[fpu]<>'' then
  243. hs1:=hs1+fputypestr[fpu];
  244. end;
  245. if hs1<>'' then
  246. begin
  247. hs:=s;
  248. Replace(hs,'$FPUINSTRUCTIONSETS',hs1);
  249. Comment(V_Normal,hs);
  250. hs1:=''
  251. end;
  252. end
  253. else if pos('$ABITARGETS',s)>0 then
  254. begin
  255. for abi:=low(abi) to high(abi) do
  256. begin
  257. if not abiinfo[abi].supported then
  258. continue;
  259. hs:=s;
  260. hs1:=abiinfo[abi].name;
  261. if hs1<>'' then
  262. begin
  263. Replace(hs,'$ABITARGETS',hs1);
  264. Comment(V_Normal,hs);
  265. end;
  266. end;
  267. end
  268. else if pos('$OPTIMIZATIONS',s)>0 then
  269. begin
  270. for opt:=low(toptimizerswitch) to high(toptimizerswitch) do
  271. begin
  272. if opt in supported_optimizerswitches then
  273. begin
  274. hs:=s;
  275. hs1:=OptimizerSwitchStr[opt];
  276. if hs1<>'' then
  277. begin
  278. Replace(hs,'$OPTIMIZATIONS',hs1);
  279. Comment(V_Normal,hs);
  280. end;
  281. end;
  282. end;
  283. end
  284. else if pos('$WPOPTIMIZATIONS',s)>0 then
  285. begin
  286. for wpopt:=low(twpoptimizerswitch) to high(twpoptimizerswitch) do
  287. begin
  288. { currently all whole program optimizations are platform-independent
  289. if opt in supported_wpoptimizerswitches then
  290. }
  291. begin
  292. hs:=s;
  293. hs1:=WPOptimizerSwitchStr[wpopt];
  294. if hs1<>'' then
  295. begin
  296. Replace(hs,'$WPOPTIMIZATIONS',hs1);
  297. Comment(V_Normal,hs);
  298. end;
  299. end;
  300. end
  301. end
  302. else if pos('$ASMMODES',s)>0 then
  303. begin
  304. for asmmode:=low(tasmmode) to high(tasmmode) do
  305. if assigned(asmmodeinfos[asmmode]) then
  306. begin
  307. hs:=s;
  308. hs1:=asmmodeinfos[asmmode]^.idtxt;
  309. if hs1<>'' then
  310. begin
  311. Replace(hs,'$ASMMODES',hs1);
  312. Comment(V_Normal,hs);
  313. end;
  314. end;
  315. end
  316. else if pos('$CONTROLLERTYPES',s)>0 then
  317. begin
  318. {$if defined(arm) or defined(avr)}
  319. hs1:='';
  320. for controllertype:=low(tcontrollertype) to high(tcontrollertype) do
  321. begin
  322. if length(hs1+embedded_controllers[controllertype].ControllerTypeStr)>70 then
  323. begin
  324. hs:=s;
  325. Replace(hs,'$CONTROLLERTYPES',hs1);
  326. Comment(V_Normal,hs);
  327. hs1:=''
  328. end
  329. else
  330. if hs1<>'' then
  331. hs1:=hs1+',';
  332. if embedded_controllers[controllertype].ControllerTypeStr<>'' then
  333. hs1:=hs1+embedded_controllers[controllertype].ControllerTypeStr;
  334. end;
  335. if hs1<>'' then
  336. begin
  337. hs:=s;
  338. Replace(hs,'$CONTROLLERTYPES',hs1);
  339. Comment(V_Normal,hs);
  340. hs1:=''
  341. end;
  342. {$else defined(arm) or defined(avr)}
  343. {$endif defined(arm) or defined(avr)}
  344. end
  345. else
  346. Comment(V_Normal,s);
  347. end;
  348. StopOptions(0);
  349. end;
  350. procedure Toption.WriteHelpPages;
  351. function PadEnd(s:string;i:longint):string;
  352. begin
  353. while (length(s)<i) do
  354. s:=s+' ';
  355. PadEnd:=s;
  356. end;
  357. var
  358. lastident,
  359. j,outline,
  360. ident,
  361. lines : longint;
  362. show : boolean;
  363. opt : string[32];
  364. input,
  365. s : string;
  366. p : pchar;
  367. begin
  368. WriteLogo;
  369. Lines:=4;
  370. if FPCHelpLines then
  371. Message1(option_usage,FixFileName(FPCBinaryPath))
  372. else
  373. Message1(option_usage,FixFileName(system.paramstr(0)));
  374. lastident:=0;
  375. p:=MessagePChar(option_help_pages);
  376. while assigned(p) do
  377. begin
  378. { get a line and reset }
  379. s:=GetMsgLine(p);
  380. ident:=0;
  381. show:=false;
  382. { parse options }
  383. case s[1] of
  384. 'F': if FPCHelpLines then
  385. Show := true;
  386. {$ifdef UNITALIASES}
  387. 'a',
  388. {$endif}
  389. {$ifdef EXTDEBUG}
  390. 'e',
  391. {$endif EXTDEBUG}
  392. {$ifdef i386}
  393. '3',
  394. {$endif}
  395. {$ifdef x86_64}
  396. '4',
  397. {$endif}
  398. {$ifdef m68k}
  399. '6',
  400. {$endif}
  401. {$ifdef i8086}
  402. '8',
  403. {$endif}
  404. {$ifdef arm}
  405. 'A',
  406. {$endif}
  407. {$ifdef powerpc}
  408. 'P',
  409. {$endif}
  410. {$ifdef powerpc64}
  411. 'p',
  412. {$endif}
  413. {$ifdef sparc}
  414. 'S',
  415. {$endif}
  416. {$ifdef vis}
  417. 'I',
  418. {$endif}
  419. {$ifdef avr}
  420. 'V',
  421. {$endif}
  422. {$ifdef jvm}
  423. 'J',
  424. {$endif}
  425. '*' : show:=true;
  426. end;
  427. if show then
  428. begin
  429. case s[2] of
  430. 'g',
  431. {$ifdef Unix}
  432. 'L',
  433. {$endif}
  434. {$ifdef os2}
  435. 'O',
  436. {$endif}
  437. '*' : show:=true;
  438. else
  439. show:=false;
  440. end;
  441. end;
  442. { now we may show the message or not }
  443. if show then
  444. begin
  445. case s[3] of
  446. '0' : begin
  447. ident:=0;
  448. outline:=0;
  449. end;
  450. '1' : begin
  451. ident:=2;
  452. outline:=7;
  453. end;
  454. '2' : begin
  455. ident:=6;
  456. outline:=11;
  457. end;
  458. '3' : begin
  459. ident:=9;
  460. outline:=11;
  461. end;
  462. else
  463. internalerror(2013112906);
  464. end;
  465. j:=pos('_',s);
  466. opt:=Copy(s,4,j-4);
  467. if opt='*' then
  468. opt:=''
  469. else
  470. if opt=' ' then
  471. opt:=PadEnd(opt,outline)
  472. else
  473. opt:=PadEnd('-'+opt,outline);
  474. if (ident=0) and (lastident<>0) then
  475. begin
  476. Comment(V_Normal,'');
  477. inc(Lines);
  478. end;
  479. { page full ? }
  480. if (lines >= page_size - 1) then
  481. begin
  482. if not NoPressEnter then
  483. begin
  484. Message(option_help_press_enter);
  485. readln(input);
  486. if upper(input)='Q' then
  487. StopOptions(0);
  488. end;
  489. lines:=0;
  490. end;
  491. Comment(V_Normal,PadEnd('',ident)+opt+Copy(s,j+1,255));
  492. LastIdent:=Ident;
  493. inc(Lines);
  494. end;
  495. end;
  496. StopOptions(0);
  497. end;
  498. procedure Toption.IllegalPara(const opt:TCmdStr);
  499. begin
  500. Message1(option_illegal_para,opt);
  501. Message(option_help_pages_para);
  502. StopOptions(1);
  503. end;
  504. procedure toption.UnsupportedPara(const opt: TCmdStr);
  505. begin
  506. Message1(option_unsupported_target,opt);
  507. StopOptions(1);
  508. end;
  509. procedure toption.IgnoredPara(const opt: TCmdStr);
  510. begin
  511. Message1(option_ignored_target,opt);
  512. end;
  513. procedure toption.ForceStaticLinking;
  514. begin
  515. def_system_macro('FPC_LINK_STATIC');
  516. undef_system_macro('FPC_LINK_SMART');
  517. undef_system_macro('FPC_LINK_DYNAMIC');
  518. include(init_settings.globalswitches,cs_link_static);
  519. exclude(init_settings.globalswitches,cs_link_smart);
  520. exclude(init_settings.globalswitches,cs_link_shared);
  521. LinkTypeSetExplicitly:=true;
  522. end;
  523. function toption.ParseMacVersionMin(out minstr, emptystr: string; const compvarname, value: string; ios: boolean): boolean;
  524. function subval(start,maxlen: longint; out stop: longint): string;
  525. var
  526. i: longint;
  527. begin
  528. result:='';
  529. i:=start;
  530. while (i<=length(value)) and
  531. (value[i] in ['0'..'9']) do
  532. inc(i);
  533. { sufficient amount of digits? }
  534. if (i=start) or
  535. (i-start>maxlen) then
  536. exit;
  537. result:=copy(value,start,i-start);
  538. stop:=i;
  539. end;
  540. var
  541. temp,
  542. compvarvalue: string[15];
  543. i: longint;
  544. begin
  545. minstr:=value;
  546. emptystr:='';
  547. MacVersionSet:=false;
  548. { check whether the value is a valid version number }
  549. if value='' then
  550. begin
  551. undef_system_macro(compvarname);
  552. exit(true);
  553. end;
  554. { major version number }
  555. compvarvalue:=subval(1,2,i);
  556. { not enough digits -> invalid }
  557. if compvarvalue='' then
  558. exit(false);
  559. { already end of string -> invalid }
  560. if (i>=length(value)) or
  561. (value[i]<>'.') then
  562. exit(false);
  563. { minor version number }
  564. temp:=subval(i+1,2,i);
  565. if temp='' then
  566. exit(false);
  567. { on Mac OS X, the minor version number is limited to 1 digit }
  568. if not ios then
  569. begin
  570. if length(temp)<>1 then
  571. exit(false);
  572. end
  573. { the minor version number always takes up two digits on iOS }
  574. else if length(temp)=1 then
  575. temp:='0'+temp;
  576. compvarvalue:=compvarvalue+temp;
  577. { optional patch level }
  578. if i<=length(value) then
  579. begin
  580. if value[i]<>'.' then
  581. exit(false);
  582. temp:=subval(i+1,2,i);
  583. if temp='' then
  584. exit(false);
  585. { there's only room for a single digit patch level in the version macro
  586. for Mac OS X. gcc sets it to zero if there are more digits, but that
  587. seems worse than clamping to 9 (don't declare as invalid like with
  588. minor version number, because there is a precedent like 10.4.11)
  589. }
  590. if not ios then
  591. begin
  592. if length(temp)<>1 then
  593. temp:='9';
  594. end
  595. else
  596. begin
  597. { on iOS, the patch level is always two digits }
  598. if length(temp)=1 then
  599. temp:='0'+temp;
  600. end;
  601. compvarvalue:=compvarvalue+temp;
  602. { must be the end }
  603. if i<=length(value) then
  604. exit(false);
  605. end
  606. else if not ios then
  607. compvarvalue:=compvarvalue+'0'
  608. else
  609. compvarvalue:=compvarvalue+'00';
  610. set_system_compvar(compvarname,compvarvalue);
  611. MacVersionSet:=true;
  612. result:=true;
  613. end;
  614. procedure TOption.MaybeSetDefaultMacVersionMacro;
  615. var
  616. envstr: ansistring;
  617. begin
  618. if not(target_info.system in systems_darwin) then
  619. exit;
  620. if MacVersionSet then
  621. exit;
  622. { check for deployment target set via environment variable }
  623. if not(target_info.system in [system_i386_iphonesim,system_arm_darwin]) then
  624. begin
  625. envstr:=GetEnvironmentVariable('MACOSX_DEPLOYMENT_TARGET');
  626. if envstr<>'' then
  627. if not ParseMacVersionMin(MacOSXVersionMin,iPhoneOSVersionMin,'MAC_OS_X_VERSION_MIN_REQUIRED',envstr,false) then
  628. Message1(option_invalid_macosx_deployment_target,envstr)
  629. else
  630. exit;
  631. end
  632. else
  633. begin
  634. envstr:=GetEnvironmentVariable('IPHONEOS_DEPLOYMENT_TARGET');
  635. if envstr<>'' then
  636. if not ParseMacVersionMin(iPhoneOSVersionMin,MacOSXVersionMin,'IPHONE_OS_VERSION_MIN_REQUIRED',envstr,true) then
  637. Message1(option_invalid_iphoneos_deployment_target,envstr)
  638. else
  639. exit;
  640. end;
  641. { nothing specified -> defaults }
  642. case target_info.system of
  643. system_powerpc_darwin:
  644. begin
  645. set_system_compvar('MAC_OS_X_VERSION_MIN_REQUIRED','1030');
  646. MacOSXVersionMin:='10.3';
  647. end;
  648. system_powerpc64_darwin,
  649. system_i386_darwin:
  650. begin
  651. set_system_compvar('MAC_OS_X_VERSION_MIN_REQUIRED','1040');
  652. MacOSXVersionMin:='10.4';
  653. end;
  654. system_x86_64_darwin:
  655. begin
  656. { actually already works on 10.4, but it's unlikely any 10.4 system
  657. with an x86-64 is still in use, so don't default to it }
  658. set_system_compvar('MAC_OS_X_VERSION_MIN_REQUIRED','1050');
  659. MacOSXVersionMin:='10.5';
  660. end;
  661. system_arm_darwin,
  662. system_i386_iphonesim:
  663. begin
  664. set_system_compvar('IPHONE_OS_VERSION_MIN_REQUIRED','30000');
  665. iPhoneOSVersionMin:='3.0';
  666. end;
  667. else
  668. internalerror(2012031001);
  669. end;
  670. end;
  671. function Toption.Unsetbool(var Opts:TCmdStr; Pos: Longint; const FullPara: TCmdStr; RequireBoolPara: boolean):boolean;
  672. { checks if the character after pos in Opts is a + or a - and returns resp.
  673. false or true. If it is another character (or none), it also returns false }
  674. begin
  675. UnsetBool := false;
  676. if Length(Opts)>Pos then
  677. begin
  678. inc(Pos);
  679. UnsetBool := Opts[Pos] = '-';
  680. if Opts[Pos] in ['-','+']then
  681. delete(Opts,Pos,1)
  682. else if RequireBoolPara then
  683. IllegalPara(FullPara);
  684. end;
  685. end;
  686. procedure TOption.interpret_option(const opt:TCmdStr;ispara:boolean);
  687. var
  688. code : integer;
  689. c : char;
  690. more : TCmdStr;
  691. major,minor : longint;
  692. error : integer;
  693. j,l : longint;
  694. d,s : TCmdStr;
  695. hs : TCmdStr;
  696. unicodemapping : punicodemap;
  697. begin
  698. if opt='' then
  699. exit;
  700. { only parse define,undef,target,verbosity,link etc options the firsttime }
  701. if firstpass and
  702. not(
  703. (opt[1]='-') and
  704. (
  705. ((length(opt)>1) and (opt[2] in ['i','d','v','T','u','n','X','l'])) or
  706. ((length(opt)>3) and (opt[2]='F') and (opt[3]='e')) or
  707. ((length(opt)>3) and (opt[2]='W') and (opt[3]='m'))
  708. )
  709. ) then
  710. exit;
  711. Message1(option_handling_option,opt);
  712. case opt[1] of
  713. '-' :
  714. begin
  715. more:=Copy(opt,3,2147483647);
  716. if firstpass then
  717. Message1(option_interpreting_firstpass_option,opt)
  718. else
  719. Message1(option_interpreting_option,opt);
  720. case opt[2] of
  721. '?' :
  722. begin
  723. if (More <> '') and (More [1] = 'F') then
  724. begin
  725. FPCHelpLines := true;
  726. Delete (More, 1, 1);
  727. FPCBinaryPath := More;
  728. end;
  729. WriteHelpPages;
  730. end;
  731. 'a' :
  732. begin
  733. include(init_settings.globalswitches,cs_asm_leave);
  734. j:=1;
  735. while j<=length(more) do
  736. begin
  737. case more[j] of
  738. 'l' :
  739. include(init_settings.globalswitches,cs_asm_source);
  740. 'r' :
  741. include(init_settings.globalswitches,cs_asm_regalloc);
  742. 't' :
  743. include(init_settings.globalswitches,cs_asm_tempalloc);
  744. 'n' :
  745. include(init_settings.globalswitches,cs_asm_nodes);
  746. { -ao option must be the last, everything behind it is passed directly to
  747. external assembler, it is ignored if internal assembler is used. }
  748. 'o' :
  749. begin
  750. asmextraopt:=copy(more,j+1,length(more)-j);
  751. break;
  752. end;
  753. 'p' :
  754. begin
  755. exclude(init_settings.globalswitches,cs_asm_leave);
  756. if UnsetBool(More, 0, opt, false) then
  757. exclude(init_settings.globalswitches,cs_asm_pipe)
  758. else
  759. include(init_settings.globalswitches,cs_asm_pipe);
  760. end;
  761. '-' :
  762. init_settings.globalswitches:=init_settings.globalswitches -
  763. [cs_asm_leave, cs_asm_source,cs_asm_regalloc, cs_asm_tempalloc,
  764. cs_asm_nodes, cs_asm_pipe];
  765. else
  766. IllegalPara(opt);
  767. end;
  768. inc(j);
  769. end;
  770. end;
  771. 'A' :
  772. begin
  773. paratargetasm:=find_asm_by_string(More);
  774. if paratargetasm=as_none then
  775. IllegalPara(opt);
  776. end;
  777. 'b' :
  778. begin
  779. // Message1(option_obsolete_switch,'-b');
  780. if UnsetBool(More,0,opt,false) then
  781. begin
  782. init_settings.moduleswitches:=init_settings.moduleswitches-[cs_browser];
  783. init_settings.moduleswitches:=init_settings.moduleswitches-[cs_local_browser];
  784. end
  785. else
  786. begin
  787. init_settings.moduleswitches:=init_settings.moduleswitches+[cs_browser];
  788. end;
  789. if More<>'' then
  790. if (More='l') or (More='l+') then
  791. init_settings.moduleswitches:=init_settings.moduleswitches+[cs_local_browser]
  792. else if More='l-' then
  793. init_settings.moduleswitches:=init_settings.moduleswitches-[cs_local_browser]
  794. else
  795. IllegalPara(opt);
  796. end;
  797. 'B' :
  798. do_build:=not UnSetBool(more,0,opt,true);
  799. 'C' :
  800. begin
  801. j:=1;
  802. while j<=length(more) do
  803. begin
  804. case more[j] of
  805. '3' :
  806. If UnsetBool(More, j, opt, false) then
  807. exclude(init_settings.localswitches,cs_ieee_errors)
  808. Else
  809. include(init_settings.localswitches,cs_ieee_errors);
  810. 'a' :
  811. begin
  812. s:=upper(copy(more,j+1,length(more)-j));
  813. if not(SetAbiType(s,target_info.abi)) then
  814. IllegalPara(opt);
  815. break;
  816. end;
  817. 'b' :
  818. begin
  819. if UnsetBool(More, j, opt, false) then
  820. target_info.endian:=endian_little
  821. else
  822. target_info.endian:=endian_big;
  823. end;
  824. 'c' :
  825. begin
  826. if not SetAktProcCall(upper(copy(more,j+1,length(more)-j)),init_settings.defproccall) then
  827. IllegalPara(opt);
  828. break;
  829. end;
  830. {$ifdef cpufpemu}
  831. 'e' :
  832. begin
  833. If UnsetBool(More, j, opt, false) then
  834. exclude(init_settings.moduleswitches,cs_fp_emulation)
  835. Else
  836. include(init_settings.moduleswitches,cs_fp_emulation);
  837. end;
  838. {$endif cpufpemu}
  839. 'f' :
  840. begin
  841. s:=upper(copy(more,j+1,length(more)-j));
  842. if not(SetFpuType(s,init_settings.fputype)) then
  843. IllegalPara(opt);
  844. FPUSetExplicitly:=True;
  845. break;
  846. end;
  847. 'F' :
  848. begin
  849. if not SetMinFPConstPrec(copy(more,j+1,length(more)-j),init_settings.minfpconstprec) then
  850. IllegalPara(opt);
  851. break;
  852. end;
  853. 'g' :
  854. begin
  855. if tf_no_pic_supported in target_info.flags then
  856. begin
  857. { consume a possible '-' coming after it }
  858. UnsetBool(More, j, opt, false);
  859. message(scan_w_pic_ignored);
  860. end
  861. else if UnsetBool(More, j, opt, false) then
  862. exclude(init_settings.moduleswitches,cs_create_pic)
  863. else
  864. include(init_settings.moduleswitches,cs_create_pic);
  865. end;
  866. 'h' :
  867. begin
  868. val(copy(more,j+1,length(more)-j),heapsize,code);
  869. if (code<>0) or (heapsize<1024) then
  870. IllegalPara(opt);
  871. break;
  872. end;
  873. 'i' :
  874. If UnsetBool(More, j, opt, false) then
  875. exclude(init_settings.localswitches,cs_check_io)
  876. else
  877. include(init_settings.localswitches,cs_check_io);
  878. {$ifdef arm}
  879. 'I' :
  880. begin
  881. if (upper(copy(more,j+1,length(more)-j))='THUMB') and
  882. { does selected CPU really understand thumb? }
  883. (init_settings.cputype in cpu_has_thumb) then
  884. init_settings.instructionset:=is_thumb
  885. else if upper(copy(more,j+1,length(more)-j))='ARM' then
  886. init_settings.instructionset:=is_arm
  887. else
  888. IllegalPara(opt);
  889. break;
  890. end;
  891. {$endif arm}
  892. 'n' :
  893. If UnsetBool(More, j, opt, false) then
  894. exclude(init_settings.globalswitches,cs_link_nolink)
  895. Else
  896. include(init_settings.globalswitches,cs_link_nolink);
  897. 'N' :
  898. If UnsetBool(More, j, opt, false) then
  899. exclude(init_settings.localswitches,cs_check_low_addr_load)
  900. Else
  901. include(init_settings.localswitches,cs_check_low_addr_load);
  902. 'o' :
  903. If UnsetBool(More, j, opt, false) then
  904. exclude(init_settings.localswitches,cs_check_overflow)
  905. Else
  906. include(init_settings.localswitches,cs_check_overflow);
  907. 'O' :
  908. If UnsetBool(More, j, opt, false) then
  909. exclude(init_settings.localswitches,cs_check_ordinal_size)
  910. Else
  911. include(init_settings.localswitches,cs_check_ordinal_size);
  912. 'p' :
  913. begin
  914. s:=upper(copy(more,j+1,length(more)-j));
  915. if not(Setcputype(s,init_settings)) then
  916. IllegalPara(opt);
  917. CPUSetExplicitly:=true;
  918. break;
  919. end;
  920. 'P':
  921. begin
  922. delete(more,1,1);
  923. if upper(copy(more,1,pos('=',more)-1))='PACKSET' then
  924. begin
  925. delete(more,1,pos('=',more));
  926. if (more='0') or (more='DEFAULT') or (more='NORMAL') then
  927. init_settings.setalloc:=0
  928. else if more='1' then
  929. init_settings.setalloc:=1
  930. else if more='2' then
  931. init_settings.setalloc:=2
  932. else if more='4' then
  933. init_settings.setalloc:=4
  934. else if more='8' then
  935. init_settings.setalloc:=8
  936. else
  937. IllegalPara(opt);
  938. end
  939. else
  940. IllegalPara(opt);
  941. end;
  942. 'r' :
  943. If UnsetBool(More, j, opt, false) then
  944. exclude(init_settings.localswitches,cs_check_range)
  945. Else
  946. include(init_settings.localswitches,cs_check_range);
  947. 'R' :
  948. If UnsetBool(More, j, opt, false) then
  949. begin
  950. exclude(init_settings.localswitches,cs_check_range);
  951. exclude(init_settings.localswitches,cs_check_object);
  952. end
  953. Else
  954. begin
  955. include(init_settings.localswitches,cs_check_range);
  956. include(init_settings.localswitches,cs_check_object);
  957. end;
  958. 's' :
  959. begin
  960. val(copy(more,j+1,length(more)-j),stacksize,code);
  961. if (code<>0) or (stacksize>=67107840) or (stacksize<1024) then
  962. IllegalPara(opt);
  963. break;
  964. end;
  965. 't' :
  966. If UnsetBool(More, j, opt, false) then
  967. exclude(init_settings.localswitches,cs_check_stack)
  968. Else
  969. include(init_settings.localswitches,cs_check_stack);
  970. 'D' :
  971. If UnsetBool(More, j, opt, false) then
  972. exclude(init_settings.moduleswitches,cs_create_dynamic)
  973. Else
  974. include(init_settings.moduleswitches,cs_create_dynamic);
  975. 'X' :
  976. If UnsetBool(More, j, opt, false) then
  977. exclude(init_settings.moduleswitches,cs_create_smart)
  978. Else
  979. include(init_settings.moduleswitches,cs_create_smart);
  980. 'T' :
  981. begin
  982. if not UpdateTargetSwitchStr(copy(more,j+1,length(more)),init_settings.targetswitches,true) then
  983. IllegalPara(opt);
  984. break;
  985. end;
  986. 'v' :
  987. If target_info.system in systems_jvm then
  988. If UnsetBool(More, j, opt, false) then
  989. exclude(init_settings.localswitches,cs_check_var_copyout)
  990. Else
  991. include(init_settings.localswitches,cs_check_var_copyout)
  992. else
  993. IllegalPara(opt)
  994. else
  995. IllegalPara(opt);
  996. end;
  997. inc(j);
  998. end;
  999. end;
  1000. 'd' :
  1001. begin
  1002. l:=Pos(':=',more);
  1003. if l>0 then
  1004. hs:=copy(more,1,l-1)
  1005. else
  1006. hs:=more;
  1007. if (not is_identifier(hs)) then
  1008. begin
  1009. if hs='' then
  1010. Message1(option_missing_arg,'-d')
  1011. else
  1012. Message1(option_malformed_para,opt);
  1013. StopOptions(1);
  1014. end;
  1015. if l>0 then
  1016. set_system_compvar(hs,Copy(more,l+2,255))
  1017. else
  1018. def_system_macro(hs);
  1019. end;
  1020. 'D' :
  1021. begin
  1022. include(init_settings.globalswitches,cs_link_deffile);
  1023. j:=1;
  1024. while j<=length(more) do
  1025. begin
  1026. case more[j] of
  1027. 'd' :
  1028. begin
  1029. description:=Copy(more,j+1,255);
  1030. break;
  1031. end;
  1032. 'v' :
  1033. begin
  1034. dllversion:=Copy(more,j+1,255);
  1035. l:=pos('.',dllversion);
  1036. dllminor:=0;
  1037. error:=0;
  1038. if l>0 then
  1039. begin
  1040. val(copy(dllversion,l+1,255),minor,error);
  1041. if (error=0) and
  1042. (minor>=0) and (minor<=$ffff) then
  1043. dllminor:=minor
  1044. else
  1045. if error=0 then
  1046. error:=1;
  1047. end;
  1048. if l=0 then
  1049. l:=256;
  1050. dllmajor:=1;
  1051. major:=0;
  1052. if error=0 then
  1053. val(copy(dllversion,1,l-1),major,error);
  1054. if (error=0) and (major>=0) and (major<=$ffff) then
  1055. dllmajor:=major
  1056. else
  1057. if error=0 then
  1058. error:=1;
  1059. if error<>0 then
  1060. Message1(scan_w_wrong_version_ignored,dllversion);
  1061. break;
  1062. end;
  1063. 'w' :
  1064. usewindowapi:=true;
  1065. '-' :
  1066. begin
  1067. exclude(init_settings.globalswitches,cs_link_deffile);
  1068. usewindowapi:=false;
  1069. end;
  1070. else
  1071. IllegalPara(opt);
  1072. end;
  1073. inc(j);
  1074. end;
  1075. end;
  1076. 'e' :
  1077. exepath:=FixPath(More,true);
  1078. 'E' :
  1079. begin
  1080. if UnsetBool(More, 0, opt, true) then
  1081. exclude(init_settings.globalswitches,cs_link_nolink)
  1082. else
  1083. include(init_settings.globalswitches,cs_link_nolink);
  1084. end;
  1085. 'f' :
  1086. begin
  1087. if more='PIC' then
  1088. begin
  1089. if tf_no_pic_supported in target_info.flags then
  1090. message(scan_w_pic_ignored)
  1091. else
  1092. include(init_settings.moduleswitches,cs_create_pic)
  1093. end
  1094. else
  1095. IllegalPara(opt);
  1096. end;
  1097. 'F' :
  1098. begin
  1099. if more='' then
  1100. IllegalPara(opt);
  1101. c:=more[1];
  1102. Delete(more,1,1);
  1103. DefaultReplacements(More);
  1104. case c of
  1105. 'a' :
  1106. autoloadunits:=more;
  1107. 'c' :
  1108. begin
  1109. if (upper(more)='UTF8') or (upper(more)='UTF-8') then
  1110. init_settings.sourcecodepage:=CP_UTF8
  1111. else if not(cpavailable(more)) then
  1112. Message1(option_code_page_not_available,more)
  1113. else
  1114. init_settings.sourcecodepage:=codepagebyname(more);
  1115. include(init_settings.moduleswitches,cs_explicit_codepage);
  1116. end;
  1117. 'C' :
  1118. RCCompiler:=More;
  1119. 'd' :
  1120. if UnsetBool(more, 0, opt, true) then
  1121. init_settings.disabledircache:=false
  1122. else
  1123. init_settings.disabledircache:=true;
  1124. 'D' :
  1125. utilsdirectory:=FixPath(More,true);
  1126. 'e' :
  1127. SetRedirectFile(More);
  1128. 'E' :
  1129. OutputExeDir:=FixPath(More,true);
  1130. 'f' :
  1131. if (target_info.system in systems_darwin) then
  1132. if ispara then
  1133. ParaFrameworkPath.AddPath(More,false)
  1134. else
  1135. frameworksearchpath.AddPath(More,true)
  1136. else
  1137. IllegalPara(opt);
  1138. 'i' :
  1139. begin
  1140. if ispara then
  1141. ParaIncludePath.AddPath(More,false)
  1142. else
  1143. includesearchpath.AddPath(More,true);
  1144. end;
  1145. 'm' :
  1146. begin
  1147. s:=ExtractFileDir(more);
  1148. if TryStrToInt(ExtractFileName(more),j) then
  1149. begin
  1150. unicodemapping:=loadunicodemapping(More,More+'.txt',j);
  1151. if assigned(unicodemapping) then
  1152. registermapping(unicodemapping)
  1153. else
  1154. IllegalPara(opt);
  1155. end
  1156. else
  1157. IllegalPara(opt);
  1158. end;
  1159. 'M' :
  1160. unicodepath:=FixPath(More,true);
  1161. 'g' :
  1162. Message2(option_obsolete_switch_use_new,'-Fg','-Fl');
  1163. 'l' :
  1164. begin
  1165. if ispara then
  1166. ParaLibraryPath.AddPath(sysrootpath,More,false)
  1167. else
  1168. LibrarySearchPath.AddPath(sysrootpath,More,true);
  1169. end;
  1170. 'L' :
  1171. begin
  1172. if More<>'' then
  1173. ParaDynamicLinker:=More
  1174. else
  1175. IllegalPara(opt);
  1176. end;
  1177. 'o' :
  1178. begin
  1179. if ispara then
  1180. ParaObjectPath.AddPath(More,false)
  1181. else
  1182. ObjectSearchPath.AddPath(More,true);
  1183. end;
  1184. 'r' :
  1185. Msgfilename:=More;
  1186. 'R' :
  1187. ResCompiler:=More;
  1188. 'u' :
  1189. begin
  1190. if ispara then
  1191. ParaUnitPath.AddPath(More,false)
  1192. else
  1193. unitsearchpath.AddPath(More,true);
  1194. end;
  1195. 'U' :
  1196. OutputUnitDir:=FixPath(More,true);
  1197. 'W',
  1198. 'w':
  1199. begin
  1200. if More<>'' then
  1201. begin
  1202. DefaultReplacements(More);
  1203. D:=ExtractFilePath(More);
  1204. if (D<>'') then
  1205. D:=FixPath(D,True);
  1206. D:=D+ExtractFileName(More);
  1207. if (c='W') then
  1208. WpoFeedbackOutput:=D
  1209. else
  1210. WpoFeedbackInput:=D;
  1211. end
  1212. else
  1213. IllegalPara(opt);
  1214. end;
  1215. else
  1216. IllegalPara(opt);
  1217. end;
  1218. end;
  1219. 'g' :
  1220. begin
  1221. if UnsetBool(More, 0, opt, false) then
  1222. begin
  1223. exclude(init_settings.moduleswitches,cs_debuginfo);
  1224. exclude(init_settings.globalswitches,cs_use_heaptrc);
  1225. exclude(init_settings.globalswitches,cs_use_lineinfo);
  1226. exclude(init_settings.localswitches,cs_checkpointer);
  1227. localvartrashing := -1;
  1228. end
  1229. else
  1230. begin
  1231. include(init_settings.moduleswitches,cs_debuginfo);
  1232. if paratargetdbg=dbg_none then
  1233. paratargetdbg:=target_info.dbg;
  1234. end;
  1235. if not RelocSectionSetExplicitly then
  1236. RelocSection:=false;
  1237. j:=1;
  1238. while j<=length(more) do
  1239. begin
  1240. case more[j] of
  1241. 'c' :
  1242. begin
  1243. if UnsetBool(More, j, opt, false) then
  1244. exclude(init_settings.localswitches,cs_checkpointer)
  1245. else if (target_info.system in supported_targets_gc) then
  1246. include(init_settings.localswitches,cs_checkpointer)
  1247. else
  1248. UnsupportedPara('-gc');
  1249. end;
  1250. 'h' :
  1251. begin
  1252. if UnsetBool(More, j, opt, false) then
  1253. exclude(init_settings.globalswitches,cs_use_heaptrc)
  1254. else
  1255. include(init_settings.globalswitches,cs_use_heaptrc);
  1256. end;
  1257. 'l' :
  1258. begin
  1259. if UnsetBool(More, j, opt, false) then
  1260. exclude(init_settings.globalswitches,cs_use_lineinfo)
  1261. else
  1262. include(init_settings.globalswitches,cs_use_lineinfo);
  1263. end;
  1264. 'o' :
  1265. begin
  1266. if not UpdateDebugStr(copy(more,j+1,length(more)),init_settings.debugswitches) then
  1267. IllegalPara(opt);
  1268. break;
  1269. end;
  1270. 'p' :
  1271. begin
  1272. if UnsetBool(More, j, opt, false) then
  1273. exclude(init_settings.globalswitches,cs_stabs_preservecase)
  1274. else
  1275. include(init_settings.globalswitches,cs_stabs_preservecase);
  1276. end;
  1277. 's' :
  1278. begin
  1279. paratargetdbg:=dbg_stabs;
  1280. end;
  1281. 't' :
  1282. begin
  1283. if UnsetBool(More, j, opt, false) then
  1284. localvartrashing := -1
  1285. else
  1286. localvartrashing := (localvartrashing + 1) mod nroftrashvalues;
  1287. end;
  1288. 'v' :
  1289. begin
  1290. if UnsetBool(More, j, opt, false) then
  1291. exclude(init_settings.globalswitches,cs_gdb_valgrind)
  1292. else
  1293. include(init_settings.globalswitches,cs_gdb_valgrind);
  1294. end;
  1295. 'w' :
  1296. begin
  1297. if (j<length(more)) and (more[j+1] in ['2','3','4']) then
  1298. begin
  1299. case more[j+1] of
  1300. '2': paratargetdbg:=dbg_dwarf2;
  1301. '3': paratargetdbg:=dbg_dwarf3;
  1302. '4': paratargetdbg:=dbg_dwarf4;
  1303. end;
  1304. inc(j);
  1305. end
  1306. else
  1307. paratargetdbg:=dbg_dwarf2;
  1308. end;
  1309. else
  1310. IllegalPara(opt);
  1311. end;
  1312. inc(j);
  1313. end;
  1314. end;
  1315. 'h' :
  1316. begin
  1317. NoPressEnter:=true;
  1318. if (More <> '') and (More [1] = 'F') then
  1319. begin
  1320. FPCHelpLines := true;
  1321. Delete (More, 1, 1);
  1322. FPCBinaryPath := More;
  1323. end;
  1324. WriteHelpPages;
  1325. end;
  1326. 'i' :
  1327. begin
  1328. if More='' then
  1329. WriteInfo
  1330. else
  1331. QuickInfo:=QuickInfo+More;
  1332. end;
  1333. 'I' :
  1334. begin
  1335. if ispara then
  1336. ParaIncludePath.AddPath(More,false)
  1337. else
  1338. includesearchpath.AddPath(More,false);
  1339. end;
  1340. 'k' :
  1341. begin
  1342. if more<>'' then
  1343. ParaLinkOptions:=ParaLinkOptions+' '+More
  1344. else
  1345. IllegalPara(opt);
  1346. end;
  1347. 'l' :
  1348. ParaLogo:=not UnSetBool(more,0,opt,true);
  1349. 'm' :
  1350. parapreprocess:=not UnSetBool(more,0,opt,true);
  1351. 'M' :
  1352. begin
  1353. more:=Upper(more);
  1354. if not SetCompileMode(more, true) then
  1355. if not SetCompileModeSwitch(more, true) then
  1356. IllegalPara(opt);
  1357. end;
  1358. 'n' :
  1359. begin
  1360. if More='' then
  1361. disable_configfile:=true
  1362. else
  1363. IllegalPara(opt);
  1364. end;
  1365. 'o' :
  1366. begin
  1367. if More<>'' then
  1368. begin
  1369. DefaultReplacements(More);
  1370. D:=ExtractFilePath(More);
  1371. if (D<>'') then
  1372. OutputExeDir:=FixPath(D,True);
  1373. OutputFileName:=ExtractFileName(More);
  1374. end
  1375. else
  1376. IllegalPara(opt);
  1377. end;
  1378. 'O' :
  1379. begin
  1380. j:=1;
  1381. while j<=length(more) do
  1382. begin
  1383. case more[j] of
  1384. '1' :
  1385. init_settings.optimizerswitches:=init_settings.optimizerswitches+level1optimizerswitches;
  1386. '2' :
  1387. init_settings.optimizerswitches:=init_settings.optimizerswitches+level2optimizerswitches;
  1388. '3' :
  1389. init_settings.optimizerswitches:=init_settings.optimizerswitches+level3optimizerswitches;
  1390. '4' :
  1391. init_settings.optimizerswitches:=init_settings.optimizerswitches+level4optimizerswitches;
  1392. 'a' :
  1393. begin
  1394. if not(UpdateAlignmentStr(Copy(Opt,j+3,255),ParaAlignment)) then
  1395. IllegalPara(opt);
  1396. break;
  1397. end;
  1398. 's' :
  1399. include(init_settings.optimizerswitches,cs_opt_size);
  1400. 'p' :
  1401. begin
  1402. if not Setoptimizecputype(copy(more,j+1,length(more)),init_settings.optimizecputype) then
  1403. begin
  1404. OptCPUSetExplicitly:=true;
  1405. { Give warning for old i386 switches }
  1406. if (Length(More)-j=1) and
  1407. (More[j+1]>='1') and (More[j+1]<='5')then
  1408. Message2(option_obsolete_switch_use_new,'-Op<nr>','-Op<name>')
  1409. else
  1410. IllegalPara(opt);
  1411. end;
  1412. break;
  1413. end;
  1414. 'o' :
  1415. begin
  1416. if not UpdateOptimizerStr(copy(more,j+1,length(more)),init_settings.optimizerswitches) then
  1417. IllegalPara(opt);
  1418. break;
  1419. end;
  1420. '-' :
  1421. begin
  1422. init_settings.optimizerswitches:=[];
  1423. FillChar(ParaAlignment,sizeof(ParaAlignment),0);
  1424. end;
  1425. { Obsolete switches }
  1426. 'g' :
  1427. Message2(option_obsolete_switch_use_new,'-Og','-Os');
  1428. 'G' :
  1429. Message1(option_obsolete_switch,'-OG');
  1430. 'r' :
  1431. Message2(option_obsolete_switch_use_new,'-Or','-O2 or -Ooregvar');
  1432. 'u' :
  1433. Message2(option_obsolete_switch_use_new,'-Ou','-Oouncertain');
  1434. 'w' :
  1435. begin
  1436. if not UpdateWpoStr(copy(more,j+1,length(more)),init_settings.dowpoptimizerswitches) then
  1437. IllegalPara(opt);
  1438. break;
  1439. end;
  1440. 'W' :
  1441. begin
  1442. if not UpdateWpoStr(copy(more,j+1,length(more)),init_settings.genwpoptimizerswitches) then
  1443. IllegalPara(opt);
  1444. break;
  1445. end;
  1446. else
  1447. IllegalPara(opt);
  1448. end;
  1449. inc(j);
  1450. end;
  1451. end;
  1452. 'p' :
  1453. begin
  1454. if UnsetBool(More, 0, opt, false) then
  1455. begin
  1456. init_settings.moduleswitches:=init_settings.moduleswitches-[cs_profile];
  1457. undef_system_macro('FPC_PROFILE');
  1458. end
  1459. else
  1460. if Length(More)=0 then
  1461. IllegalPara(opt)
  1462. else
  1463. case more[1] of
  1464. 'g' : if UnsetBool(more, 1, opt, false) then
  1465. begin
  1466. exclude(init_settings.moduleswitches,cs_profile);
  1467. undef_system_macro('FPC_PROFILE');
  1468. end
  1469. else if (target_info.system in supported_targets_pg) then
  1470. begin
  1471. include(init_settings.moduleswitches,cs_profile);
  1472. def_system_macro('FPC_PROFILE');
  1473. end
  1474. else
  1475. UnsupportedPara('-pg');
  1476. else
  1477. IllegalPara(opt);
  1478. end;
  1479. end;
  1480. 'P' : ; { Ignore used by fpc.pp }
  1481. 'R' :
  1482. begin
  1483. if not SetAsmReadMode(More,init_settings.asmmode) then
  1484. IllegalPara(opt);
  1485. end;
  1486. 's' :
  1487. begin
  1488. if UnsetBool(More, 0, opt, false) then
  1489. begin
  1490. init_settings.globalswitches:=init_settings.globalswitches-[cs_asm_extern,cs_link_extern,cs_link_nolink];
  1491. if more<>'' then
  1492. IllegalPara(opt);
  1493. end
  1494. else
  1495. begin
  1496. init_settings.globalswitches:=init_settings.globalswitches+[cs_asm_extern,cs_link_extern,cs_link_nolink];
  1497. if more='h' then
  1498. init_settings.globalswitches:=init_settings.globalswitches-[cs_link_on_target]
  1499. else if more='t' then
  1500. init_settings.globalswitches:=init_settings.globalswitches+[cs_link_on_target]
  1501. else if more='r' then
  1502. init_settings.globalswitches:=init_settings.globalswitches+[cs_asm_leave,cs_no_regalloc]
  1503. else if more<>'' then
  1504. IllegalPara(opt);
  1505. end;
  1506. end;
  1507. 'S' :
  1508. begin
  1509. if more='' then
  1510. IllegalPara(opt);
  1511. if more[1]='I' then
  1512. begin
  1513. {$ifdef jvm}
  1514. UnsupportedPara('-SI');
  1515. {$endif}
  1516. if upper(more)='ICOM' then
  1517. init_settings.interfacetype:=it_interfacecom
  1518. else if upper(more)='ICORBA' then
  1519. init_settings.interfacetype:=it_interfacecorba
  1520. else
  1521. IllegalPara(opt);
  1522. end
  1523. else
  1524. begin
  1525. j:=1;
  1526. while j<=length(more) do
  1527. begin
  1528. case more[j] of
  1529. '2' : //an alternative to -Mobjfpc
  1530. SetCompileMode('OBJFPC',true);
  1531. 'a' :
  1532. If UnsetBool(More, j, opt, false) then
  1533. exclude(init_settings.localswitches,cs_do_assertion)
  1534. else
  1535. include(init_settings.localswitches,cs_do_assertion);
  1536. 'c' :
  1537. If UnsetBool(More, j, opt, false) then
  1538. exclude(init_settings.moduleswitches,cs_support_c_operators)
  1539. else
  1540. include(init_settings.moduleswitches,cs_support_c_operators);
  1541. 'd' : //an alternative to -Mdelphi
  1542. SetCompileMode('DELPHI',true);
  1543. 'e' :
  1544. begin
  1545. SetErrorFlags(copy(more,j+1,length(more)));
  1546. break;
  1547. end;
  1548. 'f' :
  1549. begin
  1550. inc(j);
  1551. if more[j]='-' then
  1552. begin
  1553. features:=[];
  1554. if length(more)>j then
  1555. IllegalPara(opt);
  1556. end
  1557. else
  1558. begin
  1559. if (IncludeFeature(upper(copy(more,j,length(more)-j+1)))) then
  1560. j:=length(more)
  1561. else
  1562. IllegalPara(opt);
  1563. end;
  1564. end;
  1565. 'g' :
  1566. If UnsetBool(More, j, opt, false) then
  1567. exclude(init_settings.moduleswitches,cs_support_goto)
  1568. else
  1569. include(init_settings.moduleswitches,cs_support_goto);
  1570. 'h' :
  1571. If UnsetBool(More, j, opt, false) then
  1572. exclude(init_settings.localswitches,cs_refcountedstrings)
  1573. else
  1574. include(init_settings.localswitches,cs_refcountedstrings);
  1575. 'i' :
  1576. If UnsetBool(More, j, opt, false) then
  1577. exclude(init_settings.localswitches,cs_do_inline)
  1578. else
  1579. include(init_settings.localswitches,cs_do_inline);
  1580. 'k' :
  1581. If UnsetBool(More, j, opt, false) then
  1582. exclude(init_settings.globalswitches,cs_load_fpcylix_unit)
  1583. else
  1584. include(init_settings.globalswitches,cs_load_fpcylix_unit);
  1585. 'm' :
  1586. If UnsetBool(More, j, opt, false) then
  1587. exclude(init_settings.moduleswitches,cs_support_macro)
  1588. else
  1589. include(init_settings.moduleswitches,cs_support_macro);
  1590. 'o' : //an alternative to -Mtp
  1591. SetCompileMode('TP',true);
  1592. {$ifdef gpc_mode}
  1593. 'p' : //an alternative to -Mgpc
  1594. SetCompileMode('GPC',true);
  1595. {$endif}
  1596. 's' :
  1597. If UnsetBool(More, j, opt, false) then
  1598. exclude(init_settings.globalswitches,cs_constructor_name)
  1599. else
  1600. include(init_settings.globalswitches,cs_constructor_name);
  1601. 't' :
  1602. Message1(option_obsolete_switch,'-St');
  1603. 'v' :
  1604. If UnsetBool(More, j, opt, false) then
  1605. exclude(init_settings.globalswitches,cs_support_vectors)
  1606. else
  1607. include(init_settings.globalswitches,cs_support_vectors);
  1608. 'x' :
  1609. If UnsetBool(More, j, opt, false) then
  1610. exclude(init_settings.globalswitches,cs_support_exceptions)
  1611. else
  1612. include(init_settings.globalswitches,cs_support_exceptions);
  1613. 'y' :
  1614. If UnsetBool(More, j, opt, false) then
  1615. exclude(init_settings.localswitches,cs_typed_addresses)
  1616. else
  1617. include(init_settings.localswitches,cs_typed_addresses);
  1618. '-' :
  1619. begin
  1620. init_settings.globalswitches:=init_settings.globalswitches - [cs_constructor_name,cs_support_exceptions,
  1621. cs_support_vectors,cs_load_fpcylix_unit];
  1622. init_settings.localswitches:=init_settings.localswitches - [cs_do_assertion,cs_do_inline, cs_refcountedstrings,
  1623. cs_typed_addresses];
  1624. init_settings.moduleswitches:=init_settings.moduleswitches - [cs_support_c_operators, cs_support_goto,
  1625. cs_support_macro];
  1626. end;
  1627. else
  1628. IllegalPara(opt);
  1629. end;
  1630. inc(j);
  1631. end;
  1632. end;
  1633. end;
  1634. 'T' :
  1635. begin
  1636. more:=Upper(More);
  1637. if paratarget=system_none then
  1638. begin
  1639. { remove old target define }
  1640. TargetOptions(false);
  1641. { load new target }
  1642. paratarget:=find_system_by_string(More);
  1643. if paratarget<>system_none then
  1644. set_target(paratarget)
  1645. else
  1646. IllegalPara(opt);
  1647. { set new define }
  1648. TargetOptions(true);
  1649. end
  1650. else
  1651. if More<>upper(target_info.shortname) then
  1652. Message1(option_target_is_already_set,target_info.shortname);
  1653. end;
  1654. 'u' :
  1655. if is_identifier(more) then
  1656. undef_system_macro(more)
  1657. else
  1658. begin
  1659. if (more='') then
  1660. Message1(option_missing_arg,'-u')
  1661. else
  1662. Message1(option_malformed_para,opt);
  1663. StopOptions(1);
  1664. end;
  1665. 'U' :
  1666. begin
  1667. j:=1;
  1668. while j<=length(more) do
  1669. begin
  1670. case more[j] of
  1671. {$ifdef UNITALIASES}
  1672. 'a' :
  1673. begin
  1674. AddUnitAlias(Copy(More,j+1,255));
  1675. break;
  1676. end;
  1677. {$endif UNITALIASES}
  1678. 'n' :
  1679. exclude(init_settings.globalswitches,cs_check_unit_name);
  1680. 'p' :
  1681. begin
  1682. Message2(option_obsolete_switch_use_new,'-Up','-Fu');
  1683. break;
  1684. end;
  1685. 'r' :
  1686. do_release:=true;
  1687. 's' :
  1688. include(init_settings.moduleswitches,cs_compilesystem);
  1689. '-' :
  1690. begin
  1691. exclude(init_settings.moduleswitches,cs_compilesystem);
  1692. exclude(init_settings.globalswitches,cs_check_unit_name);
  1693. end;
  1694. else
  1695. IllegalPara(opt);
  1696. end;
  1697. inc(j);
  1698. end;
  1699. end;
  1700. 'v' :
  1701. begin
  1702. if not setverbosity(More) then
  1703. IllegalPara(opt);
  1704. end;
  1705. 'V' : ; { Ignore used by fpc }
  1706. 'W' :
  1707. begin
  1708. j:=1;
  1709. while j<=length(More) do
  1710. begin
  1711. case More[j] of
  1712. 'A':
  1713. begin
  1714. if target_info.system in systems_all_windows then
  1715. begin
  1716. if UnsetBool(More, j, opt, false) then
  1717. SetApptype(app_cui)
  1718. else
  1719. SetApptype(app_native);
  1720. end
  1721. else
  1722. IllegalPara(opt);
  1723. end;
  1724. 'b':
  1725. begin
  1726. if target_info.system in systems_darwin then
  1727. begin
  1728. if UnsetBool(More, j, opt, false) then
  1729. SetApptype(app_cui)
  1730. else
  1731. SetApptype(app_bundle)
  1732. end
  1733. else
  1734. IllegalPara(opt);
  1735. end;
  1736. 'B':
  1737. begin
  1738. if target_info.system in systems_all_windows+systems_symbian then
  1739. begin
  1740. { -WB200000 means set trefered base address
  1741. to $200000, but does not change relocsection boolean
  1742. this way we can create both relocatble and
  1743. non relocatable DLL at a specific base address PM }
  1744. if (length(More)>j) then
  1745. begin
  1746. val('$'+Copy(More,j+1,255),imagebase,code);
  1747. if code<>0 then
  1748. IllegalPara(opt);
  1749. ImageBaseSetExplicity:=true;
  1750. end
  1751. else
  1752. begin
  1753. RelocSection:=true;
  1754. RelocSectionSetExplicitly:=true;
  1755. end;
  1756. break;
  1757. end
  1758. else
  1759. IllegalPara(opt);
  1760. end;
  1761. 'C':
  1762. begin
  1763. if target_info.system in systems_all_windows+systems_os2+systems_macos then
  1764. begin
  1765. if UnsetBool(More, j, opt, false) then
  1766. SetApptype(app_gui)
  1767. else
  1768. SetApptype(app_cui);
  1769. end
  1770. else
  1771. IllegalPara(opt);
  1772. end;
  1773. 'D':
  1774. begin
  1775. if target_info.system in systems_all_windows then
  1776. begin
  1777. UseDeffileForExports:=not UnsetBool(More, j, opt, false);
  1778. UseDeffileForExportsSetExplicitly:=true;
  1779. end
  1780. else
  1781. IllegalPara(opt);
  1782. end;
  1783. 'e':
  1784. begin
  1785. if (target_info.system in systems_darwin) then
  1786. begin
  1787. RegisterRes(res_macosx_ext_info,TWinLikeResourceFile);
  1788. set_target_res(res_ext);
  1789. target_info.resobjext:='.fpcres';
  1790. end
  1791. else
  1792. IllegalPara(opt);
  1793. end;
  1794. 'F':
  1795. begin
  1796. if target_info.system in systems_os2 then
  1797. begin
  1798. if UnsetBool(More, j, opt, false) then
  1799. SetApptype(app_cui)
  1800. else
  1801. SetApptype(app_fs);
  1802. end
  1803. else
  1804. IllegalPara(opt);
  1805. end;
  1806. 'G':
  1807. begin
  1808. if target_info.system in systems_all_windows+systems_os2+systems_macos then
  1809. begin
  1810. if UnsetBool(More, j, opt, false) then
  1811. SetApptype(app_cui)
  1812. else
  1813. SetApptype(app_gui);
  1814. end
  1815. else
  1816. IllegalPara(opt);
  1817. end;
  1818. 'I':
  1819. begin
  1820. if target_info.system in systems_all_windows then
  1821. begin
  1822. GenerateImportSection:=not UnsetBool(More,j,opt,false);
  1823. GenerateImportSectionSetExplicitly:=true;
  1824. end
  1825. else
  1826. IllegalPara(opt);
  1827. end;
  1828. 'i':
  1829. begin
  1830. if (target_info.system in systems_darwin) then
  1831. begin
  1832. set_target_res(res_macho);
  1833. target_info.resobjext:=
  1834. targetinfos[target_info.system]^.resobjext;
  1835. end
  1836. else
  1837. IllegalPara(opt);
  1838. end;
  1839. 'm':
  1840. begin
  1841. {$if defined(i8086)}
  1842. if (target_info.system in [system_i8086_msdos]) then
  1843. begin
  1844. case Upper(Copy(More,j+1,255)) of
  1845. 'TINY': init_settings.x86memorymodel:=mm_tiny;
  1846. 'SMALL': init_settings.x86memorymodel:=mm_small;
  1847. 'MEDIUM': init_settings.x86memorymodel:=mm_medium;
  1848. 'COMPACT': init_settings.x86memorymodel:=mm_compact;
  1849. 'LARGE': init_settings.x86memorymodel:=mm_large;
  1850. 'HUGE': IllegalPara(opt); { these are not implemented yet }
  1851. else
  1852. IllegalPara(opt);
  1853. end;
  1854. break;
  1855. end
  1856. else
  1857. {$endif defined(i8086)}
  1858. IllegalPara(opt);
  1859. end;
  1860. 'M':
  1861. begin
  1862. if (target_info.system in (systems_darwin-[system_i386_iphonesim])) and
  1863. ParseMacVersionMin(MacOSXVersionMin,iPhoneOSVersionMin,'MAC_OS_X_VERSION_MIN_REQUIRED',copy(More,2,255),false) then
  1864. begin
  1865. break;
  1866. end
  1867. else
  1868. IllegalPara(opt);
  1869. end;
  1870. 'N':
  1871. begin
  1872. if target_info.system in systems_all_windows then
  1873. begin
  1874. RelocSection:=UnsetBool(More,j,opt,false);
  1875. RelocSectionSetExplicitly:=true;
  1876. end
  1877. else
  1878. IllegalPara(opt);
  1879. end;
  1880. 'p':
  1881. begin
  1882. {$if defined(arm) or defined(avr)}
  1883. if (target_info.system in systems_embedded) then
  1884. begin
  1885. s:=upper(copy(more,j+1,length(more)-j));
  1886. if not(SetControllerType(s,init_settings.controllertype)) then
  1887. IllegalPara(opt);
  1888. break;
  1889. end
  1890. else
  1891. {$endif defined(arm) or defined(avr)}
  1892. IllegalPara(opt);
  1893. end;
  1894. 'P':
  1895. begin
  1896. if (target_info.system in [system_i386_iphonesim,system_arm_darwin]) and
  1897. ParseMacVersionMin(iPhoneOSVersionMin,MacOSXVersionMin,'IPHONE_OS_VERSION_MIN_REQUIRED',copy(More,2,255),true) then
  1898. begin
  1899. break;
  1900. end
  1901. else
  1902. IllegalPara(opt);
  1903. end;
  1904. 'R':
  1905. begin
  1906. if target_info.system in systems_all_windows then
  1907. begin
  1908. { support -WR+ / -WR- as synonyms to -WR / -WN }
  1909. RelocSection:=not UnsetBool(More,j,opt,false);
  1910. RelocSectionSetExplicitly:=true;
  1911. end
  1912. else
  1913. IllegalPara(opt);
  1914. end;
  1915. 't':
  1916. begin
  1917. {$if defined(i8086)}
  1918. if (target_info.system in [system_i8086_msdos]) then
  1919. begin
  1920. case Upper(Copy(More,j+1,255)) of
  1921. 'EXE': SetAppType(app_cui);
  1922. 'COM': SetAppType(app_com);
  1923. else
  1924. IllegalPara(opt);
  1925. end;
  1926. break;
  1927. end
  1928. else
  1929. {$endif defined(i8086)}
  1930. IllegalPara(opt);
  1931. end;
  1932. 'T':
  1933. begin
  1934. if target_info.system in systems_macos then
  1935. begin
  1936. if UnsetBool(More, j, opt, false) then
  1937. SetApptype(app_cui)
  1938. else
  1939. SetApptype(app_tool);
  1940. end
  1941. else
  1942. IllegalPara(opt);
  1943. end;
  1944. 'X':
  1945. begin
  1946. if (target_info.system in systems_linux) then
  1947. begin
  1948. if UnsetBool(More, j, opt, false) then
  1949. exclude(init_settings.moduleswitches,cs_executable_stack)
  1950. else
  1951. include(init_settings.moduleswitches,cs_executable_stack)
  1952. end
  1953. else
  1954. IllegalPara(opt);
  1955. end;
  1956. else
  1957. IllegalPara(opt);
  1958. end;
  1959. inc(j);
  1960. end;
  1961. end;
  1962. 'X' :
  1963. begin
  1964. j:=1;
  1965. while j<=length(more) do
  1966. begin
  1967. case More[j] of
  1968. 'c' : Cshared:=TRUE;
  1969. 'd' : Dontlinkstdlibpath:=TRUE;
  1970. 'e' :
  1971. begin
  1972. If UnsetBool(More, j, opt, false) then
  1973. exclude(init_settings.globalswitches,cs_link_extern)
  1974. else
  1975. include(init_settings.globalswitches,cs_link_extern);
  1976. end;
  1977. 'f' :
  1978. include(init_settings.globalswitches,cs_link_pthread);
  1979. 'g' :
  1980. begin
  1981. If UnsetBool(More, j, opt, false) then
  1982. exclude(init_settings.globalswitches,cs_link_separate_dbg_file)
  1983. else
  1984. include(init_settings.globalswitches,cs_link_separate_dbg_file);
  1985. end;
  1986. 'i' :
  1987. begin
  1988. If UnsetBool(More, j, opt, false) then
  1989. include(init_settings.globalswitches,cs_link_extern)
  1990. else
  1991. exclude(init_settings.globalswitches,cs_link_extern);
  1992. end;
  1993. 'n' :
  1994. begin
  1995. If UnsetBool(More, j, opt, false) then
  1996. exclude(init_settings.globalswitches,cs_link_native)
  1997. else
  1998. include(init_settings.globalswitches,cs_link_native);
  1999. end;
  2000. 'm' :
  2001. begin
  2002. If UnsetBool(More, j, opt, false) then
  2003. exclude(init_settings.globalswitches,cs_link_map)
  2004. else
  2005. include(init_settings.globalswitches,cs_link_map);
  2006. end;
  2007. 'p' : ; { Ignore used by fpc.pp }
  2008. 'r' :
  2009. begin
  2010. if (target_info.system in suppported_targets_x_smallr) then
  2011. begin
  2012. rlinkpath:=Copy(more,2,length(More)-1);
  2013. DefaultReplacements(rlinkpath);
  2014. end
  2015. else
  2016. IgnoredPara('-Xr');
  2017. more:='';
  2018. end;
  2019. 'R' :
  2020. begin
  2021. sysrootpath:=copy(more,2,length(more)-1);
  2022. defaultreplacements(sysrootpath);
  2023. more:='';
  2024. end;
  2025. 's' :
  2026. begin
  2027. If UnsetBool(More, j, opt, false) then
  2028. exclude(init_settings.globalswitches,cs_link_strip)
  2029. else
  2030. include(init_settings.globalswitches,cs_link_strip);
  2031. end;
  2032. 't' :
  2033. include(init_settings.globalswitches,cs_link_staticflag);
  2034. 'v' :
  2035. begin
  2036. If UnsetBool(More, j, opt, false) then
  2037. exclude(init_settings.globalswitches,cs_link_opt_vtable)
  2038. else
  2039. include(init_settings.globalswitches,cs_link_opt_vtable);
  2040. end;
  2041. 'D' :
  2042. begin
  2043. def_system_macro('FPC_LINK_DYNAMIC');
  2044. undef_system_macro('FPC_LINK_SMART');
  2045. undef_system_macro('FPC_LINK_STATIC');
  2046. exclude(init_settings.globalswitches,cs_link_static);
  2047. exclude(init_settings.globalswitches,cs_link_smart);
  2048. include(init_settings.globalswitches,cs_link_shared);
  2049. LinkTypeSetExplicitly:=true;
  2050. end;
  2051. 'M' :
  2052. begin
  2053. mainaliasname:=Copy(more,2,length(More)-1);
  2054. More:='';
  2055. end;
  2056. 'P' :
  2057. begin
  2058. utilsprefix:=Copy(more,2,length(More)-1);
  2059. DefaultReplacements(utilsprefix);
  2060. More:='';
  2061. end;
  2062. 'L' : begin // -XLO is link order -XLA is link alias. -XLD avoids load defaults.
  2063. // these are not aggregable.
  2064. if (j=length(more)) or not (more[j+1] in ['O','A','D']) then
  2065. IllegalPara(opt)
  2066. else
  2067. begin
  2068. case more[j+1] of
  2069. 'A' : begin
  2070. s:=Copy(more,3,length(More)-2);
  2071. if not LinkLibraryAliases.AddDep(s) Then
  2072. IllegalPara(opt);
  2073. end;
  2074. 'O' : begin
  2075. s:=Copy(more,3,length(More)-2);
  2076. if not LinkLibraryOrder.AddWeight(s) Then
  2077. IllegalPara(opt);
  2078. end;
  2079. 'D' : include(init_settings.globalswitches,cs_link_no_default_lib_order)
  2080. else
  2081. IllegalPara(opt);
  2082. end; {case}
  2083. j:=length(more);
  2084. end; {else begin}
  2085. end;
  2086. 'S' :
  2087. begin
  2088. ForceStaticLinking;
  2089. end;
  2090. 'X' :
  2091. begin
  2092. def_system_macro('FPC_LINK_SMART');
  2093. undef_system_macro('FPC_LINK_STATIC');
  2094. undef_system_macro('FPC_LINK_DYNAMIC');
  2095. exclude(init_settings.globalswitches,cs_link_static);
  2096. include(init_settings.globalswitches,cs_link_smart);
  2097. exclude(init_settings.globalswitches,cs_link_shared);
  2098. LinkTypeSetExplicitly:=true;
  2099. end;
  2100. '-' :
  2101. begin
  2102. exclude(init_settings.globalswitches,cs_link_staticflag);
  2103. exclude(init_settings.globalswitches,cs_link_strip);
  2104. exclude(init_settings.globalswitches,cs_link_map);
  2105. set_default_link_type;
  2106. end;
  2107. else
  2108. IllegalPara(opt);
  2109. end;
  2110. inc(j);
  2111. end;
  2112. end;
  2113. else
  2114. IllegalPara(opt);
  2115. end;
  2116. end;
  2117. '@' :
  2118. begin
  2119. Message(option_no_nested_response_file);
  2120. StopOptions(1);
  2121. end;
  2122. else
  2123. begin
  2124. if (length(param_file)<>0) then
  2125. Message2(option_only_one_source_support,param_file,opt);
  2126. param_file:=opt;
  2127. Message1(option_found_file,opt);
  2128. end;
  2129. end;
  2130. end;
  2131. procedure Toption.Interpret_file(const filename : TPathStr);
  2132. procedure RemoveSep(var fn:TPathStr);
  2133. var
  2134. i : longint;
  2135. begin
  2136. i:=0;
  2137. while (i<length(fn)) and (fn[i+1] in [',',' ',#9]) do
  2138. inc(i);
  2139. Delete(fn,1,i);
  2140. i:=length(fn);
  2141. while (i>0) and (fn[i] in [',',' ',#9]) do
  2142. dec(i);
  2143. fn:=copy(fn,1,i);
  2144. end;
  2145. function GetName(var fn:TPathStr):TPathStr;
  2146. var
  2147. i : longint;
  2148. begin
  2149. i:=0;
  2150. while (i<length(fn)) and (fn[i+1] in ['a'..'z','A'..'Z','0'..'9','_','-']) do
  2151. inc(i);
  2152. GetName:=Copy(fn,1,i);
  2153. Delete(fn,1,i);
  2154. end;
  2155. const
  2156. maxlevel = 15;
  2157. var
  2158. f : text;
  2159. s, tmp,
  2160. opts : TCmdStr;
  2161. skip : array[0..maxlevel] of boolean;
  2162. line,
  2163. level : longint;
  2164. option_read : boolean;
  2165. oldfilemode : byte;
  2166. ConfigFile: TPathStr;
  2167. begin
  2168. { avoid infinite loop }
  2169. Inc(FileLevel);
  2170. Option_read:=false;
  2171. If FileLevel>MaxLevel then
  2172. Message(option_too_many_cfg_files);
  2173. if not ParaIncludeCfgPath.FindFile(fileName,true,ConfigFile) then
  2174. ConfigFile := ExpandFileName(filename);
  2175. { Maybe It's Directory ?} //Jaro Change:
  2176. if PathExists(ConfigFile,false) then
  2177. begin
  2178. Message1(option_config_is_dir,filename);
  2179. exit;
  2180. end;
  2181. { open file }
  2182. Message1(option_using_file,filename);
  2183. oldfilemode:=filemode;
  2184. filemode:=0;
  2185. assign(f,ConfigFile);
  2186. {$push}{$I-}
  2187. reset(f);
  2188. {$pop}
  2189. filemode:=oldfilemode;
  2190. if ioresult<>0 then
  2191. begin
  2192. Message1(option_unable_open_file,filename);
  2193. exit;
  2194. end;
  2195. Message1(option_start_reading_configfile,filename);
  2196. fillchar(skip,sizeof(skip),0);
  2197. level:=0;
  2198. line:=0;
  2199. while not eof(f) do
  2200. begin
  2201. readln(f,opts);
  2202. inc(line);
  2203. RemoveSep(opts);
  2204. if (opts<>'') and (opts[1]<>';') then
  2205. begin
  2206. if opts[1]='#' then
  2207. begin
  2208. Message1(option_interpreting_file_option,opts);
  2209. Delete(opts,1,1);
  2210. s:=upper(GetName(opts));
  2211. if (s='SECTION') then
  2212. begin
  2213. RemoveSep(opts);
  2214. s:=upper(GetName(opts));
  2215. if level=0 then
  2216. skip[level]:=not defined_macro(s) or (s='COMMON');
  2217. end
  2218. else
  2219. if (s='IFDEF') then
  2220. begin
  2221. RemoveSep(opts);
  2222. if Level>=maxlevel then
  2223. begin
  2224. Message2(option_too_many_ifdef,filename,tostr(line));
  2225. stopOptions(1);
  2226. end;
  2227. inc(Level);
  2228. skip[level]:=(skip[level-1] or not defined_macro(upper(GetName(opts))));
  2229. end
  2230. else
  2231. if (s='IFNDEF') then
  2232. begin
  2233. RemoveSep(opts);
  2234. if Level>=maxlevel then
  2235. begin
  2236. Message2(option_too_many_ifdef,filename,tostr(line));
  2237. stopOptions(1);
  2238. end;
  2239. inc(Level);
  2240. skip[level]:=(skip[level-1] or defined_macro(upper(GetName(opts))));
  2241. end
  2242. else
  2243. if (s='ELSE') then
  2244. begin
  2245. if Level=0 then
  2246. begin
  2247. Message2(option_else_without_if,filename,tostr(line));
  2248. stopOptions(1);
  2249. end
  2250. else
  2251. skip[level]:=skip[level-1] or (not skip[level])
  2252. end
  2253. else
  2254. if (s='ENDIF') then
  2255. begin
  2256. skip[level]:=false;
  2257. if Level=0 then
  2258. begin
  2259. Message2(option_too_many_endif,filename,tostr(line));
  2260. stopOptions(1);
  2261. end;
  2262. dec(level);
  2263. end
  2264. else
  2265. if (not skip[level]) then
  2266. begin
  2267. if (s='DEFINE') then
  2268. begin
  2269. RemoveSep(opts);
  2270. tmp:= GetName(opts);
  2271. if tmp <> '' then
  2272. def_system_macro(tmp);
  2273. Option_read:=true;
  2274. end
  2275. else
  2276. if (s='UNDEF') then
  2277. begin
  2278. RemoveSep(opts);
  2279. tmp:= GetName(opts);
  2280. if tmp <> '' then
  2281. undef_system_macro(tmp);
  2282. Option_read:=true;
  2283. end
  2284. else
  2285. if (s='WRITE') then
  2286. begin
  2287. Delete(opts,1,1);
  2288. WriteLn(opts);
  2289. Option_read:=true;
  2290. end
  2291. else
  2292. if (s='INCLUDE') then
  2293. begin
  2294. Delete(opts,1,1);
  2295. Interpret_file(opts);
  2296. Option_read:=true;
  2297. end
  2298. else
  2299. if (s='CFGDIR') then
  2300. begin
  2301. Delete(opts,1,1);
  2302. DefaultReplacements(opts);
  2303. ParaIncludeCfgPath.AddPath(opts,false);
  2304. Option_read:=true;
  2305. end;
  2306. end;
  2307. end
  2308. else
  2309. begin
  2310. if (opts[1]='-') or (opts[1]='@') then
  2311. begin
  2312. if (not skip[level]) then
  2313. interpret_option(opts,false);
  2314. Option_read:=true;
  2315. end
  2316. else
  2317. Message1(option_illegal_para,opts);
  2318. end;
  2319. end;
  2320. end;
  2321. if Level>0 then
  2322. Message(option_too_less_endif);
  2323. if Not Option_read then
  2324. Message1(option_no_option_found,filename)
  2325. else
  2326. Message1(option_end_reading_configfile,filename);
  2327. Close(f);
  2328. Dec(FileLevel);
  2329. end;
  2330. procedure Toption.Interpret_envvar(const envname : TCmdStr);
  2331. var
  2332. argstart,
  2333. env,
  2334. pc : pchar;
  2335. arglen : longint;
  2336. quote : set of char;
  2337. hs : TCmdStr;
  2338. begin
  2339. Message1(option_using_env,envname);
  2340. env:=GetEnvPChar(envname);
  2341. pc:=env;
  2342. if assigned(pc) then
  2343. begin
  2344. repeat
  2345. { skip leading spaces }
  2346. while pc^ in [' ',#9,#13] do
  2347. inc(pc);
  2348. case pc^ of
  2349. #0 :
  2350. break;
  2351. '"' :
  2352. begin
  2353. quote:=['"'];
  2354. inc(pc);
  2355. end;
  2356. '''' :
  2357. begin
  2358. quote:=[''''];
  2359. inc(pc);
  2360. end;
  2361. else
  2362. quote:=[' ',#9,#13];
  2363. end;
  2364. { scan until the end of the argument }
  2365. argstart:=pc;
  2366. while (pc^<>#0) and not(pc^ in quote) do
  2367. inc(pc);
  2368. { create argument }
  2369. arglen:=pc-argstart;
  2370. { TODO: FIXME: silent truncation of environment parameters }
  2371. if (arglen > 255) then
  2372. arglen := 255;
  2373. setlength(hs,arglen);
  2374. move(argstart^,hs[1],arglen);
  2375. interpret_option(hs,true);
  2376. { skip quote }
  2377. if pc^ in quote then
  2378. inc(pc);
  2379. until false;
  2380. end
  2381. else
  2382. Message1(option_no_option_found,'(env) '+envname);
  2383. FreeEnvPChar(env);
  2384. end;
  2385. procedure toption.read_parameters;
  2386. var
  2387. opts : TCmdStr;
  2388. paramindex : longint;
  2389. begin
  2390. paramindex:=0;
  2391. while paramindex<paramcount do
  2392. begin
  2393. inc(paramindex);
  2394. opts:=objpas.paramstr(paramindex);
  2395. if length(opts)>0 then
  2396. case opts[1] of
  2397. '@' :
  2398. if not firstpass then
  2399. begin
  2400. Delete(opts,1,1);
  2401. Message1(option_reading_further_from,opts);
  2402. interpret_file(opts);
  2403. end;
  2404. '!' :
  2405. if not firstpass then
  2406. begin
  2407. Delete(opts,1,1);
  2408. Message1(option_reading_further_from,'(env) '+opts);
  2409. interpret_envvar(opts);
  2410. end;
  2411. else
  2412. interpret_option(opts,true);
  2413. end;
  2414. end;
  2415. end;
  2416. procedure toption.parsecmd(cmd:TCmdStr);
  2417. var
  2418. i,ps : longint;
  2419. opts : TCmdStr;
  2420. begin
  2421. while (cmd<>'') do
  2422. begin
  2423. while cmd[1]=' ' do
  2424. delete(cmd,1,1);
  2425. i:=pos(' ',cmd);
  2426. if i=0 then
  2427. i:=2147483647;
  2428. opts:=Copy(cmd,1,i-1);
  2429. Delete(cmd,1,i);
  2430. case opts[1] of
  2431. '@' :
  2432. if not firstpass then
  2433. begin
  2434. Delete(opts,1,1);
  2435. Message1(option_reading_further_from,opts);
  2436. interpret_file(opts);
  2437. end;
  2438. '!' :
  2439. if not firstpass then
  2440. begin
  2441. Delete(opts,1,1);
  2442. Message1(option_reading_further_from,'(env) '+opts);
  2443. interpret_envvar(opts);
  2444. end;
  2445. '"' :
  2446. begin
  2447. Delete(opts,1,1);
  2448. ps:=pos('"',cmd);
  2449. if (i<>256) and (ps>0) then
  2450. begin
  2451. opts:=opts + ' '+ copy(cmd,1,ps-1);
  2452. cmd:=copy(cmd,ps+1,255);
  2453. end;
  2454. interpret_option(opts,true);
  2455. end;
  2456. else
  2457. interpret_option(opts,true);
  2458. end;
  2459. end;
  2460. end;
  2461. procedure toption.writequickinfo;
  2462. var
  2463. s : string;
  2464. i : longint;
  2465. procedure addinfo(const hs:string);
  2466. begin
  2467. if s<>'' then
  2468. s:=s+' '+hs
  2469. else
  2470. s:=hs;
  2471. end;
  2472. begin
  2473. s:='';
  2474. i:=0;
  2475. while (i<length(quickinfo)) do
  2476. begin
  2477. inc(i);
  2478. case quickinfo[i] of
  2479. 'S' :
  2480. begin
  2481. inc(i);
  2482. case quickinfo[i] of
  2483. 'O' :
  2484. addinfo(lower(source_info.shortname));
  2485. 'P' :
  2486. addinfo(source_cpu_string);
  2487. else
  2488. IllegalPara('-i'+QuickInfo);
  2489. end;
  2490. end;
  2491. 'T' :
  2492. begin
  2493. inc(i);
  2494. case quickinfo[i] of
  2495. 'O' :
  2496. addinfo(lower(target_info.shortname));
  2497. 'P' :
  2498. AddInfo(target_cpu_string);
  2499. else
  2500. IllegalPara('-i'+QuickInfo);
  2501. end;
  2502. end;
  2503. 'V' :
  2504. AddInfo(version_string);
  2505. 'W' :
  2506. AddInfo(full_version_string);
  2507. 'D' :
  2508. AddInfo(date_string);
  2509. '_' :
  2510. ;
  2511. else
  2512. IllegalPara('-i'+QuickInfo);
  2513. end;
  2514. end;
  2515. if s<>'' then
  2516. begin
  2517. writeln(s);
  2518. stopoptions(0);
  2519. end;
  2520. end;
  2521. procedure TOption.TargetOptions(def:boolean);
  2522. var
  2523. s : string;
  2524. i : integer;
  2525. target_unsup_features : tfeatures;
  2526. begin
  2527. if def then
  2528. def_system_macro(target_info.shortname)
  2529. else
  2530. undef_system_macro(target_info.shortname);
  2531. s:=target_info.extradefines;
  2532. while (s<>'') do
  2533. begin
  2534. i:=pos(';',s);
  2535. if i=0 then
  2536. i:=length(s)+1;
  2537. if def then
  2538. def_system_macro(Copy(s,1,i-1))
  2539. else
  2540. undef_system_macro(Copy(s,1,i-1));
  2541. delete(s,1,i);
  2542. end;
  2543. if (tf_winlikewidestring in target_info.flags) then
  2544. if def then
  2545. def_system_macro('FPC_WINLIKEWIDESTRING')
  2546. else
  2547. undef_system_macro('FPC_WINLIKEWIDESTRING');
  2548. if (tf_requires_proper_alignment in target_info.flags) then
  2549. if def then
  2550. def_system_macro('FPC_REQUIRES_PROPER_ALIGNMENT')
  2551. else
  2552. undef_system_macro('FPC_REQUIRES_PROPER_ALIGNMENT');
  2553. if source_info.system<>target_info.system then
  2554. if def then
  2555. def_system_macro('FPC_CROSSCOMPILING')
  2556. else
  2557. undef_system_macro('FPC_CROSSCOMPILING');
  2558. if source_info.cpu<>target_info.cpu then
  2559. if def then
  2560. def_system_macro('FPC_CPUCROSSCOMPILING')
  2561. else
  2562. def_system_macro('FPC_CPUCROSSCOMPILING');
  2563. if (tf_no_generic_stackcheck in target_info.flags) then
  2564. if def then
  2565. def_system_macro('FPC_NO_GENERIC_STACK_CHECK')
  2566. else
  2567. undef_system_macro('FPC_NO_GENERIC_STACK_CHECK');
  2568. if (tf_section_threadvars in target_info.flags) then
  2569. if def then
  2570. def_system_macro('FPC_SECTION_THREADVARS')
  2571. else
  2572. undef_system_macro('FPC_SECTION_THREADVARS');
  2573. { Code generation flags }
  2574. if def and
  2575. (tf_pic_default in target_info.flags) then
  2576. include(init_settings.moduleswitches,cs_create_pic)
  2577. else
  2578. exclude(init_settings.moduleswitches,cs_create_pic);
  2579. { Resources support }
  2580. if (tf_has_winlike_resources in target_info.flags) then
  2581. if def then
  2582. def_system_macro('FPC_HAS_WINLIKERESOURCES')
  2583. else
  2584. undef_system_macro('FPC_HAS_WINLIKERESOURCES');
  2585. { Features }
  2586. case target_info.system of
  2587. system_arm_gba:
  2588. target_unsup_features:=[f_dynlibs];
  2589. system_arm_nds:
  2590. target_unsup_features:=[f_threading,f_commandargs,f_fileio,f_textio,f_consoleio,f_dynlibs];
  2591. system_i386_nativent:
  2592. // until these features are implemented, they are disabled in the compiler
  2593. target_unsup_features:=[f_stackcheck];
  2594. system_jvm_java32,
  2595. system_jvm_android32:
  2596. target_unsup_features:=[f_heap,f_textio,f_consoleio,f_fileio,
  2597. f_variants,f_objects,f_commandargs,
  2598. f_processes,f_stackcheck,f_dynlibs,f_softfpu,f_objectivec1,f_resources];
  2599. else
  2600. target_unsup_features:=[];
  2601. end;
  2602. if def then
  2603. features:=features-target_unsup_features
  2604. else
  2605. features:=features+target_unsup_features;
  2606. end;
  2607. procedure TOption.checkoptionscompatibility;
  2608. begin
  2609. if (paratargetdbg in [dbg_dwarf2,dbg_dwarf3]) and
  2610. not(target_info.system in (systems_darwin+[system_i8086_msdos])) then
  2611. begin
  2612. { smartlink creation does not yet work with DWARF
  2613. debug info on most targets, but it works in internal assembler }
  2614. if (cs_create_smart in init_settings.moduleswitches) and
  2615. not (af_outputbinary in target_asm.flags) then
  2616. begin
  2617. Message(option_dwarf_smartlink_creation);
  2618. exclude(init_settings.moduleswitches,cs_create_smart);
  2619. end;
  2620. { smart linking does not yet work with DWARF debug info on most targets }
  2621. if (cs_link_smart in init_settings.globalswitches) then
  2622. begin
  2623. Message(option_dwarf_smart_linking);
  2624. ForceStaticLinking;
  2625. end;
  2626. end;
  2627. { external debug info is only supported for DWARF on darwin }
  2628. if (target_info.system in systems_darwin) and
  2629. (cs_link_separate_dbg_file in init_settings.globalswitches) and
  2630. not(paratargetdbg in [dbg_dwarf2,dbg_dwarf3]) then
  2631. begin
  2632. Message(option_debug_external_unsupported);
  2633. exclude(init_settings.globalswitches,cs_link_separate_dbg_file);
  2634. end;
  2635. end;
  2636. constructor TOption.create;
  2637. begin
  2638. LogoWritten:=false;
  2639. NoPressEnter:=false;
  2640. FirstPass:=false;
  2641. FPUSetExplicitly:=false;
  2642. CPUSetExplicitly:=false;
  2643. OptCPUSetExplicitly:=false;
  2644. FileLevel:=0;
  2645. Quickinfo:='';
  2646. ParaIncludeCfgPath:=TSearchPathList.Create;
  2647. ParaIncludePath:=TSearchPathList.Create;
  2648. ParaObjectPath:=TSearchPathList.Create;
  2649. ParaUnitPath:=TSearchPathList.Create;
  2650. ParaLibraryPath:=TSearchPathList.Create;
  2651. ParaFrameworkPath:=TSearchPathList.Create;
  2652. FillChar(ParaAlignment,sizeof(ParaAlignment),0);
  2653. MacVersionSet:=false;
  2654. end;
  2655. destructor TOption.destroy;
  2656. begin
  2657. ParaIncludeCfgPath.Free;
  2658. ParaIncludePath.Free;
  2659. ParaObjectPath.Free;
  2660. ParaUnitPath.Free;
  2661. ParaLibraryPath.Free;
  2662. ParaFrameworkPath.Free;
  2663. end;
  2664. {****************************************************************************
  2665. Callable Routines
  2666. ****************************************************************************}
  2667. function check_configfile(const fn:string;var foundfn:string):boolean;
  2668. function CfgFileExists(const fn:string):boolean;
  2669. begin
  2670. Comment(V_Tried,'Configfile search: '+fn);
  2671. CfgFileExists:=FileExists(fn);
  2672. end;
  2673. var
  2674. {$ifdef Unix}
  2675. hs,
  2676. {$endif Unix}
  2677. configpath : string;
  2678. begin
  2679. foundfn:=fn;
  2680. check_configfile:=true;
  2681. { retrieve configpath }
  2682. configpath:=FixPath(GetEnvironmentVariable('PPC_CONFIG_PATH'),false);
  2683. {$ifdef Unix}
  2684. if configpath='' then
  2685. configpath:=ExpandFileName(FixPath(exepath+'../etc/',false));
  2686. {$endif}
  2687. {
  2688. Order to read configuration file :
  2689. try reading fpc.cfg in :
  2690. 1 - current dir
  2691. 2 - configpath
  2692. 3 - compiler path
  2693. }
  2694. if not FileExists(fn) then
  2695. begin
  2696. {$ifdef Unix}
  2697. hs:=GetEnvironmentVariable('HOME');
  2698. if (hs<>'') and CfgFileExists(FixPath(hs,false)+'.'+fn) then
  2699. foundfn:=FixPath(hs,false)+'.'+fn
  2700. else
  2701. {$endif}
  2702. if CfgFileExists(configpath+fn) then
  2703. foundfn:=configpath+fn
  2704. else
  2705. {$ifdef WINDOWS}
  2706. if (GetEnvironmentVariable('USERPROFILE')<>'') and CfgFileExists(FixPath(GetEnvironmentVariable('USERPROFILE'),false)+fn) then
  2707. foundfn:=FixPath(GetEnvironmentVariable('USERPROFILE'),false)+fn
  2708. else
  2709. if (GetEnvironmentVariable('ALLUSERSPROFILE')<>'') and CfgFileExists(FixPath(GetEnvironmentVariable('ALLUSERSPROFILE'),false)+fn) then
  2710. foundfn:=FixPath(GetEnvironmentVariable('ALLUSERSPROFILE'),false)+fn
  2711. else
  2712. {$endif WINDOWS}
  2713. {$ifndef Unix}
  2714. if CfgFileExists(exepath+fn) then
  2715. foundfn:=exepath+fn
  2716. else
  2717. {$else}
  2718. if CfgFileExists('/etc/'+fn) then
  2719. foundfn:='/etc/'+fn
  2720. else
  2721. {$endif}
  2722. check_configfile:=false;
  2723. end;
  2724. end;
  2725. procedure read_arguments(cmd:TCmdStr);
  2726. var
  2727. env: ansistring;
  2728. i : tfeature;
  2729. abi : tabi;
  2730. {$if defined(cpucapabilities)}
  2731. cpuflag : tcpuflags;
  2732. hs : string;
  2733. {$endif defined(cpucapabilities)}
  2734. begin
  2735. option:=coption.create;
  2736. disable_configfile:=false;
  2737. { Non-core target defines }
  2738. Option.TargetOptions(true);
  2739. { get default messagefile }
  2740. msgfilename:=GetEnvironmentVariable('PPC_ERROR_FILE');
  2741. { default configfile can be specified on the commandline,
  2742. remove it first }
  2743. if (cmd<>'') and (cmd[1]='[') then
  2744. begin
  2745. ppccfg:=Copy(cmd,2,pos(']',cmd)-2);
  2746. Delete(cmd,1,pos(']',cmd));
  2747. end
  2748. else
  2749. ppccfg:='fpc.cfg';
  2750. { first pass reading of parameters, only -i -v -T etc.}
  2751. option.firstpass:=true;
  2752. if cmd<>'' then
  2753. option.parsecmd(cmd)
  2754. else
  2755. begin
  2756. option.read_parameters;
  2757. { Write only quickinfo }
  2758. if option.quickinfo<>'' then
  2759. option.writequickinfo;
  2760. end;
  2761. option.firstpass:=false;
  2762. { redefine target options so all defines are written even if no -Txxx is passed on the command line }
  2763. Option.TargetOptions(true);
  2764. { target is set here, for wince the default app type is gui }
  2765. if target_info.system in systems_wince then
  2766. SetApptype(app_gui)
  2767. else
  2768. SetApptype(apptype);
  2769. { default defines }
  2770. def_system_macro(target_info.shortname);
  2771. def_system_macro('FPC');
  2772. def_system_macro('VER'+version_nr);
  2773. def_system_macro('VER'+version_nr+'_'+release_nr);
  2774. def_system_macro('VER'+version_nr+'_'+release_nr+'_'+patch_nr);
  2775. { Temporary defines, until things settle down }
  2776. def_system_macro('RESSTRSECTIONS');
  2777. def_system_macro('FPC_HASFIXED64BITVARIANT');
  2778. def_system_macro('FPC_HASINTERNALOLEVARIANT2VARIANTCAST');
  2779. def_system_macro('FPC_HAS_VARSETS');
  2780. def_system_macro('FPC_HAS_VALGRINDBOOL');
  2781. def_system_macro('FPC_HAS_STR_CURRENCY');
  2782. def_system_macro('FPC_REAL2REAL_FIXED');
  2783. def_system_macro('FPC_STRTOCHARARRAYPROC');
  2784. def_system_macro('FPC_STRTOSHORTSTRINGPROC');
  2785. def_system_macro('FPC_OBJFPC_EXTENDED_IF');
  2786. def_system_macro('FPC_HAS_OPERATOR_ENUMERATOR');
  2787. def_system_macro('FPC_HAS_CONSTREF');
  2788. def_system_macro('FPC_STATICRIPFIXED');
  2789. def_system_macro('FPC_VARIANTCOPY_FIXED');
  2790. def_system_macro('FPC_DYNARRAYCOPY_FIXED');
  2791. {$if defined(x86) or defined(powerpc) or defined(powerpc64) or defined(cpuarm)}
  2792. def_system_macro('FPC_HAS_INTERNAL_ABS_LONG');
  2793. {$endif}
  2794. def_system_macro('FPC_HAS_UNICODESTRING');
  2795. def_system_macro('FPC_RTTI_PACKSET1');
  2796. def_system_macro('FPC_HAS_CPSTRING');
  2797. {$ifdef x86_64}
  2798. def_system_macro('FPC_HAS_RIP_RELATIVE');
  2799. {$endif x86_64}
  2800. def_system_macro('FPC_HAS_CEXTENDED');
  2801. def_system_macro('FPC_HAS_RESSTRINITS');
  2802. { these cpus have an inline rol/ror implementaion }
  2803. {$ifdef cpurox}
  2804. def_system_macro('FPC_HAS_INTERNAL_ROX');
  2805. {$endif}
  2806. { these cpus have an inline sar implementaion }
  2807. { currently, all supported CPUs have an internal sar implementation }
  2808. { $if defined(x86) or defined(arm) or defined(powerpc) or defined(powerpc64) or defined(sparc) or defined(mips)}
  2809. def_system_macro('FPC_HAS_INTERNAL_SAR');
  2810. { $endif}
  2811. {$ifdef powerpc64}
  2812. def_system_macro('FPC_HAS_LWSYNC');
  2813. {$endif}
  2814. def_system_macro('FPC_HAS_MEMBAR');
  2815. def_system_macro('FPC_SETBASE_USED');
  2816. {$ifdef SUPPORT_GET_FRAME}
  2817. def_system_macro('INTERNAL_BACKTRACE');
  2818. {$endif SUPPORT_GET_FRAME}
  2819. def_system_macro('STR_CONCAT_PROCS');
  2820. {$warnings off}
  2821. if pocall_default = pocall_register then
  2822. def_system_macro('REGCALL');
  2823. {$warnings on}
  2824. { don't remove this, it's also for fpdoc necessary (FK) }
  2825. def_system_macro('FPC_HAS_FEATURE_SUPPORT');
  2826. { using a case is pretty useless here (FK) }
  2827. { some stuff for TP compatibility }
  2828. {$ifdef i386}
  2829. def_system_macro('CPU86');
  2830. def_system_macro('CPU87');
  2831. def_system_macro('CPU386');
  2832. {$endif}
  2833. { new processor stuff }
  2834. {$ifdef i386}
  2835. def_system_macro('CPUI386');
  2836. def_system_macro('CPU32');
  2837. def_system_macro('CPUX86');
  2838. def_system_macro('FPC_HAS_TYPE_EXTENDED');
  2839. def_system_macro('FPC_HAS_TYPE_DOUBLE');
  2840. def_system_macro('FPC_HAS_TYPE_SINGLE');
  2841. {$endif}
  2842. {$ifdef m68k}
  2843. def_system_macro('CPU68');
  2844. def_system_macro('CPU68K');
  2845. def_system_macro('CPUM68K');
  2846. def_system_macro('CPU32');
  2847. def_system_macro('FPC_CURRENCY_IS_INT64');
  2848. def_system_macro('FPC_COMP_IS_INT64');
  2849. {$endif}
  2850. {$ifdef ALPHA}
  2851. def_system_macro('CPUALPHA');
  2852. def_system_macro('CPU64');
  2853. {$endif}
  2854. {$ifdef powerpc}
  2855. def_system_macro('CPUPOWERPC');
  2856. def_system_macro('CPUPOWERPC32');
  2857. def_system_macro('CPU32');
  2858. def_system_macro('FPC_CURRENCY_IS_INT64');
  2859. def_system_macro('FPC_COMP_IS_INT64');
  2860. {$endif}
  2861. {$ifdef POWERPC64}
  2862. def_system_macro('CPUPOWERPC');
  2863. def_system_macro('CPUPOWERPC64');
  2864. def_system_macro('CPU64');
  2865. def_system_macro('FPC_CURRENCY_IS_INT64');
  2866. def_system_macro('FPC_COMP_IS_INT64');
  2867. {$endif}
  2868. {$ifdef iA64}
  2869. def_system_macro('CPUIA64');
  2870. def_system_macro('CPU64');
  2871. {$endif}
  2872. {$ifdef x86_64}
  2873. def_system_macro('CPUX86_64');
  2874. def_system_macro('CPUAMD64');
  2875. def_system_macro('CPU64');
  2876. def_system_macro('CPUX64');
  2877. { not supported for now, afaik (FK)
  2878. def_system_macro('FPC_HAS_TYPE_FLOAT128'); }
  2879. {$ifndef FPC_SUPPORT_X87_TYPES_ON_WIN64}
  2880. { normally, win64 doesn't support the legacy fpu }
  2881. if target_info.system=system_x86_64_win64 then
  2882. begin
  2883. def_system_macro('FPC_CURRENCY_IS_INT64');
  2884. def_system_macro('FPC_COMP_IS_INT64');
  2885. end;
  2886. {$endif FPC_SUPPORT_X87_TYPES_ON_WIN64}
  2887. {$endif}
  2888. {$ifdef sparc}
  2889. def_system_macro('CPUSPARC');
  2890. def_system_macro('CPUSPARC32');
  2891. def_system_macro('CPU32');
  2892. def_system_macro('FPC_CURRENCY_IS_INT64');
  2893. def_system_macro('FPC_COMP_IS_INT64');
  2894. {$endif}
  2895. {$ifdef vis}
  2896. def_system_macro('CPUVIS');
  2897. def_system_macro('CPU32');
  2898. {$endif}
  2899. {$ifdef arm}
  2900. def_system_macro('CPUARM');
  2901. def_system_macro('CPU32');
  2902. def_system_macro('FPC_CURRENCY_IS_INT64');
  2903. def_system_macro('FPC_COMP_IS_INT64');
  2904. {$endif arm}
  2905. {$ifdef avr}
  2906. def_system_macro('CPUAVR');
  2907. def_system_macro('CPU16');
  2908. def_system_macro('FPC_CURRENCY_IS_INT64');
  2909. def_system_macro('FPC_COMP_IS_INT64');
  2910. {$endif avr}
  2911. {$ifdef jvm}
  2912. def_system_macro('CPUJVM');
  2913. def_system_macro('CPU32');
  2914. def_system_macro('FPC_CURRENCY_IS_INT64');
  2915. def_system_macro('FPC_COMP_IS_INT64');
  2916. {$endif jvm}
  2917. {$ifdef mipsel}
  2918. def_system_macro('CPUMIPS');
  2919. def_system_macro('CPUMIPS32');
  2920. def_system_macro('CPUMIPSEL');
  2921. def_system_macro('CPUMIPSEL32');
  2922. def_system_macro('CPU32');
  2923. def_system_macro('FPC_HAS_TYPE_DOUBLE');
  2924. def_system_macro('FPC_HAS_TYPE_SINGLE');
  2925. def_system_macro('FPC_INCLUDE_SOFTWARE_INT64_TO_DOUBLE');
  2926. def_system_macro('FPC_CURRENCY_IS_INT64');
  2927. def_system_macro('FPC_COMP_IS_INT64');
  2928. def_system_macro('FPC_REQUIRES_PROPER_ALIGNMENT');
  2929. { On most systems, locals are accessed relative to base pointer,
  2930. but for MIPS cpu, they are accessed relative to stack pointer.
  2931. This needs adaptation for so low level routines,
  2932. like MethodPointerLocal and related objects unit functions. }
  2933. def_system_macro('FPC_LOCALS_ARE_STACK_REG_RELATIVE');
  2934. {$endif mipsel}
  2935. {$ifdef mipseb}
  2936. def_system_macro('CPUMIPS');
  2937. def_system_macro('CPUMIPS32');
  2938. def_system_macro('CPUMIPSEB');
  2939. def_system_macro('CPUMIPSEB32');
  2940. def_system_macro('CPU32');
  2941. def_system_macro('FPC_HAS_TYPE_DOUBLE');
  2942. def_system_macro('FPC_HAS_TYPE_SINGLE');
  2943. def_system_macro('FPC_INCLUDE_SOFTWARE_INT64_TO_DOUBLE');
  2944. def_system_macro('FPC_CURRENCY_IS_INT64');
  2945. def_system_macro('FPC_COMP_IS_INT64');
  2946. def_system_macro('FPC_REQUIRES_PROPER_ALIGNMENT');
  2947. { See comment above for mipsel }
  2948. def_system_macro('FPC_LOCALS_ARE_STACK_REG_RELATIVE');
  2949. {$endif}
  2950. {$ifdef i8086}
  2951. def_system_macro('CPU86'); { Borland compatibility }
  2952. def_system_macro('CPU87'); { Borland compatibility }
  2953. def_system_macro('CPU8086');
  2954. def_system_macro('CPUI8086');
  2955. def_system_macro('CPU16');
  2956. def_system_macro('FPC_HAS_TYPE_EXTENDED');
  2957. def_system_macro('FPC_HAS_TYPE_DOUBLE');
  2958. def_system_macro('FPC_HAS_TYPE_SINGLE');
  2959. case init_settings.x86memorymodel of
  2960. mm_tiny: def_system_macro('FPC_MM_TINY');
  2961. mm_small: def_system_macro('FPC_MM_SMALL');
  2962. mm_medium: def_system_macro('FPC_MM_MEDIUM');
  2963. mm_compact: def_system_macro('FPC_MM_COMPACT');
  2964. mm_large: def_system_macro('FPC_MM_LARGE');
  2965. mm_huge: def_system_macro('FPC_MM_HUGE');
  2966. end;
  2967. {$endif i8086}
  2968. if tf_cld in target_info.flags then
  2969. if not UpdateTargetSwitchStr('CLD', init_settings.targetswitches, true) then
  2970. InternalError(2013092801);
  2971. { Set up a default prefix for binutils when cross-compiling }
  2972. if source_info.system<>target_info.system then
  2973. case target_info.system of
  2974. { Use standard Android NDK prefixes }
  2975. system_arm_android:
  2976. utilsprefix:='arm-linux-androideabi-';
  2977. system_i386_android:
  2978. utilsprefix:='i686-linux-android-';
  2979. system_mipsel_android:
  2980. utilsprefix:='mipsel-linux-android-';
  2981. end;
  2982. { Set up default value for the heap }
  2983. if target_info.system in systems_embedded then
  2984. begin
  2985. case target_info.system of
  2986. system_avr_embedded:
  2987. heapsize:=128;
  2988. system_arm_embedded:
  2989. heapsize:=256;
  2990. else
  2991. heapsize:=256;
  2992. end;
  2993. end;
  2994. { read configuration file }
  2995. if (not disable_configfile) and
  2996. (ppccfg<>'') then
  2997. read_configfile:=check_configfile(ppccfg,ppccfg)
  2998. else
  2999. read_configfile := false;
  3000. { Read commandline and configfile }
  3001. param_file:='';
  3002. { read configfile }
  3003. if read_configfile then
  3004. option.interpret_file(ppccfg);
  3005. { read parameters again to override config file }
  3006. if cmd<>'' then
  3007. option.parsecmd(cmd)
  3008. else
  3009. begin
  3010. { Write help pages if no parameters are passed }
  3011. if (paramcount=0) then
  3012. Option.WriteHelpPages;
  3013. option.read_parameters;
  3014. { Write only quickinfo }
  3015. if option.quickinfo<>'' then
  3016. option.writequickinfo;
  3017. end;
  3018. { check the compatibility of different options and adjust them if necessary
  3019. (and print possible errors)
  3020. }
  3021. option.checkoptionscompatibility;
  3022. { Stop if errors in options }
  3023. if ErrorCount>0 then
  3024. StopOptions(1);
  3025. { endian define }
  3026. case target_info.endian of
  3027. endian_little :
  3028. begin
  3029. def_system_macro('ENDIAN_LITTLE');
  3030. def_system_macro('FPC_LITTLE_ENDIAN');
  3031. end;
  3032. endian_big :
  3033. begin
  3034. def_system_macro('ENDIAN_BIG');
  3035. def_system_macro('FPC_BIG_ENDIAN');
  3036. end;
  3037. end;
  3038. { define abi }
  3039. for abi:=low(tabi) to high(tabi) do
  3040. undef_system_macro('FPC_ABI_'+abiinfo[abi].name);
  3041. def_system_macro('FPC_ABI_'+abiinfo[target_info.abi].name);
  3042. { Define FPC_ABI_EABI in addition to FPC_ABI_EABIHF on EABI VFP hardfloat
  3043. systems since most code needs to behave the same on both}
  3044. if target_info.abi = abi_eabihf then
  3045. def_system_macro('FPC_ABI_EABI');
  3046. { Write logo }
  3047. if option.ParaLogo then
  3048. option.writelogo;
  3049. { Check file to compile }
  3050. if param_file='' then
  3051. begin
  3052. Message(option_no_source_found);
  3053. StopOptions(1);
  3054. end;
  3055. {$ifndef Unix}
  3056. param_file:=FixFileName(param_file);
  3057. {$endif not unix}
  3058. inputfilepath:=ExtractFilePath(param_file);
  3059. inputfilename:=ExtractFileName(param_file);
  3060. if ExtractFileExt(inputfilename)='' then
  3061. begin
  3062. if FileExists(inputfilepath+ChangeFileExt(inputfilename,sourceext)) then
  3063. inputfilename:=ChangeFileExt(inputfilename,sourceext)
  3064. else if FileExists(inputfilepath+ChangeFileExt(inputfilename,pasext)) then
  3065. inputfilename:=ChangeFileExt(inputfilename,pasext)
  3066. else if ((m_mac in current_settings.modeswitches) or
  3067. (tf_p_ext_support in target_info.flags))
  3068. and FileExists(inputfilepath+ChangeFileExt(inputfilename,pext)) then
  3069. inputfilename:=ChangeFileExt(inputfilename,pext);
  3070. end;
  3071. { Check output dir }
  3072. if (OutputExeDir<>'') and
  3073. not PathExists(OutputExeDir,false) then
  3074. begin
  3075. Message1(general_e_path_does_not_exist,OutputExeDir);
  3076. StopOptions(1);
  3077. end;
  3078. { Add paths specified with parameters to the searchpaths }
  3079. UnitSearchPath.AddList(option.ParaUnitPath,true);
  3080. ObjectSearchPath.AddList(option.ParaObjectPath,true);
  3081. IncludeSearchPath.AddList(option.ParaIncludePath,true);
  3082. LibrarySearchPath.AddList(option.ParaLibraryPath,true);
  3083. FrameworkSearchPath.AddList(option.ParaFrameworkPath,true);
  3084. { add unit environment and exepath to the unit search path }
  3085. if inputfilepath<>'' then
  3086. Unitsearchpath.AddPath(inputfilepath,true);
  3087. if not disable_configfile then
  3088. begin
  3089. env:=GetEnvironmentVariable(target_info.unit_env);
  3090. if env<>'' then
  3091. UnitSearchPath.AddPath(GetEnvironmentVariable(target_info.unit_env),false);
  3092. end;
  3093. {$ifdef Unix}
  3094. fpcdir:=FixPath(GetEnvironmentVariable('FPCDIR'),false);
  3095. if fpcdir='' then
  3096. begin
  3097. if PathExists('/usr/local/lib/fpc/'+version_string,true) then
  3098. fpcdir:='/usr/local/lib/fpc/'+version_string+'/'
  3099. else
  3100. fpcdir:='/usr/lib/fpc/'+version_string+'/';
  3101. end;
  3102. {$else unix}
  3103. fpcdir:=FixPath(GetEnvironmentVariable('FPCDIR'),false);
  3104. if fpcdir='' then
  3105. begin
  3106. fpcdir:=ExePath+'../';
  3107. if not(PathExists(fpcdir+'units',true)) and
  3108. not(PathExists(fpcdir+'rtl',true)) then
  3109. fpcdir:=fpcdir+'../';
  3110. end;
  3111. {$endif unix}
  3112. { first try development RTL, else use the default installation path }
  3113. if not disable_configfile then
  3114. begin
  3115. if PathExists(FpcDir+'rtl',true) then
  3116. if (tf_use_8_3 in Source_Info.Flags) or
  3117. (tf_use_8_3 in Target_Info.Flags) then
  3118. UnitSearchPath.AddPath(FpcDir+'rtl/'+target_os_string,false)
  3119. else
  3120. UnitSearchPath.AddPath(FpcDir+'rtl/'+target_full_string,false)
  3121. else
  3122. if (tf_use_8_3 in Source_Info.Flags) or
  3123. (tf_use_8_3 in Target_Info.Flags) then
  3124. UnitSearchPath.AddPath(FpcDir+'units/'+target_os_string+'/rtl',false)
  3125. else
  3126. UnitSearchPath.AddPath(FpcDir+'units/'+target_full_string+'/rtl',false);
  3127. end;
  3128. { Add exepath if the exe is not in the current dir, because that is always searched already.
  3129. Do not add it when linking on the target because then we can maybe already find
  3130. .o files that are not for the target }
  3131. if (ExePath<>cfileutl.GetCurrentDir) and
  3132. not(cs_link_on_target in init_settings.globalswitches) then
  3133. UnitSearchPath.AddPath(ExePath,false);
  3134. { Add unit dir to the object and library path }
  3135. objectsearchpath.AddList(unitsearchpath,false);
  3136. librarysearchpath.AddList(unitsearchpath,false);
  3137. {$ifdef llvm}
  3138. { force llvm assembler writer }
  3139. paratargetasm:=as_llvm;
  3140. {$endif llvm}
  3141. { maybe override assembler }
  3142. if (paratargetasm<>as_none) then
  3143. begin
  3144. if not set_target_asm(paratargetasm) then
  3145. begin
  3146. Message2(option_incompatible_asm,asminfos[paratargetasm]^.idtxt,target_info.name);
  3147. set_target_asm(target_info.assemextern);
  3148. Message1(option_asm_forced,target_asm.idtxt);
  3149. end;
  3150. if (af_no_debug in asminfos[paratargetasm]^.flags) and
  3151. (paratargetdbg<>dbg_none) then
  3152. begin
  3153. Message1(option_confict_asm_debug,
  3154. asminfos[paratargetasm]^.idtxt);
  3155. paratargetdbg:=dbg_none;
  3156. exclude(init_settings.moduleswitches,cs_debuginfo);
  3157. end;
  3158. end;
  3159. {TOptionheck a second time as we might have changed assembler just above }
  3160. option.checkoptionscompatibility;
  3161. { maybe override debug info format }
  3162. if (paratargetdbg<>dbg_none) then
  3163. if not set_target_dbg(paratargetdbg) then
  3164. Message(option_w_unsupported_debug_format);
  3165. { switch assembler if it's binary and we got -a on the cmdline }
  3166. if (cs_asm_leave in init_settings.globalswitches) and
  3167. (af_outputbinary in target_asm.flags) then
  3168. begin
  3169. Message(option_switch_bin_to_src_assembler);
  3170. set_target_asm(target_info.assemextern);
  3171. end;
  3172. { Force use of external linker if there is no
  3173. internal linker or the linking is skipped }
  3174. if not(cs_link_extern in init_settings.globalswitches) and
  3175. ((target_info.link=ld_none) or
  3176. (cs_link_nolink in init_settings.globalswitches)) then
  3177. include(init_settings.globalswitches,cs_link_extern);
  3178. { turn off stripping if compiling with debuginfo or profile }
  3179. if (
  3180. (cs_debuginfo in init_settings.moduleswitches) or
  3181. (cs_profile in init_settings.moduleswitches)
  3182. ) and
  3183. not(cs_link_separate_dbg_file in init_settings.globalswitches) then
  3184. exclude(init_settings.globalswitches,cs_link_strip);
  3185. { set Mac OS X version default macros if not specified explicitly }
  3186. option.MaybeSetDefaultMacVersionMacro;
  3187. { force fpu emulation on arm/wince, arm/gba, arm/embedded and arm/nds
  3188. if fpu type not explicitly set }
  3189. if not(option.FPUSetExplicitly) and
  3190. ((target_info.system in [system_arm_wince,system_arm_gba,
  3191. system_m68k_amiga,system_m68k_atari,system_m68k_linux,
  3192. system_arm_nds,system_arm_embedded])
  3193. {$ifdef arm}
  3194. or (target_info.abi=abi_eabi)
  3195. {$endif arm}
  3196. )
  3197. {$if defined(arm) or defined (m68k)}
  3198. or (init_settings.fputype=fpu_soft)
  3199. {$endif arm or m68k}
  3200. then
  3201. begin
  3202. {$ifdef cpufpemu}
  3203. include(init_settings.moduleswitches,cs_fp_emulation);
  3204. { cs_fp_emulation and fpu_soft are equal on arm and m68k }
  3205. init_settings.fputype:=fpu_soft;
  3206. {$endif cpufpemu}
  3207. end;
  3208. {$ifdef arm}
  3209. if target_info.abi = abi_eabihf then
  3210. begin
  3211. if not(option.FPUSetExplicitly) then
  3212. begin
  3213. init_settings.fputype:=fpu_vfpv3_d16
  3214. end
  3215. else
  3216. begin
  3217. if not (init_settings.fputype in [fpu_vfpv2,fpu_vfpv3,fpu_vfpv3_d16]) then
  3218. begin
  3219. Message(option_illegal_fpu_eabihf);
  3220. StopOptions(1);
  3221. end;
  3222. end;
  3223. end;
  3224. {$endif arm}
  3225. {$ifdef arm}
  3226. case target_info.system of
  3227. system_arm_darwin:
  3228. begin
  3229. { set default cpu type to ARMv6 for Darwin unless specified otherwise, and fpu
  3230. to VFPv2 }
  3231. if not option.CPUSetExplicitly then
  3232. init_settings.cputype:=cpu_armv6;
  3233. if not option.OptCPUSetExplicitly then
  3234. init_settings.optimizecputype:=cpu_armv6;
  3235. if not option.FPUSetExplicitly then
  3236. init_settings.fputype:=fpu_vfpv2;
  3237. end;
  3238. system_arm_android:
  3239. begin
  3240. { set default cpu type to ARMv5T for Android unless specified otherwise }
  3241. if not option.CPUSetExplicitly then
  3242. init_settings.cputype:=cpu_armv5t;
  3243. if not option.OptCPUSetExplicitly then
  3244. init_settings.optimizecputype:=cpu_armv5t;
  3245. end;
  3246. end;
  3247. { set default cpu type to ARMv7a for ARMHF unless specified otherwise }
  3248. if (target_info.abi = abi_eabihf) then
  3249. begin
  3250. {$ifdef CPUARMV6}
  3251. { if the compiler is built for armv6, then
  3252. inherit this setting, e.g. Raspian is armhf but
  3253. only armv6, this makes rebuilds of the compiler
  3254. easier }
  3255. if not option.CPUSetExplicitly then
  3256. init_settings.cputype:=cpu_armv6;
  3257. if not option.OptCPUSetExplicitly then
  3258. init_settings.optimizecputype:=cpu_armv6;
  3259. {$else CPUARMV6}
  3260. if not option.CPUSetExplicitly then
  3261. init_settings.cputype:=cpu_armv7a;
  3262. if not option.OptCPUSetExplicitly then
  3263. init_settings.optimizecputype:=cpu_armv7a;
  3264. {$endif CPUARMV6}
  3265. end;
  3266. if (init_settings.instructionset=is_thumb) and not(CPUARM_HAS_THUMB2 in cpu_capabilities[init_settings.cputype]) then
  3267. begin
  3268. def_system_macro('CPUTHUMB');
  3269. if not option.FPUSetExplicitly then
  3270. init_settings.fputype:=fpu_soft;
  3271. {$if defined(FPC_ARMEL) or defined(FPC_ARMHF)}
  3272. 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';
  3273. {$else FPC_ARMAL or FPC_ARMHF}
  3274. if target_info.endian=endian_little then
  3275. 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';
  3276. {$endif FPC_ARMAL or FPC_ARMHF}
  3277. end;
  3278. if (init_settings.instructionset=is_thumb) and (CPUARM_HAS_THUMB2 in cpu_capabilities[init_settings.cputype]) then
  3279. def_system_macro('CPUTHUMB2');
  3280. {$endif arm}
  3281. {$ifdef jvm}
  3282. { set default CPU type to Dalvik when targeting Android }
  3283. if target_info.system=system_jvm_android32 then
  3284. begin
  3285. if not option.CPUSetExplicitly then
  3286. init_settings.cputype:=cpu_dalvik;
  3287. end;
  3288. {$endif jvm}
  3289. {$ifdef llvm}
  3290. { standard extension for llvm bitcode files }
  3291. target_info.asmext:='.ll';
  3292. {$endif llvm}
  3293. {$ifdef mipsel}
  3294. case target_info.system of
  3295. system_mipsel_android:
  3296. begin
  3297. { set default cpu type to MIPS32 rev. 1 and hard float for MIPS-Android unless specified otherwise }
  3298. if not option.CPUSetExplicitly then
  3299. init_settings.cputype:=cpu_mips32;
  3300. if not option.OptCPUSetExplicitly then
  3301. init_settings.optimizecputype:=cpu_mips32;
  3302. if not option.FPUSetExplicitly then
  3303. init_settings.fputype:=fpu_mips2;
  3304. end;
  3305. end;
  3306. {$endif mipsel}
  3307. { now we can define cpu and fpu type }
  3308. def_system_macro('CPU'+Cputypestr[init_settings.cputype]);
  3309. def_system_macro('FPU'+fputypestr[init_settings.fputype]);
  3310. {$if defined(cpucapabilities)}
  3311. for cpuflag:=low(cpuflag) to high(cpuflag) do
  3312. begin
  3313. str(cpuflag,hs);
  3314. if cpuflag in cpu_capabilities[init_settings.cputype] then
  3315. def_system_macro(hs)
  3316. else
  3317. undef_system_macro(hs);
  3318. end;
  3319. {$endif defined(cpucapabilities)}
  3320. if init_settings.fputype<>fpu_none then
  3321. begin
  3322. {$if defined(i386) or defined(i8086)}
  3323. def_system_macro('FPC_HAS_TYPE_EXTENDED');
  3324. {$endif}
  3325. def_system_macro('FPC_HAS_TYPE_SINGLE');
  3326. def_system_macro('FPC_HAS_TYPE_DOUBLE');
  3327. {$if not defined(i386) and not defined(x86_64) and not defined(i8086)}
  3328. def_system_macro('FPC_INCLUDE_SOFTWARE_INT64_TO_DOUBLE');
  3329. {$endif}
  3330. {$if defined(m68k)}
  3331. def_system_macro('FPC_INCLUDE_SOFTWARE_LONGWORD_TO_DOUBLE');
  3332. {$endif}
  3333. {$ifdef x86_64}
  3334. {$ifndef FPC_SUPPORT_X87_TYPES_ON_WIN64}
  3335. { normally, win64 doesn't support the legacy fpu }
  3336. if target_info.system=system_x86_64_win64 then
  3337. undef_system_macro('FPC_HAS_TYPE_EXTENDED')
  3338. else
  3339. {$endif FPC_SUPPORT_X87_TYPES_ON_WIN64}
  3340. def_system_macro('FPC_HAS_TYPE_EXTENDED');
  3341. {$endif}
  3342. end;
  3343. { Enable now for testing }
  3344. {$ifndef DISABLE_TLS_DIRECTORY}
  3345. if target_info.system in systems_windows then
  3346. def_system_macro('FPC_USE_TLS_DIRECTORY');
  3347. {$endif not DISABLE_TLS_DIRECTORY}
  3348. {$ifndef DISABLE_WIN64_SEH}
  3349. if target_info.system=system_x86_64_win64 then
  3350. def_system_macro('FPC_USE_WIN64_SEH');
  3351. {$endif DISABLE_WIN64_SEH}
  3352. {$ifdef TEST_WIN32_SEH}
  3353. if target_info.system=system_i386_win32 then
  3354. def_system_macro('FPC_USE_WIN32_SEH');
  3355. {$endif TEST_WIN32_SEH}
  3356. {$ifdef ARM}
  3357. { define FPC_DOUBLE_HILO_SWAPPED if needed to properly handle doubles in RTL }
  3358. if (init_settings.fputype in [fpu_fpa,fpu_fpa10,fpu_fpa11]) and
  3359. not(cs_fp_emulation in init_settings.moduleswitches) then
  3360. def_system_macro('FPC_DOUBLE_HILO_SWAPPED');
  3361. {$endif ARM}
  3362. { inline bsf/bsr implementation }
  3363. {$if defined(i386) or defined(x86_64)}
  3364. def_system_macro('FPC_HAS_INTERNAL_BSF');
  3365. def_system_macro('FPC_HAS_INTERNAL_BSR');
  3366. {$endif}
  3367. {$if defined(arm)}
  3368. { it is determined during system unit compilation if clz is used for bsf or not,
  3369. this is not perfect but the current implementation bsf/bsr does not allow another
  3370. solution }
  3371. if (CPUARM_HAS_CLZ in cpu_capabilities[init_settings.cputype]) and
  3372. ((init_settings.instructionset=is_arm) or
  3373. (CPUARM_HAS_THUMB2 in cpu_capabilities[init_settings.cputype])) then
  3374. begin
  3375. def_system_macro('FPC_HAS_INTERNAL_BSR');
  3376. if CPUARM_HAS_RBIT in cpu_capabilities[init_settings.cputype] then
  3377. def_system_macro('FPC_HAS_INTERNAL_BSF');
  3378. end;
  3379. {$endif}
  3380. { Section smartlinking conflicts with import sections on Windows }
  3381. if GenerateImportSection and
  3382. (target_info.system in [system_i386_win32,system_x86_64_win64]) then
  3383. exclude(target_info.flags,tf_smartlink_sections);
  3384. if not LinkTypeSetExplicitly then
  3385. set_default_link_type;
  3386. { Default alignment settings,
  3387. 1. load the defaults for the target
  3388. 2. override with generic optimizer setting (little size)
  3389. 3. override with the user specified -Oa }
  3390. UpdateAlignment(init_settings.alignment,target_info.alignment);
  3391. if (cs_opt_size in current_settings.optimizerswitches) then
  3392. begin
  3393. init_settings.alignment.procalign:=1;
  3394. init_settings.alignment.jumpalign:=1;
  3395. init_settings.alignment.loopalign:=1;
  3396. end;
  3397. UpdateAlignment(init_settings.alignment,option.paraalignment);
  3398. set_system_macro('FPC_VERSION',version_nr);
  3399. set_system_macro('FPC_RELEASE',release_nr);
  3400. set_system_macro('FPC_PATCH',patch_nr);
  3401. set_system_macro('FPC_FULLVERSION',Format('%d%.02d%.02d',[StrToInt(version_nr),StrToInt(release_nr),StrToInt(patch_nr)]));
  3402. if not(target_info.system in systems_windows) then
  3403. def_system_macro('FPC_WIDESTRING_EQUAL_UNICODESTRING');
  3404. for i:=low(tfeature) to high(tfeature) do
  3405. if i in features then
  3406. def_system_macro('FPC_HAS_FEATURE_'+featurestr[i]);
  3407. option.free;
  3408. Option:=nil;
  3409. clearstack_pocalls := [pocall_cdecl,pocall_cppdecl,pocall_syscall,pocall_mwpascal];
  3410. cdecl_pocalls := [pocall_cdecl, pocall_cppdecl, pocall_mwpascal];
  3411. if (tf_safecall_clearstack in target_info.flags) then
  3412. begin
  3413. include (cdecl_pocalls, pocall_safecall);
  3414. include (clearstack_pocalls, pocall_safecall)
  3415. end;
  3416. end;
  3417. initialization
  3418. coption:=toption;
  3419. finalization
  3420. if assigned(option) then
  3421. option.free;
  3422. end.