options.pas 46 KB

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