options.pas 57 KB

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