options.pas 47 KB

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