options.pas 63 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168
  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 not(cs_link_internal in initglobalswitches) and
  89. (target_info.system in [system_i386_win32,system_i386_wdosx]) then
  90. begin
  91. def_system_macro('FPC_LINK_SMART');
  92. undef_system_macro('FPC_LINK_STATIC');
  93. undef_system_macro('FPC_LINK_DYNAMIC');
  94. initglobalswitches:=initglobalswitches+[cs_link_smart];
  95. initglobalswitches:=initglobalswitches-[cs_link_shared,cs_link_static];
  96. end
  97. else
  98. begin
  99. undef_system_macro('FPC_LINK_SMART');
  100. def_system_macro('FPC_LINK_STATIC');
  101. undef_system_macro('FPC_LINK_DYNAMIC');
  102. initglobalswitches:=initglobalswitches+[cs_link_static];
  103. initglobalswitches:=initglobalswitches-[cs_link_shared,cs_link_smart];
  104. end;
  105. end;
  106. {****************************************************************************
  107. Toption
  108. ****************************************************************************}
  109. procedure StopOptions(err:longint);
  110. begin
  111. if assigned(Option) then
  112. begin
  113. Option.free;
  114. Option:=nil;
  115. end;
  116. raise ECompilerAbortSilent.Create;
  117. end;
  118. procedure Toption.WriteLogo;
  119. var
  120. p : pchar;
  121. begin
  122. if not LogoWritten then
  123. begin
  124. p:=MessagePchar(option_logo);
  125. while assigned(p) do
  126. Comment(V_Normal,GetMsgLine(p));
  127. LogoWritten:= true;
  128. end;
  129. end;
  130. procedure Toption.WriteInfo;
  131. var
  132. p : pchar;
  133. hs,hs1,s : TCmdStr;
  134. target : tsystem;
  135. cpu : tprocessors;
  136. fpu : tfputype;
  137. begin
  138. p:=MessagePchar(option_info);
  139. while assigned(p) do
  140. begin
  141. s:=GetMsgLine(p);
  142. { list OS Targets }
  143. if pos('$OSTARGETS',s)>0 then
  144. begin
  145. for target:=low(tsystem) to high(tsystem) do
  146. if assigned(targetinfos[target]) then
  147. begin
  148. hs:=s;
  149. hs1:=targetinfos[target]^.name;
  150. if tf_under_development in targetinfos[target]^.flags then
  151. hs1:=hs1+' (under development)';
  152. Replace(hs,'$OSTARGETS',hs1);
  153. Comment(V_Normal,hs);
  154. end;
  155. end
  156. else if pos('$INSTRUCTIONSETS',s)>0 then
  157. begin
  158. for cpu:=low(tprocessors) to high(tprocessors) do
  159. begin
  160. hs:=s;
  161. hs1:=processorsstr[cpu];
  162. if hs1<>'' then
  163. begin
  164. Replace(hs,'$INSTRUCTIONSETS',hs1);
  165. Comment(V_Normal,hs);
  166. end;
  167. end;
  168. end
  169. else if pos('$FPUINSTRUCTIONSETS',s)>0 then
  170. begin
  171. for fpu:=low(tfputype) to high(tfputype) do
  172. begin
  173. hs:=s;
  174. hs1:=fputypestr[fpu];
  175. if hs1<>'' then
  176. begin
  177. Replace(hs,'$FPUINSTRUCTIONSETS',hs1);
  178. Comment(V_Normal,hs);
  179. end;
  180. end;
  181. end
  182. else
  183. Comment(V_Normal,s);
  184. end;
  185. StopOptions(0);
  186. end;
  187. procedure Toption.WriteHelpPages;
  188. function PadEnd(s:string;i:longint):string;
  189. begin
  190. while (length(s)<i) do
  191. s:=s+' ';
  192. PadEnd:=s;
  193. end;
  194. var
  195. lastident,
  196. j,outline,
  197. ident,
  198. lines : longint;
  199. show : boolean;
  200. opt : string[32];
  201. input,
  202. s : string;
  203. p : pchar;
  204. begin
  205. WriteLogo;
  206. Lines:=4;
  207. Message1(option_usage,FixFileName(system.paramstr(0)));
  208. lastident:=0;
  209. p:=MessagePChar(option_help_pages);
  210. while assigned(p) do
  211. begin
  212. { get a line and reset }
  213. s:=GetMsgLine(p);
  214. ident:=0;
  215. show:=false;
  216. { parse options }
  217. case s[1] of
  218. {$ifdef UNITALIASES}
  219. 'a',
  220. {$endif}
  221. {$ifdef EXTDEBUG}
  222. 'e',
  223. {$endif EXTDEBUG}
  224. {$ifdef i386}
  225. '3',
  226. {$endif}
  227. {$ifdef x86_64}
  228. '4',
  229. {$endif}
  230. {$ifdef m68k}
  231. '6',
  232. {$endif}
  233. {$ifdef arm}
  234. 'A',
  235. {$endif}
  236. {$ifdef powerpc}
  237. 'P',
  238. {$endif}
  239. {$ifdef sparc}
  240. 'S',
  241. {$endif}
  242. {$ifdef vis}
  243. 'V',
  244. {$endif}
  245. '*' : show:=true;
  246. end;
  247. if show then
  248. begin
  249. case s[2] of
  250. 'g',
  251. {$ifdef Unix}
  252. 'L',
  253. {$endif}
  254. {$ifdef os2}
  255. 'O',
  256. {$endif}
  257. '*' : show:=true;
  258. else
  259. show:=false;
  260. end;
  261. end;
  262. { now we may show the message or not }
  263. if show then
  264. begin
  265. case s[3] of
  266. '0' : begin
  267. ident:=0;
  268. outline:=0;
  269. end;
  270. '1' : begin
  271. ident:=2;
  272. outline:=7;
  273. end;
  274. '2' : begin
  275. ident:=6;
  276. outline:=11;
  277. end;
  278. '3' : begin
  279. ident:=9;
  280. outline:=11;
  281. end;
  282. end;
  283. j:=pos('_',s);
  284. opt:=Copy(s,4,j-4);
  285. if opt='*' then
  286. opt:=''
  287. else
  288. if opt=' ' then
  289. opt:=PadEnd(opt,outline)
  290. else
  291. opt:=PadEnd('-'+opt,outline);
  292. if (ident=0) and (lastident<>0) then
  293. begin
  294. Comment(V_Normal,'');
  295. inc(Lines);
  296. end;
  297. { page full ? }
  298. if (lines >= page_size - 1) then
  299. begin
  300. if not NoPressEnter then
  301. begin
  302. Message(option_help_press_enter);
  303. readln(input);
  304. if upper(input)='Q' then
  305. StopOptions(0);
  306. end;
  307. lines:=0;
  308. end;
  309. Comment(V_Normal,PadEnd('',ident)+opt+Copy(s,j+1,255));
  310. LastIdent:=Ident;
  311. inc(Lines);
  312. end;
  313. end;
  314. StopOptions(0);
  315. end;
  316. procedure Toption.IllegalPara(const opt:string);
  317. begin
  318. Message1(option_illegal_para,opt);
  319. Message(option_help_pages_para);
  320. StopOptions(1);
  321. end;
  322. function Toption.Unsetbool(var Opts:string; Pos: Longint):boolean;
  323. { checks if the character after pos in Opts is a + or a - and returns resp.
  324. false or true. If it is another character (or none), it also returns false }
  325. begin
  326. UnsetBool := false;
  327. if Length(Opts)>Pos then
  328. begin
  329. inc(Pos);
  330. UnsetBool := Opts[Pos] = '-';
  331. if Opts[Pos] in ['-','+']then
  332. delete(Opts,Pos,1);
  333. end;
  334. end;
  335. procedure TOption.interpret_proc_specific_options(const opt:string);
  336. begin
  337. end;
  338. procedure TOption.interpret_option(const opt:string;ispara:boolean);
  339. var
  340. code : integer;
  341. c : char;
  342. more : string;
  343. major,minor : longint;
  344. error : integer;
  345. j,l : longint;
  346. d : DirStr;
  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. GenerateImportSectionSetExplicitly:=true;
  1067. end;
  1068. 'N':
  1069. begin
  1070. RelocSection:=UnsetBool(More,j);
  1071. RelocSectionSetExplicitly:=true;
  1072. end;
  1073. 'R':
  1074. begin
  1075. { support -WR+ / -WR- as synonyms to -WR / -WN }
  1076. RelocSection:=not UnsetBool(More,j);
  1077. RelocSectionSetExplicitly:=true;
  1078. end;
  1079. 'T':
  1080. begin
  1081. if UnsetBool(More, j) then
  1082. apptype:=app_cui
  1083. else
  1084. apptype:=app_tool;
  1085. end;
  1086. else
  1087. IllegalPara(opt);
  1088. end;
  1089. inc(j);
  1090. end;
  1091. end;
  1092. 'X' :
  1093. begin
  1094. j:=1;
  1095. while j<=length(more) do
  1096. begin
  1097. case More[j] of
  1098. 'i' :
  1099. include(initglobalswitches,cs_link_internal);
  1100. 'm' :
  1101. include(initglobalswitches,cs_link_map);
  1102. 'f' :
  1103. include(initglobalswitches,cs_link_pthread);
  1104. 's' :
  1105. include(initglobalswitches,cs_link_strip);
  1106. 'c' : Cshared:=TRUE;
  1107. 't' :
  1108. include(initglobalswitches,cs_link_staticflag);
  1109. 'D' :
  1110. begin
  1111. def_system_macro('FPC_LINK_DYNAMIC');
  1112. undef_system_macro('FPC_LINK_SMART');
  1113. undef_system_macro('FPC_LINK_STATIC');
  1114. exclude(initglobalswitches,cs_link_static);
  1115. exclude(initglobalswitches,cs_link_smart);
  1116. include(initglobalswitches,cs_link_shared);
  1117. LinkTypeSetExplicitly:=true;
  1118. end;
  1119. 'd' : Dontlinkstdlibpath:=TRUE;
  1120. 'P' : Begin
  1121. utilsprefix:=Copy(more,2,length(More)-1);
  1122. DefaultReplacements(utilsprefix);
  1123. More:='';
  1124. End;
  1125. 'r' : Begin
  1126. rlinkpath:=Copy(more,2,length(More)-1);
  1127. DefaultReplacements(rlinkpath);
  1128. More:='';
  1129. end;
  1130. 'S' :
  1131. begin
  1132. def_system_macro('FPC_LINK_STATIC');
  1133. undef_system_macro('FPC_LINK_SMART');
  1134. undef_system_macro('FPC_LINK_DYNAMIC');
  1135. include(initglobalswitches,cs_link_static);
  1136. exclude(initglobalswitches,cs_link_smart);
  1137. exclude(initglobalswitches,cs_link_shared);
  1138. LinkTypeSetExplicitly:=true;
  1139. end;
  1140. 'X' :
  1141. begin
  1142. def_system_macro('FPC_LINK_SMART');
  1143. undef_system_macro('FPC_LINK_STATIC');
  1144. undef_system_macro('FPC_LINK_DYNAMIC');
  1145. exclude(initglobalswitches,cs_link_static);
  1146. include(initglobalswitches,cs_link_smart);
  1147. exclude(initglobalswitches,cs_link_shared);
  1148. LinkTypeSetExplicitly:=true;
  1149. end;
  1150. 'M' :
  1151. begin
  1152. mainaliasname:=Copy(more,2,length(More)-1);
  1153. More:='';
  1154. end;
  1155. '-' :
  1156. begin
  1157. exclude(initglobalswitches,cs_link_staticflag);
  1158. exclude(initglobalswitches,cs_link_strip);
  1159. exclude(initglobalswitches,cs_link_map);
  1160. set_default_link_type;
  1161. end;
  1162. else
  1163. IllegalPara(opt);
  1164. end;
  1165. inc(j);
  1166. end;
  1167. end;
  1168. { give processor specific options a chance }
  1169. else
  1170. interpret_proc_specific_options(opt);
  1171. end;
  1172. end;
  1173. '@' :
  1174. begin
  1175. Message(option_no_nested_response_file);
  1176. StopOptions(1);
  1177. end;
  1178. else
  1179. begin
  1180. if (length(param_file)<>0) then
  1181. Message(option_only_one_source_support);
  1182. param_file:=opt;
  1183. Message1(option_found_file,opt);
  1184. end;
  1185. end;
  1186. end;
  1187. procedure Toption.Interpret_file(const filename : string);
  1188. procedure RemoveSep(var fn:string);
  1189. var
  1190. i : longint;
  1191. begin
  1192. i:=0;
  1193. while (i<length(fn)) and (fn[i+1] in [',',' ',#9]) do
  1194. inc(i);
  1195. Delete(fn,1,i);
  1196. i:=length(fn);
  1197. while (i>0) and (fn[i] in [',',' ',#9]) do
  1198. dec(i);
  1199. fn:=copy(fn,1,i);
  1200. end;
  1201. function GetName(var fn:string):string;
  1202. var
  1203. i : longint;
  1204. begin
  1205. i:=0;
  1206. while (i<length(fn)) and (fn[i+1] in ['a'..'z','A'..'Z','0'..'9','_','-']) do
  1207. inc(i);
  1208. GetName:=Copy(fn,1,i);
  1209. Delete(fn,1,i);
  1210. end;
  1211. const
  1212. maxlevel=16;
  1213. var
  1214. f : text;
  1215. s, tmp,
  1216. opts : string;
  1217. skip : array[0..maxlevel-1] of boolean;
  1218. level : longint;
  1219. option_read : boolean;
  1220. begin
  1221. { avoid infinite loop }
  1222. Inc(FileLevel);
  1223. Option_read:=false;
  1224. If FileLevel>MaxLevel then
  1225. Message(option_too_many_cfg_files);
  1226. { Maybe It's Directory ?} //Jaro Change:
  1227. if DirectoryExists(filename) then
  1228. begin
  1229. Message1(option_config_is_dir,filename);
  1230. exit;
  1231. end;
  1232. { open file }
  1233. Message1(option_using_file,filename);
  1234. {$ifdef USE_SYSUTILS}
  1235. assign(f,ExpandFileName(filename));
  1236. {$else USE_SYSUTILS}
  1237. assign(f,FExpand(filename));
  1238. {$endif USE_SYsUTILS}
  1239. {$I-}
  1240. reset(f);
  1241. {$I+}
  1242. if ioresult<>0 then
  1243. begin
  1244. Message1(option_unable_open_file,filename);
  1245. exit;
  1246. end;
  1247. Message1(option_start_reading_configfile,filename);
  1248. fillchar(skip,sizeof(skip),0);
  1249. level:=0;
  1250. while not eof(f) do
  1251. begin
  1252. readln(f,opts);
  1253. RemoveSep(opts);
  1254. if (opts<>'') and (opts[1]<>';') then
  1255. begin
  1256. if opts[1]='#' then
  1257. begin
  1258. Message1(option_interpreting_file_option,opts);
  1259. Delete(opts,1,1);
  1260. s:=upper(GetName(opts));
  1261. if (s='SECTION') then
  1262. begin
  1263. RemoveSep(opts);
  1264. s:=upper(GetName(opts));
  1265. if level=0 then
  1266. skip[level]:=not (assigned(search_macro(s)) or (s='COMMON'));
  1267. end
  1268. else
  1269. if (s='IFDEF') then
  1270. begin
  1271. RemoveSep(opts);
  1272. if Level>=maxlevel then
  1273. begin
  1274. Message(option_too_many_ifdef);
  1275. stopOptions(1);
  1276. end;
  1277. inc(Level);
  1278. skip[level]:=(skip[level-1] or not assigned(search_macro(upper(GetName(opts)))));
  1279. end
  1280. else
  1281. if (s='IFNDEF') then
  1282. begin
  1283. RemoveSep(opts);
  1284. if Level>=maxlevel then
  1285. begin
  1286. Message(option_too_many_ifdef);
  1287. stopOptions(1);
  1288. end;
  1289. inc(Level);
  1290. skip[level]:=(skip[level-1] or assigned(search_macro(upper(GetName(opts)))));
  1291. end
  1292. else
  1293. if (s='ELSE') then
  1294. skip[level]:=skip[level-1] or (not skip[level])
  1295. else
  1296. if (s='ENDIF') then
  1297. begin
  1298. skip[level]:=false;
  1299. if Level=0 then
  1300. begin
  1301. Message(option_too_many_endif);
  1302. stopOptions(1);
  1303. end;
  1304. dec(level);
  1305. end
  1306. else
  1307. if (not skip[level]) then
  1308. begin
  1309. if (s='DEFINE') then
  1310. begin
  1311. RemoveSep(opts);
  1312. tmp:= GetName(opts);
  1313. if tmp <> '' then
  1314. def_system_macro(tmp);
  1315. end
  1316. else
  1317. if (s='UNDEF') then
  1318. begin
  1319. RemoveSep(opts);
  1320. tmp:= GetName(opts);
  1321. if tmp <> '' then
  1322. undef_system_macro(tmp);
  1323. end
  1324. else
  1325. if (s='WRITE') then
  1326. begin
  1327. Delete(opts,1,1);
  1328. WriteLn(opts);
  1329. end
  1330. else
  1331. if (s='INCLUDE') then
  1332. begin
  1333. Delete(opts,1,1);
  1334. Interpret_file(opts);
  1335. end;
  1336. end;
  1337. end
  1338. else
  1339. begin
  1340. if (opts[1]='-') or (opts[1]='@') then
  1341. begin
  1342. if (not skip[level]) then
  1343. interpret_option(opts,false);
  1344. Option_read:=true;
  1345. end
  1346. else
  1347. Message1(option_illegal_para,opts);
  1348. end;
  1349. end;
  1350. end;
  1351. if Level>0 then
  1352. Message(option_too_less_endif);
  1353. if Not Option_read then
  1354. Message1(option_no_option_found,filename)
  1355. else
  1356. Message1(option_end_reading_configfile,filename);
  1357. Close(f);
  1358. Dec(FileLevel);
  1359. end;
  1360. procedure Toption.Interpret_envvar(const envname : string);
  1361. var
  1362. argstart,
  1363. env,
  1364. pc : pchar;
  1365. arglen : longint;
  1366. quote : set of char;
  1367. hs : string;
  1368. begin
  1369. Message1(option_using_env,envname);
  1370. env:=GetEnvPChar(envname);
  1371. pc:=env;
  1372. if assigned(pc) then
  1373. begin
  1374. repeat
  1375. { skip leading spaces }
  1376. while pc^ in [' ',#9,#13] do
  1377. inc(pc);
  1378. case pc^ of
  1379. #0 :
  1380. break;
  1381. '"' :
  1382. begin
  1383. quote:=['"'];
  1384. inc(pc);
  1385. end;
  1386. '''' :
  1387. begin
  1388. quote:=[''''];
  1389. inc(pc);
  1390. end;
  1391. else
  1392. quote:=[' ',#9,#13];
  1393. end;
  1394. { scan until the end of the argument }
  1395. argstart:=pc;
  1396. while (pc^<>#0) and not(pc^ in quote) do
  1397. inc(pc);
  1398. { create argument }
  1399. arglen:=pc-argstart;
  1400. hs[0]:=chr(arglen);
  1401. move(argstart^,hs[1],arglen);
  1402. interpret_option(hs,true);
  1403. { skip quote }
  1404. if pc^ in quote then
  1405. inc(pc);
  1406. until false;
  1407. end
  1408. else
  1409. Message1(option_no_option_found,'(env) '+envname);
  1410. FreeEnvPChar(env);
  1411. end;
  1412. procedure toption.read_parameters;
  1413. var
  1414. opts : string;
  1415. paramindex : longint;
  1416. begin
  1417. paramindex:=0;
  1418. while paramindex<paramcount do
  1419. begin
  1420. inc(paramindex);
  1421. opts:=system.paramstr(paramindex);
  1422. case opts[1] of
  1423. '@' :
  1424. if not firstpass then
  1425. begin
  1426. Delete(opts,1,1);
  1427. Message1(option_reading_further_from,opts);
  1428. interpret_file(opts);
  1429. end;
  1430. '!' :
  1431. if not firstpass then
  1432. begin
  1433. Delete(opts,1,1);
  1434. Message1(option_reading_further_from,'(env) '+opts);
  1435. interpret_envvar(opts);
  1436. end;
  1437. else
  1438. interpret_option(opts,true);
  1439. end;
  1440. end;
  1441. end;
  1442. procedure toption.parsecmd(cmd:string);
  1443. var
  1444. i,ps : longint;
  1445. opts : string;
  1446. begin
  1447. while (cmd<>'') do
  1448. begin
  1449. while cmd[1]=' ' do
  1450. delete(cmd,1,1);
  1451. i:=pos(' ',cmd);
  1452. if i=0 then
  1453. i:=256;
  1454. opts:=Copy(cmd,1,i-1);
  1455. Delete(cmd,1,i);
  1456. case opts[1] of
  1457. '@' :
  1458. if not firstpass then
  1459. begin
  1460. Delete(opts,1,1);
  1461. Message1(option_reading_further_from,opts);
  1462. interpret_file(opts);
  1463. end;
  1464. '!' :
  1465. if not firstpass then
  1466. begin
  1467. Delete(opts,1,1);
  1468. Message1(option_reading_further_from,'(env) '+opts);
  1469. interpret_envvar(opts);
  1470. end;
  1471. '"' :
  1472. begin
  1473. Delete(opts,1,1);
  1474. ps:=pos('"',cmd);
  1475. if (i<>256) and (ps>0) then
  1476. begin
  1477. opts:=opts + ' '+ copy(cmd,1,ps-1);
  1478. cmd:=copy(cmd,ps+1,255);
  1479. end;
  1480. interpret_option(opts,true);
  1481. end;
  1482. else
  1483. interpret_option(opts,true);
  1484. end;
  1485. end;
  1486. end;
  1487. procedure toption.writequickinfo;
  1488. var
  1489. s : string;
  1490. i : longint;
  1491. procedure addinfo(const hs:string);
  1492. begin
  1493. if s<>'' then
  1494. s:=s+' '+hs
  1495. else
  1496. s:=hs;
  1497. end;
  1498. begin
  1499. s:='';
  1500. i:=0;
  1501. while (i<length(quickinfo)) do
  1502. begin
  1503. inc(i);
  1504. case quickinfo[i] of
  1505. 'S' :
  1506. begin
  1507. inc(i);
  1508. case quickinfo[i] of
  1509. 'O' :
  1510. addinfo(lower(source_info.shortname));
  1511. 'P' :
  1512. addinfo(source_cpu_string);
  1513. else
  1514. IllegalPara('-i'+QuickInfo);
  1515. end;
  1516. end;
  1517. 'T' :
  1518. begin
  1519. inc(i);
  1520. case quickinfo[i] of
  1521. 'O' :
  1522. addinfo(lower(target_info.shortname));
  1523. 'P' :
  1524. AddInfo(target_cpu_string);
  1525. else
  1526. IllegalPara('-i'+QuickInfo);
  1527. end;
  1528. end;
  1529. 'V' :
  1530. AddInfo(version_string);
  1531. 'D' :
  1532. AddInfo(date_string);
  1533. '_' :
  1534. ;
  1535. else
  1536. IllegalPara('-i'+QuickInfo);
  1537. end;
  1538. end;
  1539. if s<>'' then
  1540. begin
  1541. writeln(s);
  1542. stopoptions(0);
  1543. end;
  1544. end;
  1545. procedure TOption.TargetDefines(def:boolean);
  1546. var
  1547. s : string;
  1548. i : integer;
  1549. begin
  1550. if def then
  1551. def_system_macro(target_info.shortname)
  1552. else
  1553. undef_system_macro(target_info.shortname);
  1554. s:=target_info.extradefines;
  1555. while (s<>'') do
  1556. begin
  1557. i:=pos(';',s);
  1558. if i=0 then
  1559. i:=length(s)+1;
  1560. if def then
  1561. def_system_macro(Copy(s,1,i-1))
  1562. else
  1563. undef_system_macro(Copy(s,1,i-1));
  1564. delete(s,1,i);
  1565. end;
  1566. end;
  1567. constructor TOption.create;
  1568. begin
  1569. LogoWritten:=false;
  1570. NoPressEnter:=false;
  1571. FirstPass:=false;
  1572. FileLevel:=0;
  1573. Quickinfo:='';
  1574. ParaIncludePath:=TSearchPathList.Create;
  1575. ParaObjectPath:=TSearchPathList.Create;
  1576. ParaUnitPath:=TSearchPathList.Create;
  1577. ParaLibraryPath:=TSearchPathList.Create;
  1578. FillChar(ParaAlignment,sizeof(ParaAlignment),0);
  1579. end;
  1580. destructor TOption.destroy;
  1581. begin
  1582. ParaIncludePath.Free;
  1583. ParaObjectPath.Free;
  1584. ParaUnitPath.Free;
  1585. ParaLibraryPath.Free;
  1586. end;
  1587. {****************************************************************************
  1588. Callable Routines
  1589. ****************************************************************************}
  1590. function check_configfile(const fn:string;var foundfn:string):boolean;
  1591. function CfgFileExists(const fn:string):boolean;
  1592. begin
  1593. Comment(V_Tried,'Configfile search: '+fn);
  1594. CfgFileExists:=FileExists(fn);
  1595. end;
  1596. var
  1597. configpath : pathstr;
  1598. begin
  1599. foundfn:=fn;
  1600. check_configfile:=true;
  1601. { retrieve configpath }
  1602. {$IFDEF USE_SYSUTILS}
  1603. configpath:=FixPath(GetEnvironmentVariable('PPC_CONFIG_PATH'),false);
  1604. {$ELSE USE_SYSUTILS}
  1605. configpath:=FixPath(dos.getenv('PPC_CONFIG_PATH'),false);
  1606. {$ENDIF USE_SYSUTILS}
  1607. {$ifdef Unix}
  1608. if configpath='' then
  1609. configpath:=CleanPath(FixPath(exepath+'../etc/',false));
  1610. {$endif}
  1611. {
  1612. Order to read configuration file :
  1613. try reading fpc.cfg in :
  1614. 1 - current dir
  1615. 2 - configpath
  1616. 3 - compiler path
  1617. }
  1618. if not FileExists(fn) then
  1619. begin
  1620. {$ifdef Unix}
  1621. {$IFDEF USE_SYSUTILS}
  1622. if (GetEnvironmentVariable('HOME')<>'') and CfgFileExists(FixPath(GetEnvironmentVariable('HOME'),false)+'.'+fn) then
  1623. foundfn:=FixPath(GetEnvironmentVariable('HOME'),false)+'.'+fn
  1624. {$ELSE USE_SYSUTILS}
  1625. if (dos.getenv('HOME')<>'') and CfgFileExists(FixPath(dos.getenv('HOME'),false)+'.'+fn) then
  1626. foundfn:=FixPath(dos.getenv('HOME'),false)+'.'+fn
  1627. {$ENDIF USE_SYSUTILS}
  1628. else
  1629. {$endif}
  1630. if CfgFileExists(configpath+fn) then
  1631. foundfn:=configpath+fn
  1632. else
  1633. {$ifndef Unix}
  1634. if CfgFileExists(exepath+fn) then
  1635. foundfn:=exepath+fn
  1636. else
  1637. {$else}
  1638. if CfgFileExists('/etc/'+fn) then
  1639. foundfn:='/etc/'+fn
  1640. else
  1641. {$endif}
  1642. check_configfile:=false;
  1643. end;
  1644. end;
  1645. procedure read_arguments(cmd:string);
  1646. begin
  1647. option:=coption.create;
  1648. disable_configfile:=false;
  1649. { get default messagefile }
  1650. {$IFDEF USE_SYSUTILS}
  1651. msgfilename:=GetEnvironmentVariable('PPC_ERROR_FILE');
  1652. {$ELSE USE_SYSUTILS}
  1653. msgfilename:=dos.getenv('PPC_ERROR_FILE');
  1654. {$ENDIF USE_SYSUTILS}
  1655. { default configfile can be specified on the commandline,
  1656. remove it first }
  1657. if (cmd<>'') and (cmd[1]='[') then
  1658. begin
  1659. ppccfg:=Copy(cmd,2,pos(']',cmd)-2);
  1660. Delete(cmd,1,pos(']',cmd));
  1661. end
  1662. else
  1663. begin
  1664. ppccfg:='fpc.cfg';
  1665. ppcaltcfg:='ppc386.cfg';
  1666. end;
  1667. { first pass reading of parameters, only -i -v -T etc.}
  1668. option.firstpass:=true;
  1669. if cmd<>'' then
  1670. option.parsecmd(cmd)
  1671. else
  1672. begin
  1673. option.read_parameters;
  1674. { Write only quickinfo }
  1675. if option.quickinfo<>'' then
  1676. option.writequickinfo;
  1677. end;
  1678. option.firstpass:=false;
  1679. { target is set here, for wince the default app type is gui }
  1680. if target_info.system in system_wince then
  1681. apptype:=app_gui;
  1682. { default defines }
  1683. def_system_macro(target_info.shortname);
  1684. def_system_macro('FPC');
  1685. def_system_macro('VER'+version_nr);
  1686. def_system_macro('VER'+version_nr+'_'+release_nr);
  1687. def_system_macro('VER'+version_nr+'_'+release_nr+'_'+patch_nr);
  1688. { Temporary defines, until things settle down }
  1689. { "main" symbol is generated in the main program, and left out of the system unit }
  1690. def_system_macro('FPC_DARWIN_PASCALMAIN');
  1691. def_system_macro('COMPPROCINLINEFIXED');
  1692. def_system_macro('PARAOUTFILE');
  1693. if pocall_default = pocall_register then
  1694. def_system_macro('REGCALL');
  1695. { using a case is pretty useless here (FK) }
  1696. { some stuff for TP compatibility }
  1697. {$ifdef i386}
  1698. def_system_macro('CPU86');
  1699. def_system_macro('CPU87');
  1700. {$endif}
  1701. {$ifdef m68k}
  1702. def_system_macro('CPU68');
  1703. {$endif}
  1704. { new processor stuff }
  1705. {$ifdef i386}
  1706. def_system_macro('CPUI386');
  1707. def_system_macro('CPU32');
  1708. def_system_macro('FPC_HAS_TYPE_EXTENDED');
  1709. def_system_macro('FPC_HAS_TYPE_DOUBLE');
  1710. def_system_macro('FPC_HAS_TYPE_SINGLE');
  1711. def_system_macro('FPC_HAS_RESOURCES');
  1712. {$endif}
  1713. {$ifdef m68k}
  1714. def_system_macro('CPU68K');
  1715. def_system_macro('CPUM68K');
  1716. def_system_macro('CPU32');
  1717. def_system_macro('FPC_CURRENCY_IS_INT64');
  1718. def_system_macro('FPC_COMP_IS_INT64');
  1719. {$endif}
  1720. {$ifdef ALPHA}
  1721. def_system_macro('CPUALPHA');
  1722. def_system_macro('CPU64');
  1723. {$endif}
  1724. {$ifdef powerpc}
  1725. def_system_macro('CPUPOWERPC');
  1726. def_system_macro('CPUPOWERPC32');
  1727. def_system_macro('CPU32');
  1728. def_system_macro('FPC_HAS_TYPE_DOUBLE');
  1729. def_system_macro('FPC_HAS_TYPE_SINGLE');
  1730. def_system_macro('FPC_INCLUDE_SOFTWARE_INT64_TO_DOUBLE');
  1731. def_system_macro('FPC_CURRENCY_IS_INT64');
  1732. def_system_macro('FPC_COMP_IS_INT64');
  1733. {$endif}
  1734. {$ifdef POWERPC64}
  1735. def_system_macro('CPUPOWERPC');
  1736. def_system_macro('CPUPOWERPC64');
  1737. def_system_macro('CPU64');
  1738. def_system_macro('FPC_HAS_TYPE_DOUBLE');
  1739. def_system_macro('FPC_HAS_TYPE_SINGLE');
  1740. def_system_macro('FPC_INCLUDE_SOFTWARE_INT64_TO_DOUBLE');
  1741. def_system_macro('FPC_CURRENCY_IS_INT64');
  1742. def_system_macro('FPC_COMP_IS_INT64');
  1743. def_system_macro('FPC_REQUIRES_PROPER_ALIGNMENT');
  1744. {$endif}
  1745. {$ifdef iA64}
  1746. def_system_macro('CPUIA64');
  1747. def_system_macro('CPU64');
  1748. {$endif}
  1749. {$ifdef x86_64}
  1750. def_system_macro('CPUX86_64');
  1751. def_system_macro('CPUAMD64');
  1752. def_system_macro('CPU64');
  1753. { not supported for now, afaik (FK)
  1754. def_system_macro('FPC_HAS_TYPE_FLOAT128'); }
  1755. { win64 doesn't support the legacy fpu }
  1756. if target_info.system<>system_x86_64_win64 then
  1757. def_system_macro('FPC_HAS_TYPE_EXTENDED')
  1758. else
  1759. begin
  1760. def_system_macro('FPC_CURRENCY_IS_INT64');
  1761. def_system_macro('FPC_COMP_IS_INT64');
  1762. undef_system_macro('FPC_HAS_TYPE_EXTENDED');
  1763. end;
  1764. def_system_macro('FPC_HAS_TYPE_DOUBLE');
  1765. def_system_macro('FPC_HAS_TYPE_SINGLE');
  1766. {$endif}
  1767. {$ifdef sparc}
  1768. def_system_macro('CPUSPARC');
  1769. def_system_macro('CPUSPARC32');
  1770. def_system_macro('CPU32');
  1771. def_system_macro('FPC_HAS_TYPE_DOUBLE');
  1772. def_system_macro('FPC_HAS_TYPE_SINGLE');
  1773. def_system_macro('FPC_INCLUDE_SOFTWARE_INT64_TO_DOUBLE');
  1774. def_system_macro('FPC_CURRENCY_IS_INT64');
  1775. def_system_macro('FPC_COMP_IS_INT64');
  1776. def_system_macro('FPC_REQUIRES_PROPER_ALIGNMENT');
  1777. {$endif}
  1778. {$ifdef vis}
  1779. def_system_macro('CPUVIS');
  1780. def_system_macro('CPU32');
  1781. {$endif}
  1782. {$ifdef arm}
  1783. def_system_macro('CPUARM');
  1784. def_system_macro('FPUFPA');
  1785. def_system_macro('CPU32');
  1786. def_system_macro('FPC_HAS_TYPE_DOUBLE');
  1787. def_system_macro('FPC_HAS_TYPE_SINGLE');
  1788. def_system_macro('FPC_INCLUDE_SOFTWARE_INT64_TO_DOUBLE');
  1789. def_system_macro('FPC_CURRENCY_IS_INT64');
  1790. def_system_macro('FPC_COMP_IS_INT64');
  1791. def_system_macro('FPC_REQUIRES_PROPER_ALIGNMENT');
  1792. {$endif arm}
  1793. if source_info.system<>target_info.system then
  1794. def_system_macro('FPC_CROSSCOMPILING');
  1795. if source_info.cpu<>target_info.cpu then
  1796. def_system_macro('FPC_CPUCROSSCOMPILING');
  1797. { read configuration file }
  1798. if (not disable_configfile) and
  1799. (ppccfg<>'') then
  1800. begin
  1801. read_configfile:=check_configfile(ppccfg,ppccfg);
  1802. { Maybe alternative configfile ? }
  1803. if (not read_configfile) and
  1804. (ppcaltcfg<>'') then
  1805. read_configfile:=check_configfile(ppcaltcfg,ppccfg);
  1806. end
  1807. else
  1808. read_configfile := false;
  1809. { Read commandline and configfile }
  1810. param_file:='';
  1811. { read configfile }
  1812. if read_configfile then
  1813. option.interpret_file(ppccfg);
  1814. { read parameters again to override config file }
  1815. if cmd<>'' then
  1816. option.parsecmd(cmd)
  1817. else
  1818. begin
  1819. { Write help pages if no parameters are passed }
  1820. if (paramcount=0) then
  1821. Option.WriteHelpPages;
  1822. option.read_parameters;
  1823. { Write only quickinfo }
  1824. if option.quickinfo<>'' then
  1825. option.writequickinfo;
  1826. end;
  1827. { Stop if errors in options }
  1828. if ErrorCount>0 then
  1829. StopOptions(1);
  1830. { Write logo }
  1831. if option.ParaLogo then
  1832. option.writelogo;
  1833. { Non-core target defines }
  1834. Option.TargetDefines(true);
  1835. { endian define }
  1836. case target_info.endian of
  1837. endian_little :
  1838. begin
  1839. def_system_macro('ENDIAN_LITTLE');
  1840. def_system_macro('FPC_LITTLE_ENDIAN');
  1841. end;
  1842. endian_big :
  1843. begin
  1844. def_system_macro('ENDIAN_BIG');
  1845. def_system_macro('FPC_BIG_ENDIAN');
  1846. end;
  1847. end;
  1848. { abi define }
  1849. case target_info.abi of
  1850. abi_powerpc_sysv :
  1851. def_system_macro('FPC_ABI_SYSV');
  1852. abi_powerpc_aix :
  1853. def_system_macro('FPC_ABI_AIX');
  1854. end;
  1855. {$ifdef m68k}
  1856. if initoptprocessor=MC68020 then
  1857. def_system_macro('CPUM68020');
  1858. {$endif m68k}
  1859. { Check file to compile }
  1860. if param_file='' then
  1861. begin
  1862. Message(option_no_source_found);
  1863. StopOptions(1);
  1864. end;
  1865. {$ifndef Unix}
  1866. param_file:=FixFileName(param_file);
  1867. {$endif}
  1868. {$IFDEF USE_SYSUTILS}
  1869. inputdir := SplitPath(param_file);
  1870. inputfile := SplitName(param_file);
  1871. inputextension := SplitExtension(param_file);
  1872. {$ELSE USE_SYSUTILS}
  1873. fsplit(param_file,inputdir,inputfile,inputextension);
  1874. {$ENDIF USE_SYSUTILS}
  1875. if inputextension='' then
  1876. begin
  1877. if FileExists(inputdir+inputfile+sourceext) then
  1878. inputextension:=sourceext
  1879. else if FileExists(inputdir+inputfile+pasext) then
  1880. inputextension:=pasext
  1881. else if ((m_mac in aktmodeswitches) or
  1882. (tf_p_ext_support in target_info.flags))
  1883. and FileExists(inputdir+inputfile+pext) then
  1884. inputextension:=pext;
  1885. end;
  1886. { Check output dir }
  1887. if (OutputExeDir<>'') and
  1888. not PathExists(OutputExeDir) then
  1889. begin
  1890. Message1(general_e_path_does_not_exist,OutputExeDir);
  1891. StopOptions(1);
  1892. end;
  1893. { Add paths specified with parameters to the searchpaths }
  1894. UnitSearchPath.AddList(option.ParaUnitPath,true);
  1895. ObjectSearchPath.AddList(option.ParaObjectPath,true);
  1896. IncludeSearchPath.AddList(option.ParaIncludePath,true);
  1897. LibrarySearchPath.AddList(option.ParaLibraryPath,true);
  1898. { add unit environment and exepath to the unit search path }
  1899. if inputdir<>'' then
  1900. Unitsearchpath.AddPath(inputdir,true);
  1901. if not disable_configfile then
  1902. begin
  1903. {$IFDEF USE_SYSUTILS}
  1904. UnitSearchPath.AddPath(GetEnvironmentVariable(target_info.unit_env),false);
  1905. {$ELSE USE_SYSUTILS}
  1906. UnitSearchPath.AddPath(dos.getenv(target_info.unit_env),false);
  1907. {$ENDIF USE_SYSUTILS}
  1908. end;
  1909. {$ifdef Unix}
  1910. {$IFDEF USE_SYSUTILS}
  1911. fpcdir:=FixPath(GetEnvironmentVariable('FPCDIR'),false);
  1912. {$ELSE USE_SYSUTILS}
  1913. fpcdir:=FixPath(getenv('FPCDIR'),false);
  1914. {$ENDIF USE_SYSUTILS}
  1915. if fpcdir='' then
  1916. begin
  1917. if PathExists('/usr/local/lib/fpc/'+version_string) then
  1918. fpcdir:='/usr/local/lib/fpc/'+version_string+'/'
  1919. else
  1920. fpcdir:='/usr/lib/fpc/'+version_string+'/';
  1921. end;
  1922. {$else}
  1923. {$IFDEF USE_SYSUTILS}
  1924. fpcdir:=FixPath(GetEnvironmentVariable('FPCDIR'),false);
  1925. {$ELSE USE_SYSUTILS}
  1926. fpcdir:=FixPath(getenv('FPCDIR'),false);
  1927. {$ENDIF USE_SYSUTILS}
  1928. if fpcdir='' then
  1929. begin
  1930. fpcdir:=ExePath+'../';
  1931. if not(PathExists(fpcdir+'/units')) and
  1932. not(PathExists(fpcdir+'/rtl')) then
  1933. fpcdir:=fpcdir+'../';
  1934. end;
  1935. {$endif}
  1936. { first try development RTL, else use the default installation path }
  1937. if not disable_configfile then
  1938. begin
  1939. if PathExists(FpcDir+'rtl') then
  1940. if tf_use_8_3 in Source_Info.Flags then
  1941. UnitSearchPath.AddPath(FpcDir+'rtl/'+target_os_string,false)
  1942. else
  1943. UnitSearchPath.AddPath(FpcDir+'rtl/'+target_full_string,false)
  1944. else
  1945. if tf_use_8_3 in Source_Info.Flags then
  1946. UnitSearchPath.AddPath(FpcDir+'units/'+target_os_string+'/rtl',false)
  1947. else
  1948. UnitSearchPath.AddPath(FpcDir+'units/'+target_full_string+'/rtl',false);
  1949. end;
  1950. { Add exepath if the exe is not in the current dir, because that is always searched already.
  1951. Do not add it when linking on the target because then we can maybe already find
  1952. .o files that are not for the target }
  1953. if (ExePath<>GetCurrentDir) and
  1954. not(cs_link_on_target in initglobalswitches) then
  1955. UnitSearchPath.AddPath(ExePath,false);
  1956. { Add unit dir to the object and library path }
  1957. objectsearchpath.AddList(unitsearchpath,false);
  1958. librarysearchpath.AddList(unitsearchpath,false);
  1959. { maybe override debug info format }
  1960. if (paratargetdbg<>dbg_none) then
  1961. set_target_dbg(paratargetdbg);
  1962. { maybe override assembler }
  1963. if (paratargetasm<>as_none) then
  1964. set_target_asm(paratargetasm);
  1965. { switch assembler if it's binary and we got -a on the cmdline }
  1966. if (cs_asm_leave in initglobalswitches) and
  1967. (af_outputbinary in target_asm.flags) then
  1968. begin
  1969. Message(option_switch_bin_to_src_assembler);
  1970. set_target_asm(target_info.assemextern);
  1971. end;
  1972. if (target_asm.supported_target <> system_any) and
  1973. (target_asm.supported_target <> target_info.system) then
  1974. begin
  1975. Message2(option_incompatible_asm,target_asm.idtxt,target_info.name);
  1976. set_target_asm(target_info.assemextern);
  1977. Message1(option_asm_forced,target_asm.idtxt);
  1978. end;
  1979. { turn off stripping if compiling with debuginfo or profile }
  1980. if (cs_debuginfo in initmoduleswitches) or
  1981. (cs_profile in initmoduleswitches) then
  1982. exclude(initglobalswitches,cs_link_strip);
  1983. { force fpu emulation on arm/wince }
  1984. if target_info.system=system_arm_wince then
  1985. include(initmoduleswitches,cs_fp_emulation);
  1986. { By default don't create import section if we use the internal linker }
  1987. if not GenerateImportSectionSetExplicitly and
  1988. (cs_link_internal in aktglobalswitches) then
  1989. GenerateImportSection:=false;
  1990. { Section smartlinking conflicts with import sections on Windows }
  1991. if GenerateImportSection and
  1992. (target_info.system in [system_i386_win32]) then
  1993. exclude(target_info.flags,tf_smartlink_sections);
  1994. {$ifdef x86_64}
  1995. {$warning HACK: turn off smartlinking}
  1996. exclude(initmoduleswitches,cs_create_smart);
  1997. {$endif}
  1998. if not LinkTypeSetExplicitly then
  1999. set_default_link_type;
  2000. { Default alignment settings,
  2001. 1. load the defaults for the target
  2002. 2. override with generic optimizer setting (little size)
  2003. 3. override with the user specified -Oa }
  2004. UpdateAlignment(initalignment,target_info.alignment);
  2005. if (cs_littlesize in aktglobalswitches) then
  2006. begin
  2007. initalignment.procalign:=1;
  2008. initalignment.jumpalign:=1;
  2009. initalignment.loopalign:=1;
  2010. end;
  2011. UpdateAlignment(initalignment,option.paraalignment);
  2012. set_system_macro('FPC_VERSION',version_nr);
  2013. set_system_macro('FPC_RELEASE',release_nr);
  2014. set_system_macro('FPC_PATCH',patch_nr);
  2015. option.free;
  2016. Option:=nil;
  2017. end;
  2018. initialization
  2019. coption:=toption;
  2020. finalization
  2021. if assigned(option) then
  2022. option.free;
  2023. end.