options.pas 53 KB

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