options.pas 54 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732
  1. {
  2. $Id$
  3. Copyright (c) 1998-2002 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 fpcdefs.inc}
  20. interface
  21. uses
  22. globtype,globals,verbose,systems;
  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. ParaAlignment : TAlignmentInfo;
  35. Constructor Create;
  36. Destructor Destroy;override;
  37. procedure WriteLogo;
  38. procedure WriteInfo;
  39. procedure WriteHelpPages;
  40. procedure WriteQuickInfo;
  41. procedure IllegalPara(const opt:string);
  42. function Unsetbool(var Opts:string; Pos: Longint):boolean;
  43. procedure interpret_proc_specific_options(const opt:string);virtual;
  44. procedure interpret_option(const opt :string;ispara:boolean);
  45. procedure Interpret_envvar(const envname : string);
  46. procedure Interpret_file(const filename : string);
  47. procedure Read_Parameters;
  48. procedure parsecmd(cmd:string);
  49. procedure TargetDefines(def:boolean);
  50. end;
  51. TOptionClass=class of toption;
  52. var
  53. coption : TOptionClass;
  54. procedure read_arguments(cmd:string);
  55. implementation
  56. uses
  57. {$ifdef Delphi}
  58. dmisc,
  59. {$else Delphi}
  60. dos,
  61. {$endif Delphi}
  62. version,
  63. cutils,cmsgs
  64. {$ifdef BrowserLog}
  65. ,browlog
  66. {$endif BrowserLog}
  67. ;
  68. const
  69. page_size = 24;
  70. var
  71. option : toption;
  72. read_configfile, { read config file, set when a cfgfile is found }
  73. disable_configfile,
  74. target_is_set : boolean; { do not allow contradictory target settings }
  75. asm_is_set : boolean; { -T also change initoutputformat if not set idrectly }
  76. fpcdir,
  77. ppccfg,
  78. ppcaltcfg,
  79. param_file : string; { file to compile specified on the commandline }
  80. {****************************************************************************
  81. Defines
  82. ****************************************************************************}
  83. procedure def_symbol(const s : string);
  84. begin
  85. if s='' then
  86. exit;
  87. initdefines.insert(upper(s));
  88. end;
  89. procedure undef_symbol(const s : string);
  90. begin
  91. if s='' then
  92. exit;
  93. InitDefines.Remove(s);
  94. end;
  95. function check_symbol(const s:string):boolean;
  96. begin
  97. check_symbol:=(initdefines.find(s)<>nil);
  98. end;
  99. procedure set_default_link_type;
  100. begin
  101. if (target_info.target in [target_i386_win32,target_i386_wdosx]) then
  102. begin
  103. def_symbol('FPC_LINK_SMART');
  104. undef_symbol('FPC_LINK_STATIC');
  105. undef_symbol('FPC_LINK_DYNAMIC');
  106. initglobalswitches:=initglobalswitches+[cs_link_smart];
  107. initglobalswitches:=initglobalswitches-[cs_link_shared,cs_link_static];
  108. end
  109. else
  110. begin
  111. undef_symbol('FPC_LINK_SMART');
  112. def_symbol('FPC_LINK_STATIC');
  113. undef_symbol('FPC_LINK_DYNAMIC');
  114. initglobalswitches:=initglobalswitches+[cs_link_static];
  115. initglobalswitches:=initglobalswitches-[cs_link_shared,cs_link_smart];
  116. end;
  117. end;
  118. {****************************************************************************
  119. Toption
  120. ****************************************************************************}
  121. procedure StopOptions;
  122. begin
  123. if assigned(Option) then
  124. begin
  125. Option.free;
  126. Option:=nil;
  127. end;
  128. DoneVerbose;
  129. Stop;
  130. end;
  131. procedure Toption.WriteLogo;
  132. var
  133. p : pchar;
  134. begin
  135. p:=MessagePchar(option_logo);
  136. while assigned(p) do
  137. Comment(V_Normal,GetMsgLine(p));
  138. end;
  139. procedure Toption.WriteInfo;
  140. var
  141. p : pchar;
  142. hs,hs1,s : string;
  143. target : ttarget;
  144. begin
  145. p:=MessagePchar(option_info);
  146. while assigned(p) do
  147. begin
  148. s:=GetMsgLine(p);
  149. { list OS Targets }
  150. if pos('$OSTARGETS',s)>0 then
  151. begin
  152. for target:=low(ttarget) to high(ttarget) do
  153. if assigned(targetinfos[target]) then
  154. begin
  155. hs:=s;
  156. hs1:=targetinfos[target]^.name;
  157. if tf_under_development in targetinfos[target]^.flags then
  158. hs1:=hs1+' (under development)';
  159. Replace(hs,'$OSTARGETS',hs1);
  160. Comment(V_Normal,hs);
  161. end;
  162. end
  163. else
  164. Comment(V_Normal,s);
  165. end;
  166. StopOptions;
  167. end;
  168. procedure Toption.WriteHelpPages;
  169. function PadEnd(s:string;i:longint):string;
  170. begin
  171. while (length(s)<i) do
  172. s:=s+' ';
  173. PadEnd:=s;
  174. end;
  175. var
  176. lastident,
  177. j,outline,
  178. ident,
  179. lines : longint;
  180. show : boolean;
  181. opt : string[32];
  182. input,
  183. s : string;
  184. p : pchar;
  185. begin
  186. WriteLogo;
  187. Lines:=4;
  188. Message1(option_usage,system.paramstr(0));
  189. lastident:=0;
  190. p:=MessagePChar(option_help_pages);
  191. while assigned(p) do
  192. begin
  193. { get a line and reset }
  194. s:=GetMsgLine(p);
  195. ident:=0;
  196. show:=false;
  197. { parse options }
  198. case s[1] of
  199. {$ifdef UNITALIASES}
  200. 'a',
  201. {$endif}
  202. {$ifdef EXTDEBUG}
  203. 'e',
  204. {$endif EXTDEBUG}
  205. {$ifdef i386}
  206. '3',
  207. {$endif}
  208. {$ifdef m68k}
  209. '6',
  210. {$endif}
  211. '*' : show:=true;
  212. end;
  213. if show then
  214. begin
  215. case s[2] of
  216. {$ifdef GDB}
  217. 'g',
  218. {$endif}
  219. {$ifdef Unix}
  220. 'L',
  221. {$endif}
  222. {$ifdef os2}
  223. 'O',
  224. {$endif}
  225. '*' : show:=true;
  226. else
  227. show:=false;
  228. end;
  229. end;
  230. { now we may show the message or not }
  231. if show then
  232. begin
  233. case s[3] of
  234. '0' : begin
  235. ident:=0;
  236. outline:=0;
  237. end;
  238. '1' : begin
  239. ident:=2;
  240. outline:=7;
  241. end;
  242. '2' : begin
  243. ident:=6;
  244. outline:=11;
  245. end;
  246. '3' : begin
  247. ident:=9;
  248. outline:=6;
  249. end;
  250. end;
  251. j:=pos('_',s);
  252. opt:=Copy(s,4,j-4);
  253. if opt='*' then
  254. opt:=''
  255. else
  256. if opt=' ' then
  257. opt:=PadEnd(opt,outline)
  258. else
  259. opt:=PadEnd('-'+opt,outline);
  260. if (ident=0) and (lastident<>0) then
  261. begin
  262. Comment(V_Normal,'');
  263. inc(Lines);
  264. end;
  265. { page full ? }
  266. if (lines >= page_size - 1) then
  267. begin
  268. if not NoPressEnter then
  269. begin
  270. Message(option_help_press_enter);
  271. readln(input);
  272. if upper(input)='Q' then
  273. StopOptions;
  274. end;
  275. lines:=0;
  276. end;
  277. Comment(V_Normal,PadEnd('',ident)+opt+Copy(s,j+1,255));
  278. LastIdent:=Ident;
  279. inc(Lines);
  280. end;
  281. end;
  282. StopOptions;
  283. end;
  284. procedure Toption.IllegalPara(const opt:string);
  285. begin
  286. Message1(option_illegal_para,opt);
  287. Message(option_help_pages_para);
  288. StopOptions;
  289. end;
  290. function Toption.Unsetbool(var Opts:string; Pos: Longint):boolean;
  291. { checks if the character after pos in Opts is a + or a - and returns resp.
  292. false or true. If it is another character (or none), it also returns false }
  293. begin
  294. UnsetBool := false;
  295. if Length(Opts)>Pos then
  296. begin
  297. inc(Pos);
  298. UnsetBool := Opts[Pos] = '-';
  299. if Opts[Pos] in ['-','+']then
  300. delete(Opts,Pos,1);
  301. end;
  302. end;
  303. procedure TOption.interpret_proc_specific_options(const opt:string);
  304. begin
  305. end;
  306. procedure TOption.interpret_option(const opt:string;ispara:boolean);
  307. var
  308. code : integer;
  309. c : char;
  310. more : string;
  311. major,minor : longint;
  312. error : integer;
  313. j,l : longint;
  314. d : DirStr;
  315. e : ExtStr;
  316. forceasm : tasm;
  317. begin
  318. if opt='' then
  319. exit;
  320. { only parse define,undef,target,verbosity and link options the firsttime }
  321. if firstpass and
  322. not((opt[1]='-') and (opt[2] in ['i','d','v','T','u','n','X'])) then
  323. exit;
  324. Message1(option_handling_option,opt);
  325. case opt[1] of
  326. '-' : begin
  327. more:=Copy(opt,3,255);
  328. case opt[2] of
  329. '!' : initlocalswitches:=initlocalswitches+[cs_ansistrings];
  330. '?' : WriteHelpPages;
  331. 'a' : begin
  332. initglobalswitches:=initglobalswitches+[cs_asm_leave];
  333. for j:=1 to length(more) do
  334. case more[j] of
  335. 'l' : include(initglobalswitches,cs_asm_source);
  336. 'r' : include(initglobalswitches,cs_asm_regalloc);
  337. 't' : include(initglobalswitches,cs_asm_tempalloc);
  338. 'n' : include(initglobalswitches,cs_asm_nodes);
  339. '-' : initglobalswitches:=initglobalswitches -
  340. [cs_asm_leave, cs_asm_source,cs_asm_regalloc, cs_asm_tempalloc];
  341. else
  342. IllegalPara(opt);
  343. end;
  344. end;
  345. 'A' : begin
  346. if set_target_asm_by_string(More) then
  347. asm_is_set:=true
  348. else
  349. IllegalPara(opt);
  350. end;
  351. 'b' : begin
  352. if UnsetBool(More,0) then
  353. begin
  354. exclude(initmoduleswitches,cs_browser);
  355. exclude(initmoduleswitches,cs_local_browser);
  356. {$ifdef BrowserLog}
  357. exclude(initglobalswitches,cs_browser_log);
  358. {$endif}
  359. end
  360. else
  361. begin
  362. include(initmoduleswitches,cs_browser);
  363. {$ifdef BrowserLog}
  364. include(initglobalswitches,cs_browser_log);
  365. {$endif}
  366. end;
  367. if More<>'' then
  368. if (More='l') or (More='l+') then
  369. include(initmoduleswitches,cs_local_browser)
  370. else
  371. if More='l-' then
  372. exclude(initmoduleswitches,cs_local_browser)
  373. else
  374. {$ifdef BrowserLog}
  375. browserlog.elements_to_list.insert(more);
  376. {$else}
  377. IllegalPara(opt);
  378. {$endif}
  379. end;
  380. 'B' : do_build:=not UnSetBool(more,0);
  381. 'C' : begin
  382. j := 1;
  383. while j <= length(more) Do
  384. Begin
  385. case more[j] of
  386. 'a' : Message2(option_obsolete_switch_use_new,'-Ca','-Or');
  387. 'c' :
  388. begin
  389. if not SetAktProcCall(upper(copy(more,j+1,length(more)-j)),true) then
  390. IllegalPara(opt);
  391. break;
  392. end;
  393. 'h' :
  394. begin
  395. val(copy(more,j+1,length(more)-j),heapsize,code);
  396. if (code<>0) or (heapsize>=67107840) or (heapsize<1024) then
  397. IllegalPara(opt);
  398. break;
  399. end;
  400. 'i' :
  401. If UnsetBool(More, j) then
  402. exclude(initlocalswitches,cs_check_io)
  403. else
  404. include(initlocalswitches,cs_check_io);
  405. 'n' :
  406. If UnsetBool(More, j) then
  407. exclude(initglobalswitches,cs_link_extern)
  408. Else
  409. include(initglobalswitches,cs_link_extern);
  410. 'o' :
  411. If UnsetBool(More, j) then
  412. exclude(initlocalswitches,cs_check_overflow)
  413. Else
  414. include(initlocalswitches,cs_check_overflow);
  415. 'r' :
  416. If UnsetBool(More, j) then
  417. exclude(initlocalswitches,cs_check_range)
  418. Else
  419. include(initlocalswitches,cs_check_range);
  420. 'R' :
  421. If UnsetBool(More, j) then
  422. begin
  423. exclude(initlocalswitches,cs_check_range);
  424. exclude(initlocalswitches,cs_check_object);
  425. end
  426. Else
  427. begin
  428. include(initlocalswitches,cs_check_range);
  429. include(initlocalswitches,cs_check_object);
  430. end;
  431. 's' :
  432. begin
  433. val(copy(more,j+1,length(more)-j),stacksize,code);
  434. if (code<>0) or (stacksize>=67107840) or (stacksize<1024) then
  435. IllegalPara(opt);
  436. break;
  437. end;
  438. 't' :
  439. If UnsetBool(More, j) then
  440. exclude(initlocalswitches,cs_check_stack)
  441. Else
  442. include(initlocalswitches,cs_check_stack);
  443. 'D' :
  444. If UnsetBool(More, j) then
  445. exclude(initmoduleswitches,cs_create_dynamic)
  446. Else
  447. include(initmoduleswitches,cs_create_dynamic);
  448. 'X' :
  449. If UnsetBool(More, j) then
  450. exclude(initmoduleswitches,cs_create_smart)
  451. Else
  452. include(initmoduleswitches,cs_create_smart);
  453. else
  454. IllegalPara(opt);
  455. end;
  456. inc(j);
  457. end;
  458. end;
  459. 'd' : def_symbol(more);
  460. 'D' : begin
  461. include(initglobalswitches,cs_link_deffile);
  462. for j:=1 to length(more) do
  463. case more[j] of
  464. 'd' : begin
  465. description:=Copy(more,j+1,255);
  466. break;
  467. end;
  468. 'v' : begin
  469. dllversion:=Copy(more,j+1,255);
  470. l:=pos('.',dllversion);
  471. dllminor:=0;
  472. error:=0;
  473. if l>0 then
  474. begin
  475. valint(copy(dllversion,l+1,255),minor,error);
  476. if (error=0) and
  477. (minor>=0) and (minor<=$ffff) then
  478. dllminor:=minor
  479. else if error=0 then
  480. error:=1;
  481. end;
  482. if l=0 then l:=256;
  483. dllmajor:=1;
  484. if error=0 then
  485. valint(copy(dllversion,1,l-1),major,error);
  486. if (error=0) and (major>=0) and (major<=$ffff) then
  487. dllmajor:=major
  488. else if error=0 then
  489. error:=1;
  490. if error<>0 then
  491. Message1(scan_w_wrong_version_ignored,dllversion);
  492. break;
  493. end;
  494. 'w' : usewindowapi:=true;
  495. '-' : begin
  496. exclude(initglobalswitches,cs_link_deffile);
  497. usewindowapi:=false;
  498. end;
  499. else
  500. IllegalPara(opt);
  501. end;
  502. end;
  503. 'e' : exepath:=FixPath(More,true);
  504. { Just used by RHIDE }
  505. 'E' : if UnsetBool(More, 0) then
  506. exclude(initglobalswitches,cs_link_extern)
  507. else
  508. include(initglobalswitches,cs_link_extern);
  509. 'F' : begin
  510. c:=more[1];
  511. Delete(more,1,1);
  512. DefaultReplacements(More);
  513. case c of
  514. 'D' : utilsdirectory:=FixPath(More,true);
  515. 'e' : SetRedirectFile(More);
  516. 'E' : OutputExeDir:=FixPath(More,true);
  517. 'i' : if ispara then
  518. ParaIncludePath.AddPath(More,false)
  519. else
  520. includesearchpath.AddPath(More,true);
  521. 'g' : Message2(option_obsolete_switch_use_new,'-Fg','-Fl');
  522. 'l' : if ispara then
  523. ParaLibraryPath.AddPath(More,false)
  524. else
  525. LibrarySearchPath.AddPath(More,true);
  526. 'L' : if More<>'' then
  527. ParaDynamicLinker:=More
  528. else
  529. IllegalPara(opt);
  530. 'o' : if ispara then
  531. ParaObjectPath.AddPath(More,false)
  532. else
  533. ObjectSearchPath.AddPath(More,true);
  534. 'r' : Msgfilename:=More;
  535. 'u' : if ispara then
  536. ParaUnitPath.AddPath(More,false)
  537. else
  538. unitsearchpath.AddPath(More,true);
  539. 'U' : OutputUnitDir:=FixPath(More,true);
  540. else
  541. IllegalPara(opt);
  542. end;
  543. end;
  544. 'g' : begin
  545. if UnsetBool(More, 0) then
  546. begin
  547. exclude(initmoduleswitches,cs_debuginfo);
  548. exclude(initglobalswitches,cs_gdb_dbx);
  549. exclude(initglobalswitches,cs_gdb_gsym);
  550. exclude(initglobalswitches,cs_gdb_heaptrc);
  551. exclude(initglobalswitches,cs_gdb_lineinfo);
  552. exclude(initglobalswitches,cs_checkpointer);
  553. end
  554. else
  555. begin
  556. {$ifdef GDB}
  557. include(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' : if UnsetBool(More, j) then
  563. exclude(initglobalswitches,cs_gdb_dbx)
  564. else
  565. include(initglobalswitches,cs_gdb_dbx);
  566. 'g' : if UnsetBool(More, j) then
  567. exclude(initglobalswitches,cs_gdb_gsym)
  568. else
  569. include(initglobalswitches,cs_gdb_gsym);
  570. 'h' : if UnsetBool(More, j) then
  571. exclude(initglobalswitches,cs_gdb_heaptrc)
  572. else
  573. include(initglobalswitches,cs_gdb_heaptrc);
  574. 'l' : if UnsetBool(More, j) then
  575. exclude(initglobalswitches,cs_gdb_lineinfo)
  576. else
  577. include(initglobalswitches,cs_gdb_lineinfo);
  578. 'c' : if UnsetBool(More, j) then
  579. exclude(initglobalswitches,cs_checkpointer)
  580. else
  581. include(initglobalswitches,cs_checkpointer);
  582. else
  583. IllegalPara(opt);
  584. end;
  585. {$else GDB}
  586. Message(option_no_debug_support);
  587. Message(option_no_debug_support_recompile_fpc);
  588. {$endif GDB}
  589. end;
  590. end;
  591. 'h' : begin
  592. NoPressEnter:=true;
  593. WriteHelpPages;
  594. end;
  595. 'i' : if More='' then
  596. WriteInfo
  597. else
  598. QuickInfo:=QuickInfo+More;
  599. 'I' : if ispara then
  600. ParaIncludePath.AddPath(More,false)
  601. else
  602. includesearchpath.AddPath(More,false);
  603. 'k' : if more<>'' then
  604. ParaLinkOptions:=ParaLinkOptions+' '+More
  605. else
  606. IllegalPara(opt);
  607. 'l' : DoWriteLogo:=not UnSetBool(more,0);
  608. 'm' : parapreprocess:=not UnSetBool(more,0);
  609. 'n' : if More='' then
  610. begin
  611. read_configfile:=false;
  612. disable_configfile:=true;
  613. end
  614. else
  615. IllegalPara(opt);
  616. 'o' : if More<>'' then
  617. Fsplit(More,d,OutputFile,e)
  618. else
  619. IllegalPara(opt);
  620. 'p' : begin
  621. if UnsetBool(More, 0) then
  622. begin
  623. initmoduleswitches:=initmoduleswitches-[cs_profile];
  624. undef_symbol('FPC_PROFILE');
  625. end
  626. else
  627. if Length(More)=0 then
  628. IllegalPara(opt)
  629. else
  630. case more[1] of
  631. 'g' : if UnsetBool(more, 1) then
  632. begin
  633. exclude(initmoduleswitches,cs_profile);
  634. undef_symbol('FPC_PROFILE');
  635. end
  636. else
  637. begin
  638. include(initmoduleswitches,cs_profile);
  639. def_symbol('FPC_PROFILE');
  640. end;
  641. else
  642. IllegalPara(opt);
  643. end;
  644. end;
  645. {$ifdef Unix}
  646. 'P' : if UnsetBool(More, 0) then
  647. exclude(initglobalswitches,cs_asm_pipe)
  648. else
  649. include(initglobalswitches,cs_asm_pipe);
  650. {$endif Unix}
  651. 's' :
  652. begin
  653. if UnsetBool(More, 0) then
  654. begin
  655. initglobalswitches:=initglobalswitches-[cs_asm_extern,cs_link_extern];
  656. if more<>'' then
  657. IllegalPara(opt);
  658. end
  659. else
  660. begin
  661. initglobalswitches:=initglobalswitches+[cs_asm_extern,cs_link_extern];
  662. if more='h' then
  663. initglobalswitches:=initglobalswitches-[cs_link_on_target]
  664. else if more='t' then
  665. initglobalswitches:=initglobalswitches+[cs_link_on_target]
  666. else if more<>'' then
  667. IllegalPara(opt);
  668. end;
  669. end;
  670. 'S' : begin
  671. if more[1]='I' then
  672. begin
  673. if upper(more)='ICOM' then
  674. initinterfacetype:=it_interfacecom
  675. else if upper(more)='ICORBA' then
  676. initinterfacetype:=it_interfacecorba
  677. else
  678. IllegalPara(opt);
  679. end
  680. else
  681. for j:=1 to length(more) do
  682. case more[j] of
  683. '2' : SetCompileMode('OBJFPC',true);
  684. 'a' : include(initlocalswitches,cs_do_assertion);
  685. 'c' : include(initmoduleswitches,cs_support_c_operators);
  686. 'd' : SetCompileMode('DELPHI',true);
  687. 'e' : begin
  688. SetErrorFlags(copy(more,j+1,length(more)));
  689. break;
  690. end;
  691. 'g' : include(initmoduleswitches,cs_support_goto);
  692. 'h' : include(initlocalswitches,cs_ansistrings);
  693. 'i' : include(initmoduleswitches,cs_support_inline);
  694. 'm' : include(initmoduleswitches,cs_support_macro);
  695. 'o' : SetCompileMode('TP',true);
  696. 'p' : SetCompileMode('GPC',true);
  697. 's' : include(initglobalswitches,cs_constructor_name);
  698. 't' : include(initmoduleswitches,cs_static_keyword);
  699. '-' : begin
  700. exclude(initglobalswitches,cs_constructor_name);
  701. initlocalswitches:=InitLocalswitches - [cs_do_assertion, cs_ansistrings];
  702. initmoduleswitches:=initmoduleswitches - [cs_support_c_operators, cs_support_goto,
  703. cs_support_inline, cs_support_macro,
  704. cs_static_keyword];
  705. end;
  706. else
  707. IllegalPara(opt);
  708. end;
  709. end;
  710. 'T' : begin
  711. more:=Upper(More);
  712. if not target_is_set then
  713. begin
  714. { remove old target define }
  715. TargetDefines(false);
  716. { Save assembler if set }
  717. if asm_is_set then
  718. forceasm:=target_asm.id;
  719. { load new target }
  720. if not(set_target_by_string(More)) then
  721. IllegalPara(opt);
  722. { also initialize assembler if not explicitly set }
  723. if asm_is_set then
  724. set_target_asm(forceasm);
  725. { set new define }
  726. TargetDefines(true);
  727. target_is_set:=true;
  728. end
  729. else
  730. if More<>upper(target_info.shortname) then
  731. Message1(option_target_is_already_set,target_info.shortname);
  732. end;
  733. 'u' : undef_symbol(upper(More));
  734. 'U' : begin
  735. for j:=1 to length(more) do
  736. case more[j] of
  737. {$ifdef UNITALIASES}
  738. 'a' : begin
  739. AddUnitAlias(Copy(More,j+1,255));
  740. break;
  741. end;
  742. {$endif UNITALIASES}
  743. 'n' : exclude(initglobalswitches,cs_check_unit_name);
  744. 'p' : begin
  745. Message2(option_obsolete_switch_use_new,'-Up','-Fu');
  746. break;
  747. end;
  748. 'r' : do_release:=true;
  749. 's' : include(initmoduleswitches,cs_compilesystem);
  750. '-' : begin
  751. exclude(initmoduleswitches,cs_compilesystem);
  752. exclude(initglobalswitches,cs_check_unit_name);
  753. end;
  754. else
  755. IllegalPara(opt);
  756. end;
  757. end;
  758. 'v' : if not setverbosity(More) then
  759. IllegalPara(opt);
  760. 'W' : begin
  761. j:=0;
  762. while j<length(More) do
  763. begin
  764. inc(j);
  765. case More[j] of
  766. 'B': begin
  767. { -WB200000 means set trefered base address
  768. to $200000, but does not change relocsection boolean
  769. this way we can create both relocatble and
  770. non relocatable DLL at a specific base address PM }
  771. if (length(More)>j) then
  772. begin
  773. if DLLImageBase=nil then
  774. DLLImageBase:=StringDup(Copy(More,j+1,255));
  775. end
  776. else
  777. begin
  778. RelocSection:=true;
  779. RelocSectionSetExplicitly:=true;
  780. end;
  781. break;
  782. end;
  783. 'C': if UnsetBool(More, j) then
  784. apptype:=app_gui
  785. else
  786. apptype:=app_cui;
  787. 'D': ForceDeffileForExport:=not UnsetBool(More, j);
  788. 'F': apptype:=app_fs;
  789. 'G': if UnsetBool(More, j) then
  790. apptype:=app_cui
  791. else
  792. apptype:=app_gui;
  793. 'N': begin
  794. RelocSection:=UnsetBool(More,j);
  795. RelocSectionSetExplicitly:=true;
  796. end;
  797. 'R': begin
  798. { support -WR+ / -WR- as synonims to -WR / -WN }
  799. RelocSection:=not UnsetBool(More,j);
  800. RelocSectionSetExplicitly:=true;
  801. end;
  802. else
  803. IllegalPara(opt);
  804. end;
  805. end; {of while}
  806. end;
  807. 'X' : begin
  808. for j:=1 to length(More) do
  809. case More[j] of
  810. 'i' : include(initglobalswitches,cs_link_internal);
  811. 'm' : include(initglobalswitches,cs_link_map);
  812. 's' : include(initglobalswitches,cs_link_strip);
  813. 't' : include(initglobalswitches,cs_link_staticflag);
  814. 'D' : begin
  815. def_symbol('FPC_LINK_DYNAMIC');
  816. undef_symbol('FPC_LINK_SMART');
  817. undef_symbol('FPC_LINK_STATIC');
  818. exclude(initglobalswitches,cs_link_static);
  819. exclude(initglobalswitches,cs_link_smart);
  820. include(initglobalswitches,cs_link_shared);
  821. LinkTypeSetExplicitly:=true;
  822. end;
  823. 'S' : begin
  824. def_symbol('FPC_LINK_STATIC');
  825. undef_symbol('FPC_LINK_SMART');
  826. undef_symbol('FPC_LINK_DYNAMIC');
  827. include(initglobalswitches,cs_link_static);
  828. exclude(initglobalswitches,cs_link_smart);
  829. exclude(initglobalswitches,cs_link_shared);
  830. LinkTypeSetExplicitly:=true;
  831. end;
  832. 'X' : begin
  833. def_symbol('FPC_LINK_SMART');
  834. undef_symbol('FPC_LINK_STATIC');
  835. undef_symbol('FPC_LINK_DYNAMIC');
  836. exclude(initglobalswitches,cs_link_static);
  837. include(initglobalswitches,cs_link_smart);
  838. exclude(initglobalswitches,cs_link_shared);
  839. LinkTypeSetExplicitly:=true;
  840. end;
  841. '-' : begin
  842. exclude(initglobalswitches,cs_link_staticflag);
  843. exclude(initglobalswitches,cs_link_strip);
  844. exclude(initglobalswitches,cs_link_map);
  845. set_default_link_type;
  846. end;
  847. else
  848. IllegalPara(opt);
  849. end;
  850. end;
  851. { give processor specific options a chance }
  852. else
  853. interpret_proc_specific_options(opt);
  854. end;
  855. end;
  856. '@' : begin
  857. Message(option_no_nested_response_file);
  858. StopOptions;
  859. end;
  860. else
  861. begin
  862. if (length(param_file)<>0) then
  863. Message(option_only_one_source_support);
  864. param_file:=opt;
  865. end;
  866. end;
  867. end;
  868. procedure Toption.Interpret_file(const filename : string);
  869. procedure RemoveSep(var fn:string);
  870. var
  871. i : longint;
  872. begin
  873. i:=0;
  874. while (i<length(fn)) and (fn[i+1] in [',',' ',#9]) do
  875. inc(i);
  876. Delete(fn,1,i);
  877. i:=length(fn);
  878. while (i>0) and (fn[i] in [',',' ',#9]) do
  879. dec(i);
  880. fn:=copy(fn,1,i);
  881. end;
  882. function GetName(var fn:string):string;
  883. var
  884. i : longint;
  885. begin
  886. i:=0;
  887. while (i<length(fn)) and (fn[i+1] in ['a'..'z','A'..'Z','0'..'9','_','-']) do
  888. inc(i);
  889. GetName:=Copy(fn,1,i);
  890. Delete(fn,1,i);
  891. end;
  892. const
  893. maxlevel=16;
  894. var
  895. f : text;
  896. s,
  897. opts : string;
  898. skip : array[0..maxlevel-1] of boolean;
  899. level : longint;
  900. option_read : boolean;
  901. begin
  902. { avoid infinite loop }
  903. Inc(FileLevel);
  904. Option_read:=false;
  905. If FileLevel>MaxLevel then
  906. Message(option_too_many_cfg_files);
  907. { open file }
  908. Message1(option_using_file,filename);
  909. assign(f,filename);
  910. {$I-}
  911. reset(f);
  912. {$I+}
  913. if ioresult<>0 then
  914. begin
  915. Message1(option_unable_open_file,filename);
  916. exit;
  917. end;
  918. fillchar(skip,sizeof(skip),0);
  919. level:=0;
  920. while not eof(f) do
  921. begin
  922. readln(f,opts);
  923. RemoveSep(opts);
  924. if (opts<>'') and (opts[1]<>';') then
  925. begin
  926. if opts[1]='#' then
  927. begin
  928. Delete(opts,1,1);
  929. s:=upper(GetName(opts));
  930. if (s='SECTION') then
  931. begin
  932. RemoveSep(opts);
  933. s:=upper(GetName(opts));
  934. if level=0 then
  935. skip[level]:=not (check_symbol(s) or (s='COMMON'));
  936. end
  937. else
  938. if (s='IFDEF') then
  939. begin
  940. RemoveSep(opts);
  941. if Level>=maxlevel then
  942. begin
  943. Message(option_too_many_ifdef);
  944. stopOptions;
  945. end;
  946. inc(Level);
  947. skip[level]:=(skip[level-1] or (not check_symbol(upper(GetName(opts)))));
  948. end
  949. else
  950. if (s='IFNDEF') then
  951. begin
  952. RemoveSep(opts);
  953. if Level>=maxlevel then
  954. begin
  955. Message(option_too_many_ifdef);
  956. stopOptions;
  957. end;
  958. inc(Level);
  959. skip[level]:=(skip[level-1] or (check_symbol(upper(GetName(opts)))));
  960. end
  961. else
  962. if (s='ELSE') then
  963. skip[level]:=skip[level-1] or (not skip[level])
  964. else
  965. if (s='ENDIF') then
  966. begin
  967. skip[level]:=false;
  968. if Level=0 then
  969. begin
  970. Message(option_too_many_endif);
  971. stopOptions;
  972. end;
  973. dec(level);
  974. end
  975. else
  976. if (not skip[level]) then
  977. begin
  978. if (s='DEFINE') then
  979. begin
  980. RemoveSep(opts);
  981. def_symbol(upper(GetName(opts)));
  982. end
  983. else
  984. if (s='UNDEF') then
  985. begin
  986. RemoveSep(opts);
  987. undef_symbol(upper(GetName(opts)));
  988. end
  989. else
  990. if (s='WRITE') then
  991. begin
  992. Delete(opts,1,1);
  993. WriteLn(opts);
  994. end
  995. else
  996. if (s='INCLUDE') then
  997. begin
  998. Delete(opts,1,1);
  999. Interpret_file(opts);
  1000. end;
  1001. end;
  1002. end
  1003. else
  1004. begin
  1005. if (opts[1]='-') or (opts[1]='@') then
  1006. begin
  1007. if (not skip[level]) then
  1008. interpret_option(opts,false);
  1009. Option_read:=true;
  1010. end
  1011. else
  1012. Message1(option_illegal_para,opts);
  1013. end;
  1014. end;
  1015. end;
  1016. if Level>0 then
  1017. Message(option_too_less_endif);
  1018. if Not Option_read then
  1019. Message1(option_no_option_found,filename);
  1020. Close(f);
  1021. Dec(FileLevel);
  1022. end;
  1023. procedure Toption.Interpret_envvar(const envname : string);
  1024. var
  1025. argstart,
  1026. env,
  1027. pc : pchar;
  1028. arglen : longint;
  1029. quote : set of char;
  1030. hs : string;
  1031. begin
  1032. Message1(option_using_env,envname);
  1033. env:=GetEnvPChar(envname);
  1034. pc:=env;
  1035. if assigned(pc) then
  1036. begin
  1037. repeat
  1038. { skip leading spaces }
  1039. while pc^ in [' ',#9,#13] do
  1040. inc(pc);
  1041. case pc^ of
  1042. #0 :
  1043. break;
  1044. '"' :
  1045. begin
  1046. quote:=['"'];
  1047. inc(pc);
  1048. end;
  1049. '''' :
  1050. begin
  1051. quote:=[''''];
  1052. inc(pc);
  1053. end;
  1054. else
  1055. quote:=[' ',#9,#13];
  1056. end;
  1057. { scan until the end of the argument }
  1058. argstart:=pc;
  1059. while (pc^<>#0) and not(pc^ in quote) do
  1060. inc(pc);
  1061. { create argument }
  1062. arglen:=pc-argstart;
  1063. hs[0]:=chr(arglen);
  1064. move(argstart^,hs[1],arglen);
  1065. interpret_option(hs,true);
  1066. { skip quote }
  1067. if pc^ in quote then
  1068. inc(pc);
  1069. until false;
  1070. end
  1071. else
  1072. Message1(option_no_option_found,'(env) '+envname);
  1073. FreeEnvPChar(env);
  1074. end;
  1075. procedure toption.read_parameters;
  1076. var
  1077. opts : string;
  1078. paramindex : longint;
  1079. begin
  1080. paramindex:=0;
  1081. while paramindex<paramcount do
  1082. begin
  1083. inc(paramindex);
  1084. opts:=system.paramstr(paramindex);
  1085. case opts[1] of
  1086. '@' :
  1087. if not firstpass then
  1088. begin
  1089. Delete(opts,1,1);
  1090. Message1(option_reading_further_from,opts);
  1091. interpret_file(opts);
  1092. end;
  1093. '!' :
  1094. if not firstpass then
  1095. begin
  1096. Delete(opts,1,1);
  1097. Message1(option_reading_further_from,'(env) '+opts);
  1098. interpret_envvar(opts);
  1099. end;
  1100. else
  1101. interpret_option(opts,true);
  1102. end;
  1103. end;
  1104. end;
  1105. procedure toption.parsecmd(cmd:string);
  1106. var
  1107. i,ps : longint;
  1108. opts : string;
  1109. begin
  1110. while (cmd<>'') do
  1111. begin
  1112. while cmd[1]=' ' do
  1113. delete(cmd,1,1);
  1114. i:=pos(' ',cmd);
  1115. if i=0 then
  1116. i:=256;
  1117. opts:=Copy(cmd,1,i-1);
  1118. Delete(cmd,1,i);
  1119. case opts[1] of
  1120. '@' :
  1121. if not firstpass then
  1122. begin
  1123. Delete(opts,1,1);
  1124. Message1(option_reading_further_from,opts);
  1125. interpret_file(opts);
  1126. end;
  1127. '!' :
  1128. if not firstpass then
  1129. begin
  1130. Delete(opts,1,1);
  1131. Message1(option_reading_further_from,'(env) '+opts);
  1132. interpret_envvar(opts);
  1133. end;
  1134. '"' :
  1135. begin
  1136. Delete(opts,1,1);
  1137. ps:=pos('"',cmd);
  1138. if (i<>256) and (ps>0) then
  1139. begin
  1140. opts:=opts + ' '+ copy(cmd,1,ps-1);
  1141. cmd:=copy(cmd,ps+1,255);
  1142. end;
  1143. interpret_option(opts,true);
  1144. end;
  1145. else
  1146. interpret_option(opts,true);
  1147. end;
  1148. end;
  1149. end;
  1150. procedure toption.writequickinfo;
  1151. var
  1152. s : string;
  1153. i : longint;
  1154. procedure addinfo(const hs:string);
  1155. begin
  1156. if s<>'' then
  1157. s:=s+' '+hs
  1158. else
  1159. s:=hs;
  1160. end;
  1161. begin
  1162. s:='';
  1163. i:=0;
  1164. while (i<length(quickinfo)) do
  1165. begin
  1166. inc(i);
  1167. case quickinfo[i] of
  1168. 'S' :
  1169. begin
  1170. inc(i);
  1171. case quickinfo[i] of
  1172. 'O' :
  1173. addinfo(lower(source_info.shortname));
  1174. {$ifdef Delphi}
  1175. 'P' :
  1176. addinfo('i386');
  1177. {$else Delphi}
  1178. 'P' :
  1179. addinfo(source_cpu_string);
  1180. {$endif Delphi}
  1181. else
  1182. IllegalPara('-iS'+QuickInfo);
  1183. end;
  1184. end;
  1185. 'T' :
  1186. begin
  1187. inc(i);
  1188. case quickinfo[i] of
  1189. 'O' :
  1190. addinfo(lower(target_info.shortname));
  1191. 'P' :
  1192. AddInfo(target_cpu_string);
  1193. else
  1194. IllegalPara('-iT'+QuickInfo);
  1195. end;
  1196. end;
  1197. 'V' :
  1198. AddInfo(version_string);
  1199. 'D' :
  1200. AddInfo(date_string);
  1201. '_' :
  1202. ;
  1203. else
  1204. IllegalPara('-i'+QuickInfo);
  1205. end;
  1206. end;
  1207. if s<>'' then
  1208. begin
  1209. writeln(s);
  1210. stopoptions;
  1211. end;
  1212. end;
  1213. procedure TOption.TargetDefines(def:boolean);
  1214. var
  1215. s : string;
  1216. i : integer;
  1217. begin
  1218. if def then
  1219. def_symbol(upper(target_info.shortname))
  1220. else
  1221. undef_symbol(upper(target_info.shortname));
  1222. s:=target_info.extradefines;
  1223. while (s<>'') do
  1224. begin
  1225. i:=pos(';',s);
  1226. if i=0 then
  1227. i:=length(s)+1;
  1228. if def then
  1229. def_symbol(Copy(s,1,i-1))
  1230. else
  1231. undef_symbol(Copy(s,1,i-1));
  1232. delete(s,1,i);
  1233. end;
  1234. end;
  1235. constructor TOption.create;
  1236. begin
  1237. DoWriteLogo:=false;
  1238. NoPressEnter:=false;
  1239. FirstPass:=false;
  1240. FileLevel:=0;
  1241. Quickinfo:='';
  1242. ParaIncludePath:=TSearchPathList.Create;
  1243. ParaObjectPath:=TSearchPathList.Create;
  1244. ParaUnitPath:=TSearchPathList.Create;
  1245. ParaLibraryPath:=TSearchPathList.Create;
  1246. FillChar(ParaAlignment,sizeof(ParaAlignment),0);
  1247. end;
  1248. destructor TOption.destroy;
  1249. begin
  1250. ParaIncludePath.Free;
  1251. ParaObjectPath.Free;
  1252. ParaUnitPath.Free;
  1253. ParaLibraryPath.Free;
  1254. end;
  1255. {****************************************************************************
  1256. Callable Routines
  1257. ****************************************************************************}
  1258. procedure read_arguments(cmd:string);
  1259. var
  1260. configpath : pathstr;
  1261. begin
  1262. option:=coption.create;
  1263. disable_configfile:=false;
  1264. { default defines }
  1265. def_symbol(upper(target_info.shortname));
  1266. def_symbol('FPC');
  1267. def_symbol('VER'+version_nr);
  1268. def_symbol('VER'+version_nr+'_'+release_nr);
  1269. def_symbol('VER'+version_nr+'_'+release_nr+'_'+patch_nr);
  1270. {$ifdef newcg}
  1271. def_symbol('WITHNEWCG');
  1272. {$endif}
  1273. { Temporary defines, until things settle down }
  1274. def_symbol('HASWIDECHAR');
  1275. def_symbol('HASWIDESTRING');
  1276. def_symbol('HASOUT');
  1277. def_symbol('HASINTF');
  1278. def_symbol('HASVARIANT');
  1279. def_symbol('INTERNSETLENGTH');
  1280. def_symbol('INTERNLENGTH');
  1281. def_symbol('INT64FUNCRESOK');
  1282. def_symbol('HAS_ADDR_STACK_ON_STACK');
  1283. def_symbol('NOBOUNDCHECK');
  1284. def_symbol('HASCOMPILERPROC');
  1285. def_symbol('VALUEGETMEM');
  1286. def_symbol('VALUEFREEMEM');
  1287. def_symbol('HASCURRENCY');
  1288. { some stuff for TP compatibility }
  1289. case target_info.cpu of
  1290. cpu_i386:
  1291. begin
  1292. def_symbol('CPU86');
  1293. def_symbol('CPU87');
  1294. def_symbol('CPUI386');
  1295. end;
  1296. cpu_m68k:
  1297. begin
  1298. def_symbol('CPU68');
  1299. def_symbol('CPU68K');
  1300. end;
  1301. cpu_alpha:
  1302. begin
  1303. def_symbol('CPUALPHA');
  1304. end;
  1305. cpu_powerpc:
  1306. begin
  1307. def_symbol('CPUPOWERPC');
  1308. end;
  1309. cpu_sparc:
  1310. begin
  1311. def_symbol('CPUSPARC');
  1312. end;
  1313. cpu_vm:
  1314. begin
  1315. def_symbol('CPUVIS');
  1316. end;
  1317. else
  1318. internalerror(1295969);
  1319. end;
  1320. { get default messagefile }
  1321. {$ifdef Delphi}
  1322. msgfilename:=dmisc.getenv('PPC_ERROR_FILE');
  1323. {$else Delphi}
  1324. msgfilename:=dos.getenv('PPC_ERROR_FILE');
  1325. {$endif Delphi}
  1326. { default configfile }
  1327. if (cmd<>'') and (cmd[1]='[') then
  1328. begin
  1329. ppccfg:=Copy(cmd,2,pos(']',cmd)-2);
  1330. Delete(cmd,1,pos(']',cmd));
  1331. end
  1332. else
  1333. begin
  1334. ppcaltcfg:='ppc386.cfg';
  1335. ppccfg:='fpc.cfg';
  1336. end;
  1337. { Order to read configuration file :
  1338. try reading ppc386.cfg in :
  1339. 1 - current dir
  1340. 2 - configpath
  1341. 3 - compiler path
  1342. else try reading fpc.cfg in :
  1343. 1 - current dir
  1344. 2 - configpath
  1345. 3 - compiler path
  1346. }
  1347. {$ifdef Delphi}
  1348. configpath:=FixPath(dmisc.getenv('PPC_CONFIG_PATH'),false);
  1349. {$else Delphi}
  1350. configpath:=FixPath(dos.getenv('PPC_CONFIG_PATH'),false);
  1351. {$endif Delphi}
  1352. {$ifdef Unix}
  1353. if configpath='' then
  1354. configpath:='/etc/';
  1355. {$endif}
  1356. if ppccfg<>'' then
  1357. begin
  1358. read_configfile:=true;
  1359. if not FileExists(ppcaltcfg) then
  1360. begin
  1361. {$ifdef Unix}
  1362. if (dos.getenv('HOME')<>'') and FileExists(FixPath(dos.getenv('HOME'),false)+'.'+ppcaltcfg) then
  1363. ppccfg:=FixPath(dos.getenv('HOME'),false)+'.'+ppcaltcfg
  1364. else
  1365. {$endif}
  1366. if FileExists(configpath+ppcaltcfg) then
  1367. ppccfg:=configpath+ppcaltcfg
  1368. else
  1369. {$ifndef Unix}
  1370. if FileExists(exepath+ppcaltcfg) then
  1371. ppccfg:=exepath+ppcaltcfg
  1372. else
  1373. {$endif}
  1374. read_configfile:=false;
  1375. end
  1376. else
  1377. ppccfg := ppcaltcfg; { file is found, then set it to ppccfg }
  1378. if not read_configfile then
  1379. begin
  1380. read_configfile := true;
  1381. if not FileExists(ppccfg) then
  1382. begin
  1383. {$ifdef Unix}
  1384. if (dos.getenv('HOME')<>'') and FileExists(FixPath(dos.getenv('HOME'),false)+'.'+ppccfg) then
  1385. ppccfg:=FixPath(dos.getenv('HOME'),false)+'.'+ppccfg
  1386. else
  1387. {$endif}
  1388. if FileExists(configpath+ppccfg) then
  1389. ppccfg:=configpath+ppccfg
  1390. else
  1391. {$ifndef Unix}
  1392. if FileExists(exepath+ppccfg) then
  1393. ppccfg:=exepath+ppccfg
  1394. else
  1395. {$endif}
  1396. read_configfile:=false;
  1397. end;
  1398. end
  1399. end
  1400. else
  1401. read_configfile := false;
  1402. { Read commandline and configfile }
  1403. target_is_set:=false;
  1404. asm_is_set:=false;
  1405. param_file:='';
  1406. if read_configfile then
  1407. begin
  1408. { read the parameters quick, only -i -v -T }
  1409. option.firstpass:=true;
  1410. if cmd<>'' then
  1411. option.parsecmd(cmd)
  1412. else
  1413. begin
  1414. option.read_parameters;
  1415. { Write only quickinfo }
  1416. if option.quickinfo<>'' then
  1417. option.writequickinfo;
  1418. end;
  1419. { Read the configfile }
  1420. option.firstpass:=false;
  1421. if read_configfile then
  1422. option.interpret_file(ppccfg);
  1423. end;
  1424. if cmd<>'' then
  1425. option.parsecmd(cmd)
  1426. else
  1427. begin
  1428. option.read_parameters;
  1429. { Write only quickinfo }
  1430. if option.quickinfo<>'' then
  1431. option.writequickinfo;
  1432. end;
  1433. { Write help pages }
  1434. if (cmd='') and (paramcount=0) then
  1435. Option.WriteHelpPages;
  1436. { Stop if errors in options }
  1437. if ErrorCount>0 then
  1438. StopOptions;
  1439. { Non-core target defines }
  1440. Option.TargetDefines(true);
  1441. { endian define }
  1442. case target_info.endian of
  1443. endian_little :
  1444. def_symbol('ENDIAN_LITTLE');
  1445. endian_big :
  1446. def_symbol('ENDIAN_BIG');
  1447. end;
  1448. {$ifdef m68k}
  1449. { Disable fpu emulation for linux and netbsd on m68k machines }
  1450. { FIXME: this overrides possible explicit command line emulation setting,
  1451. but this isn't supported yet anyhow PM }
  1452. if (target_info.target in [target_m68k_netbsd,target_m68k_linux]) then
  1453. exclude(initmoduleswitches,cs_fp_emulation)
  1454. else
  1455. def_symbol('M68K_FPU_EMULATED');
  1456. {$endif m68k}
  1457. { write logo if set }
  1458. if option.DoWriteLogo then
  1459. option.WriteLogo;
  1460. { Check file to compile }
  1461. if param_file='' then
  1462. begin
  1463. Message(option_no_source_found);
  1464. StopOptions;
  1465. end;
  1466. {$ifndef Unix}
  1467. param_file:=FixFileName(param_file);
  1468. {$endif}
  1469. fsplit(param_file,inputdir,inputfile,inputextension);
  1470. if inputextension='' then
  1471. begin
  1472. if FileExists(inputdir+inputfile+target_info.sourceext) then
  1473. inputextension:=target_info.sourceext
  1474. else
  1475. if FileExists(inputdir+inputfile+target_info.pasext) then
  1476. inputextension:=target_info.pasext;
  1477. end;
  1478. { Add paths specified with parameters to the searchpaths }
  1479. UnitSearchPath.AddList(option.ParaUnitPath,true);
  1480. ObjectSearchPath.AddList(option.ParaObjectPath,true);
  1481. IncludeSearchPath.AddList(option.ParaIncludePath,true);
  1482. LibrarySearchPath.AddList(option.ParaLibraryPath,true);
  1483. { add unit environment and exepath to the unit search path }
  1484. if inputdir<>'' then
  1485. Unitsearchpath.AddPath(inputdir,true);
  1486. if not disable_configfile then
  1487. {$ifdef Delphi}
  1488. UnitSearchPath.AddPath(dmisc.getenv(target_info.unit_env),false);
  1489. {$else}
  1490. UnitSearchPath.AddPath(dos.getenv(target_info.unit_env),false);
  1491. {$endif Delphi}
  1492. {$ifdef Unix}
  1493. fpcdir:=FixPath(getenv('FPCDIR'),false);
  1494. if fpcdir='' then
  1495. begin
  1496. if PathExists('/usr/local/lib/fpc/'+version_string) then
  1497. fpcdir:='/usr/local/lib/fpc/'+version_string+'/'
  1498. else
  1499. fpcdir:='/usr/lib/fpc/'+version_string+'/';
  1500. end;
  1501. {$else}
  1502. fpcdir:=FixPath(getenv('FPCDIR'),false);
  1503. if fpcdir='' then
  1504. begin
  1505. fpcdir:=ExePath+'../';
  1506. if not(PathExists(fpcdir+'/units')) and
  1507. not(PathExists(fpcdir+'/rtl')) then
  1508. fpcdir:=fpcdir+'../';
  1509. end;
  1510. {$endif}
  1511. { first try development RTL, else use the default installation path }
  1512. if not disable_configfile then
  1513. begin
  1514. if PathExists(FpcDir+'rtl/'+lower(target_info.shortname)) then
  1515. UnitSearchPath.AddPath(FpcDir+'rtl/'+lower(target_info.shortname),false)
  1516. else
  1517. begin
  1518. UnitSearchPath.AddPath(FpcDir+'units/'+lower(target_info.shortname),false);
  1519. UnitSearchPath.AddPath(FpcDir+'units/'+lower(target_info.shortname)+'/rtl',false);
  1520. end;
  1521. end;
  1522. { Add exepath if the exe is not in the current dir, because that is always searched already }
  1523. if ExePath<>GetCurrentDir then
  1524. UnitSearchPath.AddPath(ExePath,false);
  1525. { Add unit dir to the object and library path }
  1526. objectsearchpath.AddList(unitsearchpath,false);
  1527. librarysearchpath.AddList(unitsearchpath,false);
  1528. { switch assembler if it's binary and we got -a on the cmdline }
  1529. if (cs_asm_leave in initglobalswitches) and
  1530. (target_asm.outputbinary) then
  1531. begin
  1532. Message(option_switch_bin_to_src_assembler);
  1533. set_target_asm(target_info.assemextern);
  1534. end;
  1535. if (target_asm.supported_target <> target_any) and
  1536. (target_asm.supported_target <> target_info.target) then
  1537. begin
  1538. Message2(option_incompatible_asm,target_asm.idtxt,target_info.name);
  1539. set_target_asm(target_info.assemextern);
  1540. Message1(option_asm_forced,target_asm.idtxt);
  1541. end;
  1542. { turn off stripping if compiling with debuginfo or profile }
  1543. if (cs_debuginfo in initmoduleswitches) or
  1544. (cs_profile in initmoduleswitches) then
  1545. exclude(initglobalswitches,cs_link_strip);
  1546. if not LinkTypeSetExplicitly then
  1547. set_default_link_type;
  1548. { Default alignment settings,
  1549. 1. load the defaults for the target
  1550. 2. override with generic optimizer setting (little size)
  1551. 3. override with the user specified -Oa }
  1552. UpdateAlignment(initalignment,target_info.alignment);
  1553. if (cs_littlesize in aktglobalswitches) then
  1554. begin
  1555. initalignment.procalign:=1;
  1556. initalignment.jumpalign:=1;
  1557. initalignment.loopalign:=1;
  1558. end;
  1559. UpdateAlignment(initalignment,option.paraalignment);
  1560. option.free;
  1561. Option:=nil;
  1562. end;
  1563. initialization
  1564. coption:=toption;
  1565. finalization
  1566. if assigned(option) then
  1567. option.free;
  1568. end.
  1569. {
  1570. $Log$
  1571. Revision 1.75 2002-07-01 18:46:24 peter
  1572. * internal linker
  1573. * reorganized aasm layer
  1574. Revision 1.74 2002/07/01 16:23:53 peter
  1575. * cg64 patch
  1576. * basics for currency
  1577. * asnode updates for class and interface (not finished)
  1578. Revision 1.73 2002/05/18 13:34:11 peter
  1579. * readded missing revisions
  1580. Revision 1.72 2002/05/16 19:46:41 carl
  1581. + defines.inc -> fpcdefs.inc to avoid conflicts if compiling by hand
  1582. + try to fix temp allocation (still in ifdef)
  1583. + generic constructor calls
  1584. + start of tassembler / tmodulebase class cleanup
  1585. Revision 1.70 2002/05/12 16:53:08 peter
  1586. * moved entry and exitcode to ncgutil and cgobj
  1587. * foreach gets extra argument for passing local data to the
  1588. iterator function
  1589. * -CR checks also class typecasts at runtime by changing them
  1590. into as
  1591. * fixed compiler to cycle with the -CR option
  1592. * fixed stabs with elf writer, finally the global variables can
  1593. be watched
  1594. * removed a lot of routines from cga unit and replaced them by
  1595. calls to cgobj
  1596. * u32bit-s32bit updates for and,or,xor nodes. When one element is
  1597. u32bit then the other is typecasted also to u32bit without giving
  1598. a rangecheck warning/error.
  1599. * fixed pascal calling method with reversing also the high tree in
  1600. the parast, detected by tcalcst3 test
  1601. Revision 1.69 2002/04/21 19:02:04 peter
  1602. * removed newn and disposen nodes, the code is now directly
  1603. inlined from pexpr
  1604. * -an option that will write the secondpass nodes to the .s file, this
  1605. requires EXTDEBUG define to actually write the info
  1606. * fixed various internal errors and crashes due recent code changes
  1607. Revision 1.68 2002/04/20 21:32:24 carl
  1608. + generic FPC_CHECKPOINTER
  1609. + first parameter offset in stack now portable
  1610. * rename some constants
  1611. + move some cpu stuff to other units
  1612. - remove unused constents
  1613. * fix stacksize for some targets
  1614. * fix generic size problems which depend now on EXTEND_SIZE constant
  1615. Revision 1.67 2002/04/07 10:22:35 carl
  1616. + CPU defines now depends on current target
  1617. Revision 1.66 2002/04/04 19:05:58 peter
  1618. * removed unused units
  1619. * use tlocation.size in cg.a_*loc*() routines
  1620. Revision 1.65 2002/04/04 18:39:45 carl
  1621. + added wdosx support (patch from Pavel)
  1622. }