options.pas 50 KB

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