options.pas 49 KB

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