options.pas 48 KB

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