options.pas 49 KB

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