options.pas 53 KB

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