options.pas 47 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522
  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. for j:=1 to length(more) do
  663. case more[j] of
  664. '2' : initmodeswitches:=objfpcmodeswitches;
  665. 'a' : initlocalswitches:=InitLocalswitches+[cs_do_assertion];
  666. 'c' : initmoduleswitches:=initmoduleswitches+[cs_support_c_operators];
  667. 'd' : initmodeswitches:=delphimodeswitches;
  668. 'e' : begin
  669. SetErrorFlags(more);
  670. break;
  671. end;
  672. 'g' : initmoduleswitches:=initmoduleswitches+[cs_support_goto];
  673. 'h' : initlocalswitches:=initlocalswitches+[cs_ansistrings];
  674. 'i' : initmoduleswitches:=initmoduleswitches+[cs_support_inline];
  675. 'm' : initmoduleswitches:=initmoduleswitches+[cs_support_macro];
  676. 'o': initmodeswitches:=tpmodeswitches;
  677. 'p' : initmodeswitches:=gpcmodeswitches;
  678. 's' : initglobalswitches:=initglobalswitches+[cs_constructor_name];
  679. 't' : initmoduleswitches:=initmoduleswitches+[cs_static_keyword];
  680. 'v' : Message1(option_obsolete_switch,'-Sv');
  681. else
  682. IllegalPara(opt);
  683. end;
  684. end;
  685. 'T' : begin
  686. more:=Upper(More);
  687. if not target_is_set then
  688. begin
  689. { remove old target define }
  690. undef_symbol(target_info.short_name);
  691. { load new target }
  692. if not(set_string_target(More)) then
  693. IllegalPara(opt);
  694. { set new define }
  695. def_symbol(target_info.short_name);
  696. if not asm_is_set then
  697. initoutputformat:=target_asm.id;
  698. target_is_set:=true;
  699. end
  700. else
  701. if More<>target_info.short_name then
  702. Message1(option_target_is_already_set,target_info.short_name);
  703. end;
  704. 'u' : undef_symbol(upper(More));
  705. 'U' : begin
  706. for j:=1 to length(more) do
  707. case more[j] of
  708. {$ifdef UNITALIASES}
  709. 'a' : begin
  710. AddUnitAlias(Copy(More,j+1,255));
  711. break;
  712. end;
  713. {$endif UNITALIASES}
  714. 'n' : initglobalswitches:=initglobalswitches-[cs_check_unit_name];
  715. 'p' : begin
  716. Message2(option_obsolete_switch_use_new,'-Up','-Fu');
  717. break;
  718. end;
  719. 's' : initmoduleswitches:=initmoduleswitches+[cs_compilesystem];
  720. else
  721. IllegalPara(opt);
  722. end;
  723. end;
  724. 'v' : if not setverbosity(More) then
  725. IllegalPara(opt);
  726. 'W' : begin
  727. for j:=1 to length(More) do
  728. case More[j] of
  729. 'B': {bind_win32_dll:=true}
  730. begin
  731. { -WB200000 means set prefered base address
  732. to $200000, but does not change relocsection boolean
  733. this way we can create both relocatble and
  734. non relocatable DLL at a specific base address PM }
  735. if (length(More)>j) then
  736. begin
  737. if DLLImageBase=nil then
  738. DLLImageBase:=StringDup(Copy(More,j+1,255));
  739. end
  740. else
  741. begin
  742. RelocSection:=true;
  743. RelocSectionSetExplicitly:=true;
  744. end;
  745. break;
  746. end;
  747. 'C': apptype:=at_cui;
  748. 'D': ForceDeffileForExport:=true;
  749. 'G': apptype:=at_gui;
  750. 'N': begin
  751. RelocSection:=false;
  752. RelocSectionSetExplicitly:=true;
  753. end;
  754. 'R': begin
  755. RelocSection:=true;
  756. RelocSectionSetExplicitly:=true;
  757. end;
  758. else
  759. IllegalPara(opt);
  760. end;
  761. end;
  762. 'X' : begin
  763. for j:=1 to length(More) do
  764. case More[j] of
  765. 'c' : initglobalswitches:=initglobalswitches+[cs_link_toc];
  766. 's' : initglobalswitches:=initglobalswitches+[cs_link_strip];
  767. 't' : initglobalswitches:=initglobalswitches+[cs_link_staticflag];
  768. 'D' : begin
  769. def_symbol('FPC_LINK_DYNAMIC');
  770. undef_symbol('FPC_LINK_SMART');
  771. undef_symbol('FPC_LINK_STATIC');
  772. initglobalswitches:=initglobalswitches+[cs_link_shared];
  773. initglobalswitches:=initglobalswitches-[cs_link_static,cs_link_smart];
  774. LinkTypeSetExplicitly:=true;
  775. end;
  776. 'S' : begin
  777. def_symbol('FPC_LINK_STATIC');
  778. undef_symbol('FPC_LINK_SMART');
  779. undef_symbol('FPC_LINK_DYNAMIC');
  780. initglobalswitches:=initglobalswitches+[cs_link_static];
  781. initglobalswitches:=initglobalswitches-[cs_link_shared,cs_link_smart];
  782. LinkTypeSetExplicitly:=true;
  783. end;
  784. 'X' : begin
  785. def_symbol('FPC_LINK_SMART');
  786. undef_symbol('FPC_LINK_STATIC');
  787. undef_symbol('FPC_LINK_DYNAMIC');
  788. initglobalswitches:=initglobalswitches+[cs_link_smart];
  789. initglobalswitches:=initglobalswitches-[cs_link_shared,cs_link_static];
  790. LinkTypeSetExplicitly:=true;
  791. end;
  792. else
  793. IllegalPara(opt);
  794. end;
  795. end;
  796. { give processor specific options a chance }
  797. else
  798. interpret_proc_specific_options(opt);
  799. end;
  800. end;
  801. '@' : begin
  802. Message(option_no_nested_response_file);
  803. StopOptions;
  804. end;
  805. else
  806. begin
  807. if (length(param_file)<>0) then
  808. Message(option_only_one_source_support);
  809. param_file:=opt;
  810. end;
  811. end;
  812. end;
  813. procedure Toption.Interpret_file(const filename : string);
  814. procedure RemoveSep(var fn:string);
  815. var
  816. i : longint;
  817. begin
  818. i:=0;
  819. while (i<length(fn)) and (fn[i+1] in [',',' ',#9]) do
  820. inc(i);
  821. Delete(fn,1,i);
  822. i:=length(fn);
  823. while (i>0) and (fn[i] in [',',' ',#9]) do
  824. dec(i);
  825. fn:=copy(fn,1,i);
  826. end;
  827. function GetName(var fn:string):string;
  828. var
  829. i : longint;
  830. begin
  831. i:=0;
  832. while (i<length(fn)) and (fn[i+1] in ['a'..'z','A'..'Z','0'..'9','_','-']) do
  833. inc(i);
  834. GetName:=Copy(fn,1,i);
  835. Delete(fn,1,i);
  836. end;
  837. const
  838. maxlevel=16;
  839. var
  840. f : text;
  841. s,
  842. opts : string;
  843. skip : array[0..maxlevel-1] of boolean;
  844. level : longint;
  845. option_read : boolean;
  846. begin
  847. { avoid infinite loop }
  848. Inc(FileLevel);
  849. Option_read:=false;
  850. If FileLevel>MaxLevel then
  851. Message(option_too_many_cfg_files);
  852. { open file }
  853. assign(f,filename);
  854. {$ifdef extdebug}
  855. Comment(V_Info,'trying to open file: '+filename);
  856. {$endif extdebug}
  857. {$I-}
  858. reset(f);
  859. {$I+}
  860. if ioresult<>0 then
  861. begin
  862. Message1(option_unable_open_file,filename);
  863. exit;
  864. end;
  865. fillchar(skip,sizeof(skip),0);
  866. level:=0;
  867. while not eof(f) do
  868. begin
  869. readln(f,opts);
  870. RemoveSep(opts);
  871. if (opts<>'') and (opts[1]<>';') then
  872. begin
  873. if opts[1]='#' then
  874. begin
  875. Delete(opts,1,1);
  876. s:=upper(GetName(opts));
  877. if (s='SECTION') then
  878. begin
  879. RemoveSep(opts);
  880. s:=upper(GetName(opts));
  881. if level=0 then
  882. skip[level]:=not (check_symbol(s) or (s='COMMON'));
  883. end
  884. else
  885. if (s='IFDEF') then
  886. begin
  887. RemoveSep(opts);
  888. if Level>=maxlevel then
  889. begin
  890. Message(option_too_many_ifdef);
  891. stopOptions;
  892. end;
  893. inc(Level);
  894. skip[level]:=(skip[level-1] or (not check_symbol(upper(GetName(opts)))));
  895. end
  896. else
  897. if (s='IFNDEF') then
  898. begin
  899. RemoveSep(opts);
  900. if Level>=maxlevel then
  901. begin
  902. Message(option_too_many_ifdef);
  903. stopOptions;
  904. end;
  905. inc(Level);
  906. skip[level]:=(skip[level-1] or (check_symbol(upper(GetName(opts)))));
  907. end
  908. else
  909. if (s='ELSE') then
  910. skip[level]:=skip[level-1] or (not skip[level])
  911. else
  912. if (s='ENDIF') then
  913. begin
  914. skip[level]:=false;
  915. if Level=0 then
  916. begin
  917. Message(option_too_many_endif);
  918. stopOptions;
  919. end;
  920. dec(level);
  921. end
  922. else
  923. if (not skip[level]) then
  924. begin
  925. if (s='DEFINE') then
  926. begin
  927. RemoveSep(opts);
  928. def_symbol(upper(GetName(opts)));
  929. end
  930. else
  931. if (s='UNDEF') then
  932. begin
  933. RemoveSep(opts);
  934. undef_symbol(upper(GetName(opts)));
  935. end
  936. else
  937. if (s='WRITE') then
  938. begin
  939. Delete(opts,1,1);
  940. WriteLn(opts);
  941. end
  942. else
  943. if (s='INCLUDE') then
  944. begin
  945. Delete(opts,1,1);
  946. Interpret_file(opts);
  947. end;
  948. end;
  949. end
  950. else
  951. begin
  952. if (opts[1]='-') then
  953. begin
  954. if (not skip[level]) then
  955. interpret_option(opts,false);
  956. Option_read:=true;
  957. end
  958. else
  959. Message1(option_illegal_para,opts);
  960. end;
  961. end;
  962. end;
  963. if Level>0 then
  964. Message(option_too_less_endif);
  965. if Not Option_read then
  966. Message1(option_no_option_found,filename);
  967. Close(f);
  968. Dec(FileLevel);
  969. end;
  970. procedure Toption.Interpret_envvar(const envname : string);
  971. var
  972. argstart,
  973. env,
  974. pc : pchar;
  975. arglen : longint;
  976. quote : set of char;
  977. hs : string;
  978. begin
  979. env:=GetEnvPChar(envname);
  980. pc:=env;
  981. if assigned(pc) then
  982. begin
  983. repeat
  984. { skip leading spaces }
  985. while pc^ in [' ',#9,#13] do
  986. inc(pc);
  987. case pc^ of
  988. #0 :
  989. break;
  990. '"' :
  991. begin
  992. quote:=['"'];
  993. inc(pc);
  994. end;
  995. '''' :
  996. begin
  997. quote:=[''''];
  998. inc(pc);
  999. end;
  1000. else
  1001. quote:=[' ',#9,#13];
  1002. end;
  1003. { scan until the end of the argument }
  1004. argstart:=pc;
  1005. while (pc^<>#0) and not(pc^ in quote) do
  1006. inc(pc);
  1007. { create argument }
  1008. arglen:=pc-argstart;
  1009. hs[0]:=chr(arglen);
  1010. move(argstart^,hs[1],arglen);
  1011. interpret_option(hs,true);
  1012. { skip quote }
  1013. if pc^ in quote then
  1014. inc(pc);
  1015. until false;
  1016. end
  1017. else
  1018. Message1(option_no_option_found,'(env) '+envname);
  1019. FreeEnvPChar(env);
  1020. end;
  1021. procedure toption.read_parameters;
  1022. var
  1023. opts : string;
  1024. paramindex : longint;
  1025. begin
  1026. paramindex:=0;
  1027. while paramindex<paramcount do
  1028. begin
  1029. inc(paramindex);
  1030. opts:=paramstr(paramindex);
  1031. case opts[1] of
  1032. '@' :
  1033. begin
  1034. Delete(opts,1,1);
  1035. if not firstpass then
  1036. Message1(option_reading_further_from,opts);
  1037. interpret_file(opts);
  1038. end;
  1039. '!' :
  1040. begin
  1041. Delete(opts,1,1);
  1042. if not firstpass then
  1043. Message1(option_reading_further_from,'(env) '+opts);
  1044. interpret_envvar(opts);
  1045. end;
  1046. else
  1047. interpret_option(opts,true);
  1048. end;
  1049. end;
  1050. end;
  1051. procedure toption.parsecmd(cmd:string);
  1052. var
  1053. i,ps : longint;
  1054. opts : string;
  1055. begin
  1056. while (cmd<>'') do
  1057. begin
  1058. while cmd[1]=' ' do
  1059. delete(cmd,1,1);
  1060. i:=pos(' ',cmd);
  1061. if i=0 then
  1062. i:=256;
  1063. opts:=Copy(cmd,1,i-1);
  1064. Delete(cmd,1,i);
  1065. case opts[1] of
  1066. '@' :
  1067. begin
  1068. Delete(opts,1,1);
  1069. if not firstpass then
  1070. Message1(option_reading_further_from,opts);
  1071. interpret_file(opts);
  1072. end;
  1073. '!' :
  1074. begin
  1075. Delete(opts,1,1);
  1076. if not firstpass then
  1077. Message1(option_reading_further_from,'(env) '+opts);
  1078. interpret_envvar(opts);
  1079. end;
  1080. '"' :
  1081. begin
  1082. Delete(opts,1,1);
  1083. ps:=pos('"',cmd);
  1084. if (i<>256) and (ps>0) then
  1085. begin
  1086. opts:=opts + ' '+ copy(cmd,1,ps-1);
  1087. cmd:=copy(cmd,ps+1,255);
  1088. end;
  1089. interpret_option(opts,true);
  1090. end;
  1091. else
  1092. interpret_option(opts,true);
  1093. end;
  1094. end;
  1095. end;
  1096. constructor TOption.Init;
  1097. begin
  1098. DoWriteLogo:=false;
  1099. NoPressEnter:=false;
  1100. FirstPass:=false;
  1101. FileLevel:=0;
  1102. ParaIncludePath.Init;
  1103. ParaObjectPath.Init;
  1104. ParaUnitPath.Init;
  1105. ParaLibraryPath.Init;
  1106. end;
  1107. destructor TOption.Done;
  1108. begin
  1109. ParaIncludePath.Done;
  1110. ParaObjectPath.Done;
  1111. ParaUnitPath.Done;
  1112. ParaLibraryPath.Done;
  1113. end;
  1114. {****************************************************************************
  1115. Callable Routines
  1116. ****************************************************************************}
  1117. procedure read_arguments(cmd:string);
  1118. var
  1119. configpath : pathstr;
  1120. begin
  1121. {$ifdef Delphi}
  1122. option:=new(poption386,Init);
  1123. {$endif Delphi}
  1124. {$ifdef i386}
  1125. option:=new(poption386,Init);
  1126. {$endif}
  1127. {$ifdef m68k}
  1128. option:=new(poption68k,Init);
  1129. {$endif}
  1130. {$ifdef alpha}
  1131. option:=new(poption,Init);
  1132. {$endif}
  1133. {$ifdef powerpc}
  1134. option:=new(poption,Init);
  1135. {$endif}
  1136. { Load messages }
  1137. if (cmd='') and (paramcount=0) then
  1138. Option^.WriteHelpPages;
  1139. disable_configfile:=false;
  1140. { default defines }
  1141. def_symbol(target_info.short_name);
  1142. def_symbol('FPC');
  1143. def_symbol('VER'+version_nr);
  1144. def_symbol('VER'+version_nr+'_'+release_nr);
  1145. def_symbol('VER'+version_nr+'_'+release_nr+'_'+patch_nr);
  1146. {$ifdef newcg}
  1147. def_symbol('WITHNEWCG');
  1148. {$endif}
  1149. { Temporary defines, until things settle down }
  1150. def_symbol('HASWIDECHAR');
  1151. {$ifdef SUPPORT_FIXED}
  1152. def_symbol('HASFIXED');
  1153. {$endif SUPPORT_FIXED}
  1154. {$ifdef cardinalmulfix}
  1155. { for the compiler }
  1156. def_symbol('CARDINALMULFIX');
  1157. { for the RTL }
  1158. def_symbol('CARDINALMULFIXED');
  1159. {$endif cardinalmulfix}
  1160. def_symbol('PACKENUMFIXED');
  1161. { New since 1.09 }
  1162. def_symbol('HASOUT');
  1163. { some stuff for TP compatibility }
  1164. {$ifdef i386}
  1165. def_symbol('CPU86');
  1166. def_symbol('CPU87');
  1167. {$endif}
  1168. {$ifdef m68k}
  1169. def_symbol('CPU68');
  1170. {$endif}
  1171. { new processor stuff }
  1172. {$ifdef i386}
  1173. def_symbol('CPUI386');
  1174. {$endif}
  1175. {$ifdef m68k}
  1176. def_symbol('CPU68K');
  1177. {$endif}
  1178. {$ifdef ALPHA}
  1179. def_symbol('CPUALPHA');
  1180. {$endif}
  1181. {$ifdef powerpc}
  1182. def_symbol('CPUPOWERPC');
  1183. {$endif}
  1184. { get default messagefile }
  1185. {$ifdef Delphi}
  1186. msgfilename:=dmisc.getenv('PPC_ERROR_FILE');
  1187. {$else Delphi}
  1188. msgfilename:=dos.getenv('PPC_ERROR_FILE');
  1189. {$endif Delphi}
  1190. { default configfile }
  1191. if (cmd<>'') and (cmd[1]='[') then
  1192. begin
  1193. ppccfg:=Copy(cmd,2,pos(']',cmd)-2);
  1194. Delete(cmd,1,pos(']',cmd));
  1195. end
  1196. else
  1197. begin
  1198. {$ifdef i386}
  1199. ppccfg:='ppc386.cfg';
  1200. {$endif i386}
  1201. {$ifdef m68k}
  1202. ppccfg:='ppc.cfg';
  1203. {$endif}
  1204. {$ifdef alpha}
  1205. ppccfg:='ppcalpha.cfg';
  1206. {$endif}
  1207. {$ifdef powerpc}
  1208. ppccfg:='ppcppc.cfg';
  1209. {$endif}
  1210. end;
  1211. { Order to read ppc386.cfg:
  1212. 1 - current dir
  1213. 2 - configpath
  1214. 3 - compiler path }
  1215. {$ifdef Delphi}
  1216. configpath:=FixPath(dmisc.getenv('PPC_CONFIG_PATH'),false);
  1217. {$else Delphi}
  1218. configpath:=FixPath(dos.getenv('PPC_CONFIG_PATH'),false);
  1219. {$endif Delphi}
  1220. {$ifdef linux}
  1221. if configpath='' then
  1222. configpath:='/etc/';
  1223. {$endif}
  1224. if ppccfg<>'' then
  1225. begin
  1226. read_configfile:=true;
  1227. if not FileExists(ppccfg) then
  1228. begin
  1229. {$ifdef linux}
  1230. if (dos.getenv('HOME')<>'') and FileExists(FixPath(dos.getenv('HOME'),false)+'.'+ppccfg) then
  1231. ppccfg:=FixPath(dos.getenv('HOME'),false)+'.'+ppccfg
  1232. else
  1233. {$endif}
  1234. if FileExists(configpath+ppccfg) then
  1235. ppccfg:=configpath+ppccfg
  1236. else
  1237. {$ifndef linux}
  1238. if FileExists(exepath+ppccfg) then
  1239. ppccfg:=exepath+ppccfg
  1240. else
  1241. {$endif}
  1242. read_configfile:=false;
  1243. end;
  1244. end
  1245. else
  1246. read_configfile:=false;
  1247. { Read commandline and configfile }
  1248. target_is_set:=false;
  1249. asm_is_set:=false;
  1250. param_file:='';
  1251. if read_configfile then
  1252. begin
  1253. { read the parameters quick, only -v -T }
  1254. option^.firstpass:=true;
  1255. if cmd<>'' then
  1256. option^.parsecmd(cmd)
  1257. else
  1258. option^.read_parameters;
  1259. option^.firstpass:=false;
  1260. if read_configfile then
  1261. begin
  1262. {$ifdef DEBUG}
  1263. Comment(V_Debug,'read config file: '+ppccfg);
  1264. {$endif DEBUG}
  1265. option^.interpret_file(ppccfg);
  1266. end;
  1267. end;
  1268. if cmd<>'' then
  1269. option^.parsecmd(cmd)
  1270. else
  1271. option^.read_parameters;
  1272. { Stop if errors in options }
  1273. if ErrorCount>0 then
  1274. StopOptions;
  1275. { Hack: Linux define is also needed for freebsd (MvdV) }
  1276. if target_info.target=target_i386_freebsd then
  1277. begin
  1278. def_symbol('LINUX');
  1279. def_symbol('BSD');
  1280. def_symbol('FREEBSD');
  1281. end;
  1282. { write logo if set }
  1283. if option^.DoWriteLogo then
  1284. option^.WriteLogo;
  1285. { Check file to compile }
  1286. if param_file='' then
  1287. begin
  1288. Message(option_no_source_found);
  1289. StopOptions;
  1290. end;
  1291. {$ifndef linux}
  1292. param_file:=FixFileName(param_file);
  1293. {$endif}
  1294. fsplit(param_file,inputdir,inputfile,inputextension);
  1295. if inputextension='' then
  1296. begin
  1297. if FileExists(inputdir+inputfile+target_os.sourceext) then
  1298. inputextension:=target_os.sourceext
  1299. else
  1300. if FileExists(inputdir+inputfile+target_os.pasext) then
  1301. inputextension:=target_os.pasext;
  1302. end;
  1303. { Add paths specified with parameters to the searchpaths }
  1304. UnitSearchPath.AddList(Option^.ParaUnitPath,true);
  1305. ObjectSearchPath.AddList(Option^.ParaObjectPath,true);
  1306. IncludeSearchPath.AddList(Option^.ParaIncludePath,true);
  1307. LibrarySearchPath.AddList(Option^.ParaLibraryPath,true);
  1308. { add unit environment and exepath to the unit search path }
  1309. if inputdir<>'' then
  1310. Unitsearchpath.AddPath(inputdir,true);
  1311. if not disable_configfile then
  1312. {$ifdef Delphi}
  1313. UnitSearchPath.AddPath(dmisc.getenv(target_info.unit_env),false);
  1314. {$else}
  1315. UnitSearchPath.AddPath(dos.getenv(target_info.unit_env),false);
  1316. {$endif Delphi}
  1317. {$ifdef linux}
  1318. fpcdir:=FixPath(getenv('FPCDIR'),false);
  1319. if fpcdir='' then
  1320. begin
  1321. if PathExists('/usr/local/lib/fpc/'+version_string) then
  1322. fpcdir:='/usr/local/lib/fpc/'+version_string+'/'
  1323. else
  1324. fpcdir:='/usr/lib/fpc/'+version_string+'/';
  1325. end;
  1326. {$else}
  1327. fpcdir:=FixPath(getenv('FPCDIR'),false);
  1328. if fpcdir='' then
  1329. begin
  1330. fpcdir:=ExePath+'../';
  1331. if not(PathExists(fpcdir+'/units')) and
  1332. not(PathExists(fpcdir+'/rtl')) then
  1333. fpcdir:=fpcdir+'../';
  1334. end;
  1335. {$endif}
  1336. { first try development RTL, else use the default installation path }
  1337. if not disable_configfile then
  1338. begin
  1339. if PathExists(FpcDir+'rtl/'+lower(target_info.short_name)) then
  1340. UnitSearchPath.AddPath(FpcDir+'rtl/'+lower(target_info.short_name),false)
  1341. else
  1342. begin
  1343. UnitSearchPath.AddPath(FpcDir+'units/'+lower(target_info.short_name),false);
  1344. UnitSearchPath.AddPath(FpcDir+'units/'+lower(target_info.short_name)+'/rtl',false);
  1345. end;
  1346. end;
  1347. { Add exepath if the exe is not in the current dir, because that is always searched already }
  1348. if ExePath<>GetCurrentDir then
  1349. UnitSearchPath.AddPath(ExePath,false);
  1350. { Add unit dir to the object and library path }
  1351. objectsearchpath.AddList(unitsearchpath,false);
  1352. librarysearchpath.AddList(unitsearchpath,false);
  1353. { switch assembler if it's binary and we got -a on the cmdline }
  1354. if (cs_asm_leave in initglobalswitches) and
  1355. (target_asm.id in binassem) then
  1356. begin
  1357. Message(option_switch_bin_to_src_assembler);
  1358. set_target_asm(target_info.assemsrc);
  1359. initoutputformat:=target_asm.id;
  1360. end;
  1361. if (target_asm.supported_target <> target_any) and
  1362. (target_asm.supported_target <> target_info.target) then
  1363. begin
  1364. Message2(option_incompatible_asm,target_asm.idtxt,target_os.name);
  1365. { Should we reset to default ??? }
  1366. set_target_asm(target_info.assemsrc);
  1367. Message1(option_asm_forced,target_asm.idtxt);
  1368. initoutputformat:=target_asm.id;
  1369. end;
  1370. { turn off stripping if compiling with debuginfo or profile }
  1371. if (cs_debuginfo in initmoduleswitches) or
  1372. (cs_profile in initmoduleswitches) then
  1373. initglobalswitches:=initglobalswitches-[cs_link_strip];
  1374. if not LinkTypeSetExplicitly then
  1375. begin
  1376. if (target_os.id=os_i386_win32) then
  1377. begin
  1378. def_symbol('FPC_LINK_SMART');
  1379. undef_symbol('FPC_LINK_STATIC');
  1380. undef_symbol('FPC_LINK_DYNAMIC');
  1381. initglobalswitches:=initglobalswitches+[cs_link_smart];
  1382. initglobalswitches:=initglobalswitches-[cs_link_shared,cs_link_static];
  1383. end
  1384. else
  1385. begin
  1386. undef_symbol('FPC_LINK_SMART');
  1387. def_symbol('FPC_LINK_STATIC');
  1388. undef_symbol('FPC_LINK_DYNAMIC');
  1389. initglobalswitches:=initglobalswitches+[cs_link_static];
  1390. initglobalswitches:=initglobalswitches-[cs_link_shared,cs_link_smart];
  1391. end;
  1392. end;
  1393. { Set defines depending on the target }
  1394. if (target_info.target in [target_i386_GO32V1,target_i386_GO32V2]) then
  1395. def_symbol('DPMI'); { MSDOS is not defined in BP when target is DPMI }
  1396. MaybeLoadMessageFile;
  1397. dispose(option,Done);
  1398. Option:=nil;
  1399. end;
  1400. end.
  1401. {
  1402. $Log$
  1403. Revision 1.9 2000-09-24 15:06:20 peter
  1404. * use defines.inc
  1405. Revision 1.8 2000/09/18 12:28:41 marco
  1406. * Definition of multiple FreeBSD target defines moved to after error check
  1407. commandline parsing
  1408. Revision 1.7 2000/09/16 12:22:52 peter
  1409. * freebsd support merged
  1410. Revision 1.6 2000/08/27 16:11:51 peter
  1411. * moved some util functions from globals,cobjects to cutils
  1412. * splitted files into finput,fmodule
  1413. Revision 1.5 2000/08/07 11:31:04 jonas
  1414. * fixed bug in type conversions between enum subranges (it didn't take
  1415. the packenum directive into account)
  1416. + define PACKENUMFIXED symbol in options.pas
  1417. (merged from fixes branch)
  1418. Revision 1.4 2000/07/14 05:11:48 michael
  1419. + Patch to 1.1
  1420. Revision 1.3 2000/07/13 12:08:26 michael
  1421. + patched to 1.1.0 with former 1.09patch from peter
  1422. Revision 1.2 2000/07/13 11:32:44 michael
  1423. + removed logs
  1424. }