options.pas 65 KB

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