options.pas 52 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676
  1. {
  2. $Id$
  3. Copyright (c) 1998-2000 by Florian Klaempfl and Peter Vreman
  4. Reads command line options and config files
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  16. ****************************************************************************
  17. }
  18. unit options;
  19. {$i defines.inc}
  20. interface
  21. uses
  22. globtype,globals,verbose;
  23. type
  24. TOption=class
  25. FirstPass,
  26. NoPressEnter,
  27. DoWriteLogo : boolean;
  28. FileLevel : longint;
  29. QuickInfo : string;
  30. ParaIncludePath,
  31. ParaUnitPath,
  32. ParaObjectPath,
  33. ParaLibraryPath : TSearchPathList;
  34. Constructor Create;
  35. Destructor Destroy;override;
  36. procedure WriteLogo;
  37. procedure WriteInfo;
  38. procedure WriteHelpPages;
  39. procedure WriteQuickInfo;
  40. procedure IllegalPara(const opt:string);
  41. function Unsetbool(const opts:string; pos: Longint):boolean;
  42. procedure interpret_proc_specific_options(const opt:string);virtual;
  43. procedure interpret_option(const opt :string;ispara:boolean);
  44. procedure Interpret_envvar(const envname : string);
  45. procedure Interpret_file(const filename : string);
  46. procedure Read_Parameters;
  47. procedure parsecmd(cmd:string);
  48. end;
  49. var
  50. coption : class of toption;
  51. procedure read_arguments(cmd:string);
  52. implementation
  53. uses
  54. {$ifdef Delphi}
  55. dmisc,
  56. {$else Delphi}
  57. dos,
  58. {$endif Delphi}
  59. version,systems,
  60. cutils,cobjects,messages
  61. {$ifdef BrowserLog}
  62. ,browlog
  63. {$endif BrowserLog}
  64. ;
  65. const
  66. page_size = 24;
  67. var
  68. option : toption;
  69. read_configfile, { read config file, set when a cfgfile is found }
  70. disable_configfile,
  71. target_is_set : boolean; { do not allow contradictory target settings }
  72. asm_is_set : boolean; { -T also change initoutputformat if not set idrectly }
  73. fpcdir,
  74. ppccfg,
  75. msgfilename,
  76. param_file : string; { file to compile specified on the commandline }
  77. {****************************************************************************
  78. Defines
  79. ****************************************************************************}
  80. procedure def_symbol(const s : string);
  81. begin
  82. if s='' then
  83. exit;
  84. initdefines.insert(upper(s));
  85. end;
  86. procedure undef_symbol(const s : string);
  87. begin
  88. if s='' then
  89. exit;
  90. InitDefines.Remove(s);
  91. end;
  92. function check_symbol(const s:string):boolean;
  93. begin
  94. check_symbol:=(initdefines.find(s)<>nil);
  95. end;
  96. procedure MaybeLoadMessageFile;
  97. begin
  98. { Load new message file }
  99. if (msgfilename<>'') then
  100. begin
  101. if fileexists(msgfilename) then
  102. LoadMsgFile(msgfilename);
  103. msgfilename:='';
  104. end;
  105. end;
  106. procedure set_default_link_type;
  107. begin
  108. if (target_os.id=os_i386_win32) then
  109. begin
  110. def_symbol('FPC_LINK_SMART');
  111. undef_symbol('FPC_LINK_STATIC');
  112. undef_symbol('FPC_LINK_DYNAMIC');
  113. initglobalswitches:=initglobalswitches+[cs_link_smart];
  114. initglobalswitches:=initglobalswitches-[cs_link_shared,cs_link_static];
  115. end
  116. else
  117. begin
  118. undef_symbol('FPC_LINK_SMART');
  119. def_symbol('FPC_LINK_STATIC');
  120. undef_symbol('FPC_LINK_DYNAMIC');
  121. initglobalswitches:=initglobalswitches+[cs_link_static];
  122. initglobalswitches:=initglobalswitches-[cs_link_shared,cs_link_smart];
  123. end;
  124. end;
  125. {****************************************************************************
  126. Toption
  127. ****************************************************************************}
  128. procedure StopOptions;
  129. begin
  130. if assigned(Option) then
  131. begin
  132. Option.free;
  133. Option:=nil;
  134. end;
  135. DoneVerbose;
  136. Stop;
  137. end;
  138. procedure Toption.WriteLogo;
  139. var
  140. p : pchar;
  141. begin
  142. MaybeLoadMessageFile;
  143. p:=MessagePchar(option_logo);
  144. while assigned(p) do
  145. Comment(V_Normal,GetMsgLine(p));
  146. end;
  147. procedure Toption.WriteInfo;
  148. var
  149. p : pchar;
  150. begin
  151. MaybeLoadMessageFile;
  152. p:=MessagePchar(option_info);
  153. while assigned(p) do
  154. Comment(V_Normal,GetMsgLine(p));
  155. StopOptions;
  156. end;
  157. procedure Toption.WriteHelpPages;
  158. function PadEnd(s:string;i:longint):string;
  159. begin
  160. while (length(s)<i) do
  161. s:=s+' ';
  162. PadEnd:=s;
  163. end;
  164. var
  165. lastident,
  166. j,outline,
  167. ident,
  168. lines : longint;
  169. show : boolean;
  170. opt : string[32];
  171. input,
  172. s : string;
  173. p : pchar;
  174. begin
  175. WriteLogo;
  176. Lines:=4;
  177. Message1(option_usage,system.paramstr(0));
  178. lastident:=0;
  179. p:=MessagePChar(option_help_pages);
  180. while assigned(p) do
  181. begin
  182. { get a line and reset }
  183. s:=GetMsgLine(p);
  184. ident:=0;
  185. show:=false;
  186. { parse options }
  187. case s[1] of
  188. {$ifdef UNITALIASES}
  189. 'a',
  190. {$endif}
  191. {$ifdef EXTDEBUG}
  192. 'e',
  193. {$endif EXTDEBUG}
  194. {$ifdef i386}
  195. '3',
  196. {$endif}
  197. {$ifdef m68k}
  198. '6',
  199. {$endif}
  200. '*' : show:=true;
  201. end;
  202. if show then
  203. begin
  204. case s[2] of
  205. {$ifdef GDB}
  206. 'g',
  207. {$endif}
  208. {$ifdef Unix}
  209. 'L',
  210. {$endif}
  211. {$ifdef os2}
  212. 'O',
  213. {$endif}
  214. '*' : show:=true;
  215. else
  216. show:=false;
  217. end;
  218. end;
  219. { now we may show the message or not }
  220. if show then
  221. begin
  222. case s[3] of
  223. '0' : begin
  224. ident:=0;
  225. outline:=0;
  226. end;
  227. '1' : begin
  228. ident:=2;
  229. outline:=7;
  230. end;
  231. '2' : begin
  232. ident:=6;
  233. outline:=11;
  234. end;
  235. '3' : begin
  236. ident:=9;
  237. outline:=6;
  238. end;
  239. end;
  240. j:=pos('_',s);
  241. opt:=Copy(s,4,j-4);
  242. if opt='*' then
  243. opt:=''
  244. else
  245. if opt=' ' then
  246. opt:=PadEnd(opt,outline)
  247. else
  248. opt:=PadEnd('-'+opt,outline);
  249. if (ident=0) and (lastident<>0) then
  250. begin
  251. Comment(V_Normal,'');
  252. inc(Lines);
  253. end;
  254. { page full ? }
  255. if (lines>=page_size) then
  256. begin
  257. if not NoPressEnter then
  258. begin
  259. write('*** press enter ***');
  260. readln(input);
  261. if upper(input)='Q' then
  262. StopOptions;
  263. end;
  264. lines:=0;
  265. end;
  266. Comment(V_Normal,PadEnd('',ident)+opt+Copy(s,j+1,255));
  267. LastIdent:=Ident;
  268. inc(Lines);
  269. end;
  270. end;
  271. StopOptions;
  272. end;
  273. procedure Toption.IllegalPara(const opt:string);
  274. begin
  275. Message1(option_illegal_para,opt);
  276. Message(option_help_pages_para);
  277. StopOptions;
  278. end;
  279. function Toption.Unsetbool(const opts:string; pos: Longint):boolean;
  280. { checks if the character after pos in Opts is a + or a - and returns resp.
  281. false or true. If it is another character (or none), it also returns false }
  282. begin
  283. UnsetBool := (Length(Opts) > Pos) And (Opts[Succ(Pos)] = '-');
  284. end;
  285. procedure TOption.interpret_proc_specific_options(const opt:string);
  286. begin
  287. end;
  288. procedure TOption.interpret_option(const opt:string;ispara:boolean);
  289. var
  290. code : integer;
  291. c : char;
  292. more : string;
  293. major,minor : longint;
  294. error : integer;
  295. j,l : longint;
  296. d : DirStr;
  297. e : ExtStr;
  298. begin
  299. if opt='' then
  300. exit;
  301. { only parse define,undef,target,verbosity and link options the firsttime }
  302. if firstpass and
  303. not((opt[1]='-') and (opt[2] in ['i','d','v','T','u','n','X'])) then
  304. exit;
  305. Message1(option_handling_option,opt);
  306. case opt[1] of
  307. '-' : begin
  308. more:=Copy(opt,3,255);
  309. case opt[2] of
  310. '!' : initlocalswitches:=initlocalswitches+[cs_ansistrings];
  311. '?' : WriteHelpPages;
  312. 'a' : begin
  313. initglobalswitches:=initglobalswitches+[cs_asm_leave];
  314. for j:=1 to length(more) do
  315. case more[j] of
  316. 'l' : initglobalswitches:=initglobalswitches+[cs_asm_source];
  317. 'r' : initglobalswitches:=initglobalswitches+[cs_asm_regalloc];
  318. 't' : initglobalswitches:=initglobalswitches+[cs_asm_tempalloc];
  319. '-' : initglobalswitches:=initglobalswitches-
  320. [cs_asm_leave, cs_asm_source,cs_asm_regalloc, cs_asm_tempalloc];
  321. else
  322. IllegalPara(opt);
  323. end;
  324. end;
  325. 'A' : begin
  326. if set_string_asm(More) then
  327. begin
  328. initoutputformat:=target_asm.id;
  329. asm_is_set:=true;
  330. end
  331. else
  332. IllegalPara(opt);
  333. end;
  334. 'b' : begin
  335. {$ifdef BrowserLog}
  336. initglobalswitches:=initglobalswitches+[cs_browser_log];
  337. {$endif}
  338. if More<>'' then
  339. if More='l' then
  340. initmoduleswitches:=initmoduleswitches+[cs_local_browser]
  341. else if More='-' then
  342. begin
  343. initmoduleswitches:=initmoduleswitches-[cs_browser,cs_local_browser];
  344. {$ifdef BrowserLog}
  345. initglobalswitches:=initglobalswitches-[cs_browser_log];
  346. {$endif}
  347. end
  348. else if More<>'+' then
  349. {$ifdef BrowserLog}
  350. browserlog.elements_to_list.insert(more);
  351. {$else}
  352. IllegalPara(opt);
  353. {$endif}
  354. end;
  355. 'B' : if UnSetBool(more,0) then
  356. do_build:=false
  357. else
  358. do_build:=true;
  359. 'C' : begin
  360. j := 1;
  361. while j <= length(more) Do
  362. Begin
  363. case more[j] of
  364. 'a' : If UnsetBool(More, j) then
  365. Simplify_ppu:=false
  366. else
  367. Simplify_ppu:=true;
  368. 'h' :
  369. begin
  370. val(copy(more,j+1,length(more)-j),heapsize,code);
  371. if (code<>0) or (heapsize>=67107840) or (heapsize<1024) then
  372. IllegalPara(opt);
  373. break;
  374. end;
  375. 'i' : If UnsetBool(More, j) then
  376. Begin
  377. initlocalswitches:=initlocalswitches-[cs_check_io];
  378. inc(j)
  379. End
  380. else initlocalswitches:=initlocalswitches+[cs_check_io];
  381. 'n' : If UnsetBool(More, j) then
  382. Begin
  383. initglobalswitches:=initglobalswitches-[cs_link_extern];
  384. inc(j)
  385. End
  386. Else initglobalswitches:=initglobalswitches+[cs_link_extern];
  387. 'o' :
  388. If UnsetBool(More, j) then
  389. Begin
  390. initlocalswitches:=initlocalswitches-[cs_check_overflow];
  391. inc(j);
  392. End
  393. Else
  394. initlocalswitches:=initlocalswitches+[cs_check_overflow];
  395. 'r' :
  396. If UnsetBool(More, j) then
  397. Begin
  398. initlocalswitches:=initlocalswitches-[cs_check_range];
  399. inc(j);
  400. End
  401. Else
  402. initlocalswitches:=initlocalswitches+[cs_check_range];
  403. 'R' :
  404. If UnsetBool(More, j) then
  405. Begin
  406. initlocalswitches:=initlocalswitches-[cs_check_object_ext];
  407. inc(j);
  408. End
  409. Else
  410. initlocalswitches:=initlocalswitches+[cs_check_object_ext];
  411. 's' :
  412. begin
  413. val(copy(more,j+1,length(more)-j),stacksize,code);
  414. if (code<>0) or (stacksize>=67107840) or (stacksize<1024) then
  415. IllegalPara(opt);
  416. break;
  417. end;
  418. 't' :
  419. If UnsetBool(More, j) then
  420. Begin
  421. initlocalswitches:=initlocalswitches-[cs_check_stack];
  422. inc(j)
  423. End
  424. Else
  425. initlocalswitches:=initlocalswitches+[cs_check_stack];
  426. 'D' :
  427. If UnsetBool(More, j) then
  428. Begin
  429. initmoduleswitches:=initmoduleswitches-[cs_create_dynamic];
  430. inc(j)
  431. End
  432. Else
  433. initmoduleswitches:=initmoduleswitches+[cs_create_dynamic];
  434. 'X' :
  435. If UnsetBool(More, j) then
  436. Begin
  437. initmoduleswitches:=initmoduleswitches-[cs_create_smart];
  438. inc(j)
  439. End
  440. Else
  441. initmoduleswitches:=initmoduleswitches+[cs_create_smart];
  442. else
  443. IllegalPara(opt);
  444. end;
  445. inc(j);
  446. end;
  447. end;
  448. 'd' : def_symbol(more);
  449. 'D' : begin
  450. initglobalswitches:=initglobalswitches+[cs_link_deffile];
  451. for j:=1 to length(more) do
  452. case more[j] of
  453. 'd' : begin
  454. description:=Copy(more,j+1,255);
  455. break;
  456. end;
  457. 'v' : begin
  458. dllversion:=Copy(more,j+1,255);
  459. l:=pos('.',dllversion);
  460. dllminor:=0;
  461. error:=0;
  462. if l>0 then
  463. begin
  464. valint(copy(dllversion,l+1,255),minor,error);
  465. if (error=0) and
  466. (minor>=0) and (minor<=$ffff) then
  467. dllminor:=minor
  468. else if error=0 then
  469. error:=1;
  470. end;
  471. if l=0 then l:=256;
  472. dllmajor:=1;
  473. if error=0 then
  474. valint(copy(dllversion,1,l-1),major,error);
  475. if (error=0) and (major>=0) and (major<=$ffff) then
  476. dllmajor:=major
  477. else if error=0 then
  478. error:=1;
  479. if error<>0 then
  480. Message1(scan_w_wrong_version_ignored,dllversion);
  481. break;
  482. end;
  483. 'w' : usewindowapi:=true;
  484. '-' : begin
  485. initglobalswitches:=initglobalswitches-
  486. [cs_link_deffile];
  487. usewindowapi:=false;
  488. end;
  489. else
  490. IllegalPara(opt);
  491. end;
  492. end;
  493. 'e' : exepath:=FixPath(More,true);
  494. { Just used by RHIDE }
  495. 'E' : if (length(more)=0) or (UnsetBool(More, 0)) then
  496. initglobalswitches:=initglobalswitches+[cs_link_extern]
  497. else
  498. initglobalswitches:=initglobalswitches-[cs_link_extern];
  499. 'F' : begin
  500. c:=more[1];
  501. Delete(more,1,1);
  502. DefaultReplacements(More);
  503. case c of
  504. 'D' : utilsdirectory:=FixPath(More,true);
  505. 'e' : SetRedirectFile(More);
  506. 'E' : OutputExeDir:=FixPath(More,true);
  507. 'i' : if ispara then
  508. ParaIncludePath.AddPath(More,false)
  509. else
  510. includesearchpath.AddPath(More,true);
  511. 'g' : Message2(option_obsolete_switch_use_new,'-Fg','-Fl');
  512. 'l' : if ispara then
  513. ParaLibraryPath.AddPath(More,false)
  514. else
  515. LibrarySearchPath.AddPath(More,true);
  516. 'L' : if More<>'' then
  517. ParaDynamicLinker:=More
  518. else
  519. IllegalPara(opt);
  520. 'o' : if ispara then
  521. ParaObjectPath.AddPath(More,false)
  522. else
  523. ObjectSearchPath.AddPath(More,true);
  524. 'r' : Msgfilename:=More;
  525. 'u' : if ispara then
  526. ParaUnitPath.AddPath(More,false)
  527. else
  528. unitsearchpath.AddPath(More,true);
  529. 'U' : OutputUnitDir:=FixPath(More,true);
  530. else
  531. IllegalPara(opt);
  532. end;
  533. end;
  534. 'g' : begin
  535. if UnsetBool(More, 0) then
  536. begin
  537. initmoduleswitches:=initmoduleswitches-[cs_debuginfo];
  538. if (length(More)>1) and (More[2]='l') then
  539. initglobalswitches:=initglobalswitches+[cs_gdb_lineinfo];
  540. end
  541. else
  542. begin
  543. {$ifdef GDB}
  544. initmoduleswitches:=initmoduleswitches+[cs_debuginfo];
  545. if not RelocSectionSetExplicitly then
  546. RelocSection:=false;
  547. for j:=1 to length(more) do
  548. case more[j] of
  549. 'd' : initglobalswitches:=initglobalswitches+[cs_gdb_dbx];
  550. 'g' : initglobalswitches:=initglobalswitches+[cs_gdb_gsym];
  551. 'h' : initglobalswitches:=initglobalswitches+[cs_gdb_heaptrc];
  552. 'l' : initglobalswitches:=initglobalswitches+[cs_gdb_lineinfo];
  553. 'c' : initglobalswitches:=initglobalswitches+[cs_checkpointer];
  554. {$ifdef EXTDEBUG}
  555. 'p' : only_one_pass:=true;
  556. {$endif EXTDEBUG}
  557. else
  558. IllegalPara(opt);
  559. end;
  560. {$else GDB}
  561. Message(option_no_debug_support);
  562. Message(option_no_debug_support_recompile_fpc);
  563. {$endif GDB}
  564. end;
  565. end;
  566. 'h' : begin
  567. NoPressEnter:=true;
  568. WriteHelpPages;
  569. end;
  570. 'i' : if More='' then
  571. WriteInfo
  572. else
  573. QuickInfo:=QuickInfo+More;
  574. 'I' : if ispara then
  575. ParaIncludePath.AddPath(More,false)
  576. else
  577. includesearchpath.AddPath(More,false);
  578. 'k' : if more<>'' then
  579. ParaLinkOptions:=ParaLinkOptions+' '+More
  580. else
  581. IllegalPara(opt);
  582. 'l' : if UnSetBool(more,0) then
  583. DoWriteLogo:=false
  584. else
  585. DoWriteLogo:=true;
  586. 'm' : if UnSetBool(more,0) then
  587. parapreprocess:=false
  588. else
  589. parapreprocess:=true;
  590. 'n' : if More='' then
  591. begin
  592. read_configfile:=false;
  593. disable_configfile:=true;
  594. end
  595. else
  596. IllegalPara(opt);
  597. 'o' : if More<>'' then
  598. Fsplit(More,d,OutputFile,e)
  599. else
  600. IllegalPara(opt);
  601. 'p' : begin
  602. if UnsetBool(More, 0) then
  603. begin
  604. initmoduleswitches:=initmoduleswitches-[cs_profile];
  605. undef_symbol('FPC_PROFILE');
  606. end
  607. else
  608. case more[1] of
  609. 'g' : if (length(opt)=3) and UnsetBool(more, 1) then
  610. begin
  611. initmoduleswitches:=initmoduleswitches-[cs_profile];
  612. undef_symbol('FPC_PROFILE');
  613. end
  614. else
  615. begin
  616. initmoduleswitches:=initmoduleswitches+[cs_profile];
  617. def_symbol('FPC_PROFILE');
  618. end;
  619. else
  620. IllegalPara(opt);
  621. end;
  622. end;
  623. {$ifdef Unix}
  624. 'P' : if UnsetBool(More, 0) then
  625. initglobalswitches:=initglobalswitches-[cs_asm_pipe]
  626. else
  627. initglobalswitches:=initglobalswitches+[cs_asm_pipe];
  628. {$endif Unix}
  629. 's' : if UnsetBool(More, 0) then
  630. initglobalswitches:=initglobalswitches-[cs_asm_extern,cs_link_extern]
  631. else
  632. initglobalswitches:=initglobalswitches+[cs_asm_extern,cs_link_extern];
  633. 'S' : begin
  634. if more[1]='I' then
  635. begin
  636. if upper(more)='ICOM' then
  637. initinterfacetype:=it_interfacecom
  638. else if upper(more)='ICORBA' then
  639. initinterfacetype:=it_interfacecorba
  640. else
  641. IllegalPara(opt);
  642. end
  643. else
  644. for j:=1 to length(more) do
  645. case more[j] of
  646. '2' : SetCompileMode('OBJFPC',true);
  647. 'a' : initlocalswitches:=InitLocalswitches+[cs_do_assertion];
  648. 'c' : initmoduleswitches:=initmoduleswitches+[cs_support_c_operators];
  649. 'd' : SetCompileMode('DELPHI',true);
  650. 'e' : begin
  651. SetErrorFlags(more);
  652. break;
  653. end;
  654. 'g' : initmoduleswitches:=initmoduleswitches+[cs_support_goto];
  655. 'h' : initlocalswitches:=initlocalswitches+[cs_ansistrings];
  656. 'i' : initmoduleswitches:=initmoduleswitches+[cs_support_inline];
  657. 'm' : initmoduleswitches:=initmoduleswitches+[cs_support_macro];
  658. 'o' : SetCompileMode('TP',true);
  659. 'p' : SetCompileMode('GPC',true);
  660. 's' : initglobalswitches:=initglobalswitches+[cs_constructor_name];
  661. 't' : initmoduleswitches:=initmoduleswitches+[cs_static_keyword];
  662. '-' : begin
  663. initglobalswitches:=initglobalswitches -
  664. [cs_constructor_name];
  665. initlocalswitches:=InitLocalswitches -
  666. [cs_do_assertion, cs_ansistrings];
  667. initmoduleswitches:=initmoduleswitches -
  668. [cs_support_c_operators, cs_support_goto,
  669. cs_support_inline, cs_support_macro,
  670. cs_static_keyword];
  671. end;
  672. else
  673. IllegalPara(opt);
  674. end;
  675. end;
  676. 'T' : begin
  677. more:=Upper(More);
  678. if not target_is_set then
  679. begin
  680. {Remove non core targetname extra defines}
  681. case target_info.target of
  682. target_i386_freebsd :
  683. begin
  684. undef_symbol('LINUX');
  685. undef_symbol('BSD');
  686. undef_symbol('UNIX');
  687. end;
  688. target_i386_linux :
  689. begin
  690. undef_symbol('UNIX');
  691. end;
  692. end;
  693. { remove old target define }
  694. undef_symbol(target_info.short_name);
  695. { load new target }
  696. if not(set_string_target(More)) then
  697. IllegalPara(opt);
  698. { set new define }
  699. def_symbol(target_info.short_name);
  700. if not asm_is_set then
  701. initoutputformat:=target_asm.id;
  702. target_is_set:=true;
  703. end
  704. else
  705. if More<>target_info.short_name then
  706. Message1(option_target_is_already_set,target_info.short_name);
  707. end;
  708. 'u' : undef_symbol(upper(More));
  709. 'U' : begin
  710. for j:=1 to length(more) do
  711. case more[j] of
  712. {$ifdef UNITALIASES}
  713. 'a' : begin
  714. AddUnitAlias(Copy(More,j+1,255));
  715. break;
  716. end;
  717. {$endif UNITALIASES}
  718. 'n' : initglobalswitches:=initglobalswitches-[cs_check_unit_name];
  719. 'p' : begin
  720. Message2(option_obsolete_switch_use_new,'-Up','-Fu');
  721. break;
  722. end;
  723. 's' : initmoduleswitches:=initmoduleswitches+[cs_compilesystem];
  724. '-' : begin
  725. initmoduleswitches:=initmoduleswitches
  726. - [cs_compilesystem]
  727. + [cs_check_unit_name];
  728. end;
  729. else
  730. IllegalPara(opt);
  731. end;
  732. end;
  733. 'v' : if not setverbosity(More) then
  734. IllegalPara(opt);
  735. 'W' : begin
  736. for j:=1 to length(More) do
  737. case More[j] of
  738. 'B': {bind_win32_dll:=true}
  739. begin
  740. { -WB200000 means set prefered base address
  741. to $200000, but does not change relocsection boolean
  742. this way we can create both relocatble and
  743. non relocatable DLL at a specific base address PM }
  744. if (length(More)>j) then
  745. begin
  746. if DLLImageBase=nil then
  747. DLLImageBase:=StringDup(Copy(More,j+1,255));
  748. end
  749. else
  750. begin
  751. RelocSection:=true;
  752. RelocSectionSetExplicitly:=true;
  753. end;
  754. break;
  755. end;
  756. 'C': apptype:=app_cui;
  757. 'D': if UnsetBool(More, j) then
  758. ForceDeffileForExport:=false
  759. else
  760. ForceDeffileForExport:=true;
  761. 'F': apptype:=app_fs;
  762. 'G': apptype:=app_gui;
  763. 'N': begin
  764. RelocSection:=false;
  765. RelocSectionSetExplicitly:=true;
  766. end;
  767. 'R': begin
  768. RelocSection:=true;
  769. RelocSectionSetExplicitly:=true;
  770. end;
  771. else
  772. IllegalPara(opt);
  773. end;
  774. end;
  775. 'X' : begin
  776. for j:=1 to length(More) do
  777. case More[j] of
  778. 'c' : initglobalswitches:=initglobalswitches+[cs_link_toc];
  779. 's' : initglobalswitches:=initglobalswitches+[cs_link_strip];
  780. 't' : initglobalswitches:=initglobalswitches+[cs_link_staticflag];
  781. 'D' : begin
  782. def_symbol('FPC_LINK_DYNAMIC');
  783. undef_symbol('FPC_LINK_SMART');
  784. undef_symbol('FPC_LINK_STATIC');
  785. initglobalswitches:=initglobalswitches+[cs_link_shared];
  786. initglobalswitches:=initglobalswitches-[cs_link_static,cs_link_smart];
  787. LinkTypeSetExplicitly:=true;
  788. end;
  789. 'S' : begin
  790. def_symbol('FPC_LINK_STATIC');
  791. undef_symbol('FPC_LINK_SMART');
  792. undef_symbol('FPC_LINK_DYNAMIC');
  793. initglobalswitches:=initglobalswitches+[cs_link_static];
  794. initglobalswitches:=initglobalswitches-[cs_link_shared,cs_link_smart];
  795. LinkTypeSetExplicitly:=true;
  796. end;
  797. 'X' : begin
  798. def_symbol('FPC_LINK_SMART');
  799. undef_symbol('FPC_LINK_STATIC');
  800. undef_symbol('FPC_LINK_DYNAMIC');
  801. initglobalswitches:=initglobalswitches+[cs_link_smart];
  802. initglobalswitches:=initglobalswitches-[cs_link_shared,cs_link_static];
  803. LinkTypeSetExplicitly:=true;
  804. end;
  805. '-' : begin
  806. initglobalswitches:=initglobalswitches-[cs_link_toc, cs_link_strip, cs_link_staticflag];
  807. set_default_link_type;
  808. end;
  809. else
  810. IllegalPara(opt);
  811. end;
  812. end;
  813. { give processor specific options a chance }
  814. else
  815. interpret_proc_specific_options(opt);
  816. end;
  817. end;
  818. '@' : begin
  819. Message(option_no_nested_response_file);
  820. StopOptions;
  821. end;
  822. else
  823. begin
  824. if (length(param_file)<>0) then
  825. Message(option_only_one_source_support);
  826. param_file:=opt;
  827. end;
  828. end;
  829. end;
  830. procedure Toption.Interpret_file(const filename : string);
  831. procedure RemoveSep(var fn:string);
  832. var
  833. i : longint;
  834. begin
  835. i:=0;
  836. while (i<length(fn)) and (fn[i+1] in [',',' ',#9]) do
  837. inc(i);
  838. Delete(fn,1,i);
  839. i:=length(fn);
  840. while (i>0) and (fn[i] in [',',' ',#9]) do
  841. dec(i);
  842. fn:=copy(fn,1,i);
  843. end;
  844. function GetName(var fn:string):string;
  845. var
  846. i : longint;
  847. begin
  848. i:=0;
  849. while (i<length(fn)) and (fn[i+1] in ['a'..'z','A'..'Z','0'..'9','_','-']) do
  850. inc(i);
  851. GetName:=Copy(fn,1,i);
  852. Delete(fn,1,i);
  853. end;
  854. const
  855. maxlevel=16;
  856. var
  857. f : text;
  858. s,
  859. opts : string;
  860. skip : array[0..maxlevel-1] of boolean;
  861. level : longint;
  862. option_read : boolean;
  863. begin
  864. { avoid infinite loop }
  865. Inc(FileLevel);
  866. Option_read:=false;
  867. If FileLevel>MaxLevel then
  868. Message(option_too_many_cfg_files);
  869. { open file }
  870. Message1(option_using_file,filename);
  871. assign(f,filename);
  872. {$I-}
  873. reset(f);
  874. {$I+}
  875. if ioresult<>0 then
  876. begin
  877. Message1(option_unable_open_file,filename);
  878. exit;
  879. end;
  880. fillchar(skip,sizeof(skip),0);
  881. level:=0;
  882. while not eof(f) do
  883. begin
  884. readln(f,opts);
  885. RemoveSep(opts);
  886. if (opts<>'') and (opts[1]<>';') then
  887. begin
  888. if opts[1]='#' then
  889. begin
  890. Delete(opts,1,1);
  891. s:=upper(GetName(opts));
  892. if (s='SECTION') then
  893. begin
  894. RemoveSep(opts);
  895. s:=upper(GetName(opts));
  896. if level=0 then
  897. skip[level]:=not (check_symbol(s) or (s='COMMON'));
  898. end
  899. else
  900. if (s='IFDEF') then
  901. begin
  902. RemoveSep(opts);
  903. if Level>=maxlevel then
  904. begin
  905. Message(option_too_many_ifdef);
  906. stopOptions;
  907. end;
  908. inc(Level);
  909. skip[level]:=(skip[level-1] or (not check_symbol(upper(GetName(opts)))));
  910. end
  911. else
  912. if (s='IFNDEF') then
  913. begin
  914. RemoveSep(opts);
  915. if Level>=maxlevel then
  916. begin
  917. Message(option_too_many_ifdef);
  918. stopOptions;
  919. end;
  920. inc(Level);
  921. skip[level]:=(skip[level-1] or (check_symbol(upper(GetName(opts)))));
  922. end
  923. else
  924. if (s='ELSE') then
  925. skip[level]:=skip[level-1] or (not skip[level])
  926. else
  927. if (s='ENDIF') then
  928. begin
  929. skip[level]:=false;
  930. if Level=0 then
  931. begin
  932. Message(option_too_many_endif);
  933. stopOptions;
  934. end;
  935. dec(level);
  936. end
  937. else
  938. if (not skip[level]) then
  939. begin
  940. if (s='DEFINE') then
  941. begin
  942. RemoveSep(opts);
  943. def_symbol(upper(GetName(opts)));
  944. end
  945. else
  946. if (s='UNDEF') then
  947. begin
  948. RemoveSep(opts);
  949. undef_symbol(upper(GetName(opts)));
  950. end
  951. else
  952. if (s='WRITE') then
  953. begin
  954. Delete(opts,1,1);
  955. WriteLn(opts);
  956. end
  957. else
  958. if (s='INCLUDE') then
  959. begin
  960. Delete(opts,1,1);
  961. Interpret_file(opts);
  962. end;
  963. end;
  964. end
  965. else
  966. begin
  967. if (opts[1]='-') then
  968. begin
  969. if (not skip[level]) then
  970. interpret_option(opts,false);
  971. Option_read:=true;
  972. end
  973. else
  974. Message1(option_illegal_para,opts);
  975. end;
  976. end;
  977. end;
  978. if Level>0 then
  979. Message(option_too_less_endif);
  980. if Not Option_read then
  981. Message1(option_no_option_found,filename);
  982. Close(f);
  983. Dec(FileLevel);
  984. end;
  985. procedure Toption.Interpret_envvar(const envname : string);
  986. var
  987. argstart,
  988. env,
  989. pc : pchar;
  990. arglen : longint;
  991. quote : set of char;
  992. hs : string;
  993. begin
  994. Message1(option_using_env,envname);
  995. env:=GetEnvPChar(envname);
  996. pc:=env;
  997. if assigned(pc) then
  998. begin
  999. repeat
  1000. { skip leading spaces }
  1001. while pc^ in [' ',#9,#13] do
  1002. inc(pc);
  1003. case pc^ of
  1004. #0 :
  1005. break;
  1006. '"' :
  1007. begin
  1008. quote:=['"'];
  1009. inc(pc);
  1010. end;
  1011. '''' :
  1012. begin
  1013. quote:=[''''];
  1014. inc(pc);
  1015. end;
  1016. else
  1017. quote:=[' ',#9,#13];
  1018. end;
  1019. { scan until the end of the argument }
  1020. argstart:=pc;
  1021. while (pc^<>#0) and not(pc^ in quote) do
  1022. inc(pc);
  1023. { create argument }
  1024. arglen:=pc-argstart;
  1025. hs[0]:=chr(arglen);
  1026. move(argstart^,hs[1],arglen);
  1027. interpret_option(hs,true);
  1028. { skip quote }
  1029. if pc^ in quote then
  1030. inc(pc);
  1031. until false;
  1032. end
  1033. else
  1034. Message1(option_no_option_found,'(env) '+envname);
  1035. FreeEnvPChar(env);
  1036. end;
  1037. procedure toption.read_parameters;
  1038. var
  1039. opts : string;
  1040. paramindex : longint;
  1041. begin
  1042. paramindex:=0;
  1043. while paramindex<paramcount do
  1044. begin
  1045. inc(paramindex);
  1046. opts:=system.paramstr(paramindex);
  1047. case opts[1] of
  1048. '@' :
  1049. begin
  1050. Delete(opts,1,1);
  1051. if not firstpass then
  1052. Message1(option_reading_further_from,opts);
  1053. interpret_file(opts);
  1054. end;
  1055. '!' :
  1056. begin
  1057. Delete(opts,1,1);
  1058. if not firstpass then
  1059. Message1(option_reading_further_from,'(env) '+opts);
  1060. interpret_envvar(opts);
  1061. end;
  1062. else
  1063. interpret_option(opts,true);
  1064. end;
  1065. end;
  1066. end;
  1067. procedure toption.parsecmd(cmd:string);
  1068. var
  1069. i,ps : longint;
  1070. opts : string;
  1071. begin
  1072. while (cmd<>'') do
  1073. begin
  1074. while cmd[1]=' ' do
  1075. delete(cmd,1,1);
  1076. i:=pos(' ',cmd);
  1077. if i=0 then
  1078. i:=256;
  1079. opts:=Copy(cmd,1,i-1);
  1080. Delete(cmd,1,i);
  1081. case opts[1] of
  1082. '@' :
  1083. begin
  1084. Delete(opts,1,1);
  1085. if not firstpass then
  1086. Message1(option_reading_further_from,opts);
  1087. interpret_file(opts);
  1088. end;
  1089. '!' :
  1090. begin
  1091. Delete(opts,1,1);
  1092. if not firstpass then
  1093. Message1(option_reading_further_from,'(env) '+opts);
  1094. interpret_envvar(opts);
  1095. end;
  1096. '"' :
  1097. begin
  1098. Delete(opts,1,1);
  1099. ps:=pos('"',cmd);
  1100. if (i<>256) and (ps>0) then
  1101. begin
  1102. opts:=opts + ' '+ copy(cmd,1,ps-1);
  1103. cmd:=copy(cmd,ps+1,255);
  1104. end;
  1105. interpret_option(opts,true);
  1106. end;
  1107. else
  1108. interpret_option(opts,true);
  1109. end;
  1110. end;
  1111. end;
  1112. procedure toption.writequickinfo;
  1113. var
  1114. s : string;
  1115. i : longint;
  1116. procedure addinfo(const hs:string);
  1117. begin
  1118. if s<>'' then
  1119. s:=s+' '+hs
  1120. else
  1121. s:=hs;
  1122. end;
  1123. begin
  1124. s:='';
  1125. i:=0;
  1126. while (i<length(quickinfo)) do
  1127. begin
  1128. inc(i);
  1129. case quickinfo[i] of
  1130. 'S' :
  1131. begin
  1132. inc(i);
  1133. case quickinfo[i] of
  1134. 'O' :
  1135. addinfo(source_os.shortname);
  1136. {$ifdef Delphi}
  1137. 'P' :
  1138. addinfo('i386');
  1139. {$else Delphi}
  1140. 'P' :
  1141. addinfo(source_cpu_string);
  1142. {$endif Delphi}
  1143. else
  1144. IllegalPara('-iS'+QuickInfo);
  1145. end;
  1146. end;
  1147. 'T' :
  1148. begin
  1149. inc(i);
  1150. case quickinfo[i] of
  1151. 'O' :
  1152. addinfo(target_os.shortname);
  1153. 'P' :
  1154. AddInfo(target_cpu_string);
  1155. else
  1156. IllegalPara('-iT'+QuickInfo);
  1157. end;
  1158. end;
  1159. 'V' :
  1160. AddInfo(version_string);
  1161. 'D' :
  1162. AddInfo(date_string);
  1163. '_' :
  1164. ;
  1165. else
  1166. IllegalPara('-i'+QuickInfo);
  1167. end;
  1168. end;
  1169. if s<>'' then
  1170. begin
  1171. writeln(s);
  1172. stopoptions;
  1173. end;
  1174. end;
  1175. constructor TOption.create;
  1176. begin
  1177. DoWriteLogo:=false;
  1178. NoPressEnter:=false;
  1179. FirstPass:=false;
  1180. FileLevel:=0;
  1181. Quickinfo:='';
  1182. ParaIncludePath:=TSearchPathList.Create;
  1183. ParaObjectPath:=TSearchPathList.Create;
  1184. ParaUnitPath:=TSearchPathList.Create;
  1185. ParaLibraryPath:=TSearchPathList.Create;
  1186. end;
  1187. destructor TOption.destroy;
  1188. begin
  1189. ParaIncludePath.Free;
  1190. ParaObjectPath.Free;
  1191. ParaUnitPath.Free;
  1192. ParaLibraryPath.Free;
  1193. end;
  1194. {****************************************************************************
  1195. Callable Routines
  1196. ****************************************************************************}
  1197. procedure read_arguments(cmd:string);
  1198. var
  1199. configpath : pathstr;
  1200. begin
  1201. option:=coption.create;
  1202. disable_configfile:=false;
  1203. { default defines }
  1204. def_symbol(target_info.short_name);
  1205. def_symbol('FPC');
  1206. def_symbol('VER'+version_nr);
  1207. def_symbol('VER'+version_nr+'_'+release_nr);
  1208. def_symbol('VER'+version_nr+'_'+release_nr+'_'+patch_nr);
  1209. {$ifdef newcg}
  1210. def_symbol('WITHNEWCG');
  1211. {$endif}
  1212. { Temporary defines, until things settle down }
  1213. {$ifdef SUPPORT_FIXED}
  1214. def_symbol('HASFIXED');
  1215. {$endif SUPPORT_FIXED}
  1216. def_symbol('HASWIDECHAR');
  1217. def_symbol('HASOUT');
  1218. def_symbol('HASINTF');
  1219. def_symbol('INTERNSETLENGTH');
  1220. def_symbol('INT64FUNCRESOK');
  1221. def_symbol('PACKENUMFIXED');
  1222. def_symbol('HAS_ADDR_STACK_ON_STACK');
  1223. { some stuff for TP compatibility }
  1224. {$ifdef i386}
  1225. def_symbol('CPU86');
  1226. def_symbol('CPU87');
  1227. {$endif}
  1228. {$ifdef m68k}
  1229. def_symbol('CPU68');
  1230. {$endif}
  1231. { new processor stuff }
  1232. {$ifdef i386}
  1233. def_symbol('CPUI386');
  1234. {$endif}
  1235. {$ifdef m68k}
  1236. def_symbol('CPU68K');
  1237. {$endif}
  1238. {$ifdef ALPHA}
  1239. def_symbol('CPUALPHA');
  1240. {$endif}
  1241. {$ifdef powerpc}
  1242. def_symbol('CPUPOWERPC');
  1243. {$endif}
  1244. { get default messagefile }
  1245. {$ifdef Delphi}
  1246. msgfilename:=dmisc.getenv('PPC_ERROR_FILE');
  1247. {$else Delphi}
  1248. msgfilename:=dos.getenv('PPC_ERROR_FILE');
  1249. {$endif Delphi}
  1250. { default configfile }
  1251. if (cmd<>'') and (cmd[1]='[') then
  1252. begin
  1253. ppccfg:=Copy(cmd,2,pos(']',cmd)-2);
  1254. Delete(cmd,1,pos(']',cmd));
  1255. end
  1256. else
  1257. begin
  1258. {$ifdef i386}
  1259. ppccfg:='ppc386.cfg';
  1260. {$endif i386}
  1261. {$ifdef ia64}
  1262. ppccfg:='ppcia64.cfg';
  1263. {$endif ia64}
  1264. {$ifdef m68k}
  1265. ppccfg:='ppc68k.cfg';
  1266. {$endif}
  1267. {$ifdef alpha}
  1268. ppccfg:='ppcalpha.cfg';
  1269. {$endif}
  1270. {$ifdef powerpc}
  1271. ppccfg:='ppcppc.cfg';
  1272. {$endif}
  1273. end;
  1274. { Order to read ppc386.cfg:
  1275. 1 - current dir
  1276. 2 - configpath
  1277. 3 - compiler path }
  1278. {$ifdef Delphi}
  1279. configpath:=FixPath(dmisc.getenv('PPC_CONFIG_PATH'),false);
  1280. {$else Delphi}
  1281. configpath:=FixPath(dos.getenv('PPC_CONFIG_PATH'),false);
  1282. {$endif Delphi}
  1283. {$ifdef Unix}
  1284. if configpath='' then
  1285. configpath:='/etc/';
  1286. {$endif}
  1287. if ppccfg<>'' then
  1288. begin
  1289. read_configfile:=true;
  1290. if not FileExists(ppccfg) then
  1291. begin
  1292. {$ifdef Unix}
  1293. if (dos.getenv('HOME')<>'') and FileExists(FixPath(dos.getenv('HOME'),false)+'.'+ppccfg) then
  1294. ppccfg:=FixPath(dos.getenv('HOME'),false)+'.'+ppccfg
  1295. else
  1296. {$endif}
  1297. if FileExists(configpath+ppccfg) then
  1298. ppccfg:=configpath+ppccfg
  1299. else
  1300. {$ifndef Unix}
  1301. if FileExists(exepath+ppccfg) then
  1302. ppccfg:=exepath+ppccfg
  1303. else
  1304. {$endif}
  1305. read_configfile:=false;
  1306. end;
  1307. end
  1308. else
  1309. read_configfile:=false;
  1310. { Read commandline and configfile }
  1311. target_is_set:=false;
  1312. asm_is_set:=false;
  1313. param_file:='';
  1314. if read_configfile then
  1315. begin
  1316. { read the parameters quick, only -i -v -T }
  1317. option.firstpass:=true;
  1318. if cmd<>'' then
  1319. option.parsecmd(cmd)
  1320. else
  1321. begin
  1322. option.read_parameters;
  1323. { Write only quickinfo }
  1324. if option.quickinfo<>'' then
  1325. option.writequickinfo;
  1326. end;
  1327. { Read the configfile }
  1328. option.firstpass:=false;
  1329. if read_configfile then
  1330. option.interpret_file(ppccfg);
  1331. end;
  1332. if cmd<>'' then
  1333. option.parsecmd(cmd)
  1334. else
  1335. begin
  1336. option.read_parameters;
  1337. { Write only quickinfo }
  1338. if option.quickinfo<>'' then
  1339. option.writequickinfo;
  1340. end;
  1341. { Write help pages }
  1342. if (cmd='') and (paramcount=0) then
  1343. Option.WriteHelpPages;
  1344. { Stop if errors in options }
  1345. if ErrorCount>0 then
  1346. StopOptions;
  1347. { Non-core target defines }
  1348. case target_info.target of
  1349. target_i386_freebsd :
  1350. begin
  1351. def_symbol('LINUX'); { Hack: Linux define is also needed for freebsd (MvdV) }
  1352. def_symbol('BSD');
  1353. def_symbol('UNIX');
  1354. end;
  1355. target_i386_linux :
  1356. begin
  1357. def_symbol('UNIX');
  1358. end;
  1359. end;
  1360. { write logo if set }
  1361. if option.DoWriteLogo then
  1362. option.WriteLogo;
  1363. { Check file to compile }
  1364. if param_file='' then
  1365. begin
  1366. Message(option_no_source_found);
  1367. StopOptions;
  1368. end;
  1369. {$ifndef Unix}
  1370. param_file:=FixFileName(param_file);
  1371. {$endif}
  1372. fsplit(param_file,inputdir,inputfile,inputextension);
  1373. if inputextension='' then
  1374. begin
  1375. if FileExists(inputdir+inputfile+target_os.sourceext) then
  1376. inputextension:=target_os.sourceext
  1377. else
  1378. if FileExists(inputdir+inputfile+target_os.pasext) then
  1379. inputextension:=target_os.pasext;
  1380. end;
  1381. { Add paths specified with parameters to the searchpaths }
  1382. UnitSearchPath.AddList(option.ParaUnitPath,true);
  1383. ObjectSearchPath.AddList(option.ParaObjectPath,true);
  1384. IncludeSearchPath.AddList(option.ParaIncludePath,true);
  1385. LibrarySearchPath.AddList(option.ParaLibraryPath,true);
  1386. { add unit environment and exepath to the unit search path }
  1387. if inputdir<>'' then
  1388. Unitsearchpath.AddPath(inputdir,true);
  1389. if not disable_configfile then
  1390. {$ifdef Delphi}
  1391. UnitSearchPath.AddPath(dmisc.getenv(target_info.unit_env),false);
  1392. {$else}
  1393. UnitSearchPath.AddPath(dos.getenv(target_info.unit_env),false);
  1394. {$endif Delphi}
  1395. {$ifdef Unix}
  1396. fpcdir:=FixPath(getenv('FPCDIR'),false);
  1397. if fpcdir='' then
  1398. begin
  1399. if PathExists('/usr/local/lib/fpc/'+version_string) then
  1400. fpcdir:='/usr/local/lib/fpc/'+version_string+'/'
  1401. else
  1402. fpcdir:='/usr/lib/fpc/'+version_string+'/';
  1403. end;
  1404. {$else}
  1405. fpcdir:=FixPath(getenv('FPCDIR'),false);
  1406. if fpcdir='' then
  1407. begin
  1408. fpcdir:=ExePath+'../';
  1409. if not(PathExists(fpcdir+'/units')) and
  1410. not(PathExists(fpcdir+'/rtl')) then
  1411. fpcdir:=fpcdir+'../';
  1412. end;
  1413. {$endif}
  1414. { first try development RTL, else use the default installation path }
  1415. if not disable_configfile then
  1416. begin
  1417. if PathExists(FpcDir+'rtl/'+lower(target_info.short_name)) then
  1418. UnitSearchPath.AddPath(FpcDir+'rtl/'+lower(target_info.short_name),false)
  1419. else
  1420. begin
  1421. UnitSearchPath.AddPath(FpcDir+'units/'+lower(target_info.short_name),false);
  1422. UnitSearchPath.AddPath(FpcDir+'units/'+lower(target_info.short_name)+'/rtl',false);
  1423. end;
  1424. end;
  1425. { Add exepath if the exe is not in the current dir, because that is always searched already }
  1426. if ExePath<>GetCurrentDir then
  1427. UnitSearchPath.AddPath(ExePath,false);
  1428. { Add unit dir to the object and library path }
  1429. objectsearchpath.AddList(unitsearchpath,false);
  1430. librarysearchpath.AddList(unitsearchpath,false);
  1431. { switch assembler if it's binary and we got -a on the cmdline }
  1432. if (cs_asm_leave in initglobalswitches) and
  1433. (target_asm.id in binassem) then
  1434. begin
  1435. Message(option_switch_bin_to_src_assembler);
  1436. set_target_asm(target_info.assemsrc);
  1437. initoutputformat:=target_asm.id;
  1438. end;
  1439. if (target_asm.supported_target <> target_any) and
  1440. (target_asm.supported_target <> target_info.target) then
  1441. begin
  1442. Message2(option_incompatible_asm,target_asm.idtxt,target_os.name);
  1443. { Should we reset to default ??? }
  1444. set_target_asm(target_info.assemsrc);
  1445. Message1(option_asm_forced,target_asm.idtxt);
  1446. initoutputformat:=target_asm.id;
  1447. end;
  1448. { turn off stripping if compiling with debuginfo or profile }
  1449. if (cs_debuginfo in initmoduleswitches) or
  1450. (cs_profile in initmoduleswitches) then
  1451. initglobalswitches:=initglobalswitches-[cs_link_strip];
  1452. if not LinkTypeSetExplicitly then
  1453. set_default_link_type;
  1454. { Set defines depending on the target }
  1455. if (target_info.target in [target_i386_GO32V1,target_i386_GO32V2]) then
  1456. def_symbol('DPMI'); { MSDOS is not defined in BP when target is DPMI }
  1457. MaybeLoadMessageFile;
  1458. option.free;
  1459. Option:=nil;
  1460. end;
  1461. initialization
  1462. coption:=toption;
  1463. finalization
  1464. if assigned(option) then
  1465. option.free;
  1466. end.
  1467. {
  1468. $Log$
  1469. Revision 1.30 2001-02-26 08:08:39 michael
  1470. * option_help_pages:
  1471. allow to omit an option (use one space char insteed an option)
  1472. but to indent a continuation line as if option is present. For lines:
  1473. 3*2CX_first line
  1474. 3*2 _second line
  1475. 3*2*_third line
  1476. we could get:
  1477. -CX first line
  1478. second line
  1479. third line
  1480. Revision 1.29 2001/02/26 07:49:50 michael
  1481. Support replacements for all -F<x> options
  1482. Revision 1.28 2001/02/05 21:26:36 peter
  1483. * applied patches from Sergey Korshunoff
  1484. Revision 1.27 2001/01/20 18:36:51 hajny
  1485. + APPTYPE support under OS/2, app_fs, GetEnvPChar for OS/2
  1486. Revision 1.26 2001/01/12 19:21:09 peter
  1487. * fixed writing of quickinfo when no ppc386.cfg is available
  1488. Revision 1.25 2001/01/05 17:36:57 florian
  1489. * the info about exception frames is stored now on the stack
  1490. instead on the heap
  1491. Revision 1.24 2000/12/25 00:07:26 peter
  1492. + new tlinkedlist class (merge of old tstringqueue,tcontainer and
  1493. tlinkedlist objects)
  1494. Revision 1.23 2000/12/24 12:21:41 peter
  1495. * use system.paramstr()
  1496. Revision 1.22 2000/12/23 19:46:49 peter
  1497. * object to class conversion
  1498. * more verbosity for -vt and -vd
  1499. * -i options can be put after eachother so the Makefiles only need
  1500. to call fpc once for all info (will be twice as the first one will
  1501. be to check the version if fpc supports multiple info)
  1502. Revision 1.21 2000/12/16 15:56:19 jonas
  1503. - removed all ifdef cardinalmulfix code
  1504. Revision 1.20 2000/12/15 13:26:01 jonas
  1505. * only return int64's from functions if it int64funcresok is defined
  1506. + added int64funcresok define to options.pas
  1507. Revision 1.19 2000/11/30 22:48:23 florian
  1508. * opts386 renamed
  1509. Revision 1.18 2000/11/29 00:30:34 florian
  1510. * unused units removed from uses clause
  1511. * some changes for widestrings
  1512. Revision 1.17 2000/11/13 15:26:12 marco
  1513. * Renamefest
  1514. Revision 1.16 2000/11/12 22:20:37 peter
  1515. * create generic toutputsection for binary writers
  1516. Revision 1.15 2000/11/07 15:09:27 marco
  1517. * Define UNIX for FreeBSD and Linux. Checked crosscompile thingy.
  1518. Revision 1.14 2000/11/07 14:25:08 marco
  1519. * FreeBSD defines (FreeBSD,Linux,BSD,Unix) Linux defines (Linux,Unix)
  1520. Revision 1.13 2000/11/06 20:30:54 peter
  1521. * more fixes to get make cycle working
  1522. Revision 1.12 2000/11/04 14:25:20 florian
  1523. + merged Attila's changes for interfaces, not tested yet
  1524. Revision 1.11 2000/09/26 10:50:41 jonas
  1525. * initmodeswitches is changed is you change the compiler mode from the
  1526. command line (the -S<x> switches didn't work anymore for changing the
  1527. compiler mode) (merged from fixes branch)
  1528. Revision 1.10 2000/09/24 21:33:47 peter
  1529. * message updates merges
  1530. Revision 1.9 2000/09/24 15:06:20 peter
  1531. * use defines.inc
  1532. Revision 1.8 2000/09/18 12:28:41 marco
  1533. * Definition of multiple FreeBSD target defines moved to after error check
  1534. commandline parsing
  1535. Revision 1.7 2000/09/16 12:22:52 peter
  1536. * freebsd support merged
  1537. Revision 1.6 2000/08/27 16:11:51 peter
  1538. * moved some util functions from globals,cobjects to cutils
  1539. * splitted files into finput,fmodule
  1540. Revision 1.5 2000/08/07 11:31:04 jonas
  1541. * fixed bug in type conversions between enum subranges (it didn't take
  1542. the packenum directive into account)
  1543. + define PACKENUMFIXED symbol in options.pas
  1544. (merged from fixes branch)
  1545. Revision 1.4 2000/07/14 05:11:48 michael
  1546. + Patch to 1.1
  1547. Revision 1.3 2000/07/13 12:08:26 michael
  1548. + patched to 1.1.0 with former 1.09patch from peter
  1549. Revision 1.2 2000/07/13 11:32:44 michael
  1550. + removed logs
  1551. }