options.pas 55 KB

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