options.pas 57 KB

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