options.pas 53 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705
  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. 'r' : do_release:=true;
  698. 's' : initmoduleswitches:=initmoduleswitches+[cs_compilesystem];
  699. '-' : begin
  700. initmoduleswitches:=initmoduleswitches
  701. - [cs_compilesystem];
  702. initglobalswitches:=initglobalswitches
  703. + [cs_check_unit_name];
  704. end;
  705. else
  706. IllegalPara(opt);
  707. end;
  708. end;
  709. 'v' : if not setverbosity(More) then
  710. IllegalPara(opt);
  711. 'W' : begin
  712. for j:=1 to length(More) do
  713. case More[j] of
  714. 'B': {bind_win32_dll:=true}
  715. begin
  716. { -WB200000 means set trefered base address
  717. to $200000, but does not change relocsection boolean
  718. this way we can create both relocatble and
  719. non relocatable DLL at a specific base address PM }
  720. if (length(More)>j) then
  721. begin
  722. if DLLImageBase=nil then
  723. DLLImageBase:=StringDup(Copy(More,j+1,255));
  724. end
  725. else
  726. begin
  727. RelocSection:=true;
  728. RelocSectionSetExplicitly:=true;
  729. end;
  730. break;
  731. end;
  732. 'C': apptype:=app_cui;
  733. 'D': if UnsetBool(More, j) then
  734. ForceDeffileForExport:=false
  735. else
  736. ForceDeffileForExport:=true;
  737. 'F': apptype:=app_fs;
  738. 'G': apptype:=app_gui;
  739. 'N': begin
  740. RelocSection:=false;
  741. RelocSectionSetExplicitly:=true;
  742. end;
  743. 'R': begin
  744. RelocSection:=true;
  745. RelocSectionSetExplicitly:=true;
  746. end;
  747. else
  748. IllegalPara(opt);
  749. end;
  750. end;
  751. 'X' : begin
  752. for j:=1 to length(More) do
  753. case More[j] of
  754. 'c' : initglobalswitches:=initglobalswitches+[cs_link_toc];
  755. 's' : initglobalswitches:=initglobalswitches+[cs_link_strip];
  756. 't' : initglobalswitches:=initglobalswitches+[cs_link_staticflag];
  757. 'D' : begin
  758. def_symbol('FPC_LINK_DYNAMIC');
  759. undef_symbol('FPC_LINK_SMART');
  760. undef_symbol('FPC_LINK_STATIC');
  761. initglobalswitches:=initglobalswitches+[cs_link_shared];
  762. initglobalswitches:=initglobalswitches-[cs_link_static,cs_link_smart];
  763. LinkTypeSetExplicitly:=true;
  764. end;
  765. 'S' : begin
  766. def_symbol('FPC_LINK_STATIC');
  767. undef_symbol('FPC_LINK_SMART');
  768. undef_symbol('FPC_LINK_DYNAMIC');
  769. initglobalswitches:=initglobalswitches+[cs_link_static];
  770. initglobalswitches:=initglobalswitches-[cs_link_shared,cs_link_smart];
  771. LinkTypeSetExplicitly:=true;
  772. end;
  773. 'X' : begin
  774. def_symbol('FPC_LINK_SMART');
  775. undef_symbol('FPC_LINK_STATIC');
  776. undef_symbol('FPC_LINK_DYNAMIC');
  777. initglobalswitches:=initglobalswitches+[cs_link_smart];
  778. initglobalswitches:=initglobalswitches-[cs_link_shared,cs_link_static];
  779. LinkTypeSetExplicitly:=true;
  780. end;
  781. '-' : begin
  782. initglobalswitches:=initglobalswitches-[cs_link_toc, cs_link_strip, cs_link_staticflag];
  783. set_default_link_type;
  784. end;
  785. else
  786. IllegalPara(opt);
  787. end;
  788. end;
  789. { give processor specific options a chance }
  790. else
  791. interpret_proc_specific_options(opt);
  792. end;
  793. end;
  794. '@' : begin
  795. Message(option_no_nested_response_file);
  796. StopOptions;
  797. end;
  798. else
  799. begin
  800. if (length(param_file)<>0) then
  801. Message(option_only_one_source_support);
  802. param_file:=opt;
  803. end;
  804. end;
  805. end;
  806. procedure Toption.Interpret_file(const filename : string);
  807. procedure RemoveSep(var fn:string);
  808. var
  809. i : longint;
  810. begin
  811. i:=0;
  812. while (i<length(fn)) and (fn[i+1] in [',',' ',#9]) do
  813. inc(i);
  814. Delete(fn,1,i);
  815. i:=length(fn);
  816. while (i>0) and (fn[i] in [',',' ',#9]) do
  817. dec(i);
  818. fn:=copy(fn,1,i);
  819. end;
  820. function GetName(var fn:string):string;
  821. var
  822. i : longint;
  823. begin
  824. i:=0;
  825. while (i<length(fn)) and (fn[i+1] in ['a'..'z','A'..'Z','0'..'9','_','-']) do
  826. inc(i);
  827. GetName:=Copy(fn,1,i);
  828. Delete(fn,1,i);
  829. end;
  830. const
  831. maxlevel=16;
  832. var
  833. f : text;
  834. s,
  835. opts : string;
  836. skip : array[0..maxlevel-1] of boolean;
  837. level : longint;
  838. option_read : boolean;
  839. begin
  840. { avoid infinite loop }
  841. Inc(FileLevel);
  842. Option_read:=false;
  843. If FileLevel>MaxLevel then
  844. Message(option_too_many_cfg_files);
  845. { open file }
  846. Message1(option_using_file,filename);
  847. assign(f,filename);
  848. {$I-}
  849. reset(f);
  850. {$I+}
  851. if ioresult<>0 then
  852. begin
  853. Message1(option_unable_open_file,filename);
  854. exit;
  855. end;
  856. fillchar(skip,sizeof(skip),0);
  857. level:=0;
  858. while not eof(f) do
  859. begin
  860. readln(f,opts);
  861. RemoveSep(opts);
  862. if (opts<>'') and (opts[1]<>';') then
  863. begin
  864. if opts[1]='#' then
  865. begin
  866. Delete(opts,1,1);
  867. s:=upper(GetName(opts));
  868. if (s='SECTION') then
  869. begin
  870. RemoveSep(opts);
  871. s:=upper(GetName(opts));
  872. if level=0 then
  873. skip[level]:=not (check_symbol(s) or (s='COMMON'));
  874. end
  875. else
  876. if (s='IFDEF') then
  877. begin
  878. RemoveSep(opts);
  879. if Level>=maxlevel then
  880. begin
  881. Message(option_too_many_ifdef);
  882. stopOptions;
  883. end;
  884. inc(Level);
  885. skip[level]:=(skip[level-1] or (not check_symbol(upper(GetName(opts)))));
  886. end
  887. else
  888. if (s='IFNDEF') then
  889. begin
  890. RemoveSep(opts);
  891. if Level>=maxlevel then
  892. begin
  893. Message(option_too_many_ifdef);
  894. stopOptions;
  895. end;
  896. inc(Level);
  897. skip[level]:=(skip[level-1] or (check_symbol(upper(GetName(opts)))));
  898. end
  899. else
  900. if (s='ELSE') then
  901. skip[level]:=skip[level-1] or (not skip[level])
  902. else
  903. if (s='ENDIF') then
  904. begin
  905. skip[level]:=false;
  906. if Level=0 then
  907. begin
  908. Message(option_too_many_endif);
  909. stopOptions;
  910. end;
  911. dec(level);
  912. end
  913. else
  914. if (not skip[level]) then
  915. begin
  916. if (s='DEFINE') then
  917. begin
  918. RemoveSep(opts);
  919. def_symbol(upper(GetName(opts)));
  920. end
  921. else
  922. if (s='UNDEF') then
  923. begin
  924. RemoveSep(opts);
  925. undef_symbol(upper(GetName(opts)));
  926. end
  927. else
  928. if (s='WRITE') then
  929. begin
  930. Delete(opts,1,1);
  931. WriteLn(opts);
  932. end
  933. else
  934. if (s='INCLUDE') then
  935. begin
  936. Delete(opts,1,1);
  937. Interpret_file(opts);
  938. end;
  939. end;
  940. end
  941. else
  942. begin
  943. if (opts[1]='-') or (opts[1]='@') then
  944. begin
  945. if (not skip[level]) then
  946. interpret_option(opts,false);
  947. Option_read:=true;
  948. end
  949. else
  950. Message1(option_illegal_para,opts);
  951. end;
  952. end;
  953. end;
  954. if Level>0 then
  955. Message(option_too_less_endif);
  956. if Not Option_read then
  957. Message1(option_no_option_found,filename);
  958. Close(f);
  959. Dec(FileLevel);
  960. end;
  961. procedure Toption.Interpret_envvar(const envname : string);
  962. var
  963. argstart,
  964. env,
  965. pc : pchar;
  966. arglen : longint;
  967. quote : set of char;
  968. hs : string;
  969. begin
  970. Message1(option_using_env,envname);
  971. env:=GetEnvPChar(envname);
  972. pc:=env;
  973. if assigned(pc) then
  974. begin
  975. repeat
  976. { skip leading spaces }
  977. while pc^ in [' ',#9,#13] do
  978. inc(pc);
  979. case pc^ of
  980. #0 :
  981. break;
  982. '"' :
  983. begin
  984. quote:=['"'];
  985. inc(pc);
  986. end;
  987. '''' :
  988. begin
  989. quote:=[''''];
  990. inc(pc);
  991. end;
  992. else
  993. quote:=[' ',#9,#13];
  994. end;
  995. { scan until the end of the argument }
  996. argstart:=pc;
  997. while (pc^<>#0) and not(pc^ in quote) do
  998. inc(pc);
  999. { create argument }
  1000. arglen:=pc-argstart;
  1001. hs[0]:=chr(arglen);
  1002. move(argstart^,hs[1],arglen);
  1003. interpret_option(hs,true);
  1004. { skip quote }
  1005. if pc^ in quote then
  1006. inc(pc);
  1007. until false;
  1008. end
  1009. else
  1010. Message1(option_no_option_found,'(env) '+envname);
  1011. FreeEnvPChar(env);
  1012. end;
  1013. procedure toption.read_parameters;
  1014. var
  1015. opts : string;
  1016. paramindex : longint;
  1017. begin
  1018. paramindex:=0;
  1019. while paramindex<paramcount do
  1020. begin
  1021. inc(paramindex);
  1022. opts:=system.paramstr(paramindex);
  1023. case opts[1] of
  1024. '@' :
  1025. if not firstpass then
  1026. begin
  1027. Delete(opts,1,1);
  1028. Message1(option_reading_further_from,opts);
  1029. interpret_file(opts);
  1030. end;
  1031. '!' :
  1032. if not firstpass then
  1033. begin
  1034. Delete(opts,1,1);
  1035. Message1(option_reading_further_from,'(env) '+opts);
  1036. interpret_envvar(opts);
  1037. end;
  1038. else
  1039. interpret_option(opts,true);
  1040. end;
  1041. end;
  1042. end;
  1043. procedure toption.parsecmd(cmd:string);
  1044. var
  1045. i,ps : longint;
  1046. opts : string;
  1047. begin
  1048. while (cmd<>'') do
  1049. begin
  1050. while cmd[1]=' ' do
  1051. delete(cmd,1,1);
  1052. i:=pos(' ',cmd);
  1053. if i=0 then
  1054. i:=256;
  1055. opts:=Copy(cmd,1,i-1);
  1056. Delete(cmd,1,i);
  1057. case opts[1] of
  1058. '@' :
  1059. if not firstpass then
  1060. begin
  1061. Delete(opts,1,1);
  1062. Message1(option_reading_further_from,opts);
  1063. interpret_file(opts);
  1064. end;
  1065. '!' :
  1066. if not firstpass then
  1067. begin
  1068. Delete(opts,1,1);
  1069. Message1(option_reading_further_from,'(env) '+opts);
  1070. interpret_envvar(opts);
  1071. end;
  1072. '"' :
  1073. begin
  1074. Delete(opts,1,1);
  1075. ps:=pos('"',cmd);
  1076. if (i<>256) and (ps>0) then
  1077. begin
  1078. opts:=opts + ' '+ copy(cmd,1,ps-1);
  1079. cmd:=copy(cmd,ps+1,255);
  1080. end;
  1081. interpret_option(opts,true);
  1082. end;
  1083. else
  1084. interpret_option(opts,true);
  1085. end;
  1086. end;
  1087. end;
  1088. procedure toption.writequickinfo;
  1089. var
  1090. s : string;
  1091. i : longint;
  1092. procedure addinfo(const hs:string);
  1093. begin
  1094. if s<>'' then
  1095. s:=s+' '+hs
  1096. else
  1097. s:=hs;
  1098. end;
  1099. begin
  1100. s:='';
  1101. i:=0;
  1102. while (i<length(quickinfo)) do
  1103. begin
  1104. inc(i);
  1105. case quickinfo[i] of
  1106. 'S' :
  1107. begin
  1108. inc(i);
  1109. case quickinfo[i] of
  1110. 'O' :
  1111. addinfo(lower(source_info.shortname));
  1112. {$ifdef Delphi}
  1113. 'P' :
  1114. addinfo('i386');
  1115. {$else Delphi}
  1116. 'P' :
  1117. addinfo(source_cpu_string);
  1118. {$endif Delphi}
  1119. else
  1120. IllegalPara('-iS'+QuickInfo);
  1121. end;
  1122. end;
  1123. 'T' :
  1124. begin
  1125. inc(i);
  1126. case quickinfo[i] of
  1127. 'O' :
  1128. addinfo(lower(target_info.shortname));
  1129. 'P' :
  1130. AddInfo(target_cpu_string);
  1131. else
  1132. IllegalPara('-iT'+QuickInfo);
  1133. end;
  1134. end;
  1135. 'V' :
  1136. AddInfo(version_string);
  1137. 'D' :
  1138. AddInfo(date_string);
  1139. '_' :
  1140. ;
  1141. else
  1142. IllegalPara('-i'+QuickInfo);
  1143. end;
  1144. end;
  1145. if s<>'' then
  1146. begin
  1147. writeln(s);
  1148. stopoptions;
  1149. end;
  1150. end;
  1151. constructor TOption.create;
  1152. begin
  1153. DoWriteLogo:=false;
  1154. NoPressEnter:=false;
  1155. FirstPass:=false;
  1156. FileLevel:=0;
  1157. Quickinfo:='';
  1158. ParaIncludePath:=TSearchPathList.Create;
  1159. ParaObjectPath:=TSearchPathList.Create;
  1160. ParaUnitPath:=TSearchPathList.Create;
  1161. ParaLibraryPath:=TSearchPathList.Create;
  1162. end;
  1163. destructor TOption.destroy;
  1164. begin
  1165. ParaIncludePath.Free;
  1166. ParaObjectPath.Free;
  1167. ParaUnitPath.Free;
  1168. ParaLibraryPath.Free;
  1169. end;
  1170. {****************************************************************************
  1171. Callable Routines
  1172. ****************************************************************************}
  1173. procedure read_arguments(cmd:string);
  1174. var
  1175. configpath : pathstr;
  1176. s : string;
  1177. i : integer;
  1178. begin
  1179. option:=coption.create;
  1180. disable_configfile:=false;
  1181. { default defines }
  1182. def_symbol(upper(target_info.shortname));
  1183. def_symbol('FPC');
  1184. def_symbol('VER'+version_nr);
  1185. def_symbol('VER'+version_nr+'_'+release_nr);
  1186. def_symbol('VER'+version_nr+'_'+release_nr+'_'+patch_nr);
  1187. {$ifdef newcg}
  1188. def_symbol('WITHNEWCG');
  1189. {$endif}
  1190. { Temporary defines, until things settle down }
  1191. {$ifdef SUPPORT_FIXED}
  1192. def_symbol('HASFIXED');
  1193. {$endif SUPPORT_FIXED}
  1194. def_symbol('HASWIDECHAR');
  1195. def_symbol('HASOUT');
  1196. def_symbol('HASINTF');
  1197. def_symbol('HASVARIANT');
  1198. def_symbol('INTERNSETLENGTH');
  1199. def_symbol('INT64FUNCRESOK');
  1200. def_symbol('PACKENUMFIXED');
  1201. def_symbol('HAS_ADDR_STACK_ON_STACK');
  1202. def_symbol('NOBOPUNDCHECK');
  1203. { some stuff for TP compatibility }
  1204. {$ifdef i386}
  1205. def_symbol('CPU86');
  1206. def_symbol('CPU87');
  1207. {$endif}
  1208. {$ifdef m68k}
  1209. def_symbol('CPU68');
  1210. {$endif}
  1211. { new processor stuff }
  1212. {$ifdef i386}
  1213. def_symbol('CPUI386');
  1214. {$endif}
  1215. {$ifdef m68k}
  1216. def_symbol('CPU68K');
  1217. {$endif}
  1218. {$ifdef ALPHA}
  1219. def_symbol('CPUALPHA');
  1220. {$endif}
  1221. {$ifdef powerpc}
  1222. def_symbol('CPUPOWERPC');
  1223. {$endif}
  1224. { get default messagefile }
  1225. {$ifdef Delphi}
  1226. msgfilename:=dmisc.getenv('PPC_ERROR_FILE');
  1227. {$else Delphi}
  1228. msgfilename:=dos.getenv('PPC_ERROR_FILE');
  1229. {$endif Delphi}
  1230. { default configfile }
  1231. if (cmd<>'') and (cmd[1]='[') then
  1232. begin
  1233. ppccfg:=Copy(cmd,2,pos(']',cmd)-2);
  1234. Delete(cmd,1,pos(']',cmd));
  1235. end
  1236. else
  1237. begin
  1238. {$ifdef i386}
  1239. ppccfg:='ppc386.cfg';
  1240. {$endif i386}
  1241. {$ifdef ia64}
  1242. ppccfg:='ppcia64.cfg';
  1243. {$endif ia64}
  1244. {$ifdef m68k}
  1245. ppccfg:='ppc68k.cfg';
  1246. {$endif}
  1247. {$ifdef alpha}
  1248. ppccfg:='ppcalpha.cfg';
  1249. {$endif}
  1250. {$ifdef powerpc}
  1251. ppccfg:='ppcppc.cfg';
  1252. {$endif}
  1253. end;
  1254. { Order to read ppc386.cfg:
  1255. 1 - current dir
  1256. 2 - configpath
  1257. 3 - compiler path }
  1258. {$ifdef Delphi}
  1259. configpath:=FixPath(dmisc.getenv('PPC_CONFIG_PATH'),false);
  1260. {$else Delphi}
  1261. configpath:=FixPath(dos.getenv('PPC_CONFIG_PATH'),false);
  1262. {$endif Delphi}
  1263. {$ifdef Unix}
  1264. if configpath='' then
  1265. configpath:='/etc/';
  1266. {$endif}
  1267. if ppccfg<>'' then
  1268. begin
  1269. read_configfile:=true;
  1270. if not FileExists(ppccfg) then
  1271. begin
  1272. {$ifdef Unix}
  1273. if (dos.getenv('HOME')<>'') and FileExists(FixPath(dos.getenv('HOME'),false)+'.'+ppccfg) then
  1274. ppccfg:=FixPath(dos.getenv('HOME'),false)+'.'+ppccfg
  1275. else
  1276. {$endif}
  1277. if FileExists(configpath+ppccfg) then
  1278. ppccfg:=configpath+ppccfg
  1279. else
  1280. {$ifndef Unix}
  1281. if FileExists(exepath+ppccfg) then
  1282. ppccfg:=exepath+ppccfg
  1283. else
  1284. {$endif}
  1285. read_configfile:=false;
  1286. end;
  1287. end
  1288. else
  1289. read_configfile:=false;
  1290. { Read commandline and configfile }
  1291. target_is_set:=false;
  1292. asm_is_set:=false;
  1293. param_file:='';
  1294. if read_configfile then
  1295. begin
  1296. { read the parameters quick, only -i -v -T }
  1297. option.firstpass:=true;
  1298. if cmd<>'' then
  1299. option.parsecmd(cmd)
  1300. else
  1301. begin
  1302. option.read_parameters;
  1303. { Write only quickinfo }
  1304. if option.quickinfo<>'' then
  1305. option.writequickinfo;
  1306. end;
  1307. { Read the configfile }
  1308. option.firstpass:=false;
  1309. if read_configfile then
  1310. option.interpret_file(ppccfg);
  1311. end;
  1312. if cmd<>'' then
  1313. option.parsecmd(cmd)
  1314. else
  1315. begin
  1316. option.read_parameters;
  1317. { Write only quickinfo }
  1318. if option.quickinfo<>'' then
  1319. option.writequickinfo;
  1320. end;
  1321. { Write help pages }
  1322. if (cmd='') and (paramcount=0) then
  1323. Option.WriteHelpPages;
  1324. { Stop if errors in options }
  1325. if ErrorCount>0 then
  1326. StopOptions;
  1327. { Non-core target defines }
  1328. s:=target_info.extradefines;
  1329. while (s<>'') do
  1330. begin
  1331. i:=pos(';',s);
  1332. if i=0 then
  1333. i:=length(s)+1;
  1334. def_symbol(Copy(s,1,i-1));
  1335. delete(s,1,i);
  1336. end;
  1337. { endian define }
  1338. case target_info.endian of
  1339. endian_little :
  1340. def_symbol('ENDIAN_LITTLE');
  1341. endian_big :
  1342. def_symbol('ENDIAN_BIG');
  1343. end;
  1344. { write logo if set }
  1345. if option.DoWriteLogo then
  1346. option.WriteLogo;
  1347. { Check file to compile }
  1348. if param_file='' then
  1349. begin
  1350. Message(option_no_source_found);
  1351. StopOptions;
  1352. end;
  1353. {$ifndef Unix}
  1354. param_file:=FixFileName(param_file);
  1355. {$endif}
  1356. fsplit(param_file,inputdir,inputfile,inputextension);
  1357. if inputextension='' then
  1358. begin
  1359. if FileExists(inputdir+inputfile+target_info.sourceext) then
  1360. inputextension:=target_info.sourceext
  1361. else
  1362. if FileExists(inputdir+inputfile+target_info.pasext) then
  1363. inputextension:=target_info.pasext;
  1364. end;
  1365. { Add paths specified with parameters to the searchpaths }
  1366. UnitSearchPath.AddList(option.ParaUnitPath,true);
  1367. ObjectSearchPath.AddList(option.ParaObjectPath,true);
  1368. IncludeSearchPath.AddList(option.ParaIncludePath,true);
  1369. LibrarySearchPath.AddList(option.ParaLibraryPath,true);
  1370. { add unit environment and exepath to the unit search path }
  1371. if inputdir<>'' then
  1372. Unitsearchpath.AddPath(inputdir,true);
  1373. if not disable_configfile then
  1374. {$ifdef Delphi}
  1375. UnitSearchPath.AddPath(dmisc.getenv(target_info.unit_env),false);
  1376. {$else}
  1377. UnitSearchPath.AddPath(dos.getenv(target_info.unit_env),false);
  1378. {$endif Delphi}
  1379. {$ifdef Unix}
  1380. fpcdir:=FixPath(getenv('FPCDIR'),false);
  1381. if fpcdir='' then
  1382. begin
  1383. if PathExists('/usr/local/lib/fpc/'+version_string) then
  1384. fpcdir:='/usr/local/lib/fpc/'+version_string+'/'
  1385. else
  1386. fpcdir:='/usr/lib/fpc/'+version_string+'/';
  1387. end;
  1388. {$else}
  1389. fpcdir:=FixPath(getenv('FPCDIR'),false);
  1390. if fpcdir='' then
  1391. begin
  1392. fpcdir:=ExePath+'../';
  1393. if not(PathExists(fpcdir+'/units')) and
  1394. not(PathExists(fpcdir+'/rtl')) then
  1395. fpcdir:=fpcdir+'../';
  1396. end;
  1397. {$endif}
  1398. { first try development RTL, else use the default installation path }
  1399. if not disable_configfile then
  1400. begin
  1401. if PathExists(FpcDir+'rtl/'+lower(target_info.shortname)) then
  1402. UnitSearchPath.AddPath(FpcDir+'rtl/'+lower(target_info.shortname),false)
  1403. else
  1404. begin
  1405. UnitSearchPath.AddPath(FpcDir+'units/'+lower(target_info.shortname),false);
  1406. UnitSearchPath.AddPath(FpcDir+'units/'+lower(target_info.shortname)+'/rtl',false);
  1407. end;
  1408. end;
  1409. { Add exepath if the exe is not in the current dir, because that is always searched already }
  1410. if ExePath<>GetCurrentDir then
  1411. UnitSearchPath.AddPath(ExePath,false);
  1412. { Add unit dir to the object and library path }
  1413. objectsearchpath.AddList(unitsearchpath,false);
  1414. librarysearchpath.AddList(unitsearchpath,false);
  1415. { switch assembler if it's binary and we got -a on the cmdline }
  1416. if (cs_asm_leave in initglobalswitches) and
  1417. (target_asm.outputbinary) then
  1418. begin
  1419. Message(option_switch_bin_to_src_assembler);
  1420. set_target_asm(target_info.assemextern);
  1421. end;
  1422. if (target_asm.supported_target <> target_any) and
  1423. (target_asm.supported_target <> target_info.target) then
  1424. begin
  1425. Message2(option_incompatible_asm,target_asm.idtxt,target_info.name);
  1426. set_target_asm(target_info.assemextern);
  1427. Message1(option_asm_forced,target_asm.idtxt);
  1428. end;
  1429. { turn off stripping if compiling with debuginfo or profile }
  1430. if (cs_debuginfo in initmoduleswitches) or
  1431. (cs_profile in initmoduleswitches) then
  1432. initglobalswitches:=initglobalswitches-[cs_link_strip];
  1433. if not LinkTypeSetExplicitly then
  1434. set_default_link_type;
  1435. { Set defines depending on the target }
  1436. if (target_info.target in [target_i386_GO32V1,target_i386_GO32V2]) then
  1437. def_symbol('DPMI'); { MSDOS is not defined in BP when target is DPMI }
  1438. option.free;
  1439. Option:=nil;
  1440. end;
  1441. initialization
  1442. coption:=toption;
  1443. finalization
  1444. if assigned(option) then
  1445. option.free;
  1446. end.
  1447. {
  1448. $Log$
  1449. Revision 1.44 2001-06-18 20:36:24 peter
  1450. * -Ur switch (merged)
  1451. * masm fixes (merged)
  1452. * quoted filenames for go32v2 and win32
  1453. Revision 1.43 2001/06/02 19:21:45 peter
  1454. * extradefines field added to target_info, so that targets don't
  1455. need to put code in options.pas for it
  1456. Revision 1.42 2001/05/18 22:28:59 peter
  1457. * endian define
  1458. Revision 1.41 2001/05/12 12:11:31 peter
  1459. * simplify_ppu is now the default, a recompile of the compiler now
  1460. only compiles pp.pas
  1461. Revision 1.40 2001/04/18 22:01:54 peter
  1462. * registration of targets and assemblers
  1463. Revision 1.39 2001/04/13 01:22:10 peter
  1464. * symtable change to classes
  1465. * range check generation and errors fixed, make cycle DEBUG=1 works
  1466. * memory leaks fixed
  1467. Revision 1.38 2001/03/25 12:27:31 peter
  1468. * fixed -Se (merged)
  1469. Revision 1.37 2001/03/23 00:16:07 florian
  1470. + some stuff to compile FreeCLX added
  1471. Revision 1.36 2001/03/13 20:59:56 peter
  1472. * message loading fixes from Sergey (merged)
  1473. Revision 1.35 2001/03/10 13:19:10 peter
  1474. * don't check messagefile for numbers, this allows the usage of
  1475. 1.1 msgfiles with a 1.0.x compiler
  1476. Revision 1.34 2001/03/05 21:50:29 peter
  1477. * press enter moved to errore.msg
  1478. Revision 1.33 2001/03/03 12:41:22 jonas
  1479. * simplified and optimized range checking code, FPC_BOUNDCHECK is no longer necessary
  1480. Revision 1.32 2001/02/26 19:44:53 peter
  1481. * merged generic m68k updates from fixes branch
  1482. Revision 1.31 2001/02/26 12:47:46 jonas
  1483. * fixed bug in type checking for compatibility of set elements (merged)
  1484. * released fix in options.pas from Carl also for FPC (merged)
  1485. Revision 1.30 2001/02/26 08:08:39 michael
  1486. * option_help_pages:
  1487. allow to omit an option (use one space char insteed an option)
  1488. but to indent a continuation line as if option is present. For lines:
  1489. 3*2CX_first line
  1490. 3*2 _second line
  1491. 3*2*_third line
  1492. we could get:
  1493. -CX first line
  1494. second line
  1495. third line
  1496. Revision 1.29 2001/02/26 07:49:50 michael
  1497. Support replacements for all -F<x> options
  1498. Revision 1.28 2001/02/05 21:26:36 peter
  1499. * applied patches from Sergey Korshunoff
  1500. Revision 1.27 2001/01/20 18:36:51 hajny
  1501. + APPTYPE support under OS/2, app_fs, GetEnvPChar for OS/2
  1502. Revision 1.26 2001/01/12 19:21:09 peter
  1503. * fixed writing of quickinfo when no ppc386.cfg is available
  1504. Revision 1.25 2001/01/05 17:36:57 florian
  1505. * the info about exception frames is stored now on the stack
  1506. instead on the heap
  1507. Revision 1.24 2000/12/25 00:07:26 peter
  1508. + new tlinkedlist class (merge of old tstringqueue,tcontainer and
  1509. tlinkedlist objects)
  1510. Revision 1.23 2000/12/24 12:21:41 peter
  1511. * use system.paramstr()
  1512. Revision 1.22 2000/12/23 19:46:49 peter
  1513. * object to class conversion
  1514. * more verbosity for -vt and -vd
  1515. * -i options can be put after eachother so the Makefiles only need
  1516. to call fpc once for all info (will be twice as the first one will
  1517. be to check the version if fpc supports multiple info)
  1518. Revision 1.21 2000/12/16 15:56:19 jonas
  1519. - removed all ifdef cardinalmulfix code
  1520. Revision 1.20 2000/12/15 13:26:01 jonas
  1521. * only return int64's from functions if it int64funcresok is defined
  1522. + added int64funcresok define to options.pas
  1523. Revision 1.19 2000/11/30 22:48:23 florian
  1524. * opts386 renamed
  1525. Revision 1.18 2000/11/29 00:30:34 florian
  1526. * unused units removed from uses clause
  1527. * some changes for widestrings
  1528. Revision 1.17 2000/11/13 15:26:12 marco
  1529. * Renamefest
  1530. Revision 1.16 2000/11/12 22:20:37 peter
  1531. * create generic toutputsection for binary writers
  1532. Revision 1.15 2000/11/07 15:09:27 marco
  1533. * Define UNIX for FreeBSD and Linux. Checked crosscompile thingy.
  1534. Revision 1.14 2000/11/07 14:25:08 marco
  1535. * FreeBSD defines (FreeBSD,Linux,BSD,Unix) Linux defines (Linux,Unix)
  1536. Revision 1.13 2000/11/06 20:30:54 peter
  1537. * more fixes to get make cycle working
  1538. Revision 1.12 2000/11/04 14:25:20 florian
  1539. + merged Attila's changes for interfaces, not tested yet
  1540. Revision 1.11 2000/09/26 10:50:41 jonas
  1541. * initmodeswitches is changed is you change the compiler mode from the
  1542. command line (the -S<x> switches didn't work anymore for changing the
  1543. compiler mode) (merged from fixes branch)
  1544. Revision 1.10 2000/09/24 21:33:47 peter
  1545. * message updates merges
  1546. Revision 1.9 2000/09/24 15:06:20 peter
  1547. * use defines.inc
  1548. Revision 1.8 2000/09/18 12:28:41 marco
  1549. * Definition of multiple FreeBSD target defines moved to after error check
  1550. commandline parsing
  1551. Revision 1.7 2000/09/16 12:22:52 peter
  1552. * freebsd support merged
  1553. Revision 1.6 2000/08/27 16:11:51 peter
  1554. * moved some util functions from globals,cobjects to cutils
  1555. * splitted files into finput,fmodule
  1556. Revision 1.5 2000/08/07 11:31:04 jonas
  1557. * fixed bug in type conversions between enum subranges (it didn't take
  1558. the packenum directive into account)
  1559. + define PACKENUMFIXED symbol in options.pas
  1560. (merged from fixes branch)
  1561. Revision 1.4 2000/07/14 05:11:48 michael
  1562. + Patch to 1.1
  1563. Revision 1.3 2000/07/13 12:08:26 michael
  1564. + patched to 1.1.0 with former 1.09patch from peter
  1565. Revision 1.2 2000/07/13 11:32:44 michael
  1566. + removed logs
  1567. }