options.pas 60 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097
  1. {
  2. $Id$
  3. Copyright (c) 1998-2002 by Florian Klaempfl and Peter Vreman
  4. Reads command line options and config files
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  16. ****************************************************************************
  17. }
  18. unit options;
  19. {$i fpcdefs.inc}
  20. interface
  21. uses
  22. globtype,globals,verbose,systems,cpuinfo;
  23. type
  24. TOption=class
  25. FirstPass,
  26. NoPressEnter,
  27. DoWriteLogo : boolean;
  28. FileLevel : longint;
  29. QuickInfo : string;
  30. ParaIncludePath,
  31. ParaUnitPath,
  32. ParaObjectPath,
  33. ParaLibraryPath : TSearchPathList;
  34. ParaAlignment : TAlignmentInfo;
  35. Constructor Create;
  36. Destructor Destroy;override;
  37. procedure WriteLogo;
  38. procedure WriteInfo;
  39. procedure WriteHelpPages;
  40. procedure WriteQuickInfo;
  41. procedure IllegalPara(const opt:string);
  42. function Unsetbool(var Opts:string; Pos: Longint):boolean;
  43. procedure interpret_proc_specific_options(const opt:string);virtual;
  44. procedure interpret_option(const opt :string;ispara:boolean);
  45. procedure Interpret_envvar(const envname : string);
  46. procedure Interpret_file(const filename : string);
  47. procedure Read_Parameters;
  48. procedure parsecmd(cmd:string);
  49. procedure TargetDefines(def:boolean);
  50. end;
  51. TOptionClass=class of toption;
  52. var
  53. coption : TOptionClass;
  54. procedure read_arguments(cmd:string);
  55. implementation
  56. uses
  57. widestr,
  58. {$ifdef Delphi}
  59. dmisc,
  60. {$else Delphi}
  61. dos,
  62. {$endif Delphi}
  63. version,
  64. cutils,cmsgs
  65. {$ifdef BrowserLog}
  66. ,browlog
  67. {$endif BrowserLog}
  68. ;
  69. const
  70. page_size = 24;
  71. var
  72. option : toption;
  73. read_configfile, { read config file, set when a cfgfile is found }
  74. disable_configfile,
  75. target_is_set : boolean; { do not allow contradictory target settings }
  76. asm_is_set : boolean; { -T also change initoutputformat if not set idrectly }
  77. fpcdir,
  78. ppccfg,
  79. ppcaltcfg,
  80. param_file : string; { file to compile specified on the commandline }
  81. {****************************************************************************
  82. Defines
  83. ****************************************************************************}
  84. procedure def_symbol(const s : string);
  85. begin
  86. if s='' then
  87. exit;
  88. initdefines.insert(upper(s));
  89. Message1(option_defining_symbol,s);
  90. end;
  91. procedure undef_symbol(const s : string);
  92. begin
  93. if s='' then
  94. exit;
  95. InitDefines.Remove(s);
  96. Message1(option_undefining_symbol,s);
  97. end;
  98. function check_symbol(const s:string):boolean;
  99. begin
  100. check_symbol:=(initdefines.find(s)<>nil);
  101. end;
  102. procedure set_default_link_type;
  103. begin
  104. { win32 and wdosx need smartlinking by default to prevent including too much
  105. dll dependencies }
  106. if (target_info.system in [system_i386_win32,system_i386_wdosx]) then
  107. begin
  108. def_symbol('FPC_LINK_SMART');
  109. undef_symbol('FPC_LINK_STATIC');
  110. undef_symbol('FPC_LINK_DYNAMIC');
  111. initglobalswitches:=initglobalswitches+[cs_link_smart];
  112. initglobalswitches:=initglobalswitches-[cs_link_shared,cs_link_static];
  113. end
  114. else
  115. begin
  116. undef_symbol('FPC_LINK_SMART');
  117. def_symbol('FPC_LINK_STATIC');
  118. undef_symbol('FPC_LINK_DYNAMIC');
  119. initglobalswitches:=initglobalswitches+[cs_link_static];
  120. initglobalswitches:=initglobalswitches-[cs_link_shared,cs_link_smart];
  121. end;
  122. end;
  123. {****************************************************************************
  124. Toption
  125. ****************************************************************************}
  126. procedure StopOptions;
  127. begin
  128. if assigned(Option) then
  129. begin
  130. Option.free;
  131. Option:=nil;
  132. end;
  133. DoneVerbose;
  134. Stop;
  135. end;
  136. procedure Toption.WriteLogo;
  137. var
  138. p : pchar;
  139. begin
  140. p:=MessagePchar(option_logo);
  141. while assigned(p) do
  142. Comment(V_Normal,GetMsgLine(p));
  143. end;
  144. procedure Toption.WriteInfo;
  145. var
  146. p : pchar;
  147. hs,hs1,s : string;
  148. target : tsystem;
  149. begin
  150. p:=MessagePchar(option_info);
  151. while assigned(p) do
  152. begin
  153. s:=GetMsgLine(p);
  154. { list OS Targets }
  155. if pos('$OSTARGETS',s)>0 then
  156. begin
  157. for target:=low(tsystem) to high(tsystem) do
  158. if assigned(targetinfos[target]) then
  159. begin
  160. hs:=s;
  161. hs1:=targetinfos[target]^.name;
  162. if tf_under_development in targetinfos[target]^.flags then
  163. hs1:=hs1+' (under development)';
  164. Replace(hs,'$OSTARGETS',hs1);
  165. Comment(V_Normal,hs);
  166. end;
  167. end
  168. else
  169. Comment(V_Normal,s);
  170. end;
  171. StopOptions;
  172. end;
  173. procedure Toption.WriteHelpPages;
  174. function PadEnd(s:string;i:longint):string;
  175. begin
  176. while (length(s)<i) do
  177. s:=s+' ';
  178. PadEnd:=s;
  179. end;
  180. var
  181. lastident,
  182. j,outline,
  183. ident,
  184. lines : longint;
  185. show : boolean;
  186. opt : string[32];
  187. input,
  188. s : string;
  189. p : pchar;
  190. begin
  191. WriteLogo;
  192. Lines:=4;
  193. Message1(option_usage,system.paramstr(0));
  194. lastident:=0;
  195. p:=MessagePChar(option_help_pages);
  196. while assigned(p) do
  197. begin
  198. { get a line and reset }
  199. s:=GetMsgLine(p);
  200. ident:=0;
  201. show:=false;
  202. { parse options }
  203. case s[1] of
  204. {$ifdef UNITALIASES}
  205. 'a',
  206. {$endif}
  207. {$ifdef EXTDEBUG}
  208. 'e',
  209. {$endif EXTDEBUG}
  210. {$ifdef i386}
  211. '3',
  212. {$endif}
  213. {$ifdef powerpc}
  214. 'P',
  215. {$endif}
  216. {$ifdef vis}
  217. 'V',
  218. {$endif}
  219. {$ifdef sparc}
  220. 'S',
  221. {$endif}
  222. {$ifdef m68k}
  223. '6',
  224. {$endif}
  225. '*' : show:=true;
  226. end;
  227. if show then
  228. begin
  229. case s[2] of
  230. {$ifdef GDB}
  231. 'g',
  232. {$endif}
  233. {$ifdef Unix}
  234. 'L',
  235. {$endif}
  236. {$ifdef os2}
  237. 'O',
  238. {$endif}
  239. '*' : show:=true;
  240. else
  241. show:=false;
  242. end;
  243. end;
  244. { now we may show the message or not }
  245. if show then
  246. begin
  247. case s[3] of
  248. '0' : begin
  249. ident:=0;
  250. outline:=0;
  251. end;
  252. '1' : begin
  253. ident:=2;
  254. outline:=7;
  255. end;
  256. '2' : begin
  257. ident:=6;
  258. outline:=11;
  259. end;
  260. '3' : begin
  261. ident:=9;
  262. outline:=6;
  263. end;
  264. end;
  265. j:=pos('_',s);
  266. opt:=Copy(s,4,j-4);
  267. if opt='*' then
  268. opt:=''
  269. else
  270. if opt=' ' then
  271. opt:=PadEnd(opt,outline)
  272. else
  273. opt:=PadEnd('-'+opt,outline);
  274. if (ident=0) and (lastident<>0) then
  275. begin
  276. Comment(V_Normal,'');
  277. inc(Lines);
  278. end;
  279. { page full ? }
  280. if (lines >= page_size - 1) then
  281. begin
  282. if not NoPressEnter then
  283. begin
  284. Message(option_help_press_enter);
  285. readln(input);
  286. if upper(input)='Q' then
  287. StopOptions;
  288. end;
  289. lines:=0;
  290. end;
  291. Comment(V_Normal,PadEnd('',ident)+opt+Copy(s,j+1,255));
  292. LastIdent:=Ident;
  293. inc(Lines);
  294. end;
  295. end;
  296. StopOptions;
  297. end;
  298. procedure Toption.IllegalPara(const opt:string);
  299. begin
  300. Message1(option_illegal_para,opt);
  301. Message(option_help_pages_para);
  302. StopOptions;
  303. end;
  304. function Toption.Unsetbool(var Opts:string; Pos: Longint):boolean;
  305. { checks if the character after pos in Opts is a + or a - and returns resp.
  306. false or true. If it is another character (or none), it also returns false }
  307. begin
  308. UnsetBool := false;
  309. if Length(Opts)>Pos then
  310. begin
  311. inc(Pos);
  312. UnsetBool := Opts[Pos] = '-';
  313. if Opts[Pos] in ['-','+']then
  314. delete(Opts,Pos,1);
  315. end;
  316. end;
  317. procedure TOption.interpret_proc_specific_options(const opt:string);
  318. begin
  319. end;
  320. procedure TOption.interpret_option(const opt:string;ispara:boolean);
  321. var
  322. code : integer;
  323. c : char;
  324. more : string;
  325. major,minor : longint;
  326. error : integer;
  327. j,l : longint;
  328. d : DirStr;
  329. e : ExtStr;
  330. s : string;
  331. forceasm : tasm;
  332. begin
  333. if opt='' then
  334. exit;
  335. { only parse define,undef,target,verbosity and link options the firsttime }
  336. if firstpass and
  337. not((opt[1]='-') and (opt[2] in ['i','d','v','T','u','n','X'])) then
  338. exit;
  339. Message1(option_handling_option,opt);
  340. case opt[1] of
  341. '-' :
  342. begin
  343. more:=Copy(opt,3,255);
  344. if firstpass then
  345. Message1(option_interpreting_firstpass_option,opt)
  346. else
  347. Message1(option_interpreting_option,opt);
  348. case opt[2] of
  349. '?' :
  350. WriteHelpPages;
  351. 'a' :
  352. begin
  353. include(initglobalswitches,cs_asm_leave);
  354. j:=1;
  355. while j<=length(more) do
  356. begin
  357. case more[j] of
  358. 'l' :
  359. include(initglobalswitches,cs_asm_source);
  360. 'r' :
  361. include(initglobalswitches,cs_asm_regalloc);
  362. 't' :
  363. include(initglobalswitches,cs_asm_tempalloc);
  364. 'n' :
  365. include(initglobalswitches,cs_asm_nodes);
  366. 'p' :
  367. begin
  368. exclude(initglobalswitches,cs_asm_leave);
  369. if UnsetBool(More, 0) then
  370. exclude(initglobalswitches,cs_asm_pipe)
  371. else
  372. include(initglobalswitches,cs_asm_pipe);
  373. end;
  374. '-' :
  375. initglobalswitches:=initglobalswitches -
  376. [cs_asm_leave, cs_asm_source,cs_asm_regalloc, cs_asm_tempalloc,
  377. cs_asm_nodes, cs_asm_pipe];
  378. else
  379. IllegalPara(opt);
  380. end;
  381. inc(j);
  382. end;
  383. end;
  384. 'A' :
  385. begin
  386. if set_target_asm_by_string(More) then
  387. asm_is_set:=true
  388. else
  389. IllegalPara(opt);
  390. end;
  391. 'b' :
  392. begin
  393. if UnsetBool(More,0) then
  394. begin
  395. exclude(initmoduleswitches,cs_browser);
  396. exclude(initmoduleswitches,cs_local_browser);
  397. {$ifdef BrowserLog}
  398. exclude(initglobalswitches,cs_browser_log);
  399. {$endif}
  400. end
  401. else
  402. begin
  403. include(initmoduleswitches,cs_browser);
  404. {$ifdef BrowserLog}
  405. include(initglobalswitches,cs_browser_log);
  406. {$endif}
  407. end;
  408. if More<>'' then
  409. if (More='l') or (More='l+') then
  410. include(initmoduleswitches,cs_local_browser)
  411. else
  412. if More='l-' then
  413. exclude(initmoduleswitches,cs_local_browser)
  414. else
  415. {$ifdef BrowserLog}
  416. browserlog.elements_to_list.insert(more);
  417. {$else}
  418. IllegalPara(opt);
  419. {$endif}
  420. end;
  421. 'B' :
  422. do_build:=not UnSetBool(more,0);
  423. 'C' :
  424. begin
  425. j:=1;
  426. while j<=length(more) do
  427. begin
  428. case more[j] of
  429. 'a' :
  430. Message2(option_obsolete_switch_use_new,'-Ca','-Or');
  431. 'c' :
  432. begin
  433. if not SetAktProcCall(upper(copy(more,j+1,length(more)-j)),true) then
  434. IllegalPara(opt);
  435. break;
  436. end;
  437. {$ifdef cpufpemu}
  438. 'e' :
  439. begin
  440. If UnsetBool(More, j) then
  441. exclude(initmoduleswitches,cs_fp_emulation)
  442. Else
  443. include(initmoduleswitches,cs_fp_emulation);
  444. end;
  445. {$endif cpufpemu}
  446. 'f' :
  447. begin
  448. s:=upper(copy(more,j+1,length(more)-j));
  449. if not(SetFpuType(s,true)) then
  450. IllegalPara(opt);
  451. break;
  452. end;
  453. 'g' :
  454. include(initmoduleswitches,cs_create_pic);
  455. 'h' :
  456. begin
  457. val(copy(more,j+1,length(more)-j),heapsize,code);
  458. if (code<>0) or
  459. {$WARNING Is the upper limit for heapsize needed / useful?}
  460. { (heapsize>=67107840) or }
  461. (heapsize<1024) then
  462. IllegalPara(opt);
  463. break;
  464. end;
  465. 'i' :
  466. If UnsetBool(More, j) then
  467. exclude(initlocalswitches,cs_check_io)
  468. else
  469. include(initlocalswitches,cs_check_io);
  470. 'n' :
  471. If UnsetBool(More, j) then
  472. exclude(initglobalswitches,cs_link_extern)
  473. Else
  474. include(initglobalswitches,cs_link_extern);
  475. 'o' :
  476. If UnsetBool(More, j) then
  477. exclude(initlocalswitches,cs_check_overflow)
  478. Else
  479. include(initlocalswitches,cs_check_overflow);
  480. 'p' :
  481. begin
  482. s:=upper(copy(more,j+1,length(more)-j));
  483. if not(SetProcessor(s,true)) then
  484. IllegalPara(opt);
  485. break;
  486. end;
  487. 'r' :
  488. If UnsetBool(More, j) then
  489. exclude(initlocalswitches,cs_check_range)
  490. Else
  491. include(initlocalswitches,cs_check_range);
  492. 'R' :
  493. If UnsetBool(More, j) then
  494. begin
  495. exclude(initlocalswitches,cs_check_range);
  496. exclude(initlocalswitches,cs_check_object);
  497. end
  498. Else
  499. begin
  500. include(initlocalswitches,cs_check_range);
  501. include(initlocalswitches,cs_check_object);
  502. end;
  503. 's' :
  504. begin
  505. val(copy(more,j+1,length(more)-j),stacksize,code);
  506. if (code<>0) or (stacksize>=67107840) or (stacksize<1024) then
  507. IllegalPara(opt);
  508. break;
  509. end;
  510. 't' :
  511. If UnsetBool(More, j) then
  512. exclude(initlocalswitches,cs_check_stack)
  513. Else
  514. include(initlocalswitches,cs_check_stack);
  515. 'D' :
  516. If UnsetBool(More, j) then
  517. exclude(initmoduleswitches,cs_create_dynamic)
  518. Else
  519. include(initmoduleswitches,cs_create_dynamic);
  520. 'X' :
  521. If UnsetBool(More, j) then
  522. exclude(initmoduleswitches,cs_create_smart)
  523. Else
  524. include(initmoduleswitches,cs_create_smart);
  525. else
  526. IllegalPara(opt);
  527. end;
  528. inc(j);
  529. end;
  530. end;
  531. 'd' :
  532. def_symbol(more);
  533. 'D' :
  534. begin
  535. include(initglobalswitches,cs_link_deffile);
  536. j:=1;
  537. while j<=length(more) do
  538. begin
  539. case more[j] of
  540. 'd' :
  541. begin
  542. description:=Copy(more,j+1,255);
  543. break;
  544. end;
  545. 'v' :
  546. begin
  547. dllversion:=Copy(more,j+1,255);
  548. l:=pos('.',dllversion);
  549. dllminor:=0;
  550. error:=0;
  551. if l>0 then
  552. begin
  553. valint(copy(dllversion,l+1,255),minor,error);
  554. if (error=0) and
  555. (minor>=0) and (minor<=$ffff) then
  556. dllminor:=minor
  557. else
  558. if error=0 then
  559. error:=1;
  560. end;
  561. if l=0 then
  562. l:=256;
  563. dllmajor:=1;
  564. if error=0 then
  565. valint(copy(dllversion,1,l-1),major,error);
  566. if (error=0) and (major>=0) and (major<=$ffff) then
  567. dllmajor:=major
  568. else
  569. if error=0 then
  570. error:=1;
  571. if error<>0 then
  572. Message1(scan_w_wrong_version_ignored,dllversion);
  573. break;
  574. end;
  575. 'w' :
  576. usewindowapi:=true;
  577. '-' :
  578. begin
  579. exclude(initglobalswitches,cs_link_deffile);
  580. usewindowapi:=false;
  581. end;
  582. else
  583. IllegalPara(opt);
  584. end;
  585. inc(j);
  586. end;
  587. end;
  588. 'e' :
  589. exepath:=FixPath(More,true);
  590. 'E' :
  591. begin
  592. if UnsetBool(More, 0) then
  593. exclude(initglobalswitches,cs_link_extern)
  594. else
  595. include(initglobalswitches,cs_link_extern);
  596. end;
  597. 'F' :
  598. begin
  599. c:=more[1];
  600. Delete(more,1,1);
  601. DefaultReplacements(More);
  602. case c of
  603. 'c' :
  604. begin
  605. if not(cpavailable(more)) then
  606. Message1(option_code_page_not_available,more)
  607. else
  608. initsourcecodepage:=more;
  609. end;
  610. 'D' :
  611. utilsdirectory:=FixPath(More,true);
  612. 'e' :
  613. SetRedirectFile(More);
  614. 'E' :
  615. OutputExeDir:=FixPath(More,true);
  616. 'i' :
  617. begin
  618. if ispara then
  619. ParaIncludePath.AddPath(More,false)
  620. else
  621. includesearchpath.AddPath(More,true);
  622. end;
  623. 'g' :
  624. Message2(option_obsolete_switch_use_new,'-Fg','-Fl');
  625. 'l' :
  626. begin
  627. if ispara then
  628. ParaLibraryPath.AddPath(More,false)
  629. else
  630. LibrarySearchPath.AddPath(More,true);
  631. end;
  632. 'L' :
  633. begin
  634. if More<>'' then
  635. ParaDynamicLinker:=More
  636. else
  637. IllegalPara(opt);
  638. end;
  639. 'o' :
  640. begin
  641. if ispara then
  642. ParaObjectPath.AddPath(More,false)
  643. else
  644. ObjectSearchPath.AddPath(More,true);
  645. end;
  646. 'r' :
  647. Msgfilename:=More;
  648. 'u' :
  649. begin
  650. if ispara then
  651. ParaUnitPath.AddPath(More,false)
  652. else
  653. unitsearchpath.AddPath(More,true);
  654. end;
  655. 'U' :
  656. OutputUnitDir:=FixPath(More,true);
  657. else
  658. IllegalPara(opt);
  659. end;
  660. end;
  661. 'g' : begin
  662. if UnsetBool(More, 0) then
  663. begin
  664. exclude(initmoduleswitches,cs_debuginfo);
  665. exclude(initglobalswitches,cs_gdb_dbx);
  666. exclude(initglobalswitches,cs_gdb_gsym);
  667. exclude(initglobalswitches,cs_gdb_heaptrc);
  668. exclude(initglobalswitches,cs_gdb_lineinfo);
  669. exclude(initglobalswitches,cs_checkpointer);
  670. end
  671. else
  672. begin
  673. {$ifdef GDB}
  674. include(initmoduleswitches,cs_debuginfo);
  675. if not RelocSectionSetExplicitly then
  676. RelocSection:=false;
  677. j:=1;
  678. while j<=length(more) do
  679. begin
  680. case more[j] of
  681. 'd' :
  682. begin
  683. if UnsetBool(More, j) then
  684. exclude(initglobalswitches,cs_gdb_dbx)
  685. else
  686. include(initglobalswitches,cs_gdb_dbx);
  687. end;
  688. 'g' :
  689. begin
  690. if UnsetBool(More, j) then
  691. exclude(initglobalswitches,cs_gdb_gsym)
  692. else
  693. include(initglobalswitches,cs_gdb_gsym);
  694. end;
  695. 'h' :
  696. begin
  697. if UnsetBool(More, j) then
  698. exclude(initglobalswitches,cs_gdb_heaptrc)
  699. else
  700. include(initglobalswitches,cs_gdb_heaptrc);
  701. end;
  702. 'l' :
  703. begin
  704. if UnsetBool(More, j) then
  705. exclude(initglobalswitches,cs_gdb_lineinfo)
  706. else
  707. include(initglobalswitches,cs_gdb_lineinfo);
  708. end;
  709. 'c' :
  710. begin
  711. if UnsetBool(More, j) then
  712. exclude(initglobalswitches,cs_checkpointer)
  713. else
  714. include(initglobalswitches,cs_checkpointer);
  715. end;
  716. 'v' :
  717. begin
  718. if UnsetBool(More, j) then
  719. exclude(initglobalswitches,cs_gdb_valgrind)
  720. else
  721. include(initglobalswitches,cs_gdb_valgrind);
  722. end;
  723. 'w' :
  724. begin
  725. if UnsetBool(More, j) then
  726. exclude(initglobalswitches,cs_gdb_dwarf)
  727. else
  728. include(initglobalswitches,cs_gdb_dwarf);
  729. end;
  730. else
  731. IllegalPara(opt);
  732. end;
  733. inc(j);
  734. end;
  735. {$else GDB}
  736. Message(option_no_debug_support);
  737. Message(option_no_debug_support_recompile_fpc);
  738. {$endif GDB}
  739. end;
  740. end;
  741. 'h' :
  742. begin
  743. NoPressEnter:=true;
  744. WriteHelpPages;
  745. end;
  746. 'i' :
  747. begin
  748. if More='' then
  749. WriteInfo
  750. else
  751. QuickInfo:=QuickInfo+More;
  752. end;
  753. 'I' :
  754. begin
  755. if ispara then
  756. ParaIncludePath.AddPath(More,false)
  757. else
  758. includesearchpath.AddPath(More,false);
  759. end;
  760. 'k' :
  761. begin
  762. if more<>'' then
  763. ParaLinkOptions:=ParaLinkOptions+' '+More
  764. else
  765. IllegalPara(opt);
  766. end;
  767. 'l' :
  768. DoWriteLogo:=not UnSetBool(more,0);
  769. 'm' :
  770. parapreprocess:=not UnSetBool(more,0);
  771. 'n' :
  772. begin
  773. if More='' then
  774. disable_configfile:=true
  775. else
  776. IllegalPara(opt);
  777. end;
  778. 'o' :
  779. begin
  780. if More<>'' then
  781. Fsplit(More,d,OutputFile,e)
  782. else
  783. IllegalPara(opt);
  784. end;
  785. 'p' :
  786. begin
  787. if UnsetBool(More, 0) then
  788. begin
  789. initmoduleswitches:=initmoduleswitches-[cs_profile];
  790. undef_symbol('FPC_PROFILE');
  791. end
  792. else
  793. if Length(More)=0 then
  794. IllegalPara(opt)
  795. else
  796. case more[1] of
  797. 'g' : if UnsetBool(more, 1) then
  798. begin
  799. exclude(initmoduleswitches,cs_profile);
  800. undef_symbol('FPC_PROFILE');
  801. end
  802. else
  803. begin
  804. include(initmoduleswitches,cs_profile);
  805. def_symbol('FPC_PROFILE');
  806. end;
  807. else
  808. IllegalPara(opt);
  809. end;
  810. end;
  811. {$ifdef Unix}
  812. 'P' : ; { Ignore used by fpc.pp }
  813. {$endif Unix}
  814. 's' :
  815. begin
  816. if UnsetBool(More, 0) then
  817. begin
  818. initglobalswitches:=initglobalswitches-[cs_asm_extern,cs_link_extern];
  819. if more<>'' then
  820. IllegalPara(opt);
  821. end
  822. else
  823. begin
  824. initglobalswitches:=initglobalswitches+[cs_asm_extern,cs_link_extern];
  825. if more='h' then
  826. initglobalswitches:=initglobalswitches-[cs_link_on_target]
  827. else if more='t' then
  828. initglobalswitches:=initglobalswitches+[cs_link_on_target]
  829. else if more='r' then
  830. initglobalswitches:=initglobalswitches+[cs_asm_leave,cs_no_regalloc]
  831. else if more<>'' then
  832. IllegalPara(opt);
  833. end;
  834. end;
  835. 'M' :
  836. begin
  837. more:=Upper(more);
  838. if not SetCompileMode(more, true) then
  839. IllegalPara(opt);
  840. end;
  841. 'S' :
  842. begin
  843. if more[1]='I' then
  844. begin
  845. if upper(more)='ICOM' then
  846. initinterfacetype:=it_interfacecom
  847. else if upper(more)='ICORBA' then
  848. initinterfacetype:=it_interfacecorba
  849. else
  850. IllegalPara(opt);
  851. end
  852. else
  853. begin
  854. j:=1;
  855. while j<=length(more) do
  856. begin
  857. case more[j] of
  858. '2' : //an alternative to -Mobjfpc
  859. SetCompileMode('OBJFPC',true);
  860. 'a' :
  861. include(initlocalswitches,cs_do_assertion);
  862. 'c' :
  863. include(initmoduleswitches,cs_support_c_operators);
  864. 'd' : //an alternative to -Mdelphi
  865. SetCompileMode('DELPHI',true);
  866. 'e' :
  867. begin
  868. SetErrorFlags(copy(more,j+1,length(more)));
  869. break;
  870. end;
  871. 'g' :
  872. include(initmoduleswitches,cs_support_goto);
  873. 'h' :
  874. include(initlocalswitches,cs_ansistrings);
  875. 'i' :
  876. include(initmoduleswitches,cs_support_inline);
  877. 'm' :
  878. include(initmoduleswitches,cs_support_macro);
  879. 'o' : //an alternative to -Mtp
  880. SetCompileMode('TP',true);
  881. 'p' : //an alternative to -Mgpc
  882. SetCompileMode('GPC',true);
  883. 's' :
  884. include(initglobalswitches,cs_constructor_name);
  885. 't' :
  886. include(initmoduleswitches,cs_static_keyword);
  887. '-' :
  888. begin
  889. exclude(initglobalswitches,cs_constructor_name);
  890. initlocalswitches:=InitLocalswitches - [cs_do_assertion, cs_ansistrings];
  891. initmoduleswitches:=initmoduleswitches - [cs_support_c_operators, cs_support_goto,
  892. cs_support_inline, cs_support_macro,
  893. cs_static_keyword];
  894. end;
  895. else
  896. IllegalPara(opt);
  897. end;
  898. inc(j);
  899. end;
  900. end;
  901. end;
  902. 'T' :
  903. begin
  904. more:=Upper(More);
  905. if not target_is_set then
  906. begin
  907. { remove old target define }
  908. TargetDefines(false);
  909. { Save assembler if set }
  910. if asm_is_set then
  911. forceasm:=target_asm.id;
  912. { load new target }
  913. if not(set_target_by_string(More)) then
  914. IllegalPara(opt);
  915. { also initialize assembler if not explicitly set }
  916. if asm_is_set then
  917. set_target_asm(forceasm);
  918. { set new define }
  919. TargetDefines(true);
  920. target_is_set:=true;
  921. end
  922. else
  923. if More<>upper(target_info.shortname) then
  924. Message1(option_target_is_already_set,target_info.shortname);
  925. end;
  926. 'u' :
  927. undef_symbol(upper(More));
  928. 'U' :
  929. begin
  930. j:=1;
  931. while j<=length(more) do
  932. begin
  933. case more[j] of
  934. {$ifdef UNITALIASES}
  935. 'a' :
  936. begin
  937. AddUnitAlias(Copy(More,j+1,255));
  938. break;
  939. end;
  940. {$endif UNITALIASES}
  941. 'n' :
  942. exclude(initglobalswitches,cs_check_unit_name);
  943. 'p' :
  944. begin
  945. Message2(option_obsolete_switch_use_new,'-Up','-Fu');
  946. break;
  947. end;
  948. 'r' :
  949. do_release:=true;
  950. 's' :
  951. include(initmoduleswitches,cs_compilesystem);
  952. '-' :
  953. begin
  954. exclude(initmoduleswitches,cs_compilesystem);
  955. exclude(initglobalswitches,cs_check_unit_name);
  956. end;
  957. else
  958. IllegalPara(opt);
  959. end;
  960. inc(j);
  961. end;
  962. end;
  963. 'v' :
  964. begin
  965. if not setverbosity(More) then
  966. IllegalPara(opt);
  967. end;
  968. 'V' : ; { Ignore used by fpc }
  969. 'W' :
  970. begin
  971. j:=1;
  972. while j<=length(More) do
  973. begin
  974. case More[j] of
  975. 'B':
  976. begin
  977. { -WB200000 means set trefered base address
  978. to $200000, but does not change relocsection boolean
  979. this way we can create both relocatble and
  980. non relocatable DLL at a specific base address PM }
  981. if (length(More)>j) then
  982. begin
  983. if DLLImageBase=nil then
  984. DLLImageBase:=StringDup(Copy(More,j+1,255));
  985. end
  986. else
  987. begin
  988. RelocSection:=true;
  989. RelocSectionSetExplicitly:=true;
  990. end;
  991. break;
  992. end;
  993. 'C':
  994. begin
  995. if UnsetBool(More, j) then
  996. apptype:=app_gui
  997. else
  998. apptype:=app_cui;
  999. end;
  1000. 'D':
  1001. begin
  1002. UseDeffileForExports:=not UnsetBool(More, j);
  1003. UseDeffileForExportsSetExplicitly:=true;
  1004. end;
  1005. 'F':
  1006. begin
  1007. if UnsetBool(More, j) then
  1008. apptype:=app_cui
  1009. else
  1010. apptype:=app_fs;
  1011. end;
  1012. 'G':
  1013. begin
  1014. if UnsetBool(More, j) then
  1015. apptype:=app_cui
  1016. else
  1017. apptype:=app_gui;
  1018. end;
  1019. 'T':
  1020. begin
  1021. if UnsetBool(More, j) then
  1022. apptype:=app_cui
  1023. else
  1024. apptype:=app_tool;
  1025. end;
  1026. 'N':
  1027. begin
  1028. RelocSection:=UnsetBool(More,j);
  1029. RelocSectionSetExplicitly:=true;
  1030. end;
  1031. 'R':
  1032. begin
  1033. { support -WR+ / -WR- as synonyms to -WR / -WN }
  1034. RelocSection:=not UnsetBool(More,j);
  1035. RelocSectionSetExplicitly:=true;
  1036. end;
  1037. else
  1038. IllegalPara(opt);
  1039. end;
  1040. inc(j);
  1041. end;
  1042. end;
  1043. 'X' :
  1044. begin
  1045. j:=1;
  1046. while j<=length(more) do
  1047. begin
  1048. case More[j] of
  1049. 'i' :
  1050. include(initglobalswitches,cs_link_internal);
  1051. 'm' :
  1052. include(initglobalswitches,cs_link_map);
  1053. 'f' :
  1054. include(initglobalswitches,cs_link_pthread);
  1055. 's' :
  1056. include(initglobalswitches,cs_link_strip);
  1057. 'c' : Cshared:=TRUE;
  1058. 't' :
  1059. include(initglobalswitches,cs_link_staticflag);
  1060. 'D' :
  1061. begin
  1062. def_symbol('FPC_LINK_DYNAMIC');
  1063. undef_symbol('FPC_LINK_SMART');
  1064. undef_symbol('FPC_LINK_STATIC');
  1065. exclude(initglobalswitches,cs_link_static);
  1066. exclude(initglobalswitches,cs_link_smart);
  1067. include(initglobalswitches,cs_link_shared);
  1068. LinkTypeSetExplicitly:=true;
  1069. end;
  1070. 'd' : Dontlinkstdlibpath:=TRUE;
  1071. 'P' : Begin
  1072. utilsprefix:=Copy(more,2,length(More)-1);
  1073. More:='';
  1074. End;
  1075. 'r' : Begin
  1076. rlinkpath:=Copy(more,2,length(More)-1);
  1077. More:='';
  1078. end;
  1079. 'S' :
  1080. begin
  1081. def_symbol('FPC_LINK_STATIC');
  1082. undef_symbol('FPC_LINK_SMART');
  1083. undef_symbol('FPC_LINK_DYNAMIC');
  1084. include(initglobalswitches,cs_link_static);
  1085. exclude(initglobalswitches,cs_link_smart);
  1086. exclude(initglobalswitches,cs_link_shared);
  1087. LinkTypeSetExplicitly:=true;
  1088. end;
  1089. 'X' :
  1090. begin
  1091. def_symbol('FPC_LINK_SMART');
  1092. undef_symbol('FPC_LINK_STATIC');
  1093. undef_symbol('FPC_LINK_DYNAMIC');
  1094. exclude(initglobalswitches,cs_link_static);
  1095. include(initglobalswitches,cs_link_smart);
  1096. exclude(initglobalswitches,cs_link_shared);
  1097. LinkTypeSetExplicitly:=true;
  1098. end;
  1099. '-' :
  1100. begin
  1101. exclude(initglobalswitches,cs_link_staticflag);
  1102. exclude(initglobalswitches,cs_link_strip);
  1103. exclude(initglobalswitches,cs_link_map);
  1104. set_default_link_type;
  1105. end;
  1106. else
  1107. IllegalPara(opt);
  1108. end;
  1109. inc(j);
  1110. end;
  1111. end;
  1112. { give processor specific options a chance }
  1113. else
  1114. interpret_proc_specific_options(opt);
  1115. end;
  1116. end;
  1117. '@' :
  1118. begin
  1119. Message(option_no_nested_response_file);
  1120. StopOptions;
  1121. end;
  1122. else
  1123. begin
  1124. if (length(param_file)<>0) then
  1125. Message(option_only_one_source_support);
  1126. param_file:=opt;
  1127. Message1(option_found_file,opt);
  1128. end;
  1129. end;
  1130. end;
  1131. procedure Toption.Interpret_file(const filename : string);
  1132. procedure RemoveSep(var fn:string);
  1133. var
  1134. i : longint;
  1135. begin
  1136. i:=0;
  1137. while (i<length(fn)) and (fn[i+1] in [',',' ',#9]) do
  1138. inc(i);
  1139. Delete(fn,1,i);
  1140. i:=length(fn);
  1141. while (i>0) and (fn[i] in [',',' ',#9]) do
  1142. dec(i);
  1143. fn:=copy(fn,1,i);
  1144. end;
  1145. function GetName(var fn:string):string;
  1146. var
  1147. i : longint;
  1148. begin
  1149. i:=0;
  1150. while (i<length(fn)) and (fn[i+1] in ['a'..'z','A'..'Z','0'..'9','_','-']) do
  1151. inc(i);
  1152. GetName:=Copy(fn,1,i);
  1153. Delete(fn,1,i);
  1154. end;
  1155. const
  1156. maxlevel=16;
  1157. var
  1158. f : text;
  1159. s,
  1160. opts : string;
  1161. skip : array[0..maxlevel-1] of boolean;
  1162. level : longint;
  1163. option_read : boolean;
  1164. begin
  1165. { avoid infinite loop }
  1166. Inc(FileLevel);
  1167. Option_read:=false;
  1168. If FileLevel>MaxLevel then
  1169. Message(option_too_many_cfg_files);
  1170. { open file }
  1171. Message1(option_using_file,filename);
  1172. assign(f,filename);
  1173. {$I-}
  1174. reset(f);
  1175. {$I+}
  1176. if ioresult<>0 then
  1177. begin
  1178. Message1(option_unable_open_file,filename);
  1179. exit;
  1180. end;
  1181. Message1(option_start_reading_configfile,filename);
  1182. fillchar(skip,sizeof(skip),0);
  1183. level:=0;
  1184. while not eof(f) do
  1185. begin
  1186. readln(f,opts);
  1187. RemoveSep(opts);
  1188. if (opts<>'') and (opts[1]<>';') then
  1189. begin
  1190. if opts[1]='#' then
  1191. begin
  1192. Message1(option_interpreting_file_option,opts);
  1193. Delete(opts,1,1);
  1194. s:=upper(GetName(opts));
  1195. if (s='SECTION') then
  1196. begin
  1197. RemoveSep(opts);
  1198. s:=upper(GetName(opts));
  1199. if level=0 then
  1200. skip[level]:=not (check_symbol(s) or (s='COMMON'));
  1201. end
  1202. else
  1203. if (s='IFDEF') then
  1204. begin
  1205. RemoveSep(opts);
  1206. if Level>=maxlevel then
  1207. begin
  1208. Message(option_too_many_ifdef);
  1209. stopOptions;
  1210. end;
  1211. inc(Level);
  1212. skip[level]:=(skip[level-1] or (not check_symbol(upper(GetName(opts)))));
  1213. end
  1214. else
  1215. if (s='IFNDEF') then
  1216. begin
  1217. RemoveSep(opts);
  1218. if Level>=maxlevel then
  1219. begin
  1220. Message(option_too_many_ifdef);
  1221. stopOptions;
  1222. end;
  1223. inc(Level);
  1224. skip[level]:=(skip[level-1] or (check_symbol(upper(GetName(opts)))));
  1225. end
  1226. else
  1227. if (s='ELSE') then
  1228. skip[level]:=skip[level-1] or (not skip[level])
  1229. else
  1230. if (s='ENDIF') then
  1231. begin
  1232. skip[level]:=false;
  1233. if Level=0 then
  1234. begin
  1235. Message(option_too_many_endif);
  1236. stopOptions;
  1237. end;
  1238. dec(level);
  1239. end
  1240. else
  1241. if (not skip[level]) then
  1242. begin
  1243. if (s='DEFINE') then
  1244. begin
  1245. RemoveSep(opts);
  1246. def_symbol(upper(GetName(opts)));
  1247. end
  1248. else
  1249. if (s='UNDEF') then
  1250. begin
  1251. RemoveSep(opts);
  1252. undef_symbol(upper(GetName(opts)));
  1253. end
  1254. else
  1255. if (s='WRITE') then
  1256. begin
  1257. Delete(opts,1,1);
  1258. WriteLn(opts);
  1259. end
  1260. else
  1261. if (s='INCLUDE') then
  1262. begin
  1263. Delete(opts,1,1);
  1264. Interpret_file(opts);
  1265. end;
  1266. end;
  1267. end
  1268. else
  1269. begin
  1270. if (opts[1]='-') or (opts[1]='@') then
  1271. begin
  1272. if (not skip[level]) then
  1273. interpret_option(opts,false);
  1274. Option_read:=true;
  1275. end
  1276. else
  1277. Message1(option_illegal_para,opts);
  1278. end;
  1279. end;
  1280. end;
  1281. if Level>0 then
  1282. Message(option_too_less_endif);
  1283. if Not Option_read then
  1284. Message1(option_no_option_found,filename)
  1285. else
  1286. Message1(option_end_reading_configfile,filename);
  1287. Close(f);
  1288. Dec(FileLevel);
  1289. end;
  1290. procedure Toption.Interpret_envvar(const envname : string);
  1291. var
  1292. argstart,
  1293. env,
  1294. pc : pchar;
  1295. arglen : longint;
  1296. quote : set of char;
  1297. hs : string;
  1298. begin
  1299. Message1(option_using_env,envname);
  1300. env:=GetEnvPChar(envname);
  1301. pc:=env;
  1302. if assigned(pc) then
  1303. begin
  1304. repeat
  1305. { skip leading spaces }
  1306. while pc^ in [' ',#9,#13] do
  1307. inc(pc);
  1308. case pc^ of
  1309. #0 :
  1310. break;
  1311. '"' :
  1312. begin
  1313. quote:=['"'];
  1314. inc(pc);
  1315. end;
  1316. '''' :
  1317. begin
  1318. quote:=[''''];
  1319. inc(pc);
  1320. end;
  1321. else
  1322. quote:=[' ',#9,#13];
  1323. end;
  1324. { scan until the end of the argument }
  1325. argstart:=pc;
  1326. while (pc^<>#0) and not(pc^ in quote) do
  1327. inc(pc);
  1328. { create argument }
  1329. arglen:=pc-argstart;
  1330. hs[0]:=chr(arglen);
  1331. move(argstart^,hs[1],arglen);
  1332. interpret_option(hs,true);
  1333. { skip quote }
  1334. if pc^ in quote then
  1335. inc(pc);
  1336. until false;
  1337. end
  1338. else
  1339. Message1(option_no_option_found,'(env) '+envname);
  1340. FreeEnvPChar(env);
  1341. end;
  1342. procedure toption.read_parameters;
  1343. var
  1344. opts : string;
  1345. paramindex : longint;
  1346. begin
  1347. paramindex:=0;
  1348. while paramindex<paramcount do
  1349. begin
  1350. inc(paramindex);
  1351. opts:=system.paramstr(paramindex);
  1352. case opts[1] of
  1353. '@' :
  1354. if not firstpass then
  1355. begin
  1356. Delete(opts,1,1);
  1357. Message1(option_reading_further_from,opts);
  1358. interpret_file(opts);
  1359. end;
  1360. '!' :
  1361. if not firstpass then
  1362. begin
  1363. Delete(opts,1,1);
  1364. Message1(option_reading_further_from,'(env) '+opts);
  1365. interpret_envvar(opts);
  1366. end;
  1367. else
  1368. interpret_option(opts,true);
  1369. end;
  1370. end;
  1371. end;
  1372. procedure toption.parsecmd(cmd:string);
  1373. var
  1374. i,ps : longint;
  1375. opts : string;
  1376. begin
  1377. while (cmd<>'') do
  1378. begin
  1379. while cmd[1]=' ' do
  1380. delete(cmd,1,1);
  1381. i:=pos(' ',cmd);
  1382. if i=0 then
  1383. i:=256;
  1384. opts:=Copy(cmd,1,i-1);
  1385. Delete(cmd,1,i);
  1386. case opts[1] of
  1387. '@' :
  1388. if not firstpass then
  1389. begin
  1390. Delete(opts,1,1);
  1391. Message1(option_reading_further_from,opts);
  1392. interpret_file(opts);
  1393. end;
  1394. '!' :
  1395. if not firstpass then
  1396. begin
  1397. Delete(opts,1,1);
  1398. Message1(option_reading_further_from,'(env) '+opts);
  1399. interpret_envvar(opts);
  1400. end;
  1401. '"' :
  1402. begin
  1403. Delete(opts,1,1);
  1404. ps:=pos('"',cmd);
  1405. if (i<>256) and (ps>0) then
  1406. begin
  1407. opts:=opts + ' '+ copy(cmd,1,ps-1);
  1408. cmd:=copy(cmd,ps+1,255);
  1409. end;
  1410. interpret_option(opts,true);
  1411. end;
  1412. else
  1413. interpret_option(opts,true);
  1414. end;
  1415. end;
  1416. end;
  1417. procedure toption.writequickinfo;
  1418. var
  1419. s : string;
  1420. i : longint;
  1421. procedure addinfo(const hs:string);
  1422. begin
  1423. if s<>'' then
  1424. s:=s+' '+hs
  1425. else
  1426. s:=hs;
  1427. end;
  1428. begin
  1429. s:='';
  1430. i:=0;
  1431. while (i<length(quickinfo)) do
  1432. begin
  1433. inc(i);
  1434. case quickinfo[i] of
  1435. 'S' :
  1436. begin
  1437. inc(i);
  1438. case quickinfo[i] of
  1439. 'O' :
  1440. addinfo(lower(source_info.shortname));
  1441. {$ifdef Delphi}
  1442. 'P' :
  1443. addinfo('i386');
  1444. {$else Delphi}
  1445. 'P' :
  1446. addinfo(source_cpu_string);
  1447. {$endif Delphi}
  1448. else
  1449. IllegalPara('-i'+QuickInfo);
  1450. end;
  1451. end;
  1452. 'T' :
  1453. begin
  1454. inc(i);
  1455. case quickinfo[i] of
  1456. 'O' :
  1457. addinfo(lower(target_info.shortname));
  1458. 'P' :
  1459. AddInfo(target_cpu_string);
  1460. else
  1461. IllegalPara('-i'+QuickInfo);
  1462. end;
  1463. end;
  1464. 'V' :
  1465. AddInfo(version_string);
  1466. 'D' :
  1467. AddInfo(date_string);
  1468. '_' :
  1469. ;
  1470. else
  1471. IllegalPara('-i'+QuickInfo);
  1472. end;
  1473. end;
  1474. if s<>'' then
  1475. begin
  1476. writeln(s);
  1477. stopoptions;
  1478. end;
  1479. end;
  1480. procedure TOption.TargetDefines(def:boolean);
  1481. var
  1482. s : string;
  1483. i : integer;
  1484. begin
  1485. if def then
  1486. def_symbol(upper(target_info.shortname))
  1487. else
  1488. undef_symbol(upper(target_info.shortname));
  1489. s:=target_info.extradefines;
  1490. while (s<>'') do
  1491. begin
  1492. i:=pos(';',s);
  1493. if i=0 then
  1494. i:=length(s)+1;
  1495. if def then
  1496. def_symbol(Copy(s,1,i-1))
  1497. else
  1498. undef_symbol(Copy(s,1,i-1));
  1499. delete(s,1,i);
  1500. end;
  1501. end;
  1502. constructor TOption.create;
  1503. begin
  1504. DoWriteLogo:=false;
  1505. NoPressEnter:=false;
  1506. FirstPass:=false;
  1507. FileLevel:=0;
  1508. Quickinfo:='';
  1509. ParaIncludePath:=TSearchPathList.Create;
  1510. ParaObjectPath:=TSearchPathList.Create;
  1511. ParaUnitPath:=TSearchPathList.Create;
  1512. ParaLibraryPath:=TSearchPathList.Create;
  1513. FillChar(ParaAlignment,sizeof(ParaAlignment),0);
  1514. end;
  1515. destructor TOption.destroy;
  1516. begin
  1517. ParaIncludePath.Free;
  1518. ParaObjectPath.Free;
  1519. ParaUnitPath.Free;
  1520. ParaLibraryPath.Free;
  1521. end;
  1522. {****************************************************************************
  1523. Callable Routines
  1524. ****************************************************************************}
  1525. function check_configfile(const fn:string;var foundfn:string):boolean;
  1526. function CfgFileExists(const fn:string):boolean;
  1527. begin
  1528. Comment(V_Tried,'Configfile search: '+fn);
  1529. CfgFileExists:=FileExists(fn);
  1530. end;
  1531. var
  1532. configpath : pathstr;
  1533. begin
  1534. foundfn:=fn;
  1535. check_configfile:=true;
  1536. { retrieve configpath }
  1537. {$ifdef Delphi}
  1538. configpath:=FixPath(dmisc.getenv('PPC_CONFIG_PATH'),false);
  1539. {$else Delphi}
  1540. configpath:=FixPath(dos.getenv('PPC_CONFIG_PATH'),false);
  1541. {$endif Delphi}
  1542. {$ifdef Unix}
  1543. if configpath='' then
  1544. configpath:='/etc/';
  1545. {$endif}
  1546. {
  1547. Order to read configuration file :
  1548. try reading fpc.cfg in :
  1549. 1 - current dir
  1550. 2 - configpath
  1551. 3 - compiler path
  1552. }
  1553. if not FileExists(fn) then
  1554. begin
  1555. {$ifdef Unix}
  1556. if (dos.getenv('HOME')<>'') and CfgFileExists(FixPath(dos.getenv('HOME'),false)+'.'+fn) then
  1557. foundfn:=FixPath(dos.getenv('HOME'),false)+'.'+fn
  1558. else
  1559. {$endif}
  1560. if CfgFileExists(configpath+fn) then
  1561. foundfn:=configpath+fn
  1562. else
  1563. {$ifndef Unix}
  1564. if CfgFileExists(exepath+fn) then
  1565. foundfn:=exepath+fn
  1566. else
  1567. {$endif}
  1568. check_configfile:=false;
  1569. end;
  1570. end;
  1571. procedure read_arguments(cmd:string);
  1572. begin
  1573. option:=coption.create;
  1574. disable_configfile:=false;
  1575. { default defines }
  1576. def_symbol(upper(target_info.shortname));
  1577. def_symbol('FPC');
  1578. def_symbol('VER'+version_nr);
  1579. def_symbol('VER'+version_nr+'_'+release_nr);
  1580. def_symbol('VER'+version_nr+'_'+release_nr+'_'+patch_nr);
  1581. { Temporary defines, until things settle down }
  1582. def_symbol('HASWIDECHAR');
  1583. def_symbol('HASWIDESTRING');
  1584. def_symbol('HASOUT');
  1585. def_symbol('HASGLOBALPROPERTY');
  1586. def_symbol('FPC_HASPREFETCH');
  1587. {$ifdef i386}
  1588. def_symbol('HASINTF');
  1589. def_symbol('HASVARIANT');
  1590. {$endif i386}
  1591. {$ifdef x86_64}
  1592. def_symbol('HASINTF');
  1593. def_symbol('HASVARIANT');
  1594. {$endif x86_64}
  1595. {$ifdef powerpc}
  1596. def_symbol('HASINTF');
  1597. def_symbol('HASVARIANT');
  1598. def_symbol('FPC_MTFSB0_CORRECTED');
  1599. {$endif powerpc}
  1600. {$ifdef arm}
  1601. def_symbol('HASINTF');
  1602. def_symbol('HASVARIANT');
  1603. {$endif arm}
  1604. {$ifdef sparc}
  1605. def_symbol('HASINTF');
  1606. def_symbol('HASVARIANT');
  1607. {$endif sparc}
  1608. def_symbol('INTERNSETLENGTH');
  1609. def_symbol('INTERNLENGTH');
  1610. def_symbol('INTERNCOPY');
  1611. def_symbol('INT64FUNCRESOK');
  1612. def_symbol('HAS_ADDR_STACK_ON_STACK');
  1613. def_symbol('NOBOUNDCHECK');
  1614. def_symbol('HASCOMPILERPROC');
  1615. def_symbol('VALUEGETMEM');
  1616. def_symbol('VALUEFREEMEM');
  1617. def_symbol('HASCURRENCY');
  1618. def_symbol('HASTHREADVAR');
  1619. def_symbol('HAS_GENERICCONSTRUCTOR');
  1620. def_symbol('NOCLASSHELPERS');
  1621. if pocall_default = pocall_register then
  1622. def_symbol('REGCALL');
  1623. def_symbol('DECRREFNOTNIL');
  1624. def_symbol('HAS_INTERNAL_INTTYPES');
  1625. def_symbol('STR_USES_VALINT');
  1626. { using a case is pretty useless here (FK) }
  1627. { some stuff for TP compatibility }
  1628. {$ifdef i386}
  1629. def_symbol('CPU86');
  1630. def_symbol('CPU87');
  1631. {$endif}
  1632. {$ifdef m68k}
  1633. def_symbol('CPU68');
  1634. {$endif}
  1635. { new processor stuff }
  1636. {$ifdef i386}
  1637. def_symbol('CPUI386');
  1638. def_symbol('CPU32');
  1639. def_symbol('FPC_HAS_TYPE_EXTENDED');
  1640. def_symbol('FPC_HAS_TYPE_DOUBLE');
  1641. def_symbol('FPC_HAS_TYPE_SINGLE');
  1642. {$endif}
  1643. {$ifdef m68k}
  1644. def_symbol('CPU68K');
  1645. def_symbol('CPUM68K');
  1646. def_symbol('CPU32');
  1647. def_symbol('FPC_CURRENCY_IS_INT64');
  1648. def_symbol('FPC_COMP_IS_INT64');
  1649. {$endif}
  1650. {$ifdef ALPHA}
  1651. def_symbol('CPUALPHA');
  1652. def_symbol('CPU64');
  1653. {$endif}
  1654. {$ifdef powerpc}
  1655. def_symbol('CPUPOWERPC');
  1656. def_symbol('CPUPOWERPC32');
  1657. def_symbol('CPU32');
  1658. def_symbol('FPC_HAS_TYPE_DOUBLE');
  1659. def_symbol('FPC_HAS_TYPE_SINGLE');
  1660. def_symbol('FPC_INCLUDE_SOFTWARE_INT64_TO_DOUBLE');
  1661. def_symbol('FPC_CURRENCY_IS_INT64');
  1662. def_symbol('FPC_COMP_IS_INT64');
  1663. {$endif}
  1664. {$ifdef iA64}
  1665. def_symbol('CPUIA64');
  1666. def_symbol('CPU64');
  1667. {$endif}
  1668. {$ifdef x86_64}
  1669. def_symbol('CPUX86_64');
  1670. def_symbol('CPUAMD64');
  1671. def_symbol('CPU64');
  1672. { not supported for now, afaik (FK)
  1673. def_symbol('FPC_HAS_TYPE_FLOAT128'); }
  1674. def_symbol('FPC_HAS_TYPE_EXTENDED');
  1675. def_symbol('FPC_HAS_TYPE_DOUBLE');
  1676. def_symbol('FPC_HAS_TYPE_SINGLE');
  1677. {$endif}
  1678. {$ifdef sparc}
  1679. def_symbol('CPUSPARC');
  1680. def_symbol('CPUSPARC32');
  1681. def_symbol('CPU32');
  1682. def_symbol('FPC_HAS_TYPE_DOUBLE');
  1683. def_symbol('FPC_HAS_TYPE_SINGLE');
  1684. def_symbol('FPC_INCLUDE_SOFTWARE_INT64_TO_DOUBLE');
  1685. def_symbol('FPC_CURRENCY_IS_INT64');
  1686. def_symbol('FPC_COMP_IS_INT64');
  1687. def_symbol('FPC_REQUIRES_PROPER_ALIGNMENT');
  1688. {$endif}
  1689. {$ifdef vis}
  1690. def_symbol('CPUVIS');
  1691. def_symbol('CPU32');
  1692. {$endif}
  1693. {$ifdef arm}
  1694. def_symbol('CPUARM');
  1695. def_symbol('CPU32');
  1696. def_symbol('FPC_HAS_TYPE_DOUBLE');
  1697. def_symbol('FPC_HAS_TYPE_SINGLE');
  1698. def_symbol('FPC_INCLUDE_SOFTWARE_INT64_TO_DOUBLE');
  1699. def_symbol('FPC_CURRENCY_IS_INT64');
  1700. def_symbol('FPC_COMP_IS_INT64');
  1701. def_symbol('FPC_REQUIRES_PROPER_ALIGNMENT');
  1702. {$endif arm}
  1703. { get default messagefile }
  1704. {$ifdef Delphi}
  1705. msgfilename:=dmisc.getenv('PPC_ERROR_FILE');
  1706. {$else Delphi}
  1707. msgfilename:=dos.getenv('PPC_ERROR_FILE');
  1708. {$endif Delphi}
  1709. { default configfile can be specified on the commandline,
  1710. remove it first }
  1711. if (cmd<>'') and (cmd[1]='[') then
  1712. begin
  1713. ppccfg:=Copy(cmd,2,pos(']',cmd)-2);
  1714. Delete(cmd,1,pos(']',cmd));
  1715. end
  1716. else
  1717. begin
  1718. ppccfg:='fpc.cfg';
  1719. ppcaltcfg:='ppc386.cfg';
  1720. end;
  1721. { read the parameters quick, only -i -v -T }
  1722. option.firstpass:=true;
  1723. if cmd<>'' then
  1724. option.parsecmd(cmd)
  1725. else
  1726. begin
  1727. option.read_parameters;
  1728. { Write only quickinfo }
  1729. if option.quickinfo<>'' then
  1730. option.writequickinfo;
  1731. end;
  1732. option.firstpass:=false;
  1733. { read configuration file }
  1734. if (not disable_configfile) and
  1735. (ppccfg<>'') then
  1736. begin
  1737. read_configfile:=check_configfile(ppccfg,ppccfg);
  1738. { Maybe alternative configfile ? }
  1739. if (not read_configfile) and
  1740. (ppcaltcfg<>'') then
  1741. read_configfile:=check_configfile(ppcaltcfg,ppccfg);
  1742. end
  1743. else
  1744. read_configfile := false;
  1745. { Read commandline and configfile }
  1746. target_is_set:=false;
  1747. asm_is_set:=false;
  1748. param_file:='';
  1749. { read configfile }
  1750. if read_configfile then
  1751. option.interpret_file(ppccfg);
  1752. { read parameters again to override config file }
  1753. if cmd<>'' then
  1754. option.parsecmd(cmd)
  1755. else
  1756. begin
  1757. option.read_parameters;
  1758. { Write only quickinfo }
  1759. if option.quickinfo<>'' then
  1760. option.writequickinfo;
  1761. end;
  1762. { Write help pages }
  1763. if (cmd='') and (paramcount=0) then
  1764. Option.WriteHelpPages;
  1765. { Stop if errors in options }
  1766. if ErrorCount>0 then
  1767. StopOptions;
  1768. { Non-core target defines }
  1769. Option.TargetDefines(true);
  1770. { endian define }
  1771. case target_info.endian of
  1772. endian_little :
  1773. begin
  1774. def_symbol('ENDIAN_LITTLE');
  1775. def_symbol('FPC_LITTLE_ENDIAN');
  1776. end;
  1777. endian_big :
  1778. begin
  1779. def_symbol('ENDIAN_BIG');
  1780. def_symbol('FPC_BIG_ENDIAN');
  1781. end;
  1782. end;
  1783. { abi define }
  1784. case target_info.abi of
  1785. abi_powerpc_sysv :
  1786. def_symbol('FPC_ABI_SYSV');
  1787. abi_powerpc_aix :
  1788. def_symbol('FPC_ABI_AIX');
  1789. end;
  1790. {$ifdef m68k}
  1791. if initoptprocessor=MC68020 then
  1792. def_symbol('CPUM68020');
  1793. {$endif m68k}
  1794. { write logo if set }
  1795. if option.DoWriteLogo then
  1796. option.WriteLogo;
  1797. { Check file to compile }
  1798. if param_file='' then
  1799. begin
  1800. Message(option_no_source_found);
  1801. StopOptions;
  1802. end;
  1803. {$ifndef Unix}
  1804. param_file:=FixFileName(param_file);
  1805. {$endif}
  1806. fsplit(param_file,inputdir,inputfile,inputextension);
  1807. if inputextension='' then
  1808. begin
  1809. if FileExists(inputdir+inputfile+target_info.sourceext) then
  1810. inputextension:=target_info.sourceext
  1811. else
  1812. if FileExists(inputdir+inputfile+target_info.pasext) then
  1813. inputextension:=target_info.pasext;
  1814. end;
  1815. { Add paths specified with parameters to the searchpaths }
  1816. UnitSearchPath.AddList(option.ParaUnitPath,true);
  1817. ObjectSearchPath.AddList(option.ParaObjectPath,true);
  1818. IncludeSearchPath.AddList(option.ParaIncludePath,true);
  1819. LibrarySearchPath.AddList(option.ParaLibraryPath,true);
  1820. { add unit environment and exepath to the unit search path }
  1821. if inputdir<>'' then
  1822. Unitsearchpath.AddPath(inputdir,true);
  1823. if not disable_configfile then
  1824. begin
  1825. {$ifdef Delphi}
  1826. UnitSearchPath.AddPath(dmisc.getenv(target_info.unit_env),false);
  1827. {$else}
  1828. UnitSearchPath.AddPath(dos.getenv(target_info.unit_env),false);
  1829. {$endif Delphi}
  1830. end;
  1831. {$ifdef Unix}
  1832. fpcdir:=FixPath(getenv('FPCDIR'),false);
  1833. if fpcdir='' then
  1834. begin
  1835. if source_info.cpu<>target_info.cpu then
  1836. begin
  1837. if PathExists('/usr/local/lib/fpc/'+version_string+'/cross/'+cpu2str[target_info.cpu]+'-'+target_info.shortname) then
  1838. fpcdir:='/usr/local/lib/fpc/'+version_string+'/cross/'+cpu2str[target_info.cpu]+'-'+target_info.shortname+'/'
  1839. else
  1840. fpcdir:='/usr/lib/fpc/'+version_string+'/cross/'+cpu2str[target_info.cpu]+'-'+target_info.shortname+'/';
  1841. end
  1842. else
  1843. begin
  1844. if PathExists('/usr/local/lib/fpc/'+version_string) then
  1845. fpcdir:='/usr/local/lib/fpc/'+version_string+'/'
  1846. else
  1847. fpcdir:='/usr/lib/fpc/'+version_string+'/';
  1848. end;
  1849. end;
  1850. {$else}
  1851. fpcdir:=FixPath(getenv('FPCDIR'),false);
  1852. if fpcdir='' then
  1853. begin
  1854. fpcdir:=ExePath+'../';
  1855. if not(PathExists(fpcdir+'/units')) and
  1856. not(PathExists(fpcdir+'/rtl')) then
  1857. fpcdir:=fpcdir+'../';
  1858. end;
  1859. {$endif}
  1860. { first try development RTL, else use the default installation path }
  1861. if not disable_configfile then
  1862. begin
  1863. if source_info.cpu<>target_info.cpu then
  1864. begin
  1865. if PathExists(FpcDir+'rtl/'+lower(target_info.shortname)) then
  1866. UnitSearchPath.AddPath(FpcDir+'rtl/'+lower(target_info.shortname),false)
  1867. else
  1868. begin
  1869. UnitSearchPath.AddPath(FpcDir+'units/',false);
  1870. UnitSearchPath.AddPath(FpcDir+'units/rtl',false);
  1871. end;
  1872. end
  1873. else
  1874. begin
  1875. if PathExists(FpcDir+'rtl/'+lower(target_info.shortname)) then
  1876. UnitSearchPath.AddPath(FpcDir+'rtl/'+lower(target_info.shortname),false)
  1877. else
  1878. begin
  1879. UnitSearchPath.AddPath(FpcDir+'units/'+lower(target_info.shortname),false);
  1880. UnitSearchPath.AddPath(FpcDir+'units/'+lower(target_info.shortname)+'/rtl',false);
  1881. end;
  1882. end;
  1883. end;
  1884. { Add exepath if the exe is not in the current dir, because that is always searched already.
  1885. Do not add it when linking on the target because then we can maybe already find
  1886. .o files that are not for the target }
  1887. if (ExePath<>GetCurrentDir) and
  1888. not(cs_link_on_target in initglobalswitches) then
  1889. UnitSearchPath.AddPath(ExePath,false);
  1890. { Add unit dir to the object and library path }
  1891. objectsearchpath.AddList(unitsearchpath,false);
  1892. librarysearchpath.AddList(unitsearchpath,false);
  1893. { switch assembler if it's binary and we got -a on the cmdline }
  1894. if (cs_asm_leave in initglobalswitches) and
  1895. (af_outputbinary in target_asm.flags) then
  1896. begin
  1897. Message(option_switch_bin_to_src_assembler);
  1898. set_target_asm(target_info.assemextern);
  1899. end;
  1900. if (target_asm.supported_target <> system_any) and
  1901. (target_asm.supported_target <> target_info.system) then
  1902. begin
  1903. Message2(option_incompatible_asm,target_asm.idtxt,target_info.name);
  1904. set_target_asm(target_info.assemextern);
  1905. Message1(option_asm_forced,target_asm.idtxt);
  1906. end;
  1907. { turn off stripping if compiling with debuginfo or profile }
  1908. if (cs_debuginfo in initmoduleswitches) or
  1909. (cs_profile in initmoduleswitches) then
  1910. exclude(initglobalswitches,cs_link_strip);
  1911. {$ifdef x86_64}
  1912. {$warning HACK: turn off smartlinking}
  1913. exclude(initmoduleswitches,cs_create_smart);
  1914. {$endif}
  1915. if not LinkTypeSetExplicitly then
  1916. set_default_link_type;
  1917. { Default alignment settings,
  1918. 1. load the defaults for the target
  1919. 2. override with generic optimizer setting (little size)
  1920. 3. override with the user specified -Oa }
  1921. UpdateAlignment(initalignment,target_info.alignment);
  1922. if (cs_littlesize in aktglobalswitches) then
  1923. begin
  1924. initalignment.procalign:=1;
  1925. initalignment.jumpalign:=1;
  1926. initalignment.loopalign:=1;
  1927. end;
  1928. UpdateAlignment(initalignment,option.paraalignment);
  1929. option.free;
  1930. Option:=nil;
  1931. end;
  1932. initialization
  1933. coption:=toption;
  1934. finalization
  1935. if assigned(option) then
  1936. option.free;
  1937. end.
  1938. {
  1939. $Log$
  1940. Revision 1.136 2004-06-20 08:55:30 florian
  1941. * logs truncated
  1942. Revision 1.135 2004/06/16 20:07:09 florian
  1943. * dwarf branch merged
  1944. Revision 1.134 2004/05/06 20:30:51 florian
  1945. * m68k compiler compilation fixed
  1946. Revision 1.133.2.10 2004/05/18 20:24:03 florian
  1947. * fixed crash with unknown symbols
  1948. Revision 1.133.2.9 2004/05/13 20:10:38 florian
  1949. * released variant and interface support
  1950. Revision 1.133.2.8 2004/05/03 14:59:57 peter
  1951. * no dlltool needed for win32 linking executables
  1952. }