options.pas 54 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716
  1. {
  2. $Id$
  3. Copyright (c) 1998-2000 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 defines.inc}
  20. interface
  21. uses
  22. globtype,globals,verbose;
  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. Constructor Create;
  35. Destructor Destroy;override;
  36. procedure WriteLogo;
  37. procedure WriteInfo;
  38. procedure WriteHelpPages;
  39. procedure WriteQuickInfo;
  40. procedure IllegalPara(const opt:string);
  41. function Unsetbool(const opts:string; pos: Longint):boolean;
  42. procedure interpret_proc_specific_options(const opt:string);virtual;
  43. procedure interpret_option(const opt :string;ispara:boolean);
  44. procedure Interpret_envvar(const envname : string);
  45. procedure Interpret_file(const filename : string);
  46. procedure Read_Parameters;
  47. procedure parsecmd(cmd:string);
  48. end;
  49. TOptionClass=class of toption;
  50. var
  51. coption : TOptionClass;
  52. procedure read_arguments(cmd:string);
  53. implementation
  54. uses
  55. {$ifdef Delphi}
  56. dmisc,
  57. {$else Delphi}
  58. dos,
  59. {$endif Delphi}
  60. version,systems,
  61. cutils,messages
  62. {$ifdef BrowserLog}
  63. ,browlog
  64. {$endif BrowserLog}
  65. ;
  66. const
  67. page_size = 24;
  68. var
  69. option : toption;
  70. read_configfile, { read config file, set when a cfgfile is found }
  71. disable_configfile,
  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. fpcdir,
  75. ppccfg,
  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.insert(upper(s));
  85. end;
  86. procedure undef_symbol(const s : string);
  87. begin
  88. if s='' then
  89. exit;
  90. InitDefines.Remove(s);
  91. end;
  92. function check_symbol(const s:string):boolean;
  93. begin
  94. check_symbol:=(initdefines.find(s)<>nil);
  95. end;
  96. procedure set_default_link_type;
  97. begin
  98. if (target_info.target=target_i386_win32) then
  99. begin
  100. def_symbol('FPC_LINK_SMART');
  101. undef_symbol('FPC_LINK_STATIC');
  102. undef_symbol('FPC_LINK_DYNAMIC');
  103. initglobalswitches:=initglobalswitches+[cs_link_smart];
  104. initglobalswitches:=initglobalswitches-[cs_link_shared,cs_link_static];
  105. end
  106. else
  107. begin
  108. undef_symbol('FPC_LINK_SMART');
  109. def_symbol('FPC_LINK_STATIC');
  110. undef_symbol('FPC_LINK_DYNAMIC');
  111. initglobalswitches:=initglobalswitches+[cs_link_static];
  112. initglobalswitches:=initglobalswitches-[cs_link_shared,cs_link_smart];
  113. end;
  114. end;
  115. {****************************************************************************
  116. Toption
  117. ****************************************************************************}
  118. procedure StopOptions;
  119. begin
  120. if assigned(Option) then
  121. begin
  122. Option.free;
  123. Option:=nil;
  124. end;
  125. DoneVerbose;
  126. Stop;
  127. end;
  128. procedure Toption.WriteLogo;
  129. var
  130. p : pchar;
  131. begin
  132. p:=MessagePchar(option_logo);
  133. while assigned(p) do
  134. Comment(V_Normal,GetMsgLine(p));
  135. end;
  136. procedure Toption.WriteInfo;
  137. var
  138. p : pchar;
  139. begin
  140. p:=MessagePchar(option_info);
  141. while assigned(p) do
  142. Comment(V_Normal,GetMsgLine(p));
  143. StopOptions;
  144. end;
  145. procedure Toption.WriteHelpPages;
  146. function PadEnd(s:string;i:longint):string;
  147. begin
  148. while (length(s)<i) do
  149. s:=s+' ';
  150. PadEnd:=s;
  151. end;
  152. var
  153. lastident,
  154. j,outline,
  155. ident,
  156. lines : longint;
  157. show : boolean;
  158. opt : string[32];
  159. input,
  160. s : string;
  161. p : pchar;
  162. begin
  163. WriteLogo;
  164. Lines:=4;
  165. Message1(option_usage,system.paramstr(0));
  166. lastident:=0;
  167. p:=MessagePChar(option_help_pages);
  168. while assigned(p) do
  169. begin
  170. { get a line and reset }
  171. s:=GetMsgLine(p);
  172. ident:=0;
  173. show:=false;
  174. { parse options }
  175. case s[1] of
  176. {$ifdef UNITALIASES}
  177. 'a',
  178. {$endif}
  179. {$ifdef EXTDEBUG}
  180. 'e',
  181. {$endif EXTDEBUG}
  182. {$ifdef i386}
  183. '3',
  184. {$endif}
  185. {$ifdef m68k}
  186. '6',
  187. {$endif}
  188. '*' : show:=true;
  189. end;
  190. if show then
  191. begin
  192. case s[2] of
  193. {$ifdef GDB}
  194. 'g',
  195. {$endif}
  196. {$ifdef Unix}
  197. 'L',
  198. {$endif}
  199. {$ifdef os2}
  200. 'O',
  201. {$endif}
  202. '*' : show:=true;
  203. else
  204. show:=false;
  205. end;
  206. end;
  207. { now we may show the message or not }
  208. if show then
  209. begin
  210. case s[3] of
  211. '0' : begin
  212. ident:=0;
  213. outline:=0;
  214. end;
  215. '1' : begin
  216. ident:=2;
  217. outline:=7;
  218. end;
  219. '2' : begin
  220. ident:=6;
  221. outline:=11;
  222. end;
  223. '3' : begin
  224. ident:=9;
  225. outline:=6;
  226. end;
  227. end;
  228. j:=pos('_',s);
  229. opt:=Copy(s,4,j-4);
  230. if opt='*' then
  231. opt:=''
  232. else
  233. if opt=' ' then
  234. opt:=PadEnd(opt,outline)
  235. else
  236. opt:=PadEnd('-'+opt,outline);
  237. if (ident=0) and (lastident<>0) then
  238. begin
  239. Comment(V_Normal,'');
  240. inc(Lines);
  241. end;
  242. { page full ? }
  243. if (lines >= page_size - 1) then
  244. begin
  245. if not NoPressEnter then
  246. begin
  247. Message(option_help_press_enter);
  248. readln(input);
  249. if upper(input)='Q' then
  250. StopOptions;
  251. end;
  252. lines:=0;
  253. end;
  254. Comment(V_Normal,PadEnd('',ident)+opt+Copy(s,j+1,255));
  255. LastIdent:=Ident;
  256. inc(Lines);
  257. end;
  258. end;
  259. StopOptions;
  260. end;
  261. procedure Toption.IllegalPara(const opt:string);
  262. begin
  263. Message1(option_illegal_para,opt);
  264. Message(option_help_pages_para);
  265. StopOptions;
  266. end;
  267. function Toption.Unsetbool(const opts:string; pos: Longint):boolean;
  268. { checks if the character after pos in Opts is a + or a - and returns resp.
  269. false or true. If it is another character (or none), it also returns false }
  270. begin
  271. UnsetBool := (Length(Opts) > Pos) And (Opts[Succ(Pos)] = '-');
  272. end;
  273. procedure TOption.interpret_proc_specific_options(const opt:string);
  274. begin
  275. end;
  276. procedure TOption.interpret_option(const opt:string;ispara:boolean);
  277. var
  278. code : integer;
  279. c : char;
  280. more : string;
  281. major,minor : longint;
  282. error : integer;
  283. j,l : longint;
  284. d : DirStr;
  285. e : ExtStr;
  286. forceasm : tasm;
  287. begin
  288. if opt='' then
  289. exit;
  290. { only parse define,undef,target,verbosity and link options the firsttime }
  291. if firstpass and
  292. not((opt[1]='-') and (opt[2] in ['i','d','v','T','u','n','X'])) then
  293. exit;
  294. Message1(option_handling_option,opt);
  295. case opt[1] of
  296. '-' : begin
  297. more:=Copy(opt,3,255);
  298. case opt[2] of
  299. '!' : initlocalswitches:=initlocalswitches+[cs_ansistrings];
  300. '?' : WriteHelpPages;
  301. 'a' : begin
  302. initglobalswitches:=initglobalswitches+[cs_asm_leave];
  303. for j:=1 to length(more) do
  304. case more[j] of
  305. 'l' : initglobalswitches:=initglobalswitches+[cs_asm_source];
  306. 'r' : initglobalswitches:=initglobalswitches+[cs_asm_regalloc];
  307. 't' : initglobalswitches:=initglobalswitches+[cs_asm_tempalloc];
  308. '-' : initglobalswitches:=initglobalswitches-
  309. [cs_asm_leave, cs_asm_source,cs_asm_regalloc, cs_asm_tempalloc];
  310. else
  311. IllegalPara(opt);
  312. end;
  313. end;
  314. 'A' : begin
  315. if set_target_asm_by_string(More) then
  316. asm_is_set:=true
  317. else
  318. IllegalPara(opt);
  319. end;
  320. 'b' : begin
  321. {$ifdef BrowserLog}
  322. initglobalswitches:=initglobalswitches+[cs_browser_log];
  323. {$endif}
  324. if More<>'' then
  325. if More='l' then
  326. initmoduleswitches:=initmoduleswitches+[cs_local_browser]
  327. else if More='-' then
  328. begin
  329. initmoduleswitches:=initmoduleswitches-[cs_browser,cs_local_browser];
  330. {$ifdef BrowserLog}
  331. initglobalswitches:=initglobalswitches-[cs_browser_log];
  332. {$endif}
  333. end
  334. else if More<>'+' then
  335. {$ifdef BrowserLog}
  336. browserlog.elements_to_list.insert(more);
  337. {$else}
  338. IllegalPara(opt);
  339. {$endif}
  340. end;
  341. 'B' : if UnSetBool(more,0) then
  342. do_build:=false
  343. else
  344. do_build:=true;
  345. 'C' : begin
  346. j := 1;
  347. while j <= length(more) Do
  348. Begin
  349. case more[j] of
  350. 'a' : Message2(option_obsolete_switch_use_new,'-Ca','-Or');
  351. 'h' :
  352. begin
  353. val(copy(more,j+1,length(more)-j),heapsize,code);
  354. if (code<>0) or (heapsize>=67107840) or (heapsize<1024) then
  355. IllegalPara(opt);
  356. break;
  357. end;
  358. 'i' : If UnsetBool(More, j) then
  359. Begin
  360. initlocalswitches:=initlocalswitches-[cs_check_io];
  361. inc(j)
  362. End
  363. else initlocalswitches:=initlocalswitches+[cs_check_io];
  364. 'n' : If UnsetBool(More, j) then
  365. Begin
  366. initglobalswitches:=initglobalswitches-[cs_link_extern];
  367. inc(j)
  368. End
  369. Else initglobalswitches:=initglobalswitches+[cs_link_extern];
  370. 'o' :
  371. If UnsetBool(More, j) then
  372. Begin
  373. initlocalswitches:=initlocalswitches-[cs_check_overflow];
  374. inc(j);
  375. End
  376. Else
  377. initlocalswitches:=initlocalswitches+[cs_check_overflow];
  378. 'r' :
  379. If UnsetBool(More, j) then
  380. Begin
  381. initlocalswitches:=initlocalswitches-[cs_check_range];
  382. inc(j);
  383. End
  384. Else
  385. initlocalswitches:=initlocalswitches+[cs_check_range];
  386. 'R' :
  387. If UnsetBool(More, j) then
  388. Begin
  389. initlocalswitches:=initlocalswitches-[cs_check_object_ext];
  390. inc(j);
  391. End
  392. Else
  393. initlocalswitches:=initlocalswitches+[cs_check_object_ext];
  394. 's' :
  395. begin
  396. val(copy(more,j+1,length(more)-j),stacksize,code);
  397. if (code<>0) or (stacksize>=67107840) or (stacksize<1024) then
  398. IllegalPara(opt);
  399. break;
  400. end;
  401. 't' :
  402. If UnsetBool(More, j) then
  403. Begin
  404. initlocalswitches:=initlocalswitches-[cs_check_stack];
  405. inc(j)
  406. End
  407. Else
  408. initlocalswitches:=initlocalswitches+[cs_check_stack];
  409. 'D' :
  410. If UnsetBool(More, j) then
  411. Begin
  412. initmoduleswitches:=initmoduleswitches-[cs_create_dynamic];
  413. inc(j)
  414. End
  415. Else
  416. initmoduleswitches:=initmoduleswitches+[cs_create_dynamic];
  417. 'X' :
  418. If UnsetBool(More, j) then
  419. Begin
  420. initmoduleswitches:=initmoduleswitches-[cs_create_smart];
  421. inc(j)
  422. End
  423. Else
  424. initmoduleswitches:=initmoduleswitches+[cs_create_smart];
  425. else
  426. IllegalPara(opt);
  427. end;
  428. inc(j);
  429. end;
  430. end;
  431. 'd' : def_symbol(more);
  432. 'D' : begin
  433. initglobalswitches:=initglobalswitches+[cs_link_deffile];
  434. for j:=1 to length(more) do
  435. case more[j] of
  436. 'd' : begin
  437. description:=Copy(more,j+1,255);
  438. break;
  439. end;
  440. 'v' : begin
  441. dllversion:=Copy(more,j+1,255);
  442. l:=pos('.',dllversion);
  443. dllminor:=0;
  444. error:=0;
  445. if l>0 then
  446. begin
  447. valint(copy(dllversion,l+1,255),minor,error);
  448. if (error=0) and
  449. (minor>=0) and (minor<=$ffff) then
  450. dllminor:=minor
  451. else if error=0 then
  452. error:=1;
  453. end;
  454. if l=0 then l:=256;
  455. dllmajor:=1;
  456. if error=0 then
  457. valint(copy(dllversion,1,l-1),major,error);
  458. if (error=0) and (major>=0) and (major<=$ffff) then
  459. dllmajor:=major
  460. else if error=0 then
  461. error:=1;
  462. if error<>0 then
  463. Message1(scan_w_wrong_version_ignored,dllversion);
  464. break;
  465. end;
  466. 'w' : usewindowapi:=true;
  467. '-' : begin
  468. initglobalswitches:=initglobalswitches-
  469. [cs_link_deffile];
  470. usewindowapi:=false;
  471. end;
  472. else
  473. IllegalPara(opt);
  474. end;
  475. end;
  476. 'e' : exepath:=FixPath(More,true);
  477. { Just used by RHIDE }
  478. 'E' : if (length(more)=0) or (UnsetBool(More, 0)) then
  479. initglobalswitches:=initglobalswitches+[cs_link_extern]
  480. else
  481. initglobalswitches:=initglobalswitches-[cs_link_extern];
  482. 'F' : begin
  483. c:=more[1];
  484. Delete(more,1,1);
  485. DefaultReplacements(More);
  486. case c of
  487. 'D' : utilsdirectory:=FixPath(More,true);
  488. 'e' : SetRedirectFile(More);
  489. 'E' : OutputExeDir:=FixPath(More,true);
  490. 'i' : if ispara then
  491. ParaIncludePath.AddPath(More,false)
  492. else
  493. includesearchpath.AddPath(More,true);
  494. 'g' : Message2(option_obsolete_switch_use_new,'-Fg','-Fl');
  495. 'l' : if ispara then
  496. ParaLibraryPath.AddPath(More,false)
  497. else
  498. LibrarySearchPath.AddPath(More,true);
  499. 'L' : if More<>'' then
  500. ParaDynamicLinker:=More
  501. else
  502. IllegalPara(opt);
  503. 'o' : if ispara then
  504. ParaObjectPath.AddPath(More,false)
  505. else
  506. ObjectSearchPath.AddPath(More,true);
  507. 'r' : Msgfilename:=More;
  508. 'u' : if ispara then
  509. ParaUnitPath.AddPath(More,false)
  510. else
  511. unitsearchpath.AddPath(More,true);
  512. 'U' : OutputUnitDir:=FixPath(More,true);
  513. else
  514. IllegalPara(opt);
  515. end;
  516. end;
  517. 'g' : begin
  518. if UnsetBool(More, 0) then
  519. begin
  520. initmoduleswitches:=initmoduleswitches-[cs_debuginfo];
  521. if (length(More)>1) and (More[2]='l') then
  522. initglobalswitches:=initglobalswitches+[cs_gdb_lineinfo];
  523. end
  524. else
  525. begin
  526. {$ifdef GDB}
  527. initmoduleswitches:=initmoduleswitches+[cs_debuginfo];
  528. if not RelocSectionSetExplicitly then
  529. RelocSection:=false;
  530. for j:=1 to length(more) do
  531. case more[j] of
  532. 'd' : initglobalswitches:=initglobalswitches+[cs_gdb_dbx];
  533. 'g' : initglobalswitches:=initglobalswitches+[cs_gdb_gsym];
  534. 'h' : initglobalswitches:=initglobalswitches+[cs_gdb_heaptrc];
  535. 'l' : initglobalswitches:=initglobalswitches+[cs_gdb_lineinfo];
  536. 'c' : initglobalswitches:=initglobalswitches+[cs_checkpointer];
  537. {$ifdef EXTDEBUG}
  538. 'p' : only_one_pass:=true;
  539. {$endif EXTDEBUG}
  540. else
  541. IllegalPara(opt);
  542. end;
  543. {$else GDB}
  544. Message(option_no_debug_support);
  545. Message(option_no_debug_support_recompile_fpc);
  546. {$endif GDB}
  547. end;
  548. end;
  549. 'h' : begin
  550. NoPressEnter:=true;
  551. WriteHelpPages;
  552. end;
  553. 'i' : if More='' then
  554. WriteInfo
  555. else
  556. QuickInfo:=QuickInfo+More;
  557. 'I' : if ispara then
  558. ParaIncludePath.AddPath(More,false)
  559. else
  560. includesearchpath.AddPath(More,false);
  561. 'k' : if more<>'' then
  562. ParaLinkOptions:=ParaLinkOptions+' '+More
  563. else
  564. IllegalPara(opt);
  565. 'l' : if UnSetBool(more,0) then
  566. DoWriteLogo:=false
  567. else
  568. DoWriteLogo:=true;
  569. 'm' : if UnSetBool(more,0) then
  570. parapreprocess:=false
  571. else
  572. parapreprocess:=true;
  573. 'n' : if More='' then
  574. begin
  575. read_configfile:=false;
  576. disable_configfile:=true;
  577. end
  578. else
  579. IllegalPara(opt);
  580. 'o' : if More<>'' then
  581. Fsplit(More,d,OutputFile,e)
  582. else
  583. IllegalPara(opt);
  584. 'p' : begin
  585. if UnsetBool(More, 0) then
  586. begin
  587. initmoduleswitches:=initmoduleswitches-[cs_profile];
  588. undef_symbol('FPC_PROFILE');
  589. end
  590. else
  591. case more[1] of
  592. 'g' : if (length(opt)=3) and UnsetBool(more, 1) then
  593. begin
  594. initmoduleswitches:=initmoduleswitches-[cs_profile];
  595. undef_symbol('FPC_PROFILE');
  596. end
  597. else
  598. begin
  599. initmoduleswitches:=initmoduleswitches+[cs_profile];
  600. def_symbol('FPC_PROFILE');
  601. end;
  602. else
  603. IllegalPara(opt);
  604. end;
  605. end;
  606. {$ifdef Unix}
  607. 'P' : if UnsetBool(More, 0) then
  608. initglobalswitches:=initglobalswitches-[cs_asm_pipe]
  609. else
  610. initglobalswitches:=initglobalswitches+[cs_asm_pipe];
  611. {$endif Unix}
  612. 's' : if UnsetBool(More, 0) then
  613. initglobalswitches:=initglobalswitches-[cs_asm_extern,cs_link_extern]
  614. else
  615. initglobalswitches:=initglobalswitches+[cs_asm_extern,cs_link_extern];
  616. 'S' : begin
  617. if more[1]='I' then
  618. begin
  619. if upper(more)='ICOM' then
  620. initinterfacetype:=it_interfacecom
  621. else if upper(more)='ICORBA' then
  622. initinterfacetype:=it_interfacecorba
  623. else
  624. IllegalPara(opt);
  625. end
  626. else
  627. for j:=1 to length(more) do
  628. case more[j] of
  629. '2' : SetCompileMode('OBJFPC',true);
  630. 'a' : initlocalswitches:=InitLocalswitches+[cs_do_assertion];
  631. 'c' : initmoduleswitches:=initmoduleswitches+[cs_support_c_operators];
  632. 'd' : SetCompileMode('DELPHI',true);
  633. 'e' : begin
  634. SetErrorFlags(copy(more,j+1,length(more)));
  635. break;
  636. end;
  637. 'g' : initmoduleswitches:=initmoduleswitches+[cs_support_goto];
  638. 'h' : initlocalswitches:=initlocalswitches+[cs_ansistrings];
  639. 'i' : initmoduleswitches:=initmoduleswitches+[cs_support_inline];
  640. 'm' : initmoduleswitches:=initmoduleswitches+[cs_support_macro];
  641. 'o' : SetCompileMode('TP',true);
  642. 'p' : SetCompileMode('GPC',true);
  643. 's' : initglobalswitches:=initglobalswitches+[cs_constructor_name];
  644. 't' : initmoduleswitches:=initmoduleswitches+[cs_static_keyword];
  645. '-' : begin
  646. initglobalswitches:=initglobalswitches -
  647. [cs_constructor_name];
  648. initlocalswitches:=InitLocalswitches -
  649. [cs_do_assertion, cs_ansistrings];
  650. initmoduleswitches:=initmoduleswitches -
  651. [cs_support_c_operators, cs_support_goto,
  652. cs_support_inline, cs_support_macro,
  653. cs_static_keyword];
  654. end;
  655. else
  656. IllegalPara(opt);
  657. end;
  658. end;
  659. 'T' : begin
  660. more:=Upper(More);
  661. if not target_is_set then
  662. begin
  663. {Remove non core targetname extra defines}
  664. case target_info.target of
  665. target_i386_freebsd :
  666. begin
  667. undef_symbol('LINUX');
  668. undef_symbol('BSD');
  669. undef_symbol('UNIX');
  670. end;
  671. target_i386_linux :
  672. begin
  673. undef_symbol('UNIX');
  674. end;
  675. end;
  676. { remove old target define }
  677. undef_symbol(upper(target_info.shortname));
  678. { Save assembler if set }
  679. if asm_is_set then
  680. forceasm:=target_asm.id;
  681. { load new target }
  682. if not(set_target_by_string(More)) then
  683. IllegalPara(opt);
  684. { also initialize assembler if not explicitly set }
  685. if asm_is_set then
  686. set_target_asm(forceasm);
  687. { set new define }
  688. def_symbol(upper(target_info.shortname));
  689. target_is_set:=true;
  690. end
  691. else
  692. if More<>upper(target_info.shortname) then
  693. Message1(option_target_is_already_set,target_info.shortname);
  694. end;
  695. 'u' : undef_symbol(upper(More));
  696. 'U' : begin
  697. for j:=1 to length(more) do
  698. case more[j] of
  699. {$ifdef UNITALIASES}
  700. 'a' : begin
  701. AddUnitAlias(Copy(More,j+1,255));
  702. break;
  703. end;
  704. {$endif UNITALIASES}
  705. 'n' : initglobalswitches:=initglobalswitches-[cs_check_unit_name];
  706. 'p' : begin
  707. Message2(option_obsolete_switch_use_new,'-Up','-Fu');
  708. break;
  709. end;
  710. 's' : initmoduleswitches:=initmoduleswitches+[cs_compilesystem];
  711. '-' : begin
  712. initmoduleswitches:=initmoduleswitches
  713. - [cs_compilesystem];
  714. initglobalswitches:=initglobalswitches
  715. + [cs_check_unit_name];
  716. end;
  717. else
  718. IllegalPara(opt);
  719. end;
  720. end;
  721. 'v' : if not setverbosity(More) then
  722. IllegalPara(opt);
  723. 'W' : begin
  724. for j:=1 to length(More) do
  725. case More[j] of
  726. 'B': {bind_win32_dll:=true}
  727. begin
  728. { -WB200000 means set trefered base address
  729. to $200000, but does not change relocsection boolean
  730. this way we can create both relocatble and
  731. non relocatable DLL at a specific base address PM }
  732. if (length(More)>j) then
  733. begin
  734. if DLLImageBase=nil then
  735. DLLImageBase:=StringDup(Copy(More,j+1,255));
  736. end
  737. else
  738. begin
  739. RelocSection:=true;
  740. RelocSectionSetExplicitly:=true;
  741. end;
  742. break;
  743. end;
  744. 'C': apptype:=app_cui;
  745. 'D': if UnsetBool(More, j) then
  746. ForceDeffileForExport:=false
  747. else
  748. ForceDeffileForExport:=true;
  749. 'F': apptype:=app_fs;
  750. 'G': apptype:=app_gui;
  751. 'N': begin
  752. RelocSection:=false;
  753. RelocSectionSetExplicitly:=true;
  754. end;
  755. 'R': begin
  756. RelocSection:=true;
  757. RelocSectionSetExplicitly:=true;
  758. end;
  759. else
  760. IllegalPara(opt);
  761. end;
  762. end;
  763. 'X' : begin
  764. for j:=1 to length(More) do
  765. case More[j] of
  766. 'c' : initglobalswitches:=initglobalswitches+[cs_link_toc];
  767. 's' : initglobalswitches:=initglobalswitches+[cs_link_strip];
  768. 't' : initglobalswitches:=initglobalswitches+[cs_link_staticflag];
  769. 'D' : begin
  770. def_symbol('FPC_LINK_DYNAMIC');
  771. undef_symbol('FPC_LINK_SMART');
  772. undef_symbol('FPC_LINK_STATIC');
  773. initglobalswitches:=initglobalswitches+[cs_link_shared];
  774. initglobalswitches:=initglobalswitches-[cs_link_static,cs_link_smart];
  775. LinkTypeSetExplicitly:=true;
  776. end;
  777. 'S' : begin
  778. def_symbol('FPC_LINK_STATIC');
  779. undef_symbol('FPC_LINK_SMART');
  780. undef_symbol('FPC_LINK_DYNAMIC');
  781. initglobalswitches:=initglobalswitches+[cs_link_static];
  782. initglobalswitches:=initglobalswitches-[cs_link_shared,cs_link_smart];
  783. LinkTypeSetExplicitly:=true;
  784. end;
  785. 'X' : begin
  786. def_symbol('FPC_LINK_SMART');
  787. undef_symbol('FPC_LINK_STATIC');
  788. undef_symbol('FPC_LINK_DYNAMIC');
  789. initglobalswitches:=initglobalswitches+[cs_link_smart];
  790. initglobalswitches:=initglobalswitches-[cs_link_shared,cs_link_static];
  791. LinkTypeSetExplicitly:=true;
  792. end;
  793. '-' : begin
  794. initglobalswitches:=initglobalswitches-[cs_link_toc, cs_link_strip, cs_link_staticflag];
  795. set_default_link_type;
  796. end;
  797. else
  798. IllegalPara(opt);
  799. end;
  800. end;
  801. { give processor specific options a chance }
  802. else
  803. interpret_proc_specific_options(opt);
  804. end;
  805. end;
  806. '@' : begin
  807. Message(option_no_nested_response_file);
  808. StopOptions;
  809. end;
  810. else
  811. begin
  812. if (length(param_file)<>0) then
  813. Message(option_only_one_source_support);
  814. param_file:=opt;
  815. end;
  816. end;
  817. end;
  818. procedure Toption.Interpret_file(const filename : string);
  819. procedure RemoveSep(var fn:string);
  820. var
  821. i : longint;
  822. begin
  823. i:=0;
  824. while (i<length(fn)) and (fn[i+1] in [',',' ',#9]) do
  825. inc(i);
  826. Delete(fn,1,i);
  827. i:=length(fn);
  828. while (i>0) and (fn[i] in [',',' ',#9]) do
  829. dec(i);
  830. fn:=copy(fn,1,i);
  831. end;
  832. function GetName(var fn:string):string;
  833. var
  834. i : longint;
  835. begin
  836. i:=0;
  837. while (i<length(fn)) and (fn[i+1] in ['a'..'z','A'..'Z','0'..'9','_','-']) do
  838. inc(i);
  839. GetName:=Copy(fn,1,i);
  840. Delete(fn,1,i);
  841. end;
  842. const
  843. maxlevel=16;
  844. var
  845. f : text;
  846. s,
  847. opts : string;
  848. skip : array[0..maxlevel-1] of boolean;
  849. level : longint;
  850. option_read : boolean;
  851. begin
  852. { avoid infinite loop }
  853. Inc(FileLevel);
  854. Option_read:=false;
  855. If FileLevel>MaxLevel then
  856. Message(option_too_many_cfg_files);
  857. { open file }
  858. Message1(option_using_file,filename);
  859. assign(f,filename);
  860. {$I-}
  861. reset(f);
  862. {$I+}
  863. if ioresult<>0 then
  864. begin
  865. Message1(option_unable_open_file,filename);
  866. exit;
  867. end;
  868. fillchar(skip,sizeof(skip),0);
  869. level:=0;
  870. while not eof(f) do
  871. begin
  872. readln(f,opts);
  873. RemoveSep(opts);
  874. if (opts<>'') and (opts[1]<>';') then
  875. begin
  876. if opts[1]='#' then
  877. begin
  878. Delete(opts,1,1);
  879. s:=upper(GetName(opts));
  880. if (s='SECTION') then
  881. begin
  882. RemoveSep(opts);
  883. s:=upper(GetName(opts));
  884. if level=0 then
  885. skip[level]:=not (check_symbol(s) or (s='COMMON'));
  886. end
  887. else
  888. if (s='IFDEF') then
  889. begin
  890. RemoveSep(opts);
  891. if Level>=maxlevel then
  892. begin
  893. Message(option_too_many_ifdef);
  894. stopOptions;
  895. end;
  896. inc(Level);
  897. skip[level]:=(skip[level-1] or (not check_symbol(upper(GetName(opts)))));
  898. end
  899. else
  900. if (s='IFNDEF') then
  901. begin
  902. RemoveSep(opts);
  903. if Level>=maxlevel then
  904. begin
  905. Message(option_too_many_ifdef);
  906. stopOptions;
  907. end;
  908. inc(Level);
  909. skip[level]:=(skip[level-1] or (check_symbol(upper(GetName(opts)))));
  910. end
  911. else
  912. if (s='ELSE') then
  913. skip[level]:=skip[level-1] or (not skip[level])
  914. else
  915. if (s='ENDIF') then
  916. begin
  917. skip[level]:=false;
  918. if Level=0 then
  919. begin
  920. Message(option_too_many_endif);
  921. stopOptions;
  922. end;
  923. dec(level);
  924. end
  925. else
  926. if (not skip[level]) then
  927. begin
  928. if (s='DEFINE') then
  929. begin
  930. RemoveSep(opts);
  931. def_symbol(upper(GetName(opts)));
  932. end
  933. else
  934. if (s='UNDEF') then
  935. begin
  936. RemoveSep(opts);
  937. undef_symbol(upper(GetName(opts)));
  938. end
  939. else
  940. if (s='WRITE') then
  941. begin
  942. Delete(opts,1,1);
  943. WriteLn(opts);
  944. end
  945. else
  946. if (s='INCLUDE') then
  947. begin
  948. Delete(opts,1,1);
  949. Interpret_file(opts);
  950. end;
  951. end;
  952. end
  953. else
  954. begin
  955. if (opts[1]='-') or (opts[1]='@') then
  956. begin
  957. if (not skip[level]) then
  958. interpret_option(opts,false);
  959. Option_read:=true;
  960. end
  961. else
  962. Message1(option_illegal_para,opts);
  963. end;
  964. end;
  965. end;
  966. if Level>0 then
  967. Message(option_too_less_endif);
  968. if Not Option_read then
  969. Message1(option_no_option_found,filename);
  970. Close(f);
  971. Dec(FileLevel);
  972. end;
  973. procedure Toption.Interpret_envvar(const envname : string);
  974. var
  975. argstart,
  976. env,
  977. pc : pchar;
  978. arglen : longint;
  979. quote : set of char;
  980. hs : string;
  981. begin
  982. Message1(option_using_env,envname);
  983. env:=GetEnvPChar(envname);
  984. pc:=env;
  985. if assigned(pc) then
  986. begin
  987. repeat
  988. { skip leading spaces }
  989. while pc^ in [' ',#9,#13] do
  990. inc(pc);
  991. case pc^ of
  992. #0 :
  993. break;
  994. '"' :
  995. begin
  996. quote:=['"'];
  997. inc(pc);
  998. end;
  999. '''' :
  1000. begin
  1001. quote:=[''''];
  1002. inc(pc);
  1003. end;
  1004. else
  1005. quote:=[' ',#9,#13];
  1006. end;
  1007. { scan until the end of the argument }
  1008. argstart:=pc;
  1009. while (pc^<>#0) and not(pc^ in quote) do
  1010. inc(pc);
  1011. { create argument }
  1012. arglen:=pc-argstart;
  1013. hs[0]:=chr(arglen);
  1014. move(argstart^,hs[1],arglen);
  1015. interpret_option(hs,true);
  1016. { skip quote }
  1017. if pc^ in quote then
  1018. inc(pc);
  1019. until false;
  1020. end
  1021. else
  1022. Message1(option_no_option_found,'(env) '+envname);
  1023. FreeEnvPChar(env);
  1024. end;
  1025. procedure toption.read_parameters;
  1026. var
  1027. opts : string;
  1028. paramindex : longint;
  1029. begin
  1030. paramindex:=0;
  1031. while paramindex<paramcount do
  1032. begin
  1033. inc(paramindex);
  1034. opts:=system.paramstr(paramindex);
  1035. case opts[1] of
  1036. '@' :
  1037. if not firstpass then
  1038. begin
  1039. Delete(opts,1,1);
  1040. Message1(option_reading_further_from,opts);
  1041. interpret_file(opts);
  1042. end;
  1043. '!' :
  1044. if not firstpass then
  1045. begin
  1046. Delete(opts,1,1);
  1047. Message1(option_reading_further_from,'(env) '+opts);
  1048. interpret_envvar(opts);
  1049. end;
  1050. else
  1051. interpret_option(opts,true);
  1052. end;
  1053. end;
  1054. end;
  1055. procedure toption.parsecmd(cmd:string);
  1056. var
  1057. i,ps : longint;
  1058. opts : string;
  1059. begin
  1060. while (cmd<>'') do
  1061. begin
  1062. while cmd[1]=' ' do
  1063. delete(cmd,1,1);
  1064. i:=pos(' ',cmd);
  1065. if i=0 then
  1066. i:=256;
  1067. opts:=Copy(cmd,1,i-1);
  1068. Delete(cmd,1,i);
  1069. case opts[1] of
  1070. '@' :
  1071. if not firstpass then
  1072. begin
  1073. Delete(opts,1,1);
  1074. Message1(option_reading_further_from,opts);
  1075. interpret_file(opts);
  1076. end;
  1077. '!' :
  1078. if not firstpass then
  1079. begin
  1080. Delete(opts,1,1);
  1081. Message1(option_reading_further_from,'(env) '+opts);
  1082. interpret_envvar(opts);
  1083. end;
  1084. '"' :
  1085. begin
  1086. Delete(opts,1,1);
  1087. ps:=pos('"',cmd);
  1088. if (i<>256) and (ps>0) then
  1089. begin
  1090. opts:=opts + ' '+ copy(cmd,1,ps-1);
  1091. cmd:=copy(cmd,ps+1,255);
  1092. end;
  1093. interpret_option(opts,true);
  1094. end;
  1095. else
  1096. interpret_option(opts,true);
  1097. end;
  1098. end;
  1099. end;
  1100. procedure toption.writequickinfo;
  1101. var
  1102. s : string;
  1103. i : longint;
  1104. procedure addinfo(const hs:string);
  1105. begin
  1106. if s<>'' then
  1107. s:=s+' '+hs
  1108. else
  1109. s:=hs;
  1110. end;
  1111. begin
  1112. s:='';
  1113. i:=0;
  1114. while (i<length(quickinfo)) do
  1115. begin
  1116. inc(i);
  1117. case quickinfo[i] of
  1118. 'S' :
  1119. begin
  1120. inc(i);
  1121. case quickinfo[i] of
  1122. 'O' :
  1123. addinfo(lower(source_info.shortname));
  1124. {$ifdef Delphi}
  1125. 'P' :
  1126. addinfo('i386');
  1127. {$else Delphi}
  1128. 'P' :
  1129. addinfo(source_cpu_string);
  1130. {$endif Delphi}
  1131. else
  1132. IllegalPara('-iS'+QuickInfo);
  1133. end;
  1134. end;
  1135. 'T' :
  1136. begin
  1137. inc(i);
  1138. case quickinfo[i] of
  1139. 'O' :
  1140. addinfo(lower(target_info.shortname));
  1141. 'P' :
  1142. AddInfo(target_cpu_string);
  1143. else
  1144. IllegalPara('-iT'+QuickInfo);
  1145. end;
  1146. end;
  1147. 'V' :
  1148. AddInfo(version_string);
  1149. 'D' :
  1150. AddInfo(date_string);
  1151. '_' :
  1152. ;
  1153. else
  1154. IllegalPara('-i'+QuickInfo);
  1155. end;
  1156. end;
  1157. if s<>'' then
  1158. begin
  1159. writeln(s);
  1160. stopoptions;
  1161. end;
  1162. end;
  1163. constructor TOption.create;
  1164. begin
  1165. DoWriteLogo:=false;
  1166. NoPressEnter:=false;
  1167. FirstPass:=false;
  1168. FileLevel:=0;
  1169. Quickinfo:='';
  1170. ParaIncludePath:=TSearchPathList.Create;
  1171. ParaObjectPath:=TSearchPathList.Create;
  1172. ParaUnitPath:=TSearchPathList.Create;
  1173. ParaLibraryPath:=TSearchPathList.Create;
  1174. end;
  1175. destructor TOption.destroy;
  1176. begin
  1177. ParaIncludePath.Free;
  1178. ParaObjectPath.Free;
  1179. ParaUnitPath.Free;
  1180. ParaLibraryPath.Free;
  1181. end;
  1182. {****************************************************************************
  1183. Callable Routines
  1184. ****************************************************************************}
  1185. procedure read_arguments(cmd:string);
  1186. var
  1187. configpath : pathstr;
  1188. begin
  1189. option:=coption.create;
  1190. disable_configfile:=false;
  1191. { default defines }
  1192. def_symbol(upper(target_info.shortname));
  1193. def_symbol('FPC');
  1194. def_symbol('VER'+version_nr);
  1195. def_symbol('VER'+version_nr+'_'+release_nr);
  1196. def_symbol('VER'+version_nr+'_'+release_nr+'_'+patch_nr);
  1197. {$ifdef newcg}
  1198. def_symbol('WITHNEWCG');
  1199. {$endif}
  1200. { Temporary defines, until things settle down }
  1201. {$ifdef SUPPORT_FIXED}
  1202. def_symbol('HASFIXED');
  1203. {$endif SUPPORT_FIXED}
  1204. def_symbol('HASWIDECHAR');
  1205. def_symbol('HASOUT');
  1206. def_symbol('HASINTF');
  1207. def_symbol('HASVARIANT');
  1208. def_symbol('INTERNSETLENGTH');
  1209. def_symbol('INT64FUNCRESOK');
  1210. def_symbol('PACKENUMFIXED');
  1211. def_symbol('HAS_ADDR_STACK_ON_STACK');
  1212. def_symbol('NOBOPUNDCHECK');
  1213. { some stuff for TP compatibility }
  1214. {$ifdef i386}
  1215. def_symbol('CPU86');
  1216. def_symbol('CPU87');
  1217. {$endif}
  1218. {$ifdef m68k}
  1219. def_symbol('CPU68');
  1220. {$endif}
  1221. { new processor stuff }
  1222. {$ifdef i386}
  1223. def_symbol('CPUI386');
  1224. {$endif}
  1225. {$ifdef m68k}
  1226. def_symbol('CPU68K');
  1227. {$endif}
  1228. {$ifdef ALPHA}
  1229. def_symbol('CPUALPHA');
  1230. {$endif}
  1231. {$ifdef powerpc}
  1232. def_symbol('CPUPOWERPC');
  1233. {$endif}
  1234. { get default messagefile }
  1235. {$ifdef Delphi}
  1236. msgfilename:=dmisc.getenv('PPC_ERROR_FILE');
  1237. {$else Delphi}
  1238. msgfilename:=dos.getenv('PPC_ERROR_FILE');
  1239. {$endif Delphi}
  1240. { default configfile }
  1241. if (cmd<>'') and (cmd[1]='[') then
  1242. begin
  1243. ppccfg:=Copy(cmd,2,pos(']',cmd)-2);
  1244. Delete(cmd,1,pos(']',cmd));
  1245. end
  1246. else
  1247. begin
  1248. {$ifdef i386}
  1249. ppccfg:='ppc386.cfg';
  1250. {$endif i386}
  1251. {$ifdef ia64}
  1252. ppccfg:='ppcia64.cfg';
  1253. {$endif ia64}
  1254. {$ifdef m68k}
  1255. ppccfg:='ppc68k.cfg';
  1256. {$endif}
  1257. {$ifdef alpha}
  1258. ppccfg:='ppcalpha.cfg';
  1259. {$endif}
  1260. {$ifdef powerpc}
  1261. ppccfg:='ppcppc.cfg';
  1262. {$endif}
  1263. end;
  1264. { Order to read ppc386.cfg:
  1265. 1 - current dir
  1266. 2 - configpath
  1267. 3 - compiler path }
  1268. {$ifdef Delphi}
  1269. configpath:=FixPath(dmisc.getenv('PPC_CONFIG_PATH'),false);
  1270. {$else Delphi}
  1271. configpath:=FixPath(dos.getenv('PPC_CONFIG_PATH'),false);
  1272. {$endif Delphi}
  1273. {$ifdef Unix}
  1274. if configpath='' then
  1275. configpath:='/etc/';
  1276. {$endif}
  1277. if ppccfg<>'' then
  1278. begin
  1279. read_configfile:=true;
  1280. if not FileExists(ppccfg) then
  1281. begin
  1282. {$ifdef Unix}
  1283. if (dos.getenv('HOME')<>'') and FileExists(FixPath(dos.getenv('HOME'),false)+'.'+ppccfg) then
  1284. ppccfg:=FixPath(dos.getenv('HOME'),false)+'.'+ppccfg
  1285. else
  1286. {$endif}
  1287. if FileExists(configpath+ppccfg) then
  1288. ppccfg:=configpath+ppccfg
  1289. else
  1290. {$ifndef Unix}
  1291. if FileExists(exepath+ppccfg) then
  1292. ppccfg:=exepath+ppccfg
  1293. else
  1294. {$endif}
  1295. read_configfile:=false;
  1296. end;
  1297. end
  1298. else
  1299. read_configfile:=false;
  1300. { Read commandline and configfile }
  1301. target_is_set:=false;
  1302. asm_is_set:=false;
  1303. param_file:='';
  1304. if read_configfile then
  1305. begin
  1306. { read the parameters quick, only -i -v -T }
  1307. option.firstpass:=true;
  1308. if cmd<>'' then
  1309. option.parsecmd(cmd)
  1310. else
  1311. begin
  1312. option.read_parameters;
  1313. { Write only quickinfo }
  1314. if option.quickinfo<>'' then
  1315. option.writequickinfo;
  1316. end;
  1317. { Read the configfile }
  1318. option.firstpass:=false;
  1319. if read_configfile then
  1320. option.interpret_file(ppccfg);
  1321. end;
  1322. if cmd<>'' then
  1323. option.parsecmd(cmd)
  1324. else
  1325. begin
  1326. option.read_parameters;
  1327. { Write only quickinfo }
  1328. if option.quickinfo<>'' then
  1329. option.writequickinfo;
  1330. end;
  1331. { Write help pages }
  1332. if (cmd='') and (paramcount=0) then
  1333. Option.WriteHelpPages;
  1334. { Stop if errors in options }
  1335. if ErrorCount>0 then
  1336. StopOptions;
  1337. { Non-core target defines }
  1338. case target_info.target of
  1339. target_i386_freebsd :
  1340. begin
  1341. def_symbol('LINUX'); { Hack: Linux define is also needed for freebsd (MvdV) }
  1342. def_symbol('BSD');
  1343. def_symbol('UNIX');
  1344. end;
  1345. target_i386_linux :
  1346. begin
  1347. def_symbol('UNIX');
  1348. end;
  1349. target_i386_sunos :
  1350. begin
  1351. def_symbol('UNIX');
  1352. def_symbol('SOLARIS');
  1353. def_symbol('LIBC');
  1354. def_symbol('SUNOS');
  1355. end;
  1356. end;
  1357. { endian define }
  1358. case target_info.endian of
  1359. endian_little :
  1360. def_symbol('ENDIAN_LITTLE');
  1361. endian_big :
  1362. def_symbol('ENDIAN_BIG');
  1363. end;
  1364. { write logo if set }
  1365. if option.DoWriteLogo then
  1366. option.WriteLogo;
  1367. { Check file to compile }
  1368. if param_file='' then
  1369. begin
  1370. Message(option_no_source_found);
  1371. StopOptions;
  1372. end;
  1373. {$ifndef Unix}
  1374. param_file:=FixFileName(param_file);
  1375. {$endif}
  1376. fsplit(param_file,inputdir,inputfile,inputextension);
  1377. if inputextension='' then
  1378. begin
  1379. if FileExists(inputdir+inputfile+target_info.sourceext) then
  1380. inputextension:=target_info.sourceext
  1381. else
  1382. if FileExists(inputdir+inputfile+target_info.pasext) then
  1383. inputextension:=target_info.pasext;
  1384. end;
  1385. { Add paths specified with parameters to the searchpaths }
  1386. UnitSearchPath.AddList(option.ParaUnitPath,true);
  1387. ObjectSearchPath.AddList(option.ParaObjectPath,true);
  1388. IncludeSearchPath.AddList(option.ParaIncludePath,true);
  1389. LibrarySearchPath.AddList(option.ParaLibraryPath,true);
  1390. { add unit environment and exepath to the unit search path }
  1391. if inputdir<>'' then
  1392. Unitsearchpath.AddPath(inputdir,true);
  1393. if not disable_configfile then
  1394. {$ifdef Delphi}
  1395. UnitSearchPath.AddPath(dmisc.getenv(target_info.unit_env),false);
  1396. {$else}
  1397. UnitSearchPath.AddPath(dos.getenv(target_info.unit_env),false);
  1398. {$endif Delphi}
  1399. {$ifdef Unix}
  1400. fpcdir:=FixPath(getenv('FPCDIR'),false);
  1401. if fpcdir='' then
  1402. begin
  1403. if PathExists('/usr/local/lib/fpc/'+version_string) then
  1404. fpcdir:='/usr/local/lib/fpc/'+version_string+'/'
  1405. else
  1406. fpcdir:='/usr/lib/fpc/'+version_string+'/';
  1407. end;
  1408. {$else}
  1409. fpcdir:=FixPath(getenv('FPCDIR'),false);
  1410. if fpcdir='' then
  1411. begin
  1412. fpcdir:=ExePath+'../';
  1413. if not(PathExists(fpcdir+'/units')) and
  1414. not(PathExists(fpcdir+'/rtl')) then
  1415. fpcdir:=fpcdir+'../';
  1416. end;
  1417. {$endif}
  1418. { first try development RTL, else use the default installation path }
  1419. if not disable_configfile then
  1420. begin
  1421. if PathExists(FpcDir+'rtl/'+lower(target_info.shortname)) then
  1422. UnitSearchPath.AddPath(FpcDir+'rtl/'+lower(target_info.shortname),false)
  1423. else
  1424. begin
  1425. UnitSearchPath.AddPath(FpcDir+'units/'+lower(target_info.shortname),false);
  1426. UnitSearchPath.AddPath(FpcDir+'units/'+lower(target_info.shortname)+'/rtl',false);
  1427. end;
  1428. end;
  1429. { Add exepath if the exe is not in the current dir, because that is always searched already }
  1430. if ExePath<>GetCurrentDir then
  1431. UnitSearchPath.AddPath(ExePath,false);
  1432. { Add unit dir to the object and library path }
  1433. objectsearchpath.AddList(unitsearchpath,false);
  1434. librarysearchpath.AddList(unitsearchpath,false);
  1435. { switch assembler if it's binary and we got -a on the cmdline }
  1436. if (cs_asm_leave in initglobalswitches) and
  1437. (target_asm.outputbinary) then
  1438. begin
  1439. Message(option_switch_bin_to_src_assembler);
  1440. set_target_asm(target_info.assemextern);
  1441. end;
  1442. if (target_asm.supported_target <> target_any) and
  1443. (target_asm.supported_target <> target_info.target) then
  1444. begin
  1445. Message2(option_incompatible_asm,target_asm.idtxt,target_info.name);
  1446. set_target_asm(target_info.assemextern);
  1447. Message1(option_asm_forced,target_asm.idtxt);
  1448. end;
  1449. { turn off stripping if compiling with debuginfo or profile }
  1450. if (cs_debuginfo in initmoduleswitches) or
  1451. (cs_profile in initmoduleswitches) then
  1452. initglobalswitches:=initglobalswitches-[cs_link_strip];
  1453. if not LinkTypeSetExplicitly then
  1454. set_default_link_type;
  1455. { Set defines depending on the target }
  1456. if (target_info.target in [target_i386_GO32V1,target_i386_GO32V2]) then
  1457. def_symbol('DPMI'); { MSDOS is not defined in BP when target is DPMI }
  1458. option.free;
  1459. Option:=nil;
  1460. end;
  1461. initialization
  1462. coption:=toption;
  1463. finalization
  1464. if assigned(option) then
  1465. option.free;
  1466. end.
  1467. {
  1468. $Log$
  1469. Revision 1.42 2001-05-18 22:28:59 peter
  1470. * endian define
  1471. Revision 1.41 2001/05/12 12:11:31 peter
  1472. * simplify_ppu is now the default, a recompile of the compiler now
  1473. only compiles pp.pas
  1474. Revision 1.40 2001/04/18 22:01:54 peter
  1475. * registration of targets and assemblers
  1476. Revision 1.39 2001/04/13 01:22:10 peter
  1477. * symtable change to classes
  1478. * range check generation and errors fixed, make cycle DEBUG=1 works
  1479. * memory leaks fixed
  1480. Revision 1.38 2001/03/25 12:27:31 peter
  1481. * fixed -Se (merged)
  1482. Revision 1.37 2001/03/23 00:16:07 florian
  1483. + some stuff to compile FreeCLX added
  1484. Revision 1.36 2001/03/13 20:59:56 peter
  1485. * message loading fixes from Sergey (merged)
  1486. Revision 1.35 2001/03/10 13:19:10 peter
  1487. * don't check messagefile for numbers, this allows the usage of
  1488. 1.1 msgfiles with a 1.0.x compiler
  1489. Revision 1.34 2001/03/05 21:50:29 peter
  1490. * press enter moved to errore.msg
  1491. Revision 1.33 2001/03/03 12:41:22 jonas
  1492. * simplified and optimized range checking code, FPC_BOUNDCHECK is no longer necessary
  1493. Revision 1.32 2001/02/26 19:44:53 peter
  1494. * merged generic m68k updates from fixes branch
  1495. Revision 1.31 2001/02/26 12:47:46 jonas
  1496. * fixed bug in type checking for compatibility of set elements (merged)
  1497. * released fix in options.pas from Carl also for FPC (merged)
  1498. Revision 1.30 2001/02/26 08:08:39 michael
  1499. * option_help_pages:
  1500. allow to omit an option (use one space char insteed an option)
  1501. but to indent a continuation line as if option is present. For lines:
  1502. 3*2CX_first line
  1503. 3*2 _second line
  1504. 3*2*_third line
  1505. we could get:
  1506. -CX first line
  1507. second line
  1508. third line
  1509. Revision 1.29 2001/02/26 07:49:50 michael
  1510. Support replacements for all -F<x> options
  1511. Revision 1.28 2001/02/05 21:26:36 peter
  1512. * applied patches from Sergey Korshunoff
  1513. Revision 1.27 2001/01/20 18:36:51 hajny
  1514. + APPTYPE support under OS/2, app_fs, GetEnvPChar for OS/2
  1515. Revision 1.26 2001/01/12 19:21:09 peter
  1516. * fixed writing of quickinfo when no ppc386.cfg is available
  1517. Revision 1.25 2001/01/05 17:36:57 florian
  1518. * the info about exception frames is stored now on the stack
  1519. instead on the heap
  1520. Revision 1.24 2000/12/25 00:07:26 peter
  1521. + new tlinkedlist class (merge of old tstringqueue,tcontainer and
  1522. tlinkedlist objects)
  1523. Revision 1.23 2000/12/24 12:21:41 peter
  1524. * use system.paramstr()
  1525. Revision 1.22 2000/12/23 19:46:49 peter
  1526. * object to class conversion
  1527. * more verbosity for -vt and -vd
  1528. * -i options can be put after eachother so the Makefiles only need
  1529. to call fpc once for all info (will be twice as the first one will
  1530. be to check the version if fpc supports multiple info)
  1531. Revision 1.21 2000/12/16 15:56:19 jonas
  1532. - removed all ifdef cardinalmulfix code
  1533. Revision 1.20 2000/12/15 13:26:01 jonas
  1534. * only return int64's from functions if it int64funcresok is defined
  1535. + added int64funcresok define to options.pas
  1536. Revision 1.19 2000/11/30 22:48:23 florian
  1537. * opts386 renamed
  1538. Revision 1.18 2000/11/29 00:30:34 florian
  1539. * unused units removed from uses clause
  1540. * some changes for widestrings
  1541. Revision 1.17 2000/11/13 15:26:12 marco
  1542. * Renamefest
  1543. Revision 1.16 2000/11/12 22:20:37 peter
  1544. * create generic toutputsection for binary writers
  1545. Revision 1.15 2000/11/07 15:09:27 marco
  1546. * Define UNIX for FreeBSD and Linux. Checked crosscompile thingy.
  1547. Revision 1.14 2000/11/07 14:25:08 marco
  1548. * FreeBSD defines (FreeBSD,Linux,BSD,Unix) Linux defines (Linux,Unix)
  1549. Revision 1.13 2000/11/06 20:30:54 peter
  1550. * more fixes to get make cycle working
  1551. Revision 1.12 2000/11/04 14:25:20 florian
  1552. + merged Attila's changes for interfaces, not tested yet
  1553. Revision 1.11 2000/09/26 10:50:41 jonas
  1554. * initmodeswitches is changed is you change the compiler mode from the
  1555. command line (the -S<x> switches didn't work anymore for changing the
  1556. compiler mode) (merged from fixes branch)
  1557. Revision 1.10 2000/09/24 21:33:47 peter
  1558. * message updates merges
  1559. Revision 1.9 2000/09/24 15:06:20 peter
  1560. * use defines.inc
  1561. Revision 1.8 2000/09/18 12:28:41 marco
  1562. * Definition of multiple FreeBSD target defines moved to after error check
  1563. commandline parsing
  1564. Revision 1.7 2000/09/16 12:22:52 peter
  1565. * freebsd support merged
  1566. Revision 1.6 2000/08/27 16:11:51 peter
  1567. * moved some util functions from globals,cobjects to cutils
  1568. * splitted files into finput,fmodule
  1569. Revision 1.5 2000/08/07 11:31:04 jonas
  1570. * fixed bug in type conversions between enum subranges (it didn't take
  1571. the packenum directive into account)
  1572. + define PACKENUMFIXED symbol in options.pas
  1573. (merged from fixes branch)
  1574. Revision 1.4 2000/07/14 05:11:48 michael
  1575. + Patch to 1.1
  1576. Revision 1.3 2000/07/13 12:08:26 michael
  1577. + patched to 1.1.0 with former 1.09patch from peter
  1578. Revision 1.2 2000/07/13 11:32:44 michael
  1579. + removed logs
  1580. }