options.pas 50 KB

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