options.pas 49 KB

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