options.pas 57 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819
  1. {
  2. $Id$
  3. Copyright (c) 1998-2000 by Florian Klaempfl and Peter Vreman
  4. Reads command line options and config files
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  16. ****************************************************************************
  17. }
  18. unit options;
  19. {$i defines.inc}
  20. interface
  21. uses
  22. globtype,globals,verbose,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. param_file : string; { file to compile specified on the commandline }
  79. {****************************************************************************
  80. Defines
  81. ****************************************************************************}
  82. procedure def_symbol(const s : string);
  83. begin
  84. if s='' then
  85. exit;
  86. initdefines.insert(upper(s));
  87. end;
  88. procedure undef_symbol(const s : string);
  89. begin
  90. if s='' then
  91. exit;
  92. InitDefines.Remove(s);
  93. end;
  94. function check_symbol(const s:string):boolean;
  95. begin
  96. check_symbol:=(initdefines.find(s)<>nil);
  97. end;
  98. procedure set_default_link_type;
  99. begin
  100. if (target_info.target=target_i386_win32) then
  101. begin
  102. def_symbol('FPC_LINK_SMART');
  103. undef_symbol('FPC_LINK_STATIC');
  104. undef_symbol('FPC_LINK_DYNAMIC');
  105. initglobalswitches:=initglobalswitches+[cs_link_smart];
  106. initglobalswitches:=initglobalswitches-[cs_link_shared,cs_link_static];
  107. end
  108. else
  109. begin
  110. undef_symbol('FPC_LINK_SMART');
  111. def_symbol('FPC_LINK_STATIC');
  112. undef_symbol('FPC_LINK_DYNAMIC');
  113. initglobalswitches:=initglobalswitches+[cs_link_static];
  114. initglobalswitches:=initglobalswitches-[cs_link_shared,cs_link_smart];
  115. end;
  116. end;
  117. {****************************************************************************
  118. Toption
  119. ****************************************************************************}
  120. procedure StopOptions;
  121. begin
  122. if assigned(Option) then
  123. begin
  124. Option.free;
  125. Option:=nil;
  126. end;
  127. DoneVerbose;
  128. Stop;
  129. end;
  130. procedure Toption.WriteLogo;
  131. var
  132. p : pchar;
  133. begin
  134. p:=MessagePchar(option_logo);
  135. while assigned(p) do
  136. Comment(V_Normal,GetMsgLine(p));
  137. end;
  138. procedure Toption.WriteInfo;
  139. var
  140. p : pchar;
  141. hs,hs1,s : string;
  142. target : ttarget;
  143. begin
  144. p:=MessagePchar(option_info);
  145. while assigned(p) do
  146. begin
  147. s:=GetMsgLine(p);
  148. { list OS Targets }
  149. if pos('$OSTARGETS',s)>0 then
  150. begin
  151. for target:=low(ttarget) to high(ttarget) do
  152. if assigned(targetinfos[target]) then
  153. begin
  154. hs:=s;
  155. hs1:=targetinfos[target]^.name;
  156. if tf_under_development in targetinfos[target]^.flags then
  157. hs1:=hs1+' (under development)';
  158. Replace(hs,'$OSTARGETS',hs1);
  159. Comment(V_Normal,hs);
  160. end;
  161. end
  162. else
  163. Comment(V_Normal,s);
  164. end;
  165. StopOptions;
  166. end;
  167. procedure Toption.WriteHelpPages;
  168. function PadEnd(s:string;i:longint):string;
  169. begin
  170. while (length(s)<i) do
  171. s:=s+' ';
  172. PadEnd:=s;
  173. end;
  174. var
  175. lastident,
  176. j,outline,
  177. ident,
  178. lines : longint;
  179. show : boolean;
  180. opt : string[32];
  181. input,
  182. s : string;
  183. p : pchar;
  184. begin
  185. WriteLogo;
  186. Lines:=4;
  187. Message1(option_usage,system.paramstr(0));
  188. lastident:=0;
  189. p:=MessagePChar(option_help_pages);
  190. while assigned(p) do
  191. begin
  192. { get a line and reset }
  193. s:=GetMsgLine(p);
  194. ident:=0;
  195. show:=false;
  196. { parse options }
  197. case s[1] of
  198. {$ifdef UNITALIASES}
  199. 'a',
  200. {$endif}
  201. {$ifdef EXTDEBUG}
  202. 'e',
  203. {$endif EXTDEBUG}
  204. {$ifdef i386}
  205. '3',
  206. {$endif}
  207. {$ifdef m68k}
  208. '6',
  209. {$endif}
  210. '*' : show:=true;
  211. end;
  212. if show then
  213. begin
  214. case s[2] of
  215. {$ifdef GDB}
  216. 'g',
  217. {$endif}
  218. {$ifdef Unix}
  219. 'L',
  220. {$endif}
  221. {$ifdef os2}
  222. 'O',
  223. {$endif}
  224. '*' : show:=true;
  225. else
  226. show:=false;
  227. end;
  228. end;
  229. { now we may show the message or not }
  230. if show then
  231. begin
  232. case s[3] of
  233. '0' : begin
  234. ident:=0;
  235. outline:=0;
  236. end;
  237. '1' : begin
  238. ident:=2;
  239. outline:=7;
  240. end;
  241. '2' : begin
  242. ident:=6;
  243. outline:=11;
  244. end;
  245. '3' : begin
  246. ident:=9;
  247. outline:=6;
  248. end;
  249. end;
  250. j:=pos('_',s);
  251. opt:=Copy(s,4,j-4);
  252. if opt='*' then
  253. opt:=''
  254. else
  255. if opt=' ' then
  256. opt:=PadEnd(opt,outline)
  257. else
  258. opt:=PadEnd('-'+opt,outline);
  259. if (ident=0) and (lastident<>0) then
  260. begin
  261. Comment(V_Normal,'');
  262. inc(Lines);
  263. end;
  264. { page full ? }
  265. if (lines >= page_size - 1) then
  266. begin
  267. if not NoPressEnter then
  268. begin
  269. Message(option_help_press_enter);
  270. readln(input);
  271. if upper(input)='Q' then
  272. StopOptions;
  273. end;
  274. lines:=0;
  275. end;
  276. Comment(V_Normal,PadEnd('',ident)+opt+Copy(s,j+1,255));
  277. LastIdent:=Ident;
  278. inc(Lines);
  279. end;
  280. end;
  281. StopOptions;
  282. end;
  283. procedure Toption.IllegalPara(const opt:string);
  284. begin
  285. Message1(option_illegal_para,opt);
  286. Message(option_help_pages_para);
  287. StopOptions;
  288. end;
  289. function Toption.Unsetbool(var Opts:string; Pos: Longint):boolean;
  290. { checks if the character after pos in Opts is a + or a - and returns resp.
  291. false or true. If it is another character (or none), it also returns false }
  292. begin
  293. UnsetBool := false;
  294. if Length(Opts)>Pos then
  295. begin
  296. inc(Pos);
  297. UnsetBool := Opts[Pos] = '-';
  298. if Opts[Pos] in ['-','+']then
  299. delete(Opts,Pos,1);
  300. end;
  301. end;
  302. procedure TOption.interpret_proc_specific_options(const opt:string);
  303. begin
  304. end;
  305. procedure TOption.interpret_option(const opt:string;ispara:boolean);
  306. var
  307. code : integer;
  308. c : char;
  309. more : string;
  310. major,minor : longint;
  311. error : integer;
  312. j,l : longint;
  313. d : DirStr;
  314. e : ExtStr;
  315. forceasm : tasm;
  316. begin
  317. if opt='' then
  318. exit;
  319. { only parse define,undef,target,verbosity and link options the firsttime }
  320. if firstpass and
  321. not((opt[1]='-') and (opt[2] in ['i','d','v','T','u','n','X'])) then
  322. exit;
  323. Message1(option_handling_option,opt);
  324. case opt[1] of
  325. '-' : begin
  326. more:=Copy(opt,3,255);
  327. case opt[2] of
  328. '!' : initlocalswitches:=initlocalswitches+[cs_ansistrings];
  329. '?' : WriteHelpPages;
  330. 'a' : begin
  331. initglobalswitches:=initglobalswitches+[cs_asm_leave];
  332. for j:=1 to length(more) do
  333. case more[j] of
  334. 'l' : include(initglobalswitches,cs_asm_source);
  335. 'r' : include(initglobalswitches,cs_asm_regalloc);
  336. 't' : include(initglobalswitches,cs_asm_tempalloc);
  337. '-' : initglobalswitches:=initglobalswitches -
  338. [cs_asm_leave, cs_asm_source,cs_asm_regalloc, cs_asm_tempalloc];
  339. else
  340. IllegalPara(opt);
  341. end;
  342. end;
  343. 'A' : begin
  344. if set_target_asm_by_string(More) then
  345. asm_is_set:=true
  346. else
  347. IllegalPara(opt);
  348. end;
  349. 'b' : begin
  350. if UnsetBool(More,0) then
  351. begin
  352. exclude(initmoduleswitches,cs_browser);
  353. exclude(initmoduleswitches,cs_local_browser);
  354. {$ifdef BrowserLog}
  355. exclude(initglobalswitches,cs_browser_log);
  356. {$endif}
  357. end
  358. else
  359. begin
  360. include(initmoduleswitches,cs_browser);
  361. {$ifdef BrowserLog}
  362. include(initglobalswitches,cs_browser_log);
  363. {$endif}
  364. end;
  365. if More<>'' then
  366. if (More='l') or (More='l+') then
  367. include(initmoduleswitches,cs_local_browser)
  368. else
  369. if More='l-' then
  370. exclude(initmoduleswitches,cs_local_browser)
  371. else
  372. {$ifdef BrowserLog}
  373. browserlog.elements_to_list.insert(more);
  374. {$else}
  375. IllegalPara(opt);
  376. {$endif}
  377. end;
  378. 'B' : do_build:=not UnSetBool(more,0);
  379. 'C' : begin
  380. j := 1;
  381. while j <= length(more) Do
  382. Begin
  383. case more[j] of
  384. 'a' : Message2(option_obsolete_switch_use_new,'-Ca','-Or');
  385. 'h' :
  386. begin
  387. val(copy(more,j+1,length(more)-j),heapsize,code);
  388. if (code<>0) or (heapsize>=67107840) or (heapsize<1024) then
  389. IllegalPara(opt);
  390. break;
  391. end;
  392. 'i' :
  393. If UnsetBool(More, j) then
  394. exclude(initlocalswitches,cs_check_io)
  395. else
  396. include(initlocalswitches,cs_check_io);
  397. 'n' :
  398. If UnsetBool(More, j) then
  399. exclude(initglobalswitches,cs_link_extern)
  400. Else
  401. include(initglobalswitches,cs_link_extern);
  402. 'o' :
  403. If UnsetBool(More, j) then
  404. exclude(initlocalswitches,cs_check_overflow)
  405. Else
  406. include(initlocalswitches,cs_check_overflow);
  407. 'r' :
  408. If UnsetBool(More, j) then
  409. exclude(initlocalswitches,cs_check_range)
  410. Else
  411. include(initlocalswitches,cs_check_range);
  412. 'R' :
  413. If UnsetBool(More, j) then
  414. exclude(initlocalswitches,cs_check_object_ext)
  415. Else
  416. include(initlocalswitches,cs_check_object_ext);
  417. 's' :
  418. begin
  419. val(copy(more,j+1,length(more)-j),stacksize,code);
  420. if (code<>0) or (stacksize>=67107840) or (stacksize<1024) then
  421. IllegalPara(opt);
  422. break;
  423. end;
  424. 't' :
  425. If UnsetBool(More, j) then
  426. exclude(initlocalswitches,cs_check_stack)
  427. Else
  428. include(initlocalswitches,cs_check_stack);
  429. 'D' :
  430. If UnsetBool(More, j) then
  431. exclude(initmoduleswitches,cs_create_dynamic)
  432. Else
  433. include(initmoduleswitches,cs_create_dynamic);
  434. 'X' :
  435. If UnsetBool(More, j) then
  436. exclude(initmoduleswitches,cs_create_smart)
  437. Else
  438. include(initmoduleswitches,cs_create_smart);
  439. else
  440. IllegalPara(opt);
  441. end;
  442. inc(j);
  443. end;
  444. end;
  445. 'd' : def_symbol(more);
  446. 'D' : begin
  447. include(initglobalswitches,cs_link_deffile);
  448. for j:=1 to length(more) do
  449. case more[j] of
  450. 'd' : begin
  451. description:=Copy(more,j+1,255);
  452. break;
  453. end;
  454. 'v' : begin
  455. dllversion:=Copy(more,j+1,255);
  456. l:=pos('.',dllversion);
  457. dllminor:=0;
  458. error:=0;
  459. if l>0 then
  460. begin
  461. valint(copy(dllversion,l+1,255),minor,error);
  462. if (error=0) and
  463. (minor>=0) and (minor<=$ffff) then
  464. dllminor:=minor
  465. else if error=0 then
  466. error:=1;
  467. end;
  468. if l=0 then l:=256;
  469. dllmajor:=1;
  470. if error=0 then
  471. valint(copy(dllversion,1,l-1),major,error);
  472. if (error=0) and (major>=0) and (major<=$ffff) then
  473. dllmajor:=major
  474. else if error=0 then
  475. error:=1;
  476. if error<>0 then
  477. Message1(scan_w_wrong_version_ignored,dllversion);
  478. break;
  479. end;
  480. 'w' : usewindowapi:=true;
  481. '-' : begin
  482. exclude(initglobalswitches,cs_link_deffile);
  483. usewindowapi:=false;
  484. end;
  485. else
  486. IllegalPara(opt);
  487. end;
  488. end;
  489. 'e' : exepath:=FixPath(More,true);
  490. { Just used by RHIDE }
  491. 'E' : if UnsetBool(More, 0) then
  492. exclude(initglobalswitches,cs_link_extern)
  493. else
  494. include(initglobalswitches,cs_link_extern);
  495. 'F' : begin
  496. c:=more[1];
  497. Delete(more,1,1);
  498. DefaultReplacements(More);
  499. case c of
  500. 'D' : utilsdirectory:=FixPath(More,true);
  501. 'e' : SetRedirectFile(More);
  502. 'E' : OutputExeDir:=FixPath(More,true);
  503. 'i' : if ispara then
  504. ParaIncludePath.AddPath(More,false)
  505. else
  506. includesearchpath.AddPath(More,true);
  507. 'g' : Message2(option_obsolete_switch_use_new,'-Fg','-Fl');
  508. 'l' : if ispara then
  509. ParaLibraryPath.AddPath(More,false)
  510. else
  511. LibrarySearchPath.AddPath(More,true);
  512. 'L' : if More<>'' then
  513. ParaDynamicLinker:=More
  514. else
  515. IllegalPara(opt);
  516. 'o' : if ispara then
  517. ParaObjectPath.AddPath(More,false)
  518. else
  519. ObjectSearchPath.AddPath(More,true);
  520. 'r' : Msgfilename:=More;
  521. 'u' : if ispara then
  522. ParaUnitPath.AddPath(More,false)
  523. else
  524. unitsearchpath.AddPath(More,true);
  525. 'U' : OutputUnitDir:=FixPath(More,true);
  526. else
  527. IllegalPara(opt);
  528. end;
  529. end;
  530. 'g' : begin
  531. if UnsetBool(More, 0) then
  532. begin
  533. exclude(initmoduleswitches,cs_debuginfo);
  534. exclude(initglobalswitches,cs_gdb_dbx);
  535. exclude(initglobalswitches,cs_gdb_gsym);
  536. exclude(initglobalswitches,cs_gdb_heaptrc);
  537. exclude(initglobalswitches,cs_gdb_lineinfo);
  538. exclude(initglobalswitches,cs_checkpointer);
  539. end
  540. else
  541. begin
  542. {$ifdef GDB}
  543. include(initmoduleswitches,cs_debuginfo);
  544. if not RelocSectionSetExplicitly then
  545. RelocSection:=false;
  546. for j:=1 to length(more) do
  547. case more[j] of
  548. 'd' : if UnsetBool(More, j) then
  549. exclude(initglobalswitches,cs_gdb_dbx)
  550. else
  551. include(initglobalswitches,cs_gdb_dbx);
  552. 'g' : if UnsetBool(More, j) then
  553. exclude(initglobalswitches,cs_gdb_gsym)
  554. else
  555. include(initglobalswitches,cs_gdb_gsym);
  556. 'h' : if UnsetBool(More, j) then
  557. exclude(initglobalswitches,cs_gdb_heaptrc)
  558. else
  559. include(initglobalswitches,cs_gdb_heaptrc);
  560. 'l' : if UnsetBool(More, j) then
  561. exclude(initglobalswitches,cs_gdb_lineinfo)
  562. else
  563. include(initglobalswitches,cs_gdb_lineinfo);
  564. 'c' : if UnsetBool(More, j) then
  565. exclude(initglobalswitches,cs_checkpointer)
  566. else
  567. include(initglobalswitches,cs_checkpointer);
  568. else
  569. IllegalPara(opt);
  570. end;
  571. {$else GDB}
  572. Message(option_no_debug_support);
  573. Message(option_no_debug_support_recompile_fpc);
  574. {$endif GDB}
  575. end;
  576. end;
  577. 'h' : begin
  578. NoPressEnter:=true;
  579. WriteHelpPages;
  580. end;
  581. 'i' : if More='' then
  582. WriteInfo
  583. else
  584. QuickInfo:=QuickInfo+More;
  585. 'I' : if ispara then
  586. ParaIncludePath.AddPath(More,false)
  587. else
  588. includesearchpath.AddPath(More,false);
  589. 'k' : if more<>'' then
  590. ParaLinkOptions:=ParaLinkOptions+' '+More
  591. else
  592. IllegalPara(opt);
  593. 'l' : DoWriteLogo:=not UnSetBool(more,0);
  594. 'm' : parapreprocess:=not UnSetBool(more,0);
  595. 'n' : if More='' then
  596. begin
  597. read_configfile:=false;
  598. disable_configfile:=true;
  599. end
  600. else
  601. IllegalPara(opt);
  602. 'o' : if More<>'' then
  603. Fsplit(More,d,OutputFile,e)
  604. else
  605. IllegalPara(opt);
  606. 'p' : begin
  607. if UnsetBool(More, 0) then
  608. begin
  609. initmoduleswitches:=initmoduleswitches-[cs_profile];
  610. undef_symbol('FPC_PROFILE');
  611. end
  612. else
  613. if Length(More)=0 then
  614. IllegalPara(opt)
  615. else
  616. case more[1] of
  617. 'g' : if UnsetBool(more, 1) then
  618. begin
  619. exclude(initmoduleswitches,cs_profile);
  620. undef_symbol('FPC_PROFILE');
  621. end
  622. else
  623. begin
  624. include(initmoduleswitches,cs_profile);
  625. def_symbol('FPC_PROFILE');
  626. end;
  627. else
  628. IllegalPara(opt);
  629. end;
  630. end;
  631. {$ifdef Unix}
  632. 'P' : if UnsetBool(More, 0) then
  633. exclude(initglobalswitches,cs_asm_pipe)
  634. else
  635. include(initglobalswitches,cs_asm_pipe);
  636. {$endif Unix}
  637. 's' : if UnsetBool(More, 0) then
  638. initglobalswitches:=initglobalswitches-[cs_asm_extern,cs_link_extern]
  639. else
  640. initglobalswitches:=initglobalswitches+[cs_asm_extern,cs_link_extern];
  641. 'S' : begin
  642. if more[1]='I' then
  643. begin
  644. if upper(more)='ICOM' then
  645. initinterfacetype:=it_interfacecom
  646. else if upper(more)='ICORBA' then
  647. initinterfacetype:=it_interfacecorba
  648. else
  649. IllegalPara(opt);
  650. end
  651. else
  652. for j:=1 to length(more) do
  653. case more[j] of
  654. '2' : SetCompileMode('OBJFPC',true);
  655. 'a' : include(initlocalswitches,cs_do_assertion);
  656. 'c' : include(initmoduleswitches,cs_support_c_operators);
  657. 'd' : SetCompileMode('DELPHI',true);
  658. 'e' : begin
  659. SetErrorFlags(copy(more,j+1,length(more)));
  660. break;
  661. end;
  662. 'g' : include(initmoduleswitches,cs_support_goto);
  663. 'h' : include(initlocalswitches,cs_ansistrings);
  664. 'i' : include(initmoduleswitches,cs_support_inline);
  665. 'm' : include(initmoduleswitches,cs_support_macro);
  666. 'o' : SetCompileMode('TP',true);
  667. 'p' : SetCompileMode('GPC',true);
  668. 's' : include(initglobalswitches,cs_constructor_name);
  669. 't' : include(initmoduleswitches,cs_static_keyword);
  670. '-' : begin
  671. exclude(initglobalswitches,cs_constructor_name);
  672. initlocalswitches:=InitLocalswitches - [cs_do_assertion, cs_ansistrings];
  673. initmoduleswitches:=initmoduleswitches - [cs_support_c_operators, cs_support_goto,
  674. cs_support_inline, cs_support_macro,
  675. cs_static_keyword];
  676. end;
  677. else
  678. IllegalPara(opt);
  679. end;
  680. end;
  681. 'T' : begin
  682. more:=Upper(More);
  683. if not target_is_set then
  684. begin
  685. { remove old target define }
  686. TargetDefines(false);
  687. { Save assembler if set }
  688. if asm_is_set then
  689. forceasm:=target_asm.id;
  690. { load new target }
  691. if not(set_target_by_string(More)) then
  692. IllegalPara(opt);
  693. { also initialize assembler if not explicitly set }
  694. if asm_is_set then
  695. set_target_asm(forceasm);
  696. { set new define }
  697. TargetDefines(true);
  698. target_is_set:=true;
  699. end
  700. else
  701. if More<>upper(target_info.shortname) then
  702. Message1(option_target_is_already_set,target_info.shortname);
  703. end;
  704. 'u' : undef_symbol(upper(More));
  705. 'U' : begin
  706. for j:=1 to length(more) do
  707. case more[j] of
  708. {$ifdef UNITALIASES}
  709. 'a' : begin
  710. AddUnitAlias(Copy(More,j+1,255));
  711. break;
  712. end;
  713. {$endif UNITALIASES}
  714. 'n' : exclude(initglobalswitches,cs_check_unit_name);
  715. 'p' : begin
  716. Message2(option_obsolete_switch_use_new,'-Up','-Fu');
  717. break;
  718. end;
  719. 'r' : do_release:=true;
  720. 's' : include(initmoduleswitches,cs_compilesystem);
  721. '-' : begin
  722. exclude(initmoduleswitches,cs_compilesystem);
  723. exclude(initglobalswitches,cs_check_unit_name);
  724. end;
  725. else
  726. IllegalPara(opt);
  727. end;
  728. end;
  729. 'v' : if not setverbosity(More) then
  730. IllegalPara(opt);
  731. 'W' : begin
  732. j:=0;
  733. while j<length(More) do
  734. begin
  735. inc(j);
  736. case More[j] of
  737. 'B': begin
  738. { -WB200000 means set trefered base address
  739. to $200000, but does not change relocsection boolean
  740. this way we can create both relocatble and
  741. non relocatable DLL at a specific base address PM }
  742. if (length(More)>j) then
  743. begin
  744. if DLLImageBase=nil then
  745. DLLImageBase:=StringDup(Copy(More,j+1,255));
  746. end
  747. else
  748. begin
  749. RelocSection:=true;
  750. RelocSectionSetExplicitly:=true;
  751. end;
  752. break;
  753. end;
  754. 'C': if UnsetBool(More, j) then
  755. apptype:=app_gui
  756. else
  757. apptype:=app_cui;
  758. 'D': ForceDeffileForExport:=not UnsetBool(More, j);
  759. 'F': apptype:=app_fs;
  760. 'G': if UnsetBool(More, j) then
  761. apptype:=app_cui
  762. else
  763. apptype:=app_gui;
  764. 'N': begin
  765. RelocSection:=UnsetBool(More,j);
  766. RelocSectionSetExplicitly:=true;
  767. end;
  768. 'R': begin
  769. { support -WR+ / -WR- as synonims to -WR / -WN }
  770. RelocSection:=not UnsetBool(More,j);
  771. RelocSectionSetExplicitly:=true;
  772. end;
  773. else
  774. IllegalPara(opt);
  775. end;
  776. end; {of while}
  777. end;
  778. 'X' : begin
  779. for j:=1 to length(More) do
  780. case More[j] of
  781. 's' : include(initglobalswitches,cs_link_strip);
  782. 't' : include(initglobalswitches,cs_link_staticflag);
  783. 'D' : begin
  784. def_symbol('FPC_LINK_DYNAMIC');
  785. undef_symbol('FPC_LINK_SMART');
  786. undef_symbol('FPC_LINK_STATIC');
  787. exclude(initglobalswitches,cs_link_static);
  788. exclude(initglobalswitches,cs_link_smart);
  789. include(initglobalswitches,cs_link_shared);
  790. LinkTypeSetExplicitly:=true;
  791. end;
  792. 'S' : begin
  793. def_symbol('FPC_LINK_STATIC');
  794. undef_symbol('FPC_LINK_SMART');
  795. undef_symbol('FPC_LINK_DYNAMIC');
  796. include(initglobalswitches,cs_link_static);
  797. exclude(initglobalswitches,cs_link_smart);
  798. exclude(initglobalswitches,cs_link_shared);
  799. LinkTypeSetExplicitly:=true;
  800. end;
  801. 'X' : begin
  802. def_symbol('FPC_LINK_SMART');
  803. undef_symbol('FPC_LINK_STATIC');
  804. undef_symbol('FPC_LINK_DYNAMIC');
  805. exclude(initglobalswitches,cs_link_static);
  806. include(initglobalswitches,cs_link_smart);
  807. exclude(initglobalswitches,cs_link_shared);
  808. LinkTypeSetExplicitly:=true;
  809. end;
  810. '-' : begin
  811. exclude(initglobalswitches,cs_link_staticflag);
  812. exclude(initglobalswitches,cs_link_strip);
  813. set_default_link_type;
  814. end;
  815. else
  816. IllegalPara(opt);
  817. end;
  818. end;
  819. { give processor specific options a chance }
  820. else
  821. interpret_proc_specific_options(opt);
  822. end;
  823. end;
  824. '@' : begin
  825. Message(option_no_nested_response_file);
  826. StopOptions;
  827. end;
  828. else
  829. begin
  830. if (length(param_file)<>0) then
  831. Message(option_only_one_source_support);
  832. param_file:=opt;
  833. end;
  834. end;
  835. end;
  836. procedure Toption.Interpret_file(const filename : string);
  837. procedure RemoveSep(var fn:string);
  838. var
  839. i : longint;
  840. begin
  841. i:=0;
  842. while (i<length(fn)) and (fn[i+1] in [',',' ',#9]) do
  843. inc(i);
  844. Delete(fn,1,i);
  845. i:=length(fn);
  846. while (i>0) and (fn[i] in [',',' ',#9]) do
  847. dec(i);
  848. fn:=copy(fn,1,i);
  849. end;
  850. function GetName(var fn:string):string;
  851. var
  852. i : longint;
  853. begin
  854. i:=0;
  855. while (i<length(fn)) and (fn[i+1] in ['a'..'z','A'..'Z','0'..'9','_','-']) do
  856. inc(i);
  857. GetName:=Copy(fn,1,i);
  858. Delete(fn,1,i);
  859. end;
  860. const
  861. maxlevel=16;
  862. var
  863. f : text;
  864. s,
  865. opts : string;
  866. skip : array[0..maxlevel-1] of boolean;
  867. level : longint;
  868. option_read : boolean;
  869. begin
  870. { avoid infinite loop }
  871. Inc(FileLevel);
  872. Option_read:=false;
  873. If FileLevel>MaxLevel then
  874. Message(option_too_many_cfg_files);
  875. { open file }
  876. Message1(option_using_file,filename);
  877. assign(f,filename);
  878. {$I-}
  879. reset(f);
  880. {$I+}
  881. if ioresult<>0 then
  882. begin
  883. Message1(option_unable_open_file,filename);
  884. exit;
  885. end;
  886. fillchar(skip,sizeof(skip),0);
  887. level:=0;
  888. while not eof(f) do
  889. begin
  890. readln(f,opts);
  891. RemoveSep(opts);
  892. if (opts<>'') and (opts[1]<>';') then
  893. begin
  894. if opts[1]='#' then
  895. begin
  896. Delete(opts,1,1);
  897. s:=upper(GetName(opts));
  898. if (s='SECTION') then
  899. begin
  900. RemoveSep(opts);
  901. s:=upper(GetName(opts));
  902. if level=0 then
  903. skip[level]:=not (check_symbol(s) or (s='COMMON'));
  904. end
  905. else
  906. if (s='IFDEF') then
  907. begin
  908. RemoveSep(opts);
  909. if Level>=maxlevel then
  910. begin
  911. Message(option_too_many_ifdef);
  912. stopOptions;
  913. end;
  914. inc(Level);
  915. skip[level]:=(skip[level-1] or (not check_symbol(upper(GetName(opts)))));
  916. end
  917. else
  918. if (s='IFNDEF') then
  919. begin
  920. RemoveSep(opts);
  921. if Level>=maxlevel then
  922. begin
  923. Message(option_too_many_ifdef);
  924. stopOptions;
  925. end;
  926. inc(Level);
  927. skip[level]:=(skip[level-1] or (check_symbol(upper(GetName(opts)))));
  928. end
  929. else
  930. if (s='ELSE') then
  931. skip[level]:=skip[level-1] or (not skip[level])
  932. else
  933. if (s='ENDIF') then
  934. begin
  935. skip[level]:=false;
  936. if Level=0 then
  937. begin
  938. Message(option_too_many_endif);
  939. stopOptions;
  940. end;
  941. dec(level);
  942. end
  943. else
  944. if (not skip[level]) then
  945. begin
  946. if (s='DEFINE') then
  947. begin
  948. RemoveSep(opts);
  949. def_symbol(upper(GetName(opts)));
  950. end
  951. else
  952. if (s='UNDEF') then
  953. begin
  954. RemoveSep(opts);
  955. undef_symbol(upper(GetName(opts)));
  956. end
  957. else
  958. if (s='WRITE') then
  959. begin
  960. Delete(opts,1,1);
  961. WriteLn(opts);
  962. end
  963. else
  964. if (s='INCLUDE') then
  965. begin
  966. Delete(opts,1,1);
  967. Interpret_file(opts);
  968. end;
  969. end;
  970. end
  971. else
  972. begin
  973. if (opts[1]='-') or (opts[1]='@') then
  974. begin
  975. if (not skip[level]) then
  976. interpret_option(opts,false);
  977. Option_read:=true;
  978. end
  979. else
  980. Message1(option_illegal_para,opts);
  981. end;
  982. end;
  983. end;
  984. if Level>0 then
  985. Message(option_too_less_endif);
  986. if Not Option_read then
  987. Message1(option_no_option_found,filename);
  988. Close(f);
  989. Dec(FileLevel);
  990. end;
  991. procedure Toption.Interpret_envvar(const envname : string);
  992. var
  993. argstart,
  994. env,
  995. pc : pchar;
  996. arglen : longint;
  997. quote : set of char;
  998. hs : string;
  999. begin
  1000. Message1(option_using_env,envname);
  1001. env:=GetEnvPChar(envname);
  1002. pc:=env;
  1003. if assigned(pc) then
  1004. begin
  1005. repeat
  1006. { skip leading spaces }
  1007. while pc^ in [' ',#9,#13] do
  1008. inc(pc);
  1009. case pc^ of
  1010. #0 :
  1011. break;
  1012. '"' :
  1013. begin
  1014. quote:=['"'];
  1015. inc(pc);
  1016. end;
  1017. '''' :
  1018. begin
  1019. quote:=[''''];
  1020. inc(pc);
  1021. end;
  1022. else
  1023. quote:=[' ',#9,#13];
  1024. end;
  1025. { scan until the end of the argument }
  1026. argstart:=pc;
  1027. while (pc^<>#0) and not(pc^ in quote) do
  1028. inc(pc);
  1029. { create argument }
  1030. arglen:=pc-argstart;
  1031. hs[0]:=chr(arglen);
  1032. move(argstart^,hs[1],arglen);
  1033. interpret_option(hs,true);
  1034. { skip quote }
  1035. if pc^ in quote then
  1036. inc(pc);
  1037. until false;
  1038. end
  1039. else
  1040. Message1(option_no_option_found,'(env) '+envname);
  1041. FreeEnvPChar(env);
  1042. end;
  1043. procedure toption.read_parameters;
  1044. var
  1045. opts : string;
  1046. paramindex : longint;
  1047. begin
  1048. paramindex:=0;
  1049. while paramindex<paramcount do
  1050. begin
  1051. inc(paramindex);
  1052. opts:=system.paramstr(paramindex);
  1053. case opts[1] of
  1054. '@' :
  1055. if not firstpass then
  1056. begin
  1057. Delete(opts,1,1);
  1058. Message1(option_reading_further_from,opts);
  1059. interpret_file(opts);
  1060. end;
  1061. '!' :
  1062. if not firstpass then
  1063. begin
  1064. Delete(opts,1,1);
  1065. Message1(option_reading_further_from,'(env) '+opts);
  1066. interpret_envvar(opts);
  1067. end;
  1068. else
  1069. interpret_option(opts,true);
  1070. end;
  1071. end;
  1072. end;
  1073. procedure toption.parsecmd(cmd:string);
  1074. var
  1075. i,ps : longint;
  1076. opts : string;
  1077. begin
  1078. while (cmd<>'') do
  1079. begin
  1080. while cmd[1]=' ' do
  1081. delete(cmd,1,1);
  1082. i:=pos(' ',cmd);
  1083. if i=0 then
  1084. i:=256;
  1085. opts:=Copy(cmd,1,i-1);
  1086. Delete(cmd,1,i);
  1087. case opts[1] of
  1088. '@' :
  1089. if not firstpass then
  1090. begin
  1091. Delete(opts,1,1);
  1092. Message1(option_reading_further_from,opts);
  1093. interpret_file(opts);
  1094. end;
  1095. '!' :
  1096. if not firstpass then
  1097. begin
  1098. Delete(opts,1,1);
  1099. Message1(option_reading_further_from,'(env) '+opts);
  1100. interpret_envvar(opts);
  1101. end;
  1102. '"' :
  1103. begin
  1104. Delete(opts,1,1);
  1105. ps:=pos('"',cmd);
  1106. if (i<>256) and (ps>0) then
  1107. begin
  1108. opts:=opts + ' '+ copy(cmd,1,ps-1);
  1109. cmd:=copy(cmd,ps+1,255);
  1110. end;
  1111. interpret_option(opts,true);
  1112. end;
  1113. else
  1114. interpret_option(opts,true);
  1115. end;
  1116. end;
  1117. end;
  1118. procedure toption.writequickinfo;
  1119. var
  1120. s : string;
  1121. i : longint;
  1122. procedure addinfo(const hs:string);
  1123. begin
  1124. if s<>'' then
  1125. s:=s+' '+hs
  1126. else
  1127. s:=hs;
  1128. end;
  1129. begin
  1130. s:='';
  1131. i:=0;
  1132. while (i<length(quickinfo)) do
  1133. begin
  1134. inc(i);
  1135. case quickinfo[i] of
  1136. 'S' :
  1137. begin
  1138. inc(i);
  1139. case quickinfo[i] of
  1140. 'O' :
  1141. addinfo(lower(source_info.shortname));
  1142. {$ifdef Delphi}
  1143. 'P' :
  1144. addinfo('i386');
  1145. {$else Delphi}
  1146. 'P' :
  1147. addinfo(source_cpu_string);
  1148. {$endif Delphi}
  1149. else
  1150. IllegalPara('-iS'+QuickInfo);
  1151. end;
  1152. end;
  1153. 'T' :
  1154. begin
  1155. inc(i);
  1156. case quickinfo[i] of
  1157. 'O' :
  1158. addinfo(lower(target_info.shortname));
  1159. 'P' :
  1160. AddInfo(target_cpu_string);
  1161. else
  1162. IllegalPara('-iT'+QuickInfo);
  1163. end;
  1164. end;
  1165. 'V' :
  1166. AddInfo(version_string);
  1167. 'D' :
  1168. AddInfo(date_string);
  1169. '_' :
  1170. ;
  1171. else
  1172. IllegalPara('-i'+QuickInfo);
  1173. end;
  1174. end;
  1175. if s<>'' then
  1176. begin
  1177. writeln(s);
  1178. stopoptions;
  1179. end;
  1180. end;
  1181. procedure TOption.TargetDefines(def:boolean);
  1182. var
  1183. s : string;
  1184. i : integer;
  1185. begin
  1186. if def then
  1187. def_symbol(upper(target_info.shortname))
  1188. else
  1189. undef_symbol(upper(target_info.shortname));
  1190. s:=target_info.extradefines;
  1191. while (s<>'') do
  1192. begin
  1193. i:=pos(';',s);
  1194. if i=0 then
  1195. i:=length(s)+1;
  1196. if def then
  1197. def_symbol(Copy(s,1,i-1))
  1198. else
  1199. def_symbol(Copy(s,1,i-1));
  1200. delete(s,1,i);
  1201. end;
  1202. end;
  1203. constructor TOption.create;
  1204. begin
  1205. DoWriteLogo:=false;
  1206. NoPressEnter:=false;
  1207. FirstPass:=false;
  1208. FileLevel:=0;
  1209. Quickinfo:='';
  1210. ParaIncludePath:=TSearchPathList.Create;
  1211. ParaObjectPath:=TSearchPathList.Create;
  1212. ParaUnitPath:=TSearchPathList.Create;
  1213. ParaLibraryPath:=TSearchPathList.Create;
  1214. FillChar(ParaAlignment,sizeof(ParaAlignment),0);
  1215. end;
  1216. destructor TOption.destroy;
  1217. begin
  1218. ParaIncludePath.Free;
  1219. ParaObjectPath.Free;
  1220. ParaUnitPath.Free;
  1221. ParaLibraryPath.Free;
  1222. end;
  1223. {****************************************************************************
  1224. Callable Routines
  1225. ****************************************************************************}
  1226. procedure read_arguments(cmd:string);
  1227. var
  1228. configpath : pathstr;
  1229. begin
  1230. option:=coption.create;
  1231. disable_configfile:=false;
  1232. { default defines }
  1233. def_symbol(upper(target_info.shortname));
  1234. def_symbol('FPC');
  1235. def_symbol('VER'+version_nr);
  1236. def_symbol('VER'+version_nr+'_'+release_nr);
  1237. def_symbol('VER'+version_nr+'_'+release_nr+'_'+patch_nr);
  1238. {$ifdef newcg}
  1239. def_symbol('WITHNEWCG');
  1240. {$endif}
  1241. { Temporary defines, until things settle down }
  1242. def_symbol('HASWIDECHAR');
  1243. def_symbol('HASWIDESTRING');
  1244. def_symbol('HASOUT');
  1245. def_symbol('HASINTF');
  1246. def_symbol('HASVARIANT');
  1247. def_symbol('INTERNSETLENGTH');
  1248. def_symbol('INTERNLENGTH');
  1249. def_symbol('INT64FUNCRESOK');
  1250. def_symbol('PACKENUMFIXED');
  1251. def_symbol('HAS_ADDR_STACK_ON_STACK');
  1252. def_symbol('NOBOUNDCHECK');
  1253. def_symbol('HASCOMPILERPROC');
  1254. { some stuff for TP compatibility }
  1255. {$ifdef i386}
  1256. def_symbol('CPU86');
  1257. def_symbol('CPU87');
  1258. {$endif}
  1259. {$ifdef m68k}
  1260. def_symbol('CPU68');
  1261. {$endif}
  1262. { new processor stuff }
  1263. {$ifdef i386}
  1264. def_symbol('CPUI386');
  1265. {$endif}
  1266. {$ifdef m68k}
  1267. def_symbol('CPU68K');
  1268. {$endif}
  1269. {$ifdef ALPHA}
  1270. def_symbol('CPUALPHA');
  1271. {$endif}
  1272. {$ifdef powerpc}
  1273. def_symbol('CPUPOWERPC');
  1274. {$endif}
  1275. { get default messagefile }
  1276. {$ifdef Delphi}
  1277. msgfilename:=dmisc.getenv('PPC_ERROR_FILE');
  1278. {$else Delphi}
  1279. msgfilename:=dos.getenv('PPC_ERROR_FILE');
  1280. {$endif Delphi}
  1281. { default configfile }
  1282. if (cmd<>'') and (cmd[1]='[') then
  1283. begin
  1284. ppccfg:=Copy(cmd,2,pos(']',cmd)-2);
  1285. Delete(cmd,1,pos(']',cmd));
  1286. end
  1287. else
  1288. begin
  1289. {$ifdef i386}
  1290. ppccfg:='ppc386.cfg';
  1291. {$endif i386}
  1292. {$ifdef ia64}
  1293. ppccfg:='ppcia64.cfg';
  1294. {$endif ia64}
  1295. {$ifdef m68k}
  1296. ppccfg:='ppc68k.cfg';
  1297. {$endif}
  1298. {$ifdef alpha}
  1299. ppccfg:='ppcalpha.cfg';
  1300. {$endif}
  1301. {$ifdef powerpc}
  1302. ppccfg:='ppcppc.cfg';
  1303. {$endif}
  1304. end;
  1305. { Order to read ppc386.cfg:
  1306. 1 - current dir
  1307. 2 - configpath
  1308. 3 - compiler path }
  1309. {$ifdef Delphi}
  1310. configpath:=FixPath(dmisc.getenv('PPC_CONFIG_PATH'),false);
  1311. {$else Delphi}
  1312. configpath:=FixPath(dos.getenv('PPC_CONFIG_PATH'),false);
  1313. {$endif Delphi}
  1314. {$ifdef Unix}
  1315. if configpath='' then
  1316. configpath:='/etc/';
  1317. {$endif}
  1318. if ppccfg<>'' then
  1319. begin
  1320. read_configfile:=true;
  1321. if not FileExists(ppccfg) then
  1322. begin
  1323. {$ifdef Unix}
  1324. if (dos.getenv('HOME')<>'') and FileExists(FixPath(dos.getenv('HOME'),false)+'.'+ppccfg) then
  1325. ppccfg:=FixPath(dos.getenv('HOME'),false)+'.'+ppccfg
  1326. else
  1327. {$endif}
  1328. if FileExists(configpath+ppccfg) then
  1329. ppccfg:=configpath+ppccfg
  1330. else
  1331. {$ifndef Unix}
  1332. if FileExists(exepath+ppccfg) then
  1333. ppccfg:=exepath+ppccfg
  1334. else
  1335. {$endif}
  1336. read_configfile:=false;
  1337. end;
  1338. end
  1339. else
  1340. read_configfile:=false;
  1341. { Read commandline and configfile }
  1342. target_is_set:=false;
  1343. asm_is_set:=false;
  1344. param_file:='';
  1345. if read_configfile then
  1346. begin
  1347. { read the parameters quick, only -i -v -T }
  1348. option.firstpass:=true;
  1349. if cmd<>'' then
  1350. option.parsecmd(cmd)
  1351. else
  1352. begin
  1353. option.read_parameters;
  1354. { Write only quickinfo }
  1355. if option.quickinfo<>'' then
  1356. option.writequickinfo;
  1357. end;
  1358. { Read the configfile }
  1359. option.firstpass:=false;
  1360. if read_configfile then
  1361. option.interpret_file(ppccfg);
  1362. end;
  1363. if cmd<>'' then
  1364. option.parsecmd(cmd)
  1365. else
  1366. begin
  1367. option.read_parameters;
  1368. { Write only quickinfo }
  1369. if option.quickinfo<>'' then
  1370. option.writequickinfo;
  1371. end;
  1372. { Write help pages }
  1373. if (cmd='') and (paramcount=0) then
  1374. Option.WriteHelpPages;
  1375. { Stop if errors in options }
  1376. if ErrorCount>0 then
  1377. StopOptions;
  1378. { Non-core target defines }
  1379. Option.TargetDefines(true);
  1380. { endian define }
  1381. case target_info.endian of
  1382. endian_little :
  1383. def_symbol('ENDIAN_LITTLE');
  1384. endian_big :
  1385. def_symbol('ENDIAN_BIG');
  1386. end;
  1387. { write logo if set }
  1388. if option.DoWriteLogo then
  1389. option.WriteLogo;
  1390. { Check file to compile }
  1391. if param_file='' then
  1392. begin
  1393. Message(option_no_source_found);
  1394. StopOptions;
  1395. end;
  1396. {$ifndef Unix}
  1397. param_file:=FixFileName(param_file);
  1398. {$endif}
  1399. fsplit(param_file,inputdir,inputfile,inputextension);
  1400. if inputextension='' then
  1401. begin
  1402. if FileExists(inputdir+inputfile+target_info.sourceext) then
  1403. inputextension:=target_info.sourceext
  1404. else
  1405. if FileExists(inputdir+inputfile+target_info.pasext) then
  1406. inputextension:=target_info.pasext;
  1407. end;
  1408. { Add paths specified with parameters to the searchpaths }
  1409. UnitSearchPath.AddList(option.ParaUnitPath,true);
  1410. ObjectSearchPath.AddList(option.ParaObjectPath,true);
  1411. IncludeSearchPath.AddList(option.ParaIncludePath,true);
  1412. LibrarySearchPath.AddList(option.ParaLibraryPath,true);
  1413. { add unit environment and exepath to the unit search path }
  1414. if inputdir<>'' then
  1415. Unitsearchpath.AddPath(inputdir,true);
  1416. if not disable_configfile then
  1417. {$ifdef Delphi}
  1418. UnitSearchPath.AddPath(dmisc.getenv(target_info.unit_env),false);
  1419. {$else}
  1420. UnitSearchPath.AddPath(dos.getenv(target_info.unit_env),false);
  1421. {$endif Delphi}
  1422. {$ifdef Unix}
  1423. fpcdir:=FixPath(getenv('FPCDIR'),false);
  1424. if fpcdir='' then
  1425. begin
  1426. if PathExists('/usr/local/lib/fpc/'+version_string) then
  1427. fpcdir:='/usr/local/lib/fpc/'+version_string+'/'
  1428. else
  1429. fpcdir:='/usr/lib/fpc/'+version_string+'/';
  1430. end;
  1431. {$else}
  1432. fpcdir:=FixPath(getenv('FPCDIR'),false);
  1433. if fpcdir='' then
  1434. begin
  1435. fpcdir:=ExePath+'../';
  1436. if not(PathExists(fpcdir+'/units')) and
  1437. not(PathExists(fpcdir+'/rtl')) then
  1438. fpcdir:=fpcdir+'../';
  1439. end;
  1440. {$endif}
  1441. { first try development RTL, else use the default installation path }
  1442. if not disable_configfile then
  1443. begin
  1444. if PathExists(FpcDir+'rtl/'+lower(target_info.shortname)) then
  1445. UnitSearchPath.AddPath(FpcDir+'rtl/'+lower(target_info.shortname),false)
  1446. else
  1447. begin
  1448. UnitSearchPath.AddPath(FpcDir+'units/'+lower(target_info.shortname),false);
  1449. UnitSearchPath.AddPath(FpcDir+'units/'+lower(target_info.shortname)+'/rtl',false);
  1450. end;
  1451. end;
  1452. { Add exepath if the exe is not in the current dir, because that is always searched already }
  1453. if ExePath<>GetCurrentDir then
  1454. UnitSearchPath.AddPath(ExePath,false);
  1455. { Add unit dir to the object and library path }
  1456. objectsearchpath.AddList(unitsearchpath,false);
  1457. librarysearchpath.AddList(unitsearchpath,false);
  1458. { switch assembler if it's binary and we got -a on the cmdline }
  1459. if (cs_asm_leave in initglobalswitches) and
  1460. (target_asm.outputbinary) then
  1461. begin
  1462. Message(option_switch_bin_to_src_assembler);
  1463. set_target_asm(target_info.assemextern);
  1464. end;
  1465. if (target_asm.supported_target <> target_any) and
  1466. (target_asm.supported_target <> target_info.target) then
  1467. begin
  1468. Message2(option_incompatible_asm,target_asm.idtxt,target_info.name);
  1469. set_target_asm(target_info.assemextern);
  1470. Message1(option_asm_forced,target_asm.idtxt);
  1471. end;
  1472. { turn off stripping if compiling with debuginfo or profile }
  1473. if (cs_debuginfo in initmoduleswitches) or
  1474. (cs_profile in initmoduleswitches) then
  1475. exclude(initglobalswitches,cs_link_strip);
  1476. if not LinkTypeSetExplicitly then
  1477. set_default_link_type;
  1478. { Default alignment settings,
  1479. 1. load the defaults for the target
  1480. 2. override with generic optimizer setting (little size)
  1481. 3. override with the user specified -Oa }
  1482. UpdateAlignment(initalignment,target_info.alignment);
  1483. if (cs_littlesize in aktglobalswitches) then
  1484. begin
  1485. initalignment.procalign:=1;
  1486. initalignment.jumpalign:=1;
  1487. initalignment.loopalign:=1;
  1488. end;
  1489. UpdateAlignment(initalignment,option.paraalignment);
  1490. option.free;
  1491. Option:=nil;
  1492. end;
  1493. initialization
  1494. coption:=toption;
  1495. finalization
  1496. if assigned(option) then
  1497. option.free;
  1498. end.
  1499. {
  1500. $Log$
  1501. Revision 1.57 2001-08-30 20:13:53 peter
  1502. * rtti/init table updates
  1503. * rttisym for reusable global rtti/init info
  1504. * support published for interfaces
  1505. Revision 1.56 2001/08/20 10:58:48 florian
  1506. * renamed messages unit to cmsgs to avoid conflicts with the
  1507. win32 messages unit
  1508. Revision 1.55 2001/08/19 11:22:23 peter
  1509. * palmos support from v10 merged
  1510. Revision 1.54 2001/08/12 17:57:06 peter
  1511. * under development flag for targets
  1512. Revision 1.53 2001/08/07 18:42:46 peter
  1513. * list targets with -i
  1514. Revision 1.52 2001/08/01 15:07:29 jonas
  1515. + "compilerproc" directive support, which turns both the public and mangled
  1516. name to lowercase(declaration_name). This prevents a normal user from
  1517. accessing the routine, but they can still be easily looked up within
  1518. the compiler. This is used for helper procedures and should facilitate
  1519. the writing of more processor independent code in the code generator
  1520. itself (mostly written by Peter)
  1521. + new "createintern" constructor for tcal nodes to create a call to
  1522. helper exported using the "compilerproc" directive
  1523. + support for high(dynamic_array) using the the above new things
  1524. + definition of 'HASCOMPILERPROC' symbol (to be able to check in the
  1525. compiler and rtl whether the "compilerproc" directive is supported)
  1526. Revision 1.51 2001/07/31 19:38:46 peter
  1527. * removed fpu_in_rtl define (merged)
  1528. Revision 1.50 2001/07/30 21:39:26 peter
  1529. * declare fpu in rtl for m68k linux
  1530. Revision 1.49 2001/07/09 21:15:40 peter
  1531. * Length made internal
  1532. * Add array support for Length
  1533. Revision 1.48 2001/07/08 21:00:15 peter
  1534. * various widestring updates, it works now mostly without charset
  1535. mapping supported
  1536. Revision 1.47 2001/07/01 20:16:16 peter
  1537. * alignmentinfo record added
  1538. * -Oa argument supports more alignment settings that can be specified
  1539. per type: PROC,LOOP,VARMIN,VARMAX,CONSTMIN,CONSTMAX,RECORDMIN
  1540. RECORDMAX,LOCALMIN,LOCALMAX. It is possible to set the mimimum
  1541. required alignment and the maximum usefull alignment. The final
  1542. alignment will be choosen per variable size dependent on these
  1543. settings
  1544. Revision 1.46 2001/06/29 19:41:54 peter
  1545. * patch from Pavel Ozerski to support +/- better
  1546. Revision 1.45 2001/06/19 14:55:45 jonas
  1547. * fixed typo in NOBOUNDCHECK define
  1548. Revision 1.44 2001/06/18 20:36:24 peter
  1549. * -Ur switch (merged)
  1550. * masm fixes (merged)
  1551. * quoted filenames for go32v2 and win32
  1552. Revision 1.43 2001/06/02 19:21:45 peter
  1553. * extradefines field added to target_info, so that targets don't
  1554. need to put code in options.pas for it
  1555. Revision 1.42 2001/05/18 22:28:59 peter
  1556. * endian define
  1557. Revision 1.41 2001/05/12 12:11:31 peter
  1558. * simplify_ppu is now the default, a recompile of the compiler now
  1559. only compiles pp.pas
  1560. Revision 1.40 2001/04/18 22:01:54 peter
  1561. * registration of targets and assemblers
  1562. Revision 1.39 2001/04/13 01:22:10 peter
  1563. * symtable change to classes
  1564. * range check generation and errors fixed, make cycle DEBUG=1 works
  1565. * memory leaks fixed
  1566. Revision 1.38 2001/03/25 12:27:31 peter
  1567. * fixed -Se (merged)
  1568. Revision 1.37 2001/03/23 00:16:07 florian
  1569. + some stuff to compile FreeCLX added
  1570. Revision 1.36 2001/03/13 20:59:56 peter
  1571. * message loading fixes from Sergey (merged)
  1572. Revision 1.35 2001/03/10 13:19:10 peter
  1573. * don't check messagefile for numbers, this allows the usage of
  1574. 1.1 msgfiles with a 1.0.x compiler
  1575. Revision 1.34 2001/03/05 21:50:29 peter
  1576. * press enter moved to errore.msg
  1577. Revision 1.33 2001/03/03 12:41:22 jonas
  1578. * simplified and optimized range checking code, FPC_BOUNDCHECK is no longer necessary
  1579. Revision 1.32 2001/02/26 19:44:53 peter
  1580. * merged generic m68k updates from fixes branch
  1581. Revision 1.31 2001/02/26 12:47:46 jonas
  1582. * fixed bug in type checking for compatibility of set elements (merged)
  1583. * released fix in options.pas from Carl also for FPC (merged)
  1584. Revision 1.30 2001/02/26 08:08:39 michael
  1585. * option_help_pages:
  1586. allow to omit an option (use one space char insteed an option)
  1587. but to indent a continuation line as if option is present. For lines:
  1588. 3*2CX_first line
  1589. 3*2 _second line
  1590. 3*2*_third line
  1591. we could get:
  1592. -CX first line
  1593. second line
  1594. third line
  1595. Revision 1.29 2001/02/26 07:49:50 michael
  1596. Support replacements for all -F<x> options
  1597. Revision 1.28 2001/02/05 21:26:36 peter
  1598. * applied patches from Sergey Korshunoff
  1599. Revision 1.27 2001/01/20 18:36:51 hajny
  1600. + APPTYPE support under OS/2, app_fs, GetEnvPChar for OS/2
  1601. Revision 1.26 2001/01/12 19:21:09 peter
  1602. * fixed writing of quickinfo when no ppc386.cfg is available
  1603. Revision 1.25 2001/01/05 17:36:57 florian
  1604. * the info about exception frames is stored now on the stack
  1605. instead on the heap
  1606. Revision 1.24 2000/12/25 00:07:26 peter
  1607. + new tlinkedlist class (merge of old tstringqueue,tcontainer and
  1608. tlinkedlist objects)
  1609. Revision 1.23 2000/12/24 12:21:41 peter
  1610. * use system.paramstr()
  1611. Revision 1.22 2000/12/23 19:46:49 peter
  1612. * object to class conversion
  1613. * more verbosity for -vt and -vd
  1614. * -i options can be put after eachother so the Makefiles only need
  1615. to call fpc once for all info (will be twice as the first one will
  1616. be to check the version if fpc supports multiple info)
  1617. Revision 1.21 2000/12/16 15:56:19 jonas
  1618. - removed all ifdef cardinalmulfix code
  1619. Revision 1.20 2000/12/15 13:26:01 jonas
  1620. * only return int64's from functions if it int64funcresok is defined
  1621. + added int64funcresok define to options.pas
  1622. Revision 1.19 2000/11/30 22:48:23 florian
  1623. * opts386 renamed
  1624. Revision 1.18 2000/11/29 00:30:34 florian
  1625. * unused units removed from uses clause
  1626. * some changes for widestrings
  1627. Revision 1.17 2000/11/13 15:26:12 marco
  1628. * Renamefest
  1629. Revision 1.16 2000/11/12 22:20:37 peter
  1630. * create generic toutputsection for binary writers
  1631. Revision 1.15 2000/11/07 15:09:27 marco
  1632. * Define UNIX for FreeBSD and Linux. Checked crosscompile thingy.
  1633. Revision 1.14 2000/11/07 14:25:08 marco
  1634. * FreeBSD defines (FreeBSD,Linux,BSD,Unix) Linux defines (Linux,Unix)
  1635. Revision 1.13 2000/11/06 20:30:54 peter
  1636. * more fixes to get make cycle working
  1637. Revision 1.12 2000/11/04 14:25:20 florian
  1638. + merged Attila's changes for interfaces, not tested yet
  1639. Revision 1.11 2000/09/26 10:50:41 jonas
  1640. * initmodeswitches is changed is you change the compiler mode from the
  1641. command line (the -S<x> switches didn't work anymore for changing the
  1642. compiler mode) (merged from fixes branch)
  1643. Revision 1.10 2000/09/24 21:33:47 peter
  1644. * message updates merges
  1645. Revision 1.9 2000/09/24 15:06:20 peter
  1646. * use defines.inc
  1647. Revision 1.8 2000/09/18 12:28:41 marco
  1648. * Definition of multiple FreeBSD target defines moved to after error check
  1649. commandline parsing
  1650. Revision 1.7 2000/09/16 12:22:52 peter
  1651. * freebsd support merged
  1652. Revision 1.6 2000/08/27 16:11:51 peter
  1653. * moved some util functions from globals,cobjects to cutils
  1654. * splitted files into finput,fmodule
  1655. Revision 1.5 2000/08/07 11:31:04 jonas
  1656. * fixed bug in type conversions between enum subranges (it didn't take
  1657. the packenum directive into account)
  1658. + define PACKENUMFIXED symbol in options.pas
  1659. (merged from fixes branch)
  1660. Revision 1.4 2000/07/14 05:11:48 michael
  1661. + Patch to 1.1
  1662. Revision 1.3 2000/07/13 12:08:26 michael
  1663. + patched to 1.1.0 with former 1.09patch from peter
  1664. Revision 1.2 2000/07/13 11:32:44 michael
  1665. + removed logs
  1666. }