options.pas 62 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114
  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,scanner
  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. 'A',
  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. begin
  560. l:=Pos(':=',more);
  561. if l>0 then
  562. set_system_compvar(Copy(more,1,l-1),Copy(more,l+2,255))
  563. else
  564. def_system_macro(more);
  565. end;
  566. 'D' :
  567. begin
  568. include(initglobalswitches,cs_link_deffile);
  569. j:=1;
  570. while j<=length(more) do
  571. begin
  572. case more[j] of
  573. 'd' :
  574. begin
  575. description:=Copy(more,j+1,255);
  576. break;
  577. end;
  578. 'v' :
  579. begin
  580. dllversion:=Copy(more,j+1,255);
  581. l:=pos('.',dllversion);
  582. dllminor:=0;
  583. error:=0;
  584. if l>0 then
  585. begin
  586. val(copy(dllversion,l+1,255),minor,error);
  587. if (error=0) and
  588. (minor>=0) and (minor<=$ffff) then
  589. dllminor:=minor
  590. else
  591. if error=0 then
  592. error:=1;
  593. end;
  594. if l=0 then
  595. l:=256;
  596. dllmajor:=1;
  597. if error=0 then
  598. val(copy(dllversion,1,l-1),major,error);
  599. if (error=0) and (major>=0) and (major<=$ffff) then
  600. dllmajor:=major
  601. else
  602. if error=0 then
  603. error:=1;
  604. if error<>0 then
  605. Message1(scan_w_wrong_version_ignored,dllversion);
  606. break;
  607. end;
  608. 'w' :
  609. usewindowapi:=true;
  610. '-' :
  611. begin
  612. exclude(initglobalswitches,cs_link_deffile);
  613. usewindowapi:=false;
  614. end;
  615. else
  616. IllegalPara(opt);
  617. end;
  618. inc(j);
  619. end;
  620. end;
  621. 'e' :
  622. exepath:=FixPath(More,true);
  623. 'E' :
  624. begin
  625. if UnsetBool(More, 0) then
  626. exclude(initglobalswitches,cs_link_extern)
  627. else
  628. include(initglobalswitches,cs_link_extern);
  629. end;
  630. 'F' :
  631. begin
  632. c:=more[1];
  633. Delete(more,1,1);
  634. DefaultReplacements(More);
  635. case c of
  636. 'a' :
  637. autoloadunits:=more;
  638. 'c' :
  639. begin
  640. if (upper(more)='UTF8') or (upper(more)='UTF-8') then
  641. initsourcecodepage:='utf8'
  642. else if not(cpavailable(more)) then
  643. Message1(option_code_page_not_available,more)
  644. else
  645. initsourcecodepage:=more;
  646. end;
  647. 'D' :
  648. utilsdirectory:=FixPath(More,true);
  649. 'e' :
  650. SetRedirectFile(More);
  651. 'E' :
  652. OutputExeDir:=FixPath(More,true);
  653. 'i' :
  654. begin
  655. if ispara then
  656. ParaIncludePath.AddPath(More,false)
  657. else
  658. includesearchpath.AddPath(More,true);
  659. end;
  660. 'g' :
  661. Message2(option_obsolete_switch_use_new,'-Fg','-Fl');
  662. 'l' :
  663. begin
  664. if ispara then
  665. ParaLibraryPath.AddPath(More,false)
  666. else
  667. LibrarySearchPath.AddPath(More,true);
  668. end;
  669. 'L' :
  670. begin
  671. if More<>'' then
  672. ParaDynamicLinker:=More
  673. else
  674. IllegalPara(opt);
  675. end;
  676. 'o' :
  677. begin
  678. if ispara then
  679. ParaObjectPath.AddPath(More,false)
  680. else
  681. ObjectSearchPath.AddPath(More,true);
  682. end;
  683. 'r' :
  684. Msgfilename:=More;
  685. 'u' :
  686. begin
  687. if ispara then
  688. ParaUnitPath.AddPath(More,false)
  689. else
  690. unitsearchpath.AddPath(More,true);
  691. end;
  692. 'U' :
  693. OutputUnitDir:=FixPath(More,true);
  694. else
  695. IllegalPara(opt);
  696. end;
  697. end;
  698. 'g' : begin
  699. if UnsetBool(More, 0) then
  700. begin
  701. exclude(initmoduleswitches,cs_debuginfo);
  702. exclude(initglobalswitches,cs_gdb_dbx);
  703. exclude(initglobalswitches,cs_gdb_gsym);
  704. exclude(initglobalswitches,cs_gdb_heaptrc);
  705. exclude(initglobalswitches,cs_gdb_lineinfo);
  706. exclude(initlocalswitches,cs_checkpointer);
  707. end
  708. else
  709. begin
  710. {$ifdef GDB}
  711. include(initmoduleswitches,cs_debuginfo);
  712. {$else GDB}
  713. Message(option_no_debug_support);
  714. Message(option_no_debug_support_recompile_fpc);
  715. {$endif GDB}
  716. end;
  717. {$ifdef GDB}
  718. if not RelocSectionSetExplicitly then
  719. RelocSection:=false;
  720. j:=1;
  721. while j<=length(more) do
  722. begin
  723. case more[j] of
  724. 'd',
  725. 'g' :
  726. begin
  727. { ignore for compatibility,
  728. the code for dbx and gsym is broken }
  729. end;
  730. 'h' :
  731. begin
  732. if UnsetBool(More, j) then
  733. exclude(initglobalswitches,cs_gdb_heaptrc)
  734. else
  735. include(initglobalswitches,cs_gdb_heaptrc);
  736. end;
  737. 'l' :
  738. begin
  739. if UnsetBool(More, j) then
  740. exclude(initglobalswitches,cs_gdb_lineinfo)
  741. else
  742. include(initglobalswitches,cs_gdb_lineinfo);
  743. end;
  744. 'c' :
  745. begin
  746. if UnsetBool(More, j) then
  747. exclude(initlocalswitches,cs_checkpointer)
  748. else
  749. include(initlocalswitches,cs_checkpointer);
  750. end;
  751. 'v' :
  752. begin
  753. if UnsetBool(More, j) then
  754. exclude(initglobalswitches,cs_gdb_valgrind)
  755. else
  756. include(initglobalswitches,cs_gdb_valgrind);
  757. end;
  758. 'w' :
  759. begin
  760. if UnsetBool(More, j) then
  761. exclude(initglobalswitches,cs_gdb_dwarf)
  762. else
  763. include(initglobalswitches,cs_gdb_dwarf);
  764. end;
  765. else
  766. IllegalPara(opt);
  767. end;
  768. inc(j);
  769. end;
  770. {$endif GDB}
  771. end;
  772. 'h' :
  773. begin
  774. NoPressEnter:=true;
  775. WriteHelpPages;
  776. end;
  777. 'i' :
  778. begin
  779. if More='' then
  780. WriteInfo
  781. else
  782. QuickInfo:=QuickInfo+More;
  783. end;
  784. 'I' :
  785. begin
  786. if ispara then
  787. ParaIncludePath.AddPath(More,false)
  788. else
  789. includesearchpath.AddPath(More,false);
  790. end;
  791. 'k' :
  792. begin
  793. if more<>'' then
  794. ParaLinkOptions:=ParaLinkOptions+' '+More
  795. else
  796. IllegalPara(opt);
  797. end;
  798. 'l' :
  799. if not UnSetBool(more,0) then
  800. ParaLogo:=true;
  801. 'm' :
  802. parapreprocess:=not UnSetBool(more,0);
  803. 'M' :
  804. begin
  805. more:=Upper(more);
  806. if not SetCompileMode(more, true) then
  807. IllegalPara(opt);
  808. end;
  809. 'n' :
  810. begin
  811. if More='' then
  812. disable_configfile:=true
  813. else
  814. IllegalPara(opt);
  815. end;
  816. 'o' :
  817. begin
  818. if More<>'' then
  819. begin
  820. {$IFDEF USE_SYSUTILS}
  821. D:=SplitPath(More);
  822. OutputFile:=SplitFileName(More);
  823. OutputExtension:=SplitExtension(More);
  824. {$ELSE USE_SYSUTILS}
  825. FSplit(More,D,OutputFile,OutputExtension);
  826. {$ENDIF USE_SYSUTILS}
  827. if (D<>'') then
  828. OutputExeDir:=FixPath(D,True);
  829. end
  830. else
  831. IllegalPara(opt);
  832. end;
  833. 'p' :
  834. begin
  835. if UnsetBool(More, 0) then
  836. begin
  837. initmoduleswitches:=initmoduleswitches-[cs_profile];
  838. undef_system_macro('FPC_PROFILE');
  839. end
  840. else
  841. if Length(More)=0 then
  842. IllegalPara(opt)
  843. else
  844. case more[1] of
  845. 'g' : if UnsetBool(more, 1) then
  846. begin
  847. exclude(initmoduleswitches,cs_profile);
  848. undef_system_macro('FPC_PROFILE');
  849. end
  850. else
  851. begin
  852. include(initmoduleswitches,cs_profile);
  853. def_system_macro('FPC_PROFILE');
  854. end;
  855. else
  856. IllegalPara(opt);
  857. end;
  858. end;
  859. 'P' : ; { Ignore used by fpc.pp }
  860. 's' :
  861. begin
  862. if UnsetBool(More, 0) then
  863. begin
  864. initglobalswitches:=initglobalswitches-[cs_asm_extern,cs_link_extern];
  865. if more<>'' then
  866. IllegalPara(opt);
  867. end
  868. else
  869. begin
  870. initglobalswitches:=initglobalswitches+[cs_asm_extern,cs_link_extern];
  871. if more='h' then
  872. initglobalswitches:=initglobalswitches-[cs_link_on_target]
  873. else if more='t' then
  874. initglobalswitches:=initglobalswitches+[cs_link_on_target]
  875. else if more='r' then
  876. initglobalswitches:=initglobalswitches+[cs_asm_leave,cs_no_regalloc]
  877. else if more<>'' then
  878. IllegalPara(opt);
  879. end;
  880. end;
  881. 'S' :
  882. begin
  883. if more[1]='I' then
  884. begin
  885. if upper(more)='ICOM' then
  886. initinterfacetype:=it_interfacecom
  887. else if upper(more)='ICORBA' then
  888. initinterfacetype:=it_interfacecorba
  889. else
  890. IllegalPara(opt);
  891. end
  892. else
  893. begin
  894. j:=1;
  895. while j<=length(more) do
  896. begin
  897. case more[j] of
  898. '2' : //an alternative to -Mobjfpc
  899. SetCompileMode('OBJFPC',true);
  900. 'a' :
  901. include(initlocalswitches,cs_do_assertion);
  902. 'c' :
  903. include(initmoduleswitches,cs_support_c_operators);
  904. 'd' : //an alternative to -Mdelphi
  905. SetCompileMode('DELPHI',true);
  906. 'e' :
  907. begin
  908. SetErrorFlags(copy(more,j+1,length(more)));
  909. break;
  910. end;
  911. 'g' :
  912. include(initmoduleswitches,cs_support_goto);
  913. 'h' :
  914. include(initlocalswitches,cs_ansistrings);
  915. 'i' :
  916. include(initmoduleswitches,cs_support_inline);
  917. 'k' :
  918. include(initglobalswitches,cs_load_fpcylix_unit);
  919. 'm' :
  920. include(initmoduleswitches,cs_support_macro);
  921. 'o' : //an alternative to -Mtp
  922. SetCompileMode('TP',true);
  923. 'p' : //an alternative to -Mgpc
  924. SetCompileMode('GPC',true);
  925. 's' :
  926. include(initglobalswitches,cs_constructor_name);
  927. 't' :
  928. include(initmoduleswitches,cs_static_keyword);
  929. '-' :
  930. begin
  931. exclude(initglobalswitches,cs_constructor_name);
  932. initlocalswitches:=InitLocalswitches - [cs_do_assertion, cs_ansistrings];
  933. initmoduleswitches:=initmoduleswitches - [cs_support_c_operators, cs_support_goto,
  934. cs_support_inline, cs_support_macro,
  935. cs_static_keyword];
  936. end;
  937. else
  938. IllegalPara(opt);
  939. end;
  940. inc(j);
  941. end;
  942. end;
  943. end;
  944. 'T' :
  945. begin
  946. more:=Upper(More);
  947. if not target_is_set then
  948. begin
  949. { remove old target define }
  950. TargetDefines(false);
  951. { Save assembler if set }
  952. if asm_is_set then
  953. forceasm:=target_asm.id;
  954. { load new target }
  955. if not(set_target_by_string(More)) then
  956. IllegalPara(opt);
  957. { also initialize assembler if not explicitly set }
  958. if asm_is_set then
  959. set_target_asm(forceasm);
  960. { set new define }
  961. TargetDefines(true);
  962. target_is_set:=true;
  963. end
  964. else
  965. if More<>upper(target_info.shortname) then
  966. Message1(option_target_is_already_set,target_info.shortname);
  967. end;
  968. 'u' :
  969. if more <> '' then
  970. undef_system_macro(more);
  971. 'U' :
  972. begin
  973. j:=1;
  974. while j<=length(more) do
  975. begin
  976. case more[j] of
  977. {$ifdef UNITALIASES}
  978. 'a' :
  979. begin
  980. AddUnitAlias(Copy(More,j+1,255));
  981. break;
  982. end;
  983. {$endif UNITALIASES}
  984. 'n' :
  985. exclude(initglobalswitches,cs_check_unit_name);
  986. 'p' :
  987. begin
  988. Message2(option_obsolete_switch_use_new,'-Up','-Fu');
  989. break;
  990. end;
  991. 'r' :
  992. do_release:=true;
  993. 's' :
  994. include(initmoduleswitches,cs_compilesystem);
  995. '-' :
  996. begin
  997. exclude(initmoduleswitches,cs_compilesystem);
  998. exclude(initglobalswitches,cs_check_unit_name);
  999. end;
  1000. else
  1001. IllegalPara(opt);
  1002. end;
  1003. inc(j);
  1004. end;
  1005. end;
  1006. 'v' :
  1007. begin
  1008. if not setverbosity(More) then
  1009. IllegalPara(opt);
  1010. end;
  1011. 'V' : ; { Ignore used by fpc }
  1012. 'W' :
  1013. begin
  1014. j:=1;
  1015. while j<=length(More) do
  1016. begin
  1017. case More[j] of
  1018. 'B':
  1019. begin
  1020. { -WB200000 means set trefered base address
  1021. to $200000, but does not change relocsection boolean
  1022. this way we can create both relocatble and
  1023. non relocatable DLL at a specific base address PM }
  1024. if (length(More)>j) then
  1025. begin
  1026. if DLLImageBase=nil then
  1027. DLLImageBase:=StringDup(Copy(More,j+1,255));
  1028. end
  1029. else
  1030. begin
  1031. RelocSection:=true;
  1032. RelocSectionSetExplicitly:=true;
  1033. end;
  1034. break;
  1035. end;
  1036. 'C':
  1037. begin
  1038. if UnsetBool(More, j) then
  1039. apptype:=app_gui
  1040. else
  1041. apptype:=app_cui;
  1042. end;
  1043. 'D':
  1044. begin
  1045. UseDeffileForExports:=not UnsetBool(More, j);
  1046. UseDeffileForExportsSetExplicitly:=true;
  1047. end;
  1048. 'F':
  1049. begin
  1050. if UnsetBool(More, j) then
  1051. apptype:=app_cui
  1052. else
  1053. apptype:=app_fs;
  1054. end;
  1055. 'G':
  1056. begin
  1057. if UnsetBool(More, j) then
  1058. apptype:=app_cui
  1059. else
  1060. apptype:=app_gui;
  1061. end;
  1062. 'T':
  1063. begin
  1064. if UnsetBool(More, j) then
  1065. apptype:=app_cui
  1066. else
  1067. apptype:=app_tool;
  1068. end;
  1069. 'N':
  1070. begin
  1071. RelocSection:=UnsetBool(More,j);
  1072. RelocSectionSetExplicitly:=true;
  1073. end;
  1074. 'R':
  1075. begin
  1076. { support -WR+ / -WR- as synonyms to -WR / -WN }
  1077. RelocSection:=not UnsetBool(More,j);
  1078. RelocSectionSetExplicitly:=true;
  1079. end;
  1080. else
  1081. IllegalPara(opt);
  1082. end;
  1083. inc(j);
  1084. end;
  1085. end;
  1086. 'X' :
  1087. begin
  1088. j:=1;
  1089. while j<=length(more) do
  1090. begin
  1091. case More[j] of
  1092. 'i' :
  1093. include(initglobalswitches,cs_link_internal);
  1094. 'm' :
  1095. include(initglobalswitches,cs_link_map);
  1096. 'f' :
  1097. include(initglobalswitches,cs_link_pthread);
  1098. 's' :
  1099. include(initglobalswitches,cs_link_strip);
  1100. 'c' : Cshared:=TRUE;
  1101. 't' :
  1102. include(initglobalswitches,cs_link_staticflag);
  1103. 'D' :
  1104. begin
  1105. def_system_macro('FPC_LINK_DYNAMIC');
  1106. undef_system_macro('FPC_LINK_SMART');
  1107. undef_system_macro('FPC_LINK_STATIC');
  1108. exclude(initglobalswitches,cs_link_static);
  1109. exclude(initglobalswitches,cs_link_smart);
  1110. include(initglobalswitches,cs_link_shared);
  1111. LinkTypeSetExplicitly:=true;
  1112. end;
  1113. 'd' : Dontlinkstdlibpath:=TRUE;
  1114. 'P' : Begin
  1115. utilsprefix:=Copy(more,2,length(More)-1);
  1116. DefaultReplacements(utilsprefix);
  1117. More:='';
  1118. End;
  1119. 'r' : Begin
  1120. rlinkpath:=Copy(more,2,length(More)-1);
  1121. DefaultReplacements(rlinkpath);
  1122. More:='';
  1123. end;
  1124. 'S' :
  1125. begin
  1126. def_system_macro('FPC_LINK_STATIC');
  1127. undef_system_macro('FPC_LINK_SMART');
  1128. undef_system_macro('FPC_LINK_DYNAMIC');
  1129. include(initglobalswitches,cs_link_static);
  1130. exclude(initglobalswitches,cs_link_smart);
  1131. exclude(initglobalswitches,cs_link_shared);
  1132. LinkTypeSetExplicitly:=true;
  1133. end;
  1134. 'X' :
  1135. begin
  1136. def_system_macro('FPC_LINK_SMART');
  1137. undef_system_macro('FPC_LINK_STATIC');
  1138. undef_system_macro('FPC_LINK_DYNAMIC');
  1139. exclude(initglobalswitches,cs_link_static);
  1140. include(initglobalswitches,cs_link_smart);
  1141. exclude(initglobalswitches,cs_link_shared);
  1142. LinkTypeSetExplicitly:=true;
  1143. end;
  1144. 'M' :
  1145. begin
  1146. mainaliasname:=Copy(more,2,length(More)-1);
  1147. More:='';
  1148. end;
  1149. '-' :
  1150. begin
  1151. exclude(initglobalswitches,cs_link_staticflag);
  1152. exclude(initglobalswitches,cs_link_strip);
  1153. exclude(initglobalswitches,cs_link_map);
  1154. set_default_link_type;
  1155. end;
  1156. else
  1157. IllegalPara(opt);
  1158. end;
  1159. inc(j);
  1160. end;
  1161. end;
  1162. { give processor specific options a chance }
  1163. else
  1164. interpret_proc_specific_options(opt);
  1165. end;
  1166. end;
  1167. '@' :
  1168. begin
  1169. Message(option_no_nested_response_file);
  1170. StopOptions(1);
  1171. end;
  1172. else
  1173. begin
  1174. if (length(param_file)<>0) then
  1175. Message(option_only_one_source_support);
  1176. param_file:=opt;
  1177. Message1(option_found_file,opt);
  1178. end;
  1179. end;
  1180. end;
  1181. procedure Toption.Interpret_file(const filename : string);
  1182. procedure RemoveSep(var fn:string);
  1183. var
  1184. i : longint;
  1185. begin
  1186. i:=0;
  1187. while (i<length(fn)) and (fn[i+1] in [',',' ',#9]) do
  1188. inc(i);
  1189. Delete(fn,1,i);
  1190. i:=length(fn);
  1191. while (i>0) and (fn[i] in [',',' ',#9]) do
  1192. dec(i);
  1193. fn:=copy(fn,1,i);
  1194. end;
  1195. function GetName(var fn:string):string;
  1196. var
  1197. i : longint;
  1198. begin
  1199. i:=0;
  1200. while (i<length(fn)) and (fn[i+1] in ['a'..'z','A'..'Z','0'..'9','_','-']) do
  1201. inc(i);
  1202. GetName:=Copy(fn,1,i);
  1203. Delete(fn,1,i);
  1204. end;
  1205. const
  1206. maxlevel=16;
  1207. var
  1208. f : text;
  1209. s, tmp,
  1210. opts : string;
  1211. skip : array[0..maxlevel-1] of boolean;
  1212. level : longint;
  1213. option_read : boolean;
  1214. begin
  1215. { avoid infinite loop }
  1216. Inc(FileLevel);
  1217. Option_read:=false;
  1218. If FileLevel>MaxLevel then
  1219. Message(option_too_many_cfg_files);
  1220. { Maybe It's Directory ?} //Jaro Change:
  1221. if DirectoryExists(filename) then
  1222. begin
  1223. Message1(option_config_is_dir,filename);
  1224. exit;
  1225. end;
  1226. { open file }
  1227. Message1(option_using_file,filename);
  1228. {$ifdef USE_SYSUTILS}
  1229. assign(f,ExpandFileName(filename));
  1230. {$else USE_SYSUTILS}
  1231. assign(f,FExpand(filename));
  1232. {$endif USE_SYsUTILS}
  1233. {$I-}
  1234. reset(f);
  1235. {$I+}
  1236. if ioresult<>0 then
  1237. begin
  1238. Message1(option_unable_open_file,filename);
  1239. exit;
  1240. end;
  1241. Message1(option_start_reading_configfile,filename);
  1242. fillchar(skip,sizeof(skip),0);
  1243. level:=0;
  1244. while not eof(f) do
  1245. begin
  1246. readln(f,opts);
  1247. RemoveSep(opts);
  1248. if (opts<>'') and (opts[1]<>';') then
  1249. begin
  1250. if opts[1]='#' then
  1251. begin
  1252. Message1(option_interpreting_file_option,opts);
  1253. Delete(opts,1,1);
  1254. s:=upper(GetName(opts));
  1255. if (s='SECTION') then
  1256. begin
  1257. RemoveSep(opts);
  1258. s:=upper(GetName(opts));
  1259. if level=0 then
  1260. skip[level]:=not (assigned(search_macro(s)) or (s='COMMON'));
  1261. end
  1262. else
  1263. if (s='IFDEF') then
  1264. begin
  1265. RemoveSep(opts);
  1266. if Level>=maxlevel then
  1267. begin
  1268. Message(option_too_many_ifdef);
  1269. stopOptions(1);
  1270. end;
  1271. inc(Level);
  1272. skip[level]:=(skip[level-1] or not assigned(search_macro(upper(GetName(opts)))));
  1273. end
  1274. else
  1275. if (s='IFNDEF') then
  1276. begin
  1277. RemoveSep(opts);
  1278. if Level>=maxlevel then
  1279. begin
  1280. Message(option_too_many_ifdef);
  1281. stopOptions(1);
  1282. end;
  1283. inc(Level);
  1284. skip[level]:=(skip[level-1] or assigned(search_macro(upper(GetName(opts)))));
  1285. end
  1286. else
  1287. if (s='ELSE') then
  1288. skip[level]:=skip[level-1] or (not skip[level])
  1289. else
  1290. if (s='ENDIF') then
  1291. begin
  1292. skip[level]:=false;
  1293. if Level=0 then
  1294. begin
  1295. Message(option_too_many_endif);
  1296. stopOptions(1);
  1297. end;
  1298. dec(level);
  1299. end
  1300. else
  1301. if (not skip[level]) then
  1302. begin
  1303. if (s='DEFINE') then
  1304. begin
  1305. RemoveSep(opts);
  1306. tmp:= GetName(opts);
  1307. if tmp <> '' then
  1308. def_system_macro(tmp);
  1309. end
  1310. else
  1311. if (s='UNDEF') then
  1312. begin
  1313. RemoveSep(opts);
  1314. tmp:= GetName(opts);
  1315. if tmp <> '' then
  1316. undef_system_macro(tmp);
  1317. end
  1318. else
  1319. if (s='WRITE') then
  1320. begin
  1321. Delete(opts,1,1);
  1322. WriteLn(opts);
  1323. end
  1324. else
  1325. if (s='INCLUDE') then
  1326. begin
  1327. Delete(opts,1,1);
  1328. Interpret_file(opts);
  1329. end;
  1330. end;
  1331. end
  1332. else
  1333. begin
  1334. if (opts[1]='-') or (opts[1]='@') then
  1335. begin
  1336. if (not skip[level]) then
  1337. interpret_option(opts,false);
  1338. Option_read:=true;
  1339. end
  1340. else
  1341. Message1(option_illegal_para,opts);
  1342. end;
  1343. end;
  1344. end;
  1345. if Level>0 then
  1346. Message(option_too_less_endif);
  1347. if Not Option_read then
  1348. Message1(option_no_option_found,filename)
  1349. else
  1350. Message1(option_end_reading_configfile,filename);
  1351. Close(f);
  1352. Dec(FileLevel);
  1353. end;
  1354. procedure Toption.Interpret_envvar(const envname : string);
  1355. var
  1356. argstart,
  1357. env,
  1358. pc : pchar;
  1359. arglen : longint;
  1360. quote : set of char;
  1361. hs : string;
  1362. begin
  1363. Message1(option_using_env,envname);
  1364. env:=GetEnvPChar(envname);
  1365. pc:=env;
  1366. if assigned(pc) then
  1367. begin
  1368. repeat
  1369. { skip leading spaces }
  1370. while pc^ in [' ',#9,#13] do
  1371. inc(pc);
  1372. case pc^ of
  1373. #0 :
  1374. break;
  1375. '"' :
  1376. begin
  1377. quote:=['"'];
  1378. inc(pc);
  1379. end;
  1380. '''' :
  1381. begin
  1382. quote:=[''''];
  1383. inc(pc);
  1384. end;
  1385. else
  1386. quote:=[' ',#9,#13];
  1387. end;
  1388. { scan until the end of the argument }
  1389. argstart:=pc;
  1390. while (pc^<>#0) and not(pc^ in quote) do
  1391. inc(pc);
  1392. { create argument }
  1393. arglen:=pc-argstart;
  1394. hs[0]:=chr(arglen);
  1395. move(argstart^,hs[1],arglen);
  1396. interpret_option(hs,true);
  1397. { skip quote }
  1398. if pc^ in quote then
  1399. inc(pc);
  1400. until false;
  1401. end
  1402. else
  1403. Message1(option_no_option_found,'(env) '+envname);
  1404. FreeEnvPChar(env);
  1405. end;
  1406. procedure toption.read_parameters;
  1407. var
  1408. opts : string;
  1409. paramindex : longint;
  1410. begin
  1411. paramindex:=0;
  1412. while paramindex<paramcount do
  1413. begin
  1414. inc(paramindex);
  1415. opts:=system.paramstr(paramindex);
  1416. case opts[1] of
  1417. '@' :
  1418. if not firstpass then
  1419. begin
  1420. Delete(opts,1,1);
  1421. Message1(option_reading_further_from,opts);
  1422. interpret_file(opts);
  1423. end;
  1424. '!' :
  1425. if not firstpass then
  1426. begin
  1427. Delete(opts,1,1);
  1428. Message1(option_reading_further_from,'(env) '+opts);
  1429. interpret_envvar(opts);
  1430. end;
  1431. else
  1432. interpret_option(opts,true);
  1433. end;
  1434. end;
  1435. end;
  1436. procedure toption.parsecmd(cmd:string);
  1437. var
  1438. i,ps : longint;
  1439. opts : string;
  1440. begin
  1441. while (cmd<>'') do
  1442. begin
  1443. while cmd[1]=' ' do
  1444. delete(cmd,1,1);
  1445. i:=pos(' ',cmd);
  1446. if i=0 then
  1447. i:=256;
  1448. opts:=Copy(cmd,1,i-1);
  1449. Delete(cmd,1,i);
  1450. case opts[1] of
  1451. '@' :
  1452. if not firstpass then
  1453. begin
  1454. Delete(opts,1,1);
  1455. Message1(option_reading_further_from,opts);
  1456. interpret_file(opts);
  1457. end;
  1458. '!' :
  1459. if not firstpass then
  1460. begin
  1461. Delete(opts,1,1);
  1462. Message1(option_reading_further_from,'(env) '+opts);
  1463. interpret_envvar(opts);
  1464. end;
  1465. '"' :
  1466. begin
  1467. Delete(opts,1,1);
  1468. ps:=pos('"',cmd);
  1469. if (i<>256) and (ps>0) then
  1470. begin
  1471. opts:=opts + ' '+ copy(cmd,1,ps-1);
  1472. cmd:=copy(cmd,ps+1,255);
  1473. end;
  1474. interpret_option(opts,true);
  1475. end;
  1476. else
  1477. interpret_option(opts,true);
  1478. end;
  1479. end;
  1480. end;
  1481. procedure toption.writequickinfo;
  1482. var
  1483. s : string;
  1484. i : longint;
  1485. procedure addinfo(const hs:string);
  1486. begin
  1487. if s<>'' then
  1488. s:=s+' '+hs
  1489. else
  1490. s:=hs;
  1491. end;
  1492. begin
  1493. s:='';
  1494. i:=0;
  1495. while (i<length(quickinfo)) do
  1496. begin
  1497. inc(i);
  1498. case quickinfo[i] of
  1499. 'S' :
  1500. begin
  1501. inc(i);
  1502. case quickinfo[i] of
  1503. 'O' :
  1504. addinfo(lower(source_info.shortname));
  1505. 'P' :
  1506. addinfo(source_cpu_string);
  1507. else
  1508. IllegalPara('-i'+QuickInfo);
  1509. end;
  1510. end;
  1511. 'T' :
  1512. begin
  1513. inc(i);
  1514. case quickinfo[i] of
  1515. 'O' :
  1516. addinfo(lower(target_info.shortname));
  1517. 'P' :
  1518. AddInfo(target_cpu_string);
  1519. else
  1520. IllegalPara('-i'+QuickInfo);
  1521. end;
  1522. end;
  1523. 'V' :
  1524. AddInfo(version_string);
  1525. 'D' :
  1526. AddInfo(date_string);
  1527. '_' :
  1528. ;
  1529. else
  1530. IllegalPara('-i'+QuickInfo);
  1531. end;
  1532. end;
  1533. if s<>'' then
  1534. begin
  1535. writeln(s);
  1536. stopoptions(0);
  1537. end;
  1538. end;
  1539. procedure TOption.TargetDefines(def:boolean);
  1540. var
  1541. s : string;
  1542. i : integer;
  1543. begin
  1544. if def then
  1545. def_system_macro(target_info.shortname)
  1546. else
  1547. undef_system_macro(target_info.shortname);
  1548. s:=target_info.extradefines;
  1549. while (s<>'') do
  1550. begin
  1551. i:=pos(';',s);
  1552. if i=0 then
  1553. i:=length(s)+1;
  1554. if def then
  1555. def_system_macro(Copy(s,1,i-1))
  1556. else
  1557. undef_system_macro(Copy(s,1,i-1));
  1558. delete(s,1,i);
  1559. end;
  1560. end;
  1561. constructor TOption.create;
  1562. begin
  1563. LogoWritten:=false;
  1564. NoPressEnter:=false;
  1565. FirstPass:=false;
  1566. FileLevel:=0;
  1567. Quickinfo:='';
  1568. ParaIncludePath:=TSearchPathList.Create;
  1569. ParaObjectPath:=TSearchPathList.Create;
  1570. ParaUnitPath:=TSearchPathList.Create;
  1571. ParaLibraryPath:=TSearchPathList.Create;
  1572. FillChar(ParaAlignment,sizeof(ParaAlignment),0);
  1573. end;
  1574. destructor TOption.destroy;
  1575. begin
  1576. ParaIncludePath.Free;
  1577. ParaObjectPath.Free;
  1578. ParaUnitPath.Free;
  1579. ParaLibraryPath.Free;
  1580. end;
  1581. {****************************************************************************
  1582. Callable Routines
  1583. ****************************************************************************}
  1584. function check_configfile(const fn:string;var foundfn:string):boolean;
  1585. function CfgFileExists(const fn:string):boolean;
  1586. begin
  1587. Comment(V_Tried,'Configfile search: '+fn);
  1588. CfgFileExists:=FileExists(fn);
  1589. end;
  1590. var
  1591. configpath : pathstr;
  1592. begin
  1593. foundfn:=fn;
  1594. check_configfile:=true;
  1595. { retrieve configpath }
  1596. {$IFDEF USE_SYSUTILS}
  1597. configpath:=FixPath(GetEnvironmentVariable('PPC_CONFIG_PATH'),false);
  1598. {$ELSE USE_SYSUTILS}
  1599. configpath:=FixPath(dos.getenv('PPC_CONFIG_PATH'),false);
  1600. {$ENDIF USE_SYSUTILS}
  1601. {$ifdef Unix}
  1602. if configpath='' then
  1603. configpath:=CleanPath(FixPath(exepath+'../etc/',false));
  1604. {$endif}
  1605. {
  1606. Order to read configuration file :
  1607. try reading fpc.cfg in :
  1608. 1 - current dir
  1609. 2 - configpath
  1610. 3 - compiler path
  1611. }
  1612. if not FileExists(fn) then
  1613. begin
  1614. {$ifdef Unix}
  1615. {$IFDEF USE_SYSUTILS}
  1616. if (GetEnvironmentVariable('HOME')<>'') and CfgFileExists(FixPath(GetEnvironmentVariable('HOME'),false)+'.'+fn) then
  1617. foundfn:=FixPath(GetEnvironmentVariable('HOME'),false)+'.'+fn
  1618. {$ELSE USE_SYSUTILS}
  1619. if (dos.getenv('HOME')<>'') and CfgFileExists(FixPath(dos.getenv('HOME'),false)+'.'+fn) then
  1620. foundfn:=FixPath(dos.getenv('HOME'),false)+'.'+fn
  1621. {$ENDIF USE_SYSUTILS}
  1622. else
  1623. {$endif}
  1624. if CfgFileExists(configpath+fn) then
  1625. foundfn:=configpath+fn
  1626. else
  1627. {$ifndef Unix}
  1628. if CfgFileExists(exepath+fn) then
  1629. foundfn:=exepath+fn
  1630. else
  1631. {$else}
  1632. if CfgFileExists('/etc/'+fn) then
  1633. foundfn:='/etc/'+fn
  1634. else
  1635. {$endif}
  1636. check_configfile:=false;
  1637. end;
  1638. end;
  1639. procedure read_arguments(cmd:string);
  1640. begin
  1641. option:=coption.create;
  1642. disable_configfile:=false;
  1643. { get default messagefile }
  1644. {$IFDEF USE_SYSUTILS}
  1645. msgfilename:=GetEnvironmentVariable('PPC_ERROR_FILE');
  1646. {$ELSE USE_SYSUTILS}
  1647. msgfilename:=dos.getenv('PPC_ERROR_FILE');
  1648. {$ENDIF USE_SYSUTILS}
  1649. { default configfile can be specified on the commandline,
  1650. remove it first }
  1651. if (cmd<>'') and (cmd[1]='[') then
  1652. begin
  1653. ppccfg:=Copy(cmd,2,pos(']',cmd)-2);
  1654. Delete(cmd,1,pos(']',cmd));
  1655. end
  1656. else
  1657. begin
  1658. ppccfg:='fpc.cfg';
  1659. ppcaltcfg:='ppc386.cfg';
  1660. end;
  1661. { first pass reading of parameters, only -i -v -T etc.}
  1662. option.firstpass:=true;
  1663. if cmd<>'' then
  1664. option.parsecmd(cmd)
  1665. else
  1666. begin
  1667. option.read_parameters;
  1668. { Write only quickinfo }
  1669. if option.quickinfo<>'' then
  1670. option.writequickinfo;
  1671. end;
  1672. option.firstpass:=false;
  1673. { default defines }
  1674. def_system_macro(target_info.shortname);
  1675. def_system_macro('FPC');
  1676. def_system_macro('VER'+version_nr);
  1677. def_system_macro('VER'+version_nr+'_'+release_nr);
  1678. def_system_macro('VER'+version_nr+'_'+release_nr+'_'+patch_nr);
  1679. { Temporary defines, until things settle down }
  1680. def_system_macro('COMPPROCINLINEFIXED');
  1681. { "main" symbol is generated in the main program, and left out of the system unit }
  1682. def_system_macro('FPC_DARWIN_PASCALMAIN');
  1683. if pocall_default = pocall_register then
  1684. def_system_macro('REGCALL');
  1685. { using a case is pretty useless here (FK) }
  1686. { some stuff for TP compatibility }
  1687. {$ifdef i386}
  1688. def_system_macro('CPU86');
  1689. def_system_macro('CPU87');
  1690. def_system_macro('CPU386');
  1691. {$endif}
  1692. {$ifdef m68k}
  1693. def_system_macro('CPU68');
  1694. {$endif}
  1695. { new processor stuff }
  1696. {$ifdef i386}
  1697. def_system_macro('CPUI386');
  1698. def_system_macro('CPU32');
  1699. def_system_macro('FPC_HAS_TYPE_EXTENDED');
  1700. def_system_macro('FPC_HAS_TYPE_DOUBLE');
  1701. def_system_macro('FPC_HAS_TYPE_SINGLE');
  1702. def_system_macro('FPC_HAS_RESOURCES');
  1703. {$endif}
  1704. {$ifdef m68k}
  1705. def_system_macro('CPU68K');
  1706. def_system_macro('CPUM68K');
  1707. def_system_macro('CPU32');
  1708. def_system_macro('FPC_CURRENCY_IS_INT64');
  1709. def_system_macro('FPC_COMP_IS_INT64');
  1710. {$endif}
  1711. {$ifdef ALPHA}
  1712. def_system_macro('CPUALPHA');
  1713. def_system_macro('CPU64');
  1714. {$endif}
  1715. {$ifdef powerpc}
  1716. def_system_macro('CPUPOWERPC');
  1717. def_system_macro('CPUPOWERPC32');
  1718. def_system_macro('CPU32');
  1719. def_system_macro('FPC_HAS_TYPE_DOUBLE');
  1720. def_system_macro('FPC_HAS_TYPE_SINGLE');
  1721. def_system_macro('FPC_INCLUDE_SOFTWARE_INT64_TO_DOUBLE');
  1722. def_system_macro('FPC_CURRENCY_IS_INT64');
  1723. def_system_macro('FPC_COMP_IS_INT64');
  1724. {$endif}
  1725. {$ifdef iA64}
  1726. def_system_macro('CPUIA64');
  1727. def_system_macro('CPU64');
  1728. {$endif}
  1729. {$ifdef x86_64}
  1730. def_system_macro('CPUX86_64');
  1731. def_system_macro('CPUAMD64');
  1732. def_system_macro('CPU64');
  1733. { not supported for now, afaik (FK)
  1734. def_system_macro('FPC_HAS_TYPE_FLOAT128'); }
  1735. def_system_macro('FPC_HAS_TYPE_EXTENDED');
  1736. def_system_macro('FPC_HAS_TYPE_DOUBLE');
  1737. def_system_macro('FPC_HAS_TYPE_SINGLE');
  1738. {$endif}
  1739. {$ifdef sparc}
  1740. def_system_macro('CPUSPARC');
  1741. def_system_macro('CPUSPARC32');
  1742. def_system_macro('CPU32');
  1743. def_system_macro('FPC_HAS_TYPE_DOUBLE');
  1744. def_system_macro('FPC_HAS_TYPE_SINGLE');
  1745. def_system_macro('FPC_INCLUDE_SOFTWARE_INT64_TO_DOUBLE');
  1746. def_system_macro('FPC_CURRENCY_IS_INT64');
  1747. def_system_macro('FPC_COMP_IS_INT64');
  1748. def_system_macro('FPC_REQUIRES_PROPER_ALIGNMENT');
  1749. {$endif}
  1750. {$ifdef vis}
  1751. def_system_macro('CPUVIS');
  1752. def_system_macro('CPU32');
  1753. {$endif}
  1754. {$ifdef arm}
  1755. def_system_macro('CPUARM');
  1756. def_system_macro('FPUFPA');
  1757. def_system_macro('CPU32');
  1758. def_system_macro('FPC_HAS_TYPE_DOUBLE');
  1759. def_system_macro('FPC_HAS_TYPE_SINGLE');
  1760. def_system_macro('FPC_INCLUDE_SOFTWARE_INT64_TO_DOUBLE');
  1761. def_system_macro('FPC_CURRENCY_IS_INT64');
  1762. def_system_macro('FPC_COMP_IS_INT64');
  1763. def_system_macro('FPC_REQUIRES_PROPER_ALIGNMENT');
  1764. {$endif arm}
  1765. if source_info.system<>target_info.system then
  1766. def_system_macro('FPC_CROSSCOMPILING');
  1767. if source_info.cpu<>target_info.cpu then
  1768. def_system_macro('FPC_CPUCROSSCOMPILING');
  1769. { read configuration file }
  1770. if (not disable_configfile) and
  1771. (ppccfg<>'') then
  1772. begin
  1773. read_configfile:=check_configfile(ppccfg,ppccfg);
  1774. { Maybe alternative configfile ? }
  1775. if (not read_configfile) and
  1776. (ppcaltcfg<>'') then
  1777. read_configfile:=check_configfile(ppcaltcfg,ppccfg);
  1778. end
  1779. else
  1780. read_configfile := false;
  1781. { Read commandline and configfile }
  1782. target_is_set:=false;
  1783. asm_is_set:=false;
  1784. param_file:='';
  1785. { read configfile }
  1786. if read_configfile then
  1787. option.interpret_file(ppccfg);
  1788. { read parameters again to override config file }
  1789. if cmd<>'' then
  1790. option.parsecmd(cmd)
  1791. else
  1792. begin
  1793. { Write help pages if no parameters are passed }
  1794. if (paramcount=0) then
  1795. Option.WriteHelpPages;
  1796. option.read_parameters;
  1797. { Write only quickinfo }
  1798. if option.quickinfo<>'' then
  1799. option.writequickinfo;
  1800. end;
  1801. { Stop if errors in options }
  1802. if ErrorCount>0 then
  1803. StopOptions(1);
  1804. { Write logo }
  1805. if option.ParaLogo then
  1806. option.writelogo;
  1807. { Non-core target defines }
  1808. Option.TargetDefines(true);
  1809. { endian define }
  1810. case target_info.endian of
  1811. endian_little :
  1812. begin
  1813. def_system_macro('ENDIAN_LITTLE');
  1814. def_system_macro('FPC_LITTLE_ENDIAN');
  1815. end;
  1816. endian_big :
  1817. begin
  1818. def_system_macro('ENDIAN_BIG');
  1819. def_system_macro('FPC_BIG_ENDIAN');
  1820. end;
  1821. end;
  1822. { abi define }
  1823. case target_info.abi of
  1824. abi_powerpc_sysv :
  1825. def_system_macro('FPC_ABI_SYSV');
  1826. abi_powerpc_aix :
  1827. def_system_macro('FPC_ABI_AIX');
  1828. end;
  1829. {$ifdef m68k}
  1830. if initoptprocessor=MC68020 then
  1831. def_system_macro('CPUM68020');
  1832. {$endif m68k}
  1833. { Check file to compile }
  1834. if param_file='' then
  1835. begin
  1836. Message(option_no_source_found);
  1837. StopOptions(1);
  1838. end;
  1839. {$ifndef Unix}
  1840. param_file:=FixFileName(param_file);
  1841. {$endif}
  1842. {$IFDEF USE_SYSUTILS}
  1843. inputdir := SplitPath(param_file);
  1844. inputfile := SplitName(param_file);
  1845. inputextension := SplitExtension(param_file);
  1846. {$ELSE USE_SYSUTILS}
  1847. fsplit(param_file,inputdir,inputfile,inputextension);
  1848. {$ENDIF USE_SYSUTILS}
  1849. if inputextension='' then
  1850. begin
  1851. if FileExists(inputdir+inputfile+sourceext) then
  1852. inputextension:=sourceext
  1853. else if FileExists(inputdir+inputfile+pasext) then
  1854. inputextension:=pasext
  1855. else if ((m_mac in aktmodeswitches) or target_info.p_ext_support)
  1856. and FileExists(inputdir+inputfile+pext) then
  1857. inputextension:=pext;
  1858. end;
  1859. { Check output dir }
  1860. if (OutputExeDir<>'') and
  1861. not PathExists(OutputExeDir) then
  1862. begin
  1863. Message1(general_e_path_does_not_exist,OutputExeDir);
  1864. StopOptions(1);
  1865. end;
  1866. { Add paths specified with parameters to the searchpaths }
  1867. UnitSearchPath.AddList(option.ParaUnitPath,true);
  1868. ObjectSearchPath.AddList(option.ParaObjectPath,true);
  1869. IncludeSearchPath.AddList(option.ParaIncludePath,true);
  1870. LibrarySearchPath.AddList(option.ParaLibraryPath,true);
  1871. { add unit environment and exepath to the unit search path }
  1872. if inputdir<>'' then
  1873. Unitsearchpath.AddPath(inputdir,true);
  1874. if not disable_configfile then
  1875. begin
  1876. {$IFDEF USE_SYSUTILS}
  1877. UnitSearchPath.AddPath(GetEnvironmentVariable(target_info.unit_env),false);
  1878. {$ELSE USE_SYSUTILS}
  1879. UnitSearchPath.AddPath(dos.getenv(target_info.unit_env),false);
  1880. {$ENDIF USE_SYSUTILS}
  1881. end;
  1882. {$ifdef Unix}
  1883. {$IFDEF USE_SYSUTILS}
  1884. fpcdir:=FixPath(GetEnvironmentVariable('FPCDIR'),false);
  1885. {$ELSE USE_SYSUTILS}
  1886. fpcdir:=FixPath(getenv('FPCDIR'),false);
  1887. {$ENDIF USE_SYSUTILS}
  1888. if fpcdir='' then
  1889. begin
  1890. if PathExists('/usr/local/lib/fpc/'+version_string) then
  1891. fpcdir:='/usr/local/lib/fpc/'+version_string+'/'
  1892. else
  1893. fpcdir:='/usr/lib/fpc/'+version_string+'/';
  1894. end;
  1895. {$else}
  1896. {$IFDEF USE_SYSUTILS}
  1897. fpcdir:=FixPath(GetEnvironmentVariable('FPCDIR'),false);
  1898. {$ELSE USE_SYSUTILS}
  1899. fpcdir:=FixPath(getenv('FPCDIR'),false);
  1900. {$ENDIF USE_SYSUTILS}
  1901. if fpcdir='' then
  1902. begin
  1903. fpcdir:=ExePath+'../';
  1904. if not(PathExists(fpcdir+'/units')) and
  1905. not(PathExists(fpcdir+'/rtl')) then
  1906. fpcdir:=fpcdir+'../';
  1907. end;
  1908. {$endif}
  1909. { first try development RTL, else use the default installation path }
  1910. if not disable_configfile then
  1911. begin
  1912. if PathExists(FpcDir+'rtl') then
  1913. if tf_use_8_3 in Source_Info.Flags then
  1914. UnitSearchPath.AddPath(FpcDir+'rtl/'+target_os_string,false)
  1915. else
  1916. UnitSearchPath.AddPath(FpcDir+'rtl/'+target_full_string,false)
  1917. else
  1918. if tf_use_8_3 in Source_Info.Flags then
  1919. UnitSearchPath.AddPath(FpcDir+'units/'+target_os_string+'/rtl',false)
  1920. else
  1921. UnitSearchPath.AddPath(FpcDir+'units/'+target_full_string+'/rtl',false);
  1922. end;
  1923. { Add exepath if the exe is not in the current dir, because that is always searched already.
  1924. Do not add it when linking on the target because then we can maybe already find
  1925. .o files that are not for the target }
  1926. if (ExePath<>GetCurrentDir) and
  1927. not(cs_link_on_target in initglobalswitches) then
  1928. UnitSearchPath.AddPath(ExePath,false);
  1929. { Add unit dir to the object and library path }
  1930. objectsearchpath.AddList(unitsearchpath,false);
  1931. librarysearchpath.AddList(unitsearchpath,false);
  1932. { switch assembler if it's binary and we got -a on the cmdline }
  1933. if (cs_asm_leave in initglobalswitches) and
  1934. (af_outputbinary in target_asm.flags) then
  1935. begin
  1936. Message(option_switch_bin_to_src_assembler);
  1937. set_target_asm(target_info.assemextern);
  1938. end;
  1939. if (target_asm.supported_target <> system_any) and
  1940. (target_asm.supported_target <> target_info.system) then
  1941. begin
  1942. Message2(option_incompatible_asm,target_asm.idtxt,target_info.name);
  1943. set_target_asm(target_info.assemextern);
  1944. Message1(option_asm_forced,target_asm.idtxt);
  1945. end;
  1946. { turn off stripping if compiling with debuginfo or profile }
  1947. if (cs_debuginfo in initmoduleswitches) or
  1948. (cs_profile in initmoduleswitches) then
  1949. exclude(initglobalswitches,cs_link_strip);
  1950. {$ifdef x86_64}
  1951. {$warning HACK: turn off smartlinking}
  1952. exclude(initmoduleswitches,cs_create_smart);
  1953. {$endif}
  1954. if not LinkTypeSetExplicitly then
  1955. set_default_link_type;
  1956. { Default alignment settings,
  1957. 1. load the defaults for the target
  1958. 2. override with generic optimizer setting (little size)
  1959. 3. override with the user specified -Oa }
  1960. UpdateAlignment(initalignment,target_info.alignment);
  1961. if (cs_littlesize in aktglobalswitches) then
  1962. begin
  1963. initalignment.procalign:=1;
  1964. initalignment.jumpalign:=1;
  1965. initalignment.loopalign:=1;
  1966. end;
  1967. UpdateAlignment(initalignment,option.paraalignment);
  1968. set_system_macro('FPC_VERSION',version_nr);
  1969. set_system_macro('FPC_RELEASE',release_nr);
  1970. set_system_macro('FPC_PATCH',patch_nr);
  1971. option.free;
  1972. Option:=nil;
  1973. end;
  1974. initialization
  1975. coption:=toption;
  1976. finalization
  1977. if assigned(option) then
  1978. option.free;
  1979. end.