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