options.pas 63 KB

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