options.pas 43 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374
  1. {
  2. $Id$
  3. Copyright (c) 1993-98 by the FPC development team
  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. interface
  20. uses
  21. globtype,globals,verbose;
  22. type
  23. POption=^TOption;
  24. TOption=object
  25. FirstPass,
  26. NoPressEnter,
  27. DoWriteLogo : boolean;
  28. FileLevel : longint;
  29. ParaIncludePath,
  30. ParaUnitPath,
  31. ParaObjectPath,
  32. ParaLibraryPath : TSearchPathList;
  33. Constructor Init;
  34. Destructor Done;
  35. procedure WriteLogo;
  36. procedure WriteInfo;
  37. procedure WriteHelpPages;
  38. procedure QuickInfo(const s:string);
  39. procedure IllegalPara(const opt:string);
  40. function Unsetbool(const opts:string; pos: Longint):boolean;
  41. procedure interpret_proc_specific_options(const opt:string);virtual;
  42. procedure interpret_option(const opt :string);
  43. procedure Interpret_file(const filename : string);
  44. procedure Read_Parameters;
  45. procedure parsecmd(cmd:string);
  46. end;
  47. procedure read_arguments(cmd:string);
  48. implementation
  49. uses
  50. {$ifdef Delphi}
  51. dmisc,
  52. {$else Delphi}
  53. dos,
  54. {$endif Delphi}
  55. version,systems,
  56. cobjects,
  57. symtable,scanner,link,messages
  58. {$ifdef BrowserLog}
  59. ,browlog
  60. {$endif BrowserLog}
  61. {$ifdef i386}
  62. ,opts386
  63. {$endif}
  64. {$ifdef m68k}
  65. ,opts68k
  66. {$endif}
  67. ;
  68. const
  69. page_size = 24;
  70. var
  71. read_configfile, { read config file, set when a cfgfile is found }
  72. target_is_set : boolean; { do not allow contradictory target settings }
  73. asm_is_set : boolean; { -T also change initoutputformat if not set idrectly }
  74. ppccfg,
  75. msgfilename,
  76. param_file : string; { file to compile specified on the commandline }
  77. {****************************************************************************
  78. Defines
  79. ****************************************************************************}
  80. procedure def_symbol(const s : string);
  81. begin
  82. if s='' then
  83. exit;
  84. initdefines.concat(new(pstring_item,init(upper(s))));
  85. end;
  86. procedure undef_symbol(const s : string);
  87. var
  88. item,next : pstring_item;
  89. begin
  90. if s='' then
  91. exit;
  92. item:=pstring_item(initdefines.first);
  93. while assigned(item) do
  94. begin
  95. if (item^.str^=s) then
  96. begin
  97. next:=pstring_item(item^.next);
  98. initdefines.remove(item);
  99. dispose(item,done);
  100. item:=next;
  101. end
  102. else
  103. if item<>pstring_item(item^.next) then
  104. item:=pstring_item(item^.next)
  105. else
  106. break;
  107. end;
  108. end;
  109. function check_symbol(const s:string):boolean;
  110. var
  111. hp : pstring_item;
  112. begin
  113. hp:=pstring_item(initdefines.first);
  114. while assigned(hp) do
  115. begin
  116. if (hp^.str^=s) then
  117. begin
  118. check_symbol:=true;
  119. exit;
  120. end;
  121. hp:=pstring_item(hp^.next);
  122. end;
  123. check_symbol:=false;
  124. end;
  125. procedure MaybeLoadMessageFile;
  126. begin
  127. { Load new message file }
  128. if (msgfilename<>'') then
  129. begin
  130. if fileexists(msgfilename) then
  131. LoadMsgFile(msgfilename);
  132. msgfilename:='';
  133. end;
  134. end;
  135. {****************************************************************************
  136. Toption
  137. ****************************************************************************}
  138. procedure Toption.WriteLogo;
  139. var
  140. i : tmsgconst;
  141. begin
  142. MaybeLoadMessageFile;
  143. for i:=option_logo_start to option_logo_end do
  144. Message1(i,target_cpu_string);
  145. end;
  146. procedure Toption.WriteInfo;
  147. var
  148. i : tmsgconst;
  149. begin
  150. MaybeLoadMessageFile;
  151. for i:=option_info_start to option_info_end do
  152. Message(i);
  153. Stop;
  154. end;
  155. procedure Toption.WriteHelpPages;
  156. function PadEnd(s:string;i:longint):string;
  157. begin
  158. while (length(s)<i) do
  159. s:=s+' ';
  160. PadEnd:=s;
  161. end;
  162. var
  163. idx,
  164. lastident,
  165. j,outline,
  166. ident,
  167. lines : longint;
  168. show : boolean;
  169. opt : string[32];
  170. input,
  171. s : string;
  172. begin
  173. MaybeLoadMessageFile;
  174. Message1(option_usage,paramstr(0));
  175. lastident:=0;
  176. if DoWriteLogo then
  177. lines:=3
  178. else
  179. lines:=1;
  180. for idx:=ord(ol_begin) to ord(ol_end) do
  181. begin
  182. { get a line and reset }
  183. s:=msg^.Get(idx);
  184. ident:=0;
  185. show:=false;
  186. { parse options }
  187. case s[1] of
  188. {$ifdef i386}
  189. '3',
  190. {$endif}
  191. {$ifdef m68k}
  192. '6',
  193. {$endif}
  194. '*' : show:=true;
  195. end;
  196. if show then
  197. begin
  198. case s[2] of
  199. {$ifdef TP}
  200. 't',
  201. {$endif}
  202. {$ifdef GDB}
  203. 'g',
  204. {$endif}
  205. {$ifdef linux}
  206. 'L',
  207. {$endif}
  208. {$ifdef os2}
  209. 'O',
  210. {$endif}
  211. '*' : show:=true;
  212. else
  213. show:=false;
  214. end;
  215. end;
  216. { now we may show the message or not }
  217. if show then
  218. begin
  219. case s[3] of
  220. '0' : begin
  221. ident:=0;
  222. outline:=0;
  223. end;
  224. '1' : begin
  225. ident:=2;
  226. outline:=7;
  227. end;
  228. '2' : begin
  229. ident:=11;
  230. outline:=11;
  231. end;
  232. '3' : begin
  233. ident:=21;
  234. outline:=6;
  235. end;
  236. end;
  237. j:=pos('_',s);
  238. opt:=Copy(s,4,j-4);
  239. if opt='*' then
  240. opt:=''
  241. else
  242. opt:=PadEnd('-'+opt,outline);
  243. if (ident=0) and (lastident<>0) then
  244. begin
  245. Comment(V_Normal,'');
  246. inc(Lines);
  247. end;
  248. { page full ? }
  249. if (lines>=page_size) then
  250. begin
  251. if not NoPressEnter then
  252. begin
  253. write('*** press enter ***');
  254. readln(input);
  255. if upper(input)='Q' then
  256. stop;
  257. end;
  258. lines:=0;
  259. end;
  260. Comment(V_Normal,PadEnd('',ident)+opt+Copy(s,j+1,255));
  261. LastIdent:=Ident;
  262. inc(Lines);
  263. end;
  264. end;
  265. stop;
  266. end;
  267. procedure Toption.QuickInfo(const s:string);
  268. begin
  269. if source_os.newline=#13#10 then
  270. Write(s+#10)
  271. else
  272. Writeln(s);
  273. Stop;
  274. end;
  275. procedure Toption.IllegalPara(const opt:string);
  276. begin
  277. Message1(option_illegal_para,opt);
  278. Message(option_help_pages_para);
  279. stop;
  280. end;
  281. function Toption.Unsetbool(const opts:string; pos: Longint):boolean;
  282. { checks if the character after pos in Opts is a + or a - and returns resp.
  283. false or true. If it is another character (or none), it also returns false }
  284. begin
  285. UnsetBool := (Length(Opts) > Pos) And (Opts[Succ(Pos)] = '-');
  286. end;
  287. procedure TOption.interpret_proc_specific_options(const opt:string);
  288. begin
  289. end;
  290. procedure TOption.interpret_option(const opt:string);
  291. var
  292. code : integer;
  293. c : char;
  294. more : string;
  295. j,l : longint;
  296. d : DirStr;
  297. e : ExtStr;
  298. begin
  299. if opt='' then
  300. exit;
  301. case opt[1] of
  302. '-' : begin
  303. more:=Copy(opt,3,255);
  304. case opt[2] of
  305. '!' : initlocalswitches:=initlocalswitches+[cs_ansistrings];
  306. '?' : WriteHelpPages;
  307. 'a' : begin
  308. initglobalswitches:=initglobalswitches+[cs_asm_leave];
  309. for j:=1 to length(more) do
  310. case more[j] of
  311. 'l' : initglobalswitches:=initglobalswitches+[cs_asm_source];
  312. 'r' : initglobalswitches:=initglobalswitches+[cs_asm_regalloc];
  313. 't' : initglobalswitches:=initglobalswitches+[cs_asm_tempalloc];
  314. '-' : initglobalswitches:=initglobalswitches-[cs_asm_leave,cs_asm_source,cs_asm_regalloc];
  315. else
  316. IllegalPara(opt);
  317. end;
  318. end;
  319. 'A' : begin
  320. if set_string_asm(More) then
  321. begin
  322. initoutputformat:=target_asm.id;
  323. asm_is_set:=true;
  324. end
  325. else
  326. IllegalPara(opt);
  327. end;
  328. 'b' : begin
  329. {$ifdef BrowserLog}
  330. initglobalswitches:=initglobalswitches+[cs_browser_log];
  331. {$endif}
  332. if More<>'' then
  333. if More='l' then
  334. initmoduleswitches:=initmoduleswitches+[cs_local_browser]
  335. else if More='-' then
  336. begin
  337. initmoduleswitches:=initmoduleswitches-[cs_browser,cs_local_browser];
  338. {$ifdef BrowserLog}
  339. initglobalswitches:=initglobalswitches-[cs_browser_log];
  340. {$endif}
  341. end
  342. else if More<>'+' then
  343. {$ifdef BrowserLog}
  344. browserlog.elements_to_list^.insert(more);
  345. {$else}
  346. IllegalPara(opt);
  347. {$endif}
  348. end;
  349. 'B' : if more='' then
  350. do_build:=true
  351. else
  352. if more = '-' then
  353. do_build := False
  354. else
  355. IllegalPara(opt);
  356. 'C' : begin
  357. j := 1;
  358. while j <= length(more) Do
  359. Begin
  360. case more[j] of
  361. 'a' : Simplify_ppu:=true;
  362. 'h' :
  363. begin
  364. val(copy(more,j+1,length(more)-j),heapsize,code);
  365. if (code<>0) or (heapsize>=67107840) or (heapsize<1024) then
  366. IllegalPara(opt);
  367. break;
  368. end;
  369. 'i' : If UnsetBool(More, j) then
  370. Begin
  371. initlocalswitches:=initlocalswitches-[cs_check_io];
  372. inc(j)
  373. End
  374. else initlocalswitches:=initlocalswitches+[cs_check_io];
  375. 'n' : If UnsetBool(More, j) then
  376. Begin
  377. initglobalswitches:=initglobalswitches-[cs_link_extern];
  378. inc(j)
  379. End
  380. Else initglobalswitches:=initglobalswitches+[cs_link_extern];
  381. 'o' :
  382. If UnsetBool(More, j) then
  383. Begin
  384. initlocalswitches:=initlocalswitches-[cs_check_overflow];
  385. inc(j);
  386. End
  387. Else
  388. initlocalswitches:=initlocalswitches+[cs_check_overflow];
  389. 'r' :
  390. If UnsetBool(More, j) then
  391. Begin
  392. initlocalswitches:=initlocalswitches-[cs_check_range];
  393. inc(j);
  394. End
  395. Else
  396. initlocalswitches:=initlocalswitches+[cs_check_range];
  397. 's' :
  398. begin
  399. val(copy(more,j+1,length(more)-j),stacksize,code);
  400. if (code<>0) or (stacksize>=67107840) or (stacksize<1024) then
  401. IllegalPara(opt);
  402. break;
  403. end;
  404. 't' :
  405. If UnsetBool(More, j) then
  406. Begin
  407. initlocalswitches:=initlocalswitches-[cs_check_stack];
  408. inc(j)
  409. End
  410. Else
  411. initlocalswitches:=initlocalswitches+[cs_check_stack];
  412. 'D' :
  413. If UnsetBool(More, j) then
  414. Begin
  415. initmoduleswitches:=initmoduleswitches-[cs_create_dynamic];
  416. inc(j)
  417. End
  418. Else
  419. initmoduleswitches:=initmoduleswitches+[cs_create_dynamic];
  420. 'X' :
  421. If UnsetBool(More, j) then
  422. Begin
  423. initmoduleswitches:=initmoduleswitches-[cs_create_smart];
  424. inc(j)
  425. End
  426. Else
  427. initmoduleswitches:=initmoduleswitches+[cs_create_smart];
  428. else
  429. IllegalPara(opt);
  430. end;
  431. inc(j);
  432. end;
  433. end;
  434. 'd' : def_symbol(more);
  435. 'D' : begin
  436. initglobalswitches:=initglobalswitches+[cs_link_deffile];
  437. for j:=1 to length(more) do
  438. case more[j] of
  439. 'd' : begin
  440. description:=Copy(more,j+1,255);
  441. break;
  442. end;
  443. 'w' : usewindowapi:=true;
  444. else
  445. IllegalPara(opt);
  446. end;
  447. end;
  448. 'e' : exepath:=FixPath(More,true);
  449. { Just used by RHIDE }
  450. 'E' : if (length(more)=0) or (UnsetBool(More, 0)) then
  451. initglobalswitches:=initglobalswitches+[cs_link_extern]
  452. else
  453. initglobalswitches:=initglobalswitches-[cs_link_extern];
  454. 'F' : begin
  455. c:=more[1];
  456. Delete(more,1,1);
  457. case c of
  458. 'D' : utilsdirectory:=FixPath(More,true);
  459. 'e' : SetRedirectFile(More);
  460. 'E' : OutputExeDir:=FixPath(More,true);
  461. 'i' : if firstpass then
  462. includesearchpath.AddPath(More,false)
  463. else
  464. ParaIncludePath.AddPath(More,false);
  465. 'g' : Message2(option_obsolete_switch_use_new,'-Fg','-Fl');
  466. 'l' : if firstpass then
  467. LibrarySearchPath.AddPath(More,false)
  468. else
  469. ParaLibraryPath.AddPath(More,false);
  470. 'L' : if More<>'' then
  471. ParaDynamicLinker:=More
  472. else
  473. IllegalPara(opt);
  474. 'o' : if firstpass then
  475. ObjectSearchPath.AddPath(More,false)
  476. else
  477. ParaObjectPath.AddPath(More,false);
  478. 'r' : Msgfilename:=More;
  479. 'u' : if firstpass then
  480. unitsearchpath.AddPath(More,false)
  481. else
  482. ParaUnitPath.AddPath(More,false);
  483. 'U' : OutputUnitDir:=FixPath(More,true);
  484. else
  485. IllegalPara(opt);
  486. end;
  487. end;
  488. 'g' : begin
  489. if UnsetBool(More, 0) then
  490. initmoduleswitches:=initmoduleswitches-[cs_debuginfo]
  491. else
  492. begin
  493. {$ifdef GDB}
  494. initmoduleswitches:=initmoduleswitches+[cs_debuginfo];
  495. if not RelocSectionSetExplicitly then
  496. RelocSection:=false;
  497. for j:=1 to length(more) do
  498. case more[j] of
  499. 'd' : initglobalswitches:=initglobalswitches+[cs_gdb_dbx];
  500. 'g' : initglobalswitches:=initglobalswitches+[cs_gdb_gsym];
  501. 'h' : initglobalswitches:=initglobalswitches+[cs_gdb_heaptrc];
  502. 'c' : initglobalswitches:=initglobalswitches+[cs_checkpointer];
  503. {$ifdef EXTDEBUG}
  504. 'p' : only_one_pass:=true;
  505. {$endif EXTDEBUG}
  506. else
  507. IllegalPara(opt);
  508. end;
  509. {$else GDB}
  510. Message(option_no_debug_support);
  511. Message(option_no_debug_support_recompile_fpc);
  512. {$endif GDB}
  513. end;
  514. end;
  515. 'h' : begin
  516. NoPressEnter:=true;
  517. WriteHelpPages;
  518. end;
  519. 'i' : if more='' then
  520. WriteInfo
  521. else
  522. begin
  523. { Specific info, which can be used in Makefiles }
  524. case More[1] of
  525. {$ifdef FPC_USE_CPREFIX}
  526. 'C' : QuickInfo('use C prefix');
  527. {$endif FPC_USE_CPREFIX}
  528. 'S' : begin
  529. case More[2] of
  530. 'O' : QuickInfo(source_os.shortname);
  531. {$ifdef Delphi !!!!!!!!!}
  532. 'P' : QuickInfo('unknown');
  533. {$else}
  534. 'P' : QuickInfo(source_cpu_string);
  535. {$endif}
  536. end;
  537. end;
  538. 'T' : begin
  539. case More[2] of
  540. 'O' : QuickInfo(target_os.shortname);
  541. 'P' : QuickInfo(target_cpu_string);
  542. end;
  543. end;
  544. 'V' : QuickInfo(version_string);
  545. 'D' : QuickInfo(date_string);
  546. else
  547. IllegalPara(Opt);
  548. end;
  549. end;
  550. 'I' : if firstpass then
  551. includesearchpath.AddPath(More,false)
  552. else
  553. ParaIncludePath.AddPath(More,false);
  554. 'k' : if more<>'' then
  555. ParaLinkOptions:=ParaLinkOptions+' '+More
  556. else
  557. IllegalPara(opt);
  558. 'l' : if more='' then
  559. DoWriteLogo:=true
  560. else
  561. IllegalPara(opt);
  562. 'm' : parapreprocess:=true;
  563. 'n' : if More='' then
  564. read_configfile:=false
  565. else
  566. IllegalPara(opt);
  567. 'o' : if More<>'' then
  568. Fsplit(More,d,OutputFile,e)
  569. else
  570. IllegalPara(opt);
  571. 'p' : begin
  572. if UnsetBool(More, 0) then
  573. begin
  574. initmoduleswitches:=initmoduleswitches-[cs_profile];
  575. undef_symbol('FPC_PROFILE');
  576. end
  577. else
  578. case more[1] of
  579. 'g' : if (length(opt)=3) and UnsetBool(more, 1) then
  580. begin
  581. initmoduleswitches:=initmoduleswitches-[cs_profile];
  582. undef_symbol('FPC_PROFILE');
  583. end
  584. else
  585. begin
  586. initmoduleswitches:=initmoduleswitches+[cs_profile];
  587. def_symbol('FPC_PROFILE');
  588. end;
  589. else
  590. IllegalPara(opt);
  591. end;
  592. end;
  593. {$ifdef linux}
  594. 'P' : initglobalswitches:=initglobalswitches+[cs_asm_pipe];
  595. {$endif}
  596. 's' : initglobalswitches:=initglobalswitches+[cs_asm_extern,cs_link_extern];
  597. 'S' : begin
  598. for j:=1 to length(more) do
  599. case more[j] of
  600. '2' : initmodeswitches:=objfpcmodeswitches;
  601. 'c' : initmoduleswitches:=initmoduleswitches+[cs_support_c_operators];
  602. 'd' : initmodeswitches:=delphimodeswitches;
  603. 'e' : begin
  604. val(copy(more,j+1,length(more)-j),l,code);
  605. if (code<>0) then
  606. SetMaxErrorCount(1)
  607. else
  608. begin
  609. SetMaxErrorCount(l);
  610. break;
  611. end;
  612. end;
  613. 'g' : initmoduleswitches:=initmoduleswitches+[cs_support_goto];
  614. 'h' : initlocalswitches:=initlocalswitches+[cs_ansistrings];
  615. 'i' : initmoduleswitches:=initmoduleswitches+[cs_support_inline];
  616. 'm' : initmoduleswitches:=initmoduleswitches+[cs_support_macro];
  617. 'o': initmodeswitches:=tpmodeswitches;
  618. 'p' : initmodeswitches:=gpcmodeswitches;
  619. 's' : initglobalswitches:=initglobalswitches+[cs_constructor_name];
  620. 't' : initmoduleswitches:=initmoduleswitches+[cs_static_keyword];
  621. 'v' : Message1(option_obsolete_switch,'-Sv');
  622. else
  623. IllegalPara(opt);
  624. end;
  625. end;
  626. 'T' : begin
  627. more:=Upper(More);
  628. if not target_is_set then
  629. begin
  630. { remove old target define }
  631. undef_symbol(target_info.short_name);
  632. { load new target }
  633. if not(set_string_target(More)) then
  634. IllegalPara(opt);
  635. { set new define }
  636. def_symbol(target_info.short_name);
  637. if not asm_is_set then
  638. initoutputformat:=target_asm.id;
  639. target_is_set:=true;
  640. end
  641. else
  642. if More<>target_info.short_name then
  643. Message1(option_target_is_already_set,target_info.short_name);
  644. end;
  645. 'u' : undef_symbol(upper(More));
  646. 'U' : begin
  647. for j:=1 to length(more) do
  648. case more[j] of
  649. {$ifdef UNITALIASES}
  650. 'a' : begin
  651. AddUnitAlias(Copy(More,j+1,255));
  652. break;
  653. end;
  654. {$endif UNITALIASES}
  655. 'n' : initglobalswitches:=initglobalswitches-[cs_check_unit_name];
  656. 'p' : begin
  657. Message2(option_obsolete_switch_use_new,'-Up','-Fu');
  658. break;
  659. end;
  660. 's' : initmoduleswitches:=initmoduleswitches+[cs_compilesystem];
  661. else
  662. IllegalPara(opt);
  663. end;
  664. end;
  665. 'v' : if not setverbosity(More) then
  666. IllegalPara(opt);
  667. 'W' : begin
  668. for j:=1 to length(More) do
  669. case More[j] of
  670. 'B': {bind_win32_dll:=true}
  671. begin
  672. { -WB200000 means set prefered base address
  673. to $200000, but does not change relocsection boolean
  674. this way we can create both relocatble and
  675. non relocatable DLL at a specific base address PM }
  676. if (length(More)>j) then
  677. begin
  678. if DLLImageBase=nil then
  679. DLLImageBase:=StringDup(Copy(More,j+1,255));
  680. end
  681. else
  682. begin
  683. RelocSection:=true;
  684. RelocSectionSetExplicitly:=true;
  685. end;
  686. break;
  687. end;
  688. 'C': apptype:=at_cui;
  689. 'G': apptype:=at_gui;
  690. 'N': begin
  691. RelocSection:=false;
  692. RelocSectionSetExplicitly:=true;
  693. end;
  694. 'R': begin
  695. RelocSection:=true;
  696. RelocSectionSetExplicitly:=true;
  697. end;
  698. else
  699. IllegalPara(opt);
  700. end;
  701. end;
  702. 'X' : begin
  703. for j:=1 to length(More) do
  704. case More[j] of
  705. 'c' : initglobalswitches:=initglobalswitches+[cs_link_toc];
  706. 's' : initglobalswitches:=initglobalswitches+[cs_link_strip];
  707. 'D' : begin
  708. def_symbol('FPC_LINK_DYNAMIC');
  709. undef_symbol('FPC_LINK_SMART');
  710. undef_symbol('FPC_LINK_STATIC');
  711. initglobalswitches:=initglobalswitches+[cs_link_shared];
  712. initglobalswitches:=initglobalswitches-[cs_link_static,cs_link_smart];
  713. end;
  714. 'S' : begin
  715. def_symbol('FPC_LINK_STATIC');
  716. undef_symbol('FPC_LINK_SMART');
  717. undef_symbol('FPC_LINK_DYNAMIC');
  718. initglobalswitches:=initglobalswitches+[cs_link_static];
  719. initglobalswitches:=initglobalswitches-[cs_link_shared,cs_link_smart];
  720. end;
  721. 'X' : begin
  722. def_symbol('FPC_LINK_SMART');
  723. undef_symbol('FPC_LINK_STATIC');
  724. undef_symbol('FPC_LINK_DYNAMIC');
  725. initglobalswitches:=initglobalswitches+[cs_link_smart];
  726. initglobalswitches:=initglobalswitches-[cs_link_shared,cs_link_static];
  727. end;
  728. else
  729. IllegalPara(opt);
  730. end;
  731. end;
  732. { give processor specific options a chance }
  733. else
  734. interpret_proc_specific_options(opt);
  735. end;
  736. end;
  737. '@' : begin
  738. Message(option_no_nested_response_file);
  739. Stop;
  740. end;
  741. else
  742. begin
  743. if (length(param_file)<>0) then
  744. Message(option_only_one_source_support);
  745. param_file:=opt;
  746. end;
  747. end;
  748. end;
  749. procedure Toption.Interpret_file(const filename : string);
  750. procedure RemoveSep(var fn:string);
  751. var
  752. i : longint;
  753. begin
  754. i:=0;
  755. while (i<length(fn)) and (fn[i+1] in [',',' ',#9]) do
  756. inc(i);
  757. Delete(fn,1,i);
  758. i:=length(fn);
  759. while (i>0) and (fn[i] in [',',' ',#9]) do
  760. dec(i);
  761. fn:=copy(fn,1,i);
  762. end;
  763. function GetName(var fn:string):string;
  764. var
  765. i : longint;
  766. begin
  767. i:=0;
  768. while (i<length(fn)) and (fn[i+1] in ['a'..'z','A'..'Z','0'..'9','_','-']) do
  769. inc(i);
  770. GetName:=Copy(fn,1,i);
  771. Delete(fn,1,i);
  772. end;
  773. const
  774. maxlevel=16;
  775. var
  776. f : text;
  777. s,
  778. opts : string;
  779. skip : array[0..maxlevel-1] of boolean;
  780. level : longint;
  781. begin
  782. { avoid infinite loop }
  783. Inc(FileLevel);
  784. If FileLevel>MaxLevel then
  785. Message(option_too_many_cfg_files);
  786. { open file }
  787. assign(f,filename);
  788. {$ifdef extdebug}
  789. Comment(V_Info,'trying to open file: '+filename);
  790. {$endif extdebug}
  791. {$I-}
  792. reset(f);
  793. {$I+}
  794. if ioresult<>0 then
  795. begin
  796. Message1(option_unable_open_file,filename);
  797. exit;
  798. end;
  799. fillchar(skip,sizeof(skip),0);
  800. level:=0;
  801. while not eof(f) do
  802. begin
  803. readln(f,opts);
  804. RemoveSep(opts);
  805. if (opts<>'') then
  806. begin
  807. if opts[1]='#' then
  808. begin
  809. Delete(opts,1,1);
  810. s:=upper(GetName(opts));
  811. if (s='SECTION') then
  812. begin
  813. RemoveSep(opts);
  814. s:=upper(GetName(opts));
  815. if level=0 then
  816. skip[level]:=not (check_symbol(s) or (s='COMMON'));
  817. end
  818. else
  819. if (s='IFDEF') then
  820. begin
  821. RemoveSep(opts);
  822. if Level>=maxlevel then
  823. begin
  824. Message(option_too_many_ifdef);
  825. stop;
  826. end;
  827. inc(Level);
  828. skip[level]:=(skip[level-1] or (not check_symbol(upper(GetName(opts)))));
  829. end
  830. else
  831. if (s='IFNDEF') then
  832. begin
  833. RemoveSep(opts);
  834. if Level>=maxlevel then
  835. begin
  836. Message(option_too_many_ifdef);
  837. stop;
  838. end;
  839. inc(Level);
  840. skip[level]:=(skip[level-1] or (check_symbol(upper(GetName(opts)))));
  841. end
  842. else
  843. if (s='ELSE') then
  844. skip[level]:=skip[level-1] or (not skip[level])
  845. else
  846. if (s='ENDIF') then
  847. begin
  848. skip[level]:=false;
  849. if Level=0 then
  850. begin
  851. Message(option_too_many_endif);
  852. stop;
  853. end;
  854. dec(level);
  855. end
  856. else
  857. if (not skip[level]) then
  858. begin
  859. if (s='DEFINE') then
  860. begin
  861. RemoveSep(opts);
  862. def_symbol(upper(GetName(opts)));
  863. end
  864. else
  865. if (s='UNDEF') then
  866. begin
  867. RemoveSep(opts);
  868. undef_symbol(upper(GetName(opts)));
  869. end
  870. else
  871. if (s='WRITE') then
  872. begin
  873. Delete(opts,1,1);
  874. WriteLn(opts);
  875. end
  876. else
  877. if (s='INCLUDE') then
  878. begin
  879. Delete(opts,1,1);
  880. Interpret_file(opts);
  881. end;
  882. end;
  883. end
  884. else
  885. begin
  886. if (not skip[level]) and (opts[1]='-') then
  887. interpret_option(opts)
  888. end;
  889. end;
  890. end;
  891. if Level>0 then
  892. Message(option_too_less_endif);
  893. Close(f);
  894. Dec(FileLevel);
  895. end;
  896. procedure toption.read_parameters;
  897. var
  898. opts : string;
  899. paramindex : longint;
  900. begin
  901. paramindex:=0;
  902. while paramindex<paramcount do
  903. begin
  904. inc(paramindex);
  905. opts:=paramstr(paramindex);
  906. if firstpass then
  907. begin
  908. { only parse define,undef,target,verbosity and link options }
  909. if (opts[1]='-') and (opts[2] in ['i','d','v','T','u','n','X']) then
  910. interpret_option(opts);
  911. end
  912. else
  913. begin
  914. if opts[1]='@' then
  915. begin
  916. Delete(opts,1,1);
  917. Message1(option_reading_further_from,opts);
  918. interpret_file(opts);
  919. end
  920. else
  921. interpret_option(opts);
  922. end;
  923. end;
  924. end;
  925. procedure toption.parsecmd(cmd:string);
  926. var
  927. i : longint;
  928. opts : string;
  929. begin
  930. while (cmd<>'') do
  931. begin
  932. while cmd[1]=' ' do
  933. delete(cmd,1,1);
  934. i:=pos(' ',cmd);
  935. if i=0 then
  936. i:=255;
  937. opts:=Copy(cmd,1,i-1);
  938. Delete(cmd,1,i);
  939. if firstpass then
  940. begin
  941. { only parse define,undef,target,verbosity and link options }
  942. if (opts[1]='-') and (opts[2] in ['d','v','T','u','n','X']) then
  943. interpret_option(opts);
  944. end
  945. else
  946. begin
  947. if opts[1]='@' then
  948. begin
  949. Delete(opts,1,1);
  950. Message1(option_reading_further_from,opts);
  951. interpret_file(opts);
  952. end
  953. else
  954. interpret_option(opts);
  955. end;
  956. end;
  957. end;
  958. constructor TOption.Init;
  959. begin
  960. DoWriteLogo:=false;
  961. NoPressEnter:=false;
  962. FirstPass:=false;
  963. FileLevel:=0;
  964. ParaIncludePath.Init;
  965. ParaObjectPath.Init;
  966. ParaUnitPath.Init;
  967. ParaLibraryPath.Init;
  968. end;
  969. destructor TOption.Done;
  970. begin
  971. ParaIncludePath.Done;
  972. ParaObjectPath.Done;
  973. ParaUnitPath.Done;
  974. ParaLibraryPath.Done;
  975. end;
  976. {****************************************************************************
  977. Callable Routines
  978. ****************************************************************************}
  979. procedure read_arguments(cmd:string);
  980. var
  981. configpath : pathstr;
  982. option : poption;
  983. begin
  984. {$ifdef Delphi}
  985. option:=new(poption386,Init);
  986. {$endif Delphi}
  987. {$ifdef i386}
  988. option:=new(poption386,Init);
  989. {$endif}
  990. {$ifdef m68k}
  991. option:=new(poption68k,Init);
  992. {$endif}
  993. {$ifdef alpha}
  994. option:=new(poption,Init);
  995. {$endif}
  996. {$ifdef powerpc}
  997. option:=new(poption,Init);
  998. {$endif}
  999. { Load messages }
  1000. if (cmd='') and (paramcount=0) then
  1001. Option^.WriteHelpPages;
  1002. { default defines }
  1003. def_symbol(target_info.short_name);
  1004. def_symbol('FPK');
  1005. def_symbol('FPC');
  1006. def_symbol('VER'+version_nr);
  1007. def_symbol('VER'+version_nr+'_'+release_nr);
  1008. def_symbol('VER'+version_nr+'_'+release_nr+'_'+patch_nr);
  1009. {$ifdef newcg}
  1010. def_symbol('WITHNEWCG');
  1011. {$endif}
  1012. { Temporary defines, until things settle down }
  1013. def_symbol('INT64');
  1014. def_symbol('HASRESOURCESTRINGS');
  1015. def_symbol('HASSAVEREGISTERS');
  1016. def_symbol('NEWVMTOFFSET');
  1017. def_symbol('HASINTERNMATH');
  1018. def_symbol('SYSTEMTVARREC');
  1019. def_symbol('INCLUDEOK');
  1020. def_symbol('NEWMM');
  1021. {$ifdef FPC_USE_CPREFIX}
  1022. { default on next round }
  1023. def_symbol('FPC_USE_CPREFIX');
  1024. {$endif FPC_USE_CPREFIX}
  1025. { some stuff for TP compatibility }
  1026. {$ifdef i386}
  1027. def_symbol('CPU86');
  1028. def_symbol('CPU87');
  1029. {$endif}
  1030. {$ifdef m68k}
  1031. def_symbol('CPU68');
  1032. {$endif}
  1033. { new processor stuff }
  1034. {$ifdef i386}
  1035. def_symbol('CPUI386');
  1036. {$endif}
  1037. {$ifdef m68k}
  1038. def_symbol('CPU68K');
  1039. {$endif}
  1040. {$ifdef ALPHA}
  1041. def_symbol('CPUALPHA');
  1042. {$endif}
  1043. {$ifdef powerpc}
  1044. def_symbol('CPUPOWERPC');
  1045. {$endif}
  1046. { get default messagefile }
  1047. {$ifdef Delphi}
  1048. msgfilename:=dmisc.getenv('PPC_ERROR_FILE');
  1049. {$else Delphi}
  1050. msgfilename:=dos.getenv('PPC_ERROR_FILE');
  1051. {$endif Delphi}
  1052. { default configfile }
  1053. if (cmd<>'') and (cmd[1]='[') then
  1054. begin
  1055. ppccfg:=Copy(cmd,2,pos(']',cmd)-2);
  1056. Delete(cmd,1,pos(']',cmd));
  1057. end
  1058. else
  1059. begin
  1060. {$ifdef i386}
  1061. ppccfg:='ppc386.cfg';
  1062. {$endif i386}
  1063. {$ifdef m68k}
  1064. ppccfg:='ppc.cfg';
  1065. {$endif}
  1066. {$ifdef alpha}
  1067. ppccfg:='ppcalpha.cfg';
  1068. {$endif}
  1069. {$ifdef powerpc}
  1070. ppccfg:='ppcppc.cfg';
  1071. {$endif}
  1072. end;
  1073. { Order to read ppc386.cfg:
  1074. 1 - current dir
  1075. 2 - configpath
  1076. 3 - compiler path }
  1077. {$ifdef Delphi}
  1078. configpath:=FixPath(dmisc.getenv('PPC_CONFIG_PATH'),false);
  1079. {$else Delphi}
  1080. configpath:=FixPath(dos.getenv('PPC_CONFIG_PATH'),false);
  1081. {$endif Delphi}
  1082. {$ifdef linux}
  1083. if configpath='' then
  1084. configpath:='/etc/';
  1085. {$endif}
  1086. if ppccfg<>'' then
  1087. begin
  1088. read_configfile:=true;
  1089. if not FileExists(ppccfg) then
  1090. begin
  1091. {$ifdef linux}
  1092. if (dos.getenv('HOME')<>'') and FileExists(FixPath(dos.getenv('HOME'),false)+'.'+ppccfg) then
  1093. ppccfg:=FixPath(dos.getenv('HOME'),false)+'.'+ppccfg
  1094. else
  1095. {$endif}
  1096. if FileExists(configpath+ppccfg) then
  1097. ppccfg:=configpath+ppccfg
  1098. else
  1099. {$ifndef linux}
  1100. if FileExists(exepath+ppccfg) then
  1101. ppccfg:=exepath+ppccfg
  1102. else
  1103. {$endif}
  1104. read_configfile:=false;
  1105. end;
  1106. end
  1107. else
  1108. read_configfile:=false;
  1109. { Read commandline and configfile }
  1110. target_is_set:=false;
  1111. asm_is_set:=false;
  1112. param_file:='';
  1113. if read_configfile then
  1114. begin
  1115. { read the parameters quick, only -v -T }
  1116. option^.firstpass:=true;
  1117. if cmd<>'' then
  1118. option^.parsecmd(cmd)
  1119. else
  1120. option^.read_parameters;
  1121. if read_configfile then
  1122. begin
  1123. {$ifdef EXTDEBUG}
  1124. Comment(V_Debug,'read config file: '+ppccfg);
  1125. {$endif EXTDEBUG}
  1126. option^.interpret_file(ppccfg);
  1127. end;
  1128. end;
  1129. option^.firstpass:=false;
  1130. if cmd<>'' then
  1131. option^.parsecmd(cmd)
  1132. else
  1133. option^.read_parameters;
  1134. { Stop if errors in options }
  1135. if ErrorCount>0 then
  1136. Stop;
  1137. { write logo if set }
  1138. if option^.DoWriteLogo then
  1139. option^.WriteLogo;
  1140. { Check file to compile }
  1141. if param_file='' then
  1142. begin
  1143. Message(option_no_source_found);
  1144. Stop;
  1145. end;
  1146. {$ifndef linux}
  1147. param_file:=FixFileName(param_file);
  1148. {$endif}
  1149. fsplit(param_file,inputdir,inputfile,inputextension);
  1150. if inputextension='' then
  1151. begin
  1152. if FileExists(inputdir+inputfile+target_os.sourceext) then
  1153. inputextension:=target_os.sourceext
  1154. else
  1155. if FileExists(inputdir+inputfile+target_os.pasext) then
  1156. inputextension:=target_os.pasext;
  1157. end;
  1158. { Add paths specified with parameters to the searchpaths }
  1159. UnitSearchPath.AddList(Option^.ParaUnitPath,true);
  1160. ObjectSearchPath.AddList(Option^.ParaObjectPath,true);
  1161. IncludeSearchPath.AddList(Option^.ParaIncludePath,true);
  1162. LibrarySearchPath.AddList(Option^.ParaLibraryPath,true);
  1163. { add unit environment and exepath to the unit search path }
  1164. if inputdir<>'' then
  1165. Unitsearchpath.AddPath(inputdir,true);
  1166. {$ifdef Delphi}
  1167. UnitSearchPath.AddPath(dmisc.getenv(target_info.unit_env),false);
  1168. {$else}
  1169. UnitSearchPath.AddPath(dos.getenv(target_info.unit_env),false);
  1170. {$endif Delphi}
  1171. {$ifdef linux}
  1172. UnitSearchPath.AddPath('/usr/lib/fpc/'+version_string+'/units/'+lower(target_info.short_name),false);
  1173. UnitSearchPath.AddPath('/usr/lib/fpc/'+version_string+'/rtl/'+lower(target_info.short_name),false);
  1174. {$else}
  1175. UnitSearchPath.AddPath(ExePath+'../units/'+lower(target_info.short_name),false);
  1176. UnitSearchPath.AddPath(ExePath+'../rtl/'+lower(target_info.short_name),false);
  1177. {$endif}
  1178. UnitSearchPath.AddPath(ExePath,false);
  1179. { Add unit dir to the object and library path }
  1180. objectsearchpath.AddList(unitsearchpath,false);
  1181. librarysearchpath.AddList(unitsearchpath,false);
  1182. { switch assembler if it's binary and we got -a on the cmdline }
  1183. if (cs_asm_leave in initglobalswitches) and
  1184. (target_asm.id in binassem) then
  1185. begin
  1186. Message(option_switch_bin_to_src_assembler);
  1187. set_target_asm(target_info.assemsrc);
  1188. initoutputformat:=target_asm.id;
  1189. end;
  1190. { turn off stripping if compiling with debuginfo or profile }
  1191. if (cs_debuginfo in initmoduleswitches) or
  1192. (cs_profile in initmoduleswitches) then
  1193. initglobalswitches:=initglobalswitches-[cs_link_strip];
  1194. { Set defines depending on the target }
  1195. if (target_info.target in [target_i386_GO32V1,target_i386_GO32V2]) then
  1196. def_symbol('DPMI'); { MSDOS is not defined in BP when target is DPMI }
  1197. MaybeLoadMessageFile;
  1198. dispose(option,Done);
  1199. end;
  1200. end.
  1201. {
  1202. $Log$
  1203. Revision 1.38 1999-12-02 17:34:34 peter
  1204. * preprocessor support. But it fails on the caret in type blocks
  1205. Revision 1.37 1999/11/20 01:22:19 pierre
  1206. + cond FPC_USE_CPREFIX (needs also some RTL changes)
  1207. this allows to use unit global vars as DLL exports
  1208. (the underline prefix seems needed by dlltool)
  1209. Revision 1.36 1999/11/15 17:42:40 pierre
  1210. * -g disables reloc section for win32
  1211. Revision 1.35 1999/11/12 11:03:50 peter
  1212. * searchpaths changed to stringqueue object
  1213. Revision 1.34 1999/11/09 23:06:45 peter
  1214. * esi_offset -> selfpointer_offset to be newcg compatible
  1215. * hcogegen -> cgbase fixes for newcg
  1216. Revision 1.33 1999/11/06 14:34:21 peter
  1217. * truncated log to 20 revs
  1218. Revision 1.32 1999/11/04 23:13:25 peter
  1219. * moved unit alias support into ifdef
  1220. Revision 1.31 1999/11/04 10:54:03 peter
  1221. + -Ua<oldname>=<newname> unit alias support
  1222. Revision 1.30 1999/11/03 23:43:09 peter
  1223. * default units/rtl paths
  1224. Revision 1.29 1999/10/30 17:35:26 peter
  1225. * fpc_freemem fpc_getmem new callings updated
  1226. Revision 1.28 1999/10/28 11:13:36 pierre
  1227. * fix for cygwin make problem with -iTP
  1228. Revision 1.27 1999/10/26 13:13:47 peter
  1229. * define INCLUDEOK, which seems to work correct
  1230. Revision 1.26 1999/10/14 14:57:52 florian
  1231. - removed the hcodegen use in the new cg, use cgbase instead
  1232. Revision 1.25 1999/10/13 10:24:49 peter
  1233. * dpmi can only be set after reading the options
  1234. Revision 1.24 1999/10/03 19:44:41 peter
  1235. * removed objpasunit reference, tvarrec is now searched in systemunit
  1236. where it already was located
  1237. Revision 1.23 1999/09/20 16:38:59 peter
  1238. * cs_create_smart instead of cs_smartlink
  1239. * -CX is create smartlink
  1240. * -CD is create dynamic, but does nothing atm.
  1241. Revision 1.22 1999/09/16 11:34:56 pierre
  1242. * typo correction
  1243. Revision 1.21 1999/09/15 20:35:40 florian
  1244. * small fix to operator overloading when in MMX mode
  1245. + the compiler uses now fldz and fld1 if possible
  1246. + some fixes to floating point registers
  1247. + some math. functions (arctan, ln, sin, cos, sqrt, sqr, pi) are now inlined
  1248. * .... ???
  1249. Revision 1.20 1999/09/03 09:31:22 peter
  1250. * reading of search paths fixed to work as expected
  1251. Revision 1.19 1999/09/01 22:07:20 peter
  1252. * turn off stripping if profiling or debugging
  1253. Revision 1.18 1999/08/28 17:46:10 peter
  1254. * resources are working correct
  1255. Revision 1.17 1999/08/28 15:34:19 florian
  1256. * bug 519 fixed
  1257. Revision 1.16 1999/08/27 10:45:03 pierre
  1258. options -Ca sets simply_ppu to true
  1259. Revision 1.15 1999/08/25 22:51:00 pierre
  1260. * remove trailing space in cfg files
  1261. Revision 1.14 1999/08/16 15:35:26 pierre
  1262. * fix for DLL relocation problems
  1263. * external bss vars had wrong stabs for pecoff
  1264. + -WB11000000 to specify default image base, allows to
  1265. load several DLLs with debugging info included
  1266. (relocatable DLL are stripped because the relocation
  1267. of the .Stab section is misplaced by ldw)
  1268. Revision 1.13 1999/08/11 17:26:35 peter
  1269. * tlinker object is now inherited for win32 and dos
  1270. * postprocessexecutable is now a method of tlinker
  1271. }