options.pas 92 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853
  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. CClasses,cfileutl,
  22. globtype,globals,verbose,systems,cpuinfo, comprsrc;
  23. Type
  24. TOption=class
  25. FirstPass,
  26. ParaLogo,
  27. NoPressEnter,
  28. LogoWritten,
  29. FPUSetExplicitly,
  30. CPUSetExplicitly,
  31. OptCPUSetExplicitly: boolean;
  32. FileLevel : longint;
  33. QuickInfo : string;
  34. ParaIncludePath,
  35. ParaUnitPath,
  36. ParaObjectPath,
  37. ParaLibraryPath,
  38. ParaFrameworkPath : TSearchPathList;
  39. ParaAlignment : TAlignmentInfo;
  40. Constructor Create;
  41. Destructor Destroy;override;
  42. procedure WriteLogo;
  43. procedure WriteInfo;
  44. procedure WriteHelpPages;
  45. procedure WriteQuickInfo;
  46. procedure IllegalPara(const opt:string);
  47. procedure UnsupportedPara(const opt:string);
  48. procedure IgnoredPara(const opt:string);
  49. function Unsetbool(var Opts:TCmdStr; Pos: Longint):boolean;
  50. procedure interpret_option(const opt :string;ispara:boolean);
  51. procedure Interpret_envvar(const envname : string);
  52. procedure Interpret_file(const filename : string);
  53. procedure Read_Parameters;
  54. procedure parsecmd(cmd:string);
  55. procedure TargetOptions(def:boolean);
  56. procedure CheckOptionsCompatibility;
  57. procedure ForceStaticLinking;
  58. end;
  59. TOptionClass=class of toption;
  60. var
  61. coption : TOptionClass;
  62. procedure read_arguments(cmd:string);
  63. implementation
  64. uses
  65. widestr,
  66. {$ifdef VER2_2}ccharset{$else VER2_2}charset{$endif VER2_2},
  67. SysUtils,
  68. version,
  69. cutils,cmsgs,
  70. comphook,
  71. symtable,scanner,rabase,
  72. wpobase,
  73. symconst,
  74. i_bsd;
  75. const
  76. page_size = 24;
  77. var
  78. option : toption;
  79. read_configfile, { read config file, set when a cfgfile is found }
  80. disable_configfile : boolean;
  81. fpcdir,
  82. ppccfg,
  83. param_file : string; { file to compile specified on the commandline }
  84. {****************************************************************************
  85. Options not supported on all platforms
  86. ****************************************************************************}
  87. const
  88. { pointer checking (requires special code in FPC_CHECKPOINTER,
  89. and can never work for libc-based targets or any other program
  90. linking to an external library)
  91. }
  92. supported_targets_gc = [system_i386_linux,system_powerpc_linux]
  93. + [system_i386_win32]
  94. + [system_i386_GO32V2]
  95. + [system_i386_os2]
  96. + [system_i386_beos,system_i386_haiku]
  97. + [system_powerpc_morphos];
  98. { gprof (requires implementation of g_profilecode in the code generator) }
  99. supported_targets_pg = [system_i386_linux,system_x86_64_linux]
  100. + [system_i386_win32]
  101. + [system_powerpc_darwin,system_x86_64_darwin]
  102. + [system_i386_GO32V2]
  103. + [system_i386_freebsd]
  104. + [system_i386_netbsd]
  105. + [system_i386_wdosx];
  106. suppported_targets_x_smallr = systems_linux + systems_solaris
  107. + [system_i386_haiku]
  108. + [system_i386_beos];
  109. {****************************************************************************
  110. Defines
  111. ****************************************************************************}
  112. procedure set_default_link_type;
  113. begin
  114. undef_system_macro('FPC_LINK_SMART');
  115. def_system_macro('FPC_LINK_STATIC');
  116. undef_system_macro('FPC_LINK_DYNAMIC');
  117. init_settings.globalswitches:=init_settings.globalswitches+[cs_link_static];
  118. init_settings.globalswitches:=init_settings.globalswitches-[cs_link_shared,cs_link_smart];
  119. end;
  120. {****************************************************************************
  121. Toption
  122. ****************************************************************************}
  123. procedure StopOptions(err:longint);
  124. begin
  125. if assigned(Option) then
  126. begin
  127. Option.free;
  128. Option:=nil;
  129. end;
  130. raise ECompilerAbortSilent.Create;
  131. end;
  132. procedure Toption.WriteLogo;
  133. var
  134. p : pchar;
  135. begin
  136. if not LogoWritten then
  137. begin
  138. p:=MessagePchar(option_logo);
  139. while assigned(p) do
  140. Comment(V_Normal,GetMsgLine(p));
  141. LogoWritten:= true;
  142. end;
  143. end;
  144. procedure Toption.WriteInfo;
  145. var
  146. p : pchar;
  147. hs,hs1,s : TCmdStr;
  148. target : tsystem;
  149. cpu : tcputype;
  150. fpu : tfputype;
  151. opt : toptimizerswitch;
  152. wpopt: twpoptimizerswitch;
  153. abi : tabi;
  154. {$if defined(arm) or defined(avr)}
  155. controllertype : tcontrollertype;
  156. {$endif defined(arm) or defined(avr)}
  157. begin
  158. p:=MessagePchar(option_info);
  159. while assigned(p) do
  160. begin
  161. s:=GetMsgLine(p);
  162. { list OS Targets }
  163. if pos('$OSTARGETS',s)>0 then
  164. begin
  165. for target:=low(tsystem) to high(tsystem) do
  166. if assigned(targetinfos[target]) then
  167. begin
  168. hs:=s;
  169. hs1:=targetinfos[target]^.name;
  170. if tf_under_development in targetinfos[target]^.flags then
  171. hs1:=hs1+' (under development)';
  172. Replace(hs,'$OSTARGETS',hs1);
  173. Comment(V_Normal,hs);
  174. end;
  175. end
  176. else if pos('$INSTRUCTIONSETS',s)>0 then
  177. begin
  178. for cpu:=low(tcputype) to high(tcputype) do
  179. begin
  180. hs:=s;
  181. hs1:=cputypestr[cpu];
  182. if hs1<>'' then
  183. begin
  184. Replace(hs,'$INSTRUCTIONSETS',hs1);
  185. Comment(V_Normal,hs);
  186. end;
  187. end;
  188. end
  189. else if pos('$FPUINSTRUCTIONSETS',s)>0 then
  190. begin
  191. for fpu:=low(tfputype) to high(tfputype) do
  192. begin
  193. hs:=s;
  194. hs1:=fputypestr[fpu];
  195. if hs1<>'' then
  196. begin
  197. Replace(hs,'$FPUINSTRUCTIONSETS',hs1);
  198. Comment(V_Normal,hs);
  199. end;
  200. end;
  201. end
  202. else if pos('$ABITARGETS',s)>0 then
  203. begin
  204. for abi:=low(abi) to high(abi) do
  205. begin
  206. hs:=s;
  207. hs1:=abi2str[abi];
  208. if hs1<>'' then
  209. begin
  210. Replace(hs,'$ABITARGETS',hs1);
  211. Comment(V_Normal,hs);
  212. end;
  213. end;
  214. end
  215. else if pos('$OPTIMIZATIONS',s)>0 then
  216. begin
  217. for opt:=low(toptimizerswitch) to high(toptimizerswitch) do
  218. begin
  219. if opt in supported_optimizerswitches then
  220. begin
  221. hs:=s;
  222. hs1:=OptimizerSwitchStr[opt];
  223. if hs1<>'' then
  224. begin
  225. Replace(hs,'$OPTIMIZATIONS',hs1);
  226. Comment(V_Normal,hs);
  227. end;
  228. end;
  229. end;
  230. end
  231. else if pos('$WPOPTIMIZATIONS',s)>0 then
  232. begin
  233. for wpopt:=low(twpoptimizerswitch) to high(twpoptimizerswitch) do
  234. begin
  235. { currently all whole program optimizations are platform-independent
  236. if opt in supported_wpoptimizerswitches then
  237. }
  238. begin
  239. hs:=s;
  240. hs1:=WPOptimizerSwitchStr[wpopt];
  241. if hs1<>'' then
  242. begin
  243. Replace(hs,'$WPOPTIMIZATIONS',hs1);
  244. Comment(V_Normal,hs);
  245. end;
  246. end;
  247. end
  248. end
  249. else if pos('$CONTROLLERTYPES',s)>0 then
  250. begin
  251. {$if defined(arm) or defined(avr)}
  252. for controllertype:=low(tcontrollertype) to high(tcontrollertype) do
  253. begin
  254. { currently all whole program optimizations are platform-independent
  255. if opt in supported_wpoptimizerswitches then
  256. }
  257. begin
  258. hs:=s;
  259. hs1:=ControllerTypeStr[controllertype];
  260. if hs1<>'' then
  261. begin
  262. Replace(hs,'$CONTROLLERTYPES',hs1);
  263. Comment(V_Normal,hs);
  264. end;
  265. end;
  266. end
  267. {$else defined(arm) or defined(avr)}
  268. {$endif defined(arm) or defined(avr)}
  269. end
  270. else
  271. Comment(V_Normal,s);
  272. end;
  273. StopOptions(0);
  274. end;
  275. procedure Toption.WriteHelpPages;
  276. function PadEnd(s:string;i:longint):string;
  277. begin
  278. while (length(s)<i) do
  279. s:=s+' ';
  280. PadEnd:=s;
  281. end;
  282. var
  283. lastident,
  284. j,outline,
  285. ident,
  286. lines : longint;
  287. show : boolean;
  288. opt : string[32];
  289. input,
  290. s : string;
  291. p : pchar;
  292. begin
  293. WriteLogo;
  294. Lines:=4;
  295. Message1(option_usage,FixFileName(system.paramstr(0)));
  296. lastident:=0;
  297. p:=MessagePChar(option_help_pages);
  298. while assigned(p) do
  299. begin
  300. { get a line and reset }
  301. s:=GetMsgLine(p);
  302. ident:=0;
  303. show:=false;
  304. { parse options }
  305. case s[1] of
  306. {$ifdef UNITALIASES}
  307. 'a',
  308. {$endif}
  309. {$ifdef EXTDEBUG}
  310. 'e',
  311. {$endif EXTDEBUG}
  312. {$ifdef i386}
  313. '3',
  314. {$endif}
  315. {$ifdef x86_64}
  316. '4',
  317. {$endif}
  318. {$ifdef m68k}
  319. '6',
  320. {$endif}
  321. {$ifdef arm}
  322. 'A',
  323. {$endif}
  324. {$ifdef powerpc}
  325. 'P',
  326. {$endif}
  327. {$ifdef powerpc64}
  328. 'p',
  329. {$endif}
  330. {$ifdef sparc}
  331. 'S',
  332. {$endif}
  333. {$ifdef vis}
  334. 'V',
  335. {$endif}
  336. '*' : show:=true;
  337. end;
  338. if show then
  339. begin
  340. case s[2] of
  341. 'g',
  342. {$ifdef Unix}
  343. 'L',
  344. {$endif}
  345. {$ifdef os2}
  346. 'O',
  347. {$endif}
  348. '*' : show:=true;
  349. else
  350. show:=false;
  351. end;
  352. end;
  353. { now we may show the message or not }
  354. if show then
  355. begin
  356. case s[3] of
  357. '0' : begin
  358. ident:=0;
  359. outline:=0;
  360. end;
  361. '1' : begin
  362. ident:=2;
  363. outline:=7;
  364. end;
  365. '2' : begin
  366. ident:=6;
  367. outline:=11;
  368. end;
  369. '3' : begin
  370. ident:=9;
  371. outline:=11;
  372. end;
  373. end;
  374. j:=pos('_',s);
  375. opt:=Copy(s,4,j-4);
  376. if opt='*' then
  377. opt:=''
  378. else
  379. if opt=' ' then
  380. opt:=PadEnd(opt,outline)
  381. else
  382. opt:=PadEnd('-'+opt,outline);
  383. if (ident=0) and (lastident<>0) then
  384. begin
  385. Comment(V_Normal,'');
  386. inc(Lines);
  387. end;
  388. { page full ? }
  389. if (lines >= page_size - 1) then
  390. begin
  391. if not NoPressEnter then
  392. begin
  393. Message(option_help_press_enter);
  394. readln(input);
  395. if upper(input)='Q' then
  396. StopOptions(0);
  397. end;
  398. lines:=0;
  399. end;
  400. Comment(V_Normal,PadEnd('',ident)+opt+Copy(s,j+1,255));
  401. LastIdent:=Ident;
  402. inc(Lines);
  403. end;
  404. end;
  405. StopOptions(0);
  406. end;
  407. procedure Toption.IllegalPara(const opt:string);
  408. begin
  409. Message1(option_illegal_para,opt);
  410. Message(option_help_pages_para);
  411. StopOptions(1);
  412. end;
  413. procedure toption.UnsupportedPara(const opt: string);
  414. begin
  415. Message1(option_unsupported_target,opt);
  416. StopOptions(1);
  417. end;
  418. procedure toption.IgnoredPara(const opt: string);
  419. begin
  420. Message1(option_ignored_target,opt);
  421. end;
  422. procedure toption.ForceStaticLinking;
  423. begin
  424. def_system_macro('FPC_LINK_STATIC');
  425. undef_system_macro('FPC_LINK_SMART');
  426. undef_system_macro('FPC_LINK_DYNAMIC');
  427. include(init_settings.globalswitches,cs_link_static);
  428. exclude(init_settings.globalswitches,cs_link_smart);
  429. exclude(init_settings.globalswitches,cs_link_shared);
  430. LinkTypeSetExplicitly:=true;
  431. end;
  432. function Toption.Unsetbool(var Opts:TCmdStr; Pos: Longint):boolean;
  433. { checks if the character after pos in Opts is a + or a - and returns resp.
  434. false or true. If it is another character (or none), it also returns false }
  435. begin
  436. UnsetBool := false;
  437. if Length(Opts)>Pos then
  438. begin
  439. inc(Pos);
  440. UnsetBool := Opts[Pos] = '-';
  441. if Opts[Pos] in ['-','+']then
  442. delete(Opts,Pos,1);
  443. end;
  444. end;
  445. procedure TOption.interpret_option(const opt:string;ispara:boolean);
  446. var
  447. code : integer;
  448. c : char;
  449. more : TCmdStr;
  450. major,minor : longint;
  451. error : integer;
  452. j,l : longint;
  453. d,s : TCmdStr;
  454. unicodemapping : punicodemap;
  455. begin
  456. if opt='' then
  457. exit;
  458. { only parse define,undef,target,verbosity,link etc options the firsttime }
  459. if firstpass and
  460. not(
  461. (opt[1]='-') and
  462. (
  463. ((length(opt)>1) and (opt[2] in ['i','d','v','T','u','n','X','l'])) or
  464. ((length(opt)>3) and (opt[2]='F') and (opt[3]='e'))
  465. )
  466. ) then
  467. exit;
  468. Message1(option_handling_option,opt);
  469. case opt[1] of
  470. '-' :
  471. begin
  472. more:=Copy(opt,3,255);
  473. if firstpass then
  474. Message1(option_interpreting_firstpass_option,opt)
  475. else
  476. Message1(option_interpreting_option,opt);
  477. case opt[2] of
  478. '?' :
  479. WriteHelpPages;
  480. 'a' :
  481. begin
  482. include(init_settings.globalswitches,cs_asm_leave);
  483. j:=1;
  484. while j<=length(more) do
  485. begin
  486. case more[j] of
  487. 'l' :
  488. include(init_settings.globalswitches,cs_asm_source);
  489. 'r' :
  490. include(init_settings.globalswitches,cs_asm_regalloc);
  491. 't' :
  492. include(init_settings.globalswitches,cs_asm_tempalloc);
  493. 'n' :
  494. include(init_settings.globalswitches,cs_asm_nodes);
  495. 'p' :
  496. begin
  497. exclude(init_settings.globalswitches,cs_asm_leave);
  498. if UnsetBool(More, 0) then
  499. exclude(init_settings.globalswitches,cs_asm_pipe)
  500. else
  501. include(init_settings.globalswitches,cs_asm_pipe);
  502. end;
  503. '-' :
  504. init_settings.globalswitches:=init_settings.globalswitches -
  505. [cs_asm_leave, cs_asm_source,cs_asm_regalloc, cs_asm_tempalloc,
  506. cs_asm_nodes, cs_asm_pipe];
  507. else
  508. IllegalPara(opt);
  509. end;
  510. inc(j);
  511. end;
  512. end;
  513. 'A' :
  514. begin
  515. paratargetasm:=find_asm_by_string(More);
  516. if paratargetasm=as_none then
  517. IllegalPara(opt);
  518. end;
  519. 'b' :
  520. begin
  521. // Message1(option_obsolete_switch,'-b');
  522. if UnsetBool(More,0) then
  523. begin
  524. init_settings.moduleswitches:=init_settings.moduleswitches-[cs_browser];
  525. init_settings.moduleswitches:=init_settings.moduleswitches-[cs_local_browser];
  526. end
  527. else
  528. begin
  529. init_settings.moduleswitches:=init_settings.moduleswitches+[cs_browser];
  530. end;
  531. if More<>'' then
  532. if (More='l') or (More='l+') then
  533. init_settings.moduleswitches:=init_settings.moduleswitches+[cs_local_browser]
  534. else if More='l-' then
  535. init_settings.moduleswitches:=init_settings.moduleswitches-[cs_local_browser]
  536. else
  537. IllegalPara(opt);
  538. end;
  539. 'B' :
  540. do_build:=not UnSetBool(more,0);
  541. 'C' :
  542. begin
  543. j:=1;
  544. while j<=length(more) do
  545. begin
  546. case more[j] of
  547. '3' :
  548. If UnsetBool(More, j) then
  549. exclude(init_settings.localswitches,cs_ieee_errors)
  550. Else
  551. include(init_settings.localswitches,cs_ieee_errors);
  552. 'a' :
  553. begin
  554. s:=upper(copy(more,j+1,length(more)-j));
  555. if not(SetAbiType(s,target_info.abi)) then
  556. IllegalPara(opt);
  557. break;
  558. end;
  559. 'b' :
  560. begin
  561. if UnsetBool(More, j) then
  562. target_info.endian:=endian_little
  563. else
  564. target_info.endian:=endian_big;
  565. end;
  566. 'c' :
  567. begin
  568. if not SetAktProcCall(upper(copy(more,j+1,length(more)-j)),init_settings.defproccall) then
  569. IllegalPara(opt);
  570. break;
  571. end;
  572. {$ifdef cpufpemu}
  573. 'e' :
  574. begin
  575. If UnsetBool(More, j) then
  576. exclude(init_settings.moduleswitches,cs_fp_emulation)
  577. Else
  578. include(init_settings.moduleswitches,cs_fp_emulation);
  579. end;
  580. {$endif cpufpemu}
  581. 'f' :
  582. begin
  583. s:=upper(copy(more,j+1,length(more)-j));
  584. if not(SetFpuType(s,init_settings.fputype)) then
  585. IllegalPara(opt);
  586. FPUSetExplicitly:=True;
  587. break;
  588. end;
  589. 'F' :
  590. begin
  591. if not SetMinFPConstPrec(copy(more,j+1,length(more)-j),init_settings.minfpconstprec) then
  592. IllegalPara(opt);
  593. break;
  594. end;
  595. 'g' :
  596. begin
  597. if tf_no_pic_supported in target_info.flags then
  598. begin
  599. { consume a possible '-' coming after it }
  600. UnsetBool(More, j);
  601. message(scan_w_pic_ignored);
  602. end
  603. else if UnsetBool(More, j) then
  604. exclude(init_settings.moduleswitches,cs_create_pic)
  605. else
  606. include(init_settings.moduleswitches,cs_create_pic);
  607. end;
  608. 'h' :
  609. begin
  610. val(copy(more,j+1,length(more)-j),heapsize,code);
  611. if (code<>0) or (heapsize<1024) then
  612. IllegalPara(opt);
  613. break;
  614. end;
  615. 'i' :
  616. If UnsetBool(More, j) then
  617. exclude(init_settings.localswitches,cs_check_io)
  618. else
  619. include(init_settings.localswitches,cs_check_io);
  620. 'n' :
  621. If UnsetBool(More, j) then
  622. exclude(init_settings.globalswitches,cs_link_nolink)
  623. Else
  624. include(init_settings.globalswitches,cs_link_nolink);
  625. 'o' :
  626. If UnsetBool(More, j) then
  627. exclude(init_settings.localswitches,cs_check_overflow)
  628. Else
  629. include(init_settings.localswitches,cs_check_overflow);
  630. 'O' :
  631. If UnsetBool(More, j) then
  632. exclude(init_settings.localswitches,cs_check_ordinal_size)
  633. Else
  634. include(init_settings.localswitches,cs_check_ordinal_size);
  635. 'p' :
  636. begin
  637. s:=upper(copy(more,j+1,length(more)-j));
  638. if not(Setcputype(s,init_settings.cputype)) then
  639. IllegalPara(opt);
  640. CPUSetExplicitly:=true;
  641. break;
  642. end;
  643. 'P':
  644. begin
  645. delete(more,1,1);
  646. if upper(copy(more,1,pos('=',more)-1))='PACKSET' then
  647. begin
  648. delete(more,1,pos('=',more));
  649. if more='0' then
  650. init_settings.setalloc:=0
  651. else if (more='1') or (more='DEFAULT') or (more='NORMAL') then
  652. init_settings.setalloc:=1
  653. else if more='2' then
  654. init_settings.setalloc:=2
  655. else if more='4' then
  656. init_settings.setalloc:=4
  657. else if more='8' then
  658. init_settings.setalloc:=8
  659. else
  660. IllegalPara(opt);
  661. end
  662. else
  663. IllegalPara(opt);
  664. end;
  665. 'r' :
  666. If UnsetBool(More, j) then
  667. exclude(init_settings.localswitches,cs_check_range)
  668. Else
  669. include(init_settings.localswitches,cs_check_range);
  670. 'R' :
  671. If UnsetBool(More, j) then
  672. begin
  673. exclude(init_settings.localswitches,cs_check_range);
  674. exclude(init_settings.localswitches,cs_check_object);
  675. end
  676. Else
  677. begin
  678. include(init_settings.localswitches,cs_check_range);
  679. include(init_settings.localswitches,cs_check_object);
  680. end;
  681. 's' :
  682. begin
  683. val(copy(more,j+1,length(more)-j),stacksize,code);
  684. if (code<>0) or (stacksize>=67107840) or (stacksize<1024) then
  685. IllegalPara(opt);
  686. break;
  687. end;
  688. 't' :
  689. If UnsetBool(More, j) then
  690. exclude(init_settings.localswitches,cs_check_stack)
  691. Else
  692. include(init_settings.localswitches,cs_check_stack);
  693. 'D' :
  694. If UnsetBool(More, j) then
  695. exclude(init_settings.moduleswitches,cs_create_dynamic)
  696. Else
  697. include(init_settings.moduleswitches,cs_create_dynamic);
  698. 'X' :
  699. If UnsetBool(More, j) then
  700. exclude(init_settings.moduleswitches,cs_create_smart)
  701. Else
  702. include(init_settings.moduleswitches,cs_create_smart);
  703. else
  704. IllegalPara(opt);
  705. end;
  706. inc(j);
  707. end;
  708. end;
  709. 'd' :
  710. if more <> '' then
  711. begin
  712. l:=Pos(':=',more);
  713. if l>0 then
  714. set_system_compvar(Copy(more,1,l-1),Copy(more,l+2,255))
  715. else
  716. def_system_macro(more);
  717. end;
  718. 'D' :
  719. begin
  720. include(init_settings.globalswitches,cs_link_deffile);
  721. j:=1;
  722. while j<=length(more) do
  723. begin
  724. case more[j] of
  725. 'd' :
  726. begin
  727. description:=Copy(more,j+1,255);
  728. break;
  729. end;
  730. 'v' :
  731. begin
  732. dllversion:=Copy(more,j+1,255);
  733. l:=pos('.',dllversion);
  734. dllminor:=0;
  735. error:=0;
  736. if l>0 then
  737. begin
  738. val(copy(dllversion,l+1,255),minor,error);
  739. if (error=0) and
  740. (minor>=0) and (minor<=$ffff) then
  741. dllminor:=minor
  742. else
  743. if error=0 then
  744. error:=1;
  745. end;
  746. if l=0 then
  747. l:=256;
  748. dllmajor:=1;
  749. if error=0 then
  750. val(copy(dllversion,1,l-1),major,error);
  751. if (error=0) and (major>=0) and (major<=$ffff) then
  752. dllmajor:=major
  753. else
  754. if error=0 then
  755. error:=1;
  756. if error<>0 then
  757. Message1(scan_w_wrong_version_ignored,dllversion);
  758. break;
  759. end;
  760. 'w' :
  761. usewindowapi:=true;
  762. '-' :
  763. begin
  764. exclude(init_settings.globalswitches,cs_link_deffile);
  765. usewindowapi:=false;
  766. end;
  767. else
  768. IllegalPara(opt);
  769. end;
  770. inc(j);
  771. end;
  772. end;
  773. 'e' :
  774. exepath:=FixPath(More,true);
  775. 'E' :
  776. begin
  777. if UnsetBool(More, 0) then
  778. exclude(init_settings.globalswitches,cs_link_nolink)
  779. else
  780. include(init_settings.globalswitches,cs_link_nolink);
  781. end;
  782. 'f' :
  783. begin
  784. if more='PIC' then
  785. begin
  786. if tf_no_pic_supported in target_info.flags then
  787. message(scan_w_pic_ignored)
  788. else
  789. include(init_settings.moduleswitches,cs_create_pic)
  790. end
  791. else
  792. IllegalPara(opt);
  793. end;
  794. 'F' :
  795. begin
  796. if more='' then
  797. IllegalPara(opt);
  798. c:=more[1];
  799. Delete(more,1,1);
  800. DefaultReplacements(More);
  801. case c of
  802. 'a' :
  803. autoloadunits:=more;
  804. 'c' :
  805. begin
  806. if (upper(more)='UTF8') or (upper(more)='UTF-8') then
  807. init_settings.sourcecodepage:='utf8'
  808. else if not(cpavailable(more)) then
  809. Message1(option_code_page_not_available,more)
  810. else
  811. init_settings.sourcecodepage:=more;
  812. end;
  813. 'C' :
  814. RCCompiler := More;
  815. 'd' :
  816. if UnsetBool(more, 0) then
  817. init_settings.disabledircache:=false
  818. else
  819. init_settings.disabledircache:=true;
  820. 'D' :
  821. utilsdirectory:=FixPath(More,true);
  822. 'e' :
  823. SetRedirectFile(More);
  824. 'E' :
  825. OutputExeDir:=FixPath(More,true);
  826. 'f' :
  827. if (target_info.system in systems_darwin) then
  828. if ispara then
  829. ParaFrameworkPath.AddPath(More,false)
  830. else
  831. frameworksearchpath.AddPath(More,true)
  832. else
  833. IllegalPara(opt);
  834. 'i' :
  835. begin
  836. if ispara then
  837. ParaIncludePath.AddPath(More,false)
  838. else
  839. includesearchpath.AddPath(More,true);
  840. end;
  841. 'm' :
  842. begin
  843. unicodemapping:=loadunicodemapping(More,More+'.txt');
  844. if assigned(unicodemapping) then
  845. registermapping(unicodemapping)
  846. else
  847. IllegalPara(opt);
  848. end;
  849. 'g' :
  850. Message2(option_obsolete_switch_use_new,'-Fg','-Fl');
  851. 'l' :
  852. begin
  853. if ispara then
  854. ParaLibraryPath.AddPath(sysrootpath,More,false)
  855. else
  856. LibrarySearchPath.AddPath(sysrootpath,More,true);
  857. end;
  858. 'L' :
  859. begin
  860. if More<>'' then
  861. ParaDynamicLinker:=More
  862. else
  863. IllegalPara(opt);
  864. end;
  865. 'o' :
  866. begin
  867. if ispara then
  868. ParaObjectPath.AddPath(More,false)
  869. else
  870. ObjectSearchPath.AddPath(More,true);
  871. end;
  872. 'r' :
  873. Msgfilename:=More;
  874. 'R' :
  875. ResCompiler := More;
  876. 'u' :
  877. begin
  878. if ispara then
  879. ParaUnitPath.AddPath(More,false)
  880. else
  881. unitsearchpath.AddPath(More,true);
  882. end;
  883. 'U' :
  884. OutputUnitDir:=FixPath(More,true);
  885. 'W',
  886. 'w':
  887. begin
  888. if More<>'' then
  889. begin
  890. DefaultReplacements(More);
  891. D:=ExtractFilePath(More);
  892. if (D<>'') then
  893. D:=FixPath(D,True);
  894. D:=D+ExtractFileName(More);
  895. if (c='W') then
  896. WpoFeedbackOutput:=D
  897. else
  898. WpoFeedbackInput:=D;
  899. end
  900. else
  901. IllegalPara(opt);
  902. end;
  903. else
  904. IllegalPara(opt);
  905. end;
  906. end;
  907. 'g' :
  908. begin
  909. if UnsetBool(More, 0) then
  910. begin
  911. exclude(init_settings.moduleswitches,cs_debuginfo);
  912. exclude(init_settings.globalswitches,cs_use_heaptrc);
  913. exclude(init_settings.globalswitches,cs_use_lineinfo);
  914. exclude(init_settings.localswitches,cs_checkpointer);
  915. localvartrashing := -1;
  916. end
  917. else
  918. begin
  919. include(init_settings.moduleswitches,cs_debuginfo);
  920. if paratargetdbg=dbg_none then
  921. paratargetdbg:=target_info.dbg;
  922. end;
  923. if not RelocSectionSetExplicitly then
  924. RelocSection:=false;
  925. j:=1;
  926. while j<=length(more) do
  927. begin
  928. case more[j] of
  929. 'c' :
  930. begin
  931. if UnsetBool(More, j) then
  932. exclude(init_settings.localswitches,cs_checkpointer)
  933. else if (target_info.system in supported_targets_gc) then
  934. include(init_settings.localswitches,cs_checkpointer)
  935. else
  936. UnsupportedPara('-gc');
  937. end;
  938. 'h' :
  939. begin
  940. if UnsetBool(More, j) then
  941. exclude(init_settings.globalswitches,cs_use_heaptrc)
  942. else
  943. include(init_settings.globalswitches,cs_use_heaptrc);
  944. end;
  945. 'l' :
  946. begin
  947. if UnsetBool(More, j) then
  948. exclude(init_settings.globalswitches,cs_use_lineinfo)
  949. else
  950. include(init_settings.globalswitches,cs_use_lineinfo);
  951. end;
  952. 'o' :
  953. begin
  954. if not UpdateDebugStr(copy(more,j+1,length(more)),init_settings.debugswitches) then
  955. IllegalPara(opt);
  956. break;
  957. end;
  958. 'p' :
  959. begin
  960. if UnsetBool(More, j) then
  961. exclude(init_settings.globalswitches,cs_stabs_preservecase)
  962. else
  963. include(init_settings.globalswitches,cs_stabs_preservecase);
  964. end;
  965. 's' :
  966. begin
  967. paratargetdbg:=dbg_stabs;
  968. end;
  969. 't' :
  970. begin
  971. if UnsetBool(More, j) then
  972. localvartrashing := -1
  973. else
  974. localvartrashing := (localvartrashing + 1) mod nroftrashvalues;
  975. end;
  976. 'v' :
  977. begin
  978. if UnsetBool(More, j) then
  979. exclude(init_settings.globalswitches,cs_gdb_valgrind)
  980. else
  981. include(init_settings.globalswitches,cs_gdb_valgrind);
  982. end;
  983. 'w' :
  984. begin
  985. if (j<length(more)) and (more[j+1] in ['2','3','4']) then
  986. begin
  987. case more[j+1] of
  988. '2': paratargetdbg:=dbg_dwarf2;
  989. '3': paratargetdbg:=dbg_dwarf3;
  990. '4': paratargetdbg:=dbg_dwarf4;
  991. end;
  992. inc(j);
  993. end
  994. else
  995. paratargetdbg:=dbg_dwarf2;
  996. end;
  997. else
  998. IllegalPara(opt);
  999. end;
  1000. inc(j);
  1001. end;
  1002. end;
  1003. 'h' :
  1004. begin
  1005. NoPressEnter:=true;
  1006. WriteHelpPages;
  1007. end;
  1008. 'i' :
  1009. begin
  1010. if More='' then
  1011. WriteInfo
  1012. else
  1013. QuickInfo:=QuickInfo+More;
  1014. end;
  1015. 'I' :
  1016. begin
  1017. if ispara then
  1018. ParaIncludePath.AddPath(More,false)
  1019. else
  1020. includesearchpath.AddPath(More,false);
  1021. end;
  1022. 'k' :
  1023. begin
  1024. if more<>'' then
  1025. ParaLinkOptions:=ParaLinkOptions+' '+More
  1026. else
  1027. IllegalPara(opt);
  1028. end;
  1029. 'l' :
  1030. ParaLogo:=not UnSetBool(more,0);
  1031. 'm' :
  1032. parapreprocess:=not UnSetBool(more,0);
  1033. 'M' :
  1034. begin
  1035. more:=Upper(more);
  1036. if not SetCompileMode(more, true) then
  1037. if not SetCompileModeSwitch(more, true) then
  1038. IllegalPara(opt);
  1039. end;
  1040. 'n' :
  1041. begin
  1042. if More='' then
  1043. disable_configfile:=true
  1044. else
  1045. IllegalPara(opt);
  1046. end;
  1047. 'o' :
  1048. begin
  1049. if More<>'' then
  1050. begin
  1051. DefaultReplacements(More);
  1052. D:=ExtractFilePath(More);
  1053. if (D<>'') then
  1054. OutputExeDir:=FixPath(D,True);
  1055. OutputFileName:=ExtractFileName(More);
  1056. end
  1057. else
  1058. IllegalPara(opt);
  1059. end;
  1060. 'O' :
  1061. begin
  1062. j:=1;
  1063. while j<=length(more) do
  1064. begin
  1065. case more[j] of
  1066. '1' :
  1067. init_settings.optimizerswitches:=init_settings.optimizerswitches+level1optimizerswitches;
  1068. '2' :
  1069. init_settings.optimizerswitches:=init_settings.optimizerswitches+level2optimizerswitches;
  1070. '3' :
  1071. init_settings.optimizerswitches:=init_settings.optimizerswitches+level3optimizerswitches;
  1072. 'a' :
  1073. begin
  1074. if not(UpdateAlignmentStr(Copy(Opt,j+3,255),ParaAlignment)) then
  1075. IllegalPara(opt);
  1076. break;
  1077. end;
  1078. 's' :
  1079. include(init_settings.optimizerswitches,cs_opt_size);
  1080. 'p' :
  1081. begin
  1082. if not Setcputype(copy(more,j+1,length(more)),init_settings.optimizecputype) then
  1083. begin
  1084. OptCPUSetExplicitly:=true;
  1085. { Give warning for old i386 switches }
  1086. if (Length(More)-j=1) and
  1087. (More[j+1]>='1') and (More[j+1]<='5')then
  1088. Message2(option_obsolete_switch_use_new,'-Op<nr>','-Op<name>')
  1089. else
  1090. IllegalPara(opt);
  1091. end;
  1092. break;
  1093. end;
  1094. 'o' :
  1095. begin
  1096. if not UpdateOptimizerStr(copy(more,j+1,length(more)),init_settings.optimizerswitches) then
  1097. IllegalPara(opt);
  1098. break;
  1099. end;
  1100. '-' :
  1101. begin
  1102. init_settings.optimizerswitches:=[];
  1103. FillChar(ParaAlignment,sizeof(ParaAlignment),0);
  1104. end;
  1105. { Obsolete switches }
  1106. 'g' :
  1107. Message2(option_obsolete_switch_use_new,'-Og','-Os');
  1108. 'G' :
  1109. Message1(option_obsolete_switch,'-OG');
  1110. 'r' :
  1111. Message2(option_obsolete_switch_use_new,'-Or','-O2 or -Ooregvar');
  1112. 'u' :
  1113. Message2(option_obsolete_switch_use_new,'-Ou','-Oouncertain');
  1114. 'w' :
  1115. begin
  1116. if not UpdateWpoStr(copy(more,j+1,length(more)),init_settings.dowpoptimizerswitches) then
  1117. IllegalPara(opt);
  1118. break;
  1119. end;
  1120. 'W' :
  1121. begin
  1122. if not UpdateWpoStr(copy(more,j+1,length(more)),init_settings.genwpoptimizerswitches) then
  1123. IllegalPara(opt);
  1124. break;
  1125. end;
  1126. else
  1127. IllegalPara(opt);
  1128. end;
  1129. inc(j);
  1130. end;
  1131. end;
  1132. 'p' :
  1133. begin
  1134. if UnsetBool(More, 0) then
  1135. begin
  1136. init_settings.moduleswitches:=init_settings.moduleswitches-[cs_profile];
  1137. undef_system_macro('FPC_PROFILE');
  1138. end
  1139. else
  1140. if Length(More)=0 then
  1141. IllegalPara(opt)
  1142. else
  1143. case more[1] of
  1144. 'g' : if UnsetBool(more, 1) then
  1145. begin
  1146. exclude(init_settings.moduleswitches,cs_profile);
  1147. undef_system_macro('FPC_PROFILE');
  1148. end
  1149. else if (target_info.system in supported_targets_pg) then
  1150. begin
  1151. include(init_settings.moduleswitches,cs_profile);
  1152. def_system_macro('FPC_PROFILE');
  1153. end
  1154. else
  1155. UnsupportedPara('-pg');
  1156. else
  1157. IllegalPara(opt);
  1158. end;
  1159. end;
  1160. 'P' : ; { Ignore used by fpc.pp }
  1161. 'R' :
  1162. begin
  1163. if not SetAsmReadMode(More,init_settings.asmmode) then
  1164. IllegalPara(opt);
  1165. end;
  1166. 's' :
  1167. begin
  1168. if UnsetBool(More, 0) then
  1169. begin
  1170. init_settings.globalswitches:=init_settings.globalswitches-[cs_asm_extern,cs_link_extern,cs_link_nolink];
  1171. if more<>'' then
  1172. IllegalPara(opt);
  1173. end
  1174. else
  1175. begin
  1176. init_settings.globalswitches:=init_settings.globalswitches+[cs_asm_extern,cs_link_extern,cs_link_nolink];
  1177. if more='h' then
  1178. init_settings.globalswitches:=init_settings.globalswitches-[cs_link_on_target]
  1179. else if more='t' then
  1180. init_settings.globalswitches:=init_settings.globalswitches+[cs_link_on_target]
  1181. else if more='r' then
  1182. init_settings.globalswitches:=init_settings.globalswitches+[cs_asm_leave,cs_no_regalloc]
  1183. else if more<>'' then
  1184. IllegalPara(opt);
  1185. end;
  1186. end;
  1187. 'S' :
  1188. begin
  1189. if more='' then
  1190. IllegalPara(opt);
  1191. if more[1]='I' then
  1192. begin
  1193. if upper(more)='ICOM' then
  1194. init_settings.interfacetype:=it_interfacecom
  1195. else if upper(more)='ICORBA' then
  1196. init_settings.interfacetype:=it_interfacecorba
  1197. else
  1198. IllegalPara(opt);
  1199. end
  1200. else
  1201. begin
  1202. j:=1;
  1203. while j<=length(more) do
  1204. begin
  1205. case more[j] of
  1206. '2' : //an alternative to -Mobjfpc
  1207. SetCompileMode('OBJFPC',true);
  1208. 'a' :
  1209. If UnsetBool(More, j) then
  1210. exclude(init_settings.localswitches,cs_do_assertion)
  1211. else
  1212. include(init_settings.localswitches,cs_do_assertion);
  1213. 'c' :
  1214. If UnsetBool(More, j) then
  1215. include(init_settings.moduleswitches,cs_support_c_operators)
  1216. else
  1217. include(init_settings.moduleswitches,cs_support_c_operators);
  1218. 'd' : //an alternative to -Mdelphi
  1219. SetCompileMode('DELPHI',true);
  1220. 'e' :
  1221. begin
  1222. SetErrorFlags(copy(more,j+1,length(more)));
  1223. break;
  1224. end;
  1225. 'f' :
  1226. begin
  1227. inc(j);
  1228. if more[j]='-' then
  1229. begin
  1230. features:=[];
  1231. if length(more)>j then
  1232. IllegalPara(opt);
  1233. end
  1234. else
  1235. begin
  1236. if (IncludeFeature(upper(copy(more,j,length(more)-j+1)))) then
  1237. j:=length(more)
  1238. else
  1239. IllegalPara(opt);
  1240. end;
  1241. end;
  1242. 'g' :
  1243. If UnsetBool(More, j) then
  1244. exclude(init_settings.moduleswitches,cs_support_goto)
  1245. else
  1246. include(init_settings.moduleswitches,cs_support_goto);
  1247. 'h' :
  1248. If UnsetBool(More, j) then
  1249. exclude(init_settings.localswitches,cs_ansistrings)
  1250. else
  1251. include(init_settings.localswitches,cs_ansistrings);
  1252. 'i' :
  1253. If UnsetBool(More, j) then
  1254. exclude(init_settings.localswitches,cs_do_inline)
  1255. else
  1256. include(init_settings.localswitches,cs_do_inline);
  1257. 'k' :
  1258. If UnsetBool(More, j) then
  1259. exclude(init_settings.globalswitches,cs_load_fpcylix_unit)
  1260. else
  1261. include(init_settings.globalswitches,cs_load_fpcylix_unit);
  1262. 'm' :
  1263. If UnsetBool(More, j) then
  1264. exclude(init_settings.moduleswitches,cs_support_macro)
  1265. else
  1266. include(init_settings.moduleswitches,cs_support_macro);
  1267. 'o' : //an alternative to -Mtp
  1268. SetCompileMode('TP',true);
  1269. {$ifdef gpc_mode}
  1270. 'p' : //an alternative to -Mgpc
  1271. SetCompileMode('GPC',true);
  1272. {$endif}
  1273. 's' :
  1274. If UnsetBool(More, j) then
  1275. exclude(init_settings.globalswitches,cs_constructor_name)
  1276. else
  1277. include(init_settings.globalswitches,cs_constructor_name);
  1278. 't' :
  1279. Message1(option_obsolete_switch,'-St');
  1280. 'v' :
  1281. If UnsetBool(More, j) then
  1282. exclude(init_settings.globalswitches,cs_support_vectors)
  1283. else
  1284. include(init_settings.globalswitches,cs_support_vectors);
  1285. 'x' :
  1286. If UnsetBool(More, j) then
  1287. exclude(init_settings.globalswitches,cs_support_exceptions)
  1288. else
  1289. include(init_settings.globalswitches,cs_support_exceptions);
  1290. '-' :
  1291. begin
  1292. init_settings.globalswitches:=init_settings.globalswitches - [cs_constructor_name,cs_support_exceptions];
  1293. init_settings.localswitches:=init_settings.localswitches - [cs_do_assertion, cs_do_inline, cs_ansistrings];
  1294. init_settings.moduleswitches:=init_settings.moduleswitches - [cs_support_c_operators, cs_support_goto,
  1295. cs_support_macro];
  1296. end;
  1297. else
  1298. IllegalPara(opt);
  1299. end;
  1300. inc(j);
  1301. end;
  1302. end;
  1303. end;
  1304. 'T' :
  1305. begin
  1306. more:=Upper(More);
  1307. if paratarget=system_none then
  1308. begin
  1309. { remove old target define }
  1310. TargetOptions(false);
  1311. { load new target }
  1312. paratarget:=find_system_by_string(More);
  1313. if paratarget<>system_none then
  1314. set_target(paratarget)
  1315. else
  1316. IllegalPara(opt);
  1317. { set new define }
  1318. TargetOptions(true);
  1319. end
  1320. else
  1321. if More<>upper(target_info.shortname) then
  1322. Message1(option_target_is_already_set,target_info.shortname);
  1323. end;
  1324. 'u' :
  1325. if more <> '' then
  1326. undef_system_macro(more);
  1327. 'U' :
  1328. begin
  1329. j:=1;
  1330. while j<=length(more) do
  1331. begin
  1332. case more[j] of
  1333. {$ifdef UNITALIASES}
  1334. 'a' :
  1335. begin
  1336. AddUnitAlias(Copy(More,j+1,255));
  1337. break;
  1338. end;
  1339. {$endif UNITALIASES}
  1340. 'n' :
  1341. exclude(init_settings.globalswitches,cs_check_unit_name);
  1342. 'p' :
  1343. begin
  1344. Message2(option_obsolete_switch_use_new,'-Up','-Fu');
  1345. break;
  1346. end;
  1347. 'r' :
  1348. do_release:=true;
  1349. 's' :
  1350. include(init_settings.moduleswitches,cs_compilesystem);
  1351. '-' :
  1352. begin
  1353. exclude(init_settings.moduleswitches,cs_compilesystem);
  1354. exclude(init_settings.globalswitches,cs_check_unit_name);
  1355. end;
  1356. else
  1357. IllegalPara(opt);
  1358. end;
  1359. inc(j);
  1360. end;
  1361. end;
  1362. 'v' :
  1363. begin
  1364. if not setverbosity(More) then
  1365. IllegalPara(opt);
  1366. end;
  1367. 'V' : ; { Ignore used by fpc }
  1368. 'W' :
  1369. begin
  1370. j:=1;
  1371. while j<=length(More) do
  1372. begin
  1373. case More[j] of
  1374. 'A':
  1375. begin
  1376. if UnsetBool(More, j) then
  1377. apptype:=app_native
  1378. else
  1379. apptype:=app_cui;
  1380. end;
  1381. 'b':
  1382. begin
  1383. if (target_info.system in systems_darwin) then
  1384. begin
  1385. if not UnsetBool(More, j) then
  1386. apptype:=app_bundle
  1387. else
  1388. apptype:=app_cui
  1389. end
  1390. else
  1391. IllegalPara(opt);
  1392. end;
  1393. 'B':
  1394. begin
  1395. { -WB200000 means set trefered base address
  1396. to $200000, but does not change relocsection boolean
  1397. this way we can create both relocatble and
  1398. non relocatable DLL at a specific base address PM }
  1399. if (length(More)>j) then
  1400. begin
  1401. val('$'+Copy(More,j+1,255),imagebase,code);
  1402. if code<>0 then
  1403. IllegalPara(opt);
  1404. ImageBaseSetExplicity:=true;
  1405. end
  1406. else
  1407. begin
  1408. RelocSection:=true;
  1409. RelocSectionSetExplicitly:=true;
  1410. end;
  1411. break;
  1412. end;
  1413. 'C':
  1414. begin
  1415. if UnsetBool(More, j) then
  1416. apptype:=app_gui
  1417. else
  1418. apptype:=app_cui;
  1419. end;
  1420. 'D':
  1421. begin
  1422. UseDeffileForExports:=not UnsetBool(More, j);
  1423. UseDeffileForExportsSetExplicitly:=true;
  1424. end;
  1425. 'e':
  1426. begin
  1427. if (target_info.system in systems_darwin) then
  1428. begin
  1429. RegisterRes(res_macosx_ext_info,TWinLikeResourceFile);
  1430. set_target_res(res_ext);
  1431. target_info.resobjext:='.fpcres';
  1432. end
  1433. else
  1434. IllegalPara(opt);
  1435. end;
  1436. 'F':
  1437. begin
  1438. if UnsetBool(More, j) then
  1439. apptype:=app_cui
  1440. else
  1441. apptype:=app_fs;
  1442. end;
  1443. 'G':
  1444. begin
  1445. if UnsetBool(More, j) then
  1446. apptype:=app_cui
  1447. else
  1448. apptype:=app_gui;
  1449. end;
  1450. 'I':
  1451. begin
  1452. GenerateImportSection:=not UnsetBool(More,j);
  1453. GenerateImportSectionSetExplicitly:=true;
  1454. end;
  1455. 'i':
  1456. begin
  1457. if (target_info.system in systems_darwin) then
  1458. begin
  1459. set_target_res(res_macho);
  1460. target_info.resobjext:=
  1461. targetinfos[target_info.system]^.resobjext;
  1462. end
  1463. else
  1464. IllegalPara(opt);
  1465. end;
  1466. 'N':
  1467. begin
  1468. RelocSection:=UnsetBool(More,j);
  1469. RelocSectionSetExplicitly:=true;
  1470. end;
  1471. 'p':
  1472. begin
  1473. {$if defined(arm) or defined(avr)}
  1474. if (target_info.system in systems_embedded) then
  1475. begin
  1476. s:=upper(copy(more,j+1,length(more)-j));
  1477. if not(SetControllerType(s,init_settings.controllertype)) then
  1478. IllegalPara(opt);
  1479. break;
  1480. end
  1481. else
  1482. {$endif defined(arm) or defined(avr)}
  1483. IllegalPara(opt);
  1484. end;
  1485. 'R':
  1486. begin
  1487. { support -WR+ / -WR- as synonyms to -WR / -WN }
  1488. RelocSection:=not UnsetBool(More,j);
  1489. RelocSectionSetExplicitly:=true;
  1490. end;
  1491. 'T':
  1492. begin
  1493. if UnsetBool(More, j) then
  1494. apptype:=app_cui
  1495. else
  1496. apptype:=app_tool;
  1497. end;
  1498. 'X':
  1499. begin
  1500. if (target_info.system in systems_linux) then
  1501. begin
  1502. if UnsetBool(More, j) then
  1503. exclude(init_settings.moduleswitches,cs_executable_stack)
  1504. else
  1505. include(init_settings.moduleswitches,cs_executable_stack)
  1506. end
  1507. else
  1508. IllegalPara(opt);
  1509. end
  1510. else
  1511. IllegalPara(opt);
  1512. end;
  1513. inc(j);
  1514. end;
  1515. end;
  1516. 'X' :
  1517. begin
  1518. j:=1;
  1519. while j<=length(more) do
  1520. begin
  1521. case More[j] of
  1522. 'c' : Cshared:=TRUE;
  1523. 'd' : Dontlinkstdlibpath:=TRUE;
  1524. 'e' :
  1525. begin
  1526. If UnsetBool(More, j) then
  1527. exclude(init_settings.globalswitches,cs_link_extern)
  1528. else
  1529. include(init_settings.globalswitches,cs_link_extern);
  1530. end;
  1531. 'f' :
  1532. include(init_settings.globalswitches,cs_link_pthread);
  1533. 'g' :
  1534. begin
  1535. If UnsetBool(More, j) then
  1536. exclude(init_settings.globalswitches,cs_link_separate_dbg_file)
  1537. else
  1538. include(init_settings.globalswitches,cs_link_separate_dbg_file);
  1539. end;
  1540. 'i' :
  1541. begin
  1542. If UnsetBool(More, j) then
  1543. include(init_settings.globalswitches,cs_link_extern)
  1544. else
  1545. exclude(init_settings.globalswitches,cs_link_extern);
  1546. end;
  1547. 'n' :
  1548. begin
  1549. If UnsetBool(More, j) then
  1550. exclude(init_settings.globalswitches,cs_link_native)
  1551. else
  1552. include(init_settings.globalswitches,cs_link_native);
  1553. end;
  1554. 'm' :
  1555. begin
  1556. If UnsetBool(More, j) then
  1557. exclude(init_settings.globalswitches,cs_link_map)
  1558. else
  1559. include(init_settings.globalswitches,cs_link_map);
  1560. end;
  1561. 'p' : ; { Ignore used by fpc.pp }
  1562. 'r' :
  1563. begin
  1564. if (target_info.system in suppported_targets_x_smallr) then
  1565. begin
  1566. rlinkpath:=Copy(more,2,length(More)-1);
  1567. DefaultReplacements(rlinkpath);
  1568. end
  1569. else
  1570. IgnoredPara('-Xr');
  1571. more:='';
  1572. end;
  1573. 'R' :
  1574. begin
  1575. sysrootpath:=copy(more,2,length(more)-1);
  1576. defaultreplacements(sysrootpath);
  1577. more:='';
  1578. end;
  1579. 's' :
  1580. begin
  1581. If UnsetBool(More, j) then
  1582. exclude(init_settings.globalswitches,cs_link_strip)
  1583. else
  1584. include(init_settings.globalswitches,cs_link_strip);
  1585. end;
  1586. 't' :
  1587. include(init_settings.globalswitches,cs_link_staticflag);
  1588. 'v' :
  1589. begin
  1590. If UnsetBool(More, j) then
  1591. exclude(init_settings.globalswitches,cs_link_opt_vtable)
  1592. else
  1593. include(init_settings.globalswitches,cs_link_opt_vtable);
  1594. end;
  1595. 'D' :
  1596. begin
  1597. def_system_macro('FPC_LINK_DYNAMIC');
  1598. undef_system_macro('FPC_LINK_SMART');
  1599. undef_system_macro('FPC_LINK_STATIC');
  1600. exclude(init_settings.globalswitches,cs_link_static);
  1601. exclude(init_settings.globalswitches,cs_link_smart);
  1602. include(init_settings.globalswitches,cs_link_shared);
  1603. LinkTypeSetExplicitly:=true;
  1604. end;
  1605. 'M' :
  1606. begin
  1607. mainaliasname:=Copy(more,2,length(More)-1);
  1608. More:='';
  1609. end;
  1610. 'P' :
  1611. begin
  1612. utilsprefix:=Copy(more,2,length(More)-1);
  1613. DefaultReplacements(utilsprefix);
  1614. More:='';
  1615. end;
  1616. 'L' : begin // -XLO is link order -XLA is link alias. -XLD avoids load defaults.
  1617. // these are not aggregable.
  1618. if (j=length(more)) or not (more[j+1] in ['O','A','D']) then
  1619. IllegalPara(opt)
  1620. else
  1621. begin
  1622. case more[j+1] of
  1623. 'A' : begin
  1624. s:=Copy(more,3,length(More)-2);
  1625. if not LinkLibraryAliases.AddDep(s) Then
  1626. IllegalPara(opt);
  1627. end;
  1628. 'O' : begin
  1629. s:=Copy(more,3,length(More)-2);
  1630. if not LinkLibraryOrder.AddWeight(s) Then
  1631. IllegalPara(opt);
  1632. end;
  1633. 'D' : include(init_settings.globalswitches,cs_link_no_default_lib_order)
  1634. else
  1635. IllegalPara(opt);
  1636. end; {case}
  1637. j:=length(more);
  1638. end; {else begin}
  1639. end;
  1640. 'S' :
  1641. begin
  1642. ForceStaticLinking;
  1643. end;
  1644. 'X' :
  1645. begin
  1646. def_system_macro('FPC_LINK_SMART');
  1647. undef_system_macro('FPC_LINK_STATIC');
  1648. undef_system_macro('FPC_LINK_DYNAMIC');
  1649. exclude(init_settings.globalswitches,cs_link_static);
  1650. include(init_settings.globalswitches,cs_link_smart);
  1651. exclude(init_settings.globalswitches,cs_link_shared);
  1652. LinkTypeSetExplicitly:=true;
  1653. end;
  1654. '-' :
  1655. begin
  1656. exclude(init_settings.globalswitches,cs_link_staticflag);
  1657. exclude(init_settings.globalswitches,cs_link_strip);
  1658. exclude(init_settings.globalswitches,cs_link_map);
  1659. set_default_link_type;
  1660. end;
  1661. else
  1662. IllegalPara(opt);
  1663. end;
  1664. inc(j);
  1665. end;
  1666. end;
  1667. else
  1668. IllegalPara(opt);
  1669. end;
  1670. end;
  1671. '@' :
  1672. begin
  1673. Message(option_no_nested_response_file);
  1674. StopOptions(1);
  1675. end;
  1676. else
  1677. begin
  1678. if (length(param_file)<>0) then
  1679. Message2(option_only_one_source_support,param_file,opt);
  1680. param_file:=opt;
  1681. Message1(option_found_file,opt);
  1682. end;
  1683. end;
  1684. end;
  1685. procedure Toption.Interpret_file(const filename : string);
  1686. procedure RemoveSep(var fn:string);
  1687. var
  1688. i : longint;
  1689. begin
  1690. i:=0;
  1691. while (i<length(fn)) and (fn[i+1] in [',',' ',#9]) do
  1692. inc(i);
  1693. Delete(fn,1,i);
  1694. i:=length(fn);
  1695. while (i>0) and (fn[i] in [',',' ',#9]) do
  1696. dec(i);
  1697. fn:=copy(fn,1,i);
  1698. end;
  1699. function GetName(var fn:string):string;
  1700. var
  1701. i : longint;
  1702. begin
  1703. i:=0;
  1704. while (i<length(fn)) and (fn[i+1] in ['a'..'z','A'..'Z','0'..'9','_','-']) do
  1705. inc(i);
  1706. GetName:=Copy(fn,1,i);
  1707. Delete(fn,1,i);
  1708. end;
  1709. const
  1710. maxlevel = 15;
  1711. var
  1712. f : text;
  1713. s, tmp,
  1714. opts : string;
  1715. skip : array[0..maxlevel] of boolean;
  1716. line,
  1717. level : longint;
  1718. option_read : boolean;
  1719. begin
  1720. { avoid infinite loop }
  1721. Inc(FileLevel);
  1722. Option_read:=false;
  1723. If FileLevel>MaxLevel then
  1724. Message(option_too_many_cfg_files);
  1725. { Maybe It's Directory ?} //Jaro Change:
  1726. if PathExists(filename,false) then
  1727. begin
  1728. Message1(option_config_is_dir,filename);
  1729. exit;
  1730. end;
  1731. { open file }
  1732. Message1(option_using_file,filename);
  1733. assign(f,ExpandFileName(filename));
  1734. {$I-}
  1735. reset(f);
  1736. {$I+}
  1737. if ioresult<>0 then
  1738. begin
  1739. Message1(option_unable_open_file,filename);
  1740. exit;
  1741. end;
  1742. Message1(option_start_reading_configfile,filename);
  1743. fillchar(skip,sizeof(skip),0);
  1744. level:=0;
  1745. line:=0;
  1746. while not eof(f) do
  1747. begin
  1748. readln(f,opts);
  1749. inc(line);
  1750. RemoveSep(opts);
  1751. if (opts<>'') and (opts[1]<>';') then
  1752. begin
  1753. if opts[1]='#' then
  1754. begin
  1755. Message1(option_interpreting_file_option,opts);
  1756. Delete(opts,1,1);
  1757. s:=upper(GetName(opts));
  1758. if (s='SECTION') then
  1759. begin
  1760. RemoveSep(opts);
  1761. s:=upper(GetName(opts));
  1762. if level=0 then
  1763. skip[level]:=not defined_macro(s) or (s='COMMON');
  1764. end
  1765. else
  1766. if (s='IFDEF') then
  1767. begin
  1768. RemoveSep(opts);
  1769. if Level>=maxlevel then
  1770. begin
  1771. Message2(option_too_many_ifdef,filename,tostr(line));
  1772. stopOptions(1);
  1773. end;
  1774. inc(Level);
  1775. skip[level]:=(skip[level-1] or not defined_macro(upper(GetName(opts))));
  1776. end
  1777. else
  1778. if (s='IFNDEF') then
  1779. begin
  1780. RemoveSep(opts);
  1781. if Level>=maxlevel then
  1782. begin
  1783. Message2(option_too_many_ifdef,filename,tostr(line));
  1784. stopOptions(1);
  1785. end;
  1786. inc(Level);
  1787. skip[level]:=(skip[level-1] or defined_macro(upper(GetName(opts))));
  1788. end
  1789. else
  1790. if (s='ELSE') then
  1791. begin
  1792. if Level=0 then
  1793. begin
  1794. Message2(option_else_without_if,filename,tostr(line));
  1795. stopOptions(1);
  1796. end
  1797. else
  1798. skip[level]:=skip[level-1] or (not skip[level])
  1799. end
  1800. else
  1801. if (s='ENDIF') then
  1802. begin
  1803. skip[level]:=false;
  1804. if Level=0 then
  1805. begin
  1806. Message2(option_too_many_endif,filename,tostr(line));
  1807. stopOptions(1);
  1808. end;
  1809. dec(level);
  1810. end
  1811. else
  1812. if (not skip[level]) then
  1813. begin
  1814. if (s='DEFINE') then
  1815. begin
  1816. RemoveSep(opts);
  1817. tmp:= GetName(opts);
  1818. if tmp <> '' then
  1819. def_system_macro(tmp);
  1820. end
  1821. else
  1822. if (s='UNDEF') then
  1823. begin
  1824. RemoveSep(opts);
  1825. tmp:= GetName(opts);
  1826. if tmp <> '' then
  1827. undef_system_macro(tmp);
  1828. end
  1829. else
  1830. if (s='WRITE') then
  1831. begin
  1832. Delete(opts,1,1);
  1833. WriteLn(opts);
  1834. end
  1835. else
  1836. if (s='INCLUDE') then
  1837. begin
  1838. Delete(opts,1,1);
  1839. Interpret_file(opts);
  1840. end;
  1841. end;
  1842. end
  1843. else
  1844. begin
  1845. if (opts[1]='-') or (opts[1]='@') then
  1846. begin
  1847. if (not skip[level]) then
  1848. interpret_option(opts,false);
  1849. Option_read:=true;
  1850. end
  1851. else
  1852. Message1(option_illegal_para,opts);
  1853. end;
  1854. end;
  1855. end;
  1856. if Level>0 then
  1857. Message(option_too_less_endif);
  1858. if Not Option_read then
  1859. Message1(option_no_option_found,filename)
  1860. else
  1861. Message1(option_end_reading_configfile,filename);
  1862. Close(f);
  1863. Dec(FileLevel);
  1864. end;
  1865. procedure Toption.Interpret_envvar(const envname : string);
  1866. var
  1867. argstart,
  1868. env,
  1869. pc : pchar;
  1870. arglen : longint;
  1871. quote : set of char;
  1872. hs : string;
  1873. begin
  1874. Message1(option_using_env,envname);
  1875. env:=GetEnvPChar(envname);
  1876. pc:=env;
  1877. if assigned(pc) then
  1878. begin
  1879. repeat
  1880. { skip leading spaces }
  1881. while pc^ in [' ',#9,#13] do
  1882. inc(pc);
  1883. case pc^ of
  1884. #0 :
  1885. break;
  1886. '"' :
  1887. begin
  1888. quote:=['"'];
  1889. inc(pc);
  1890. end;
  1891. '''' :
  1892. begin
  1893. quote:=[''''];
  1894. inc(pc);
  1895. end;
  1896. else
  1897. quote:=[' ',#9,#13];
  1898. end;
  1899. { scan until the end of the argument }
  1900. argstart:=pc;
  1901. while (pc^<>#0) and not(pc^ in quote) do
  1902. inc(pc);
  1903. { create argument }
  1904. arglen:=pc-argstart;
  1905. { TODO: FIXME: silent truncation of environment parameters }
  1906. if (arglen > 255) then
  1907. arglen := 255;
  1908. setlength(hs,arglen);
  1909. move(argstart^,hs[1],arglen);
  1910. interpret_option(hs,true);
  1911. { skip quote }
  1912. if pc^ in quote then
  1913. inc(pc);
  1914. until false;
  1915. end
  1916. else
  1917. Message1(option_no_option_found,'(env) '+envname);
  1918. FreeEnvPChar(env);
  1919. end;
  1920. procedure toption.read_parameters;
  1921. var
  1922. opts : string;
  1923. paramindex : longint;
  1924. begin
  1925. paramindex:=0;
  1926. while paramindex<paramcount do
  1927. begin
  1928. inc(paramindex);
  1929. opts:=system.paramstr(paramindex);
  1930. case opts[1] of
  1931. '@' :
  1932. if not firstpass then
  1933. begin
  1934. Delete(opts,1,1);
  1935. Message1(option_reading_further_from,opts);
  1936. interpret_file(opts);
  1937. end;
  1938. '!' :
  1939. if not firstpass then
  1940. begin
  1941. Delete(opts,1,1);
  1942. Message1(option_reading_further_from,'(env) '+opts);
  1943. interpret_envvar(opts);
  1944. end;
  1945. else
  1946. interpret_option(opts,true);
  1947. end;
  1948. end;
  1949. end;
  1950. procedure toption.parsecmd(cmd:string);
  1951. var
  1952. i,ps : longint;
  1953. opts : string;
  1954. begin
  1955. while (cmd<>'') do
  1956. begin
  1957. while cmd[1]=' ' do
  1958. delete(cmd,1,1);
  1959. i:=pos(' ',cmd);
  1960. if i=0 then
  1961. i:=256;
  1962. opts:=Copy(cmd,1,i-1);
  1963. Delete(cmd,1,i);
  1964. case opts[1] of
  1965. '@' :
  1966. if not firstpass then
  1967. begin
  1968. Delete(opts,1,1);
  1969. Message1(option_reading_further_from,opts);
  1970. interpret_file(opts);
  1971. end;
  1972. '!' :
  1973. if not firstpass then
  1974. begin
  1975. Delete(opts,1,1);
  1976. Message1(option_reading_further_from,'(env) '+opts);
  1977. interpret_envvar(opts);
  1978. end;
  1979. '"' :
  1980. begin
  1981. Delete(opts,1,1);
  1982. ps:=pos('"',cmd);
  1983. if (i<>256) and (ps>0) then
  1984. begin
  1985. opts:=opts + ' '+ copy(cmd,1,ps-1);
  1986. cmd:=copy(cmd,ps+1,255);
  1987. end;
  1988. interpret_option(opts,true);
  1989. end;
  1990. else
  1991. interpret_option(opts,true);
  1992. end;
  1993. end;
  1994. end;
  1995. procedure toption.writequickinfo;
  1996. var
  1997. s : string;
  1998. i : longint;
  1999. procedure addinfo(const hs:string);
  2000. begin
  2001. if s<>'' then
  2002. s:=s+' '+hs
  2003. else
  2004. s:=hs;
  2005. end;
  2006. begin
  2007. s:='';
  2008. i:=0;
  2009. while (i<length(quickinfo)) do
  2010. begin
  2011. inc(i);
  2012. case quickinfo[i] of
  2013. 'S' :
  2014. begin
  2015. inc(i);
  2016. case quickinfo[i] of
  2017. 'O' :
  2018. addinfo(lower(source_info.shortname));
  2019. 'P' :
  2020. addinfo(source_cpu_string);
  2021. else
  2022. IllegalPara('-i'+QuickInfo);
  2023. end;
  2024. end;
  2025. 'T' :
  2026. begin
  2027. inc(i);
  2028. case quickinfo[i] of
  2029. 'O' :
  2030. addinfo(lower(target_info.shortname));
  2031. 'P' :
  2032. AddInfo(target_cpu_string);
  2033. else
  2034. IllegalPara('-i'+QuickInfo);
  2035. end;
  2036. end;
  2037. 'V' :
  2038. AddInfo(version_string);
  2039. 'W' :
  2040. AddInfo(full_version_string);
  2041. 'D' :
  2042. AddInfo(date_string);
  2043. '_' :
  2044. ;
  2045. else
  2046. IllegalPara('-i'+QuickInfo);
  2047. end;
  2048. end;
  2049. if s<>'' then
  2050. begin
  2051. writeln(s);
  2052. stopoptions(0);
  2053. end;
  2054. end;
  2055. procedure TOption.TargetOptions(def:boolean);
  2056. var
  2057. s : string;
  2058. i : integer;
  2059. target_unsup_features : tfeatures;
  2060. begin
  2061. if def then
  2062. def_system_macro(target_info.shortname)
  2063. else
  2064. undef_system_macro(target_info.shortname);
  2065. s:=target_info.extradefines;
  2066. while (s<>'') do
  2067. begin
  2068. i:=pos(';',s);
  2069. if i=0 then
  2070. i:=length(s)+1;
  2071. if def then
  2072. def_system_macro(Copy(s,1,i-1))
  2073. else
  2074. undef_system_macro(Copy(s,1,i-1));
  2075. delete(s,1,i);
  2076. end;
  2077. if (tf_winlikewidestring in target_info.flags) then
  2078. if def then
  2079. def_system_macro('FPC_WINLIKEWIDESTRING')
  2080. else
  2081. undef_system_macro('FPC_WINLIKEWIDESTRING');
  2082. if (tf_requires_proper_alignment in target_info.flags) then
  2083. if def then
  2084. def_system_macro('FPC_REQUIRES_PROPER_ALIGNMENT')
  2085. else
  2086. undef_system_macro('FPC_REQUIRES_PROPER_ALIGNMENT');
  2087. if source_info.system<>target_info.system then
  2088. if def then
  2089. def_system_macro('FPC_CROSSCOMPILING')
  2090. else
  2091. undef_system_macro('FPC_CROSSCOMPILING');
  2092. if source_info.cpu<>target_info.cpu then
  2093. if def then
  2094. def_system_macro('FPC_CPUCROSSCOMPILING')
  2095. else
  2096. def_system_macro('FPC_CPUCROSSCOMPILING');
  2097. if (tf_no_generic_stackcheck in target_info.flags) then
  2098. if def then
  2099. def_system_macro('FPC_NO_GENERIC_STACK_CHECK')
  2100. else
  2101. undef_system_macro('FPC_NO_GENERIC_STACK_CHECK');
  2102. { Code generation flags }
  2103. if def and
  2104. (tf_pic_default in target_info.flags) then
  2105. include(init_settings.moduleswitches,cs_create_pic)
  2106. else
  2107. exclude(init_settings.moduleswitches,cs_create_pic);
  2108. { Resources support }
  2109. if (tf_has_winlike_resources in target_info.flags) then
  2110. if def then
  2111. def_system_macro('FPC_HAS_WINLIKERESOURCES')
  2112. else
  2113. undef_system_macro('FPC_HAS_WINLIKERESOURCES');
  2114. { Features }
  2115. case target_info.system of
  2116. system_arm_gba:
  2117. target_unsup_features:=[f_threading,f_commandargs,f_fileio,f_textio,f_consoleio,f_dynlibs];
  2118. system_arm_nds:
  2119. target_unsup_features:=[f_threading,f_commandargs,f_fileio,f_textio,f_consoleio,f_dynlibs];
  2120. system_i386_nativent:
  2121. // until these features are implemented, they are disabled in the compiler
  2122. target_unsup_features:=[f_stackcheck];
  2123. else
  2124. target_unsup_features:=[];
  2125. end;
  2126. if def then
  2127. features:=features-target_unsup_features
  2128. else
  2129. features:=features+target_unsup_features;
  2130. end;
  2131. procedure TOption.checkoptionscompatibility;
  2132. begin
  2133. if (paratargetdbg in [dbg_dwarf2,dbg_dwarf3]) and
  2134. not(target_info.system in systems_darwin) then
  2135. begin
  2136. { smart linking does not yet work with DWARF debug info on most targets }
  2137. if (cs_link_smart in init_settings.globalswitches) then
  2138. begin
  2139. Message(option_dwarf_smart_linking);
  2140. ForceStaticLinking;
  2141. end;
  2142. end;
  2143. { external debug info is only supported for DWARF on darwin }
  2144. if (target_info.system in systems_darwin) and
  2145. (cs_link_separate_dbg_file in init_settings.globalswitches) and
  2146. not(paratargetdbg in [dbg_dwarf2,dbg_dwarf3]) then
  2147. begin
  2148. Message(option_debug_external_unsupported);
  2149. exclude(init_settings.globalswitches,cs_link_separate_dbg_file);
  2150. end;
  2151. end;
  2152. constructor TOption.create;
  2153. begin
  2154. LogoWritten:=false;
  2155. NoPressEnter:=false;
  2156. FirstPass:=false;
  2157. FPUSetExplicitly:=false;
  2158. CPUSetExplicitly:=false;
  2159. OptCPUSetExplicitly:=false;
  2160. FileLevel:=0;
  2161. Quickinfo:='';
  2162. ParaIncludePath:=TSearchPathList.Create;
  2163. ParaObjectPath:=TSearchPathList.Create;
  2164. ParaUnitPath:=TSearchPathList.Create;
  2165. ParaLibraryPath:=TSearchPathList.Create;
  2166. ParaFrameworkPath:=TSearchPathList.Create;
  2167. FillChar(ParaAlignment,sizeof(ParaAlignment),0);
  2168. end;
  2169. destructor TOption.destroy;
  2170. begin
  2171. ParaIncludePath.Free;
  2172. ParaObjectPath.Free;
  2173. ParaUnitPath.Free;
  2174. ParaLibraryPath.Free;
  2175. ParaFrameworkPath.Free;
  2176. end;
  2177. {****************************************************************************
  2178. Callable Routines
  2179. ****************************************************************************}
  2180. function check_configfile(const fn:string;var foundfn:string):boolean;
  2181. function CfgFileExists(const fn:string):boolean;
  2182. begin
  2183. Comment(V_Tried,'Configfile search: '+fn);
  2184. CfgFileExists:=FileExists(fn);
  2185. end;
  2186. var
  2187. {$ifdef Unix}
  2188. hs,
  2189. {$endif Unix}
  2190. configpath : string;
  2191. begin
  2192. foundfn:=fn;
  2193. check_configfile:=true;
  2194. { retrieve configpath }
  2195. configpath:=FixPath(GetEnvironmentVariable('PPC_CONFIG_PATH'),false);
  2196. {$ifdef Unix}
  2197. if configpath='' then
  2198. configpath:=ExpandFileName(FixPath(exepath+'../etc/',false));
  2199. {$endif}
  2200. {
  2201. Order to read configuration file :
  2202. try reading fpc.cfg in :
  2203. 1 - current dir
  2204. 2 - configpath
  2205. 3 - compiler path
  2206. }
  2207. if not FileExists(fn) then
  2208. begin
  2209. {$ifdef Unix}
  2210. hs:=GetEnvironmentVariable('HOME');
  2211. if (hs<>'') and CfgFileExists(FixPath(hs,false)+'.'+fn) then
  2212. foundfn:=FixPath(hs,false)+'.'+fn
  2213. else
  2214. {$endif}
  2215. if CfgFileExists(configpath+fn) then
  2216. foundfn:=configpath+fn
  2217. else
  2218. {$ifndef Unix}
  2219. if CfgFileExists(exepath+fn) then
  2220. foundfn:=exepath+fn
  2221. else
  2222. {$else}
  2223. if CfgFileExists('/etc/'+fn) then
  2224. foundfn:='/etc/'+fn
  2225. else
  2226. {$endif}
  2227. check_configfile:=false;
  2228. end;
  2229. end;
  2230. procedure read_arguments(cmd:string);
  2231. var
  2232. env: ansistring;
  2233. i : tfeature;
  2234. abi : tabi;
  2235. begin
  2236. option:=coption.create;
  2237. disable_configfile:=false;
  2238. { Non-core target defines }
  2239. Option.TargetOptions(true);
  2240. { get default messagefile }
  2241. msgfilename:=GetEnvironmentVariable('PPC_ERROR_FILE');
  2242. { default configfile can be specified on the commandline,
  2243. remove it first }
  2244. if (cmd<>'') and (cmd[1]='[') then
  2245. begin
  2246. ppccfg:=Copy(cmd,2,pos(']',cmd)-2);
  2247. Delete(cmd,1,pos(']',cmd));
  2248. end
  2249. else
  2250. ppccfg:='fpc.cfg';
  2251. { first pass reading of parameters, only -i -v -T etc.}
  2252. option.firstpass:=true;
  2253. if cmd<>'' then
  2254. option.parsecmd(cmd)
  2255. else
  2256. begin
  2257. option.read_parameters;
  2258. { Write only quickinfo }
  2259. if option.quickinfo<>'' then
  2260. option.writequickinfo;
  2261. end;
  2262. option.firstpass:=false;
  2263. { target is set here, for wince the default app type is gui }
  2264. if target_info.system in systems_wince then
  2265. apptype:=app_gui;
  2266. { default defines }
  2267. def_system_macro(target_info.shortname);
  2268. def_system_macro('FPC');
  2269. def_system_macro('VER'+version_nr);
  2270. def_system_macro('VER'+version_nr+'_'+release_nr);
  2271. def_system_macro('VER'+version_nr+'_'+release_nr+'_'+patch_nr);
  2272. { Temporary defines, until things settle down }
  2273. def_system_macro('RESSTRSECTIONS');
  2274. def_system_macro('FPC_HASFIXED64BITVARIANT');
  2275. def_system_macro('FPC_HASINTERNALOLEVARIANT2VARIANTCAST');
  2276. def_system_macro('FPC_HAS_VARSETS');
  2277. def_system_macro('FPC_HAS_VALGRINDBOOL');
  2278. def_system_macro('FPC_HAS_STR_CURRENCY');
  2279. def_system_macro('FPC_REAL2REAL_FIXED');
  2280. def_system_macro('FPC_STRTOCHARARRAYPROC');
  2281. def_system_macro('FPC_STRTOSHORTSTRINGPROC');
  2282. def_system_macro('FPC_OBJFPC_EXTENDED_IF');
  2283. def_system_macro('FPC_HAS_OPERATOR_ENUMERATOR');
  2284. def_system_macro('FPC_HAS_CONSTREF');
  2285. def_system_macro('FPC_STATICRIPFIXED');
  2286. {$if defined(x86) or defined(powerpc) or defined(powerpc64)}
  2287. def_system_macro('FPC_HAS_INTERNAL_ABS_LONG');
  2288. {$endif}
  2289. def_system_macro('FPC_HAS_UNICODESTRING');
  2290. def_system_macro('FPC_RTTI_PACKSET1');
  2291. {$ifdef x86_64}
  2292. def_system_macro('FPC_HAS_RIP_RELATIVE');
  2293. {$endif x86_64}
  2294. def_system_macro('FPC_HAS_CEXTENDED');
  2295. { these cpus have an inline rol/ror implementaion }
  2296. {$if defined(x86) or defined(arm) or defined(powerpc) or defined(powerpc64)}
  2297. def_system_macro('FPC_HAS_INTERNAL_ROX');
  2298. {$endif}
  2299. { these cpus have an inline sar implementaion }
  2300. { currently, all supported CPUs have an internal sar implementation }
  2301. { $if defined(x86) or defined(arm) or defined(powerpc) or defined(powerpc64) or defined(sparc)}
  2302. def_system_macro('FPC_HAS_INTERNAL_SAR');
  2303. { $endif}
  2304. { inline bsf/bsr implementation }
  2305. {$if defined(x86) or defined(x86_64)}
  2306. def_system_macro('FPC_HAS_INTERNAL_BSX');
  2307. {$endif}
  2308. {$ifdef powerpc64}
  2309. def_system_macro('FPC_HAS_LWSYNC');
  2310. {$endif}
  2311. def_system_macro('FPC_HAS_MEMBAR');
  2312. def_system_macro('FPC_SETBASE_USED');
  2313. {$if defined(x86) or defined(arm)}
  2314. def_system_macro('INTERNAL_BACKTRACE');
  2315. {$endif}
  2316. def_system_macro('STR_CONCAT_PROCS');
  2317. {$warnings off}
  2318. if pocall_default = pocall_register then
  2319. def_system_macro('REGCALL');
  2320. {$warnings on}
  2321. { don't remove this, it's also for fpdoc necessary (FK) }
  2322. def_system_macro('FPC_HAS_FEATURE_SUPPORT');
  2323. { using a case is pretty useless here (FK) }
  2324. { some stuff for TP compatibility }
  2325. {$ifdef i386}
  2326. def_system_macro('CPU86');
  2327. def_system_macro('CPU87');
  2328. def_system_macro('CPU386');
  2329. {$endif}
  2330. { new processor stuff }
  2331. {$ifdef i386}
  2332. def_system_macro('CPUI386');
  2333. def_system_macro('CPU32');
  2334. def_system_macro('FPC_HAS_TYPE_EXTENDED');
  2335. def_system_macro('FPC_HAS_TYPE_DOUBLE');
  2336. def_system_macro('FPC_HAS_TYPE_SINGLE');
  2337. {$endif}
  2338. {$ifdef m68k}
  2339. def_system_macro('CPU68');
  2340. def_system_macro('CPU68K');
  2341. def_system_macro('CPUM68K');
  2342. def_system_macro('CPU32');
  2343. def_system_macro('FPC_CURRENCY_IS_INT64');
  2344. def_system_macro('FPC_COMP_IS_INT64');
  2345. {$endif}
  2346. {$ifdef ALPHA}
  2347. def_system_macro('CPUALPHA');
  2348. def_system_macro('CPU64');
  2349. {$endif}
  2350. {$ifdef powerpc}
  2351. def_system_macro('CPUPOWERPC');
  2352. def_system_macro('CPUPOWERPC32');
  2353. def_system_macro('CPU32');
  2354. def_system_macro('FPC_CURRENCY_IS_INT64');
  2355. def_system_macro('FPC_COMP_IS_INT64');
  2356. {$endif}
  2357. {$ifdef POWERPC64}
  2358. def_system_macro('CPUPOWERPC');
  2359. def_system_macro('CPUPOWERPC64');
  2360. def_system_macro('CPU64');
  2361. def_system_macro('FPC_CURRENCY_IS_INT64');
  2362. def_system_macro('FPC_COMP_IS_INT64');
  2363. {$endif}
  2364. {$ifdef iA64}
  2365. def_system_macro('CPUIA64');
  2366. def_system_macro('CPU64');
  2367. {$endif}
  2368. {$ifdef x86_64}
  2369. def_system_macro('CPUX86_64');
  2370. def_system_macro('CPUAMD64');
  2371. def_system_macro('CPU64');
  2372. { not supported for now, afaik (FK)
  2373. def_system_macro('FPC_HAS_TYPE_FLOAT128'); }
  2374. { win64 doesn't support the legacy fpu }
  2375. if target_info.system=system_x86_64_win64 then
  2376. begin
  2377. def_system_macro('FPC_CURRENCY_IS_INT64');
  2378. def_system_macro('FPC_COMP_IS_INT64');
  2379. end;
  2380. {$endif}
  2381. {$ifdef sparc}
  2382. def_system_macro('CPUSPARC');
  2383. def_system_macro('CPUSPARC32');
  2384. def_system_macro('CPU32');
  2385. def_system_macro('FPC_CURRENCY_IS_INT64');
  2386. def_system_macro('FPC_COMP_IS_INT64');
  2387. {$endif}
  2388. {$ifdef vis}
  2389. def_system_macro('CPUVIS');
  2390. def_system_macro('CPU32');
  2391. {$endif}
  2392. {$ifdef arm}
  2393. def_system_macro('CPUARM');
  2394. def_system_macro('CPU32');
  2395. def_system_macro('FPC_CURRENCY_IS_INT64');
  2396. def_system_macro('FPC_COMP_IS_INT64');
  2397. {$endif arm}
  2398. {$ifdef avr}
  2399. def_system_macro('CPUAVR');
  2400. def_system_macro('CPU16');
  2401. def_system_macro('FPC_CURRENCY_IS_INT64');
  2402. def_system_macro('FPC_COMP_IS_INT64');
  2403. {$endif avr}
  2404. { read configuration file }
  2405. if (not disable_configfile) and
  2406. (ppccfg<>'') then
  2407. read_configfile:=check_configfile(ppccfg,ppccfg)
  2408. else
  2409. read_configfile := false;
  2410. { Read commandline and configfile }
  2411. param_file:='';
  2412. { read configfile }
  2413. if read_configfile then
  2414. option.interpret_file(ppccfg);
  2415. { read parameters again to override config file }
  2416. if cmd<>'' then
  2417. option.parsecmd(cmd)
  2418. else
  2419. begin
  2420. { Write help pages if no parameters are passed }
  2421. if (paramcount=0) then
  2422. Option.WriteHelpPages;
  2423. option.read_parameters;
  2424. { Write only quickinfo }
  2425. if option.quickinfo<>'' then
  2426. option.writequickinfo;
  2427. end;
  2428. { check the compatibility of different options and adjust them if necessary
  2429. (and print possible errors)
  2430. }
  2431. option.checkoptionscompatibility;
  2432. { Stop if errors in options }
  2433. if ErrorCount>0 then
  2434. StopOptions(1);
  2435. { endian define }
  2436. case target_info.endian of
  2437. endian_little :
  2438. begin
  2439. def_system_macro('ENDIAN_LITTLE');
  2440. def_system_macro('FPC_LITTLE_ENDIAN');
  2441. end;
  2442. endian_big :
  2443. begin
  2444. def_system_macro('ENDIAN_BIG');
  2445. def_system_macro('FPC_BIG_ENDIAN');
  2446. end;
  2447. end;
  2448. { define abi }
  2449. for abi:=low(tabi) to high(tabi) do
  2450. undef_system_macro('FPC_ABI_'+abi2str[abi]);
  2451. def_system_macro('FPC_ABI_'+abi2str[target_info.abi]);
  2452. { Write logo }
  2453. if option.ParaLogo then
  2454. option.writelogo;
  2455. { Check file to compile }
  2456. if param_file='' then
  2457. begin
  2458. Message(option_no_source_found);
  2459. StopOptions(1);
  2460. end;
  2461. {$ifndef Unix}
  2462. param_file:=FixFileName(param_file);
  2463. {$endif not unix}
  2464. inputfilepath:=ExtractFilePath(param_file);
  2465. inputfilename:=ExtractFileName(param_file);
  2466. if ExtractFileExt(inputfilename)='' then
  2467. begin
  2468. if FileExists(inputfilepath+ChangeFileExt(inputfilename,sourceext)) then
  2469. inputfilename:=ChangeFileExt(inputfilename,sourceext)
  2470. else if FileExists(inputfilepath+ChangeFileExt(inputfilename,pasext)) then
  2471. inputfilename:=ChangeFileExt(inputfilename,pasext)
  2472. else if ((m_mac in current_settings.modeswitches) or
  2473. (tf_p_ext_support in target_info.flags))
  2474. and FileExists(inputfilepath+ChangeFileExt(inputfilename,pext)) then
  2475. inputfilename:=ChangeFileExt(inputfilename,pext);
  2476. end;
  2477. { Check output dir }
  2478. if (OutputExeDir<>'') and
  2479. not PathExists(OutputExeDir,false) then
  2480. begin
  2481. Message1(general_e_path_does_not_exist,OutputExeDir);
  2482. StopOptions(1);
  2483. end;
  2484. { Add paths specified with parameters to the searchpaths }
  2485. UnitSearchPath.AddList(option.ParaUnitPath,true);
  2486. ObjectSearchPath.AddList(option.ParaObjectPath,true);
  2487. IncludeSearchPath.AddList(option.ParaIncludePath,true);
  2488. LibrarySearchPath.AddList(option.ParaLibraryPath,true);
  2489. FrameworkSearchPath.AddList(option.ParaFrameworkPath,true);
  2490. { add unit environment and exepath to the unit search path }
  2491. if inputfilepath<>'' then
  2492. Unitsearchpath.AddPath(inputfilepath,true);
  2493. if not disable_configfile then
  2494. begin
  2495. env:=GetEnvironmentVariable(target_info.unit_env);
  2496. if env<>'' then
  2497. UnitSearchPath.AddPath(GetEnvironmentVariable(target_info.unit_env),false);
  2498. end;
  2499. {$ifdef Unix}
  2500. fpcdir:=FixPath(GetEnvironmentVariable('FPCDIR'),false);
  2501. if fpcdir='' then
  2502. begin
  2503. if PathExists('/usr/local/lib/fpc/'+version_string,true) then
  2504. fpcdir:='/usr/local/lib/fpc/'+version_string+'/'
  2505. else
  2506. fpcdir:='/usr/lib/fpc/'+version_string+'/';
  2507. end;
  2508. {$else unix}
  2509. fpcdir:=FixPath(GetEnvironmentVariable('FPCDIR'),false);
  2510. if fpcdir='' then
  2511. begin
  2512. fpcdir:=ExePath+'../';
  2513. if not(PathExists(fpcdir+'units',true)) and
  2514. not(PathExists(fpcdir+'rtl',true)) then
  2515. fpcdir:=fpcdir+'../';
  2516. end;
  2517. {$endif unix}
  2518. { first try development RTL, else use the default installation path }
  2519. if not disable_configfile then
  2520. begin
  2521. if PathExists(FpcDir+'rtl',true) then
  2522. if tf_use_8_3 in Source_Info.Flags then
  2523. UnitSearchPath.AddPath(FpcDir+'rtl/'+target_os_string,false)
  2524. else
  2525. UnitSearchPath.AddPath(FpcDir+'rtl/'+target_full_string,false)
  2526. else
  2527. if tf_use_8_3 in Source_Info.Flags then
  2528. UnitSearchPath.AddPath(FpcDir+'units/'+target_os_string+'/rtl',false)
  2529. else
  2530. UnitSearchPath.AddPath(FpcDir+'units/'+target_full_string+'/rtl',false);
  2531. end;
  2532. { Add exepath if the exe is not in the current dir, because that is always searched already.
  2533. Do not add it when linking on the target because then we can maybe already find
  2534. .o files that are not for the target }
  2535. if (ExePath<>GetCurrentDir) and
  2536. not(cs_link_on_target in init_settings.globalswitches) then
  2537. UnitSearchPath.AddPath(ExePath,false);
  2538. { Add unit dir to the object and library path }
  2539. objectsearchpath.AddList(unitsearchpath,false);
  2540. librarysearchpath.AddList(unitsearchpath,false);
  2541. { maybe override assembler }
  2542. if (paratargetasm<>as_none) then
  2543. begin
  2544. if not set_target_asm(paratargetasm) then
  2545. begin
  2546. Message2(option_incompatible_asm,asminfos[paratargetasm]^.idtxt,target_info.name);
  2547. set_target_asm(target_info.assemextern);
  2548. Message1(option_asm_forced,target_asm.idtxt);
  2549. end;
  2550. if (af_no_debug in asminfos[paratargetasm]^.flags) and
  2551. (paratargetdbg<>dbg_none) then
  2552. begin
  2553. Message1(option_confict_asm_debug,
  2554. asminfos[paratargetasm]^.idtxt);
  2555. paratargetdbg:=dbg_none;
  2556. exclude(init_settings.moduleswitches,cs_debuginfo);
  2557. end;
  2558. end;
  2559. { maybe override debug info format }
  2560. if (paratargetdbg<>dbg_none) then
  2561. set_target_dbg(paratargetdbg);
  2562. { switch assembler if it's binary and we got -a on the cmdline }
  2563. if (cs_asm_leave in init_settings.globalswitches) and
  2564. (af_outputbinary in target_asm.flags) then
  2565. begin
  2566. Message(option_switch_bin_to_src_assembler);
  2567. set_target_asm(target_info.assemextern);
  2568. end;
  2569. { Force use of external linker if there is no
  2570. internal linker or the linking is skipped }
  2571. if not(cs_link_extern in init_settings.globalswitches) and
  2572. (not assigned(target_info.link) or
  2573. (cs_link_nolink in init_settings.globalswitches)) then
  2574. include(init_settings.globalswitches,cs_link_extern);
  2575. { turn off stripping if compiling with debuginfo or profile }
  2576. if (
  2577. (cs_debuginfo in init_settings.moduleswitches) or
  2578. (cs_profile in init_settings.moduleswitches)
  2579. ) and
  2580. not(cs_link_separate_dbg_file in init_settings.globalswitches) then
  2581. exclude(init_settings.globalswitches,cs_link_strip);
  2582. { force fpu emulation on arm/wince, arm/gba, arm/embedded, arm/nds and
  2583. arm/darwin if fpu type not explicitly set }
  2584. if not(option.FPUSetExplicitly) and
  2585. ((target_info.system in [system_arm_wince,system_arm_gba,system_m68k_amiga,
  2586. system_m68k_linux,system_arm_nds,system_arm_embedded,system_arm_darwin])
  2587. {$ifdef arm}
  2588. or (target_info.abi=abi_eabi)
  2589. {$endif arm}
  2590. )
  2591. {$ifdef arm}
  2592. or (init_settings.fputype=fpu_soft)
  2593. {$endif arm}
  2594. then
  2595. begin
  2596. {$ifdef cpufpemu}
  2597. include(init_settings.moduleswitches,cs_fp_emulation);
  2598. { cs_fp_emulation and fpu_soft are equal on arm }
  2599. init_settings.fputype:=fpu_soft;
  2600. {$endif cpufpemu}
  2601. end;
  2602. {$ifdef arm}
  2603. { set default cpu type to ARMv6 for Darwin unless specified otherwise }
  2604. if (target_info.system=system_arm_darwin) then
  2605. begin
  2606. if not option.CPUSetExplicitly then
  2607. init_settings.cputype:=cpu_armv6;
  2608. if not option.OptCPUSetExplicitly then
  2609. init_settings.optimizecputype:=cpu_armv6;
  2610. end;
  2611. {$endif arm}
  2612. { now we can define cpu and fpu type }
  2613. def_system_macro('CPU'+Cputypestr[init_settings.cputype]);
  2614. def_system_macro('FPU'+fputypestr[init_settings.fputype]);
  2615. if init_settings.fputype<>fpu_none then
  2616. begin
  2617. {$if defined(i386)}
  2618. def_system_macro('FPC_HAS_TYPE_EXTENDED');
  2619. {$endif}
  2620. def_system_macro('FPC_HAS_TYPE_SINGLE');
  2621. def_system_macro('FPC_HAS_TYPE_DOUBLE');
  2622. {$if not defined(i386) and not defined(x86_64)}
  2623. def_system_macro('FPC_INCLUDE_SOFTWARE_INT64_TO_DOUBLE');
  2624. {$endif}
  2625. {$ifdef x86_64}
  2626. { win64 doesn't support the legacy fpu }
  2627. if target_info.system=system_x86_64_win64 then
  2628. undef_system_macro('FPC_HAS_TYPE_EXTENDED')
  2629. else
  2630. def_system_macro('FPC_HAS_TYPE_EXTENDED');
  2631. {$endif}
  2632. end;
  2633. {$ifdef ARM}
  2634. { define FPC_DOUBLE_HILO_SWAPPED if needed to properly handle doubles in RTL }
  2635. if (init_settings.fputype in [fpu_fpa,fpu_fpa10,fpu_fpa11]) and
  2636. not(cs_fp_emulation in init_settings.moduleswitches) then
  2637. def_system_macro('FPC_DOUBLE_HILO_SWAPPED');
  2638. {$endif ARM}
  2639. { Section smartlinking conflicts with import sections on Windows }
  2640. if GenerateImportSection and
  2641. (target_info.system in [system_i386_win32,system_x86_64_win64]) then
  2642. exclude(target_info.flags,tf_smartlink_sections);
  2643. if not LinkTypeSetExplicitly then
  2644. set_default_link_type;
  2645. { Default alignment settings,
  2646. 1. load the defaults for the target
  2647. 2. override with generic optimizer setting (little size)
  2648. 3. override with the user specified -Oa }
  2649. UpdateAlignment(init_settings.alignment,target_info.alignment);
  2650. if (cs_opt_size in current_settings.optimizerswitches) then
  2651. begin
  2652. init_settings.alignment.procalign:=1;
  2653. init_settings.alignment.jumpalign:=1;
  2654. init_settings.alignment.loopalign:=1;
  2655. end;
  2656. UpdateAlignment(init_settings.alignment,option.paraalignment);
  2657. set_system_macro('FPC_VERSION',version_nr);
  2658. set_system_macro('FPC_RELEASE',release_nr);
  2659. set_system_macro('FPC_PATCH',patch_nr);
  2660. set_system_macro('FPC_FULLVERSION',Format('%d%.02d%.02d',[StrToInt(version_nr),StrToInt(release_nr),StrToInt(patch_nr)]));
  2661. if not(target_info.system in systems_windows) then
  2662. def_system_macro('FPC_WIDESTRING_EQUAL_UNICODESTRING');
  2663. for i:=low(tfeature) to high(tfeature) do
  2664. if i in features then
  2665. def_system_macro('FPC_HAS_FEATURE_'+featurestr[i]);
  2666. option.free;
  2667. Option:=nil;
  2668. clearstack_pocalls := [pocall_cdecl,pocall_cppdecl,pocall_syscall,pocall_mwpascal];
  2669. cdecl_pocalls := [pocall_cdecl, pocall_cppdecl];
  2670. if (tf_safecall_clearstack in target_info.flags) then
  2671. begin
  2672. include (cdecl_pocalls, pocall_safecall);
  2673. include (clearstack_pocalls, pocall_safecall)
  2674. end;
  2675. end;
  2676. initialization
  2677. coption:=toption;
  2678. finalization
  2679. if assigned(option) then
  2680. option.free;
  2681. end.