options.pas 69 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296
  1. {
  2. Copyright (c) 1998-2002 by Florian Klaempfl and Peter Vreman
  3. Reads command line options and config files
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  15. ****************************************************************************
  16. }
  17. unit options;
  18. {$i fpcdefs.inc}
  19. interface
  20. uses
  21. CClasses,globtype,globals,verbose,systems,cpuinfo;
  22. Type
  23. TOption=class
  24. FirstPass,
  25. ParaLogo,
  26. NoPressEnter,
  27. LogoWritten : boolean;
  28. FileLevel : longint;
  29. QuickInfo : string;
  30. ParaIncludePath,
  31. ParaUnitPath,
  32. ParaObjectPath,
  33. ParaLibraryPath : TSearchPathList;
  34. ParaAlignment : TAlignmentInfo;
  35. Constructor Create;
  36. Destructor Destroy;override;
  37. procedure WriteLogo;
  38. procedure WriteInfo;
  39. procedure WriteHelpPages;
  40. procedure WriteQuickInfo;
  41. procedure IllegalPara(const opt:string);
  42. function Unsetbool(var Opts:string; Pos: Longint):boolean;
  43. procedure interpret_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. procedure TargetDefines(def:boolean);
  49. end;
  50. TOptionClass=class of toption;
  51. var
  52. coption : TOptionClass;
  53. procedure read_arguments(cmd:string);
  54. implementation
  55. uses
  56. widestr,
  57. {$IFDEF USE_SYSUTILS}
  58. SysUtils,
  59. {$ELSE USE_SYSUTILS}
  60. dos,
  61. {$ENDIF USE_SYSUTILS}
  62. version,
  63. cutils,cmsgs,
  64. comphook,
  65. symtable,scanner,rabase
  66. {$ifdef BrowserLog}
  67. ,browlog
  68. {$endif BrowserLog}
  69. ;
  70. const
  71. page_size = 24;
  72. var
  73. option : toption;
  74. read_configfile, { read config file, set when a cfgfile is found }
  75. disable_configfile : boolean;
  76. fpcdir,
  77. ppccfg,
  78. ppcaltcfg,
  79. param_file : string; { file to compile specified on the commandline }
  80. {****************************************************************************
  81. Defines
  82. ****************************************************************************}
  83. procedure set_default_link_type;
  84. begin
  85. undef_system_macro('FPC_LINK_SMART');
  86. def_system_macro('FPC_LINK_STATIC');
  87. undef_system_macro('FPC_LINK_DYNAMIC');
  88. initglobalswitches:=initglobalswitches+[cs_link_static];
  89. initglobalswitches:=initglobalswitches-[cs_link_shared,cs_link_smart];
  90. end;
  91. {****************************************************************************
  92. Toption
  93. ****************************************************************************}
  94. procedure StopOptions(err:longint);
  95. begin
  96. if assigned(Option) then
  97. begin
  98. Option.free;
  99. Option:=nil;
  100. end;
  101. raise ECompilerAbortSilent.Create;
  102. end;
  103. procedure Toption.WriteLogo;
  104. var
  105. p : pchar;
  106. begin
  107. if not LogoWritten then
  108. begin
  109. p:=MessagePchar(option_logo);
  110. while assigned(p) do
  111. Comment(V_Normal,GetMsgLine(p));
  112. LogoWritten:= true;
  113. end;
  114. end;
  115. procedure Toption.WriteInfo;
  116. var
  117. p : pchar;
  118. hs,hs1,s : TCmdStr;
  119. target : tsystem;
  120. cpu : tcputype;
  121. fpu : tfputype;
  122. opt : toptimizerswitch;
  123. begin
  124. p:=MessagePchar(option_info);
  125. while assigned(p) do
  126. begin
  127. s:=GetMsgLine(p);
  128. { list OS Targets }
  129. if pos('$OSTARGETS',s)>0 then
  130. begin
  131. for target:=low(tsystem) to high(tsystem) do
  132. if assigned(targetinfos[target]) then
  133. begin
  134. hs:=s;
  135. hs1:=targetinfos[target]^.name;
  136. if tf_under_development in targetinfos[target]^.flags then
  137. hs1:=hs1+' (under development)';
  138. Replace(hs,'$OSTARGETS',hs1);
  139. Comment(V_Normal,hs);
  140. end;
  141. end
  142. else if pos('$INSTRUCTIONSETS',s)>0 then
  143. begin
  144. for cpu:=low(tcputype) to high(tcputype) do
  145. begin
  146. hs:=s;
  147. hs1:=cputypestr[cpu];
  148. if hs1<>'' then
  149. begin
  150. Replace(hs,'$INSTRUCTIONSETS',hs1);
  151. Comment(V_Normal,hs);
  152. end;
  153. end;
  154. end
  155. else if pos('$FPUINSTRUCTIONSETS',s)>0 then
  156. begin
  157. for fpu:=low(tfputype) to high(tfputype) do
  158. begin
  159. hs:=s;
  160. hs1:=fputypestr[fpu];
  161. if hs1<>'' then
  162. begin
  163. Replace(hs,'$FPUINSTRUCTIONSETS',hs1);
  164. Comment(V_Normal,hs);
  165. end;
  166. end;
  167. end
  168. else if pos('$OPTIMIZATIONS',s)>0 then
  169. begin
  170. for opt:=low(toptimizerswitch) to high(toptimizerswitch) do
  171. begin
  172. if opt in supported_optimizerswitches then
  173. begin
  174. hs:=s;
  175. hs1:=OptimizerSwitchStr[opt];
  176. if hs1<>'' then
  177. begin
  178. Replace(hs,'$OPTIMIZATIONS',hs1);
  179. Comment(V_Normal,hs);
  180. end;
  181. end;
  182. end;
  183. end
  184. else
  185. Comment(V_Normal,s);
  186. end;
  187. StopOptions(0);
  188. end;
  189. procedure Toption.WriteHelpPages;
  190. function PadEnd(s:string;i:longint):string;
  191. begin
  192. while (length(s)<i) do
  193. s:=s+' ';
  194. PadEnd:=s;
  195. end;
  196. var
  197. lastident,
  198. j,outline,
  199. ident,
  200. lines : longint;
  201. show : boolean;
  202. opt : string[32];
  203. input,
  204. s : string;
  205. p : pchar;
  206. begin
  207. WriteLogo;
  208. Lines:=4;
  209. Message1(option_usage,FixFileName(system.paramstr(0)));
  210. lastident:=0;
  211. p:=MessagePChar(option_help_pages);
  212. while assigned(p) do
  213. begin
  214. { get a line and reset }
  215. s:=GetMsgLine(p);
  216. ident:=0;
  217. show:=false;
  218. { parse options }
  219. case s[1] of
  220. {$ifdef UNITALIASES}
  221. 'a',
  222. {$endif}
  223. {$ifdef EXTDEBUG}
  224. 'e',
  225. {$endif EXTDEBUG}
  226. {$ifdef i386}
  227. '3',
  228. {$endif}
  229. {$ifdef x86_64}
  230. '4',
  231. {$endif}
  232. {$ifdef m68k}
  233. '6',
  234. {$endif}
  235. {$ifdef arm}
  236. 'A',
  237. {$endif}
  238. {$ifdef powerpc}
  239. 'P',
  240. {$endif}
  241. {$ifdef sparc}
  242. 'S',
  243. {$endif}
  244. {$ifdef vis}
  245. 'V',
  246. {$endif}
  247. '*' : show:=true;
  248. end;
  249. if show then
  250. begin
  251. case s[2] of
  252. 'g',
  253. {$ifdef Unix}
  254. 'L',
  255. {$endif}
  256. {$ifdef os2}
  257. 'O',
  258. {$endif}
  259. '*' : show:=true;
  260. else
  261. show:=false;
  262. end;
  263. end;
  264. { now we may show the message or not }
  265. if show then
  266. begin
  267. case s[3] of
  268. '0' : begin
  269. ident:=0;
  270. outline:=0;
  271. end;
  272. '1' : begin
  273. ident:=2;
  274. outline:=7;
  275. end;
  276. '2' : begin
  277. ident:=6;
  278. outline:=11;
  279. end;
  280. '3' : begin
  281. ident:=9;
  282. outline:=11;
  283. end;
  284. end;
  285. j:=pos('_',s);
  286. opt:=Copy(s,4,j-4);
  287. if opt='*' then
  288. opt:=''
  289. else
  290. if opt=' ' then
  291. opt:=PadEnd(opt,outline)
  292. else
  293. opt:=PadEnd('-'+opt,outline);
  294. if (ident=0) and (lastident<>0) then
  295. begin
  296. Comment(V_Normal,'');
  297. inc(Lines);
  298. end;
  299. { page full ? }
  300. if (lines >= page_size - 1) then
  301. begin
  302. if not NoPressEnter then
  303. begin
  304. Message(option_help_press_enter);
  305. readln(input);
  306. if upper(input)='Q' then
  307. StopOptions(0);
  308. end;
  309. lines:=0;
  310. end;
  311. Comment(V_Normal,PadEnd('',ident)+opt+Copy(s,j+1,255));
  312. LastIdent:=Ident;
  313. inc(Lines);
  314. end;
  315. end;
  316. StopOptions(0);
  317. end;
  318. procedure Toption.IllegalPara(const opt:string);
  319. begin
  320. Message1(option_illegal_para,opt);
  321. Message(option_help_pages_para);
  322. StopOptions(1);
  323. end;
  324. function Toption.Unsetbool(var Opts:string; Pos: Longint):boolean;
  325. { checks if the character after pos in Opts is a + or a - and returns resp.
  326. false or true. If it is another character (or none), it also returns false }
  327. begin
  328. UnsetBool := false;
  329. if Length(Opts)>Pos then
  330. begin
  331. inc(Pos);
  332. UnsetBool := Opts[Pos] = '-';
  333. if Opts[Pos] in ['-','+']then
  334. delete(Opts,Pos,1);
  335. end;
  336. end;
  337. procedure TOption.interpret_option(const opt:string;ispara:boolean);
  338. var
  339. code : integer;
  340. c : char;
  341. more : string;
  342. major,minor : longint;
  343. error : integer;
  344. j,l : longint;
  345. d : DirStr;
  346. s : string;
  347. begin
  348. if opt='' then
  349. exit;
  350. { only parse define,undef,target,verbosity,link etc options the firsttime }
  351. if firstpass and
  352. not(
  353. (opt[1]='-') and
  354. (
  355. ((length(opt)>1) and (opt[2] in ['i','d','v','T','u','n','X','l'])) or
  356. ((length(opt)>3) and (opt[2]='F') and (opt[3]='e'))
  357. )
  358. ) then
  359. exit;
  360. Message1(option_handling_option,opt);
  361. case opt[1] of
  362. '-' :
  363. begin
  364. more:=Copy(opt,3,255);
  365. if firstpass then
  366. Message1(option_interpreting_firstpass_option,opt)
  367. else
  368. Message1(option_interpreting_option,opt);
  369. case opt[2] of
  370. '?' :
  371. WriteHelpPages;
  372. 'a' :
  373. begin
  374. include(initglobalswitches,cs_asm_leave);
  375. j:=1;
  376. while j<=length(more) do
  377. begin
  378. case more[j] of
  379. 'l' :
  380. include(initglobalswitches,cs_asm_source);
  381. 'r' :
  382. include(initglobalswitches,cs_asm_regalloc);
  383. 't' :
  384. include(initglobalswitches,cs_asm_tempalloc);
  385. 'n' :
  386. include(initglobalswitches,cs_asm_nodes);
  387. 'p' :
  388. begin
  389. exclude(initglobalswitches,cs_asm_leave);
  390. if UnsetBool(More, 0) then
  391. exclude(initglobalswitches,cs_asm_pipe)
  392. else
  393. include(initglobalswitches,cs_asm_pipe);
  394. end;
  395. '-' :
  396. initglobalswitches:=initglobalswitches -
  397. [cs_asm_leave, cs_asm_source,cs_asm_regalloc, cs_asm_tempalloc,
  398. cs_asm_nodes, cs_asm_pipe];
  399. else
  400. IllegalPara(opt);
  401. end;
  402. inc(j);
  403. end;
  404. end;
  405. 'A' :
  406. begin
  407. paratargetasm:=find_asm_by_string(More);
  408. if paratargetasm=as_none then
  409. IllegalPara(opt);
  410. end;
  411. 'b' :
  412. begin
  413. {$ifdef supportbrowser}
  414. if UnsetBool(More,0) then
  415. begin
  416. exclude(initmoduleswitches,cs_browser);
  417. exclude(initmoduleswitches,cs_local_browser);
  418. {$ifdef BrowserLog}
  419. exclude(initglobalswitches,cs_browser_log);
  420. {$endif}
  421. end
  422. else
  423. begin
  424. include(initmoduleswitches,cs_browser);
  425. {$ifdef BrowserLog}
  426. include(initglobalswitches,cs_browser_log);
  427. {$endif}
  428. end;
  429. if More<>'' then
  430. if (More='l') or (More='l+') then
  431. include(initmoduleswitches,cs_local_browser)
  432. else
  433. if More='l-' then
  434. exclude(initmoduleswitches,cs_local_browser)
  435. else
  436. {$ifdef BrowserLog}
  437. browserlog.elements_to_list.insert(more);
  438. {$else}
  439. IllegalPara(opt);
  440. {$endif}
  441. {$endif supportbrowser}
  442. end;
  443. 'B' :
  444. do_build:=not UnSetBool(more,0);
  445. 'C' :
  446. begin
  447. j:=1;
  448. while j<=length(more) do
  449. begin
  450. case more[j] of
  451. 'c' :
  452. begin
  453. if not SetAktProcCall(upper(copy(more,j+1,length(more)-j)),initdefproccall) then
  454. IllegalPara(opt);
  455. break;
  456. end;
  457. {$ifdef cpufpemu}
  458. 'e' :
  459. begin
  460. If UnsetBool(More, j) then
  461. exclude(initmoduleswitches,cs_fp_emulation)
  462. Else
  463. include(initmoduleswitches,cs_fp_emulation);
  464. end;
  465. {$endif cpufpemu}
  466. 'f' :
  467. begin
  468. s:=upper(copy(more,j+1,length(more)-j));
  469. if not(SetFpuType(s,initfputype)) then
  470. IllegalPara(opt);
  471. break;
  472. end;
  473. 'g' :
  474. include(initmoduleswitches,cs_create_pic);
  475. 'h' :
  476. begin
  477. val(copy(more,j+1,length(more)-j),heapsize,code);
  478. if (code<>0) or (heapsize<1024) then
  479. IllegalPara(opt);
  480. break;
  481. end;
  482. 'i' :
  483. If UnsetBool(More, j) then
  484. exclude(initlocalswitches,cs_check_io)
  485. else
  486. include(initlocalswitches,cs_check_io);
  487. 'n' :
  488. If UnsetBool(More, j) then
  489. exclude(initglobalswitches,cs_link_nolink)
  490. Else
  491. include(initglobalswitches,cs_link_nolink);
  492. 'o' :
  493. If UnsetBool(More, j) then
  494. exclude(initlocalswitches,cs_check_overflow)
  495. Else
  496. include(initlocalswitches,cs_check_overflow);
  497. 'p' :
  498. begin
  499. s:=upper(copy(more,j+1,length(more)-j));
  500. if not(Setcputype(s,initcputype)) then
  501. IllegalPara(opt);
  502. break;
  503. end;
  504. 'r' :
  505. If UnsetBool(More, j) then
  506. exclude(initlocalswitches,cs_check_range)
  507. Else
  508. include(initlocalswitches,cs_check_range);
  509. 'R' :
  510. If UnsetBool(More, j) then
  511. begin
  512. exclude(initlocalswitches,cs_check_range);
  513. exclude(initlocalswitches,cs_check_object);
  514. end
  515. Else
  516. begin
  517. include(initlocalswitches,cs_check_range);
  518. include(initlocalswitches,cs_check_object);
  519. end;
  520. 's' :
  521. begin
  522. val(copy(more,j+1,length(more)-j),stacksize,code);
  523. if (code<>0) or (stacksize>=67107840) or (stacksize<1024) then
  524. IllegalPara(opt);
  525. break;
  526. end;
  527. 't' :
  528. If UnsetBool(More, j) then
  529. exclude(initlocalswitches,cs_check_stack)
  530. Else
  531. include(initlocalswitches,cs_check_stack);
  532. 'D' :
  533. If UnsetBool(More, j) then
  534. exclude(initmoduleswitches,cs_create_dynamic)
  535. Else
  536. include(initmoduleswitches,cs_create_dynamic);
  537. 'X' :
  538. If UnsetBool(More, j) then
  539. exclude(initmoduleswitches,cs_create_smart)
  540. Else
  541. include(initmoduleswitches,cs_create_smart);
  542. else
  543. IllegalPara(opt);
  544. end;
  545. inc(j);
  546. end;
  547. end;
  548. 'd' :
  549. if more <> '' then
  550. begin
  551. l:=Pos(':=',more);
  552. if l>0 then
  553. set_system_compvar(Copy(more,1,l-1),Copy(more,l+2,255))
  554. else
  555. def_system_macro(more);
  556. end;
  557. 'D' :
  558. begin
  559. include(initglobalswitches,cs_link_deffile);
  560. j:=1;
  561. while j<=length(more) do
  562. begin
  563. case more[j] of
  564. 'd' :
  565. begin
  566. description:=Copy(more,j+1,255);
  567. break;
  568. end;
  569. 'v' :
  570. begin
  571. dllversion:=Copy(more,j+1,255);
  572. l:=pos('.',dllversion);
  573. dllminor:=0;
  574. error:=0;
  575. if l>0 then
  576. begin
  577. val(copy(dllversion,l+1,255),minor,error);
  578. if (error=0) and
  579. (minor>=0) and (minor<=$ffff) then
  580. dllminor:=minor
  581. else
  582. if error=0 then
  583. error:=1;
  584. end;
  585. if l=0 then
  586. l:=256;
  587. dllmajor:=1;
  588. if error=0 then
  589. val(copy(dllversion,1,l-1),major,error);
  590. if (error=0) and (major>=0) and (major<=$ffff) then
  591. dllmajor:=major
  592. else
  593. if error=0 then
  594. error:=1;
  595. if error<>0 then
  596. Message1(scan_w_wrong_version_ignored,dllversion);
  597. break;
  598. end;
  599. 'w' :
  600. usewindowapi:=true;
  601. '-' :
  602. begin
  603. exclude(initglobalswitches,cs_link_deffile);
  604. usewindowapi:=false;
  605. end;
  606. else
  607. IllegalPara(opt);
  608. end;
  609. inc(j);
  610. end;
  611. end;
  612. 'e' :
  613. exepath:=FixPath(More,true);
  614. 'E' :
  615. begin
  616. if UnsetBool(More, 0) then
  617. exclude(initglobalswitches,cs_link_nolink)
  618. else
  619. include(initglobalswitches,cs_link_nolink);
  620. end;
  621. 'F' :
  622. begin
  623. c:=more[1];
  624. Delete(more,1,1);
  625. DefaultReplacements(More);
  626. case c of
  627. 'a' :
  628. autoloadunits:=more;
  629. 'c' :
  630. begin
  631. if (upper(more)='UTF8') or (upper(more)='UTF-8') then
  632. initsourcecodepage:='utf8'
  633. else if not(cpavailable(more)) then
  634. Message1(option_code_page_not_available,more)
  635. else
  636. initsourcecodepage:=more;
  637. end;
  638. 'D' :
  639. utilsdirectory:=FixPath(More,true);
  640. 'e' :
  641. SetRedirectFile(More);
  642. 'E' :
  643. OutputExeDir:=FixPath(More,true);
  644. 'i' :
  645. begin
  646. if ispara then
  647. ParaIncludePath.AddPath(More,false)
  648. else
  649. includesearchpath.AddPath(More,true);
  650. end;
  651. 'g' :
  652. Message2(option_obsolete_switch_use_new,'-Fg','-Fl');
  653. 'l' :
  654. begin
  655. if ispara then
  656. ParaLibraryPath.AddPath(More,false)
  657. else
  658. LibrarySearchPath.AddPath(More,true);
  659. end;
  660. 'L' :
  661. begin
  662. if More<>'' then
  663. ParaDynamicLinker:=More
  664. else
  665. IllegalPara(opt);
  666. end;
  667. 'o' :
  668. begin
  669. if ispara then
  670. ParaObjectPath.AddPath(More,false)
  671. else
  672. ObjectSearchPath.AddPath(More,true);
  673. end;
  674. 'r' :
  675. Msgfilename:=More;
  676. 'u' :
  677. begin
  678. if ispara then
  679. ParaUnitPath.AddPath(More,false)
  680. else
  681. unitsearchpath.AddPath(More,true);
  682. end;
  683. 'U' :
  684. OutputUnitDir:=FixPath(More,true);
  685. else
  686. IllegalPara(opt);
  687. end;
  688. end;
  689. 'g' :
  690. begin
  691. if UnsetBool(More, 0) then
  692. begin
  693. exclude(initmoduleswitches,cs_debuginfo);
  694. exclude(initglobalswitches,cs_use_heaptrc);
  695. exclude(initglobalswitches,cs_use_lineinfo);
  696. exclude(initlocalswitches,cs_checkpointer);
  697. localvartrashing := -1;
  698. end
  699. else
  700. begin
  701. include(initmoduleswitches,cs_debuginfo);
  702. end;
  703. if not RelocSectionSetExplicitly then
  704. RelocSection:=false;
  705. j:=1;
  706. while j<=length(more) do
  707. begin
  708. case more[j] of
  709. 'c' :
  710. begin
  711. if UnsetBool(More, j) then
  712. exclude(initlocalswitches,cs_checkpointer)
  713. else
  714. include(initlocalswitches,cs_checkpointer);
  715. end;
  716. 'd' :
  717. begin
  718. paratargetdbg:=dbg_dwarf2;
  719. end;
  720. 'h' :
  721. begin
  722. if UnsetBool(More, j) then
  723. exclude(initglobalswitches,cs_use_heaptrc)
  724. else
  725. include(initglobalswitches,cs_use_heaptrc);
  726. end;
  727. 'l' :
  728. begin
  729. if UnsetBool(More, j) then
  730. exclude(initglobalswitches,cs_use_lineinfo)
  731. else
  732. include(initglobalswitches,cs_use_lineinfo);
  733. end;
  734. 's' :
  735. begin
  736. paratargetdbg:=dbg_stabs;
  737. end;
  738. 't' :
  739. begin
  740. if UnsetBool(More, j) then
  741. localvartrashing := -1
  742. else
  743. localvartrashing := (localvartrashing + 1) mod nroftrashvalues;
  744. end;
  745. 'v' :
  746. begin
  747. if UnsetBool(More, j) then
  748. exclude(initglobalswitches,cs_gdb_valgrind)
  749. else
  750. include(initglobalswitches,cs_gdb_valgrind);
  751. end;
  752. 'w' :
  753. begin
  754. if (j<length(more)) and (more[j+1] in ['2','3']) then
  755. begin
  756. case more[j+1] of
  757. '2': paratargetdbg:=dbg_dwarf2;
  758. '3': paratargetdbg:=dbg_dwarf3;
  759. end;
  760. inc(j);
  761. end
  762. else
  763. paratargetdbg:=dbg_dwarf2;
  764. end;
  765. else
  766. IllegalPara(opt);
  767. end;
  768. inc(j);
  769. end;
  770. end;
  771. 'h' :
  772. begin
  773. NoPressEnter:=true;
  774. WriteHelpPages;
  775. end;
  776. 'i' :
  777. begin
  778. if More='' then
  779. WriteInfo
  780. else
  781. QuickInfo:=QuickInfo+More;
  782. end;
  783. 'I' :
  784. begin
  785. if ispara then
  786. ParaIncludePath.AddPath(More,false)
  787. else
  788. includesearchpath.AddPath(More,false);
  789. end;
  790. 'k' :
  791. begin
  792. if more<>'' then
  793. ParaLinkOptions:=ParaLinkOptions+' '+More
  794. else
  795. IllegalPara(opt);
  796. end;
  797. 'l' :
  798. if not UnSetBool(more,0) then
  799. ParaLogo:=true;
  800. 'm' :
  801. parapreprocess:=not UnSetBool(more,0);
  802. 'M' :
  803. begin
  804. more:=Upper(more);
  805. if not SetCompileMode(more, true) then
  806. IllegalPara(opt);
  807. end;
  808. 'n' :
  809. begin
  810. if More='' then
  811. disable_configfile:=true
  812. else
  813. IllegalPara(opt);
  814. end;
  815. 'o' :
  816. begin
  817. if More<>'' then
  818. begin
  819. DefaultReplacements(More);
  820. {$IFDEF USE_SYSUTILS}
  821. D:=SplitPath(More);
  822. OutputFile:=SplitFileName(More);
  823. OutputExtension:=SplitExtension(More);
  824. {$ELSE USE_SYSUTILS}
  825. FSplit(More,D,OutputFile,OutputExtension);
  826. {$ENDIF USE_SYSUTILS}
  827. if (D<>'') then
  828. OutputExeDir:=FixPath(D,True);
  829. end
  830. else
  831. IllegalPara(opt);
  832. end;
  833. 'O' :
  834. begin
  835. j:=1;
  836. while j<=length(more) do
  837. begin
  838. case more[j] of
  839. '1' :
  840. initoptimizerswitches:=initoptimizerswitches+level1optimizerswitches;
  841. '2' :
  842. initoptimizerswitches:=initoptimizerswitches+level2optimizerswitches;
  843. '3' :
  844. initoptimizerswitches:=initoptimizerswitches+level3optimizerswitches;
  845. 'a' :
  846. begin
  847. if not(UpdateAlignmentStr(Copy(Opt,j+3,255),ParaAlignment)) then
  848. IllegalPara(opt);
  849. break;
  850. end;
  851. 's' :
  852. include(initoptimizerswitches,cs_opt_size);
  853. 'p' :
  854. begin
  855. if not Setcputype(copy(more,j+1,length(more)),initoptimizecputype) then
  856. begin
  857. { Give warning for old i386 switches }
  858. if (Length(More)-j=1) and
  859. (More[j+1]>='1') and (More[j+1]<='5')then
  860. Message2(option_obsolete_switch_use_new,'-Op<nr>','-Op<name>')
  861. else
  862. IllegalPara(opt);
  863. end;
  864. break;
  865. end;
  866. 'o' :
  867. begin
  868. if not UpdateOptimizerStr(copy(more,j+1,length(more)),initoptimizerswitches) then
  869. IllegalPara(opt);
  870. break;
  871. end;
  872. '-' :
  873. begin
  874. initoptimizerswitches:=[];
  875. FillChar(ParaAlignment,sizeof(ParaAlignment),0);
  876. end;
  877. { Obsolete switches }
  878. 'g' :
  879. Message2(option_obsolete_switch_use_new,'-Og','-Os');
  880. 'G' :
  881. Message1(option_obsolete_switch,'-OG');
  882. 'r' :
  883. Message2(option_obsolete_switch_use_new,'-Or','-O2 or -Ooregvar');
  884. 'u' :
  885. Message2(option_obsolete_switch_use_new,'-Ou','-Oouncertain');
  886. else
  887. IllegalPara(opt);
  888. end;
  889. inc(j);
  890. end;
  891. end;
  892. 'p' :
  893. begin
  894. if UnsetBool(More, 0) then
  895. begin
  896. initmoduleswitches:=initmoduleswitches-[cs_profile];
  897. undef_system_macro('FPC_PROFILE');
  898. end
  899. else
  900. if Length(More)=0 then
  901. IllegalPara(opt)
  902. else
  903. case more[1] of
  904. 'g' : if UnsetBool(more, 1) then
  905. begin
  906. exclude(initmoduleswitches,cs_profile);
  907. undef_system_macro('FPC_PROFILE');
  908. end
  909. else
  910. begin
  911. include(initmoduleswitches,cs_profile);
  912. def_system_macro('FPC_PROFILE');
  913. end;
  914. else
  915. IllegalPara(opt);
  916. end;
  917. end;
  918. 'P' : ; { Ignore used by fpc.pp }
  919. 'R' :
  920. begin
  921. if not SetAsmReadMode(More,initasmmode) then
  922. IllegalPara(opt);
  923. end;
  924. 's' :
  925. begin
  926. if UnsetBool(More, 0) then
  927. begin
  928. initglobalswitches:=initglobalswitches-[cs_asm_extern,cs_link_extern,cs_link_nolink];
  929. if more<>'' then
  930. IllegalPara(opt);
  931. end
  932. else
  933. begin
  934. initglobalswitches:=initglobalswitches+[cs_asm_extern,cs_link_extern,cs_link_nolink];
  935. if more='h' then
  936. initglobalswitches:=initglobalswitches-[cs_link_on_target]
  937. else if more='t' then
  938. initglobalswitches:=initglobalswitches+[cs_link_on_target]
  939. else if more='r' then
  940. initglobalswitches:=initglobalswitches+[cs_asm_leave,cs_no_regalloc]
  941. else if more<>'' then
  942. IllegalPara(opt);
  943. end;
  944. end;
  945. 'S' :
  946. begin
  947. if more[1]='I' then
  948. begin
  949. if upper(more)='ICOM' then
  950. initinterfacetype:=it_interfacecom
  951. else if upper(more)='ICORBA' then
  952. initinterfacetype:=it_interfacecorba
  953. else
  954. IllegalPara(opt);
  955. end
  956. else
  957. begin
  958. j:=1;
  959. while j<=length(more) do
  960. begin
  961. case more[j] of
  962. '2' : //an alternative to -Mobjfpc
  963. SetCompileMode('OBJFPC',true);
  964. 'a' :
  965. include(initlocalswitches,cs_do_assertion);
  966. 'c' :
  967. include(initmoduleswitches,cs_support_c_operators);
  968. 'd' : //an alternative to -Mdelphi
  969. SetCompileMode('DELPHI',true);
  970. 'e' :
  971. begin
  972. SetErrorFlags(copy(more,j+1,length(more)));
  973. break;
  974. end;
  975. 'g' :
  976. include(initmoduleswitches,cs_support_goto);
  977. 'h' :
  978. include(initlocalswitches,cs_ansistrings);
  979. 'i' :
  980. include(initlocalswitches,cs_do_inline);
  981. 'k' :
  982. include(initglobalswitches,cs_load_fpcylix_unit);
  983. 'm' :
  984. include(initmoduleswitches,cs_support_macro);
  985. 'o' : //an alternative to -Mtp
  986. SetCompileMode('TP',true);
  987. 'p' : //an alternative to -Mgpc
  988. SetCompileMode('GPC',true);
  989. 's' :
  990. include(initglobalswitches,cs_constructor_name);
  991. 't' :
  992. include(initmoduleswitches,cs_static_keyword);
  993. 'v' :
  994. include(initglobalswitches,cs_support_vectors);
  995. '-' :
  996. begin
  997. exclude(initglobalswitches,cs_constructor_name);
  998. initlocalswitches:=InitLocalswitches - [cs_do_assertion, cs_do_inline, cs_ansistrings];
  999. initmoduleswitches:=initmoduleswitches - [cs_support_c_operators, cs_support_goto,
  1000. cs_support_macro,
  1001. cs_static_keyword];
  1002. end;
  1003. else
  1004. IllegalPara(opt);
  1005. end;
  1006. inc(j);
  1007. end;
  1008. end;
  1009. end;
  1010. 'T' :
  1011. begin
  1012. more:=Upper(More);
  1013. if paratarget=system_none then
  1014. begin
  1015. { remove old target define }
  1016. TargetDefines(false);
  1017. { load new target }
  1018. paratarget:=find_system_by_string(More);
  1019. if paratarget<>system_none then
  1020. set_target(paratarget)
  1021. else
  1022. IllegalPara(opt);
  1023. { set new define }
  1024. TargetDefines(true);
  1025. end
  1026. else
  1027. if More<>upper(target_info.shortname) then
  1028. Message1(option_target_is_already_set,target_info.shortname);
  1029. end;
  1030. 'u' :
  1031. if more <> '' then
  1032. undef_system_macro(more);
  1033. 'U' :
  1034. begin
  1035. j:=1;
  1036. while j<=length(more) do
  1037. begin
  1038. case more[j] of
  1039. {$ifdef UNITALIASES}
  1040. 'a' :
  1041. begin
  1042. AddUnitAlias(Copy(More,j+1,255));
  1043. break;
  1044. end;
  1045. {$endif UNITALIASES}
  1046. 'n' :
  1047. exclude(initglobalswitches,cs_check_unit_name);
  1048. 'p' :
  1049. begin
  1050. Message2(option_obsolete_switch_use_new,'-Up','-Fu');
  1051. break;
  1052. end;
  1053. 'r' :
  1054. do_release:=true;
  1055. 's' :
  1056. include(initmoduleswitches,cs_compilesystem);
  1057. '-' :
  1058. begin
  1059. exclude(initmoduleswitches,cs_compilesystem);
  1060. exclude(initglobalswitches,cs_check_unit_name);
  1061. end;
  1062. else
  1063. IllegalPara(opt);
  1064. end;
  1065. inc(j);
  1066. end;
  1067. end;
  1068. 'v' :
  1069. begin
  1070. if not setverbosity(More) then
  1071. IllegalPara(opt);
  1072. end;
  1073. 'V' : ; { Ignore used by fpc }
  1074. 'W' :
  1075. begin
  1076. j:=1;
  1077. while j<=length(More) do
  1078. begin
  1079. case More[j] of
  1080. 'A':
  1081. begin
  1082. if UnsetBool(More, j) then
  1083. apptype:=app_native
  1084. else
  1085. apptype:=app_cui;
  1086. end;
  1087. 'B':
  1088. begin
  1089. { -WB200000 means set trefered base address
  1090. to $200000, but does not change relocsection boolean
  1091. this way we can create both relocatble and
  1092. non relocatable DLL at a specific base address PM }
  1093. if (length(More)>j) then
  1094. begin
  1095. if DLLImageBase=nil then
  1096. DLLImageBase:=StringDup(Copy(More,j+1,255));
  1097. end
  1098. else
  1099. begin
  1100. RelocSection:=true;
  1101. RelocSectionSetExplicitly:=true;
  1102. end;
  1103. break;
  1104. end;
  1105. 'C':
  1106. begin
  1107. if UnsetBool(More, j) then
  1108. apptype:=app_gui
  1109. else
  1110. apptype:=app_cui;
  1111. end;
  1112. 'D':
  1113. begin
  1114. UseDeffileForExports:=not UnsetBool(More, j);
  1115. UseDeffileForExportsSetExplicitly:=true;
  1116. end;
  1117. 'F':
  1118. begin
  1119. if UnsetBool(More, j) then
  1120. apptype:=app_cui
  1121. else
  1122. apptype:=app_fs;
  1123. end;
  1124. 'G':
  1125. begin
  1126. if UnsetBool(More, j) then
  1127. apptype:=app_cui
  1128. else
  1129. apptype:=app_gui;
  1130. end;
  1131. 'I':
  1132. begin
  1133. GenerateImportSection:=not UnsetBool(More,j);
  1134. GenerateImportSectionSetExplicitly:=true;
  1135. end;
  1136. 'N':
  1137. begin
  1138. RelocSection:=UnsetBool(More,j);
  1139. RelocSectionSetExplicitly:=true;
  1140. end;
  1141. 'R':
  1142. begin
  1143. { support -WR+ / -WR- as synonyms to -WR / -WN }
  1144. RelocSection:=not UnsetBool(More,j);
  1145. RelocSectionSetExplicitly:=true;
  1146. end;
  1147. 'T':
  1148. begin
  1149. if UnsetBool(More, j) then
  1150. apptype:=app_cui
  1151. else
  1152. apptype:=app_tool;
  1153. end;
  1154. else
  1155. IllegalPara(opt);
  1156. end;
  1157. inc(j);
  1158. end;
  1159. end;
  1160. 'X' :
  1161. begin
  1162. j:=1;
  1163. while j<=length(more) do
  1164. begin
  1165. case More[j] of
  1166. 'c' : Cshared:=TRUE;
  1167. 'd' : Dontlinkstdlibpath:=TRUE;
  1168. 'e' :
  1169. begin
  1170. If UnsetBool(More, j) then
  1171. exclude(initglobalswitches,cs_link_extern)
  1172. else
  1173. include(initglobalswitches,cs_link_extern);
  1174. end;
  1175. 'f' :
  1176. include(initglobalswitches,cs_link_pthread);
  1177. 'i' :
  1178. begin
  1179. If UnsetBool(More, j) then
  1180. include(initglobalswitches,cs_link_extern)
  1181. else
  1182. exclude(initglobalswitches,cs_link_extern);
  1183. end;
  1184. 'm' :
  1185. begin
  1186. If UnsetBool(More, j) then
  1187. exclude(initglobalswitches,cs_link_map)
  1188. else
  1189. include(initglobalswitches,cs_link_map);
  1190. end;
  1191. 'r' :
  1192. begin
  1193. rlinkpath:=Copy(more,2,length(More)-1);
  1194. DefaultReplacements(rlinkpath);
  1195. More:='';
  1196. end;
  1197. 's' :
  1198. begin
  1199. If UnsetBool(More, j) then
  1200. exclude(initglobalswitches,cs_link_strip)
  1201. else
  1202. include(initglobalswitches,cs_link_strip);
  1203. end;
  1204. 't' :
  1205. include(initglobalswitches,cs_link_staticflag);
  1206. 'v' :
  1207. begin
  1208. If UnsetBool(More, j) then
  1209. exclude(initglobalswitches,cs_link_opt_vtable)
  1210. else
  1211. include(initglobalswitches,cs_link_opt_vtable);
  1212. end;
  1213. 'D' :
  1214. begin
  1215. def_system_macro('FPC_LINK_DYNAMIC');
  1216. undef_system_macro('FPC_LINK_SMART');
  1217. undef_system_macro('FPC_LINK_STATIC');
  1218. exclude(initglobalswitches,cs_link_static);
  1219. exclude(initglobalswitches,cs_link_smart);
  1220. include(initglobalswitches,cs_link_shared);
  1221. LinkTypeSetExplicitly:=true;
  1222. end;
  1223. 'M' :
  1224. begin
  1225. mainaliasname:=Copy(more,2,length(More)-1);
  1226. More:='';
  1227. end;
  1228. 'P' :
  1229. begin
  1230. utilsprefix:=Copy(more,2,length(More)-1);
  1231. DefaultReplacements(utilsprefix);
  1232. More:='';
  1233. end;
  1234. 'L' : begin // -XLO is link order -XLA is link alias. -XLD avoids load defaults.
  1235. // these are not aggregable.
  1236. if (j=length(more)) or not (more[j+1] in ['O','A','D']) then
  1237. IllegalPara(opt)
  1238. else
  1239. begin
  1240. case more[j+1] of
  1241. 'A' : begin
  1242. s:=Copy(more,3,length(More)-2);
  1243. if not LinkLibraryAliases.AddDep(s) Then
  1244. IllegalPara(opt);
  1245. end;
  1246. 'O' : begin
  1247. s:=Copy(more,3,length(More)-2);
  1248. if not LinkLibraryOrder.AddWeight(s) Then
  1249. IllegalPara(opt);
  1250. end;
  1251. 'D' : include(initglobalswitches,cs_link_no_default_lib_order)
  1252. else
  1253. IllegalPara(opt);
  1254. end; {case}
  1255. j:=length(more);
  1256. end; {else begin}
  1257. end;
  1258. 'S' :
  1259. begin
  1260. def_system_macro('FPC_LINK_STATIC');
  1261. undef_system_macro('FPC_LINK_SMART');
  1262. undef_system_macro('FPC_LINK_DYNAMIC');
  1263. include(initglobalswitches,cs_link_static);
  1264. exclude(initglobalswitches,cs_link_smart);
  1265. exclude(initglobalswitches,cs_link_shared);
  1266. LinkTypeSetExplicitly:=true;
  1267. end;
  1268. 'X' :
  1269. begin
  1270. def_system_macro('FPC_LINK_SMART');
  1271. undef_system_macro('FPC_LINK_STATIC');
  1272. undef_system_macro('FPC_LINK_DYNAMIC');
  1273. exclude(initglobalswitches,cs_link_static);
  1274. include(initglobalswitches,cs_link_smart);
  1275. exclude(initglobalswitches,cs_link_shared);
  1276. LinkTypeSetExplicitly:=true;
  1277. end;
  1278. '-' :
  1279. begin
  1280. exclude(initglobalswitches,cs_link_staticflag);
  1281. exclude(initglobalswitches,cs_link_strip);
  1282. exclude(initglobalswitches,cs_link_map);
  1283. set_default_link_type;
  1284. end;
  1285. else
  1286. IllegalPara(opt);
  1287. end;
  1288. inc(j);
  1289. end;
  1290. end;
  1291. end;
  1292. end;
  1293. '@' :
  1294. begin
  1295. Message(option_no_nested_response_file);
  1296. StopOptions(1);
  1297. end;
  1298. else
  1299. begin
  1300. if (length(param_file)<>0) then
  1301. Message(option_only_one_source_support);
  1302. param_file:=opt;
  1303. Message1(option_found_file,opt);
  1304. end;
  1305. end;
  1306. end;
  1307. procedure Toption.Interpret_file(const filename : string);
  1308. procedure RemoveSep(var fn:string);
  1309. var
  1310. i : longint;
  1311. begin
  1312. i:=0;
  1313. while (i<length(fn)) and (fn[i+1] in [',',' ',#9]) do
  1314. inc(i);
  1315. Delete(fn,1,i);
  1316. i:=length(fn);
  1317. while (i>0) and (fn[i] in [',',' ',#9]) do
  1318. dec(i);
  1319. fn:=copy(fn,1,i);
  1320. end;
  1321. function GetName(var fn:string):string;
  1322. var
  1323. i : longint;
  1324. begin
  1325. i:=0;
  1326. while (i<length(fn)) and (fn[i+1] in ['a'..'z','A'..'Z','0'..'9','_','-']) do
  1327. inc(i);
  1328. GetName:=Copy(fn,1,i);
  1329. Delete(fn,1,i);
  1330. end;
  1331. const
  1332. maxlevel=16;
  1333. var
  1334. f : text;
  1335. s, tmp,
  1336. opts : string;
  1337. skip : array[0..maxlevel-1] of boolean;
  1338. level : longint;
  1339. option_read : boolean;
  1340. begin
  1341. { avoid infinite loop }
  1342. Inc(FileLevel);
  1343. Option_read:=false;
  1344. If FileLevel>MaxLevel then
  1345. Message(option_too_many_cfg_files);
  1346. { Maybe It's Directory ?} //Jaro Change:
  1347. if DirectoryExists(filename) then
  1348. begin
  1349. Message1(option_config_is_dir,filename);
  1350. exit;
  1351. end;
  1352. { open file }
  1353. Message1(option_using_file,filename);
  1354. {$ifdef USE_SYSUTILS}
  1355. assign(f,ExpandFileName(filename));
  1356. {$else USE_SYSUTILS}
  1357. assign(f,FExpand(filename));
  1358. {$endif USE_SYsUTILS}
  1359. {$I-}
  1360. reset(f);
  1361. {$I+}
  1362. if ioresult<>0 then
  1363. begin
  1364. Message1(option_unable_open_file,filename);
  1365. exit;
  1366. end;
  1367. Message1(option_start_reading_configfile,filename);
  1368. fillchar(skip,sizeof(skip),0);
  1369. level:=0;
  1370. while not eof(f) do
  1371. begin
  1372. readln(f,opts);
  1373. RemoveSep(opts);
  1374. if (opts<>'') and (opts[1]<>';') then
  1375. begin
  1376. if opts[1]='#' then
  1377. begin
  1378. Message1(option_interpreting_file_option,opts);
  1379. Delete(opts,1,1);
  1380. s:=upper(GetName(opts));
  1381. if (s='SECTION') then
  1382. begin
  1383. RemoveSep(opts);
  1384. s:=upper(GetName(opts));
  1385. if level=0 then
  1386. skip[level]:=not (assigned(search_macro(s)) or (s='COMMON'));
  1387. end
  1388. else
  1389. if (s='IFDEF') then
  1390. begin
  1391. RemoveSep(opts);
  1392. if Level>=maxlevel then
  1393. begin
  1394. Message(option_too_many_ifdef);
  1395. stopOptions(1);
  1396. end;
  1397. inc(Level);
  1398. skip[level]:=(skip[level-1] or not assigned(search_macro(upper(GetName(opts)))));
  1399. end
  1400. else
  1401. if (s='IFNDEF') then
  1402. begin
  1403. RemoveSep(opts);
  1404. if Level>=maxlevel then
  1405. begin
  1406. Message(option_too_many_ifdef);
  1407. stopOptions(1);
  1408. end;
  1409. inc(Level);
  1410. skip[level]:=(skip[level-1] or assigned(search_macro(upper(GetName(opts)))));
  1411. end
  1412. else
  1413. if (s='ELSE') then
  1414. skip[level]:=skip[level-1] or (not skip[level])
  1415. else
  1416. if (s='ENDIF') then
  1417. begin
  1418. skip[level]:=false;
  1419. if Level=0 then
  1420. begin
  1421. Message(option_too_many_endif);
  1422. stopOptions(1);
  1423. end;
  1424. dec(level);
  1425. end
  1426. else
  1427. if (not skip[level]) then
  1428. begin
  1429. if (s='DEFINE') then
  1430. begin
  1431. RemoveSep(opts);
  1432. tmp:= GetName(opts);
  1433. if tmp <> '' then
  1434. def_system_macro(tmp);
  1435. end
  1436. else
  1437. if (s='UNDEF') then
  1438. begin
  1439. RemoveSep(opts);
  1440. tmp:= GetName(opts);
  1441. if tmp <> '' then
  1442. undef_system_macro(tmp);
  1443. end
  1444. else
  1445. if (s='WRITE') then
  1446. begin
  1447. Delete(opts,1,1);
  1448. WriteLn(opts);
  1449. end
  1450. else
  1451. if (s='INCLUDE') then
  1452. begin
  1453. Delete(opts,1,1);
  1454. Interpret_file(opts);
  1455. end;
  1456. end;
  1457. end
  1458. else
  1459. begin
  1460. if (opts[1]='-') or (opts[1]='@') then
  1461. begin
  1462. if (not skip[level]) then
  1463. interpret_option(opts,false);
  1464. Option_read:=true;
  1465. end
  1466. else
  1467. Message1(option_illegal_para,opts);
  1468. end;
  1469. end;
  1470. end;
  1471. if Level>0 then
  1472. Message(option_too_less_endif);
  1473. if Not Option_read then
  1474. Message1(option_no_option_found,filename)
  1475. else
  1476. Message1(option_end_reading_configfile,filename);
  1477. Close(f);
  1478. Dec(FileLevel);
  1479. end;
  1480. procedure Toption.Interpret_envvar(const envname : string);
  1481. var
  1482. argstart,
  1483. env,
  1484. pc : pchar;
  1485. arglen : longint;
  1486. quote : set of char;
  1487. hs : string;
  1488. begin
  1489. Message1(option_using_env,envname);
  1490. env:=GetEnvPChar(envname);
  1491. pc:=env;
  1492. if assigned(pc) then
  1493. begin
  1494. repeat
  1495. { skip leading spaces }
  1496. while pc^ in [' ',#9,#13] do
  1497. inc(pc);
  1498. case pc^ of
  1499. #0 :
  1500. break;
  1501. '"' :
  1502. begin
  1503. quote:=['"'];
  1504. inc(pc);
  1505. end;
  1506. '''' :
  1507. begin
  1508. quote:=[''''];
  1509. inc(pc);
  1510. end;
  1511. else
  1512. quote:=[' ',#9,#13];
  1513. end;
  1514. { scan until the end of the argument }
  1515. argstart:=pc;
  1516. while (pc^<>#0) and not(pc^ in quote) do
  1517. inc(pc);
  1518. { create argument }
  1519. arglen:=pc-argstart;
  1520. hs[0]:=chr(arglen);
  1521. move(argstart^,hs[1],arglen);
  1522. interpret_option(hs,true);
  1523. { skip quote }
  1524. if pc^ in quote then
  1525. inc(pc);
  1526. until false;
  1527. end
  1528. else
  1529. Message1(option_no_option_found,'(env) '+envname);
  1530. FreeEnvPChar(env);
  1531. end;
  1532. procedure toption.read_parameters;
  1533. var
  1534. opts : string;
  1535. paramindex : longint;
  1536. begin
  1537. paramindex:=0;
  1538. while paramindex<paramcount do
  1539. begin
  1540. inc(paramindex);
  1541. opts:=system.paramstr(paramindex);
  1542. case opts[1] of
  1543. '@' :
  1544. if not firstpass then
  1545. begin
  1546. Delete(opts,1,1);
  1547. Message1(option_reading_further_from,opts);
  1548. interpret_file(opts);
  1549. end;
  1550. '!' :
  1551. if not firstpass then
  1552. begin
  1553. Delete(opts,1,1);
  1554. Message1(option_reading_further_from,'(env) '+opts);
  1555. interpret_envvar(opts);
  1556. end;
  1557. else
  1558. interpret_option(opts,true);
  1559. end;
  1560. end;
  1561. end;
  1562. procedure toption.parsecmd(cmd:string);
  1563. var
  1564. i,ps : longint;
  1565. opts : string;
  1566. begin
  1567. while (cmd<>'') do
  1568. begin
  1569. while cmd[1]=' ' do
  1570. delete(cmd,1,1);
  1571. i:=pos(' ',cmd);
  1572. if i=0 then
  1573. i:=256;
  1574. opts:=Copy(cmd,1,i-1);
  1575. Delete(cmd,1,i);
  1576. case opts[1] of
  1577. '@' :
  1578. if not firstpass then
  1579. begin
  1580. Delete(opts,1,1);
  1581. Message1(option_reading_further_from,opts);
  1582. interpret_file(opts);
  1583. end;
  1584. '!' :
  1585. if not firstpass then
  1586. begin
  1587. Delete(opts,1,1);
  1588. Message1(option_reading_further_from,'(env) '+opts);
  1589. interpret_envvar(opts);
  1590. end;
  1591. '"' :
  1592. begin
  1593. Delete(opts,1,1);
  1594. ps:=pos('"',cmd);
  1595. if (i<>256) and (ps>0) then
  1596. begin
  1597. opts:=opts + ' '+ copy(cmd,1,ps-1);
  1598. cmd:=copy(cmd,ps+1,255);
  1599. end;
  1600. interpret_option(opts,true);
  1601. end;
  1602. else
  1603. interpret_option(opts,true);
  1604. end;
  1605. end;
  1606. end;
  1607. procedure toption.writequickinfo;
  1608. var
  1609. s : string;
  1610. i : longint;
  1611. procedure addinfo(const hs:string);
  1612. begin
  1613. if s<>'' then
  1614. s:=s+' '+hs
  1615. else
  1616. s:=hs;
  1617. end;
  1618. begin
  1619. s:='';
  1620. i:=0;
  1621. while (i<length(quickinfo)) do
  1622. begin
  1623. inc(i);
  1624. case quickinfo[i] of
  1625. 'S' :
  1626. begin
  1627. inc(i);
  1628. case quickinfo[i] of
  1629. 'O' :
  1630. addinfo(lower(source_info.shortname));
  1631. 'P' :
  1632. addinfo(source_cpu_string);
  1633. else
  1634. IllegalPara('-i'+QuickInfo);
  1635. end;
  1636. end;
  1637. 'T' :
  1638. begin
  1639. inc(i);
  1640. case quickinfo[i] of
  1641. 'O' :
  1642. addinfo(lower(target_info.shortname));
  1643. 'P' :
  1644. AddInfo(target_cpu_string);
  1645. else
  1646. IllegalPara('-i'+QuickInfo);
  1647. end;
  1648. end;
  1649. 'V' :
  1650. AddInfo(version_string);
  1651. 'W' :
  1652. AddInfo(full_version_string);
  1653. 'D' :
  1654. AddInfo(date_string);
  1655. '_' :
  1656. ;
  1657. else
  1658. IllegalPara('-i'+QuickInfo);
  1659. end;
  1660. end;
  1661. if s<>'' then
  1662. begin
  1663. writeln(s);
  1664. stopoptions(0);
  1665. end;
  1666. end;
  1667. procedure TOption.TargetDefines(def:boolean);
  1668. var
  1669. s : string;
  1670. i : integer;
  1671. begin
  1672. if def then
  1673. def_system_macro(target_info.shortname)
  1674. else
  1675. undef_system_macro(target_info.shortname);
  1676. s:=target_info.extradefines;
  1677. while (s<>'') do
  1678. begin
  1679. i:=pos(';',s);
  1680. if i=0 then
  1681. i:=length(s)+1;
  1682. if def then
  1683. def_system_macro(Copy(s,1,i-1))
  1684. else
  1685. undef_system_macro(Copy(s,1,i-1));
  1686. delete(s,1,i);
  1687. end;
  1688. end;
  1689. constructor TOption.create;
  1690. begin
  1691. LogoWritten:=false;
  1692. NoPressEnter:=false;
  1693. FirstPass:=false;
  1694. FileLevel:=0;
  1695. Quickinfo:='';
  1696. ParaIncludePath:=TSearchPathList.Create;
  1697. ParaObjectPath:=TSearchPathList.Create;
  1698. ParaUnitPath:=TSearchPathList.Create;
  1699. ParaLibraryPath:=TSearchPathList.Create;
  1700. FillChar(ParaAlignment,sizeof(ParaAlignment),0);
  1701. end;
  1702. destructor TOption.destroy;
  1703. begin
  1704. ParaIncludePath.Free;
  1705. ParaObjectPath.Free;
  1706. ParaUnitPath.Free;
  1707. ParaLibraryPath.Free;
  1708. end;
  1709. {****************************************************************************
  1710. Callable Routines
  1711. ****************************************************************************}
  1712. function check_configfile(const fn:string;var foundfn:string):boolean;
  1713. function CfgFileExists(const fn:string):boolean;
  1714. begin
  1715. Comment(V_Tried,'Configfile search: '+fn);
  1716. CfgFileExists:=FileExists(fn);
  1717. end;
  1718. var
  1719. configpath : pathstr;
  1720. begin
  1721. foundfn:=fn;
  1722. check_configfile:=true;
  1723. { retrieve configpath }
  1724. {$IFDEF USE_SYSUTILS}
  1725. configpath:=FixPath(GetEnvironmentVariable('PPC_CONFIG_PATH'),false);
  1726. {$ELSE USE_SYSUTILS}
  1727. configpath:=FixPath(dos.getenv('PPC_CONFIG_PATH'),false);
  1728. {$ENDIF USE_SYSUTILS}
  1729. {$ifdef Unix}
  1730. if configpath='' then
  1731. configpath:=CleanPath(FixPath(exepath+'../etc/',false));
  1732. {$endif}
  1733. {
  1734. Order to read configuration file :
  1735. try reading fpc.cfg in :
  1736. 1 - current dir
  1737. 2 - configpath
  1738. 3 - compiler path
  1739. }
  1740. if not FileExists(fn) then
  1741. begin
  1742. {$ifdef Unix}
  1743. {$IFDEF USE_SYSUTILS}
  1744. if (GetEnvironmentVariable('HOME')<>'') and CfgFileExists(FixPath(GetEnvironmentVariable('HOME'),false)+'.'+fn) then
  1745. foundfn:=FixPath(GetEnvironmentVariable('HOME'),false)+'.'+fn
  1746. {$ELSE USE_SYSUTILS}
  1747. if (dos.getenv('HOME')<>'') and CfgFileExists(FixPath(dos.getenv('HOME'),false)+'.'+fn) then
  1748. foundfn:=FixPath(dos.getenv('HOME'),false)+'.'+fn
  1749. {$ENDIF USE_SYSUTILS}
  1750. else
  1751. {$endif}
  1752. if CfgFileExists(configpath+fn) then
  1753. foundfn:=configpath+fn
  1754. else
  1755. {$ifndef Unix}
  1756. if CfgFileExists(exepath+fn) then
  1757. foundfn:=exepath+fn
  1758. else
  1759. {$else}
  1760. if CfgFileExists('/etc/'+fn) then
  1761. foundfn:='/etc/'+fn
  1762. else
  1763. {$endif}
  1764. check_configfile:=false;
  1765. end;
  1766. end;
  1767. procedure read_arguments(cmd:string);
  1768. begin
  1769. option:=coption.create;
  1770. disable_configfile:=false;
  1771. { get default messagefile }
  1772. {$IFDEF USE_SYSUTILS}
  1773. msgfilename:=GetEnvironmentVariable('PPC_ERROR_FILE');
  1774. {$ELSE USE_SYSUTILS}
  1775. msgfilename:=dos.getenv('PPC_ERROR_FILE');
  1776. {$ENDIF USE_SYSUTILS}
  1777. { default configfile can be specified on the commandline,
  1778. remove it first }
  1779. if (cmd<>'') and (cmd[1]='[') then
  1780. begin
  1781. ppccfg:=Copy(cmd,2,pos(']',cmd)-2);
  1782. Delete(cmd,1,pos(']',cmd));
  1783. end
  1784. else
  1785. begin
  1786. ppccfg:='fpc.cfg';
  1787. ppcaltcfg:='ppc386.cfg';
  1788. end;
  1789. { first pass reading of parameters, only -i -v -T etc.}
  1790. option.firstpass:=true;
  1791. if cmd<>'' then
  1792. option.parsecmd(cmd)
  1793. else
  1794. begin
  1795. option.read_parameters;
  1796. { Write only quickinfo }
  1797. if option.quickinfo<>'' then
  1798. option.writequickinfo;
  1799. end;
  1800. option.firstpass:=false;
  1801. { target is set here, for wince the default app type is gui }
  1802. if target_info.system in system_wince then
  1803. apptype:=app_gui;
  1804. { default defines }
  1805. def_system_macro(target_info.shortname);
  1806. def_system_macro('FPC');
  1807. def_system_macro('VER'+version_nr);
  1808. def_system_macro('VER'+version_nr+'_'+release_nr);
  1809. def_system_macro('VER'+version_nr+'_'+release_nr+'_'+patch_nr);
  1810. { Temporary defines, until things settle down }
  1811. { "main" symbol is generated in the main program, and left out of the system unit }
  1812. def_system_macro('FPC_DARWIN_PASCALMAIN');
  1813. def_system_macro('FPC_DARWIN_JMP_MAIN');
  1814. def_system_macro('COMPPROCINLINEFIXED');
  1815. def_system_macro('PARAOUTFILE');
  1816. def_system_macro('RESSTRSECTIONS');
  1817. def_system_macro('FPC_HASFIXED64BITVARIANT');
  1818. {$ifdef x86}
  1819. { def_system_macro('INTERNAL_BACKTRACE');}
  1820. {$endif}
  1821. def_system_macro('STR_CONCAT_PROCS');
  1822. if pocall_default = pocall_register then
  1823. def_system_macro('REGCALL');
  1824. { using a case is pretty useless here (FK) }
  1825. { some stuff for TP compatibility }
  1826. {$ifdef i386}
  1827. def_system_macro('CPU86');
  1828. def_system_macro('CPU87');
  1829. def_system_macro('CPU386');
  1830. {$endif}
  1831. {$ifdef m68k}
  1832. def_system_macro('CPU68');
  1833. {$endif}
  1834. { new processor stuff }
  1835. {$ifdef i386}
  1836. def_system_macro('CPUI386');
  1837. def_system_macro('CPU32');
  1838. def_system_macro('FPC_HAS_TYPE_EXTENDED');
  1839. def_system_macro('FPC_HAS_TYPE_DOUBLE');
  1840. def_system_macro('FPC_HAS_TYPE_SINGLE');
  1841. def_system_macro('FPC_HAS_RESOURCES');
  1842. {$endif}
  1843. {$ifdef m68k}
  1844. def_system_macro('CPU68K');
  1845. def_system_macro('CPUM68K');
  1846. def_system_macro('CPU32');
  1847. def_system_macro('FPC_CURRENCY_IS_INT64');
  1848. def_system_macro('FPC_COMP_IS_INT64');
  1849. {$endif}
  1850. {$ifdef ALPHA}
  1851. def_system_macro('CPUALPHA');
  1852. def_system_macro('CPU64');
  1853. {$endif}
  1854. {$ifdef powerpc}
  1855. def_system_macro('CPUPOWERPC');
  1856. def_system_macro('CPUPOWERPC32');
  1857. def_system_macro('CPU32');
  1858. def_system_macro('FPC_HAS_TYPE_DOUBLE');
  1859. def_system_macro('FPC_HAS_TYPE_SINGLE');
  1860. def_system_macro('FPC_INCLUDE_SOFTWARE_INT64_TO_DOUBLE');
  1861. def_system_macro('FPC_CURRENCY_IS_INT64');
  1862. def_system_macro('FPC_COMP_IS_INT64');
  1863. {$endif}
  1864. {$ifdef POWERPC64}
  1865. def_system_macro('CPUPOWERPC');
  1866. def_system_macro('CPUPOWERPC64');
  1867. def_system_macro('CPU64');
  1868. def_system_macro('FPC_HAS_TYPE_DOUBLE');
  1869. def_system_macro('FPC_HAS_TYPE_SINGLE');
  1870. def_system_macro('FPC_INCLUDE_SOFTWARE_INT64_TO_DOUBLE');
  1871. def_system_macro('FPC_CURRENCY_IS_INT64');
  1872. def_system_macro('FPC_COMP_IS_INT64');
  1873. def_system_macro('FPC_REQUIRES_PROPER_ALIGNMENT');
  1874. {$endif}
  1875. {$ifdef iA64}
  1876. def_system_macro('CPUIA64');
  1877. def_system_macro('CPU64');
  1878. {$endif}
  1879. {$ifdef x86_64}
  1880. def_system_macro('CPUX86_64');
  1881. def_system_macro('CPUAMD64');
  1882. def_system_macro('CPU64');
  1883. { not supported for now, afaik (FK)
  1884. def_system_macro('FPC_HAS_TYPE_FLOAT128'); }
  1885. { win64 doesn't support the legacy fpu }
  1886. if target_info.system<>system_x86_64_win64 then
  1887. def_system_macro('FPC_HAS_TYPE_EXTENDED')
  1888. else
  1889. begin
  1890. def_system_macro('FPC_CURRENCY_IS_INT64');
  1891. def_system_macro('FPC_COMP_IS_INT64');
  1892. undef_system_macro('FPC_HAS_TYPE_EXTENDED');
  1893. end;
  1894. def_system_macro('FPC_HAS_TYPE_DOUBLE');
  1895. def_system_macro('FPC_HAS_TYPE_SINGLE');
  1896. {$endif}
  1897. {$ifdef sparc}
  1898. def_system_macro('CPUSPARC');
  1899. def_system_macro('CPUSPARC32');
  1900. def_system_macro('CPU32');
  1901. def_system_macro('FPC_HAS_TYPE_DOUBLE');
  1902. def_system_macro('FPC_HAS_TYPE_SINGLE');
  1903. def_system_macro('FPC_INCLUDE_SOFTWARE_INT64_TO_DOUBLE');
  1904. def_system_macro('FPC_CURRENCY_IS_INT64');
  1905. def_system_macro('FPC_COMP_IS_INT64');
  1906. def_system_macro('FPC_REQUIRES_PROPER_ALIGNMENT');
  1907. {$endif}
  1908. {$ifdef vis}
  1909. def_system_macro('CPUVIS');
  1910. def_system_macro('CPU32');
  1911. {$endif}
  1912. {$ifdef arm}
  1913. def_system_macro('CPUARM');
  1914. def_system_macro('FPUFPA');
  1915. def_system_macro('CPU32');
  1916. def_system_macro('FPC_HAS_TYPE_DOUBLE');
  1917. def_system_macro('FPC_HAS_TYPE_SINGLE');
  1918. def_system_macro('FPC_INCLUDE_SOFTWARE_INT64_TO_DOUBLE');
  1919. def_system_macro('FPC_CURRENCY_IS_INT64');
  1920. def_system_macro('FPC_COMP_IS_INT64');
  1921. def_system_macro('FPC_REQUIRES_PROPER_ALIGNMENT');
  1922. {$endif arm}
  1923. if source_info.system<>target_info.system then
  1924. def_system_macro('FPC_CROSSCOMPILING');
  1925. if source_info.cpu<>target_info.cpu then
  1926. def_system_macro('FPC_CPUCROSSCOMPILING');
  1927. if tf_winlikewidestring in target_info.flags then
  1928. def_system_macro('FPC_WINLIKEWIDESTRING');
  1929. { read configuration file }
  1930. if (not disable_configfile) and
  1931. (ppccfg<>'') then
  1932. begin
  1933. read_configfile:=check_configfile(ppccfg,ppccfg);
  1934. { Maybe alternative configfile ? }
  1935. if (not read_configfile) and
  1936. (ppcaltcfg<>'') then
  1937. read_configfile:=check_configfile(ppcaltcfg,ppccfg);
  1938. end
  1939. else
  1940. read_configfile := false;
  1941. { Read commandline and configfile }
  1942. param_file:='';
  1943. { read configfile }
  1944. if read_configfile then
  1945. option.interpret_file(ppccfg);
  1946. { read parameters again to override config file }
  1947. if cmd<>'' then
  1948. option.parsecmd(cmd)
  1949. else
  1950. begin
  1951. { Write help pages if no parameters are passed }
  1952. if (paramcount=0) then
  1953. Option.WriteHelpPages;
  1954. option.read_parameters;
  1955. { Write only quickinfo }
  1956. if option.quickinfo<>'' then
  1957. option.writequickinfo;
  1958. end;
  1959. { Stop if errors in options }
  1960. if ErrorCount>0 then
  1961. StopOptions(1);
  1962. { Write logo }
  1963. if option.ParaLogo then
  1964. option.writelogo;
  1965. { Non-core target defines }
  1966. Option.TargetDefines(true);
  1967. { endian define }
  1968. case target_info.endian of
  1969. endian_little :
  1970. begin
  1971. def_system_macro('ENDIAN_LITTLE');
  1972. def_system_macro('FPC_LITTLE_ENDIAN');
  1973. end;
  1974. endian_big :
  1975. begin
  1976. def_system_macro('ENDIAN_BIG');
  1977. def_system_macro('FPC_BIG_ENDIAN');
  1978. end;
  1979. end;
  1980. { abi define }
  1981. case target_info.abi of
  1982. abi_powerpc_sysv :
  1983. def_system_macro('FPC_ABI_SYSV');
  1984. abi_powerpc_aix :
  1985. def_system_macro('FPC_ABI_AIX');
  1986. end;
  1987. { CPU Define }
  1988. def_system_macro('CPU'+Cputypestr[initcputype]);
  1989. { Check file to compile }
  1990. if param_file='' then
  1991. begin
  1992. Message(option_no_source_found);
  1993. StopOptions(1);
  1994. end;
  1995. {$ifndef Unix}
  1996. param_file:=FixFileName(param_file);
  1997. {$endif}
  1998. {$IFDEF USE_SYSUTILS}
  1999. inputdir := SplitPath(param_file);
  2000. inputfile := SplitName(param_file);
  2001. inputextension := SplitExtension(param_file);
  2002. {$ELSE USE_SYSUTILS}
  2003. fsplit(param_file,inputdir,inputfile,inputextension);
  2004. {$ENDIF USE_SYSUTILS}
  2005. if inputextension='' then
  2006. begin
  2007. if FileExists(inputdir+inputfile+sourceext) then
  2008. inputextension:=sourceext
  2009. else if FileExists(inputdir+inputfile+pasext) then
  2010. inputextension:=pasext
  2011. else if ((m_mac in aktmodeswitches) or
  2012. (tf_p_ext_support in target_info.flags))
  2013. and FileExists(inputdir+inputfile+pext) then
  2014. inputextension:=pext;
  2015. end;
  2016. { Check output dir }
  2017. if (OutputExeDir<>'') and
  2018. not PathExists(OutputExeDir) then
  2019. begin
  2020. Message1(general_e_path_does_not_exist,OutputExeDir);
  2021. StopOptions(1);
  2022. end;
  2023. { Add paths specified with parameters to the searchpaths }
  2024. UnitSearchPath.AddList(option.ParaUnitPath,true);
  2025. ObjectSearchPath.AddList(option.ParaObjectPath,true);
  2026. IncludeSearchPath.AddList(option.ParaIncludePath,true);
  2027. LibrarySearchPath.AddList(option.ParaLibraryPath,true);
  2028. { add unit environment and exepath to the unit search path }
  2029. if inputdir<>'' then
  2030. Unitsearchpath.AddPath(inputdir,true);
  2031. if not disable_configfile then
  2032. begin
  2033. {$IFDEF USE_SYSUTILS}
  2034. UnitSearchPath.AddPath(GetEnvironmentVariable(target_info.unit_env),false);
  2035. {$ELSE USE_SYSUTILS}
  2036. UnitSearchPath.AddPath(dos.getenv(target_info.unit_env),false);
  2037. {$ENDIF USE_SYSUTILS}
  2038. end;
  2039. {$ifdef Unix}
  2040. {$IFDEF USE_SYSUTILS}
  2041. fpcdir:=FixPath(GetEnvironmentVariable('FPCDIR'),false);
  2042. {$ELSE USE_SYSUTILS}
  2043. fpcdir:=FixPath(getenv('FPCDIR'),false);
  2044. {$ENDIF USE_SYSUTILS}
  2045. if fpcdir='' then
  2046. begin
  2047. if PathExists('/usr/local/lib/fpc/'+version_string) then
  2048. fpcdir:='/usr/local/lib/fpc/'+version_string+'/'
  2049. else
  2050. fpcdir:='/usr/lib/fpc/'+version_string+'/';
  2051. end;
  2052. {$else}
  2053. {$IFDEF USE_SYSUTILS}
  2054. fpcdir:=FixPath(GetEnvironmentVariable('FPCDIR'),false);
  2055. {$ELSE USE_SYSUTILS}
  2056. fpcdir:=FixPath(getenv('FPCDIR'),false);
  2057. {$ENDIF USE_SYSUTILS}
  2058. if fpcdir='' then
  2059. begin
  2060. fpcdir:=ExePath+'../';
  2061. if not(PathExists(fpcdir+'/units')) and
  2062. not(PathExists(fpcdir+'/rtl')) then
  2063. fpcdir:=fpcdir+'../';
  2064. end;
  2065. {$endif}
  2066. { first try development RTL, else use the default installation path }
  2067. if not disable_configfile then
  2068. begin
  2069. if PathExists(FpcDir+'rtl') then
  2070. if tf_use_8_3 in Source_Info.Flags then
  2071. UnitSearchPath.AddPath(FpcDir+'rtl/'+target_os_string,false)
  2072. else
  2073. UnitSearchPath.AddPath(FpcDir+'rtl/'+target_full_string,false)
  2074. else
  2075. if tf_use_8_3 in Source_Info.Flags then
  2076. UnitSearchPath.AddPath(FpcDir+'units/'+target_os_string+'/rtl',false)
  2077. else
  2078. UnitSearchPath.AddPath(FpcDir+'units/'+target_full_string+'/rtl',false);
  2079. end;
  2080. { Add exepath if the exe is not in the current dir, because that is always searched already.
  2081. Do not add it when linking on the target because then we can maybe already find
  2082. .o files that are not for the target }
  2083. if (ExePath<>GetCurrentDir) and
  2084. not(cs_link_on_target in initglobalswitches) then
  2085. UnitSearchPath.AddPath(ExePath,false);
  2086. { Add unit dir to the object and library path }
  2087. objectsearchpath.AddList(unitsearchpath,false);
  2088. librarysearchpath.AddList(unitsearchpath,false);
  2089. { maybe override debug info format }
  2090. if (paratargetdbg<>dbg_none) then
  2091. set_target_dbg(paratargetdbg);
  2092. { maybe override assembler }
  2093. if (paratargetasm<>as_none) then
  2094. begin
  2095. if not set_target_asm(paratargetasm) then
  2096. begin
  2097. Message2(option_incompatible_asm,asminfos[paratargetasm]^.idtxt,target_info.name);
  2098. set_target_asm(target_info.assemextern);
  2099. Message1(option_asm_forced,target_asm.idtxt);
  2100. end;
  2101. end;
  2102. { switch assembler if it's binary and we got -a on the cmdline }
  2103. if (cs_asm_leave in initglobalswitches) and
  2104. (af_outputbinary in target_asm.flags) then
  2105. begin
  2106. Message(option_switch_bin_to_src_assembler);
  2107. set_target_asm(target_info.assemextern);
  2108. end;
  2109. { Force use of external linker if there is no
  2110. internal linker or the linking is skipped }
  2111. if not(cs_link_extern in initglobalswitches) and
  2112. (not assigned(target_info.link) or
  2113. (cs_link_nolink in initglobalswitches)) then
  2114. include(initglobalswitches,cs_link_extern);
  2115. { turn off stripping if compiling with debuginfo or profile }
  2116. if (cs_debuginfo in initmoduleswitches) or
  2117. (cs_profile in initmoduleswitches) then
  2118. exclude(initglobalswitches,cs_link_strip);
  2119. { force fpu emulation on arm/wince and arm/gba }
  2120. if target_info.system in [system_arm_wince,system_arm_gba] then
  2121. include(initmoduleswitches,cs_fp_emulation);
  2122. { Section smartlinking conflicts with import sections on Windows }
  2123. if GenerateImportSection and
  2124. (target_info.system in [system_i386_win32,system_x86_64_win64]) then
  2125. exclude(target_info.flags,tf_smartlink_sections);
  2126. {$ifdef x86_64}
  2127. {$warning HACK: turn off smartlinking}
  2128. exclude(initmoduleswitches,cs_create_smart);
  2129. {$endif}
  2130. if not LinkTypeSetExplicitly then
  2131. set_default_link_type;
  2132. { Default alignment settings,
  2133. 1. load the defaults for the target
  2134. 2. override with generic optimizer setting (little size)
  2135. 3. override with the user specified -Oa }
  2136. UpdateAlignment(initalignment,target_info.alignment);
  2137. if (cs_opt_size in aktoptimizerswitches) then
  2138. begin
  2139. initalignment.procalign:=1;
  2140. initalignment.jumpalign:=1;
  2141. initalignment.loopalign:=1;
  2142. end;
  2143. UpdateAlignment(initalignment,option.paraalignment);
  2144. set_system_macro('FPC_VERSION',version_nr);
  2145. set_system_macro('FPC_RELEASE',release_nr);
  2146. set_system_macro('FPC_PATCH',patch_nr);
  2147. option.free;
  2148. Option:=nil;
  2149. end;
  2150. initialization
  2151. coption:=toption;
  2152. finalization
  2153. if assigned(option) then
  2154. option.free;
  2155. end.