options.pas 63 KB

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