options.pas 62 KB

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