options.pas 57 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021
  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. else if more<>'' then
  791. IllegalPara(opt);
  792. end;
  793. end;
  794. 'S' :
  795. begin
  796. if more[1]='I' then
  797. begin
  798. if upper(more)='ICOM' then
  799. initinterfacetype:=it_interfacecom
  800. else if upper(more)='ICORBA' then
  801. initinterfacetype:=it_interfacecorba
  802. else
  803. IllegalPara(opt);
  804. end
  805. else
  806. begin
  807. j:=1;
  808. while j<=length(more) do
  809. begin
  810. case more[j] of
  811. '2' :
  812. SetCompileMode('OBJFPC',true);
  813. 'a' :
  814. include(initlocalswitches,cs_do_assertion);
  815. 'c' :
  816. include(initmoduleswitches,cs_support_c_operators);
  817. 'd' :
  818. SetCompileMode('DELPHI',true);
  819. 'e' :
  820. begin
  821. SetErrorFlags(copy(more,j+1,length(more)));
  822. break;
  823. end;
  824. 'g' :
  825. include(initmoduleswitches,cs_support_goto);
  826. 'h' :
  827. include(initlocalswitches,cs_ansistrings);
  828. 'i' :
  829. include(initmoduleswitches,cs_support_inline);
  830. 'm' :
  831. include(initmoduleswitches,cs_support_macro);
  832. 'o' :
  833. SetCompileMode('TP',true);
  834. 'p' :
  835. SetCompileMode('GPC',true);
  836. 's' :
  837. include(initglobalswitches,cs_constructor_name);
  838. 't' :
  839. include(initmoduleswitches,cs_static_keyword);
  840. '-' :
  841. begin
  842. exclude(initglobalswitches,cs_constructor_name);
  843. initlocalswitches:=InitLocalswitches - [cs_do_assertion, cs_ansistrings];
  844. initmoduleswitches:=initmoduleswitches - [cs_support_c_operators, cs_support_goto,
  845. cs_support_inline, cs_support_macro,
  846. cs_static_keyword];
  847. end;
  848. else
  849. IllegalPara(opt);
  850. end;
  851. inc(j);
  852. end;
  853. end;
  854. end;
  855. 'T' :
  856. begin
  857. more:=Upper(More);
  858. if not target_is_set then
  859. begin
  860. { remove old target define }
  861. TargetDefines(false);
  862. { Save assembler if set }
  863. if asm_is_set then
  864. forceasm:=target_asm.id;
  865. { load new target }
  866. if not(set_target_by_string(More)) then
  867. IllegalPara(opt);
  868. { also initialize assembler if not explicitly set }
  869. if asm_is_set then
  870. set_target_asm(forceasm);
  871. { set new define }
  872. TargetDefines(true);
  873. target_is_set:=true;
  874. end
  875. else
  876. if More<>upper(target_info.shortname) then
  877. Message1(option_target_is_already_set,target_info.shortname);
  878. end;
  879. 'u' :
  880. undef_symbol(upper(More));
  881. 'U' :
  882. begin
  883. j:=1;
  884. while j<=length(more) do
  885. begin
  886. case more[j] of
  887. {$ifdef UNITALIASES}
  888. 'a' :
  889. begin
  890. AddUnitAlias(Copy(More,j+1,255));
  891. break;
  892. end;
  893. {$endif UNITALIASES}
  894. 'n' :
  895. exclude(initglobalswitches,cs_check_unit_name);
  896. 'p' :
  897. begin
  898. Message2(option_obsolete_switch_use_new,'-Up','-Fu');
  899. break;
  900. end;
  901. 'r' :
  902. do_release:=true;
  903. 's' :
  904. include(initmoduleswitches,cs_compilesystem);
  905. '-' :
  906. begin
  907. exclude(initmoduleswitches,cs_compilesystem);
  908. exclude(initglobalswitches,cs_check_unit_name);
  909. end;
  910. else
  911. IllegalPara(opt);
  912. end;
  913. inc(j);
  914. end;
  915. end;
  916. 'v' :
  917. begin
  918. if not setverbosity(More) then
  919. IllegalPara(opt);
  920. end;
  921. 'V' :
  922. PrepareReport;
  923. 'W' :
  924. begin
  925. j:=1;
  926. while j<=length(More) do
  927. begin
  928. case More[j] of
  929. 'B':
  930. begin
  931. { -WB200000 means set trefered base address
  932. to $200000, but does not change relocsection boolean
  933. this way we can create both relocatble and
  934. non relocatable DLL at a specific base address PM }
  935. if (length(More)>j) then
  936. begin
  937. if DLLImageBase=nil then
  938. DLLImageBase:=StringDup(Copy(More,j+1,255));
  939. end
  940. else
  941. begin
  942. RelocSection:=true;
  943. RelocSectionSetExplicitly:=true;
  944. end;
  945. break;
  946. end;
  947. 'C':
  948. begin
  949. if UnsetBool(More, j) then
  950. apptype:=app_gui
  951. else
  952. apptype:=app_cui;
  953. end;
  954. 'D':
  955. ForceDeffileForExport:=not UnsetBool(More, j);
  956. 'F':
  957. apptype:=app_fs;
  958. 'G':
  959. begin
  960. if UnsetBool(More, j) then
  961. apptype:=app_cui
  962. else
  963. apptype:=app_gui;
  964. end;
  965. 'N':
  966. begin
  967. RelocSection:=UnsetBool(More,j);
  968. RelocSectionSetExplicitly:=true;
  969. end;
  970. 'R':
  971. begin
  972. { support -WR+ / -WR- as synonims to -WR / -WN }
  973. RelocSection:=not UnsetBool(More,j);
  974. RelocSectionSetExplicitly:=true;
  975. end;
  976. else
  977. IllegalPara(opt);
  978. end;
  979. inc(j);
  980. end;
  981. end;
  982. 'X' :
  983. begin
  984. j:=1;
  985. while j<=length(more) do
  986. begin
  987. case More[j] of
  988. 'i' :
  989. include(initglobalswitches,cs_link_internal);
  990. 'm' :
  991. include(initglobalswitches,cs_link_map);
  992. 's' :
  993. include(initglobalswitches,cs_link_strip);
  994. 't' :
  995. include(initglobalswitches,cs_link_staticflag);
  996. 'D' :
  997. begin
  998. def_symbol('FPC_LINK_DYNAMIC');
  999. undef_symbol('FPC_LINK_SMART');
  1000. undef_symbol('FPC_LINK_STATIC');
  1001. exclude(initglobalswitches,cs_link_static);
  1002. exclude(initglobalswitches,cs_link_smart);
  1003. include(initglobalswitches,cs_link_shared);
  1004. LinkTypeSetExplicitly:=true;
  1005. end;
  1006. 'S' :
  1007. begin
  1008. def_symbol('FPC_LINK_STATIC');
  1009. undef_symbol('FPC_LINK_SMART');
  1010. undef_symbol('FPC_LINK_DYNAMIC');
  1011. include(initglobalswitches,cs_link_static);
  1012. exclude(initglobalswitches,cs_link_smart);
  1013. exclude(initglobalswitches,cs_link_shared);
  1014. LinkTypeSetExplicitly:=true;
  1015. end;
  1016. 'X' :
  1017. begin
  1018. def_symbol('FPC_LINK_SMART');
  1019. undef_symbol('FPC_LINK_STATIC');
  1020. undef_symbol('FPC_LINK_DYNAMIC');
  1021. exclude(initglobalswitches,cs_link_static);
  1022. include(initglobalswitches,cs_link_smart);
  1023. exclude(initglobalswitches,cs_link_shared);
  1024. LinkTypeSetExplicitly:=true;
  1025. end;
  1026. '-' :
  1027. begin
  1028. exclude(initglobalswitches,cs_link_staticflag);
  1029. exclude(initglobalswitches,cs_link_strip);
  1030. exclude(initglobalswitches,cs_link_map);
  1031. set_default_link_type;
  1032. end;
  1033. else
  1034. IllegalPara(opt);
  1035. end;
  1036. inc(j);
  1037. end;
  1038. end;
  1039. { give processor specific options a chance }
  1040. else
  1041. interpret_proc_specific_options(opt);
  1042. end;
  1043. end;
  1044. '@' :
  1045. begin
  1046. Message(option_no_nested_response_file);
  1047. StopOptions;
  1048. end;
  1049. else
  1050. begin
  1051. if (length(param_file)<>0) then
  1052. Message(option_only_one_source_support);
  1053. param_file:=opt;
  1054. Message1(option_found_file,opt);
  1055. end;
  1056. end;
  1057. end;
  1058. procedure Toption.Interpret_file(const filename : string);
  1059. procedure RemoveSep(var fn:string);
  1060. var
  1061. i : longint;
  1062. begin
  1063. i:=0;
  1064. while (i<length(fn)) and (fn[i+1] in [',',' ',#9]) do
  1065. inc(i);
  1066. Delete(fn,1,i);
  1067. i:=length(fn);
  1068. while (i>0) and (fn[i] in [',',' ',#9]) do
  1069. dec(i);
  1070. fn:=copy(fn,1,i);
  1071. end;
  1072. function GetName(var fn:string):string;
  1073. var
  1074. i : longint;
  1075. begin
  1076. i:=0;
  1077. while (i<length(fn)) and (fn[i+1] in ['a'..'z','A'..'Z','0'..'9','_','-']) do
  1078. inc(i);
  1079. GetName:=Copy(fn,1,i);
  1080. Delete(fn,1,i);
  1081. end;
  1082. const
  1083. maxlevel=16;
  1084. var
  1085. f : text;
  1086. s,
  1087. opts : string;
  1088. skip : array[0..maxlevel-1] of boolean;
  1089. level : longint;
  1090. option_read : boolean;
  1091. begin
  1092. { avoid infinite loop }
  1093. Inc(FileLevel);
  1094. Option_read:=false;
  1095. If FileLevel>MaxLevel then
  1096. Message(option_too_many_cfg_files);
  1097. { open file }
  1098. Message1(option_using_file,filename);
  1099. assign(f,filename);
  1100. {$I-}
  1101. reset(f);
  1102. {$I+}
  1103. if ioresult<>0 then
  1104. begin
  1105. Message1(option_unable_open_file,filename);
  1106. exit;
  1107. end;
  1108. Message1(option_start_reading_configfile,filename);
  1109. fillchar(skip,sizeof(skip),0);
  1110. level:=0;
  1111. while not eof(f) do
  1112. begin
  1113. readln(f,opts);
  1114. RemoveSep(opts);
  1115. if (opts<>'') and (opts[1]<>';') then
  1116. begin
  1117. if opts[1]='#' then
  1118. begin
  1119. Message1(option_interpreting_file_option,opts);
  1120. Delete(opts,1,1);
  1121. s:=upper(GetName(opts));
  1122. if (s='SECTION') then
  1123. begin
  1124. RemoveSep(opts);
  1125. s:=upper(GetName(opts));
  1126. if level=0 then
  1127. skip[level]:=not (check_symbol(s) or (s='COMMON'));
  1128. end
  1129. else
  1130. if (s='IFDEF') then
  1131. begin
  1132. RemoveSep(opts);
  1133. if Level>=maxlevel then
  1134. begin
  1135. Message(option_too_many_ifdef);
  1136. stopOptions;
  1137. end;
  1138. inc(Level);
  1139. skip[level]:=(skip[level-1] or (not check_symbol(upper(GetName(opts)))));
  1140. end
  1141. else
  1142. if (s='IFNDEF') then
  1143. begin
  1144. RemoveSep(opts);
  1145. if Level>=maxlevel then
  1146. begin
  1147. Message(option_too_many_ifdef);
  1148. stopOptions;
  1149. end;
  1150. inc(Level);
  1151. skip[level]:=(skip[level-1] or (check_symbol(upper(GetName(opts)))));
  1152. end
  1153. else
  1154. if (s='ELSE') then
  1155. skip[level]:=skip[level-1] or (not skip[level])
  1156. else
  1157. if (s='ENDIF') then
  1158. begin
  1159. skip[level]:=false;
  1160. if Level=0 then
  1161. begin
  1162. Message(option_too_many_endif);
  1163. stopOptions;
  1164. end;
  1165. dec(level);
  1166. end
  1167. else
  1168. if (not skip[level]) then
  1169. begin
  1170. if (s='DEFINE') then
  1171. begin
  1172. RemoveSep(opts);
  1173. def_symbol(upper(GetName(opts)));
  1174. end
  1175. else
  1176. if (s='UNDEF') then
  1177. begin
  1178. RemoveSep(opts);
  1179. undef_symbol(upper(GetName(opts)));
  1180. end
  1181. else
  1182. if (s='WRITE') then
  1183. begin
  1184. Delete(opts,1,1);
  1185. WriteLn(opts);
  1186. end
  1187. else
  1188. if (s='INCLUDE') then
  1189. begin
  1190. Delete(opts,1,1);
  1191. Interpret_file(opts);
  1192. end;
  1193. end;
  1194. end
  1195. else
  1196. begin
  1197. if (opts[1]='-') or (opts[1]='@') then
  1198. begin
  1199. if (not skip[level]) then
  1200. interpret_option(opts,false);
  1201. Option_read:=true;
  1202. end
  1203. else
  1204. Message1(option_illegal_para,opts);
  1205. end;
  1206. end;
  1207. end;
  1208. if Level>0 then
  1209. Message(option_too_less_endif);
  1210. if Not Option_read then
  1211. Message1(option_no_option_found,filename)
  1212. else
  1213. Message1(option_end_reading_configfile,filename);
  1214. Close(f);
  1215. Dec(FileLevel);
  1216. end;
  1217. procedure Toption.Interpret_envvar(const envname : string);
  1218. var
  1219. argstart,
  1220. env,
  1221. pc : pchar;
  1222. arglen : longint;
  1223. quote : set of char;
  1224. hs : string;
  1225. begin
  1226. Message1(option_using_env,envname);
  1227. env:=GetEnvPChar(envname);
  1228. pc:=env;
  1229. if assigned(pc) then
  1230. begin
  1231. repeat
  1232. { skip leading spaces }
  1233. while pc^ in [' ',#9,#13] do
  1234. inc(pc);
  1235. case pc^ of
  1236. #0 :
  1237. break;
  1238. '"' :
  1239. begin
  1240. quote:=['"'];
  1241. inc(pc);
  1242. end;
  1243. '''' :
  1244. begin
  1245. quote:=[''''];
  1246. inc(pc);
  1247. end;
  1248. else
  1249. quote:=[' ',#9,#13];
  1250. end;
  1251. { scan until the end of the argument }
  1252. argstart:=pc;
  1253. while (pc^<>#0) and not(pc^ in quote) do
  1254. inc(pc);
  1255. { create argument }
  1256. arglen:=pc-argstart;
  1257. hs[0]:=chr(arglen);
  1258. move(argstart^,hs[1],arglen);
  1259. interpret_option(hs,true);
  1260. { skip quote }
  1261. if pc^ in quote then
  1262. inc(pc);
  1263. until false;
  1264. end
  1265. else
  1266. Message1(option_no_option_found,'(env) '+envname);
  1267. FreeEnvPChar(env);
  1268. end;
  1269. procedure toption.read_parameters;
  1270. var
  1271. opts : string;
  1272. paramindex : longint;
  1273. begin
  1274. paramindex:=0;
  1275. while paramindex<paramcount do
  1276. begin
  1277. inc(paramindex);
  1278. opts:=system.paramstr(paramindex);
  1279. case opts[1] of
  1280. '@' :
  1281. if not firstpass then
  1282. begin
  1283. Delete(opts,1,1);
  1284. Message1(option_reading_further_from,opts);
  1285. interpret_file(opts);
  1286. end;
  1287. '!' :
  1288. if not firstpass then
  1289. begin
  1290. Delete(opts,1,1);
  1291. Message1(option_reading_further_from,'(env) '+opts);
  1292. interpret_envvar(opts);
  1293. end;
  1294. else
  1295. interpret_option(opts,true);
  1296. end;
  1297. end;
  1298. end;
  1299. procedure toption.parsecmd(cmd:string);
  1300. var
  1301. i,ps : longint;
  1302. opts : string;
  1303. begin
  1304. while (cmd<>'') do
  1305. begin
  1306. while cmd[1]=' ' do
  1307. delete(cmd,1,1);
  1308. i:=pos(' ',cmd);
  1309. if i=0 then
  1310. i:=256;
  1311. opts:=Copy(cmd,1,i-1);
  1312. Delete(cmd,1,i);
  1313. case opts[1] of
  1314. '@' :
  1315. if not firstpass then
  1316. begin
  1317. Delete(opts,1,1);
  1318. Message1(option_reading_further_from,opts);
  1319. interpret_file(opts);
  1320. end;
  1321. '!' :
  1322. if not firstpass then
  1323. begin
  1324. Delete(opts,1,1);
  1325. Message1(option_reading_further_from,'(env) '+opts);
  1326. interpret_envvar(opts);
  1327. end;
  1328. '"' :
  1329. begin
  1330. Delete(opts,1,1);
  1331. ps:=pos('"',cmd);
  1332. if (i<>256) and (ps>0) then
  1333. begin
  1334. opts:=opts + ' '+ copy(cmd,1,ps-1);
  1335. cmd:=copy(cmd,ps+1,255);
  1336. end;
  1337. interpret_option(opts,true);
  1338. end;
  1339. else
  1340. interpret_option(opts,true);
  1341. end;
  1342. end;
  1343. end;
  1344. procedure toption.writequickinfo;
  1345. var
  1346. s : string;
  1347. i : longint;
  1348. procedure addinfo(const hs:string);
  1349. begin
  1350. if s<>'' then
  1351. s:=s+' '+hs
  1352. else
  1353. s:=hs;
  1354. end;
  1355. begin
  1356. s:='';
  1357. i:=0;
  1358. while (i<length(quickinfo)) do
  1359. begin
  1360. inc(i);
  1361. case quickinfo[i] of
  1362. 'S' :
  1363. begin
  1364. inc(i);
  1365. case quickinfo[i] of
  1366. 'O' :
  1367. addinfo(lower(source_info.shortname));
  1368. {$ifdef Delphi}
  1369. 'P' :
  1370. addinfo('i386');
  1371. {$else Delphi}
  1372. 'P' :
  1373. addinfo(source_cpu_string);
  1374. {$endif Delphi}
  1375. else
  1376. IllegalPara('-iS'+QuickInfo);
  1377. end;
  1378. end;
  1379. 'T' :
  1380. begin
  1381. inc(i);
  1382. case quickinfo[i] of
  1383. 'O' :
  1384. addinfo(lower(target_info.shortname));
  1385. 'P' :
  1386. AddInfo(target_cpu_string);
  1387. else
  1388. IllegalPara('-iT'+QuickInfo);
  1389. end;
  1390. end;
  1391. 'V' :
  1392. AddInfo(version_string);
  1393. 'D' :
  1394. AddInfo(date_string);
  1395. '_' :
  1396. ;
  1397. else
  1398. IllegalPara('-i'+QuickInfo);
  1399. end;
  1400. end;
  1401. if s<>'' then
  1402. begin
  1403. writeln(s);
  1404. stopoptions;
  1405. end;
  1406. end;
  1407. procedure TOption.TargetDefines(def:boolean);
  1408. var
  1409. s : string;
  1410. i : integer;
  1411. begin
  1412. if def then
  1413. def_symbol(upper(target_info.shortname))
  1414. else
  1415. undef_symbol(upper(target_info.shortname));
  1416. s:=target_info.extradefines;
  1417. while (s<>'') do
  1418. begin
  1419. i:=pos(';',s);
  1420. if i=0 then
  1421. i:=length(s)+1;
  1422. if def then
  1423. def_symbol(Copy(s,1,i-1))
  1424. else
  1425. undef_symbol(Copy(s,1,i-1));
  1426. delete(s,1,i);
  1427. end;
  1428. end;
  1429. constructor TOption.create;
  1430. begin
  1431. DoWriteLogo:=false;
  1432. NoPressEnter:=false;
  1433. FirstPass:=false;
  1434. FileLevel:=0;
  1435. Quickinfo:='';
  1436. ParaIncludePath:=TSearchPathList.Create;
  1437. ParaObjectPath:=TSearchPathList.Create;
  1438. ParaUnitPath:=TSearchPathList.Create;
  1439. ParaLibraryPath:=TSearchPathList.Create;
  1440. FillChar(ParaAlignment,sizeof(ParaAlignment),0);
  1441. end;
  1442. destructor TOption.destroy;
  1443. begin
  1444. ParaIncludePath.Free;
  1445. ParaObjectPath.Free;
  1446. ParaUnitPath.Free;
  1447. ParaLibraryPath.Free;
  1448. end;
  1449. {****************************************************************************
  1450. Callable Routines
  1451. ****************************************************************************}
  1452. function check_configfile(const fn:string;var foundfn:string):boolean;
  1453. function CfgFileExists(const fn:string):boolean;
  1454. begin
  1455. Comment(V_Tried,'Configfile search: '+fn);
  1456. CfgFileExists:=FileExists(fn);
  1457. end;
  1458. var
  1459. configpath : pathstr;
  1460. begin
  1461. foundfn:=fn;
  1462. check_configfile:=true;
  1463. { retrieve configpath }
  1464. {$ifdef Delphi}
  1465. configpath:=FixPath(dmisc.getenv('PPC_CONFIG_PATH'),false);
  1466. {$else Delphi}
  1467. configpath:=FixPath(dos.getenv('PPC_CONFIG_PATH'),false);
  1468. {$endif Delphi}
  1469. {$ifdef Unix}
  1470. if configpath='' then
  1471. configpath:='/etc/';
  1472. {$endif}
  1473. {
  1474. Order to read configuration file :
  1475. try reading fpc.cfg in :
  1476. 1 - current dir
  1477. 2 - configpath
  1478. 3 - compiler path
  1479. }
  1480. if not FileExists(fn) then
  1481. begin
  1482. {$ifdef Unix}
  1483. if (dos.getenv('HOME')<>'') and CfgFileExists(FixPath(dos.getenv('HOME'),false)+'.'+fn) then
  1484. foundfn:=FixPath(dos.getenv('HOME'),false)+'.'+fn
  1485. else
  1486. {$endif}
  1487. if CfgFileExists(configpath+fn) then
  1488. foundfn:=configpath+fn
  1489. else
  1490. {$ifndef Unix}
  1491. if CfgFileExists(exepath+fn) then
  1492. foundfn:=exepath+fn
  1493. else
  1494. {$endif}
  1495. check_configfile:=false;
  1496. end;
  1497. end;
  1498. procedure read_arguments(cmd:string);
  1499. begin
  1500. option:=coption.create;
  1501. disable_configfile:=false;
  1502. { default defines }
  1503. def_symbol(upper(target_info.shortname));
  1504. def_symbol('FPC');
  1505. def_symbol('VER'+version_nr);
  1506. def_symbol('VER'+version_nr+'_'+release_nr);
  1507. def_symbol('VER'+version_nr+'_'+release_nr+'_'+patch_nr);
  1508. { Temporary defines, until things settle down }
  1509. def_symbol('HASWIDECHAR');
  1510. def_symbol('HASWIDESTRING');
  1511. def_symbol('HASOUT');
  1512. { for now, the PowerPC doesn't support variants and interfaces }
  1513. {$ifdef i386}
  1514. def_symbol('HASINTF');
  1515. def_symbol('HASVARIANT');
  1516. {$endif i386}
  1517. def_symbol('INTERNSETLENGTH');
  1518. def_symbol('INTERNLENGTH');
  1519. def_symbol('INTERNCOPY');
  1520. def_symbol('INT64FUNCRESOK');
  1521. def_symbol('HAS_ADDR_STACK_ON_STACK');
  1522. def_symbol('NOBOUNDCHECK');
  1523. def_symbol('HASCOMPILERPROC');
  1524. def_symbol('VALUEGETMEM');
  1525. def_symbol('VALUEFREEMEM');
  1526. def_symbol('HASCURRENCY');
  1527. def_symbol('HASTHREADVAR');
  1528. { using a case is pretty useless here (FK) }
  1529. { some stuff for TP compatibility }
  1530. {$ifdef i386}
  1531. def_symbol('CPU86');
  1532. def_symbol('CPU87');
  1533. {$endif}
  1534. {$ifdef m68k}
  1535. def_symbol('CPU68');
  1536. {$endif}
  1537. { new processor stuff }
  1538. {$ifdef i386}
  1539. def_symbol('CPUI386');
  1540. {$endif}
  1541. {$ifdef m68k}
  1542. def_symbol('CPU68K');
  1543. {$endif}
  1544. {$ifdef ALPHA}
  1545. def_symbol('CPUALPHA');
  1546. {$endif}
  1547. {$ifdef powerpc}
  1548. def_symbol('CPUPOWERPC');
  1549. {$endif}
  1550. {$ifdef iA64}
  1551. def_symbol('CPUIA64');
  1552. {$endif}
  1553. {$ifdef x64_64}
  1554. def_symbol('CPU86_64');
  1555. {$endif}
  1556. {$ifdef sparc}
  1557. def_symbol('CPUSPARC');
  1558. {$endif}
  1559. {$ifdef vis}
  1560. def_symbol('CPUVIS');
  1561. {$endif}
  1562. { get default messagefile }
  1563. {$ifdef Delphi}
  1564. msgfilename:=dmisc.getenv('PPC_ERROR_FILE');
  1565. {$else Delphi}
  1566. msgfilename:=dos.getenv('PPC_ERROR_FILE');
  1567. {$endif Delphi}
  1568. { default configfile can be specified on the commandline,
  1569. remove it first }
  1570. if (cmd<>'') and (cmd[1]='[') then
  1571. begin
  1572. ppccfg:=Copy(cmd,2,pos(']',cmd)-2);
  1573. Delete(cmd,1,pos(']',cmd));
  1574. end
  1575. else
  1576. begin
  1577. ppccfg:='fpc.cfg';
  1578. ppcaltcfg:='ppc386.cfg';
  1579. end;
  1580. { read the parameters quick, only -i -v -T }
  1581. option.firstpass:=true;
  1582. if cmd<>'' then
  1583. option.parsecmd(cmd)
  1584. else
  1585. begin
  1586. option.read_parameters;
  1587. { Write only quickinfo }
  1588. if option.quickinfo<>'' then
  1589. option.writequickinfo;
  1590. end;
  1591. option.firstpass:=false;
  1592. { read configuration file }
  1593. if (not disable_configfile) and
  1594. (ppccfg<>'') then
  1595. begin
  1596. read_configfile:=check_configfile(ppccfg,ppccfg);
  1597. { Maybe alternative configfile ? }
  1598. if (not read_configfile) and
  1599. (ppcaltcfg<>'') then
  1600. read_configfile:=check_configfile(ppcaltcfg,ppccfg);
  1601. end
  1602. else
  1603. read_configfile := false;
  1604. { Read commandline and configfile }
  1605. target_is_set:=false;
  1606. asm_is_set:=false;
  1607. param_file:='';
  1608. { read configfile }
  1609. if read_configfile then
  1610. option.interpret_file(ppccfg);
  1611. { read parameters again to override config file }
  1612. if cmd<>'' then
  1613. option.parsecmd(cmd)
  1614. else
  1615. begin
  1616. option.read_parameters;
  1617. { Write only quickinfo }
  1618. if option.quickinfo<>'' then
  1619. option.writequickinfo;
  1620. end;
  1621. { Write help pages }
  1622. if (cmd='') and (paramcount=0) then
  1623. Option.WriteHelpPages;
  1624. { Stop if errors in options }
  1625. if ErrorCount>0 then
  1626. StopOptions;
  1627. { Non-core target defines }
  1628. Option.TargetDefines(true);
  1629. { endian define }
  1630. case target_info.endian of
  1631. endian_little :
  1632. def_symbol('ENDIAN_LITTLE');
  1633. endian_big :
  1634. def_symbol('ENDIAN_BIG');
  1635. end;
  1636. {$ifdef m68k}
  1637. if initoptprocessor=MC68020 then
  1638. def_symbol('CPUM68020');
  1639. {$endif m68k}
  1640. { write logo if set }
  1641. if option.DoWriteLogo then
  1642. option.WriteLogo;
  1643. { Check file to compile }
  1644. if param_file='' then
  1645. begin
  1646. Message(option_no_source_found);
  1647. StopOptions;
  1648. end;
  1649. {$ifndef Unix}
  1650. param_file:=FixFileName(param_file);
  1651. {$endif}
  1652. fsplit(param_file,inputdir,inputfile,inputextension);
  1653. if inputextension='' then
  1654. begin
  1655. if FileExists(inputdir+inputfile+target_info.sourceext) then
  1656. inputextension:=target_info.sourceext
  1657. else
  1658. if FileExists(inputdir+inputfile+target_info.pasext) then
  1659. inputextension:=target_info.pasext;
  1660. end;
  1661. { Add paths specified with parameters to the searchpaths }
  1662. UnitSearchPath.AddList(option.ParaUnitPath,true);
  1663. ObjectSearchPath.AddList(option.ParaObjectPath,true);
  1664. IncludeSearchPath.AddList(option.ParaIncludePath,true);
  1665. LibrarySearchPath.AddList(option.ParaLibraryPath,true);
  1666. { add unit environment and exepath to the unit search path }
  1667. if inputdir<>'' then
  1668. Unitsearchpath.AddPath(inputdir,true);
  1669. if not disable_configfile then
  1670. begin
  1671. {$ifdef Delphi}
  1672. UnitSearchPath.AddPath(dmisc.getenv(target_info.unit_env),false);
  1673. {$else}
  1674. UnitSearchPath.AddPath(dos.getenv(target_info.unit_env),false);
  1675. {$endif Delphi}
  1676. end;
  1677. {$ifdef Unix}
  1678. fpcdir:=FixPath(getenv('FPCDIR'),false);
  1679. if fpcdir='' then
  1680. begin
  1681. if PathExists('/usr/local/lib/fpc/'+version_string) then
  1682. fpcdir:='/usr/local/lib/fpc/'+version_string+'/'
  1683. else
  1684. fpcdir:='/usr/lib/fpc/'+version_string+'/';
  1685. end;
  1686. {$else}
  1687. fpcdir:=FixPath(getenv('FPCDIR'),false);
  1688. if fpcdir='' then
  1689. begin
  1690. fpcdir:=ExePath+'../';
  1691. if not(PathExists(fpcdir+'/units')) and
  1692. not(PathExists(fpcdir+'/rtl')) then
  1693. fpcdir:=fpcdir+'../';
  1694. end;
  1695. {$endif}
  1696. { first try development RTL, else use the default installation path }
  1697. if not disable_configfile then
  1698. begin
  1699. if PathExists(FpcDir+'rtl/'+lower(target_info.shortname)) then
  1700. UnitSearchPath.AddPath(FpcDir+'rtl/'+lower(target_info.shortname),false)
  1701. else
  1702. begin
  1703. UnitSearchPath.AddPath(FpcDir+'units/'+lower(target_info.shortname),false);
  1704. UnitSearchPath.AddPath(FpcDir+'units/'+lower(target_info.shortname)+'/rtl',false);
  1705. end;
  1706. end;
  1707. { Add exepath if the exe is not in the current dir, because that is always searched already }
  1708. if ExePath<>GetCurrentDir then
  1709. UnitSearchPath.AddPath(ExePath,false);
  1710. { Add unit dir to the object and library path }
  1711. objectsearchpath.AddList(unitsearchpath,false);
  1712. librarysearchpath.AddList(unitsearchpath,false);
  1713. { switch assembler if it's binary and we got -a on the cmdline }
  1714. if (cs_asm_leave in initglobalswitches) and
  1715. (target_asm.outputbinary) then
  1716. begin
  1717. Message(option_switch_bin_to_src_assembler);
  1718. set_target_asm(target_info.assemextern);
  1719. end;
  1720. if (target_asm.supported_target <> system_any) and
  1721. (target_asm.supported_target <> target_info.system) then
  1722. begin
  1723. Message2(option_incompatible_asm,target_asm.idtxt,target_info.name);
  1724. set_target_asm(target_info.assemextern);
  1725. Message1(option_asm_forced,target_asm.idtxt);
  1726. end;
  1727. { turn off stripping if compiling with debuginfo or profile }
  1728. if (cs_debuginfo in initmoduleswitches) or
  1729. (cs_profile in initmoduleswitches) then
  1730. exclude(initglobalswitches,cs_link_strip);
  1731. if not LinkTypeSetExplicitly then
  1732. set_default_link_type;
  1733. { Default alignment settings,
  1734. 1. load the defaults for the target
  1735. 2. override with generic optimizer setting (little size)
  1736. 3. override with the user specified -Oa }
  1737. UpdateAlignment(initalignment,target_info.alignment);
  1738. if (cs_littlesize in aktglobalswitches) then
  1739. begin
  1740. initalignment.procalign:=1;
  1741. initalignment.jumpalign:=1;
  1742. initalignment.loopalign:=1;
  1743. end;
  1744. UpdateAlignment(initalignment,option.paraalignment);
  1745. option.free;
  1746. Option:=nil;
  1747. end;
  1748. initialization
  1749. coption:=toption;
  1750. finalization
  1751. if assigned(option) then
  1752. option.free;
  1753. end.
  1754. {
  1755. $Log$
  1756. Revision 1.91 2002-12-06 16:56:58 peter
  1757. * only compile cs_fp_emulation support when cpufpuemu is defined
  1758. * define cpufpuemu for m68k only
  1759. Revision 1.90 2002/11/30 23:14:55 carl
  1760. - removed cs_fp_emulation checking for m68k, its now controled
  1761. by a global switch
  1762. + added powerpc/sparc/vis message options support
  1763. Revision 1.89 2002/11/30 21:29:56 carl
  1764. + -Ce for softfpu
  1765. Revision 1.88 2002/11/15 01:58:52 peter
  1766. * merged changes from 1.0.7 up to 04-11
  1767. - -V option for generating bug report tracing
  1768. - more tracing for option parsing
  1769. - errors for cdecl and high()
  1770. - win32 import stabs
  1771. - win32 records<=8 are returned in eax:edx (turned off by default)
  1772. - heaptrc update
  1773. - more info for temp management in .s file with EXTDEBUG
  1774. Revision 1.87 2002/10/23 17:07:40 peter
  1775. * fix -n that was broken in the previous commit
  1776. Revision 1.86 2002/10/23 16:57:16 peter
  1777. * first search for fpc.cfg instead of deprecated ppc386.cfg
  1778. * parse commandline options first before searching configfile so -vt
  1779. can be used to display the searched files
  1780. Revision 1.85 2002/10/13 21:33:01 peter
  1781. * define HASTHREADVAR
  1782. Revision 1.84 2002/10/02 18:20:52 peter
  1783. * Copy() is now internal syssym that calls compilerprocs
  1784. Revision 1.83 2002/09/22 14:02:35 carl
  1785. * stack checking cannot be called before system unit is initialized
  1786. * MC68020 define
  1787. Revision 1.82 2002/08/12 15:08:40 carl
  1788. + stab register indexes for powerpc (moved from gdb to cpubase)
  1789. + tprocessor enumeration moved to cpuinfo
  1790. + linker in target_info is now a class
  1791. * many many updates for m68k (will soon start to compile)
  1792. - removed some ifdef or correct them for correct cpu
  1793. Revision 1.81 2002/08/10 14:46:29 carl
  1794. + moved target_cpu_string to cpuinfo
  1795. * renamed asmmode enum.
  1796. * assembler reader has now less ifdef's
  1797. * move from nppcmem.pas -> ncgmem.pas vec. node.
  1798. Revision 1.80 2002/08/09 19:15:41 carl
  1799. - removed newcg define
  1800. Revision 1.79 2002/07/26 22:22:10 florian
  1801. * several PowerPC related fixes to get forward with system unit compilation
  1802. Revision 1.78 2002/07/26 21:15:39 florian
  1803. * rewrote the system handling
  1804. Revision 1.77 2002/07/20 17:16:03 florian
  1805. + source code page support
  1806. Revision 1.76 2002/07/04 20:43:01 florian
  1807. * first x86-64 patches
  1808. Revision 1.75 2002/07/01 18:46:24 peter
  1809. * internal linker
  1810. * reorganized aasm layer
  1811. Revision 1.74 2002/07/01 16:23:53 peter
  1812. * cg64 patch
  1813. * basics for currency
  1814. * asnode updates for class and interface (not finished)
  1815. Revision 1.73 2002/05/18 13:34:11 peter
  1816. * readded missing revisions
  1817. Revision 1.72 2002/05/16 19:46:41 carl
  1818. + defines.inc -> fpcdefs.inc to avoid conflicts if compiling by hand
  1819. + try to fix temp allocation (still in ifdef)
  1820. + generic constructor calls
  1821. + start of tassembler / tmodulebase class cleanup
  1822. Revision 1.70 2002/05/12 16:53:08 peter
  1823. * moved entry and exitcode to ncgutil and cgobj
  1824. * foreach gets extra argument for passing local data to the
  1825. iterator function
  1826. * -CR checks also class typecasts at runtime by changing them
  1827. into as
  1828. * fixed compiler to cycle with the -CR option
  1829. * fixed stabs with elf writer, finally the global variables can
  1830. be watched
  1831. * removed a lot of routines from cga unit and replaced them by
  1832. calls to cgobj
  1833. * u32bit-s32bit updates for and,or,xor nodes. When one element is
  1834. u32bit then the other is typecasted also to u32bit without giving
  1835. a rangecheck warning/error.
  1836. * fixed pascal calling method with reversing also the high tree in
  1837. the parast, detected by tcalcst3 test
  1838. Revision 1.69 2002/04/21 19:02:04 peter
  1839. * removed newn and disposen nodes, the code is now directly
  1840. inlined from pexpr
  1841. * -an option that will write the secondpass nodes to the .s file, this
  1842. requires EXTDEBUG define to actually write the info
  1843. * fixed various internal errors and crashes due recent code changes
  1844. Revision 1.68 2002/04/20 21:32:24 carl
  1845. + generic FPC_CHECKPOINTER
  1846. + first parameter offset in stack now portable
  1847. * rename some constants
  1848. + move some cpu stuff to other units
  1849. - remove unused constents
  1850. * fix stacksize for some targets
  1851. * fix generic size problems which depend now on EXTEND_SIZE constant
  1852. Revision 1.67 2002/04/07 10:22:35 carl
  1853. + CPU defines now depends on current target
  1854. Revision 1.66 2002/04/04 19:05:58 peter
  1855. * removed unused units
  1856. * use tlocation.size in cg.a_*loc*() routines
  1857. Revision 1.65 2002/04/04 18:39:45 carl
  1858. + added wdosx support (patch from Pavel)
  1859. }