options.pas 53 KB

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