options.pas 49 KB

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