options.pas 60 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085
  1. {
  2. $Id$
  3. Copyright (c) 1998-2002 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 fpcdefs.inc}
  20. interface
  21. uses
  22. globtype,globals,verbose,systems,cpuinfo;
  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. widestr,
  58. {$ifdef Delphi}
  59. dmisc,
  60. {$else Delphi}
  61. dos,
  62. {$endif Delphi}
  63. version,
  64. cutils,cmsgs
  65. {$ifdef BrowserLog}
  66. ,browlog
  67. {$endif BrowserLog}
  68. ;
  69. const
  70. page_size = 24;
  71. var
  72. option : toption;
  73. read_configfile, { read config file, set when a cfgfile is found }
  74. disable_configfile,
  75. target_is_set : boolean; { do not allow contradictory target settings }
  76. asm_is_set : boolean; { -T also change initoutputformat if not set idrectly }
  77. fpcdir,
  78. ppccfg,
  79. ppcaltcfg,
  80. param_file : string; { file to compile specified on the commandline }
  81. {****************************************************************************
  82. Defines
  83. ****************************************************************************}
  84. procedure def_symbol(const s : string);
  85. begin
  86. if s='' then
  87. exit;
  88. initdefines.insert(upper(s));
  89. Message1(option_defining_symbol,s);
  90. end;
  91. procedure undef_symbol(const s : string);
  92. begin
  93. if s='' then
  94. exit;
  95. InitDefines.Remove(s);
  96. Message1(option_undefining_symbol,s);
  97. end;
  98. function check_symbol(const s:string):boolean;
  99. begin
  100. check_symbol:=(initdefines.find(s)<>nil);
  101. end;
  102. procedure set_default_link_type;
  103. begin
  104. if (target_info.system in [system_i386_win32,system_i386_wdosx]) then
  105. begin
  106. def_symbol('FPC_LINK_SMART');
  107. undef_symbol('FPC_LINK_STATIC');
  108. undef_symbol('FPC_LINK_DYNAMIC');
  109. initglobalswitches:=initglobalswitches+[cs_link_smart];
  110. initglobalswitches:=initglobalswitches-[cs_link_shared,cs_link_static];
  111. end
  112. else
  113. begin
  114. undef_symbol('FPC_LINK_SMART');
  115. def_symbol('FPC_LINK_STATIC');
  116. undef_symbol('FPC_LINK_DYNAMIC');
  117. initglobalswitches:=initglobalswitches+[cs_link_static];
  118. initglobalswitches:=initglobalswitches-[cs_link_shared,cs_link_smart];
  119. end;
  120. end;
  121. {****************************************************************************
  122. Toption
  123. ****************************************************************************}
  124. procedure StopOptions;
  125. begin
  126. if assigned(Option) then
  127. begin
  128. Option.free;
  129. Option:=nil;
  130. end;
  131. DoneVerbose;
  132. Stop;
  133. end;
  134. procedure Toption.WriteLogo;
  135. var
  136. p : pchar;
  137. begin
  138. p:=MessagePchar(option_logo);
  139. while assigned(p) do
  140. Comment(V_Normal,GetMsgLine(p));
  141. end;
  142. procedure Toption.WriteInfo;
  143. var
  144. p : pchar;
  145. hs,hs1,s : string;
  146. target : tsystem;
  147. begin
  148. p:=MessagePchar(option_info);
  149. while assigned(p) do
  150. begin
  151. s:=GetMsgLine(p);
  152. { list OS Targets }
  153. if pos('$OSTARGETS',s)>0 then
  154. begin
  155. for target:=low(tsystem) to high(tsystem) do
  156. if assigned(targetinfos[target]) then
  157. begin
  158. hs:=s;
  159. hs1:=targetinfos[target]^.name;
  160. if tf_under_development in targetinfos[target]^.flags then
  161. hs1:=hs1+' (under development)';
  162. Replace(hs,'$OSTARGETS',hs1);
  163. Comment(V_Normal,hs);
  164. end;
  165. end
  166. else
  167. Comment(V_Normal,s);
  168. end;
  169. StopOptions;
  170. end;
  171. procedure Toption.WriteHelpPages;
  172. function PadEnd(s:string;i:longint):string;
  173. begin
  174. while (length(s)<i) do
  175. s:=s+' ';
  176. PadEnd:=s;
  177. end;
  178. var
  179. lastident,
  180. j,outline,
  181. ident,
  182. lines : longint;
  183. show : boolean;
  184. opt : string[32];
  185. input,
  186. s : string;
  187. p : pchar;
  188. begin
  189. WriteLogo;
  190. Lines:=4;
  191. Message1(option_usage,system.paramstr(0));
  192. lastident:=0;
  193. p:=MessagePChar(option_help_pages);
  194. while assigned(p) do
  195. begin
  196. { get a line and reset }
  197. s:=GetMsgLine(p);
  198. ident:=0;
  199. show:=false;
  200. { parse options }
  201. case s[1] of
  202. {$ifdef UNITALIASES}
  203. 'a',
  204. {$endif}
  205. {$ifdef EXTDEBUG}
  206. 'e',
  207. {$endif EXTDEBUG}
  208. {$ifdef i386}
  209. '3',
  210. {$endif}
  211. {$ifdef powerpc}
  212. 'P',
  213. {$endif}
  214. {$ifdef vis}
  215. 'V',
  216. {$endif}
  217. {$ifdef sparc}
  218. 'S',
  219. {$endif}
  220. {$ifdef m68k}
  221. '6',
  222. {$endif}
  223. '*' : show:=true;
  224. end;
  225. if show then
  226. begin
  227. case s[2] of
  228. {$ifdef GDB}
  229. 'g',
  230. {$endif}
  231. {$ifdef Unix}
  232. 'L',
  233. {$endif}
  234. {$ifdef os2}
  235. 'O',
  236. {$endif}
  237. '*' : show:=true;
  238. else
  239. show:=false;
  240. end;
  241. end;
  242. { now we may show the message or not }
  243. if show then
  244. begin
  245. case s[3] of
  246. '0' : begin
  247. ident:=0;
  248. outline:=0;
  249. end;
  250. '1' : begin
  251. ident:=2;
  252. outline:=7;
  253. end;
  254. '2' : begin
  255. ident:=6;
  256. outline:=11;
  257. end;
  258. '3' : begin
  259. ident:=9;
  260. outline:=6;
  261. end;
  262. end;
  263. j:=pos('_',s);
  264. opt:=Copy(s,4,j-4);
  265. if opt='*' then
  266. opt:=''
  267. else
  268. if opt=' ' then
  269. opt:=PadEnd(opt,outline)
  270. else
  271. opt:=PadEnd('-'+opt,outline);
  272. if (ident=0) and (lastident<>0) then
  273. begin
  274. Comment(V_Normal,'');
  275. inc(Lines);
  276. end;
  277. { page full ? }
  278. if (lines >= page_size - 1) then
  279. begin
  280. if not NoPressEnter then
  281. begin
  282. Message(option_help_press_enter);
  283. readln(input);
  284. if upper(input)='Q' then
  285. StopOptions;
  286. end;
  287. lines:=0;
  288. end;
  289. Comment(V_Normal,PadEnd('',ident)+opt+Copy(s,j+1,255));
  290. LastIdent:=Ident;
  291. inc(Lines);
  292. end;
  293. end;
  294. StopOptions;
  295. end;
  296. procedure Toption.IllegalPara(const opt:string);
  297. begin
  298. Message1(option_illegal_para,opt);
  299. Message(option_help_pages_para);
  300. StopOptions;
  301. end;
  302. function Toption.Unsetbool(var Opts:string; Pos: Longint):boolean;
  303. { checks if the character after pos in Opts is a + or a - and returns resp.
  304. false or true. If it is another character (or none), it also returns false }
  305. begin
  306. UnsetBool := false;
  307. if Length(Opts)>Pos then
  308. begin
  309. inc(Pos);
  310. UnsetBool := Opts[Pos] = '-';
  311. if Opts[Pos] in ['-','+']then
  312. delete(Opts,Pos,1);
  313. end;
  314. end;
  315. procedure TOption.interpret_proc_specific_options(const opt:string);
  316. begin
  317. end;
  318. procedure TOption.interpret_option(const opt:string;ispara:boolean);
  319. var
  320. code : integer;
  321. c : char;
  322. more : string;
  323. major,minor : longint;
  324. error : integer;
  325. j,l : longint;
  326. d : DirStr;
  327. e : ExtStr;
  328. forceasm : tasm;
  329. begin
  330. if opt='' then
  331. exit;
  332. { only parse define,undef,target,verbosity and link options the firsttime }
  333. if firstpass and
  334. not((opt[1]='-') and (opt[2] in ['i','d','v','V','T','u','n','X'])) then
  335. exit;
  336. Message1(option_handling_option,opt);
  337. case opt[1] of
  338. '-' :
  339. begin
  340. more:=Copy(opt,3,255);
  341. if firstpass then
  342. Message1(option_interpreting_firstpass_option,opt)
  343. else
  344. Message1(option_interpreting_option,opt);
  345. case opt[2] of
  346. '?' :
  347. WriteHelpPages;
  348. 'a' :
  349. begin
  350. include(initglobalswitches,cs_asm_leave);
  351. j:=1;
  352. while j<=length(more) do
  353. begin
  354. case more[j] of
  355. 'l' :
  356. include(initglobalswitches,cs_asm_source);
  357. 'r' :
  358. include(initglobalswitches,cs_asm_regalloc);
  359. 't' :
  360. include(initglobalswitches,cs_asm_tempalloc);
  361. 'n' :
  362. include(initglobalswitches,cs_asm_nodes);
  363. '-' :
  364. initglobalswitches:=initglobalswitches -
  365. [cs_asm_leave, cs_asm_source,cs_asm_regalloc, cs_asm_tempalloc, cs_asm_nodes];
  366. else
  367. IllegalPara(opt);
  368. end;
  369. inc(j);
  370. end;
  371. end;
  372. 'A' :
  373. begin
  374. if set_target_asm_by_string(More) then
  375. asm_is_set:=true
  376. else
  377. IllegalPara(opt);
  378. end;
  379. 'b' :
  380. begin
  381. if UnsetBool(More,0) then
  382. begin
  383. exclude(initmoduleswitches,cs_browser);
  384. exclude(initmoduleswitches,cs_local_browser);
  385. {$ifdef BrowserLog}
  386. exclude(initglobalswitches,cs_browser_log);
  387. {$endif}
  388. end
  389. else
  390. begin
  391. include(initmoduleswitches,cs_browser);
  392. {$ifdef BrowserLog}
  393. include(initglobalswitches,cs_browser_log);
  394. {$endif}
  395. end;
  396. if More<>'' then
  397. if (More='l') or (More='l+') then
  398. include(initmoduleswitches,cs_local_browser)
  399. else
  400. if More='l-' then
  401. exclude(initmoduleswitches,cs_local_browser)
  402. else
  403. {$ifdef BrowserLog}
  404. browserlog.elements_to_list.insert(more);
  405. {$else}
  406. IllegalPara(opt);
  407. {$endif}
  408. end;
  409. 'B' :
  410. do_build:=not UnSetBool(more,0);
  411. 'C' :
  412. begin
  413. j:=1;
  414. while j<=length(more) do
  415. begin
  416. case more[j] of
  417. 'a' :
  418. Message2(option_obsolete_switch_use_new,'-Ca','-Or');
  419. 'c' :
  420. begin
  421. if not SetAktProcCall(upper(copy(more,j+1,length(more)-j)),true) then
  422. IllegalPara(opt);
  423. break;
  424. end;
  425. {$ifdef cpufpemu}
  426. 'e' :
  427. begin
  428. If UnsetBool(More, j) then
  429. exclude(initmoduleswitches,cs_fp_emulation)
  430. Else
  431. include(initmoduleswitches,cs_fp_emulation);
  432. end;
  433. {$endif cpufpemu}
  434. 'h' :
  435. begin
  436. val(copy(more,j+1,length(more)-j),heapsize,code);
  437. if (code<>0) or (heapsize>=67107840) or (heapsize<1024) then
  438. IllegalPara(opt);
  439. break;
  440. end;
  441. 'i' :
  442. If UnsetBool(More, j) then
  443. exclude(initlocalswitches,cs_check_io)
  444. else
  445. include(initlocalswitches,cs_check_io);
  446. 'n' :
  447. If UnsetBool(More, j) then
  448. exclude(initglobalswitches,cs_link_extern)
  449. Else
  450. include(initglobalswitches,cs_link_extern);
  451. 'o' :
  452. If UnsetBool(More, j) then
  453. exclude(initlocalswitches,cs_check_overflow)
  454. Else
  455. include(initlocalswitches,cs_check_overflow);
  456. 'r' :
  457. If UnsetBool(More, j) then
  458. exclude(initlocalswitches,cs_check_range)
  459. Else
  460. include(initlocalswitches,cs_check_range);
  461. 'R' :
  462. If UnsetBool(More, j) then
  463. begin
  464. exclude(initlocalswitches,cs_check_range);
  465. exclude(initlocalswitches,cs_check_object);
  466. end
  467. Else
  468. begin
  469. include(initlocalswitches,cs_check_range);
  470. include(initlocalswitches,cs_check_object);
  471. end;
  472. 's' :
  473. begin
  474. val(copy(more,j+1,length(more)-j),stacksize,code);
  475. if (code<>0) or (stacksize>=67107840) or (stacksize<1024) then
  476. IllegalPara(opt);
  477. break;
  478. end;
  479. 't' :
  480. If UnsetBool(More, j) then
  481. exclude(initlocalswitches,cs_check_stack)
  482. Else
  483. include(initlocalswitches,cs_check_stack);
  484. 'D' :
  485. If UnsetBool(More, j) then
  486. exclude(initmoduleswitches,cs_create_dynamic)
  487. Else
  488. include(initmoduleswitches,cs_create_dynamic);
  489. 'X' :
  490. If UnsetBool(More, j) then
  491. exclude(initmoduleswitches,cs_create_smart)
  492. Else
  493. include(initmoduleswitches,cs_create_smart);
  494. else
  495. IllegalPara(opt);
  496. end;
  497. inc(j);
  498. end;
  499. end;
  500. 'd' :
  501. def_symbol(more);
  502. 'D' :
  503. begin
  504. include(initglobalswitches,cs_link_deffile);
  505. j:=1;
  506. while j<=length(more) do
  507. begin
  508. case more[j] of
  509. 'd' :
  510. begin
  511. description:=Copy(more,j+1,255);
  512. break;
  513. end;
  514. 'v' :
  515. begin
  516. dllversion:=Copy(more,j+1,255);
  517. l:=pos('.',dllversion);
  518. dllminor:=0;
  519. error:=0;
  520. if l>0 then
  521. begin
  522. valint(copy(dllversion,l+1,255),minor,error);
  523. if (error=0) and
  524. (minor>=0) and (minor<=$ffff) then
  525. dllminor:=minor
  526. else
  527. if error=0 then
  528. error:=1;
  529. end;
  530. if l=0 then
  531. l:=256;
  532. dllmajor:=1;
  533. if error=0 then
  534. valint(copy(dllversion,1,l-1),major,error);
  535. if (error=0) and (major>=0) and (major<=$ffff) then
  536. dllmajor:=major
  537. else
  538. if error=0 then
  539. error:=1;
  540. if error<>0 then
  541. Message1(scan_w_wrong_version_ignored,dllversion);
  542. break;
  543. end;
  544. 'w' :
  545. usewindowapi:=true;
  546. '-' :
  547. begin
  548. exclude(initglobalswitches,cs_link_deffile);
  549. usewindowapi:=false;
  550. end;
  551. else
  552. IllegalPara(opt);
  553. end;
  554. inc(j);
  555. end;
  556. end;
  557. 'e' :
  558. exepath:=FixPath(More,true);
  559. 'E' :
  560. begin
  561. if UnsetBool(More, 0) then
  562. exclude(initglobalswitches,cs_link_extern)
  563. else
  564. include(initglobalswitches,cs_link_extern);
  565. end;
  566. 'F' :
  567. begin
  568. c:=more[1];
  569. Delete(more,1,1);
  570. DefaultReplacements(More);
  571. case c of
  572. 'c' :
  573. begin
  574. if not(cpavailable(more)) then
  575. Message1(option_code_page_not_available,more)
  576. else
  577. initsourcecodepage:=more;
  578. end;
  579. 'D' :
  580. utilsdirectory:=FixPath(More,true);
  581. 'e' :
  582. SetRedirectFile(More);
  583. 'E' :
  584. OutputExeDir:=FixPath(More,true);
  585. 'i' :
  586. begin
  587. if ispara then
  588. ParaIncludePath.AddPath(More,false)
  589. else
  590. includesearchpath.AddPath(More,true);
  591. end;
  592. 'g' :
  593. Message2(option_obsolete_switch_use_new,'-Fg','-Fl');
  594. 'l' :
  595. begin
  596. if ispara then
  597. ParaLibraryPath.AddPath(More,false)
  598. else
  599. LibrarySearchPath.AddPath(More,true);
  600. end;
  601. 'L' :
  602. begin
  603. if More<>'' then
  604. ParaDynamicLinker:=More
  605. else
  606. IllegalPara(opt);
  607. end;
  608. 'o' :
  609. begin
  610. if ispara then
  611. ParaObjectPath.AddPath(More,false)
  612. else
  613. ObjectSearchPath.AddPath(More,true);
  614. end;
  615. 'r' :
  616. Msgfilename:=More;
  617. 'u' :
  618. begin
  619. if ispara then
  620. ParaUnitPath.AddPath(More,false)
  621. else
  622. unitsearchpath.AddPath(More,true);
  623. end;
  624. 'U' :
  625. OutputUnitDir:=FixPath(More,true);
  626. else
  627. IllegalPara(opt);
  628. end;
  629. end;
  630. 'g' : begin
  631. if UnsetBool(More, 0) then
  632. begin
  633. exclude(initmoduleswitches,cs_debuginfo);
  634. exclude(initglobalswitches,cs_gdb_dbx);
  635. exclude(initglobalswitches,cs_gdb_gsym);
  636. exclude(initglobalswitches,cs_gdb_heaptrc);
  637. exclude(initglobalswitches,cs_gdb_lineinfo);
  638. exclude(initglobalswitches,cs_checkpointer);
  639. end
  640. else
  641. begin
  642. {$ifdef GDB}
  643. include(initmoduleswitches,cs_debuginfo);
  644. if not RelocSectionSetExplicitly then
  645. RelocSection:=false;
  646. j:=1;
  647. while j<=length(more) do
  648. begin
  649. case more[j] of
  650. 'd' :
  651. begin
  652. if UnsetBool(More, j) then
  653. exclude(initglobalswitches,cs_gdb_dbx)
  654. else
  655. include(initglobalswitches,cs_gdb_dbx);
  656. end;
  657. 'g' :
  658. begin
  659. if UnsetBool(More, j) then
  660. exclude(initglobalswitches,cs_gdb_gsym)
  661. else
  662. include(initglobalswitches,cs_gdb_gsym);
  663. end;
  664. 'h' :
  665. begin
  666. if UnsetBool(More, j) then
  667. exclude(initglobalswitches,cs_gdb_heaptrc)
  668. else
  669. include(initglobalswitches,cs_gdb_heaptrc);
  670. end;
  671. 'l' :
  672. begin
  673. if UnsetBool(More, j) then
  674. exclude(initglobalswitches,cs_gdb_lineinfo)
  675. else
  676. include(initglobalswitches,cs_gdb_lineinfo);
  677. end;
  678. 'c' :
  679. begin
  680. if UnsetBool(More, j) then
  681. exclude(initglobalswitches,cs_checkpointer)
  682. else
  683. include(initglobalswitches,cs_checkpointer);
  684. end;
  685. else
  686. IllegalPara(opt);
  687. end;
  688. inc(j);
  689. end;
  690. {$else GDB}
  691. Message(option_no_debug_support);
  692. Message(option_no_debug_support_recompile_fpc);
  693. {$endif GDB}
  694. end;
  695. end;
  696. 'h' :
  697. begin
  698. NoPressEnter:=true;
  699. WriteHelpPages;
  700. end;
  701. 'i' :
  702. begin
  703. if More='' then
  704. WriteInfo
  705. else
  706. QuickInfo:=QuickInfo+More;
  707. end;
  708. 'I' :
  709. begin
  710. if ispara then
  711. ParaIncludePath.AddPath(More,false)
  712. else
  713. includesearchpath.AddPath(More,false);
  714. end;
  715. 'k' :
  716. begin
  717. if more<>'' then
  718. ParaLinkOptions:=ParaLinkOptions+' '+More
  719. else
  720. IllegalPara(opt);
  721. end;
  722. 'l' :
  723. DoWriteLogo:=not UnSetBool(more,0);
  724. 'm' :
  725. parapreprocess:=not UnSetBool(more,0);
  726. 'n' :
  727. begin
  728. if More='' then
  729. disable_configfile:=true
  730. else
  731. IllegalPara(opt);
  732. end;
  733. 'o' :
  734. begin
  735. if More<>'' then
  736. Fsplit(More,d,OutputFile,e)
  737. else
  738. IllegalPara(opt);
  739. end;
  740. 'p' :
  741. begin
  742. if UnsetBool(More, 0) then
  743. begin
  744. initmoduleswitches:=initmoduleswitches-[cs_profile];
  745. undef_symbol('FPC_PROFILE');
  746. end
  747. else
  748. if Length(More)=0 then
  749. IllegalPara(opt)
  750. else
  751. case more[1] of
  752. 'g' : if UnsetBool(more, 1) then
  753. begin
  754. exclude(initmoduleswitches,cs_profile);
  755. undef_symbol('FPC_PROFILE');
  756. end
  757. else
  758. begin
  759. include(initmoduleswitches,cs_profile);
  760. def_symbol('FPC_PROFILE');
  761. end;
  762. else
  763. IllegalPara(opt);
  764. end;
  765. end;
  766. {$ifdef Unix}
  767. 'P' :
  768. begin
  769. if UnsetBool(More, 0) then
  770. exclude(initglobalswitches,cs_asm_pipe)
  771. else
  772. include(initglobalswitches,cs_asm_pipe);
  773. end;
  774. {$endif Unix}
  775. 's' :
  776. begin
  777. if UnsetBool(More, 0) then
  778. begin
  779. initglobalswitches:=initglobalswitches-[cs_asm_extern,cs_link_extern];
  780. if more<>'' then
  781. IllegalPara(opt);
  782. end
  783. else
  784. begin
  785. initglobalswitches:=initglobalswitches+[cs_asm_extern,cs_link_extern];
  786. if more='h' then
  787. initglobalswitches:=initglobalswitches-[cs_link_on_target]
  788. else if more='t' then
  789. initglobalswitches:=initglobalswitches+[cs_link_on_target]
  790. {$ifdef newra}
  791. else if more='r' then
  792. initglobalswitches:=initglobalswitches+[cs_no_regalloc]
  793. {$endif newra}
  794. else if more<>'' then
  795. IllegalPara(opt);
  796. end;
  797. end;
  798. 'S' :
  799. begin
  800. if more[1]='I' then
  801. begin
  802. if upper(more)='ICOM' then
  803. initinterfacetype:=it_interfacecom
  804. else if upper(more)='ICORBA' then
  805. initinterfacetype:=it_interfacecorba
  806. else
  807. IllegalPara(opt);
  808. end
  809. else
  810. begin
  811. j:=1;
  812. while j<=length(more) do
  813. begin
  814. case more[j] of
  815. '2' :
  816. SetCompileMode('OBJFPC',true);
  817. 'a' :
  818. include(initlocalswitches,cs_do_assertion);
  819. 'c' :
  820. include(initmoduleswitches,cs_support_c_operators);
  821. 'd' :
  822. SetCompileMode('DELPHI',true);
  823. 'e' :
  824. begin
  825. SetErrorFlags(copy(more,j+1,length(more)));
  826. break;
  827. end;
  828. 'g' :
  829. include(initmoduleswitches,cs_support_goto);
  830. 'h' :
  831. include(initlocalswitches,cs_ansistrings);
  832. 'i' :
  833. include(initmoduleswitches,cs_support_inline);
  834. 'm' :
  835. include(initmoduleswitches,cs_support_macro);
  836. 'o' :
  837. SetCompileMode('TP',true);
  838. 'p' :
  839. SetCompileMode('GPC',true);
  840. 's' :
  841. include(initglobalswitches,cs_constructor_name);
  842. 't' :
  843. include(initmoduleswitches,cs_static_keyword);
  844. '-' :
  845. begin
  846. exclude(initglobalswitches,cs_constructor_name);
  847. initlocalswitches:=InitLocalswitches - [cs_do_assertion, cs_ansistrings];
  848. initmoduleswitches:=initmoduleswitches - [cs_support_c_operators, cs_support_goto,
  849. cs_support_inline, cs_support_macro,
  850. cs_static_keyword];
  851. end;
  852. else
  853. IllegalPara(opt);
  854. end;
  855. inc(j);
  856. end;
  857. end;
  858. end;
  859. 'T' :
  860. begin
  861. more:=Upper(More);
  862. if not target_is_set then
  863. begin
  864. { remove old target define }
  865. TargetDefines(false);
  866. { Save assembler if set }
  867. if asm_is_set then
  868. forceasm:=target_asm.id;
  869. { load new target }
  870. if not(set_target_by_string(More)) then
  871. IllegalPara(opt);
  872. { also initialize assembler if not explicitly set }
  873. if asm_is_set then
  874. set_target_asm(forceasm);
  875. { set new define }
  876. TargetDefines(true);
  877. target_is_set:=true;
  878. end
  879. else
  880. if More<>upper(target_info.shortname) then
  881. Message1(option_target_is_already_set,target_info.shortname);
  882. end;
  883. 'u' :
  884. undef_symbol(upper(More));
  885. 'U' :
  886. begin
  887. j:=1;
  888. while j<=length(more) do
  889. begin
  890. case more[j] of
  891. {$ifdef UNITALIASES}
  892. 'a' :
  893. begin
  894. AddUnitAlias(Copy(More,j+1,255));
  895. break;
  896. end;
  897. {$endif UNITALIASES}
  898. 'n' :
  899. exclude(initglobalswitches,cs_check_unit_name);
  900. 'p' :
  901. begin
  902. Message2(option_obsolete_switch_use_new,'-Up','-Fu');
  903. break;
  904. end;
  905. 'r' :
  906. do_release:=true;
  907. 's' :
  908. include(initmoduleswitches,cs_compilesystem);
  909. '-' :
  910. begin
  911. exclude(initmoduleswitches,cs_compilesystem);
  912. exclude(initglobalswitches,cs_check_unit_name);
  913. end;
  914. else
  915. IllegalPara(opt);
  916. end;
  917. inc(j);
  918. end;
  919. end;
  920. 'v' :
  921. begin
  922. if not setverbosity(More) then
  923. IllegalPara(opt);
  924. end;
  925. 'V' :
  926. PrepareReport;
  927. 'W' :
  928. begin
  929. j:=1;
  930. while j<=length(More) do
  931. begin
  932. case More[j] of
  933. 'B':
  934. begin
  935. { -WB200000 means set trefered base address
  936. to $200000, but does not change relocsection boolean
  937. this way we can create both relocatble and
  938. non relocatable DLL at a specific base address PM }
  939. if (length(More)>j) then
  940. begin
  941. if DLLImageBase=nil then
  942. DLLImageBase:=StringDup(Copy(More,j+1,255));
  943. end
  944. else
  945. begin
  946. RelocSection:=true;
  947. RelocSectionSetExplicitly:=true;
  948. end;
  949. break;
  950. end;
  951. 'C':
  952. begin
  953. if UnsetBool(More, j) then
  954. apptype:=app_gui
  955. else
  956. apptype:=app_cui;
  957. end;
  958. 'D':
  959. ForceDeffileForExport:=not UnsetBool(More, j);
  960. 'F':
  961. begin
  962. if UnsetBool(More, j) then
  963. apptype:=app_cui
  964. else
  965. apptype:=app_fs;
  966. end;
  967. 'G':
  968. begin
  969. if UnsetBool(More, j) then
  970. apptype:=app_cui
  971. else
  972. apptype:=app_gui;
  973. end;
  974. 'N':
  975. begin
  976. RelocSection:=UnsetBool(More,j);
  977. RelocSectionSetExplicitly:=true;
  978. end;
  979. 'R':
  980. begin
  981. { support -WR+ / -WR- as synonyms to -WR / -WN }
  982. RelocSection:=not UnsetBool(More,j);
  983. RelocSectionSetExplicitly:=true;
  984. end;
  985. else
  986. IllegalPara(opt);
  987. end;
  988. inc(j);
  989. end;
  990. end;
  991. 'X' :
  992. begin
  993. j:=1;
  994. while j<=length(more) do
  995. begin
  996. case More[j] of
  997. 'i' :
  998. include(initglobalswitches,cs_link_internal);
  999. 'm' :
  1000. include(initglobalswitches,cs_link_map);
  1001. 's' :
  1002. include(initglobalswitches,cs_link_strip);
  1003. 't' :
  1004. include(initglobalswitches,cs_link_staticflag);
  1005. 'D' :
  1006. begin
  1007. def_symbol('FPC_LINK_DYNAMIC');
  1008. undef_symbol('FPC_LINK_SMART');
  1009. undef_symbol('FPC_LINK_STATIC');
  1010. exclude(initglobalswitches,cs_link_static);
  1011. exclude(initglobalswitches,cs_link_smart);
  1012. include(initglobalswitches,cs_link_shared);
  1013. LinkTypeSetExplicitly:=true;
  1014. end;
  1015. 'S' :
  1016. begin
  1017. def_symbol('FPC_LINK_STATIC');
  1018. undef_symbol('FPC_LINK_SMART');
  1019. undef_symbol('FPC_LINK_DYNAMIC');
  1020. include(initglobalswitches,cs_link_static);
  1021. exclude(initglobalswitches,cs_link_smart);
  1022. exclude(initglobalswitches,cs_link_shared);
  1023. LinkTypeSetExplicitly:=true;
  1024. end;
  1025. 'X' :
  1026. begin
  1027. def_symbol('FPC_LINK_SMART');
  1028. undef_symbol('FPC_LINK_STATIC');
  1029. undef_symbol('FPC_LINK_DYNAMIC');
  1030. exclude(initglobalswitches,cs_link_static);
  1031. include(initglobalswitches,cs_link_smart);
  1032. exclude(initglobalswitches,cs_link_shared);
  1033. LinkTypeSetExplicitly:=true;
  1034. end;
  1035. '-' :
  1036. begin
  1037. exclude(initglobalswitches,cs_link_staticflag);
  1038. exclude(initglobalswitches,cs_link_strip);
  1039. exclude(initglobalswitches,cs_link_map);
  1040. set_default_link_type;
  1041. end;
  1042. else
  1043. IllegalPara(opt);
  1044. end;
  1045. inc(j);
  1046. end;
  1047. end;
  1048. { give processor specific options a chance }
  1049. else
  1050. interpret_proc_specific_options(opt);
  1051. end;
  1052. end;
  1053. '@' :
  1054. begin
  1055. Message(option_no_nested_response_file);
  1056. StopOptions;
  1057. end;
  1058. else
  1059. begin
  1060. if (length(param_file)<>0) then
  1061. Message(option_only_one_source_support);
  1062. param_file:=opt;
  1063. Message1(option_found_file,opt);
  1064. end;
  1065. end;
  1066. end;
  1067. procedure Toption.Interpret_file(const filename : string);
  1068. procedure RemoveSep(var fn:string);
  1069. var
  1070. i : longint;
  1071. begin
  1072. i:=0;
  1073. while (i<length(fn)) and (fn[i+1] in [',',' ',#9]) do
  1074. inc(i);
  1075. Delete(fn,1,i);
  1076. i:=length(fn);
  1077. while (i>0) and (fn[i] in [',',' ',#9]) do
  1078. dec(i);
  1079. fn:=copy(fn,1,i);
  1080. end;
  1081. function GetName(var fn:string):string;
  1082. var
  1083. i : longint;
  1084. begin
  1085. i:=0;
  1086. while (i<length(fn)) and (fn[i+1] in ['a'..'z','A'..'Z','0'..'9','_','-']) do
  1087. inc(i);
  1088. GetName:=Copy(fn,1,i);
  1089. Delete(fn,1,i);
  1090. end;
  1091. const
  1092. maxlevel=16;
  1093. var
  1094. f : text;
  1095. s,
  1096. opts : string;
  1097. skip : array[0..maxlevel-1] of boolean;
  1098. level : longint;
  1099. option_read : boolean;
  1100. begin
  1101. { avoid infinite loop }
  1102. Inc(FileLevel);
  1103. Option_read:=false;
  1104. If FileLevel>MaxLevel then
  1105. Message(option_too_many_cfg_files);
  1106. { open file }
  1107. Message1(option_using_file,filename);
  1108. assign(f,filename);
  1109. {$I-}
  1110. reset(f);
  1111. {$I+}
  1112. if ioresult<>0 then
  1113. begin
  1114. Message1(option_unable_open_file,filename);
  1115. exit;
  1116. end;
  1117. Message1(option_start_reading_configfile,filename);
  1118. fillchar(skip,sizeof(skip),0);
  1119. level:=0;
  1120. while not eof(f) do
  1121. begin
  1122. readln(f,opts);
  1123. RemoveSep(opts);
  1124. if (opts<>'') and (opts[1]<>';') then
  1125. begin
  1126. if opts[1]='#' then
  1127. begin
  1128. Message1(option_interpreting_file_option,opts);
  1129. Delete(opts,1,1);
  1130. s:=upper(GetName(opts));
  1131. if (s='SECTION') then
  1132. begin
  1133. RemoveSep(opts);
  1134. s:=upper(GetName(opts));
  1135. if level=0 then
  1136. skip[level]:=not (check_symbol(s) or (s='COMMON'));
  1137. end
  1138. else
  1139. if (s='IFDEF') then
  1140. begin
  1141. RemoveSep(opts);
  1142. if Level>=maxlevel then
  1143. begin
  1144. Message(option_too_many_ifdef);
  1145. stopOptions;
  1146. end;
  1147. inc(Level);
  1148. skip[level]:=(skip[level-1] or (not check_symbol(upper(GetName(opts)))));
  1149. end
  1150. else
  1151. if (s='IFNDEF') then
  1152. begin
  1153. RemoveSep(opts);
  1154. if Level>=maxlevel then
  1155. begin
  1156. Message(option_too_many_ifdef);
  1157. stopOptions;
  1158. end;
  1159. inc(Level);
  1160. skip[level]:=(skip[level-1] or (check_symbol(upper(GetName(opts)))));
  1161. end
  1162. else
  1163. if (s='ELSE') then
  1164. skip[level]:=skip[level-1] or (not skip[level])
  1165. else
  1166. if (s='ENDIF') then
  1167. begin
  1168. skip[level]:=false;
  1169. if Level=0 then
  1170. begin
  1171. Message(option_too_many_endif);
  1172. stopOptions;
  1173. end;
  1174. dec(level);
  1175. end
  1176. else
  1177. if (not skip[level]) then
  1178. begin
  1179. if (s='DEFINE') then
  1180. begin
  1181. RemoveSep(opts);
  1182. def_symbol(upper(GetName(opts)));
  1183. end
  1184. else
  1185. if (s='UNDEF') then
  1186. begin
  1187. RemoveSep(opts);
  1188. undef_symbol(upper(GetName(opts)));
  1189. end
  1190. else
  1191. if (s='WRITE') then
  1192. begin
  1193. Delete(opts,1,1);
  1194. WriteLn(opts);
  1195. end
  1196. else
  1197. if (s='INCLUDE') then
  1198. begin
  1199. Delete(opts,1,1);
  1200. Interpret_file(opts);
  1201. end;
  1202. end;
  1203. end
  1204. else
  1205. begin
  1206. if (opts[1]='-') or (opts[1]='@') then
  1207. begin
  1208. if (not skip[level]) then
  1209. interpret_option(opts,false);
  1210. Option_read:=true;
  1211. end
  1212. else
  1213. Message1(option_illegal_para,opts);
  1214. end;
  1215. end;
  1216. end;
  1217. if Level>0 then
  1218. Message(option_too_less_endif);
  1219. if Not Option_read then
  1220. Message1(option_no_option_found,filename)
  1221. else
  1222. Message1(option_end_reading_configfile,filename);
  1223. Close(f);
  1224. Dec(FileLevel);
  1225. end;
  1226. procedure Toption.Interpret_envvar(const envname : string);
  1227. var
  1228. argstart,
  1229. env,
  1230. pc : pchar;
  1231. arglen : longint;
  1232. quote : set of char;
  1233. hs : string;
  1234. begin
  1235. Message1(option_using_env,envname);
  1236. env:=GetEnvPChar(envname);
  1237. pc:=env;
  1238. if assigned(pc) then
  1239. begin
  1240. repeat
  1241. { skip leading spaces }
  1242. while pc^ in [' ',#9,#13] do
  1243. inc(pc);
  1244. case pc^ of
  1245. #0 :
  1246. break;
  1247. '"' :
  1248. begin
  1249. quote:=['"'];
  1250. inc(pc);
  1251. end;
  1252. '''' :
  1253. begin
  1254. quote:=[''''];
  1255. inc(pc);
  1256. end;
  1257. else
  1258. quote:=[' ',#9,#13];
  1259. end;
  1260. { scan until the end of the argument }
  1261. argstart:=pc;
  1262. while (pc^<>#0) and not(pc^ in quote) do
  1263. inc(pc);
  1264. { create argument }
  1265. arglen:=pc-argstart;
  1266. hs[0]:=chr(arglen);
  1267. move(argstart^,hs[1],arglen);
  1268. interpret_option(hs,true);
  1269. { skip quote }
  1270. if pc^ in quote then
  1271. inc(pc);
  1272. until false;
  1273. end
  1274. else
  1275. Message1(option_no_option_found,'(env) '+envname);
  1276. FreeEnvPChar(env);
  1277. end;
  1278. procedure toption.read_parameters;
  1279. var
  1280. opts : string;
  1281. paramindex : longint;
  1282. begin
  1283. paramindex:=0;
  1284. while paramindex<paramcount do
  1285. begin
  1286. inc(paramindex);
  1287. opts:=system.paramstr(paramindex);
  1288. case opts[1] of
  1289. '@' :
  1290. if not firstpass then
  1291. begin
  1292. Delete(opts,1,1);
  1293. Message1(option_reading_further_from,opts);
  1294. interpret_file(opts);
  1295. end;
  1296. '!' :
  1297. if not firstpass then
  1298. begin
  1299. Delete(opts,1,1);
  1300. Message1(option_reading_further_from,'(env) '+opts);
  1301. interpret_envvar(opts);
  1302. end;
  1303. else
  1304. interpret_option(opts,true);
  1305. end;
  1306. end;
  1307. end;
  1308. procedure toption.parsecmd(cmd:string);
  1309. var
  1310. i,ps : longint;
  1311. opts : string;
  1312. begin
  1313. while (cmd<>'') do
  1314. begin
  1315. while cmd[1]=' ' do
  1316. delete(cmd,1,1);
  1317. i:=pos(' ',cmd);
  1318. if i=0 then
  1319. i:=256;
  1320. opts:=Copy(cmd,1,i-1);
  1321. Delete(cmd,1,i);
  1322. case opts[1] of
  1323. '@' :
  1324. if not firstpass then
  1325. begin
  1326. Delete(opts,1,1);
  1327. Message1(option_reading_further_from,opts);
  1328. interpret_file(opts);
  1329. end;
  1330. '!' :
  1331. if not firstpass then
  1332. begin
  1333. Delete(opts,1,1);
  1334. Message1(option_reading_further_from,'(env) '+opts);
  1335. interpret_envvar(opts);
  1336. end;
  1337. '"' :
  1338. begin
  1339. Delete(opts,1,1);
  1340. ps:=pos('"',cmd);
  1341. if (i<>256) and (ps>0) then
  1342. begin
  1343. opts:=opts + ' '+ copy(cmd,1,ps-1);
  1344. cmd:=copy(cmd,ps+1,255);
  1345. end;
  1346. interpret_option(opts,true);
  1347. end;
  1348. else
  1349. interpret_option(opts,true);
  1350. end;
  1351. end;
  1352. end;
  1353. procedure toption.writequickinfo;
  1354. var
  1355. s : string;
  1356. i : longint;
  1357. procedure addinfo(const hs:string);
  1358. begin
  1359. if s<>'' then
  1360. s:=s+' '+hs
  1361. else
  1362. s:=hs;
  1363. end;
  1364. begin
  1365. s:='';
  1366. i:=0;
  1367. while (i<length(quickinfo)) do
  1368. begin
  1369. inc(i);
  1370. case quickinfo[i] of
  1371. 'S' :
  1372. begin
  1373. inc(i);
  1374. case quickinfo[i] of
  1375. 'O' :
  1376. addinfo(lower(source_info.shortname));
  1377. {$ifdef Delphi}
  1378. 'P' :
  1379. addinfo('i386');
  1380. {$else Delphi}
  1381. 'P' :
  1382. addinfo(source_cpu_string);
  1383. {$endif Delphi}
  1384. else
  1385. IllegalPara('-iS'+QuickInfo);
  1386. end;
  1387. end;
  1388. 'T' :
  1389. begin
  1390. inc(i);
  1391. case quickinfo[i] of
  1392. 'O' :
  1393. addinfo(lower(target_info.shortname));
  1394. 'P' :
  1395. AddInfo(target_cpu_string);
  1396. else
  1397. IllegalPara('-iT'+QuickInfo);
  1398. end;
  1399. end;
  1400. 'V' :
  1401. AddInfo(version_string);
  1402. 'D' :
  1403. AddInfo(date_string);
  1404. '_' :
  1405. ;
  1406. else
  1407. IllegalPara('-i'+QuickInfo);
  1408. end;
  1409. end;
  1410. if s<>'' then
  1411. begin
  1412. writeln(s);
  1413. stopoptions;
  1414. end;
  1415. end;
  1416. procedure TOption.TargetDefines(def:boolean);
  1417. var
  1418. s : string;
  1419. i : integer;
  1420. begin
  1421. if def then
  1422. def_symbol(upper(target_info.shortname))
  1423. else
  1424. undef_symbol(upper(target_info.shortname));
  1425. s:=target_info.extradefines;
  1426. while (s<>'') do
  1427. begin
  1428. i:=pos(';',s);
  1429. if i=0 then
  1430. i:=length(s)+1;
  1431. if def then
  1432. def_symbol(Copy(s,1,i-1))
  1433. else
  1434. undef_symbol(Copy(s,1,i-1));
  1435. delete(s,1,i);
  1436. end;
  1437. end;
  1438. constructor TOption.create;
  1439. begin
  1440. DoWriteLogo:=false;
  1441. NoPressEnter:=false;
  1442. FirstPass:=false;
  1443. FileLevel:=0;
  1444. Quickinfo:='';
  1445. ParaIncludePath:=TSearchPathList.Create;
  1446. ParaObjectPath:=TSearchPathList.Create;
  1447. ParaUnitPath:=TSearchPathList.Create;
  1448. ParaLibraryPath:=TSearchPathList.Create;
  1449. FillChar(ParaAlignment,sizeof(ParaAlignment),0);
  1450. end;
  1451. destructor TOption.destroy;
  1452. begin
  1453. ParaIncludePath.Free;
  1454. ParaObjectPath.Free;
  1455. ParaUnitPath.Free;
  1456. ParaLibraryPath.Free;
  1457. end;
  1458. {****************************************************************************
  1459. Callable Routines
  1460. ****************************************************************************}
  1461. function check_configfile(const fn:string;var foundfn:string):boolean;
  1462. function CfgFileExists(const fn:string):boolean;
  1463. begin
  1464. Comment(V_Tried,'Configfile search: '+fn);
  1465. CfgFileExists:=FileExists(fn);
  1466. end;
  1467. var
  1468. configpath : pathstr;
  1469. begin
  1470. foundfn:=fn;
  1471. check_configfile:=true;
  1472. { retrieve configpath }
  1473. {$ifdef Delphi}
  1474. configpath:=FixPath(dmisc.getenv('PPC_CONFIG_PATH'),false);
  1475. {$else Delphi}
  1476. configpath:=FixPath(dos.getenv('PPC_CONFIG_PATH'),false);
  1477. {$endif Delphi}
  1478. {$ifdef Unix}
  1479. if configpath='' then
  1480. configpath:='/etc/';
  1481. {$endif}
  1482. {
  1483. Order to read configuration file :
  1484. try reading fpc.cfg in :
  1485. 1 - current dir
  1486. 2 - configpath
  1487. 3 - compiler path
  1488. }
  1489. if not FileExists(fn) then
  1490. begin
  1491. {$ifdef Unix}
  1492. if (dos.getenv('HOME')<>'') and CfgFileExists(FixPath(dos.getenv('HOME'),false)+'.'+fn) then
  1493. foundfn:=FixPath(dos.getenv('HOME'),false)+'.'+fn
  1494. else
  1495. {$endif}
  1496. if CfgFileExists(configpath+fn) then
  1497. foundfn:=configpath+fn
  1498. else
  1499. {$ifndef Unix}
  1500. if CfgFileExists(exepath+fn) then
  1501. foundfn:=exepath+fn
  1502. else
  1503. {$endif}
  1504. check_configfile:=false;
  1505. end;
  1506. end;
  1507. procedure read_arguments(cmd:string);
  1508. begin
  1509. option:=coption.create;
  1510. disable_configfile:=false;
  1511. { default defines }
  1512. def_symbol(upper(target_info.shortname));
  1513. def_symbol('FPC');
  1514. def_symbol('VER'+version_nr);
  1515. def_symbol('VER'+version_nr+'_'+release_nr);
  1516. def_symbol('VER'+version_nr+'_'+release_nr+'_'+patch_nr);
  1517. { Temporary defines, until things settle down }
  1518. def_symbol('HASWIDECHAR');
  1519. def_symbol('HASWIDESTRING');
  1520. def_symbol('HASOUT');
  1521. { for now, the PowerPC doesn't support variants and interfaces }
  1522. {$ifdef i386}
  1523. def_symbol('HASINTF');
  1524. def_symbol('HASVARIANT');
  1525. {$endif i386}
  1526. def_symbol('INTERNSETLENGTH');
  1527. def_symbol('INTERNLENGTH');
  1528. def_symbol('INTERNCOPY');
  1529. def_symbol('INT64FUNCRESOK');
  1530. def_symbol('HAS_ADDR_STACK_ON_STACK');
  1531. def_symbol('NOBOUNDCHECK');
  1532. def_symbol('HASCOMPILERPROC');
  1533. def_symbol('VALUEGETMEM');
  1534. def_symbol('VALUEFREEMEM');
  1535. def_symbol('HASCURRENCY');
  1536. def_symbol('HASTHREADVAR');
  1537. def_symbol('HAS_GENERICCONSTRUCTOR');
  1538. { using a case is pretty useless here (FK) }
  1539. { some stuff for TP compatibility }
  1540. {$ifdef i386}
  1541. def_symbol('CPU86');
  1542. def_symbol('CPU87');
  1543. {$endif}
  1544. {$ifdef m68k}
  1545. def_symbol('CPU68');
  1546. {$endif}
  1547. { new processor stuff }
  1548. {$ifdef i386}
  1549. def_symbol('CPUI386');
  1550. def_symbol('CPU32');
  1551. def_symbol('FPC_HAS_TYPE_EXTENDED');
  1552. def_symbol('FPC_HAS_TYPE_DOUBLE');
  1553. def_symbol('FPC_HAS_TYPE_SINGLE');
  1554. {$endif}
  1555. {$ifdef m68k}
  1556. def_symbol('CPU68K');
  1557. def_symbol('CPU32');
  1558. {$endif}
  1559. {$ifdef ALPHA}
  1560. def_symbol('CPUALPHA');
  1561. def_symbol('CPU64');
  1562. {$endif}
  1563. {$ifdef powerpc}
  1564. def_symbol('CPUPOWERPC');
  1565. def_symbol('CPUPOWERPC32');
  1566. def_symbol('CPU32');
  1567. def_symbol('FPC_HAS_TYPE_DOUBLE');
  1568. def_symbol('FPC_HAS_TYPE_SINGLE');
  1569. {$endif}
  1570. {$ifdef iA64}
  1571. def_symbol('CPUIA64');
  1572. def_symbol('CPU64');
  1573. {$endif}
  1574. {$ifdef x86_64}
  1575. def_symbol('CPUX86_64');
  1576. def_symbol('CPU64');
  1577. def_symbol('FPC_HAS_TYPE_FLOAT128');
  1578. def_symbol('FPC_HAS_TYPE_EXTENDED');
  1579. def_symbol('FPC_HAS_TYPE_DOUBLE');
  1580. def_symbol('FPC_HAS_TYPE_SINGLE');
  1581. {$endif}
  1582. {$ifdef sparc}
  1583. def_symbol('CPUSPARC');
  1584. def_symbol('CPUSPARC32');
  1585. def_symbol('CPU32');
  1586. {$endif}
  1587. {$ifdef vis}
  1588. def_symbol('CPUVIS');
  1589. def_symbol('CPU32');
  1590. {$endif}
  1591. { get default messagefile }
  1592. {$ifdef Delphi}
  1593. msgfilename:=dmisc.getenv('PPC_ERROR_FILE');
  1594. {$else Delphi}
  1595. msgfilename:=dos.getenv('PPC_ERROR_FILE');
  1596. {$endif Delphi}
  1597. { default configfile can be specified on the commandline,
  1598. remove it first }
  1599. if (cmd<>'') and (cmd[1]='[') then
  1600. begin
  1601. ppccfg:=Copy(cmd,2,pos(']',cmd)-2);
  1602. Delete(cmd,1,pos(']',cmd));
  1603. end
  1604. else
  1605. begin
  1606. ppccfg:='fpc.cfg';
  1607. ppcaltcfg:='ppc386.cfg';
  1608. end;
  1609. { read the parameters quick, only -i -v -T }
  1610. option.firstpass:=true;
  1611. if cmd<>'' then
  1612. option.parsecmd(cmd)
  1613. else
  1614. begin
  1615. option.read_parameters;
  1616. { Write only quickinfo }
  1617. if option.quickinfo<>'' then
  1618. option.writequickinfo;
  1619. end;
  1620. option.firstpass:=false;
  1621. { read configuration file }
  1622. if (not disable_configfile) and
  1623. (ppccfg<>'') then
  1624. begin
  1625. read_configfile:=check_configfile(ppccfg,ppccfg);
  1626. { Maybe alternative configfile ? }
  1627. if (not read_configfile) and
  1628. (ppcaltcfg<>'') then
  1629. read_configfile:=check_configfile(ppcaltcfg,ppccfg);
  1630. end
  1631. else
  1632. read_configfile := false;
  1633. { Read commandline and configfile }
  1634. target_is_set:=false;
  1635. asm_is_set:=false;
  1636. param_file:='';
  1637. { read configfile }
  1638. if read_configfile then
  1639. option.interpret_file(ppccfg);
  1640. { read parameters again to override config file }
  1641. if cmd<>'' then
  1642. option.parsecmd(cmd)
  1643. else
  1644. begin
  1645. option.read_parameters;
  1646. { Write only quickinfo }
  1647. if option.quickinfo<>'' then
  1648. option.writequickinfo;
  1649. end;
  1650. { Write help pages }
  1651. if (cmd='') and (paramcount=0) then
  1652. Option.WriteHelpPages;
  1653. { Stop if errors in options }
  1654. if ErrorCount>0 then
  1655. StopOptions;
  1656. { Non-core target defines }
  1657. Option.TargetDefines(true);
  1658. { endian define }
  1659. case target_info.endian of
  1660. endian_little :
  1661. begin
  1662. def_symbol('ENDIAN_LITTLE');
  1663. def_symbol('FPC_LITTLE_ENDIAN');
  1664. end;
  1665. endian_big :
  1666. begin
  1667. def_symbol('ENDIAN_BIG');
  1668. def_symbol('FPC_BIG_ENDIAN');
  1669. end;
  1670. end;
  1671. {$ifdef m68k}
  1672. if initoptprocessor=MC68020 then
  1673. def_symbol('CPUM68020');
  1674. {$endif m68k}
  1675. { write logo if set }
  1676. if option.DoWriteLogo then
  1677. option.WriteLogo;
  1678. { Check file to compile }
  1679. if param_file='' then
  1680. begin
  1681. Message(option_no_source_found);
  1682. StopOptions;
  1683. end;
  1684. {$ifndef Unix}
  1685. param_file:=FixFileName(param_file);
  1686. {$endif}
  1687. fsplit(param_file,inputdir,inputfile,inputextension);
  1688. if inputextension='' then
  1689. begin
  1690. if FileExists(inputdir+inputfile+target_info.sourceext) then
  1691. inputextension:=target_info.sourceext
  1692. else
  1693. if FileExists(inputdir+inputfile+target_info.pasext) then
  1694. inputextension:=target_info.pasext;
  1695. end;
  1696. { Add paths specified with parameters to the searchpaths }
  1697. UnitSearchPath.AddList(option.ParaUnitPath,true);
  1698. ObjectSearchPath.AddList(option.ParaObjectPath,true);
  1699. IncludeSearchPath.AddList(option.ParaIncludePath,true);
  1700. LibrarySearchPath.AddList(option.ParaLibraryPath,true);
  1701. { add unit environment and exepath to the unit search path }
  1702. if inputdir<>'' then
  1703. Unitsearchpath.AddPath(inputdir,true);
  1704. if not disable_configfile then
  1705. begin
  1706. {$ifdef Delphi}
  1707. UnitSearchPath.AddPath(dmisc.getenv(target_info.unit_env),false);
  1708. {$else}
  1709. UnitSearchPath.AddPath(dos.getenv(target_info.unit_env),false);
  1710. {$endif Delphi}
  1711. end;
  1712. {$ifdef Unix}
  1713. fpcdir:=FixPath(getenv('FPCDIR'),false);
  1714. if fpcdir='' then
  1715. begin
  1716. if PathExists('/usr/local/lib/fpc/'+version_string) then
  1717. fpcdir:='/usr/local/lib/fpc/'+version_string+'/'
  1718. else
  1719. fpcdir:='/usr/lib/fpc/'+version_string+'/';
  1720. end;
  1721. {$else}
  1722. fpcdir:=FixPath(getenv('FPCDIR'),false);
  1723. if fpcdir='' then
  1724. begin
  1725. fpcdir:=ExePath+'../';
  1726. if not(PathExists(fpcdir+'/units')) and
  1727. not(PathExists(fpcdir+'/rtl')) then
  1728. fpcdir:=fpcdir+'../';
  1729. end;
  1730. {$endif}
  1731. { first try development RTL, else use the default installation path }
  1732. if not disable_configfile then
  1733. begin
  1734. if PathExists(FpcDir+'rtl/'+lower(target_info.shortname)) then
  1735. UnitSearchPath.AddPath(FpcDir+'rtl/'+lower(target_info.shortname),false)
  1736. else
  1737. begin
  1738. UnitSearchPath.AddPath(FpcDir+'units/'+lower(target_info.shortname),false);
  1739. UnitSearchPath.AddPath(FpcDir+'units/'+lower(target_info.shortname)+'/rtl',false);
  1740. end;
  1741. end;
  1742. { Add exepath if the exe is not in the current dir, because that is always searched already }
  1743. if ExePath<>GetCurrentDir then
  1744. UnitSearchPath.AddPath(ExePath,false);
  1745. { Add unit dir to the object and library path }
  1746. objectsearchpath.AddList(unitsearchpath,false);
  1747. librarysearchpath.AddList(unitsearchpath,false);
  1748. { switch assembler if it's binary and we got -a on the cmdline }
  1749. if (cs_asm_leave in initglobalswitches) and
  1750. (target_asm.outputbinary) then
  1751. begin
  1752. Message(option_switch_bin_to_src_assembler);
  1753. set_target_asm(target_info.assemextern);
  1754. end;
  1755. if (target_asm.supported_target <> system_any) and
  1756. (target_asm.supported_target <> target_info.system) then
  1757. begin
  1758. Message2(option_incompatible_asm,target_asm.idtxt,target_info.name);
  1759. set_target_asm(target_info.assemextern);
  1760. Message1(option_asm_forced,target_asm.idtxt);
  1761. end;
  1762. { turn off stripping if compiling with debuginfo or profile }
  1763. if (cs_debuginfo in initmoduleswitches) or
  1764. (cs_profile in initmoduleswitches) then
  1765. exclude(initglobalswitches,cs_link_strip);
  1766. if not LinkTypeSetExplicitly then
  1767. set_default_link_type;
  1768. { Default alignment settings,
  1769. 1. load the defaults for the target
  1770. 2. override with generic optimizer setting (little size)
  1771. 3. override with the user specified -Oa }
  1772. UpdateAlignment(initalignment,target_info.alignment);
  1773. if (cs_littlesize in aktglobalswitches) then
  1774. begin
  1775. initalignment.procalign:=1;
  1776. initalignment.jumpalign:=1;
  1777. initalignment.loopalign:=1;
  1778. end;
  1779. UpdateAlignment(initalignment,option.paraalignment);
  1780. option.free;
  1781. Option:=nil;
  1782. end;
  1783. initialization
  1784. coption:=toption;
  1785. finalization
  1786. if assigned(option) then
  1787. option.free;
  1788. end.
  1789. {
  1790. $Log$
  1791. Revision 1.98 2003-05-11 19:17:16 florian
  1792. * FPC_LITTLE_ENDIAN and FPC_BIG_ENDIAN is now defined as well
  1793. Revision 1.97 2003/05/01 07:59:42 florian
  1794. * introduced defaultordconsttype to decribe the default size of ordinal constants
  1795. on 64 bit CPUs it's equal to cs64bitdef while on 32 bit CPUs it's equal to s32bitdef
  1796. + added defines CPU32 and CPU64 for 32 bit and 64 bit CPUs
  1797. * int64s/qwords are allowed as for loop counter on 64 bit CPUs
  1798. Revision 1.96 2003/04/30 16:35:00 florian
  1799. * fixed defines for x86-64
  1800. Revision 1.95 2003/04/24 11:21:45 florian
  1801. + HAS_TYPE_* defines for floats on i386 and powerpc added
  1802. Revision 1.94 2003/03/28 19:16:56 peter
  1803. * generic constructor working for i386
  1804. * remove fixed self register
  1805. * esi added as address register for i386
  1806. Revision 1.93 2003/03/23 23:20:38 hajny
  1807. + emx target added
  1808. Revision 1.92 2003/03/08 08:59:07 daniel
  1809. + $define newra will enable new register allocator
  1810. + getregisterint will return imaginary registers with $newra
  1811. + -sr switch added, will skip register allocation so you can see
  1812. the direct output of the code generator before register allocation
  1813. Revision 1.91 2002/12/06 16:56:58 peter
  1814. * only compile cs_fp_emulation support when cpufpuemu is defined
  1815. * define cpufpuemu for m68k only
  1816. Revision 1.90 2002/11/30 23:14:55 carl
  1817. - removed cs_fp_emulation checking for m68k, its now controled
  1818. by a global switch
  1819. + added powerpc/sparc/vis message options support
  1820. Revision 1.89 2002/11/30 21:29:56 carl
  1821. + -Ce for softfpu
  1822. Revision 1.88 2002/11/15 01:58:52 peter
  1823. * merged changes from 1.0.7 up to 04-11
  1824. - -V option for generating bug report tracing
  1825. - more tracing for option parsing
  1826. - errors for cdecl and high()
  1827. - win32 import stabs
  1828. - win32 records<=8 are returned in eax:edx (turned off by default)
  1829. - heaptrc update
  1830. - more info for temp management in .s file with EXTDEBUG
  1831. Revision 1.87 2002/10/23 17:07:40 peter
  1832. * fix -n that was broken in the previous commit
  1833. Revision 1.86 2002/10/23 16:57:16 peter
  1834. * first search for fpc.cfg instead of deprecated ppc386.cfg
  1835. * parse commandline options first before searching configfile so -vt
  1836. can be used to display the searched files
  1837. Revision 1.85 2002/10/13 21:33:01 peter
  1838. * define HASTHREADVAR
  1839. Revision 1.84 2002/10/02 18:20:52 peter
  1840. * Copy() is now internal syssym that calls compilerprocs
  1841. Revision 1.83 2002/09/22 14:02:35 carl
  1842. * stack checking cannot be called before system unit is initialized
  1843. * MC68020 define
  1844. Revision 1.82 2002/08/12 15:08:40 carl
  1845. + stab register indexes for powerpc (moved from gdb to cpubase)
  1846. + tprocessor enumeration moved to cpuinfo
  1847. + linker in target_info is now a class
  1848. * many many updates for m68k (will soon start to compile)
  1849. - removed some ifdef or correct them for correct cpu
  1850. Revision 1.81 2002/08/10 14:46:29 carl
  1851. + moved target_cpu_string to cpuinfo
  1852. * renamed asmmode enum.
  1853. * assembler reader has now less ifdef's
  1854. * move from nppcmem.pas -> ncgmem.pas vec. node.
  1855. Revision 1.80 2002/08/09 19:15:41 carl
  1856. - removed newcg define
  1857. Revision 1.79 2002/07/26 22:22:10 florian
  1858. * several PowerPC related fixes to get forward with system unit compilation
  1859. Revision 1.78 2002/07/26 21:15:39 florian
  1860. * rewrote the system handling
  1861. Revision 1.77 2002/07/20 17:16:03 florian
  1862. + source code page support
  1863. Revision 1.76 2002/07/04 20:43:01 florian
  1864. * first x86-64 patches
  1865. Revision 1.75 2002/07/01 18:46:24 peter
  1866. * internal linker
  1867. * reorganized aasm layer
  1868. Revision 1.74 2002/07/01 16:23:53 peter
  1869. * cg64 patch
  1870. * basics for currency
  1871. * asnode updates for class and interface (not finished)
  1872. Revision 1.73 2002/05/18 13:34:11 peter
  1873. * readded missing revisions
  1874. Revision 1.72 2002/05/16 19:46:41 carl
  1875. + defines.inc -> fpcdefs.inc to avoid conflicts if compiling by hand
  1876. + try to fix temp allocation (still in ifdef)
  1877. + generic constructor calls
  1878. + start of tassembler / tmodulebase class cleanup
  1879. Revision 1.70 2002/05/12 16:53:08 peter
  1880. * moved entry and exitcode to ncgutil and cgobj
  1881. * foreach gets extra argument for passing local data to the
  1882. iterator function
  1883. * -CR checks also class typecasts at runtime by changing them
  1884. into as
  1885. * fixed compiler to cycle with the -CR option
  1886. * fixed stabs with elf writer, finally the global variables can
  1887. be watched
  1888. * removed a lot of routines from cga unit and replaced them by
  1889. calls to cgobj
  1890. * u32bit-s32bit updates for and,or,xor nodes. When one element is
  1891. u32bit then the other is typecasted also to u32bit without giving
  1892. a rangecheck warning/error.
  1893. * fixed pascal calling method with reversing also the high tree in
  1894. the parast, detected by tcalcst3 test
  1895. Revision 1.69 2002/04/21 19:02:04 peter
  1896. * removed newn and disposen nodes, the code is now directly
  1897. inlined from pexpr
  1898. * -an option that will write the secondpass nodes to the .s file, this
  1899. requires EXTDEBUG define to actually write the info
  1900. * fixed various internal errors and crashes due recent code changes
  1901. Revision 1.68 2002/04/20 21:32:24 carl
  1902. + generic FPC_CHECKPOINTER
  1903. + first parameter offset in stack now portable
  1904. * rename some constants
  1905. + move some cpu stuff to other units
  1906. - remove unused constents
  1907. * fix stacksize for some targets
  1908. * fix generic size problems which depend now on EXTEND_SIZE constant
  1909. Revision 1.67 2002/04/07 10:22:35 carl
  1910. + CPU defines now depends on current target
  1911. Revision 1.66 2002/04/04 19:05:58 peter
  1912. * removed unused units
  1913. * use tlocation.size in cg.a_*loc*() routines
  1914. Revision 1.65 2002/04/04 18:39:45 carl
  1915. + added wdosx support (patch from Pavel)
  1916. }