options.pas 47 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520
  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. cutils,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('FPC');
  1145. def_symbol('VER'+version_nr);
  1146. def_symbol('VER'+version_nr+'_'+release_nr);
  1147. def_symbol('VER'+version_nr+'_'+release_nr+'_'+patch_nr);
  1148. {$ifdef newcg}
  1149. def_symbol('WITHNEWCG');
  1150. {$endif}
  1151. { Temporary defines, until things settle down }
  1152. def_symbol('HASWIDECHAR');
  1153. {$ifdef SUPPORT_FIXED}
  1154. def_symbol('HASFIXED');
  1155. {$endif SUPPORT_FIXED}
  1156. {$ifdef cardinalmulfix}
  1157. { for the compiler }
  1158. def_symbol('CARDINALMULFIX');
  1159. { for the RTL }
  1160. def_symbol('CARDINALMULFIXED');
  1161. {$endif cardinalmulfix}
  1162. def_symbol('PACKENUMFIXED');
  1163. { New since 1.09 }
  1164. def_symbol('HASOUT');
  1165. { some stuff for TP compatibility }
  1166. {$ifdef i386}
  1167. def_symbol('CPU86');
  1168. def_symbol('CPU87');
  1169. {$endif}
  1170. {$ifdef m68k}
  1171. def_symbol('CPU68');
  1172. {$endif}
  1173. { new processor stuff }
  1174. {$ifdef i386}
  1175. def_symbol('CPUI386');
  1176. {$endif}
  1177. {$ifdef m68k}
  1178. def_symbol('CPU68K');
  1179. {$endif}
  1180. {$ifdef ALPHA}
  1181. def_symbol('CPUALPHA');
  1182. {$endif}
  1183. {$ifdef powerpc}
  1184. def_symbol('CPUPOWERPC');
  1185. {$endif}
  1186. { get default messagefile }
  1187. {$ifdef Delphi}
  1188. msgfilename:=dmisc.getenv('PPC_ERROR_FILE');
  1189. {$else Delphi}
  1190. msgfilename:=dos.getenv('PPC_ERROR_FILE');
  1191. {$endif Delphi}
  1192. { default configfile }
  1193. if (cmd<>'') and (cmd[1]='[') then
  1194. begin
  1195. ppccfg:=Copy(cmd,2,pos(']',cmd)-2);
  1196. Delete(cmd,1,pos(']',cmd));
  1197. end
  1198. else
  1199. begin
  1200. {$ifdef i386}
  1201. ppccfg:='ppc386.cfg';
  1202. {$endif i386}
  1203. {$ifdef m68k}
  1204. ppccfg:='ppc.cfg';
  1205. {$endif}
  1206. {$ifdef alpha}
  1207. ppccfg:='ppcalpha.cfg';
  1208. {$endif}
  1209. {$ifdef powerpc}
  1210. ppccfg:='ppcppc.cfg';
  1211. {$endif}
  1212. end;
  1213. { Order to read ppc386.cfg:
  1214. 1 - current dir
  1215. 2 - configpath
  1216. 3 - compiler path }
  1217. {$ifdef Delphi}
  1218. configpath:=FixPath(dmisc.getenv('PPC_CONFIG_PATH'),false);
  1219. {$else Delphi}
  1220. configpath:=FixPath(dos.getenv('PPC_CONFIG_PATH'),false);
  1221. {$endif Delphi}
  1222. {$ifdef linux}
  1223. if configpath='' then
  1224. configpath:='/etc/';
  1225. {$endif}
  1226. if ppccfg<>'' then
  1227. begin
  1228. read_configfile:=true;
  1229. if not FileExists(ppccfg) then
  1230. begin
  1231. {$ifdef linux}
  1232. if (dos.getenv('HOME')<>'') and FileExists(FixPath(dos.getenv('HOME'),false)+'.'+ppccfg) then
  1233. ppccfg:=FixPath(dos.getenv('HOME'),false)+'.'+ppccfg
  1234. else
  1235. {$endif}
  1236. if FileExists(configpath+ppccfg) then
  1237. ppccfg:=configpath+ppccfg
  1238. else
  1239. {$ifndef linux}
  1240. if FileExists(exepath+ppccfg) then
  1241. ppccfg:=exepath+ppccfg
  1242. else
  1243. {$endif}
  1244. read_configfile:=false;
  1245. end;
  1246. end
  1247. else
  1248. read_configfile:=false;
  1249. { Read commandline and configfile }
  1250. target_is_set:=false;
  1251. asm_is_set:=false;
  1252. param_file:='';
  1253. if read_configfile then
  1254. begin
  1255. { read the parameters quick, only -v -T }
  1256. option^.firstpass:=true;
  1257. if cmd<>'' then
  1258. option^.parsecmd(cmd)
  1259. else
  1260. option^.read_parameters;
  1261. option^.firstpass:=false;
  1262. if read_configfile then
  1263. begin
  1264. {$ifdef DEBUG}
  1265. Comment(V_Debug,'read config file: '+ppccfg);
  1266. {$endif DEBUG}
  1267. option^.interpret_file(ppccfg);
  1268. end;
  1269. end;
  1270. if cmd<>'' then
  1271. option^.parsecmd(cmd)
  1272. else
  1273. option^.read_parameters;
  1274. { Stop if errors in options }
  1275. if ErrorCount>0 then
  1276. StopOptions;
  1277. { Hack: Linux define is also needed for freebsd (MvdV) }
  1278. if target_info.target=target_i386_freebsd then
  1279. begin
  1280. def_symbol('LINUX');
  1281. def_symbol('BSD');
  1282. def_symbol('FREEBSD');
  1283. end;
  1284. { write logo if set }
  1285. if option^.DoWriteLogo then
  1286. option^.WriteLogo;
  1287. { Check file to compile }
  1288. if param_file='' then
  1289. begin
  1290. Message(option_no_source_found);
  1291. StopOptions;
  1292. end;
  1293. {$ifndef linux}
  1294. param_file:=FixFileName(param_file);
  1295. {$endif}
  1296. fsplit(param_file,inputdir,inputfile,inputextension);
  1297. if inputextension='' then
  1298. begin
  1299. if FileExists(inputdir+inputfile+target_os.sourceext) then
  1300. inputextension:=target_os.sourceext
  1301. else
  1302. if FileExists(inputdir+inputfile+target_os.pasext) then
  1303. inputextension:=target_os.pasext;
  1304. end;
  1305. { Add paths specified with parameters to the searchpaths }
  1306. UnitSearchPath.AddList(Option^.ParaUnitPath,true);
  1307. ObjectSearchPath.AddList(Option^.ParaObjectPath,true);
  1308. IncludeSearchPath.AddList(Option^.ParaIncludePath,true);
  1309. LibrarySearchPath.AddList(Option^.ParaLibraryPath,true);
  1310. { add unit environment and exepath to the unit search path }
  1311. if inputdir<>'' then
  1312. Unitsearchpath.AddPath(inputdir,true);
  1313. if not disable_configfile then
  1314. {$ifdef Delphi}
  1315. UnitSearchPath.AddPath(dmisc.getenv(target_info.unit_env),false);
  1316. {$else}
  1317. UnitSearchPath.AddPath(dos.getenv(target_info.unit_env),false);
  1318. {$endif Delphi}
  1319. {$ifdef linux}
  1320. fpcdir:=FixPath(getenv('FPCDIR'),false);
  1321. if fpcdir='' then
  1322. begin
  1323. if PathExists('/usr/local/lib/fpc/'+version_string) then
  1324. fpcdir:='/usr/local/lib/fpc/'+version_string+'/'
  1325. else
  1326. fpcdir:='/usr/lib/fpc/'+version_string+'/';
  1327. end;
  1328. {$else}
  1329. fpcdir:=FixPath(getenv('FPCDIR'),false);
  1330. if fpcdir='' then
  1331. begin
  1332. fpcdir:=ExePath+'../';
  1333. if not(PathExists(fpcdir+'/units')) and
  1334. not(PathExists(fpcdir+'/rtl')) then
  1335. fpcdir:=fpcdir+'../';
  1336. end;
  1337. {$endif}
  1338. { first try development RTL, else use the default installation path }
  1339. if not disable_configfile then
  1340. begin
  1341. if PathExists(FpcDir+'rtl/'+lower(target_info.short_name)) then
  1342. UnitSearchPath.AddPath(FpcDir+'rtl/'+lower(target_info.short_name),false)
  1343. else
  1344. begin
  1345. UnitSearchPath.AddPath(FpcDir+'units/'+lower(target_info.short_name),false);
  1346. UnitSearchPath.AddPath(FpcDir+'units/'+lower(target_info.short_name)+'/rtl',false);
  1347. end;
  1348. end;
  1349. { Add exepath if the exe is not in the current dir, because that is always searched already }
  1350. if ExePath<>GetCurrentDir then
  1351. UnitSearchPath.AddPath(ExePath,false);
  1352. { Add unit dir to the object and library path }
  1353. objectsearchpath.AddList(unitsearchpath,false);
  1354. librarysearchpath.AddList(unitsearchpath,false);
  1355. { switch assembler if it's binary and we got -a on the cmdline }
  1356. if (cs_asm_leave in initglobalswitches) and
  1357. (target_asm.id in binassem) then
  1358. begin
  1359. Message(option_switch_bin_to_src_assembler);
  1360. set_target_asm(target_info.assemsrc);
  1361. initoutputformat:=target_asm.id;
  1362. end;
  1363. if (target_asm.supported_target <> target_any) and
  1364. (target_asm.supported_target <> target_info.target) then
  1365. begin
  1366. Message2(option_incompatible_asm,target_asm.idtxt,target_os.name);
  1367. { Should we reset to default ??? }
  1368. set_target_asm(target_info.assemsrc);
  1369. Message1(option_asm_forced,target_asm.idtxt);
  1370. initoutputformat:=target_asm.id;
  1371. end;
  1372. { turn off stripping if compiling with debuginfo or profile }
  1373. if (cs_debuginfo in initmoduleswitches) or
  1374. (cs_profile in initmoduleswitches) then
  1375. initglobalswitches:=initglobalswitches-[cs_link_strip];
  1376. if not LinkTypeSetExplicitly then
  1377. begin
  1378. if (target_os.id=os_i386_win32) then
  1379. begin
  1380. def_symbol('FPC_LINK_SMART');
  1381. undef_symbol('FPC_LINK_STATIC');
  1382. undef_symbol('FPC_LINK_DYNAMIC');
  1383. initglobalswitches:=initglobalswitches+[cs_link_smart];
  1384. initglobalswitches:=initglobalswitches-[cs_link_shared,cs_link_static];
  1385. end
  1386. else
  1387. begin
  1388. undef_symbol('FPC_LINK_SMART');
  1389. def_symbol('FPC_LINK_STATIC');
  1390. undef_symbol('FPC_LINK_DYNAMIC');
  1391. initglobalswitches:=initglobalswitches+[cs_link_static];
  1392. initglobalswitches:=initglobalswitches-[cs_link_shared,cs_link_smart];
  1393. end;
  1394. end;
  1395. { Set defines depending on the target }
  1396. if (target_info.target in [target_i386_GO32V1,target_i386_GO32V2]) then
  1397. def_symbol('DPMI'); { MSDOS is not defined in BP when target is DPMI }
  1398. MaybeLoadMessageFile;
  1399. dispose(option,Done);
  1400. Option:=nil;
  1401. end;
  1402. end.
  1403. {
  1404. $Log$
  1405. Revision 1.8 2000-09-18 12:28:41 marco
  1406. * Definition of multiple FreeBSD target defines moved to after error check
  1407. commandline parsing
  1408. Revision 1.7 2000/09/16 12:22:52 peter
  1409. * freebsd support merged
  1410. Revision 1.6 2000/08/27 16:11:51 peter
  1411. * moved some util functions from globals,cobjects to cutils
  1412. * splitted files into finput,fmodule
  1413. Revision 1.5 2000/08/07 11:31:04 jonas
  1414. * fixed bug in type conversions between enum subranges (it didn't take
  1415. the packenum directive into account)
  1416. + define PACKENUMFIXED symbol in options.pas
  1417. (merged from fixes branch)
  1418. Revision 1.4 2000/07/14 05:11:48 michael
  1419. + Patch to 1.1
  1420. Revision 1.3 2000/07/13 12:08:26 michael
  1421. + patched to 1.1.0 with former 1.09patch from peter
  1422. Revision 1.2 2000/07/13 11:32:44 michael
  1423. + removed logs
  1424. }