options.pas 53 KB

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