options.pas 49 KB

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