options.pas 50 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603
  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. interface
  20. uses
  21. globtype,globals,verbose;
  22. type
  23. POption=^TOption;
  24. TOption=object
  25. FirstPass,
  26. NoPressEnter,
  27. DoWriteLogo : boolean;
  28. FileLevel : longint;
  29. ParaIncludePath,
  30. ParaUnitPath,
  31. ParaObjectPath,
  32. ParaLibraryPath : TSearchPathList;
  33. Constructor Init;
  34. Destructor Done;
  35. procedure WriteLogo;
  36. procedure WriteInfo;
  37. procedure WriteHelpPages;
  38. procedure QuickInfo(const s:string);
  39. procedure IllegalPara(const opt:string);
  40. function Unsetbool(const opts:string; pos: Longint):boolean;
  41. procedure interpret_proc_specific_options(const opt:string);virtual;
  42. procedure interpret_option(const opt :string;ispara:boolean);
  43. procedure Interpret_envvar(const envname : string);
  44. procedure Interpret_file(const filename : string);
  45. procedure Read_Parameters;
  46. procedure parsecmd(cmd:string);
  47. end;
  48. procedure read_arguments(cmd:string);
  49. implementation
  50. uses
  51. {$ifdef Delphi}
  52. dmisc,
  53. {$else Delphi}
  54. dos,
  55. {$endif Delphi}
  56. version,systems,
  57. cobjects,
  58. symtable,scanner,link,messages
  59. {$ifdef BrowserLog}
  60. ,browlog
  61. {$endif BrowserLog}
  62. {$ifdef i386}
  63. ,opts386
  64. {$endif}
  65. {$ifdef m68k}
  66. ,opts68k
  67. {$endif}
  68. ;
  69. const
  70. page_size = 24;
  71. var
  72. option : poption;
  73. read_configfile, { read config file, set when a cfgfile is found }
  74. disable_configfile,
  75. target_is_set : boolean; { do not allow contradictory target settings }
  76. asm_is_set : boolean; { -T also change initoutputformat if not set idrectly }
  77. fpcdir,
  78. ppccfg,
  79. msgfilename,
  80. param_file : string; { file to compile specified on the commandline }
  81. {****************************************************************************
  82. Defines
  83. ****************************************************************************}
  84. procedure def_symbol(const s : string);
  85. begin
  86. if s='' then
  87. exit;
  88. initdefines.concat(new(pstring_item,init(upper(s))));
  89. end;
  90. procedure undef_symbol(const s : string);
  91. var
  92. item,next : pstring_item;
  93. begin
  94. if s='' then
  95. exit;
  96. item:=pstring_item(initdefines.first);
  97. while assigned(item) do
  98. begin
  99. if (item^.str^=s) then
  100. begin
  101. next:=pstring_item(item^.next);
  102. initdefines.remove(item);
  103. dispose(item,done);
  104. item:=next;
  105. end
  106. else
  107. if item<>pstring_item(item^.next) then
  108. item:=pstring_item(item^.next)
  109. else
  110. break;
  111. end;
  112. end;
  113. function check_symbol(const s:string):boolean;
  114. var
  115. hp : pstring_item;
  116. begin
  117. hp:=pstring_item(initdefines.first);
  118. while assigned(hp) do
  119. begin
  120. if (hp^.str^=s) then
  121. begin
  122. check_symbol:=true;
  123. exit;
  124. end;
  125. hp:=pstring_item(hp^.next);
  126. end;
  127. check_symbol:=false;
  128. end;
  129. procedure MaybeLoadMessageFile;
  130. begin
  131. { Load new message file }
  132. if (msgfilename<>'') then
  133. begin
  134. if fileexists(msgfilename) then
  135. LoadMsgFile(msgfilename);
  136. msgfilename:='';
  137. end;
  138. end;
  139. {****************************************************************************
  140. Toption
  141. ****************************************************************************}
  142. procedure StopOptions;
  143. begin
  144. if assigned(Option) then
  145. begin
  146. dispose(Option,Done);
  147. Option:=nil;
  148. end;
  149. DoneVerbose;
  150. Stop;
  151. end;
  152. procedure Toption.WriteLogo;
  153. var
  154. i : tmsgconst;
  155. begin
  156. MaybeLoadMessageFile;
  157. for i:=option_logo_start to option_logo_end do
  158. Message1(i,target_cpu_string);
  159. end;
  160. procedure Toption.WriteInfo;
  161. var
  162. i : tmsgconst;
  163. begin
  164. MaybeLoadMessageFile;
  165. for i:=option_info_start to option_info_end do
  166. Message(i);
  167. StopOptions;
  168. end;
  169. procedure Toption.WriteHelpPages;
  170. function PadEnd(s:string;i:longint):string;
  171. begin
  172. while (length(s)<i) do
  173. s:=s+' ';
  174. PadEnd:=s;
  175. end;
  176. var
  177. idx,
  178. lastident,
  179. j,outline,
  180. ident,
  181. lines : longint;
  182. show : boolean;
  183. opt : string[32];
  184. input,
  185. s : string;
  186. begin
  187. MaybeLoadMessageFile;
  188. Message1(option_usage,paramstr(0));
  189. lastident:=0;
  190. if DoWriteLogo then
  191. lines:=3
  192. else
  193. lines:=1;
  194. for idx:=ord(ol_begin) to ord(ol_end) do
  195. begin
  196. { get a line and reset }
  197. s:=msg^.Get(idx);
  198. ident:=0;
  199. show:=false;
  200. { parse options }
  201. case s[1] of
  202. {$ifdef i386}
  203. '3',
  204. {$endif}
  205. {$ifdef m68k}
  206. '6',
  207. {$endif}
  208. '*' : show:=true;
  209. end;
  210. if show then
  211. begin
  212. case s[2] of
  213. {$ifdef TP}
  214. 't',
  215. {$endif}
  216. {$ifdef GDB}
  217. 'g',
  218. {$endif}
  219. {$ifdef linux}
  220. 'L',
  221. {$endif}
  222. {$ifdef os2}
  223. 'O',
  224. {$endif}
  225. '*' : show:=true;
  226. else
  227. show:=false;
  228. end;
  229. end;
  230. { now we may show the message or not }
  231. if show then
  232. begin
  233. case s[3] of
  234. '0' : begin
  235. ident:=0;
  236. outline:=0;
  237. end;
  238. '1' : begin
  239. ident:=2;
  240. outline:=7;
  241. end;
  242. '2' : begin
  243. ident:=11;
  244. outline:=11;
  245. end;
  246. '3' : begin
  247. ident:=21;
  248. outline:=6;
  249. end;
  250. end;
  251. j:=pos('_',s);
  252. opt:=Copy(s,4,j-4);
  253. if opt='*' then
  254. opt:=''
  255. else
  256. opt:=PadEnd('-'+opt,outline);
  257. if (ident=0) and (lastident<>0) then
  258. begin
  259. Comment(V_Normal,'');
  260. inc(Lines);
  261. end;
  262. { page full ? }
  263. if (lines>=page_size) then
  264. begin
  265. if not NoPressEnter then
  266. begin
  267. write('*** press enter ***');
  268. readln(input);
  269. if upper(input)='Q' then
  270. StopOptions;
  271. end;
  272. lines:=0;
  273. end;
  274. Comment(V_Normal,PadEnd('',ident)+opt+Copy(s,j+1,255));
  275. LastIdent:=Ident;
  276. inc(Lines);
  277. end;
  278. end;
  279. StopOptions;
  280. end;
  281. procedure Toption.QuickInfo(const s:string);
  282. begin
  283. if source_os.newline=#13#10 then
  284. Write(s+#10)
  285. else
  286. Writeln(s);
  287. StopOptions;
  288. end;
  289. procedure Toption.IllegalPara(const opt:string);
  290. begin
  291. Message1(option_illegal_para,opt);
  292. Message(option_help_pages_para);
  293. StopOptions;
  294. end;
  295. function Toption.Unsetbool(const opts:string; pos: Longint):boolean;
  296. { checks if the character after pos in Opts is a + or a - and returns resp.
  297. false or true. If it is another character (or none), it also returns false }
  298. begin
  299. UnsetBool := (Length(Opts) > Pos) And (Opts[Succ(Pos)] = '-');
  300. end;
  301. procedure TOption.interpret_proc_specific_options(const opt:string);
  302. begin
  303. end;
  304. procedure TOption.interpret_option(const opt:string;ispara:boolean);
  305. var
  306. code : integer;
  307. c : char;
  308. more : string;
  309. major,minor : longint;
  310. error : integer;
  311. j,l : longint;
  312. d : DirStr;
  313. e : ExtStr;
  314. begin
  315. if opt='' then
  316. exit;
  317. { only parse define,undef,target,verbosity and link options the firsttime }
  318. if firstpass and
  319. not((opt[1]='-') and (opt[2] in ['i','d','v','T','u','n','X'])) then
  320. exit;
  321. case opt[1] of
  322. '-' : begin
  323. more:=Copy(opt,3,255);
  324. case opt[2] of
  325. '!' : initlocalswitches:=initlocalswitches+[cs_ansistrings];
  326. '?' : WriteHelpPages;
  327. 'a' : begin
  328. initglobalswitches:=initglobalswitches+[cs_asm_leave];
  329. for j:=1 to length(more) do
  330. case more[j] of
  331. 'l' : initglobalswitches:=initglobalswitches+[cs_asm_source];
  332. 'r' : initglobalswitches:=initglobalswitches+[cs_asm_regalloc];
  333. 't' : initglobalswitches:=initglobalswitches+[cs_asm_tempalloc];
  334. '-' : initglobalswitches:=initglobalswitches-[cs_asm_leave,cs_asm_source,cs_asm_regalloc];
  335. else
  336. IllegalPara(opt);
  337. end;
  338. end;
  339. 'A' : begin
  340. if set_string_asm(More) then
  341. begin
  342. initoutputformat:=target_asm.id;
  343. asm_is_set:=true;
  344. end
  345. else
  346. IllegalPara(opt);
  347. end;
  348. 'b' : begin
  349. {$ifdef BrowserLog}
  350. initglobalswitches:=initglobalswitches+[cs_browser_log];
  351. {$endif}
  352. if More<>'' then
  353. if More='l' then
  354. initmoduleswitches:=initmoduleswitches+[cs_local_browser]
  355. else if More='-' then
  356. begin
  357. initmoduleswitches:=initmoduleswitches-[cs_browser,cs_local_browser];
  358. {$ifdef BrowserLog}
  359. initglobalswitches:=initglobalswitches-[cs_browser_log];
  360. {$endif}
  361. end
  362. else if More<>'+' then
  363. {$ifdef BrowserLog}
  364. browserlog.elements_to_list^.insert(more);
  365. {$else}
  366. IllegalPara(opt);
  367. {$endif}
  368. end;
  369. 'B' : if more='' then
  370. do_build:=true
  371. else
  372. if more = '-' then
  373. do_build := False
  374. else
  375. IllegalPara(opt);
  376. 'C' : begin
  377. j := 1;
  378. while j <= length(more) Do
  379. Begin
  380. case more[j] of
  381. 'a' : Simplify_ppu:=true;
  382. 'h' :
  383. begin
  384. val(copy(more,j+1,length(more)-j),heapsize,code);
  385. if (code<>0) or (heapsize>=67107840) or (heapsize<1024) then
  386. IllegalPara(opt);
  387. break;
  388. end;
  389. 'i' : If UnsetBool(More, j) then
  390. Begin
  391. initlocalswitches:=initlocalswitches-[cs_check_io];
  392. inc(j)
  393. End
  394. else initlocalswitches:=initlocalswitches+[cs_check_io];
  395. 'n' : If UnsetBool(More, j) then
  396. Begin
  397. initglobalswitches:=initglobalswitches-[cs_link_extern];
  398. inc(j)
  399. End
  400. Else initglobalswitches:=initglobalswitches+[cs_link_extern];
  401. 'o' :
  402. If UnsetBool(More, j) then
  403. Begin
  404. initlocalswitches:=initlocalswitches-[cs_check_overflow];
  405. inc(j);
  406. End
  407. Else
  408. initlocalswitches:=initlocalswitches+[cs_check_overflow];
  409. 'r' :
  410. If UnsetBool(More, j) then
  411. Begin
  412. initlocalswitches:=initlocalswitches-[cs_check_range];
  413. inc(j);
  414. End
  415. Else
  416. initlocalswitches:=initlocalswitches+[cs_check_range];
  417. 'R' :
  418. If UnsetBool(More, j) then
  419. Begin
  420. initlocalswitches:=initlocalswitches-[cs_check_object_ext];
  421. inc(j);
  422. End
  423. Else
  424. initlocalswitches:=initlocalswitches+[cs_check_object_ext];
  425. 's' :
  426. begin
  427. val(copy(more,j+1,length(more)-j),stacksize,code);
  428. if (code<>0) or (stacksize>=67107840) or (stacksize<1024) then
  429. IllegalPara(opt);
  430. break;
  431. end;
  432. 't' :
  433. If UnsetBool(More, j) then
  434. Begin
  435. initlocalswitches:=initlocalswitches-[cs_check_stack];
  436. inc(j)
  437. End
  438. Else
  439. initlocalswitches:=initlocalswitches+[cs_check_stack];
  440. 'D' :
  441. If UnsetBool(More, j) then
  442. Begin
  443. initmoduleswitches:=initmoduleswitches-[cs_create_dynamic];
  444. inc(j)
  445. End
  446. Else
  447. initmoduleswitches:=initmoduleswitches+[cs_create_dynamic];
  448. 'X' :
  449. If UnsetBool(More, j) then
  450. Begin
  451. initmoduleswitches:=initmoduleswitches-[cs_create_smart];
  452. inc(j)
  453. End
  454. Else
  455. initmoduleswitches:=initmoduleswitches+[cs_create_smart];
  456. else
  457. IllegalPara(opt);
  458. end;
  459. inc(j);
  460. end;
  461. end;
  462. 'd' : def_symbol(more);
  463. 'D' : begin
  464. initglobalswitches:=initglobalswitches+[cs_link_deffile];
  465. for j:=1 to length(more) do
  466. case more[j] of
  467. 'd' : begin
  468. description:=Copy(more,j+1,255);
  469. break;
  470. end;
  471. 'v' : begin
  472. dllversion:=Copy(more,j+1,255);
  473. l:=pos('.',dllversion);
  474. dllminor:=0;
  475. error:=0;
  476. if l>0 then
  477. begin
  478. valint(copy(dllversion,l+1,255),minor,error);
  479. if (error=0) and
  480. (minor>=0) and (minor<=$ffff) then
  481. dllminor:=minor
  482. else if error=0 then
  483. error:=1;
  484. end;
  485. if l=0 then l:=256;
  486. dllmajor:=1;
  487. if error=0 then
  488. valint(copy(dllversion,1,l-1),major,error);
  489. if (error=0) and (major>=0) and (major<=$ffff) then
  490. dllmajor:=major
  491. else if error=0 then
  492. error:=1;
  493. if error<>0 then
  494. Message1(scan_w_wrong_version_ignored,dllversion);
  495. break;
  496. end;
  497. 'w' : usewindowapi:=true;
  498. else
  499. IllegalPara(opt);
  500. end;
  501. end;
  502. 'e' : exepath:=FixPath(More,true);
  503. { Just used by RHIDE }
  504. 'E' : if (length(more)=0) or (UnsetBool(More, 0)) then
  505. initglobalswitches:=initglobalswitches+[cs_link_extern]
  506. else
  507. initglobalswitches:=initglobalswitches-[cs_link_extern];
  508. 'F' : begin
  509. c:=more[1];
  510. Delete(more,1,1);
  511. case c of
  512. 'D' : begin
  513. if not ispara then
  514. DefaultReplacements(More);
  515. utilsdirectory:=FixPath(More,true);
  516. end;
  517. 'e' : SetRedirectFile(More);
  518. 'E' : OutputExeDir:=FixPath(More,true);
  519. 'i' : if ispara then
  520. ParaIncludePath.AddPath(More,false)
  521. else
  522. includesearchpath.AddPath(More,true);
  523. 'g' : Message2(option_obsolete_switch_use_new,'-Fg','-Fl');
  524. 'l' : if ispara then
  525. ParaLibraryPath.AddPath(More,false)
  526. else
  527. LibrarySearchPath.AddPath(More,true);
  528. 'L' : if More<>'' then
  529. ParaDynamicLinker:=More
  530. else
  531. IllegalPara(opt);
  532. 'o' : if ispara then
  533. ParaObjectPath.AddPath(More,false)
  534. else
  535. ObjectSearchPath.AddPath(More,true);
  536. 'r' : Msgfilename:=More;
  537. 'u' : if ispara then
  538. ParaUnitPath.AddPath(More,false)
  539. else
  540. unitsearchpath.AddPath(More,true);
  541. 'U' : OutputUnitDir:=FixPath(More,true);
  542. else
  543. IllegalPara(opt);
  544. end;
  545. end;
  546. 'g' : begin
  547. if UnsetBool(More, 0) then
  548. begin
  549. initmoduleswitches:=initmoduleswitches-[cs_debuginfo];
  550. if (length(More)>1) and (More[2]='l') then
  551. initglobalswitches:=initglobalswitches+[cs_gdb_lineinfo];
  552. end
  553. else
  554. begin
  555. {$ifdef GDB}
  556. initmoduleswitches:=initmoduleswitches+[cs_debuginfo];
  557. if not RelocSectionSetExplicitly then
  558. RelocSection:=false;
  559. for j:=1 to length(more) do
  560. case more[j] of
  561. 'd' : initglobalswitches:=initglobalswitches+[cs_gdb_dbx];
  562. 'g' : initglobalswitches:=initglobalswitches+[cs_gdb_gsym];
  563. 'h' : initglobalswitches:=initglobalswitches+[cs_gdb_heaptrc];
  564. 'l' : initglobalswitches:=initglobalswitches+[cs_gdb_lineinfo];
  565. 'c' : initglobalswitches:=initglobalswitches+[cs_checkpointer];
  566. {$ifdef EXTDEBUG}
  567. 'p' : only_one_pass:=true;
  568. {$endif EXTDEBUG}
  569. else
  570. IllegalPara(opt);
  571. end;
  572. {$else GDB}
  573. Message(option_no_debug_support);
  574. Message(option_no_debug_support_recompile_fpc);
  575. {$endif GDB}
  576. end;
  577. end;
  578. 'h' : begin
  579. NoPressEnter:=true;
  580. WriteHelpPages;
  581. end;
  582. 'i' : if more='' then
  583. WriteInfo
  584. else
  585. begin
  586. { Specific info, which can be used in Makefiles }
  587. case More[1] of
  588. 'S' : begin
  589. case More[2] of
  590. 'O' : QuickInfo(source_os.shortname);
  591. {$ifdef Delphi !!!!!!!!!}
  592. 'P' : QuickInfo('unknown');
  593. {$else}
  594. 'P' : QuickInfo(source_cpu_string);
  595. {$endif}
  596. end;
  597. end;
  598. 'T' : begin
  599. case More[2] of
  600. 'O' : QuickInfo(target_os.shortname);
  601. 'P' : QuickInfo(target_cpu_string);
  602. end;
  603. end;
  604. 'V' : QuickInfo(version_string);
  605. 'D' : QuickInfo(date_string);
  606. else
  607. IllegalPara(Opt);
  608. end;
  609. end;
  610. 'I' : if ispara then
  611. ParaIncludePath.AddPath(More,false)
  612. else
  613. includesearchpath.AddPath(More,false);
  614. 'k' : if more<>'' then
  615. ParaLinkOptions:=ParaLinkOptions+' '+More
  616. else
  617. IllegalPara(opt);
  618. 'l' : if more='' then
  619. DoWriteLogo:=true
  620. else
  621. IllegalPara(opt);
  622. 'm' : parapreprocess:=true;
  623. 'n' : if More='' then
  624. begin
  625. read_configfile:=false;
  626. disable_configfile:=true;
  627. end
  628. else
  629. IllegalPara(opt);
  630. 'o' : if More<>'' then
  631. Fsplit(More,d,OutputFile,e)
  632. else
  633. IllegalPara(opt);
  634. 'p' : begin
  635. if UnsetBool(More, 0) then
  636. begin
  637. initmoduleswitches:=initmoduleswitches-[cs_profile];
  638. undef_symbol('FPC_PROFILE');
  639. end
  640. else
  641. case more[1] of
  642. 'g' : if (length(opt)=3) and UnsetBool(more, 1) then
  643. begin
  644. initmoduleswitches:=initmoduleswitches-[cs_profile];
  645. undef_symbol('FPC_PROFILE');
  646. end
  647. else
  648. begin
  649. initmoduleswitches:=initmoduleswitches+[cs_profile];
  650. def_symbol('FPC_PROFILE');
  651. end;
  652. else
  653. IllegalPara(opt);
  654. end;
  655. end;
  656. {$ifdef linux}
  657. 'P' : initglobalswitches:=initglobalswitches+[cs_asm_pipe];
  658. {$endif}
  659. 's' : initglobalswitches:=initglobalswitches+[cs_asm_extern,cs_link_extern];
  660. 'S' : begin
  661. for j:=1 to length(more) do
  662. case more[j] of
  663. '2' : initmodeswitches:=objfpcmodeswitches;
  664. 'a' : initlocalswitches:=InitLocalswitches+[cs_do_assertion];
  665. 'c' : initmoduleswitches:=initmoduleswitches+[cs_support_c_operators];
  666. 'd' : initmodeswitches:=delphimodeswitches;
  667. 'e' : begin
  668. SetErrorFlags(more);
  669. break;
  670. end;
  671. 'g' : initmoduleswitches:=initmoduleswitches+[cs_support_goto];
  672. 'h' : initlocalswitches:=initlocalswitches+[cs_ansistrings];
  673. 'i' : initmoduleswitches:=initmoduleswitches+[cs_support_inline];
  674. 'm' : initmoduleswitches:=initmoduleswitches+[cs_support_macro];
  675. 'o': initmodeswitches:=tpmodeswitches;
  676. 'p' : initmodeswitches:=gpcmodeswitches;
  677. 's' : initglobalswitches:=initglobalswitches+[cs_constructor_name];
  678. 't' : initmoduleswitches:=initmoduleswitches+[cs_static_keyword];
  679. 'v' : Message1(option_obsolete_switch,'-Sv');
  680. else
  681. IllegalPara(opt);
  682. end;
  683. end;
  684. 'T' : begin
  685. more:=Upper(More);
  686. if not target_is_set then
  687. begin
  688. { remove old target define }
  689. undef_symbol(target_info.short_name);
  690. { load new target }
  691. if not(set_string_target(More)) then
  692. IllegalPara(opt);
  693. { set new define }
  694. def_symbol(target_info.short_name);
  695. if not asm_is_set then
  696. initoutputformat:=target_asm.id;
  697. target_is_set:=true;
  698. end
  699. else
  700. if More<>target_info.short_name then
  701. Message1(option_target_is_already_set,target_info.short_name);
  702. end;
  703. 'u' : undef_symbol(upper(More));
  704. 'U' : begin
  705. for j:=1 to length(more) do
  706. case more[j] of
  707. {$ifdef UNITALIASES}
  708. 'a' : begin
  709. AddUnitAlias(Copy(More,j+1,255));
  710. break;
  711. end;
  712. {$endif UNITALIASES}
  713. 'n' : initglobalswitches:=initglobalswitches-[cs_check_unit_name];
  714. 'p' : begin
  715. Message2(option_obsolete_switch_use_new,'-Up','-Fu');
  716. break;
  717. end;
  718. 's' : initmoduleswitches:=initmoduleswitches+[cs_compilesystem];
  719. else
  720. IllegalPara(opt);
  721. end;
  722. end;
  723. 'v' : if not setverbosity(More) then
  724. IllegalPara(opt);
  725. 'W' : begin
  726. for j:=1 to length(More) do
  727. case More[j] of
  728. 'B': {bind_win32_dll:=true}
  729. begin
  730. { -WB200000 means set prefered base address
  731. to $200000, but does not change relocsection boolean
  732. this way we can create both relocatble and
  733. non relocatable DLL at a specific base address PM }
  734. if (length(More)>j) then
  735. begin
  736. if DLLImageBase=nil then
  737. DLLImageBase:=StringDup(Copy(More,j+1,255));
  738. end
  739. else
  740. begin
  741. RelocSection:=true;
  742. RelocSectionSetExplicitly:=true;
  743. end;
  744. break;
  745. end;
  746. 'C': apptype:=at_cui;
  747. 'D': ForceDeffileForExport:=true;
  748. 'G': apptype:=at_gui;
  749. 'N': begin
  750. RelocSection:=false;
  751. RelocSectionSetExplicitly:=true;
  752. end;
  753. 'R': begin
  754. RelocSection:=true;
  755. RelocSectionSetExplicitly:=true;
  756. end;
  757. else
  758. IllegalPara(opt);
  759. end;
  760. end;
  761. 'X' : begin
  762. for j:=1 to length(More) do
  763. case More[j] of
  764. 'c' : initglobalswitches:=initglobalswitches+[cs_link_toc];
  765. 's' : initglobalswitches:=initglobalswitches+[cs_link_strip];
  766. 't' : initglobalswitches:=initglobalswitches+[cs_link_staticflag];
  767. 'D' : begin
  768. def_symbol('FPC_LINK_DYNAMIC');
  769. undef_symbol('FPC_LINK_SMART');
  770. undef_symbol('FPC_LINK_STATIC');
  771. initglobalswitches:=initglobalswitches+[cs_link_shared];
  772. initglobalswitches:=initglobalswitches-[cs_link_static,cs_link_smart];
  773. LinkTypeSetExplicitly:=true;
  774. end;
  775. 'S' : begin
  776. def_symbol('FPC_LINK_STATIC');
  777. undef_symbol('FPC_LINK_SMART');
  778. undef_symbol('FPC_LINK_DYNAMIC');
  779. initglobalswitches:=initglobalswitches+[cs_link_static];
  780. initglobalswitches:=initglobalswitches-[cs_link_shared,cs_link_smart];
  781. LinkTypeSetExplicitly:=true;
  782. end;
  783. 'X' : begin
  784. def_symbol('FPC_LINK_SMART');
  785. undef_symbol('FPC_LINK_STATIC');
  786. undef_symbol('FPC_LINK_DYNAMIC');
  787. initglobalswitches:=initglobalswitches+[cs_link_smart];
  788. initglobalswitches:=initglobalswitches-[cs_link_shared,cs_link_static];
  789. LinkTypeSetExplicitly:=true;
  790. end;
  791. else
  792. IllegalPara(opt);
  793. end;
  794. end;
  795. { give processor specific options a chance }
  796. else
  797. interpret_proc_specific_options(opt);
  798. end;
  799. end;
  800. '@' : begin
  801. Message(option_no_nested_response_file);
  802. StopOptions;
  803. end;
  804. else
  805. begin
  806. if (length(param_file)<>0) then
  807. Message(option_only_one_source_support);
  808. param_file:=opt;
  809. end;
  810. end;
  811. end;
  812. procedure Toption.Interpret_file(const filename : string);
  813. procedure RemoveSep(var fn:string);
  814. var
  815. i : longint;
  816. begin
  817. i:=0;
  818. while (i<length(fn)) and (fn[i+1] in [',',' ',#9]) do
  819. inc(i);
  820. Delete(fn,1,i);
  821. i:=length(fn);
  822. while (i>0) and (fn[i] in [',',' ',#9]) do
  823. dec(i);
  824. fn:=copy(fn,1,i);
  825. end;
  826. function GetName(var fn:string):string;
  827. var
  828. i : longint;
  829. begin
  830. i:=0;
  831. while (i<length(fn)) and (fn[i+1] in ['a'..'z','A'..'Z','0'..'9','_','-']) do
  832. inc(i);
  833. GetName:=Copy(fn,1,i);
  834. Delete(fn,1,i);
  835. end;
  836. const
  837. maxlevel=16;
  838. var
  839. f : text;
  840. s,
  841. opts : string;
  842. skip : array[0..maxlevel-1] of boolean;
  843. level : longint;
  844. option_read : boolean;
  845. begin
  846. { avoid infinite loop }
  847. Inc(FileLevel);
  848. Option_read:=false;
  849. If FileLevel>MaxLevel then
  850. Message(option_too_many_cfg_files);
  851. { open file }
  852. assign(f,filename);
  853. {$ifdef extdebug}
  854. Comment(V_Info,'trying to open file: '+filename);
  855. {$endif extdebug}
  856. {$I-}
  857. reset(f);
  858. {$I+}
  859. if ioresult<>0 then
  860. begin
  861. Message1(option_unable_open_file,filename);
  862. exit;
  863. end;
  864. fillchar(skip,sizeof(skip),0);
  865. level:=0;
  866. while not eof(f) do
  867. begin
  868. readln(f,opts);
  869. RemoveSep(opts);
  870. if (opts<>'') and (opts[1]<>';') then
  871. begin
  872. if opts[1]='#' then
  873. begin
  874. Delete(opts,1,1);
  875. s:=upper(GetName(opts));
  876. if (s='SECTION') then
  877. begin
  878. RemoveSep(opts);
  879. s:=upper(GetName(opts));
  880. if level=0 then
  881. skip[level]:=not (check_symbol(s) or (s='COMMON'));
  882. end
  883. else
  884. if (s='IFDEF') then
  885. begin
  886. RemoveSep(opts);
  887. if Level>=maxlevel then
  888. begin
  889. Message(option_too_many_ifdef);
  890. stopOptions;
  891. end;
  892. inc(Level);
  893. skip[level]:=(skip[level-1] or (not check_symbol(upper(GetName(opts)))));
  894. end
  895. else
  896. if (s='IFNDEF') then
  897. begin
  898. RemoveSep(opts);
  899. if Level>=maxlevel then
  900. begin
  901. Message(option_too_many_ifdef);
  902. stopOptions;
  903. end;
  904. inc(Level);
  905. skip[level]:=(skip[level-1] or (check_symbol(upper(GetName(opts)))));
  906. end
  907. else
  908. if (s='ELSE') then
  909. skip[level]:=skip[level-1] or (not skip[level])
  910. else
  911. if (s='ENDIF') then
  912. begin
  913. skip[level]:=false;
  914. if Level=0 then
  915. begin
  916. Message(option_too_many_endif);
  917. stopOptions;
  918. end;
  919. dec(level);
  920. end
  921. else
  922. if (not skip[level]) then
  923. begin
  924. if (s='DEFINE') then
  925. begin
  926. RemoveSep(opts);
  927. def_symbol(upper(GetName(opts)));
  928. end
  929. else
  930. if (s='UNDEF') then
  931. begin
  932. RemoveSep(opts);
  933. undef_symbol(upper(GetName(opts)));
  934. end
  935. else
  936. if (s='WRITE') then
  937. begin
  938. Delete(opts,1,1);
  939. WriteLn(opts);
  940. end
  941. else
  942. if (s='INCLUDE') then
  943. begin
  944. Delete(opts,1,1);
  945. Interpret_file(opts);
  946. end;
  947. end;
  948. end
  949. else
  950. begin
  951. if (opts[1]='-') then
  952. begin
  953. if (not skip[level]) then
  954. interpret_option(opts,false);
  955. Option_read:=true;
  956. end
  957. else
  958. Message1(option_illegal_para,opts);
  959. end;
  960. end;
  961. end;
  962. if Level>0 then
  963. Message(option_too_less_endif);
  964. if Not Option_read then
  965. Message1(option_no_option_found,filename);
  966. Close(f);
  967. Dec(FileLevel);
  968. end;
  969. procedure Toption.Interpret_envvar(const envname : string);
  970. var
  971. argstart,
  972. env,
  973. pc : pchar;
  974. arglen : longint;
  975. quote : set of char;
  976. hs : string;
  977. begin
  978. env:=GetEnvPChar(envname);
  979. pc:=env;
  980. if assigned(pc) then
  981. begin
  982. repeat
  983. { skip leading spaces }
  984. while pc^ in [' ',#9,#13] do
  985. inc(pc);
  986. case pc^ of
  987. #0 :
  988. break;
  989. '"' :
  990. begin
  991. quote:=['"'];
  992. inc(pc);
  993. end;
  994. '''' :
  995. begin
  996. quote:=[''''];
  997. inc(pc);
  998. end;
  999. else
  1000. quote:=[' ',#9,#13];
  1001. end;
  1002. { scan until the end of the argument }
  1003. argstart:=pc;
  1004. while (pc^<>#0) and not(pc^ in quote) do
  1005. inc(pc);
  1006. { create argument }
  1007. arglen:=pc-argstart;
  1008. hs[0]:=chr(arglen);
  1009. move(argstart^,hs[1],arglen);
  1010. interpret_option(hs,true);
  1011. { skip quote }
  1012. if pc^ in quote then
  1013. inc(pc);
  1014. until false;
  1015. end
  1016. else
  1017. Message1(option_no_option_found,'(env) '+envname);
  1018. FreeEnvPChar(env);
  1019. end;
  1020. procedure toption.read_parameters;
  1021. var
  1022. opts : string;
  1023. paramindex : longint;
  1024. begin
  1025. paramindex:=0;
  1026. while paramindex<paramcount do
  1027. begin
  1028. inc(paramindex);
  1029. opts:=paramstr(paramindex);
  1030. case opts[1] of
  1031. '@' :
  1032. begin
  1033. Delete(opts,1,1);
  1034. if not firstpass then
  1035. Message1(option_reading_further_from,opts);
  1036. interpret_file(opts);
  1037. end;
  1038. '!' :
  1039. begin
  1040. Delete(opts,1,1);
  1041. if not firstpass then
  1042. Message1(option_reading_further_from,'(env) '+opts);
  1043. interpret_envvar(opts);
  1044. end;
  1045. else
  1046. interpret_option(opts,true);
  1047. end;
  1048. end;
  1049. end;
  1050. procedure toption.parsecmd(cmd:string);
  1051. var
  1052. i,ps : longint;
  1053. opts : string;
  1054. begin
  1055. while (cmd<>'') do
  1056. begin
  1057. while cmd[1]=' ' do
  1058. delete(cmd,1,1);
  1059. i:=pos(' ',cmd);
  1060. if i=0 then
  1061. i:=256;
  1062. opts:=Copy(cmd,1,i-1);
  1063. Delete(cmd,1,i);
  1064. case opts[1] of
  1065. '@' :
  1066. begin
  1067. Delete(opts,1,1);
  1068. if not firstpass then
  1069. Message1(option_reading_further_from,opts);
  1070. interpret_file(opts);
  1071. end;
  1072. '!' :
  1073. begin
  1074. Delete(opts,1,1);
  1075. if not firstpass then
  1076. Message1(option_reading_further_from,'(env) '+opts);
  1077. interpret_envvar(opts);
  1078. end;
  1079. '"' :
  1080. begin
  1081. Delete(opts,1,1);
  1082. ps:=pos('"',cmd);
  1083. if (i<>256) and (ps>0) then
  1084. begin
  1085. opts:=opts + ' '+ copy(cmd,1,ps-1);
  1086. cmd:=copy(cmd,ps+1,255);
  1087. end;
  1088. interpret_option(opts,true);
  1089. end;
  1090. else
  1091. interpret_option(opts,true);
  1092. end;
  1093. end;
  1094. end;
  1095. constructor TOption.Init;
  1096. begin
  1097. DoWriteLogo:=false;
  1098. NoPressEnter:=false;
  1099. FirstPass:=false;
  1100. FileLevel:=0;
  1101. ParaIncludePath.Init;
  1102. ParaObjectPath.Init;
  1103. ParaUnitPath.Init;
  1104. ParaLibraryPath.Init;
  1105. end;
  1106. destructor TOption.Done;
  1107. begin
  1108. ParaIncludePath.Done;
  1109. ParaObjectPath.Done;
  1110. ParaUnitPath.Done;
  1111. ParaLibraryPath.Done;
  1112. end;
  1113. {****************************************************************************
  1114. Callable Routines
  1115. ****************************************************************************}
  1116. procedure read_arguments(cmd:string);
  1117. var
  1118. configpath : pathstr;
  1119. begin
  1120. {$ifdef Delphi}
  1121. option:=new(poption386,Init);
  1122. {$endif Delphi}
  1123. {$ifdef i386}
  1124. option:=new(poption386,Init);
  1125. {$endif}
  1126. {$ifdef m68k}
  1127. option:=new(poption68k,Init);
  1128. {$endif}
  1129. {$ifdef alpha}
  1130. option:=new(poption,Init);
  1131. {$endif}
  1132. {$ifdef powerpc}
  1133. option:=new(poption,Init);
  1134. {$endif}
  1135. { Load messages }
  1136. if (cmd='') and (paramcount=0) then
  1137. Option^.WriteHelpPages;
  1138. disable_configfile:=false;
  1139. { default defines }
  1140. def_symbol(target_info.short_name);
  1141. def_symbol('FPK');
  1142. def_symbol('FPC');
  1143. def_symbol('VER'+version_nr);
  1144. def_symbol('VER'+version_nr+'_'+release_nr);
  1145. def_symbol('VER'+version_nr+'_'+release_nr+'_'+patch_nr);
  1146. {$ifdef newcg}
  1147. def_symbol('WITHNEWCG');
  1148. {$endif}
  1149. { Temporary defines, until things settle down }
  1150. def_symbol('INT64');
  1151. def_symbol('HASRESOURCESTRINGS');
  1152. def_symbol('HASSAVEREGISTERS');
  1153. def_symbol('NEWVMTOFFSET');
  1154. def_symbol('HASINTERNMATH');
  1155. def_symbol('SYSTEMTVARREC');
  1156. def_symbol('INCLUDEOK');
  1157. def_symbol('NEWMM');
  1158. def_symbol('HASWIDECHAR');
  1159. {$ifdef SUPPORT_FIXED}
  1160. def_symbol('HASFIXED');
  1161. {$endif SUPPORT_FIXED}
  1162. {$ifdef cardinalmulfix}
  1163. { for the compiler }
  1164. def_symbol('CARDINALMULFIX');
  1165. { for the RTL }
  1166. def_symbol('CARDINALMULFIXED');
  1167. {$endif cardinalmulfix}
  1168. def_symbol('CORRECTFLDCW');
  1169. def_symbol('ENHANCEDRAISE');
  1170. { some stuff for TP compatibility }
  1171. {$ifdef i386}
  1172. def_symbol('CPU86');
  1173. def_symbol('CPU87');
  1174. {$endif}
  1175. {$ifdef m68k}
  1176. def_symbol('CPU68');
  1177. {$endif}
  1178. { new processor stuff }
  1179. {$ifdef i386}
  1180. def_symbol('CPUI386');
  1181. {$endif}
  1182. {$ifdef m68k}
  1183. def_symbol('CPU68K');
  1184. {$endif}
  1185. {$ifdef ALPHA}
  1186. def_symbol('CPUALPHA');
  1187. {$endif}
  1188. {$ifdef powerpc}
  1189. def_symbol('CPUPOWERPC');
  1190. {$endif}
  1191. { get default messagefile }
  1192. {$ifdef Delphi}
  1193. msgfilename:=dmisc.getenv('PPC_ERROR_FILE');
  1194. {$else Delphi}
  1195. msgfilename:=dos.getenv('PPC_ERROR_FILE');
  1196. {$endif Delphi}
  1197. { default configfile }
  1198. if (cmd<>'') and (cmd[1]='[') then
  1199. begin
  1200. ppccfg:=Copy(cmd,2,pos(']',cmd)-2);
  1201. Delete(cmd,1,pos(']',cmd));
  1202. end
  1203. else
  1204. begin
  1205. {$ifdef i386}
  1206. ppccfg:='ppc386.cfg';
  1207. {$endif i386}
  1208. {$ifdef m68k}
  1209. ppccfg:='ppc.cfg';
  1210. {$endif}
  1211. {$ifdef alpha}
  1212. ppccfg:='ppcalpha.cfg';
  1213. {$endif}
  1214. {$ifdef powerpc}
  1215. ppccfg:='ppcppc.cfg';
  1216. {$endif}
  1217. end;
  1218. { Order to read ppc386.cfg:
  1219. 1 - current dir
  1220. 2 - configpath
  1221. 3 - compiler path }
  1222. {$ifdef Delphi}
  1223. configpath:=FixPath(dmisc.getenv('PPC_CONFIG_PATH'),false);
  1224. {$else Delphi}
  1225. configpath:=FixPath(dos.getenv('PPC_CONFIG_PATH'),false);
  1226. {$endif Delphi}
  1227. {$ifdef linux}
  1228. if configpath='' then
  1229. configpath:='/etc/';
  1230. {$endif}
  1231. if ppccfg<>'' then
  1232. begin
  1233. read_configfile:=true;
  1234. if not FileExists(ppccfg) then
  1235. begin
  1236. {$ifdef linux}
  1237. if (dos.getenv('HOME')<>'') and FileExists(FixPath(dos.getenv('HOME'),false)+'.'+ppccfg) then
  1238. ppccfg:=FixPath(dos.getenv('HOME'),false)+'.'+ppccfg
  1239. else
  1240. {$endif}
  1241. if FileExists(configpath+ppccfg) then
  1242. ppccfg:=configpath+ppccfg
  1243. else
  1244. {$ifndef linux}
  1245. if FileExists(exepath+ppccfg) then
  1246. ppccfg:=exepath+ppccfg
  1247. else
  1248. {$endif}
  1249. read_configfile:=false;
  1250. end;
  1251. end
  1252. else
  1253. read_configfile:=false;
  1254. { Read commandline and configfile }
  1255. target_is_set:=false;
  1256. asm_is_set:=false;
  1257. param_file:='';
  1258. if read_configfile then
  1259. begin
  1260. { read the parameters quick, only -v -T }
  1261. option^.firstpass:=true;
  1262. if cmd<>'' then
  1263. option^.parsecmd(cmd)
  1264. else
  1265. option^.read_parameters;
  1266. option^.firstpass:=false;
  1267. if read_configfile then
  1268. begin
  1269. {$ifdef DEBUG}
  1270. Comment(V_Debug,'read config file: '+ppccfg);
  1271. {$endif DEBUG}
  1272. option^.interpret_file(ppccfg);
  1273. end;
  1274. end;
  1275. if cmd<>'' then
  1276. option^.parsecmd(cmd)
  1277. else
  1278. option^.read_parameters;
  1279. { Stop if errors in options }
  1280. if ErrorCount>0 then
  1281. StopOptions;
  1282. { write logo if set }
  1283. if option^.DoWriteLogo then
  1284. option^.WriteLogo;
  1285. { Check file to compile }
  1286. if param_file='' then
  1287. begin
  1288. Message(option_no_source_found);
  1289. StopOptions;
  1290. end;
  1291. {$ifndef linux}
  1292. param_file:=FixFileName(param_file);
  1293. {$endif}
  1294. fsplit(param_file,inputdir,inputfile,inputextension);
  1295. if inputextension='' then
  1296. begin
  1297. if FileExists(inputdir+inputfile+target_os.sourceext) then
  1298. inputextension:=target_os.sourceext
  1299. else
  1300. if FileExists(inputdir+inputfile+target_os.pasext) then
  1301. inputextension:=target_os.pasext;
  1302. end;
  1303. { Add paths specified with parameters to the searchpaths }
  1304. UnitSearchPath.AddList(Option^.ParaUnitPath,true);
  1305. ObjectSearchPath.AddList(Option^.ParaObjectPath,true);
  1306. IncludeSearchPath.AddList(Option^.ParaIncludePath,true);
  1307. LibrarySearchPath.AddList(Option^.ParaLibraryPath,true);
  1308. { add unit environment and exepath to the unit search path }
  1309. if inputdir<>'' then
  1310. Unitsearchpath.AddPath(inputdir,true);
  1311. if not disable_configfile then
  1312. {$ifdef Delphi}
  1313. UnitSearchPath.AddPath(dmisc.getenv(target_info.unit_env),false);
  1314. {$else}
  1315. UnitSearchPath.AddPath(dos.getenv(target_info.unit_env),false);
  1316. {$endif Delphi}
  1317. {$ifdef linux}
  1318. fpcdir:=FixPath(getenv('FPCDIR'),false);
  1319. if fpcdir='' then
  1320. begin
  1321. if PathExists('/usr/local/lib/fpc/'+version_string) then
  1322. fpcdir:='/usr/local/lib/fpc/'+version_string+'/'
  1323. else
  1324. fpcdir:='/usr/lib/fpc/'+version_string+'/';
  1325. end;
  1326. {$else}
  1327. fpcdir:=FixPath(getenv('FPCDIR'),false);
  1328. if fpcdir='' then
  1329. begin
  1330. fpcdir:=ExePath+'../';
  1331. if not(PathExists(fpcdir+'/units')) and
  1332. not(PathExists(fpcdir+'/rtl')) then
  1333. fpcdir:=fpcdir+'../';
  1334. end;
  1335. {$endif}
  1336. { first try development RTL, else use the default installation path }
  1337. if not disable_configfile then
  1338. begin
  1339. if PathExists(FpcDir+'rtl/'+lower(target_info.short_name)) then
  1340. UnitSearchPath.AddPath(FpcDir+'rtl/'+lower(target_info.short_name),false)
  1341. else
  1342. begin
  1343. UnitSearchPath.AddPath(FpcDir+'units/'+lower(target_info.short_name),false);
  1344. UnitSearchPath.AddPath(FpcDir+'units/'+lower(target_info.short_name)+'/rtl',false);
  1345. end;
  1346. end;
  1347. { Add exepath if the exe is not in the current dir, because that is always searched already }
  1348. if ExePath<>GetCurrentDir then
  1349. UnitSearchPath.AddPath(ExePath,false);
  1350. { Add unit dir to the object and library path }
  1351. objectsearchpath.AddList(unitsearchpath,false);
  1352. librarysearchpath.AddList(unitsearchpath,false);
  1353. { switch assembler if it's binary and we got -a on the cmdline }
  1354. if (cs_asm_leave in initglobalswitches) and
  1355. (target_asm.id in binassem) then
  1356. begin
  1357. Message(option_switch_bin_to_src_assembler);
  1358. set_target_asm(target_info.assemsrc);
  1359. initoutputformat:=target_asm.id;
  1360. end;
  1361. if (target_asm.supported_target <> target_any) and
  1362. (target_asm.supported_target <> target_info.target) then
  1363. begin
  1364. Message2(option_incompatible_asm,target_asm.idtxt,target_os.name);
  1365. { Should we reset to default ??? }
  1366. set_target_asm(target_info.assemsrc);
  1367. Message1(option_asm_forced,target_asm.idtxt);
  1368. initoutputformat:=target_asm.id;
  1369. end;
  1370. { turn off stripping if compiling with debuginfo or profile }
  1371. if (cs_debuginfo in initmoduleswitches) or
  1372. (cs_profile in initmoduleswitches) then
  1373. initglobalswitches:=initglobalswitches-[cs_link_strip];
  1374. if not LinkTypeSetExplicitly then
  1375. begin
  1376. if (target_os.id=os_i386_win32) then
  1377. begin
  1378. def_symbol('FPC_LINK_SMART');
  1379. undef_symbol('FPC_LINK_STATIC');
  1380. undef_symbol('FPC_LINK_DYNAMIC');
  1381. initglobalswitches:=initglobalswitches+[cs_link_smart];
  1382. initglobalswitches:=initglobalswitches-[cs_link_shared,cs_link_static];
  1383. end
  1384. else
  1385. begin
  1386. undef_symbol('FPC_LINK_SMART');
  1387. def_symbol('FPC_LINK_STATIC');
  1388. undef_symbol('FPC_LINK_DYNAMIC');
  1389. initglobalswitches:=initglobalswitches+[cs_link_static];
  1390. initglobalswitches:=initglobalswitches-[cs_link_shared,cs_link_smart];
  1391. end;
  1392. end;
  1393. { Set defines depending on the target }
  1394. if (target_info.target in [target_i386_GO32V1,target_i386_GO32V2]) then
  1395. def_symbol('DPMI'); { MSDOS is not defined in BP when target is DPMI }
  1396. MaybeLoadMessageFile;
  1397. dispose(option,Done);
  1398. Option:=nil;
  1399. end;
  1400. end.
  1401. {
  1402. $Log$
  1403. Revision 1.70 2000-06-19 19:57:19 pierre
  1404. * smart link is default on win32
  1405. Revision 1.69 2000/05/23 21:28:22 pierre
  1406. + check of compatibility between selected assembler
  1407. output and target OS
  1408. Revision 1.68 2000/05/16 20:19:06 pierre
  1409. + -CR option to enable check for object virtual method
  1410. Revision 1.67 2000/05/10 13:40:19 peter
  1411. * -Se<x> option extended to increase errorcount for
  1412. warning,notes or hints
  1413. Revision 1.66 2000/04/24 13:34:29 peter
  1414. * added enhancedraise define
  1415. Revision 1.65 2000/04/10 11:36:19 pierre
  1416. * get -g-l to work
  1417. Revision 1.64 2000/04/07 14:56:18 peter
  1418. * correctfldcw define added
  1419. Revision 1.63 2000/04/05 21:57:34 pierre
  1420. * no unitdir automatically added if -n option present
  1421. Revision 1.62 2000/03/13 20:06:59 michael
  1422. + Added switch to swicth on assertions.
  1423. Revision 1.61 2000/02/15 14:36:45 florian
  1424. * disable FIXED data type per default
  1425. Revision 1.60 2000/02/10 11:45:48 peter
  1426. * addpath fixed with list of paths when inserting at the beginning
  1427. * if exepath=currentdir then it's not inserted in path list
  1428. * searchpaths in ppc386.cfg are now added at the beginning of the
  1429. list instead of at the end. (commandline is not changed)
  1430. * check paths before inserting in list
  1431. Revision 1.59 2000/02/09 13:22:54 peter
  1432. * log truncated
  1433. Revision 1.58 2000/02/09 10:35:48 peter
  1434. * -Xt option to link staticly against c libs
  1435. Revision 1.57 2000/02/06 17:20:52 peter
  1436. * -gl switch for auto lineinfo including
  1437. Revision 1.56 2000/01/31 15:55:42 peter
  1438. * fixed default unit location for linux when fpcdir was not set
  1439. Revision 1.55 2000/01/23 18:20:50 sg
  1440. * Fixed typo in line 1375 ("fpidr" instead of "fpcdir")
  1441. Revision 1.54 2000/01/23 16:36:37 peter
  1442. * better auto RTL dir detection
  1443. Revision 1.53 2000/01/20 10:36:44 daniel
  1444. * also support ; comments in cfg file
  1445. Revision 1.52 2000/01/17 22:50:28 peter
  1446. * fixed interpret_envvar whcih crashed when the envvar was not set
  1447. * also warn if the envvar is empty (=not set)
  1448. Revision 1.51 2000/01/14 15:33:15 pierre
  1449. + parsecmd supports "filename with spaces" for IDE
  1450. Revision 1.50 2000/01/14 14:33:54 pierre
  1451. + some warnings for wrong lines inside config files
  1452. Revision 1.49 2000/01/10 11:14:19 peter
  1453. * fixed memory leak with options, you must use StopOptions instead of
  1454. Stop
  1455. * fixed memory leak with forward resolving, make_ref is now false
  1456. Revision 1.48 2000/01/07 22:22:02 marco
  1457. * Added $target support for -FD
  1458. Revision 1.47 2000/01/07 01:14:27 peter
  1459. * updated copyright to 2000
  1460. Revision 1.46 2000/01/06 15:48:59 peter
  1461. * wildcard support for directory adding, this allows the use of units/*
  1462. in ppc386.cfg
  1463. Revision 1.45 1999/12/20 23:23:30 pierre
  1464. + $description $version
  1465. Revision 1.44 1999/12/20 21:42:36 pierre
  1466. + dllversion global variable
  1467. * FPC_USE_CPREFIX code removed, not necessary anymore
  1468. as we use .edata direct writing by default now.
  1469. Revision 1.43 1999/12/18 14:55:21 florian
  1470. * very basic widestring support
  1471. Revision 1.42 1999/12/11 18:53:31 jonas
  1472. * fixed type conversions of results of operations with cardinals
  1473. (between -dcardinalmulfix)
  1474. Revision 1.41 1999/12/10 10:03:54 peter
  1475. * fixed parameter orderning
  1476. Revision 1.40 1999/12/08 10:40:01 pierre
  1477. + allow use of unit var in exports of DLL for win32
  1478. by using direct export writing by default instead of use of DEFFILE
  1479. that does not allow assembler labels that do not
  1480. start with an underscore.
  1481. Use -WD to force use of Deffile for Win32 DLL
  1482. Revision 1.39 1999/12/06 18:21:03 peter
  1483. * support !ENVVAR for long commandlines
  1484. * win32/go32v2 write short pathnames to link.res so c:\Program Files\ is
  1485. finally supported as installdir.
  1486. }