options.pas 63 KB

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