options.pas 93 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862
  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:TCmdStr);
  47. procedure UnsupportedPara(const opt:TCmdStr);
  48. procedure IgnoredPara(const opt:TCmdStr);
  49. function Unsetbool(var Opts:TCmdStr; Pos: Longint):boolean;
  50. procedure interpret_option(const opt :TCmdStr;ispara:boolean);
  51. procedure Interpret_envvar(const envname : TCmdStr);
  52. procedure Interpret_file(const filename : TPathStr);
  53. procedure Read_Parameters;
  54. procedure parsecmd(cmd:TCmdStr);
  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:TCmdStr);
  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:TCmdStr);
  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: TCmdStr);
  414. begin
  415. Message1(option_unsupported_target,opt);
  416. StopOptions(1);
  417. end;
  418. procedure toption.IgnoredPara(const opt: TCmdStr);
  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:TCmdStr;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,2147483647);
  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. 'y' :
  1291. If UnsetBool(More, j) then
  1292. exclude(init_settings.localswitches,cs_typed_addresses)
  1293. else
  1294. include(init_settings.localswitches,cs_typed_addresses);
  1295. '-' :
  1296. begin
  1297. init_settings.globalswitches:=init_settings.globalswitches - [cs_constructor_name,cs_support_exceptions,
  1298. cs_support_vectors,cs_load_fpcylix_unit];
  1299. init_settings.localswitches:=init_settings.localswitches - [cs_do_assertion,cs_do_inline, cs_ansistrings,
  1300. cs_typed_addresses];
  1301. init_settings.moduleswitches:=init_settings.moduleswitches - [cs_support_c_operators, cs_support_goto,
  1302. cs_support_macro];
  1303. end;
  1304. else
  1305. IllegalPara(opt);
  1306. end;
  1307. inc(j);
  1308. end;
  1309. end;
  1310. end;
  1311. 'T' :
  1312. begin
  1313. more:=Upper(More);
  1314. if paratarget=system_none then
  1315. begin
  1316. { remove old target define }
  1317. TargetOptions(false);
  1318. { load new target }
  1319. paratarget:=find_system_by_string(More);
  1320. if paratarget<>system_none then
  1321. set_target(paratarget)
  1322. else
  1323. IllegalPara(opt);
  1324. { set new define }
  1325. TargetOptions(true);
  1326. end
  1327. else
  1328. if More<>upper(target_info.shortname) then
  1329. Message1(option_target_is_already_set,target_info.shortname);
  1330. end;
  1331. 'u' :
  1332. if more <> '' then
  1333. undef_system_macro(more);
  1334. 'U' :
  1335. begin
  1336. j:=1;
  1337. while j<=length(more) do
  1338. begin
  1339. case more[j] of
  1340. {$ifdef UNITALIASES}
  1341. 'a' :
  1342. begin
  1343. AddUnitAlias(Copy(More,j+1,255));
  1344. break;
  1345. end;
  1346. {$endif UNITALIASES}
  1347. 'n' :
  1348. exclude(init_settings.globalswitches,cs_check_unit_name);
  1349. 'p' :
  1350. begin
  1351. Message2(option_obsolete_switch_use_new,'-Up','-Fu');
  1352. break;
  1353. end;
  1354. 'r' :
  1355. do_release:=true;
  1356. 's' :
  1357. include(init_settings.moduleswitches,cs_compilesystem);
  1358. '-' :
  1359. begin
  1360. exclude(init_settings.moduleswitches,cs_compilesystem);
  1361. exclude(init_settings.globalswitches,cs_check_unit_name);
  1362. end;
  1363. else
  1364. IllegalPara(opt);
  1365. end;
  1366. inc(j);
  1367. end;
  1368. end;
  1369. 'v' :
  1370. begin
  1371. if not setverbosity(More) then
  1372. IllegalPara(opt);
  1373. end;
  1374. 'V' : ; { Ignore used by fpc }
  1375. 'W' :
  1376. begin
  1377. j:=1;
  1378. while j<=length(More) do
  1379. begin
  1380. case More[j] of
  1381. 'A':
  1382. begin
  1383. if UnsetBool(More, j) then
  1384. apptype:=app_native
  1385. else
  1386. apptype:=app_cui;
  1387. end;
  1388. 'b':
  1389. begin
  1390. if (target_info.system in systems_darwin) then
  1391. begin
  1392. if not UnsetBool(More, j) then
  1393. apptype:=app_bundle
  1394. else
  1395. apptype:=app_cui
  1396. end
  1397. else
  1398. IllegalPara(opt);
  1399. end;
  1400. 'B':
  1401. begin
  1402. { -WB200000 means set trefered base address
  1403. to $200000, but does not change relocsection boolean
  1404. this way we can create both relocatble and
  1405. non relocatable DLL at a specific base address PM }
  1406. if (length(More)>j) then
  1407. begin
  1408. val('$'+Copy(More,j+1,255),imagebase,code);
  1409. if code<>0 then
  1410. IllegalPara(opt);
  1411. ImageBaseSetExplicity:=true;
  1412. end
  1413. else
  1414. begin
  1415. RelocSection:=true;
  1416. RelocSectionSetExplicitly:=true;
  1417. end;
  1418. break;
  1419. end;
  1420. 'C':
  1421. begin
  1422. if UnsetBool(More, j) then
  1423. apptype:=app_gui
  1424. else
  1425. apptype:=app_cui;
  1426. end;
  1427. 'D':
  1428. begin
  1429. UseDeffileForExports:=not UnsetBool(More, j);
  1430. UseDeffileForExportsSetExplicitly:=true;
  1431. end;
  1432. 'e':
  1433. begin
  1434. if (target_info.system in systems_darwin) then
  1435. begin
  1436. RegisterRes(res_macosx_ext_info,TWinLikeResourceFile);
  1437. set_target_res(res_ext);
  1438. target_info.resobjext:='.fpcres';
  1439. end
  1440. else
  1441. IllegalPara(opt);
  1442. end;
  1443. 'F':
  1444. begin
  1445. if UnsetBool(More, j) then
  1446. apptype:=app_cui
  1447. else
  1448. apptype:=app_fs;
  1449. end;
  1450. 'G':
  1451. begin
  1452. if UnsetBool(More, j) then
  1453. apptype:=app_cui
  1454. else
  1455. apptype:=app_gui;
  1456. end;
  1457. 'I':
  1458. begin
  1459. GenerateImportSection:=not UnsetBool(More,j);
  1460. GenerateImportSectionSetExplicitly:=true;
  1461. end;
  1462. 'i':
  1463. begin
  1464. if (target_info.system in systems_darwin) then
  1465. begin
  1466. set_target_res(res_macho);
  1467. target_info.resobjext:=
  1468. targetinfos[target_info.system]^.resobjext;
  1469. end
  1470. else
  1471. IllegalPara(opt);
  1472. end;
  1473. 'N':
  1474. begin
  1475. RelocSection:=UnsetBool(More,j);
  1476. RelocSectionSetExplicitly:=true;
  1477. end;
  1478. 'p':
  1479. begin
  1480. {$if defined(arm) or defined(avr)}
  1481. if (target_info.system in systems_embedded) then
  1482. begin
  1483. s:=upper(copy(more,j+1,length(more)-j));
  1484. if not(SetControllerType(s,init_settings.controllertype)) then
  1485. IllegalPara(opt);
  1486. break;
  1487. end
  1488. else
  1489. {$endif defined(arm) or defined(avr)}
  1490. IllegalPara(opt);
  1491. end;
  1492. 'R':
  1493. begin
  1494. { support -WR+ / -WR- as synonyms to -WR / -WN }
  1495. RelocSection:=not UnsetBool(More,j);
  1496. RelocSectionSetExplicitly:=true;
  1497. end;
  1498. 'T':
  1499. begin
  1500. if UnsetBool(More, j) then
  1501. apptype:=app_cui
  1502. else
  1503. apptype:=app_tool;
  1504. end;
  1505. 'X':
  1506. begin
  1507. if (target_info.system in systems_linux) then
  1508. begin
  1509. if UnsetBool(More, j) then
  1510. exclude(init_settings.moduleswitches,cs_executable_stack)
  1511. else
  1512. include(init_settings.moduleswitches,cs_executable_stack)
  1513. end
  1514. else
  1515. IllegalPara(opt);
  1516. end
  1517. else
  1518. IllegalPara(opt);
  1519. end;
  1520. inc(j);
  1521. end;
  1522. end;
  1523. 'X' :
  1524. begin
  1525. j:=1;
  1526. while j<=length(more) do
  1527. begin
  1528. case More[j] of
  1529. 'c' : Cshared:=TRUE;
  1530. 'd' : Dontlinkstdlibpath:=TRUE;
  1531. 'e' :
  1532. begin
  1533. If UnsetBool(More, j) then
  1534. exclude(init_settings.globalswitches,cs_link_extern)
  1535. else
  1536. include(init_settings.globalswitches,cs_link_extern);
  1537. end;
  1538. 'f' :
  1539. include(init_settings.globalswitches,cs_link_pthread);
  1540. 'g' :
  1541. begin
  1542. If UnsetBool(More, j) then
  1543. exclude(init_settings.globalswitches,cs_link_separate_dbg_file)
  1544. else
  1545. include(init_settings.globalswitches,cs_link_separate_dbg_file);
  1546. end;
  1547. 'i' :
  1548. begin
  1549. If UnsetBool(More, j) then
  1550. include(init_settings.globalswitches,cs_link_extern)
  1551. else
  1552. exclude(init_settings.globalswitches,cs_link_extern);
  1553. end;
  1554. 'n' :
  1555. begin
  1556. If UnsetBool(More, j) then
  1557. exclude(init_settings.globalswitches,cs_link_native)
  1558. else
  1559. include(init_settings.globalswitches,cs_link_native);
  1560. end;
  1561. 'm' :
  1562. begin
  1563. If UnsetBool(More, j) then
  1564. exclude(init_settings.globalswitches,cs_link_map)
  1565. else
  1566. include(init_settings.globalswitches,cs_link_map);
  1567. end;
  1568. 'p' : ; { Ignore used by fpc.pp }
  1569. 'r' :
  1570. begin
  1571. if (target_info.system in suppported_targets_x_smallr) then
  1572. begin
  1573. rlinkpath:=Copy(more,2,length(More)-1);
  1574. DefaultReplacements(rlinkpath);
  1575. end
  1576. else
  1577. IgnoredPara('-Xr');
  1578. more:='';
  1579. end;
  1580. 'R' :
  1581. begin
  1582. sysrootpath:=copy(more,2,length(more)-1);
  1583. defaultreplacements(sysrootpath);
  1584. more:='';
  1585. end;
  1586. 's' :
  1587. begin
  1588. If UnsetBool(More, j) then
  1589. exclude(init_settings.globalswitches,cs_link_strip)
  1590. else
  1591. include(init_settings.globalswitches,cs_link_strip);
  1592. end;
  1593. 't' :
  1594. include(init_settings.globalswitches,cs_link_staticflag);
  1595. 'v' :
  1596. begin
  1597. If UnsetBool(More, j) then
  1598. exclude(init_settings.globalswitches,cs_link_opt_vtable)
  1599. else
  1600. include(init_settings.globalswitches,cs_link_opt_vtable);
  1601. end;
  1602. 'D' :
  1603. begin
  1604. def_system_macro('FPC_LINK_DYNAMIC');
  1605. undef_system_macro('FPC_LINK_SMART');
  1606. undef_system_macro('FPC_LINK_STATIC');
  1607. exclude(init_settings.globalswitches,cs_link_static);
  1608. exclude(init_settings.globalswitches,cs_link_smart);
  1609. include(init_settings.globalswitches,cs_link_shared);
  1610. LinkTypeSetExplicitly:=true;
  1611. end;
  1612. 'M' :
  1613. begin
  1614. mainaliasname:=Copy(more,2,length(More)-1);
  1615. More:='';
  1616. end;
  1617. 'P' :
  1618. begin
  1619. utilsprefix:=Copy(more,2,length(More)-1);
  1620. DefaultReplacements(utilsprefix);
  1621. More:='';
  1622. end;
  1623. 'L' : begin // -XLO is link order -XLA is link alias. -XLD avoids load defaults.
  1624. // these are not aggregable.
  1625. if (j=length(more)) or not (more[j+1] in ['O','A','D']) then
  1626. IllegalPara(opt)
  1627. else
  1628. begin
  1629. case more[j+1] of
  1630. 'A' : begin
  1631. s:=Copy(more,3,length(More)-2);
  1632. if not LinkLibraryAliases.AddDep(s) Then
  1633. IllegalPara(opt);
  1634. end;
  1635. 'O' : begin
  1636. s:=Copy(more,3,length(More)-2);
  1637. if not LinkLibraryOrder.AddWeight(s) Then
  1638. IllegalPara(opt);
  1639. end;
  1640. 'D' : include(init_settings.globalswitches,cs_link_no_default_lib_order)
  1641. else
  1642. IllegalPara(opt);
  1643. end; {case}
  1644. j:=length(more);
  1645. end; {else begin}
  1646. end;
  1647. 'S' :
  1648. begin
  1649. ForceStaticLinking;
  1650. end;
  1651. 'X' :
  1652. begin
  1653. def_system_macro('FPC_LINK_SMART');
  1654. undef_system_macro('FPC_LINK_STATIC');
  1655. undef_system_macro('FPC_LINK_DYNAMIC');
  1656. exclude(init_settings.globalswitches,cs_link_static);
  1657. include(init_settings.globalswitches,cs_link_smart);
  1658. exclude(init_settings.globalswitches,cs_link_shared);
  1659. LinkTypeSetExplicitly:=true;
  1660. end;
  1661. '-' :
  1662. begin
  1663. exclude(init_settings.globalswitches,cs_link_staticflag);
  1664. exclude(init_settings.globalswitches,cs_link_strip);
  1665. exclude(init_settings.globalswitches,cs_link_map);
  1666. set_default_link_type;
  1667. end;
  1668. else
  1669. IllegalPara(opt);
  1670. end;
  1671. inc(j);
  1672. end;
  1673. end;
  1674. else
  1675. IllegalPara(opt);
  1676. end;
  1677. end;
  1678. '@' :
  1679. begin
  1680. Message(option_no_nested_response_file);
  1681. StopOptions(1);
  1682. end;
  1683. else
  1684. begin
  1685. if (length(param_file)<>0) then
  1686. Message2(option_only_one_source_support,param_file,opt);
  1687. param_file:=opt;
  1688. Message1(option_found_file,opt);
  1689. end;
  1690. end;
  1691. end;
  1692. procedure Toption.Interpret_file(const filename : TPathStr);
  1693. procedure RemoveSep(var fn:TPathStr);
  1694. var
  1695. i : longint;
  1696. begin
  1697. i:=0;
  1698. while (i<length(fn)) and (fn[i+1] in [',',' ',#9]) do
  1699. inc(i);
  1700. Delete(fn,1,i);
  1701. i:=length(fn);
  1702. while (i>0) and (fn[i] in [',',' ',#9]) do
  1703. dec(i);
  1704. fn:=copy(fn,1,i);
  1705. end;
  1706. function GetName(var fn:TPathStr):TPathStr;
  1707. var
  1708. i : longint;
  1709. begin
  1710. i:=0;
  1711. while (i<length(fn)) and (fn[i+1] in ['a'..'z','A'..'Z','0'..'9','_','-']) do
  1712. inc(i);
  1713. GetName:=Copy(fn,1,i);
  1714. Delete(fn,1,i);
  1715. end;
  1716. const
  1717. maxlevel = 15;
  1718. var
  1719. f : text;
  1720. s, tmp,
  1721. opts : TCmdStr;
  1722. skip : array[0..maxlevel] of boolean;
  1723. line,
  1724. level : longint;
  1725. option_read : boolean;
  1726. begin
  1727. { avoid infinite loop }
  1728. Inc(FileLevel);
  1729. Option_read:=false;
  1730. If FileLevel>MaxLevel then
  1731. Message(option_too_many_cfg_files);
  1732. { Maybe It's Directory ?} //Jaro Change:
  1733. if PathExists(filename,false) then
  1734. begin
  1735. Message1(option_config_is_dir,filename);
  1736. exit;
  1737. end;
  1738. { open file }
  1739. Message1(option_using_file,filename);
  1740. assign(f,ExpandFileName(filename));
  1741. {$I-}
  1742. reset(f);
  1743. {$I+}
  1744. if ioresult<>0 then
  1745. begin
  1746. Message1(option_unable_open_file,filename);
  1747. exit;
  1748. end;
  1749. Message1(option_start_reading_configfile,filename);
  1750. fillchar(skip,sizeof(skip),0);
  1751. level:=0;
  1752. line:=0;
  1753. while not eof(f) do
  1754. begin
  1755. readln(f,opts);
  1756. inc(line);
  1757. RemoveSep(opts);
  1758. if (opts<>'') and (opts[1]<>';') then
  1759. begin
  1760. if opts[1]='#' then
  1761. begin
  1762. Message1(option_interpreting_file_option,opts);
  1763. Delete(opts,1,1);
  1764. s:=upper(GetName(opts));
  1765. if (s='SECTION') then
  1766. begin
  1767. RemoveSep(opts);
  1768. s:=upper(GetName(opts));
  1769. if level=0 then
  1770. skip[level]:=not defined_macro(s) or (s='COMMON');
  1771. end
  1772. else
  1773. if (s='IFDEF') then
  1774. begin
  1775. RemoveSep(opts);
  1776. if Level>=maxlevel then
  1777. begin
  1778. Message2(option_too_many_ifdef,filename,tostr(line));
  1779. stopOptions(1);
  1780. end;
  1781. inc(Level);
  1782. skip[level]:=(skip[level-1] or not defined_macro(upper(GetName(opts))));
  1783. end
  1784. else
  1785. if (s='IFNDEF') then
  1786. begin
  1787. RemoveSep(opts);
  1788. if Level>=maxlevel then
  1789. begin
  1790. Message2(option_too_many_ifdef,filename,tostr(line));
  1791. stopOptions(1);
  1792. end;
  1793. inc(Level);
  1794. skip[level]:=(skip[level-1] or defined_macro(upper(GetName(opts))));
  1795. end
  1796. else
  1797. if (s='ELSE') then
  1798. begin
  1799. if Level=0 then
  1800. begin
  1801. Message2(option_else_without_if,filename,tostr(line));
  1802. stopOptions(1);
  1803. end
  1804. else
  1805. skip[level]:=skip[level-1] or (not skip[level])
  1806. end
  1807. else
  1808. if (s='ENDIF') then
  1809. begin
  1810. skip[level]:=false;
  1811. if Level=0 then
  1812. begin
  1813. Message2(option_too_many_endif,filename,tostr(line));
  1814. stopOptions(1);
  1815. end;
  1816. dec(level);
  1817. end
  1818. else
  1819. if (not skip[level]) then
  1820. begin
  1821. if (s='DEFINE') then
  1822. begin
  1823. RemoveSep(opts);
  1824. tmp:= GetName(opts);
  1825. if tmp <> '' then
  1826. def_system_macro(tmp);
  1827. end
  1828. else
  1829. if (s='UNDEF') then
  1830. begin
  1831. RemoveSep(opts);
  1832. tmp:= GetName(opts);
  1833. if tmp <> '' then
  1834. undef_system_macro(tmp);
  1835. end
  1836. else
  1837. if (s='WRITE') then
  1838. begin
  1839. Delete(opts,1,1);
  1840. WriteLn(opts);
  1841. end
  1842. else
  1843. if (s='INCLUDE') then
  1844. begin
  1845. Delete(opts,1,1);
  1846. Interpret_file(opts);
  1847. end;
  1848. end;
  1849. end
  1850. else
  1851. begin
  1852. if (opts[1]='-') or (opts[1]='@') then
  1853. begin
  1854. if (not skip[level]) then
  1855. interpret_option(opts,false);
  1856. Option_read:=true;
  1857. end
  1858. else
  1859. Message1(option_illegal_para,opts);
  1860. end;
  1861. end;
  1862. end;
  1863. if Level>0 then
  1864. Message(option_too_less_endif);
  1865. if Not Option_read then
  1866. Message1(option_no_option_found,filename)
  1867. else
  1868. Message1(option_end_reading_configfile,filename);
  1869. Close(f);
  1870. Dec(FileLevel);
  1871. end;
  1872. procedure Toption.Interpret_envvar(const envname : TCmdStr);
  1873. var
  1874. argstart,
  1875. env,
  1876. pc : pchar;
  1877. arglen : longint;
  1878. quote : set of char;
  1879. hs : TCmdStr;
  1880. begin
  1881. Message1(option_using_env,envname);
  1882. env:=GetEnvPChar(envname);
  1883. pc:=env;
  1884. if assigned(pc) then
  1885. begin
  1886. repeat
  1887. { skip leading spaces }
  1888. while pc^ in [' ',#9,#13] do
  1889. inc(pc);
  1890. case pc^ of
  1891. #0 :
  1892. break;
  1893. '"' :
  1894. begin
  1895. quote:=['"'];
  1896. inc(pc);
  1897. end;
  1898. '''' :
  1899. begin
  1900. quote:=[''''];
  1901. inc(pc);
  1902. end;
  1903. else
  1904. quote:=[' ',#9,#13];
  1905. end;
  1906. { scan until the end of the argument }
  1907. argstart:=pc;
  1908. while (pc^<>#0) and not(pc^ in quote) do
  1909. inc(pc);
  1910. { create argument }
  1911. arglen:=pc-argstart;
  1912. { TODO: FIXME: silent truncation of environment parameters }
  1913. if (arglen > 255) then
  1914. arglen := 255;
  1915. setlength(hs,arglen);
  1916. move(argstart^,hs[1],arglen);
  1917. interpret_option(hs,true);
  1918. { skip quote }
  1919. if pc^ in quote then
  1920. inc(pc);
  1921. until false;
  1922. end
  1923. else
  1924. Message1(option_no_option_found,'(env) '+envname);
  1925. FreeEnvPChar(env);
  1926. end;
  1927. procedure toption.read_parameters;
  1928. var
  1929. opts : TCmdStr;
  1930. paramindex : longint;
  1931. begin
  1932. paramindex:=0;
  1933. while paramindex<paramcount do
  1934. begin
  1935. inc(paramindex);
  1936. opts:=objpas.paramstr(paramindex);
  1937. case opts[1] of
  1938. '@' :
  1939. if not firstpass then
  1940. begin
  1941. Delete(opts,1,1);
  1942. Message1(option_reading_further_from,opts);
  1943. interpret_file(opts);
  1944. end;
  1945. '!' :
  1946. if not firstpass then
  1947. begin
  1948. Delete(opts,1,1);
  1949. Message1(option_reading_further_from,'(env) '+opts);
  1950. interpret_envvar(opts);
  1951. end;
  1952. else
  1953. interpret_option(opts,true);
  1954. end;
  1955. end;
  1956. end;
  1957. procedure toption.parsecmd(cmd:TCmdStr);
  1958. var
  1959. i,ps : longint;
  1960. opts : TCmdStr;
  1961. begin
  1962. while (cmd<>'') do
  1963. begin
  1964. while cmd[1]=' ' do
  1965. delete(cmd,1,1);
  1966. i:=pos(' ',cmd);
  1967. if i=0 then
  1968. i:=2147483647;
  1969. opts:=Copy(cmd,1,i-1);
  1970. Delete(cmd,1,i);
  1971. case opts[1] of
  1972. '@' :
  1973. if not firstpass then
  1974. begin
  1975. Delete(opts,1,1);
  1976. Message1(option_reading_further_from,opts);
  1977. interpret_file(opts);
  1978. end;
  1979. '!' :
  1980. if not firstpass then
  1981. begin
  1982. Delete(opts,1,1);
  1983. Message1(option_reading_further_from,'(env) '+opts);
  1984. interpret_envvar(opts);
  1985. end;
  1986. '"' :
  1987. begin
  1988. Delete(opts,1,1);
  1989. ps:=pos('"',cmd);
  1990. if (i<>256) and (ps>0) then
  1991. begin
  1992. opts:=opts + ' '+ copy(cmd,1,ps-1);
  1993. cmd:=copy(cmd,ps+1,255);
  1994. end;
  1995. interpret_option(opts,true);
  1996. end;
  1997. else
  1998. interpret_option(opts,true);
  1999. end;
  2000. end;
  2001. end;
  2002. procedure toption.writequickinfo;
  2003. var
  2004. s : string;
  2005. i : longint;
  2006. procedure addinfo(const hs:string);
  2007. begin
  2008. if s<>'' then
  2009. s:=s+' '+hs
  2010. else
  2011. s:=hs;
  2012. end;
  2013. begin
  2014. s:='';
  2015. i:=0;
  2016. while (i<length(quickinfo)) do
  2017. begin
  2018. inc(i);
  2019. case quickinfo[i] of
  2020. 'S' :
  2021. begin
  2022. inc(i);
  2023. case quickinfo[i] of
  2024. 'O' :
  2025. addinfo(lower(source_info.shortname));
  2026. 'P' :
  2027. addinfo(source_cpu_string);
  2028. else
  2029. IllegalPara('-i'+QuickInfo);
  2030. end;
  2031. end;
  2032. 'T' :
  2033. begin
  2034. inc(i);
  2035. case quickinfo[i] of
  2036. 'O' :
  2037. addinfo(lower(target_info.shortname));
  2038. 'P' :
  2039. AddInfo(target_cpu_string);
  2040. else
  2041. IllegalPara('-i'+QuickInfo);
  2042. end;
  2043. end;
  2044. 'V' :
  2045. AddInfo(version_string);
  2046. 'W' :
  2047. AddInfo(full_version_string);
  2048. 'D' :
  2049. AddInfo(date_string);
  2050. '_' :
  2051. ;
  2052. else
  2053. IllegalPara('-i'+QuickInfo);
  2054. end;
  2055. end;
  2056. if s<>'' then
  2057. begin
  2058. writeln(s);
  2059. stopoptions(0);
  2060. end;
  2061. end;
  2062. procedure TOption.TargetOptions(def:boolean);
  2063. var
  2064. s : string;
  2065. i : integer;
  2066. target_unsup_features : tfeatures;
  2067. begin
  2068. if def then
  2069. def_system_macro(target_info.shortname)
  2070. else
  2071. undef_system_macro(target_info.shortname);
  2072. s:=target_info.extradefines;
  2073. while (s<>'') do
  2074. begin
  2075. i:=pos(';',s);
  2076. if i=0 then
  2077. i:=length(s)+1;
  2078. if def then
  2079. def_system_macro(Copy(s,1,i-1))
  2080. else
  2081. undef_system_macro(Copy(s,1,i-1));
  2082. delete(s,1,i);
  2083. end;
  2084. if (tf_winlikewidestring in target_info.flags) then
  2085. if def then
  2086. def_system_macro('FPC_WINLIKEWIDESTRING')
  2087. else
  2088. undef_system_macro('FPC_WINLIKEWIDESTRING');
  2089. if (tf_requires_proper_alignment in target_info.flags) then
  2090. if def then
  2091. def_system_macro('FPC_REQUIRES_PROPER_ALIGNMENT')
  2092. else
  2093. undef_system_macro('FPC_REQUIRES_PROPER_ALIGNMENT');
  2094. if source_info.system<>target_info.system then
  2095. if def then
  2096. def_system_macro('FPC_CROSSCOMPILING')
  2097. else
  2098. undef_system_macro('FPC_CROSSCOMPILING');
  2099. if source_info.cpu<>target_info.cpu then
  2100. if def then
  2101. def_system_macro('FPC_CPUCROSSCOMPILING')
  2102. else
  2103. def_system_macro('FPC_CPUCROSSCOMPILING');
  2104. if (tf_no_generic_stackcheck in target_info.flags) then
  2105. if def then
  2106. def_system_macro('FPC_NO_GENERIC_STACK_CHECK')
  2107. else
  2108. undef_system_macro('FPC_NO_GENERIC_STACK_CHECK');
  2109. { Code generation flags }
  2110. if def and
  2111. (tf_pic_default in target_info.flags) then
  2112. include(init_settings.moduleswitches,cs_create_pic)
  2113. else
  2114. exclude(init_settings.moduleswitches,cs_create_pic);
  2115. { Resources support }
  2116. if (tf_has_winlike_resources in target_info.flags) then
  2117. if def then
  2118. def_system_macro('FPC_HAS_WINLIKERESOURCES')
  2119. else
  2120. undef_system_macro('FPC_HAS_WINLIKERESOURCES');
  2121. { Features }
  2122. case target_info.system of
  2123. system_arm_gba:
  2124. target_unsup_features:=[f_threading,f_commandargs,f_fileio,f_textio,f_consoleio,f_dynlibs];
  2125. system_arm_nds:
  2126. target_unsup_features:=[f_threading,f_commandargs,f_fileio,f_textio,f_consoleio,f_dynlibs];
  2127. system_i386_nativent:
  2128. // until these features are implemented, they are disabled in the compiler
  2129. target_unsup_features:=[f_stackcheck];
  2130. else
  2131. target_unsup_features:=[];
  2132. end;
  2133. if def then
  2134. features:=features-target_unsup_features
  2135. else
  2136. features:=features+target_unsup_features;
  2137. end;
  2138. procedure TOption.checkoptionscompatibility;
  2139. begin
  2140. if (paratargetdbg in [dbg_dwarf2,dbg_dwarf3]) and
  2141. not(target_info.system in systems_darwin) then
  2142. begin
  2143. { smart linking does not yet work with DWARF debug info on most targets }
  2144. if (cs_link_smart in init_settings.globalswitches) then
  2145. begin
  2146. Message(option_dwarf_smart_linking);
  2147. ForceStaticLinking;
  2148. end;
  2149. end;
  2150. { external debug info is only supported for DWARF on darwin }
  2151. if (target_info.system in systems_darwin) and
  2152. (cs_link_separate_dbg_file in init_settings.globalswitches) and
  2153. not(paratargetdbg in [dbg_dwarf2,dbg_dwarf3]) then
  2154. begin
  2155. Message(option_debug_external_unsupported);
  2156. exclude(init_settings.globalswitches,cs_link_separate_dbg_file);
  2157. end;
  2158. end;
  2159. constructor TOption.create;
  2160. begin
  2161. LogoWritten:=false;
  2162. NoPressEnter:=false;
  2163. FirstPass:=false;
  2164. FPUSetExplicitly:=false;
  2165. CPUSetExplicitly:=false;
  2166. OptCPUSetExplicitly:=false;
  2167. FileLevel:=0;
  2168. Quickinfo:='';
  2169. ParaIncludePath:=TSearchPathList.Create;
  2170. ParaObjectPath:=TSearchPathList.Create;
  2171. ParaUnitPath:=TSearchPathList.Create;
  2172. ParaLibraryPath:=TSearchPathList.Create;
  2173. ParaFrameworkPath:=TSearchPathList.Create;
  2174. FillChar(ParaAlignment,sizeof(ParaAlignment),0);
  2175. end;
  2176. destructor TOption.destroy;
  2177. begin
  2178. ParaIncludePath.Free;
  2179. ParaObjectPath.Free;
  2180. ParaUnitPath.Free;
  2181. ParaLibraryPath.Free;
  2182. ParaFrameworkPath.Free;
  2183. end;
  2184. {****************************************************************************
  2185. Callable Routines
  2186. ****************************************************************************}
  2187. function check_configfile(const fn:string;var foundfn:string):boolean;
  2188. function CfgFileExists(const fn:string):boolean;
  2189. begin
  2190. Comment(V_Tried,'Configfile search: '+fn);
  2191. CfgFileExists:=FileExists(fn);
  2192. end;
  2193. var
  2194. {$ifdef Unix}
  2195. hs,
  2196. {$endif Unix}
  2197. configpath : string;
  2198. begin
  2199. foundfn:=fn;
  2200. check_configfile:=true;
  2201. { retrieve configpath }
  2202. configpath:=FixPath(GetEnvironmentVariable('PPC_CONFIG_PATH'),false);
  2203. {$ifdef Unix}
  2204. if configpath='' then
  2205. configpath:=ExpandFileName(FixPath(exepath+'../etc/',false));
  2206. {$endif}
  2207. {
  2208. Order to read configuration file :
  2209. try reading fpc.cfg in :
  2210. 1 - current dir
  2211. 2 - configpath
  2212. 3 - compiler path
  2213. }
  2214. if not FileExists(fn) then
  2215. begin
  2216. {$ifdef Unix}
  2217. hs:=GetEnvironmentVariable('HOME');
  2218. if (hs<>'') and CfgFileExists(FixPath(hs,false)+'.'+fn) then
  2219. foundfn:=FixPath(hs,false)+'.'+fn
  2220. else
  2221. {$endif}
  2222. if CfgFileExists(configpath+fn) then
  2223. foundfn:=configpath+fn
  2224. else
  2225. {$ifndef Unix}
  2226. if CfgFileExists(exepath+fn) then
  2227. foundfn:=exepath+fn
  2228. else
  2229. {$else}
  2230. if CfgFileExists('/etc/'+fn) then
  2231. foundfn:='/etc/'+fn
  2232. else
  2233. {$endif}
  2234. check_configfile:=false;
  2235. end;
  2236. end;
  2237. procedure read_arguments(cmd:TCmdStr);
  2238. var
  2239. env: ansistring;
  2240. i : tfeature;
  2241. abi : tabi;
  2242. begin
  2243. option:=coption.create;
  2244. disable_configfile:=false;
  2245. { Non-core target defines }
  2246. Option.TargetOptions(true);
  2247. { get default messagefile }
  2248. msgfilename:=GetEnvironmentVariable('PPC_ERROR_FILE');
  2249. { default configfile can be specified on the commandline,
  2250. remove it first }
  2251. if (cmd<>'') and (cmd[1]='[') then
  2252. begin
  2253. ppccfg:=Copy(cmd,2,pos(']',cmd)-2);
  2254. Delete(cmd,1,pos(']',cmd));
  2255. end
  2256. else
  2257. ppccfg:='fpc.cfg';
  2258. { first pass reading of parameters, only -i -v -T etc.}
  2259. option.firstpass:=true;
  2260. if cmd<>'' then
  2261. option.parsecmd(cmd)
  2262. else
  2263. begin
  2264. option.read_parameters;
  2265. { Write only quickinfo }
  2266. if option.quickinfo<>'' then
  2267. option.writequickinfo;
  2268. end;
  2269. option.firstpass:=false;
  2270. { target is set here, for wince the default app type is gui }
  2271. if target_info.system in systems_wince then
  2272. apptype:=app_gui;
  2273. { default defines }
  2274. def_system_macro(target_info.shortname);
  2275. def_system_macro('FPC');
  2276. def_system_macro('VER'+version_nr);
  2277. def_system_macro('VER'+version_nr+'_'+release_nr);
  2278. def_system_macro('VER'+version_nr+'_'+release_nr+'_'+patch_nr);
  2279. { Temporary defines, until things settle down }
  2280. def_system_macro('RESSTRSECTIONS');
  2281. def_system_macro('FPC_HASFIXED64BITVARIANT');
  2282. def_system_macro('FPC_HASINTERNALOLEVARIANT2VARIANTCAST');
  2283. def_system_macro('FPC_HAS_VARSETS');
  2284. def_system_macro('FPC_HAS_VALGRINDBOOL');
  2285. def_system_macro('FPC_HAS_STR_CURRENCY');
  2286. def_system_macro('FPC_REAL2REAL_FIXED');
  2287. def_system_macro('FPC_STRTOCHARARRAYPROC');
  2288. def_system_macro('FPC_STRTOSHORTSTRINGPROC');
  2289. def_system_macro('FPC_OBJFPC_EXTENDED_IF');
  2290. def_system_macro('FPC_HAS_OPERATOR_ENUMERATOR');
  2291. def_system_macro('FPC_HAS_CONSTREF');
  2292. def_system_macro('FPC_STATICRIPFIXED');
  2293. {$if defined(x86) or defined(powerpc) or defined(powerpc64)}
  2294. def_system_macro('FPC_HAS_INTERNAL_ABS_LONG');
  2295. {$endif}
  2296. def_system_macro('FPC_HAS_UNICODESTRING');
  2297. def_system_macro('FPC_RTTI_PACKSET1');
  2298. {$ifdef x86_64}
  2299. def_system_macro('FPC_HAS_RIP_RELATIVE');
  2300. {$endif x86_64}
  2301. def_system_macro('FPC_HAS_CEXTENDED');
  2302. { these cpus have an inline rol/ror implementaion }
  2303. {$if defined(x86) or defined(arm) or defined(powerpc) or defined(powerpc64)}
  2304. def_system_macro('FPC_HAS_INTERNAL_ROX');
  2305. {$endif}
  2306. { these cpus have an inline sar implementaion }
  2307. { currently, all supported CPUs have an internal sar implementation }
  2308. { $if defined(x86) or defined(arm) or defined(powerpc) or defined(powerpc64) or defined(sparc)}
  2309. def_system_macro('FPC_HAS_INTERNAL_SAR');
  2310. { $endif}
  2311. { inline bsf/bsr implementation }
  2312. {$if defined(x86) or defined(x86_64)}
  2313. def_system_macro('FPC_HAS_INTERNAL_BSX');
  2314. {$endif}
  2315. {$ifdef powerpc64}
  2316. def_system_macro('FPC_HAS_LWSYNC');
  2317. {$endif}
  2318. def_system_macro('FPC_HAS_MEMBAR');
  2319. def_system_macro('FPC_SETBASE_USED');
  2320. {$if defined(x86) or defined(arm)}
  2321. def_system_macro('INTERNAL_BACKTRACE');
  2322. {$endif}
  2323. def_system_macro('STR_CONCAT_PROCS');
  2324. {$warnings off}
  2325. if pocall_default = pocall_register then
  2326. def_system_macro('REGCALL');
  2327. {$warnings on}
  2328. { don't remove this, it's also for fpdoc necessary (FK) }
  2329. def_system_macro('FPC_HAS_FEATURE_SUPPORT');
  2330. { using a case is pretty useless here (FK) }
  2331. { some stuff for TP compatibility }
  2332. {$ifdef i386}
  2333. def_system_macro('CPU86');
  2334. def_system_macro('CPU87');
  2335. def_system_macro('CPU386');
  2336. {$endif}
  2337. { new processor stuff }
  2338. {$ifdef i386}
  2339. def_system_macro('CPUI386');
  2340. def_system_macro('CPU32');
  2341. def_system_macro('FPC_HAS_TYPE_EXTENDED');
  2342. def_system_macro('FPC_HAS_TYPE_DOUBLE');
  2343. def_system_macro('FPC_HAS_TYPE_SINGLE');
  2344. {$endif}
  2345. {$ifdef m68k}
  2346. def_system_macro('CPU68');
  2347. def_system_macro('CPU68K');
  2348. def_system_macro('CPUM68K');
  2349. def_system_macro('CPU32');
  2350. def_system_macro('FPC_CURRENCY_IS_INT64');
  2351. def_system_macro('FPC_COMP_IS_INT64');
  2352. {$endif}
  2353. {$ifdef ALPHA}
  2354. def_system_macro('CPUALPHA');
  2355. def_system_macro('CPU64');
  2356. {$endif}
  2357. {$ifdef powerpc}
  2358. def_system_macro('CPUPOWERPC');
  2359. def_system_macro('CPUPOWERPC32');
  2360. def_system_macro('CPU32');
  2361. def_system_macro('FPC_CURRENCY_IS_INT64');
  2362. def_system_macro('FPC_COMP_IS_INT64');
  2363. {$endif}
  2364. {$ifdef POWERPC64}
  2365. def_system_macro('CPUPOWERPC');
  2366. def_system_macro('CPUPOWERPC64');
  2367. def_system_macro('CPU64');
  2368. def_system_macro('FPC_CURRENCY_IS_INT64');
  2369. def_system_macro('FPC_COMP_IS_INT64');
  2370. {$endif}
  2371. {$ifdef iA64}
  2372. def_system_macro('CPUIA64');
  2373. def_system_macro('CPU64');
  2374. {$endif}
  2375. {$ifdef x86_64}
  2376. def_system_macro('CPUX86_64');
  2377. def_system_macro('CPUAMD64');
  2378. def_system_macro('CPU64');
  2379. { not supported for now, afaik (FK)
  2380. def_system_macro('FPC_HAS_TYPE_FLOAT128'); }
  2381. { win64 doesn't support the legacy fpu }
  2382. if target_info.system=system_x86_64_win64 then
  2383. begin
  2384. def_system_macro('FPC_CURRENCY_IS_INT64');
  2385. def_system_macro('FPC_COMP_IS_INT64');
  2386. end;
  2387. {$endif}
  2388. {$ifdef sparc}
  2389. def_system_macro('CPUSPARC');
  2390. def_system_macro('CPUSPARC32');
  2391. def_system_macro('CPU32');
  2392. def_system_macro('FPC_CURRENCY_IS_INT64');
  2393. def_system_macro('FPC_COMP_IS_INT64');
  2394. {$endif}
  2395. {$ifdef vis}
  2396. def_system_macro('CPUVIS');
  2397. def_system_macro('CPU32');
  2398. {$endif}
  2399. {$ifdef arm}
  2400. def_system_macro('CPUARM');
  2401. def_system_macro('CPU32');
  2402. def_system_macro('FPC_CURRENCY_IS_INT64');
  2403. def_system_macro('FPC_COMP_IS_INT64');
  2404. {$endif arm}
  2405. {$ifdef avr}
  2406. def_system_macro('CPUAVR');
  2407. def_system_macro('CPU16');
  2408. def_system_macro('FPC_CURRENCY_IS_INT64');
  2409. def_system_macro('FPC_COMP_IS_INT64');
  2410. {$endif avr}
  2411. { read configuration file }
  2412. if (not disable_configfile) and
  2413. (ppccfg<>'') then
  2414. read_configfile:=check_configfile(ppccfg,ppccfg)
  2415. else
  2416. read_configfile := false;
  2417. { Read commandline and configfile }
  2418. param_file:='';
  2419. { read configfile }
  2420. if read_configfile then
  2421. option.interpret_file(ppccfg);
  2422. { read parameters again to override config file }
  2423. if cmd<>'' then
  2424. option.parsecmd(cmd)
  2425. else
  2426. begin
  2427. { Write help pages if no parameters are passed }
  2428. if (paramcount=0) then
  2429. Option.WriteHelpPages;
  2430. option.read_parameters;
  2431. { Write only quickinfo }
  2432. if option.quickinfo<>'' then
  2433. option.writequickinfo;
  2434. end;
  2435. { check the compatibility of different options and adjust them if necessary
  2436. (and print possible errors)
  2437. }
  2438. option.checkoptionscompatibility;
  2439. { Stop if errors in options }
  2440. if ErrorCount>0 then
  2441. StopOptions(1);
  2442. { endian define }
  2443. case target_info.endian of
  2444. endian_little :
  2445. begin
  2446. def_system_macro('ENDIAN_LITTLE');
  2447. def_system_macro('FPC_LITTLE_ENDIAN');
  2448. end;
  2449. endian_big :
  2450. begin
  2451. def_system_macro('ENDIAN_BIG');
  2452. def_system_macro('FPC_BIG_ENDIAN');
  2453. end;
  2454. end;
  2455. { define abi }
  2456. for abi:=low(tabi) to high(tabi) do
  2457. undef_system_macro('FPC_ABI_'+abi2str[abi]);
  2458. def_system_macro('FPC_ABI_'+abi2str[target_info.abi]);
  2459. { Write logo }
  2460. if option.ParaLogo then
  2461. option.writelogo;
  2462. { Check file to compile }
  2463. if param_file='' then
  2464. begin
  2465. Message(option_no_source_found);
  2466. StopOptions(1);
  2467. end;
  2468. {$ifndef Unix}
  2469. param_file:=FixFileName(param_file);
  2470. {$endif not unix}
  2471. inputfilepath:=ExtractFilePath(param_file);
  2472. inputfilename:=ExtractFileName(param_file);
  2473. if ExtractFileExt(inputfilename)='' then
  2474. begin
  2475. if FileExists(inputfilepath+ChangeFileExt(inputfilename,sourceext)) then
  2476. inputfilename:=ChangeFileExt(inputfilename,sourceext)
  2477. else if FileExists(inputfilepath+ChangeFileExt(inputfilename,pasext)) then
  2478. inputfilename:=ChangeFileExt(inputfilename,pasext)
  2479. else if ((m_mac in current_settings.modeswitches) or
  2480. (tf_p_ext_support in target_info.flags))
  2481. and FileExists(inputfilepath+ChangeFileExt(inputfilename,pext)) then
  2482. inputfilename:=ChangeFileExt(inputfilename,pext);
  2483. end;
  2484. { Check output dir }
  2485. if (OutputExeDir<>'') and
  2486. not PathExists(OutputExeDir,false) then
  2487. begin
  2488. Message1(general_e_path_does_not_exist,OutputExeDir);
  2489. StopOptions(1);
  2490. end;
  2491. { Add paths specified with parameters to the searchpaths }
  2492. UnitSearchPath.AddList(option.ParaUnitPath,true);
  2493. ObjectSearchPath.AddList(option.ParaObjectPath,true);
  2494. IncludeSearchPath.AddList(option.ParaIncludePath,true);
  2495. LibrarySearchPath.AddList(option.ParaLibraryPath,true);
  2496. FrameworkSearchPath.AddList(option.ParaFrameworkPath,true);
  2497. { add unit environment and exepath to the unit search path }
  2498. if inputfilepath<>'' then
  2499. Unitsearchpath.AddPath(inputfilepath,true);
  2500. if not disable_configfile then
  2501. begin
  2502. env:=GetEnvironmentVariable(target_info.unit_env);
  2503. if env<>'' then
  2504. UnitSearchPath.AddPath(GetEnvironmentVariable(target_info.unit_env),false);
  2505. end;
  2506. {$ifdef Unix}
  2507. fpcdir:=FixPath(GetEnvironmentVariable('FPCDIR'),false);
  2508. if fpcdir='' then
  2509. begin
  2510. if PathExists('/usr/local/lib/fpc/'+version_string,true) then
  2511. fpcdir:='/usr/local/lib/fpc/'+version_string+'/'
  2512. else
  2513. fpcdir:='/usr/lib/fpc/'+version_string+'/';
  2514. end;
  2515. {$else unix}
  2516. fpcdir:=FixPath(GetEnvironmentVariable('FPCDIR'),false);
  2517. if fpcdir='' then
  2518. begin
  2519. fpcdir:=ExePath+'../';
  2520. if not(PathExists(fpcdir+'units',true)) and
  2521. not(PathExists(fpcdir+'rtl',true)) then
  2522. fpcdir:=fpcdir+'../';
  2523. end;
  2524. {$endif unix}
  2525. { first try development RTL, else use the default installation path }
  2526. if not disable_configfile then
  2527. begin
  2528. if PathExists(FpcDir+'rtl',true) then
  2529. if tf_use_8_3 in Source_Info.Flags then
  2530. UnitSearchPath.AddPath(FpcDir+'rtl/'+target_os_string,false)
  2531. else
  2532. UnitSearchPath.AddPath(FpcDir+'rtl/'+target_full_string,false)
  2533. else
  2534. if tf_use_8_3 in Source_Info.Flags then
  2535. UnitSearchPath.AddPath(FpcDir+'units/'+target_os_string+'/rtl',false)
  2536. else
  2537. UnitSearchPath.AddPath(FpcDir+'units/'+target_full_string+'/rtl',false);
  2538. end;
  2539. { Add exepath if the exe is not in the current dir, because that is always searched already.
  2540. Do not add it when linking on the target because then we can maybe already find
  2541. .o files that are not for the target }
  2542. if (ExePath<>GetCurrentDir) and
  2543. not(cs_link_on_target in init_settings.globalswitches) then
  2544. UnitSearchPath.AddPath(ExePath,false);
  2545. { Add unit dir to the object and library path }
  2546. objectsearchpath.AddList(unitsearchpath,false);
  2547. librarysearchpath.AddList(unitsearchpath,false);
  2548. { maybe override assembler }
  2549. if (paratargetasm<>as_none) then
  2550. begin
  2551. if not set_target_asm(paratargetasm) then
  2552. begin
  2553. Message2(option_incompatible_asm,asminfos[paratargetasm]^.idtxt,target_info.name);
  2554. set_target_asm(target_info.assemextern);
  2555. Message1(option_asm_forced,target_asm.idtxt);
  2556. end;
  2557. if (af_no_debug in asminfos[paratargetasm]^.flags) and
  2558. (paratargetdbg<>dbg_none) then
  2559. begin
  2560. Message1(option_confict_asm_debug,
  2561. asminfos[paratargetasm]^.idtxt);
  2562. paratargetdbg:=dbg_none;
  2563. exclude(init_settings.moduleswitches,cs_debuginfo);
  2564. end;
  2565. end;
  2566. { maybe override debug info format }
  2567. if (paratargetdbg<>dbg_none) then
  2568. set_target_dbg(paratargetdbg);
  2569. { switch assembler if it's binary and we got -a on the cmdline }
  2570. if (cs_asm_leave in init_settings.globalswitches) and
  2571. (af_outputbinary in target_asm.flags) then
  2572. begin
  2573. Message(option_switch_bin_to_src_assembler);
  2574. set_target_asm(target_info.assemextern);
  2575. end;
  2576. { Force use of external linker if there is no
  2577. internal linker or the linking is skipped }
  2578. if not(cs_link_extern in init_settings.globalswitches) and
  2579. (not assigned(target_info.link) or
  2580. (cs_link_nolink in init_settings.globalswitches)) then
  2581. include(init_settings.globalswitches,cs_link_extern);
  2582. { turn off stripping if compiling with debuginfo or profile }
  2583. if (
  2584. (cs_debuginfo in init_settings.moduleswitches) or
  2585. (cs_profile in init_settings.moduleswitches)
  2586. ) and
  2587. not(cs_link_separate_dbg_file in init_settings.globalswitches) then
  2588. exclude(init_settings.globalswitches,cs_link_strip);
  2589. { force fpu emulation on arm/wince, arm/gba, arm/embedded, arm/nds and
  2590. arm/darwin if fpu type not explicitly set }
  2591. if not(option.FPUSetExplicitly) and
  2592. ((target_info.system in [system_arm_wince,system_arm_gba,system_m68k_amiga,
  2593. system_m68k_linux,system_arm_nds,system_arm_embedded,system_arm_darwin])
  2594. {$ifdef arm}
  2595. or (target_info.abi=abi_eabi)
  2596. {$endif arm}
  2597. )
  2598. {$ifdef arm}
  2599. or (init_settings.fputype=fpu_soft)
  2600. {$endif arm}
  2601. then
  2602. begin
  2603. {$ifdef cpufpemu}
  2604. include(init_settings.moduleswitches,cs_fp_emulation);
  2605. { cs_fp_emulation and fpu_soft are equal on arm }
  2606. init_settings.fputype:=fpu_soft;
  2607. {$endif cpufpemu}
  2608. end;
  2609. {$ifdef arm}
  2610. { set default cpu type to ARMv6 for Darwin unless specified otherwise }
  2611. if (target_info.system=system_arm_darwin) then
  2612. begin
  2613. if not option.CPUSetExplicitly then
  2614. init_settings.cputype:=cpu_armv6;
  2615. if not option.OptCPUSetExplicitly then
  2616. init_settings.optimizecputype:=cpu_armv6;
  2617. end;
  2618. {$endif arm}
  2619. { now we can define cpu and fpu type }
  2620. def_system_macro('CPU'+Cputypestr[init_settings.cputype]);
  2621. def_system_macro('FPU'+fputypestr[init_settings.fputype]);
  2622. if init_settings.fputype<>fpu_none then
  2623. begin
  2624. {$if defined(i386)}
  2625. def_system_macro('FPC_HAS_TYPE_EXTENDED');
  2626. {$endif}
  2627. def_system_macro('FPC_HAS_TYPE_SINGLE');
  2628. def_system_macro('FPC_HAS_TYPE_DOUBLE');
  2629. {$if not defined(i386) and not defined(x86_64)}
  2630. def_system_macro('FPC_INCLUDE_SOFTWARE_INT64_TO_DOUBLE');
  2631. {$endif}
  2632. {$ifdef x86_64}
  2633. { win64 doesn't support the legacy fpu }
  2634. if target_info.system=system_x86_64_win64 then
  2635. undef_system_macro('FPC_HAS_TYPE_EXTENDED')
  2636. else
  2637. def_system_macro('FPC_HAS_TYPE_EXTENDED');
  2638. {$endif}
  2639. end;
  2640. {$ifdef ARM}
  2641. { define FPC_DOUBLE_HILO_SWAPPED if needed to properly handle doubles in RTL }
  2642. if (init_settings.fputype in [fpu_fpa,fpu_fpa10,fpu_fpa11]) and
  2643. not(cs_fp_emulation in init_settings.moduleswitches) then
  2644. def_system_macro('FPC_DOUBLE_HILO_SWAPPED');
  2645. {$endif ARM}
  2646. { Section smartlinking conflicts with import sections on Windows }
  2647. if GenerateImportSection and
  2648. (target_info.system in [system_i386_win32,system_x86_64_win64]) then
  2649. exclude(target_info.flags,tf_smartlink_sections);
  2650. if not LinkTypeSetExplicitly then
  2651. set_default_link_type;
  2652. { Default alignment settings,
  2653. 1. load the defaults for the target
  2654. 2. override with generic optimizer setting (little size)
  2655. 3. override with the user specified -Oa }
  2656. UpdateAlignment(init_settings.alignment,target_info.alignment);
  2657. if (cs_opt_size in current_settings.optimizerswitches) then
  2658. begin
  2659. init_settings.alignment.procalign:=1;
  2660. init_settings.alignment.jumpalign:=1;
  2661. init_settings.alignment.loopalign:=1;
  2662. end;
  2663. UpdateAlignment(init_settings.alignment,option.paraalignment);
  2664. set_system_macro('FPC_VERSION',version_nr);
  2665. set_system_macro('FPC_RELEASE',release_nr);
  2666. set_system_macro('FPC_PATCH',patch_nr);
  2667. set_system_macro('FPC_FULLVERSION',Format('%d%.02d%.02d',[StrToInt(version_nr),StrToInt(release_nr),StrToInt(patch_nr)]));
  2668. if not(target_info.system in systems_windows) then
  2669. def_system_macro('FPC_WIDESTRING_EQUAL_UNICODESTRING');
  2670. for i:=low(tfeature) to high(tfeature) do
  2671. if i in features then
  2672. def_system_macro('FPC_HAS_FEATURE_'+featurestr[i]);
  2673. option.free;
  2674. Option:=nil;
  2675. clearstack_pocalls := [pocall_cdecl,pocall_cppdecl,pocall_syscall,pocall_mwpascal];
  2676. cdecl_pocalls := [pocall_cdecl, pocall_cppdecl];
  2677. if (tf_safecall_clearstack in target_info.flags) then
  2678. begin
  2679. include (cdecl_pocalls, pocall_safecall);
  2680. include (clearstack_pocalls, pocall_safecall)
  2681. end;
  2682. end;
  2683. initialization
  2684. coption:=toption;
  2685. finalization
  2686. if assigned(option) then
  2687. option.free;
  2688. end.