options.pas 57 KB

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