options.pas 96 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945
  1. {
  2. Copyright (c) 1998-2008 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. CClasses,cfileutl,
  22. globtype,globals,verbose,systems,cpuinfo, comprsrc;
  23. Type
  24. TOption=class
  25. FirstPass,
  26. ParaLogo,
  27. NoPressEnter,
  28. LogoWritten,
  29. FPUSetExplicitly,
  30. CPUSetExplicitly,
  31. OptCPUSetExplicitly: boolean;
  32. FileLevel : longint;
  33. QuickInfo : string;
  34. ParaIncludePath,
  35. ParaUnitPath,
  36. ParaObjectPath,
  37. ParaLibraryPath,
  38. ParaFrameworkPath : TSearchPathList;
  39. ParaAlignment : TAlignmentInfo;
  40. Constructor Create;
  41. Destructor Destroy;override;
  42. procedure WriteLogo;
  43. procedure WriteInfo;
  44. procedure WriteHelpPages;
  45. procedure WriteQuickInfo;
  46. procedure IllegalPara(const opt:TCmdStr);
  47. procedure UnsupportedPara(const opt:TCmdStr);
  48. procedure IgnoredPara(const opt:TCmdStr);
  49. function Unsetbool(var Opts:TCmdStr; Pos: Longint):boolean;
  50. procedure interpret_option(const opt :TCmdStr;ispara:boolean);
  51. procedure Interpret_envvar(const envname : TCmdStr);
  52. procedure Interpret_file(const filename : TPathStr);
  53. procedure Read_Parameters;
  54. procedure parsecmd(cmd:TCmdStr);
  55. procedure TargetOptions(def:boolean);
  56. procedure CheckOptionsCompatibility;
  57. procedure ForceStaticLinking;
  58. end;
  59. TOptionClass=class of toption;
  60. var
  61. coption : TOptionClass;
  62. procedure read_arguments(cmd:TCmdStr);
  63. implementation
  64. uses
  65. widestr,
  66. {$if FPC_FULLVERSION<20700}ccharset{$else}charset{$endif},
  67. SysUtils,
  68. version,
  69. cutils,cmsgs,
  70. comphook,
  71. symtable,scanner,rabase,
  72. wpobase,
  73. symconst,
  74. i_bsd;
  75. const
  76. page_size = 24;
  77. var
  78. option : toption;
  79. read_configfile, { read config file, set when a cfgfile is found }
  80. disable_configfile : boolean;
  81. fpcdir,
  82. ppccfg,
  83. param_file : string; { file to compile specified on the commandline }
  84. {****************************************************************************
  85. Options not supported on all platforms
  86. ****************************************************************************}
  87. const
  88. { pointer checking (requires special code in FPC_CHECKPOINTER,
  89. and can never work for libc-based targets or any other program
  90. linking to an external library)
  91. }
  92. supported_targets_gc = [system_i386_linux,system_powerpc_linux]
  93. + [system_i386_win32]
  94. + [system_i386_GO32V2]
  95. + [system_i386_os2]
  96. + [system_i386_beos,system_i386_haiku]
  97. + [system_powerpc_morphos];
  98. { gprof (requires implementation of g_profilecode in the code generator) }
  99. supported_targets_pg = [system_i386_linux,system_x86_64_linux]
  100. + [system_i386_win32]
  101. + [system_powerpc_darwin,system_x86_64_darwin]
  102. + [system_i386_GO32V2]
  103. + [system_i386_freebsd]
  104. + [system_i386_netbsd]
  105. + [system_i386_wdosx];
  106. suppported_targets_x_smallr = systems_linux + systems_solaris
  107. + [system_i386_haiku]
  108. + [system_i386_beos];
  109. {****************************************************************************
  110. Defines
  111. ****************************************************************************}
  112. procedure set_default_link_type;
  113. begin
  114. undef_system_macro('FPC_LINK_SMART');
  115. def_system_macro('FPC_LINK_STATIC');
  116. undef_system_macro('FPC_LINK_DYNAMIC');
  117. init_settings.globalswitches:=init_settings.globalswitches+[cs_link_static];
  118. init_settings.globalswitches:=init_settings.globalswitches-[cs_link_shared,cs_link_smart];
  119. end;
  120. {****************************************************************************
  121. Toption
  122. ****************************************************************************}
  123. procedure StopOptions(err:longint);
  124. begin
  125. if assigned(Option) then
  126. begin
  127. Option.free;
  128. Option:=nil;
  129. end;
  130. raise ECompilerAbortSilent.Create;
  131. end;
  132. procedure Toption.WriteLogo;
  133. var
  134. p : pchar;
  135. begin
  136. if not LogoWritten then
  137. begin
  138. p:=MessagePchar(option_logo);
  139. while assigned(p) do
  140. Comment(V_Normal,GetMsgLine(p));
  141. LogoWritten:= true;
  142. end;
  143. end;
  144. procedure Toption.WriteInfo;
  145. var
  146. p : pchar;
  147. hs,hs1,s : TCmdStr;
  148. target : tsystem;
  149. cpu : tcputype;
  150. fpu : tfputype;
  151. opt : toptimizerswitch;
  152. wpopt: twpoptimizerswitch;
  153. abi : tabi;
  154. {$if defined(arm) or defined(avr)}
  155. controllertype : tcontrollertype;
  156. {$endif defined(arm) or defined(avr)}
  157. begin
  158. p:=MessagePchar(option_info);
  159. while assigned(p) do
  160. begin
  161. s:=GetMsgLine(p);
  162. { list OS Targets }
  163. if pos('$OSTARGETS',s)>0 then
  164. begin
  165. for target:=low(tsystem) to high(tsystem) do
  166. if assigned(targetinfos[target]) then
  167. begin
  168. hs:=s;
  169. hs1:=targetinfos[target]^.name;
  170. if tf_under_development in targetinfos[target]^.flags then
  171. hs1:=hs1+' (under development)';
  172. Replace(hs,'$OSTARGETS',hs1);
  173. Comment(V_Normal,hs);
  174. end;
  175. end
  176. else if pos('$INSTRUCTIONSETS',s)>0 then
  177. begin
  178. for cpu:=low(tcputype) to high(tcputype) do
  179. begin
  180. hs:=s;
  181. hs1:=cputypestr[cpu];
  182. if hs1<>'' then
  183. begin
  184. Replace(hs,'$INSTRUCTIONSETS',hs1);
  185. Comment(V_Normal,hs);
  186. end;
  187. end;
  188. end
  189. else if pos('$FPUINSTRUCTIONSETS',s)>0 then
  190. begin
  191. for fpu:=low(tfputype) to high(tfputype) do
  192. begin
  193. hs:=s;
  194. hs1:=fputypestr[fpu];
  195. if hs1<>'' then
  196. begin
  197. Replace(hs,'$FPUINSTRUCTIONSETS',hs1);
  198. Comment(V_Normal,hs);
  199. end;
  200. end;
  201. end
  202. else if pos('$ABITARGETS',s)>0 then
  203. begin
  204. for abi:=low(abi) to high(abi) do
  205. begin
  206. hs:=s;
  207. hs1:=abi2str[abi];
  208. if hs1<>'' then
  209. begin
  210. Replace(hs,'$ABITARGETS',hs1);
  211. Comment(V_Normal,hs);
  212. end;
  213. end;
  214. end
  215. else if pos('$OPTIMIZATIONS',s)>0 then
  216. begin
  217. for opt:=low(toptimizerswitch) to high(toptimizerswitch) do
  218. begin
  219. if opt in supported_optimizerswitches then
  220. begin
  221. hs:=s;
  222. hs1:=OptimizerSwitchStr[opt];
  223. if hs1<>'' then
  224. begin
  225. Replace(hs,'$OPTIMIZATIONS',hs1);
  226. Comment(V_Normal,hs);
  227. end;
  228. end;
  229. end;
  230. end
  231. else if pos('$WPOPTIMIZATIONS',s)>0 then
  232. begin
  233. for wpopt:=low(twpoptimizerswitch) to high(twpoptimizerswitch) do
  234. begin
  235. { currently all whole program optimizations are platform-independent
  236. if opt in supported_wpoptimizerswitches then
  237. }
  238. begin
  239. hs:=s;
  240. hs1:=WPOptimizerSwitchStr[wpopt];
  241. if hs1<>'' then
  242. begin
  243. Replace(hs,'$WPOPTIMIZATIONS',hs1);
  244. Comment(V_Normal,hs);
  245. end;
  246. end;
  247. end
  248. end
  249. else if pos('$CONTROLLERTYPES',s)>0 then
  250. begin
  251. {$if defined(arm) or defined(avr)}
  252. for controllertype:=low(tcontrollertype) to high(tcontrollertype) do
  253. begin
  254. { currently all whole program optimizations are platform-independent
  255. if opt in supported_wpoptimizerswitches then
  256. }
  257. begin
  258. hs:=s;
  259. hs1:=embedded_controllers[controllertype].ControllerTypeStr;
  260. if hs1<>'' then
  261. begin
  262. Replace(hs,'$CONTROLLERTYPES',hs1);
  263. Comment(V_Normal,hs);
  264. end;
  265. end;
  266. end
  267. {$else defined(arm) or defined(avr)}
  268. {$endif defined(arm) or defined(avr)}
  269. end
  270. else
  271. Comment(V_Normal,s);
  272. end;
  273. StopOptions(0);
  274. end;
  275. procedure Toption.WriteHelpPages;
  276. function PadEnd(s:string;i:longint):string;
  277. begin
  278. while (length(s)<i) do
  279. s:=s+' ';
  280. PadEnd:=s;
  281. end;
  282. var
  283. lastident,
  284. j,outline,
  285. ident,
  286. lines : longint;
  287. show : boolean;
  288. opt : string[32];
  289. input,
  290. s : string;
  291. p : pchar;
  292. begin
  293. WriteLogo;
  294. Lines:=4;
  295. Message1(option_usage,FixFileName(system.paramstr(0)));
  296. lastident:=0;
  297. p:=MessagePChar(option_help_pages);
  298. while assigned(p) do
  299. begin
  300. { get a line and reset }
  301. s:=GetMsgLine(p);
  302. ident:=0;
  303. show:=false;
  304. { parse options }
  305. case s[1] of
  306. {$ifdef UNITALIASES}
  307. 'a',
  308. {$endif}
  309. {$ifdef EXTDEBUG}
  310. 'e',
  311. {$endif EXTDEBUG}
  312. {$ifdef i386}
  313. '3',
  314. {$endif}
  315. {$ifdef x86_64}
  316. '4',
  317. {$endif}
  318. {$ifdef m68k}
  319. '6',
  320. {$endif}
  321. {$ifdef arm}
  322. 'A',
  323. {$endif}
  324. {$ifdef powerpc}
  325. 'P',
  326. {$endif}
  327. {$ifdef powerpc64}
  328. 'p',
  329. {$endif}
  330. {$ifdef sparc}
  331. 'S',
  332. {$endif}
  333. {$ifdef vis}
  334. 'I',
  335. {$endif}
  336. {$ifdef avr}
  337. 'V',
  338. {$endif}
  339. '*' : show:=true;
  340. end;
  341. if show then
  342. begin
  343. case s[2] of
  344. 'g',
  345. {$ifdef Unix}
  346. 'L',
  347. {$endif}
  348. {$ifdef os2}
  349. 'O',
  350. {$endif}
  351. '*' : show:=true;
  352. else
  353. show:=false;
  354. end;
  355. end;
  356. { now we may show the message or not }
  357. if show then
  358. begin
  359. case s[3] of
  360. '0' : begin
  361. ident:=0;
  362. outline:=0;
  363. end;
  364. '1' : begin
  365. ident:=2;
  366. outline:=7;
  367. end;
  368. '2' : begin
  369. ident:=6;
  370. outline:=11;
  371. end;
  372. '3' : begin
  373. ident:=9;
  374. outline:=11;
  375. end;
  376. end;
  377. j:=pos('_',s);
  378. opt:=Copy(s,4,j-4);
  379. if opt='*' then
  380. opt:=''
  381. else
  382. if opt=' ' then
  383. opt:=PadEnd(opt,outline)
  384. else
  385. opt:=PadEnd('-'+opt,outline);
  386. if (ident=0) and (lastident<>0) then
  387. begin
  388. Comment(V_Normal,'');
  389. inc(Lines);
  390. end;
  391. { page full ? }
  392. if (lines >= page_size - 1) then
  393. begin
  394. if not NoPressEnter then
  395. begin
  396. Message(option_help_press_enter);
  397. readln(input);
  398. if upper(input)='Q' then
  399. StopOptions(0);
  400. end;
  401. lines:=0;
  402. end;
  403. Comment(V_Normal,PadEnd('',ident)+opt+Copy(s,j+1,255));
  404. LastIdent:=Ident;
  405. inc(Lines);
  406. end;
  407. end;
  408. StopOptions(0);
  409. end;
  410. procedure Toption.IllegalPara(const opt:TCmdStr);
  411. begin
  412. Message1(option_illegal_para,opt);
  413. Message(option_help_pages_para);
  414. StopOptions(1);
  415. end;
  416. procedure toption.UnsupportedPara(const opt: TCmdStr);
  417. begin
  418. Message1(option_unsupported_target,opt);
  419. StopOptions(1);
  420. end;
  421. procedure toption.IgnoredPara(const opt: TCmdStr);
  422. begin
  423. Message1(option_ignored_target,opt);
  424. end;
  425. procedure toption.ForceStaticLinking;
  426. begin
  427. def_system_macro('FPC_LINK_STATIC');
  428. undef_system_macro('FPC_LINK_SMART');
  429. undef_system_macro('FPC_LINK_DYNAMIC');
  430. include(init_settings.globalswitches,cs_link_static);
  431. exclude(init_settings.globalswitches,cs_link_smart);
  432. exclude(init_settings.globalswitches,cs_link_shared);
  433. LinkTypeSetExplicitly:=true;
  434. end;
  435. function Toption.Unsetbool(var Opts:TCmdStr; Pos: Longint):boolean;
  436. { checks if the character after pos in Opts is a + or a - and returns resp.
  437. false or true. If it is another character (or none), it also returns false }
  438. begin
  439. UnsetBool := false;
  440. if Length(Opts)>Pos then
  441. begin
  442. inc(Pos);
  443. UnsetBool := Opts[Pos] = '-';
  444. if Opts[Pos] in ['-','+']then
  445. delete(Opts,Pos,1);
  446. end;
  447. end;
  448. procedure TOption.interpret_option(const opt:TCmdStr;ispara:boolean);
  449. var
  450. code : integer;
  451. c : char;
  452. more : TCmdStr;
  453. major,minor : longint;
  454. error : integer;
  455. j,l : longint;
  456. d,s : TCmdStr;
  457. unicodemapping : punicodemap;
  458. begin
  459. if opt='' then
  460. exit;
  461. { only parse define,undef,target,verbosity,link etc options the firsttime }
  462. if firstpass and
  463. not(
  464. (opt[1]='-') and
  465. (
  466. ((length(opt)>1) and (opt[2] in ['i','d','v','T','u','n','X','l'])) or
  467. ((length(opt)>3) and (opt[2]='F') and (opt[3]='e'))
  468. )
  469. ) then
  470. exit;
  471. Message1(option_handling_option,opt);
  472. case opt[1] of
  473. '-' :
  474. begin
  475. more:=Copy(opt,3,2147483647);
  476. if firstpass then
  477. Message1(option_interpreting_firstpass_option,opt)
  478. else
  479. Message1(option_interpreting_option,opt);
  480. case opt[2] of
  481. '?' :
  482. WriteHelpPages;
  483. 'a' :
  484. begin
  485. include(init_settings.globalswitches,cs_asm_leave);
  486. j:=1;
  487. while j<=length(more) do
  488. begin
  489. case more[j] of
  490. 'l' :
  491. include(init_settings.globalswitches,cs_asm_source);
  492. 'r' :
  493. include(init_settings.globalswitches,cs_asm_regalloc);
  494. 't' :
  495. include(init_settings.globalswitches,cs_asm_tempalloc);
  496. 'n' :
  497. include(init_settings.globalswitches,cs_asm_nodes);
  498. 'p' :
  499. begin
  500. exclude(init_settings.globalswitches,cs_asm_leave);
  501. if UnsetBool(More, 0) then
  502. exclude(init_settings.globalswitches,cs_asm_pipe)
  503. else
  504. include(init_settings.globalswitches,cs_asm_pipe);
  505. end;
  506. '-' :
  507. init_settings.globalswitches:=init_settings.globalswitches -
  508. [cs_asm_leave, cs_asm_source,cs_asm_regalloc, cs_asm_tempalloc,
  509. cs_asm_nodes, cs_asm_pipe];
  510. else
  511. IllegalPara(opt);
  512. end;
  513. inc(j);
  514. end;
  515. end;
  516. 'A' :
  517. begin
  518. paratargetasm:=find_asm_by_string(More);
  519. if paratargetasm=as_none then
  520. IllegalPara(opt);
  521. end;
  522. 'b' :
  523. begin
  524. // Message1(option_obsolete_switch,'-b');
  525. if UnsetBool(More,0) then
  526. begin
  527. init_settings.moduleswitches:=init_settings.moduleswitches-[cs_browser];
  528. init_settings.moduleswitches:=init_settings.moduleswitches-[cs_local_browser];
  529. end
  530. else
  531. begin
  532. init_settings.moduleswitches:=init_settings.moduleswitches+[cs_browser];
  533. end;
  534. if More<>'' then
  535. if (More='l') or (More='l+') then
  536. init_settings.moduleswitches:=init_settings.moduleswitches+[cs_local_browser]
  537. else if More='l-' then
  538. init_settings.moduleswitches:=init_settings.moduleswitches-[cs_local_browser]
  539. else
  540. IllegalPara(opt);
  541. end;
  542. 'B' :
  543. do_build:=not UnSetBool(more,0);
  544. 'C' :
  545. begin
  546. j:=1;
  547. while j<=length(more) do
  548. begin
  549. case more[j] of
  550. '3' :
  551. If UnsetBool(More, j) then
  552. exclude(init_settings.localswitches,cs_ieee_errors)
  553. Else
  554. include(init_settings.localswitches,cs_ieee_errors);
  555. 'a' :
  556. begin
  557. s:=upper(copy(more,j+1,length(more)-j));
  558. if not(SetAbiType(s,target_info.abi)) then
  559. IllegalPara(opt);
  560. break;
  561. end;
  562. 'b' :
  563. begin
  564. if UnsetBool(More, j) then
  565. target_info.endian:=endian_little
  566. else
  567. target_info.endian:=endian_big;
  568. end;
  569. 'c' :
  570. begin
  571. if not SetAktProcCall(upper(copy(more,j+1,length(more)-j)),init_settings.defproccall) then
  572. IllegalPara(opt);
  573. break;
  574. end;
  575. {$ifdef cpufpemu}
  576. 'e' :
  577. begin
  578. If UnsetBool(More, j) then
  579. exclude(init_settings.moduleswitches,cs_fp_emulation)
  580. Else
  581. include(init_settings.moduleswitches,cs_fp_emulation);
  582. end;
  583. {$endif cpufpemu}
  584. 'f' :
  585. begin
  586. s:=upper(copy(more,j+1,length(more)-j));
  587. if not(SetFpuType(s,init_settings.fputype)) then
  588. IllegalPara(opt);
  589. FPUSetExplicitly:=True;
  590. break;
  591. end;
  592. 'F' :
  593. begin
  594. if not SetMinFPConstPrec(copy(more,j+1,length(more)-j),init_settings.minfpconstprec) then
  595. IllegalPara(opt);
  596. break;
  597. end;
  598. 'g' :
  599. begin
  600. if tf_no_pic_supported in target_info.flags then
  601. begin
  602. { consume a possible '-' coming after it }
  603. UnsetBool(More, j);
  604. message(scan_w_pic_ignored);
  605. end
  606. else if UnsetBool(More, j) then
  607. exclude(init_settings.moduleswitches,cs_create_pic)
  608. else
  609. include(init_settings.moduleswitches,cs_create_pic);
  610. end;
  611. 'h' :
  612. begin
  613. val(copy(more,j+1,length(more)-j),heapsize,code);
  614. if (code<>0) or (heapsize<1024) then
  615. IllegalPara(opt);
  616. break;
  617. end;
  618. 'i' :
  619. If UnsetBool(More, j) then
  620. exclude(init_settings.localswitches,cs_check_io)
  621. else
  622. include(init_settings.localswitches,cs_check_io);
  623. 'n' :
  624. If UnsetBool(More, j) then
  625. exclude(init_settings.globalswitches,cs_link_nolink)
  626. Else
  627. include(init_settings.globalswitches,cs_link_nolink);
  628. 'o' :
  629. If UnsetBool(More, j) then
  630. exclude(init_settings.localswitches,cs_check_overflow)
  631. Else
  632. include(init_settings.localswitches,cs_check_overflow);
  633. 'O' :
  634. If UnsetBool(More, j) then
  635. exclude(init_settings.localswitches,cs_check_ordinal_size)
  636. Else
  637. include(init_settings.localswitches,cs_check_ordinal_size);
  638. 'p' :
  639. begin
  640. s:=upper(copy(more,j+1,length(more)-j));
  641. if not(Setcputype(s,init_settings.cputype)) then
  642. IllegalPara(opt);
  643. CPUSetExplicitly:=true;
  644. break;
  645. end;
  646. 'P':
  647. begin
  648. delete(more,1,1);
  649. if upper(copy(more,1,pos('=',more)-1))='PACKSET' then
  650. begin
  651. delete(more,1,pos('=',more));
  652. if more='0' then
  653. init_settings.setalloc:=0
  654. else if (more='1') or (more='DEFAULT') or (more='NORMAL') then
  655. init_settings.setalloc:=1
  656. else if more='2' then
  657. init_settings.setalloc:=2
  658. else if more='4' then
  659. init_settings.setalloc:=4
  660. else if more='8' then
  661. init_settings.setalloc:=8
  662. else
  663. IllegalPara(opt);
  664. end
  665. else
  666. IllegalPara(opt);
  667. end;
  668. 'r' :
  669. If UnsetBool(More, j) then
  670. exclude(init_settings.localswitches,cs_check_range)
  671. Else
  672. include(init_settings.localswitches,cs_check_range);
  673. 'R' :
  674. If UnsetBool(More, j) then
  675. begin
  676. exclude(init_settings.localswitches,cs_check_range);
  677. exclude(init_settings.localswitches,cs_check_object);
  678. end
  679. Else
  680. begin
  681. include(init_settings.localswitches,cs_check_range);
  682. include(init_settings.localswitches,cs_check_object);
  683. end;
  684. 's' :
  685. begin
  686. val(copy(more,j+1,length(more)-j),stacksize,code);
  687. if (code<>0) or (stacksize>=67107840) or (stacksize<1024) then
  688. IllegalPara(opt);
  689. break;
  690. end;
  691. 't' :
  692. If UnsetBool(More, j) then
  693. exclude(init_settings.localswitches,cs_check_stack)
  694. Else
  695. include(init_settings.localswitches,cs_check_stack);
  696. 'D' :
  697. If UnsetBool(More, j) then
  698. exclude(init_settings.moduleswitches,cs_create_dynamic)
  699. Else
  700. include(init_settings.moduleswitches,cs_create_dynamic);
  701. 'X' :
  702. If UnsetBool(More, j) then
  703. exclude(init_settings.moduleswitches,cs_create_smart)
  704. Else
  705. include(init_settings.moduleswitches,cs_create_smart);
  706. else
  707. IllegalPara(opt);
  708. end;
  709. inc(j);
  710. end;
  711. end;
  712. 'd' :
  713. if more <> '' then
  714. begin
  715. l:=Pos(':=',more);
  716. if l>0 then
  717. set_system_compvar(Copy(more,1,l-1),Copy(more,l+2,255))
  718. else
  719. def_system_macro(more);
  720. end;
  721. 'D' :
  722. begin
  723. include(init_settings.globalswitches,cs_link_deffile);
  724. j:=1;
  725. while j<=length(more) do
  726. begin
  727. case more[j] of
  728. 'd' :
  729. begin
  730. description:=Copy(more,j+1,255);
  731. break;
  732. end;
  733. 'v' :
  734. begin
  735. dllversion:=Copy(more,j+1,255);
  736. l:=pos('.',dllversion);
  737. dllminor:=0;
  738. error:=0;
  739. if l>0 then
  740. begin
  741. val(copy(dllversion,l+1,255),minor,error);
  742. if (error=0) and
  743. (minor>=0) and (minor<=$ffff) then
  744. dllminor:=minor
  745. else
  746. if error=0 then
  747. error:=1;
  748. end;
  749. if l=0 then
  750. l:=256;
  751. dllmajor:=1;
  752. if error=0 then
  753. val(copy(dllversion,1,l-1),major,error);
  754. if (error=0) and (major>=0) and (major<=$ffff) then
  755. dllmajor:=major
  756. else
  757. if error=0 then
  758. error:=1;
  759. if error<>0 then
  760. Message1(scan_w_wrong_version_ignored,dllversion);
  761. break;
  762. end;
  763. 'w' :
  764. usewindowapi:=true;
  765. '-' :
  766. begin
  767. exclude(init_settings.globalswitches,cs_link_deffile);
  768. usewindowapi:=false;
  769. end;
  770. else
  771. IllegalPara(opt);
  772. end;
  773. inc(j);
  774. end;
  775. end;
  776. 'e' :
  777. exepath:=FixPath(More,true);
  778. 'E' :
  779. begin
  780. if UnsetBool(More, 0) then
  781. exclude(init_settings.globalswitches,cs_link_nolink)
  782. else
  783. include(init_settings.globalswitches,cs_link_nolink);
  784. end;
  785. 'f' :
  786. begin
  787. if more='PIC' then
  788. begin
  789. if tf_no_pic_supported in target_info.flags then
  790. message(scan_w_pic_ignored)
  791. else
  792. include(init_settings.moduleswitches,cs_create_pic)
  793. end
  794. else
  795. IllegalPara(opt);
  796. end;
  797. 'F' :
  798. begin
  799. if more='' then
  800. IllegalPara(opt);
  801. c:=more[1];
  802. Delete(more,1,1);
  803. DefaultReplacements(More);
  804. case c of
  805. 'a' :
  806. autoloadunits:=more;
  807. 'c' :
  808. begin
  809. if (upper(more)='UTF8') or (upper(more)='UTF-8') then
  810. init_settings.sourcecodepage:=CP_UTF8
  811. else if not(cpavailable(more)) then
  812. Message1(option_code_page_not_available,more)
  813. else
  814. init_settings.sourcecodepage:=codepagebyname(more);
  815. include(init_settings.moduleswitches,cs_explicit_codepage);
  816. end;
  817. 'C' :
  818. RCCompiler := More;
  819. 'd' :
  820. if UnsetBool(more, 0) then
  821. init_settings.disabledircache:=false
  822. else
  823. init_settings.disabledircache:=true;
  824. 'D' :
  825. utilsdirectory:=FixPath(More,true);
  826. 'e' :
  827. SetRedirectFile(More);
  828. 'E' :
  829. OutputExeDir:=FixPath(More,true);
  830. 'f' :
  831. if (target_info.system in systems_darwin) then
  832. if ispara then
  833. ParaFrameworkPath.AddPath(More,false)
  834. else
  835. frameworksearchpath.AddPath(More,true)
  836. else
  837. IllegalPara(opt);
  838. 'i' :
  839. begin
  840. if ispara then
  841. ParaIncludePath.AddPath(More,false)
  842. else
  843. includesearchpath.AddPath(More,true);
  844. end;
  845. 'm' :
  846. begin
  847. s:=ExtractFileDir(more);
  848. if TryStrToInt(ExtractFileName(more),j) then
  849. begin
  850. unicodemapping:=loadunicodemapping(More,More+'.txt',j);
  851. if assigned(unicodemapping) then
  852. registermapping(unicodemapping)
  853. else
  854. IllegalPara(opt);
  855. end
  856. else
  857. IllegalPara(opt);
  858. end;
  859. 'g' :
  860. Message2(option_obsolete_switch_use_new,'-Fg','-Fl');
  861. 'l' :
  862. begin
  863. if ispara then
  864. ParaLibraryPath.AddPath(sysrootpath,More,false)
  865. else
  866. LibrarySearchPath.AddPath(sysrootpath,More,true);
  867. end;
  868. 'L' :
  869. begin
  870. if More<>'' then
  871. ParaDynamicLinker:=More
  872. else
  873. IllegalPara(opt);
  874. end;
  875. 'o' :
  876. begin
  877. if ispara then
  878. ParaObjectPath.AddPath(More,false)
  879. else
  880. ObjectSearchPath.AddPath(More,true);
  881. end;
  882. 'r' :
  883. Msgfilename:=More;
  884. 'R' :
  885. ResCompiler := More;
  886. 'u' :
  887. begin
  888. if ispara then
  889. ParaUnitPath.AddPath(More,false)
  890. else
  891. unitsearchpath.AddPath(More,true);
  892. end;
  893. 'U' :
  894. OutputUnitDir:=FixPath(More,true);
  895. 'W',
  896. 'w':
  897. begin
  898. if More<>'' then
  899. begin
  900. DefaultReplacements(More);
  901. D:=ExtractFilePath(More);
  902. if (D<>'') then
  903. D:=FixPath(D,True);
  904. D:=D+ExtractFileName(More);
  905. if (c='W') then
  906. WpoFeedbackOutput:=D
  907. else
  908. WpoFeedbackInput:=D;
  909. end
  910. else
  911. IllegalPara(opt);
  912. end;
  913. else
  914. IllegalPara(opt);
  915. end;
  916. end;
  917. 'g' :
  918. begin
  919. if UnsetBool(More, 0) then
  920. begin
  921. exclude(init_settings.moduleswitches,cs_debuginfo);
  922. exclude(init_settings.globalswitches,cs_use_heaptrc);
  923. exclude(init_settings.globalswitches,cs_use_lineinfo);
  924. exclude(init_settings.localswitches,cs_checkpointer);
  925. localvartrashing := -1;
  926. end
  927. else
  928. begin
  929. include(init_settings.moduleswitches,cs_debuginfo);
  930. if paratargetdbg=dbg_none then
  931. paratargetdbg:=target_info.dbg;
  932. end;
  933. if not RelocSectionSetExplicitly then
  934. RelocSection:=false;
  935. j:=1;
  936. while j<=length(more) do
  937. begin
  938. case more[j] of
  939. 'c' :
  940. begin
  941. if UnsetBool(More, j) then
  942. exclude(init_settings.localswitches,cs_checkpointer)
  943. else if (target_info.system in supported_targets_gc) then
  944. include(init_settings.localswitches,cs_checkpointer)
  945. else
  946. UnsupportedPara('-gc');
  947. end;
  948. 'h' :
  949. begin
  950. if UnsetBool(More, j) then
  951. exclude(init_settings.globalswitches,cs_use_heaptrc)
  952. else
  953. include(init_settings.globalswitches,cs_use_heaptrc);
  954. end;
  955. 'l' :
  956. begin
  957. if UnsetBool(More, j) then
  958. exclude(init_settings.globalswitches,cs_use_lineinfo)
  959. else
  960. include(init_settings.globalswitches,cs_use_lineinfo);
  961. end;
  962. 'o' :
  963. begin
  964. if not UpdateDebugStr(copy(more,j+1,length(more)),init_settings.debugswitches) then
  965. IllegalPara(opt);
  966. break;
  967. end;
  968. 'p' :
  969. begin
  970. if UnsetBool(More, j) then
  971. exclude(init_settings.globalswitches,cs_stabs_preservecase)
  972. else
  973. include(init_settings.globalswitches,cs_stabs_preservecase);
  974. end;
  975. 's' :
  976. begin
  977. paratargetdbg:=dbg_stabs;
  978. end;
  979. 't' :
  980. begin
  981. if UnsetBool(More, j) then
  982. localvartrashing := -1
  983. else
  984. localvartrashing := (localvartrashing + 1) mod nroftrashvalues;
  985. end;
  986. 'v' :
  987. begin
  988. if UnsetBool(More, j) then
  989. exclude(init_settings.globalswitches,cs_gdb_valgrind)
  990. else
  991. include(init_settings.globalswitches,cs_gdb_valgrind);
  992. end;
  993. 'w' :
  994. begin
  995. if (j<length(more)) and (more[j+1] in ['2','3','4']) then
  996. begin
  997. case more[j+1] of
  998. '2': paratargetdbg:=dbg_dwarf2;
  999. '3': paratargetdbg:=dbg_dwarf3;
  1000. '4': paratargetdbg:=dbg_dwarf4;
  1001. end;
  1002. inc(j);
  1003. end
  1004. else
  1005. paratargetdbg:=dbg_dwarf2;
  1006. end;
  1007. else
  1008. IllegalPara(opt);
  1009. end;
  1010. inc(j);
  1011. end;
  1012. end;
  1013. 'h' :
  1014. begin
  1015. NoPressEnter:=true;
  1016. WriteHelpPages;
  1017. end;
  1018. 'i' :
  1019. begin
  1020. if More='' then
  1021. WriteInfo
  1022. else
  1023. QuickInfo:=QuickInfo+More;
  1024. end;
  1025. 'I' :
  1026. begin
  1027. if ispara then
  1028. ParaIncludePath.AddPath(More,false)
  1029. else
  1030. includesearchpath.AddPath(More,false);
  1031. end;
  1032. 'k' :
  1033. begin
  1034. if more<>'' then
  1035. ParaLinkOptions:=ParaLinkOptions+' '+More
  1036. else
  1037. IllegalPara(opt);
  1038. end;
  1039. 'l' :
  1040. ParaLogo:=not UnSetBool(more,0);
  1041. 'm' :
  1042. parapreprocess:=not UnSetBool(more,0);
  1043. 'M' :
  1044. begin
  1045. more:=Upper(more);
  1046. if not SetCompileMode(more, true) then
  1047. if not SetCompileModeSwitch(more, true) then
  1048. IllegalPara(opt);
  1049. end;
  1050. 'n' :
  1051. begin
  1052. if More='' then
  1053. disable_configfile:=true
  1054. else
  1055. IllegalPara(opt);
  1056. end;
  1057. 'o' :
  1058. begin
  1059. if More<>'' then
  1060. begin
  1061. DefaultReplacements(More);
  1062. D:=ExtractFilePath(More);
  1063. if (D<>'') then
  1064. OutputExeDir:=FixPath(D,True);
  1065. OutputFileName:=ExtractFileName(More);
  1066. end
  1067. else
  1068. IllegalPara(opt);
  1069. end;
  1070. 'O' :
  1071. begin
  1072. j:=1;
  1073. while j<=length(more) do
  1074. begin
  1075. case more[j] of
  1076. '1' :
  1077. init_settings.optimizerswitches:=init_settings.optimizerswitches+level1optimizerswitches;
  1078. '2' :
  1079. init_settings.optimizerswitches:=init_settings.optimizerswitches+level2optimizerswitches;
  1080. '3' :
  1081. init_settings.optimizerswitches:=init_settings.optimizerswitches+level3optimizerswitches;
  1082. 'a' :
  1083. begin
  1084. if not(UpdateAlignmentStr(Copy(Opt,j+3,255),ParaAlignment)) then
  1085. IllegalPara(opt);
  1086. break;
  1087. end;
  1088. 's' :
  1089. include(init_settings.optimizerswitches,cs_opt_size);
  1090. 'p' :
  1091. begin
  1092. if not Setcputype(copy(more,j+1,length(more)),init_settings.optimizecputype) then
  1093. begin
  1094. OptCPUSetExplicitly:=true;
  1095. { Give warning for old i386 switches }
  1096. if (Length(More)-j=1) and
  1097. (More[j+1]>='1') and (More[j+1]<='5')then
  1098. Message2(option_obsolete_switch_use_new,'-Op<nr>','-Op<name>')
  1099. else
  1100. IllegalPara(opt);
  1101. end;
  1102. break;
  1103. end;
  1104. 'o' :
  1105. begin
  1106. if not UpdateOptimizerStr(copy(more,j+1,length(more)),init_settings.optimizerswitches) then
  1107. IllegalPara(opt);
  1108. break;
  1109. end;
  1110. '-' :
  1111. begin
  1112. init_settings.optimizerswitches:=[];
  1113. FillChar(ParaAlignment,sizeof(ParaAlignment),0);
  1114. end;
  1115. { Obsolete switches }
  1116. 'g' :
  1117. Message2(option_obsolete_switch_use_new,'-Og','-Os');
  1118. 'G' :
  1119. Message1(option_obsolete_switch,'-OG');
  1120. 'r' :
  1121. Message2(option_obsolete_switch_use_new,'-Or','-O2 or -Ooregvar');
  1122. 'u' :
  1123. Message2(option_obsolete_switch_use_new,'-Ou','-Oouncertain');
  1124. 'w' :
  1125. begin
  1126. if not UpdateWpoStr(copy(more,j+1,length(more)),init_settings.dowpoptimizerswitches) then
  1127. IllegalPara(opt);
  1128. break;
  1129. end;
  1130. 'W' :
  1131. begin
  1132. if not UpdateWpoStr(copy(more,j+1,length(more)),init_settings.genwpoptimizerswitches) then
  1133. IllegalPara(opt);
  1134. break;
  1135. end;
  1136. else
  1137. IllegalPara(opt);
  1138. end;
  1139. inc(j);
  1140. end;
  1141. end;
  1142. 'p' :
  1143. begin
  1144. if UnsetBool(More, 0) then
  1145. begin
  1146. init_settings.moduleswitches:=init_settings.moduleswitches-[cs_profile];
  1147. undef_system_macro('FPC_PROFILE');
  1148. end
  1149. else
  1150. if Length(More)=0 then
  1151. IllegalPara(opt)
  1152. else
  1153. case more[1] of
  1154. 'g' : if UnsetBool(more, 1) then
  1155. begin
  1156. exclude(init_settings.moduleswitches,cs_profile);
  1157. undef_system_macro('FPC_PROFILE');
  1158. end
  1159. else if (target_info.system in supported_targets_pg) then
  1160. begin
  1161. include(init_settings.moduleswitches,cs_profile);
  1162. def_system_macro('FPC_PROFILE');
  1163. end
  1164. else
  1165. UnsupportedPara('-pg');
  1166. else
  1167. IllegalPara(opt);
  1168. end;
  1169. end;
  1170. 'P' : ; { Ignore used by fpc.pp }
  1171. 'R' :
  1172. begin
  1173. if not SetAsmReadMode(More,init_settings.asmmode) then
  1174. IllegalPara(opt);
  1175. end;
  1176. 's' :
  1177. begin
  1178. if UnsetBool(More, 0) then
  1179. begin
  1180. init_settings.globalswitches:=init_settings.globalswitches-[cs_asm_extern,cs_link_extern,cs_link_nolink];
  1181. if more<>'' then
  1182. IllegalPara(opt);
  1183. end
  1184. else
  1185. begin
  1186. init_settings.globalswitches:=init_settings.globalswitches+[cs_asm_extern,cs_link_extern,cs_link_nolink];
  1187. if more='h' then
  1188. init_settings.globalswitches:=init_settings.globalswitches-[cs_link_on_target]
  1189. else if more='t' then
  1190. init_settings.globalswitches:=init_settings.globalswitches+[cs_link_on_target]
  1191. else if more='r' then
  1192. init_settings.globalswitches:=init_settings.globalswitches+[cs_asm_leave,cs_no_regalloc]
  1193. else if more<>'' then
  1194. IllegalPara(opt);
  1195. end;
  1196. end;
  1197. 'S' :
  1198. begin
  1199. if more='' then
  1200. IllegalPara(opt);
  1201. if more[1]='I' then
  1202. begin
  1203. if upper(more)='ICOM' then
  1204. init_settings.interfacetype:=it_interfacecom
  1205. else if upper(more)='ICORBA' then
  1206. init_settings.interfacetype:=it_interfacecorba
  1207. else
  1208. IllegalPara(opt);
  1209. end
  1210. else
  1211. begin
  1212. j:=1;
  1213. while j<=length(more) do
  1214. begin
  1215. case more[j] of
  1216. '2' : //an alternative to -Mobjfpc
  1217. SetCompileMode('OBJFPC',true);
  1218. 'a' :
  1219. If UnsetBool(More, j) then
  1220. exclude(init_settings.localswitches,cs_do_assertion)
  1221. else
  1222. include(init_settings.localswitches,cs_do_assertion);
  1223. 'c' :
  1224. If UnsetBool(More, j) then
  1225. include(init_settings.moduleswitches,cs_support_c_operators)
  1226. else
  1227. include(init_settings.moduleswitches,cs_support_c_operators);
  1228. 'd' : //an alternative to -Mdelphi
  1229. SetCompileMode('DELPHI',true);
  1230. 'e' :
  1231. begin
  1232. SetErrorFlags(copy(more,j+1,length(more)));
  1233. break;
  1234. end;
  1235. 'f' :
  1236. begin
  1237. inc(j);
  1238. if more[j]='-' then
  1239. begin
  1240. features:=[];
  1241. if length(more)>j then
  1242. IllegalPara(opt);
  1243. end
  1244. else
  1245. begin
  1246. if (IncludeFeature(upper(copy(more,j,length(more)-j+1)))) then
  1247. j:=length(more)
  1248. else
  1249. IllegalPara(opt);
  1250. end;
  1251. end;
  1252. 'g' :
  1253. If UnsetBool(More, j) then
  1254. exclude(init_settings.moduleswitches,cs_support_goto)
  1255. else
  1256. include(init_settings.moduleswitches,cs_support_goto);
  1257. 'h' :
  1258. If UnsetBool(More, j) then
  1259. exclude(init_settings.localswitches,cs_ansistrings)
  1260. else
  1261. include(init_settings.localswitches,cs_ansistrings);
  1262. 'i' :
  1263. If UnsetBool(More, j) then
  1264. exclude(init_settings.localswitches,cs_do_inline)
  1265. else
  1266. include(init_settings.localswitches,cs_do_inline);
  1267. 'k' :
  1268. If UnsetBool(More, j) then
  1269. exclude(init_settings.globalswitches,cs_load_fpcylix_unit)
  1270. else
  1271. include(init_settings.globalswitches,cs_load_fpcylix_unit);
  1272. 'm' :
  1273. If UnsetBool(More, j) then
  1274. exclude(init_settings.moduleswitches,cs_support_macro)
  1275. else
  1276. include(init_settings.moduleswitches,cs_support_macro);
  1277. 'o' : //an alternative to -Mtp
  1278. SetCompileMode('TP',true);
  1279. {$ifdef gpc_mode}
  1280. 'p' : //an alternative to -Mgpc
  1281. SetCompileMode('GPC',true);
  1282. {$endif}
  1283. 's' :
  1284. If UnsetBool(More, j) then
  1285. exclude(init_settings.globalswitches,cs_constructor_name)
  1286. else
  1287. include(init_settings.globalswitches,cs_constructor_name);
  1288. 't' :
  1289. Message1(option_obsolete_switch,'-St');
  1290. 'v' :
  1291. If UnsetBool(More, j) then
  1292. exclude(init_settings.globalswitches,cs_support_vectors)
  1293. else
  1294. include(init_settings.globalswitches,cs_support_vectors);
  1295. 'x' :
  1296. If UnsetBool(More, j) then
  1297. exclude(init_settings.globalswitches,cs_support_exceptions)
  1298. else
  1299. include(init_settings.globalswitches,cs_support_exceptions);
  1300. 'y' :
  1301. If UnsetBool(More, j) then
  1302. exclude(init_settings.localswitches,cs_typed_addresses)
  1303. else
  1304. include(init_settings.localswitches,cs_typed_addresses);
  1305. '-' :
  1306. begin
  1307. init_settings.globalswitches:=init_settings.globalswitches - [cs_constructor_name,cs_support_exceptions,
  1308. cs_support_vectors,cs_load_fpcylix_unit];
  1309. init_settings.localswitches:=init_settings.localswitches - [cs_do_assertion,cs_do_inline, cs_ansistrings,
  1310. cs_typed_addresses];
  1311. init_settings.moduleswitches:=init_settings.moduleswitches - [cs_support_c_operators, cs_support_goto,
  1312. cs_support_macro];
  1313. end;
  1314. else
  1315. IllegalPara(opt);
  1316. end;
  1317. inc(j);
  1318. end;
  1319. end;
  1320. end;
  1321. 'T' :
  1322. begin
  1323. more:=Upper(More);
  1324. if paratarget=system_none then
  1325. begin
  1326. { remove old target define }
  1327. TargetOptions(false);
  1328. { load new target }
  1329. paratarget:=find_system_by_string(More);
  1330. if paratarget<>system_none then
  1331. set_target(paratarget)
  1332. else
  1333. IllegalPara(opt);
  1334. { set new define }
  1335. TargetOptions(true);
  1336. end
  1337. else
  1338. if More<>upper(target_info.shortname) then
  1339. Message1(option_target_is_already_set,target_info.shortname);
  1340. end;
  1341. 'u' :
  1342. if more <> '' then
  1343. undef_system_macro(more);
  1344. 'U' :
  1345. begin
  1346. j:=1;
  1347. while j<=length(more) do
  1348. begin
  1349. case more[j] of
  1350. {$ifdef UNITALIASES}
  1351. 'a' :
  1352. begin
  1353. AddUnitAlias(Copy(More,j+1,255));
  1354. break;
  1355. end;
  1356. {$endif UNITALIASES}
  1357. 'n' :
  1358. exclude(init_settings.globalswitches,cs_check_unit_name);
  1359. 'p' :
  1360. begin
  1361. Message2(option_obsolete_switch_use_new,'-Up','-Fu');
  1362. break;
  1363. end;
  1364. 'r' :
  1365. do_release:=true;
  1366. 's' :
  1367. include(init_settings.moduleswitches,cs_compilesystem);
  1368. '-' :
  1369. begin
  1370. exclude(init_settings.moduleswitches,cs_compilesystem);
  1371. exclude(init_settings.globalswitches,cs_check_unit_name);
  1372. end;
  1373. else
  1374. IllegalPara(opt);
  1375. end;
  1376. inc(j);
  1377. end;
  1378. end;
  1379. 'v' :
  1380. begin
  1381. if not setverbosity(More) then
  1382. IllegalPara(opt);
  1383. end;
  1384. 'V' : ; { Ignore used by fpc }
  1385. 'W' :
  1386. begin
  1387. j:=1;
  1388. while j<=length(More) do
  1389. begin
  1390. case More[j] of
  1391. 'A':
  1392. begin
  1393. if target_info.system in systems_all_windows then
  1394. begin
  1395. if UnsetBool(More, j) then
  1396. apptype:=app_cui
  1397. else
  1398. apptype:=app_native;
  1399. end
  1400. else
  1401. IllegalPara(opt);
  1402. end;
  1403. 'b':
  1404. begin
  1405. if target_info.system in systems_darwin then
  1406. begin
  1407. if UnsetBool(More, j) then
  1408. apptype:=app_cui
  1409. else
  1410. apptype:=app_bundle
  1411. end
  1412. else
  1413. IllegalPara(opt);
  1414. end;
  1415. 'B':
  1416. begin
  1417. if target_info.system in systems_all_windows+systems_symbian then
  1418. begin
  1419. { -WB200000 means set trefered base address
  1420. to $200000, but does not change relocsection boolean
  1421. this way we can create both relocatble and
  1422. non relocatable DLL at a specific base address PM }
  1423. if (length(More)>j) then
  1424. begin
  1425. val('$'+Copy(More,j+1,255),imagebase,code);
  1426. if code<>0 then
  1427. IllegalPara(opt);
  1428. ImageBaseSetExplicity:=true;
  1429. end
  1430. else
  1431. begin
  1432. RelocSection:=true;
  1433. RelocSectionSetExplicitly:=true;
  1434. end;
  1435. break;
  1436. end
  1437. else
  1438. IllegalPara(opt);
  1439. end;
  1440. 'C':
  1441. begin
  1442. if target_info.system in systems_all_windows+systems_os2+systems_macos then
  1443. begin
  1444. if UnsetBool(More, j) then
  1445. apptype:=app_gui
  1446. else
  1447. apptype:=app_cui;
  1448. end
  1449. else
  1450. IllegalPara(opt);
  1451. end;
  1452. 'D':
  1453. begin
  1454. if target_info.system in systems_all_windows then
  1455. begin
  1456. UseDeffileForExports:=not UnsetBool(More, j);
  1457. UseDeffileForExportsSetExplicitly:=true;
  1458. end
  1459. else
  1460. IllegalPara(opt);
  1461. end;
  1462. 'e':
  1463. begin
  1464. if (target_info.system in systems_darwin) then
  1465. begin
  1466. RegisterRes(res_macosx_ext_info,TWinLikeResourceFile);
  1467. set_target_res(res_ext);
  1468. target_info.resobjext:='.fpcres';
  1469. end
  1470. else
  1471. IllegalPara(opt);
  1472. end;
  1473. 'F':
  1474. begin
  1475. if target_info.system in systems_os2 then
  1476. begin
  1477. if UnsetBool(More, j) then
  1478. apptype:=app_cui
  1479. else
  1480. apptype:=app_fs;
  1481. end
  1482. else
  1483. IllegalPara(opt);
  1484. end;
  1485. 'G':
  1486. begin
  1487. if target_info.system in systems_all_windows+systems_os2+systems_macos then
  1488. begin
  1489. if UnsetBool(More, j) then
  1490. apptype:=app_cui
  1491. else
  1492. apptype:=app_gui;
  1493. end
  1494. else
  1495. IllegalPara(opt);
  1496. end;
  1497. 'I':
  1498. begin
  1499. if target_info.system in systems_all_windows then
  1500. begin
  1501. GenerateImportSection:=not UnsetBool(More,j);
  1502. GenerateImportSectionSetExplicitly:=true;
  1503. end
  1504. else
  1505. IllegalPara(opt);
  1506. end;
  1507. 'i':
  1508. begin
  1509. if (target_info.system in systems_darwin) then
  1510. begin
  1511. set_target_res(res_macho);
  1512. target_info.resobjext:=
  1513. targetinfos[target_info.system]^.resobjext;
  1514. end
  1515. else
  1516. IllegalPara(opt);
  1517. end;
  1518. 'N':
  1519. begin
  1520. if target_info.system in systems_all_windows then
  1521. begin
  1522. RelocSection:=UnsetBool(More,j);
  1523. RelocSectionSetExplicitly:=true;
  1524. end
  1525. else
  1526. IllegalPara(opt);
  1527. end;
  1528. 'p':
  1529. begin
  1530. {$if defined(arm) or defined(avr)}
  1531. if (target_info.system in systems_embedded) then
  1532. begin
  1533. s:=upper(copy(more,j+1,length(more)-j));
  1534. if not(SetControllerType(s,init_settings.controllertype)) then
  1535. IllegalPara(opt);
  1536. break;
  1537. end
  1538. else
  1539. {$endif defined(arm) or defined(avr)}
  1540. IllegalPara(opt);
  1541. end;
  1542. 'R':
  1543. begin
  1544. if target_info.system in systems_all_windows then
  1545. begin
  1546. { support -WR+ / -WR- as synonyms to -WR / -WN }
  1547. RelocSection:=not UnsetBool(More,j);
  1548. RelocSectionSetExplicitly:=true;
  1549. end
  1550. else
  1551. IllegalPara(opt);
  1552. end;
  1553. 'T':
  1554. begin
  1555. if target_info.system in systems_macos then
  1556. begin
  1557. if UnsetBool(More, j) then
  1558. apptype:=app_cui
  1559. else
  1560. apptype:=app_tool;
  1561. end
  1562. else
  1563. IllegalPara(opt);
  1564. end;
  1565. 'X':
  1566. begin
  1567. if (target_info.system in systems_linux) then
  1568. begin
  1569. if UnsetBool(More, j) then
  1570. exclude(init_settings.moduleswitches,cs_executable_stack)
  1571. else
  1572. include(init_settings.moduleswitches,cs_executable_stack)
  1573. end
  1574. else
  1575. IllegalPara(opt);
  1576. end
  1577. else
  1578. IllegalPara(opt);
  1579. end;
  1580. inc(j);
  1581. end;
  1582. end;
  1583. 'X' :
  1584. begin
  1585. j:=1;
  1586. while j<=length(more) do
  1587. begin
  1588. case More[j] of
  1589. 'c' : Cshared:=TRUE;
  1590. 'd' : Dontlinkstdlibpath:=TRUE;
  1591. 'e' :
  1592. begin
  1593. If UnsetBool(More, j) then
  1594. exclude(init_settings.globalswitches,cs_link_extern)
  1595. else
  1596. include(init_settings.globalswitches,cs_link_extern);
  1597. end;
  1598. 'f' :
  1599. include(init_settings.globalswitches,cs_link_pthread);
  1600. 'g' :
  1601. begin
  1602. If UnsetBool(More, j) then
  1603. exclude(init_settings.globalswitches,cs_link_separate_dbg_file)
  1604. else
  1605. include(init_settings.globalswitches,cs_link_separate_dbg_file);
  1606. end;
  1607. 'i' :
  1608. begin
  1609. If UnsetBool(More, j) then
  1610. include(init_settings.globalswitches,cs_link_extern)
  1611. else
  1612. exclude(init_settings.globalswitches,cs_link_extern);
  1613. end;
  1614. 'n' :
  1615. begin
  1616. If UnsetBool(More, j) then
  1617. exclude(init_settings.globalswitches,cs_link_native)
  1618. else
  1619. include(init_settings.globalswitches,cs_link_native);
  1620. end;
  1621. 'm' :
  1622. begin
  1623. If UnsetBool(More, j) then
  1624. exclude(init_settings.globalswitches,cs_link_map)
  1625. else
  1626. include(init_settings.globalswitches,cs_link_map);
  1627. end;
  1628. 'p' : ; { Ignore used by fpc.pp }
  1629. 'r' :
  1630. begin
  1631. if (target_info.system in suppported_targets_x_smallr) then
  1632. begin
  1633. rlinkpath:=Copy(more,2,length(More)-1);
  1634. DefaultReplacements(rlinkpath);
  1635. end
  1636. else
  1637. IgnoredPara('-Xr');
  1638. more:='';
  1639. end;
  1640. 'R' :
  1641. begin
  1642. sysrootpath:=copy(more,2,length(more)-1);
  1643. defaultreplacements(sysrootpath);
  1644. more:='';
  1645. end;
  1646. 's' :
  1647. begin
  1648. If UnsetBool(More, j) then
  1649. exclude(init_settings.globalswitches,cs_link_strip)
  1650. else
  1651. include(init_settings.globalswitches,cs_link_strip);
  1652. end;
  1653. 't' :
  1654. include(init_settings.globalswitches,cs_link_staticflag);
  1655. 'v' :
  1656. begin
  1657. If UnsetBool(More, j) then
  1658. exclude(init_settings.globalswitches,cs_link_opt_vtable)
  1659. else
  1660. include(init_settings.globalswitches,cs_link_opt_vtable);
  1661. end;
  1662. 'D' :
  1663. begin
  1664. def_system_macro('FPC_LINK_DYNAMIC');
  1665. undef_system_macro('FPC_LINK_SMART');
  1666. undef_system_macro('FPC_LINK_STATIC');
  1667. exclude(init_settings.globalswitches,cs_link_static);
  1668. exclude(init_settings.globalswitches,cs_link_smart);
  1669. include(init_settings.globalswitches,cs_link_shared);
  1670. LinkTypeSetExplicitly:=true;
  1671. end;
  1672. 'M' :
  1673. begin
  1674. mainaliasname:=Copy(more,2,length(More)-1);
  1675. More:='';
  1676. end;
  1677. 'P' :
  1678. begin
  1679. utilsprefix:=Copy(more,2,length(More)-1);
  1680. DefaultReplacements(utilsprefix);
  1681. More:='';
  1682. end;
  1683. 'L' : begin // -XLO is link order -XLA is link alias. -XLD avoids load defaults.
  1684. // these are not aggregable.
  1685. if (j=length(more)) or not (more[j+1] in ['O','A','D']) then
  1686. IllegalPara(opt)
  1687. else
  1688. begin
  1689. case more[j+1] of
  1690. 'A' : begin
  1691. s:=Copy(more,3,length(More)-2);
  1692. if not LinkLibraryAliases.AddDep(s) Then
  1693. IllegalPara(opt);
  1694. end;
  1695. 'O' : begin
  1696. s:=Copy(more,3,length(More)-2);
  1697. if not LinkLibraryOrder.AddWeight(s) Then
  1698. IllegalPara(opt);
  1699. end;
  1700. 'D' : include(init_settings.globalswitches,cs_link_no_default_lib_order)
  1701. else
  1702. IllegalPara(opt);
  1703. end; {case}
  1704. j:=length(more);
  1705. end; {else begin}
  1706. end;
  1707. 'S' :
  1708. begin
  1709. ForceStaticLinking;
  1710. end;
  1711. 'X' :
  1712. begin
  1713. def_system_macro('FPC_LINK_SMART');
  1714. undef_system_macro('FPC_LINK_STATIC');
  1715. undef_system_macro('FPC_LINK_DYNAMIC');
  1716. exclude(init_settings.globalswitches,cs_link_static);
  1717. include(init_settings.globalswitches,cs_link_smart);
  1718. exclude(init_settings.globalswitches,cs_link_shared);
  1719. LinkTypeSetExplicitly:=true;
  1720. end;
  1721. '-' :
  1722. begin
  1723. exclude(init_settings.globalswitches,cs_link_staticflag);
  1724. exclude(init_settings.globalswitches,cs_link_strip);
  1725. exclude(init_settings.globalswitches,cs_link_map);
  1726. set_default_link_type;
  1727. end;
  1728. else
  1729. IllegalPara(opt);
  1730. end;
  1731. inc(j);
  1732. end;
  1733. end;
  1734. else
  1735. IllegalPara(opt);
  1736. end;
  1737. end;
  1738. '@' :
  1739. begin
  1740. Message(option_no_nested_response_file);
  1741. StopOptions(1);
  1742. end;
  1743. else
  1744. begin
  1745. if (length(param_file)<>0) then
  1746. Message2(option_only_one_source_support,param_file,opt);
  1747. param_file:=opt;
  1748. Message1(option_found_file,opt);
  1749. end;
  1750. end;
  1751. end;
  1752. procedure Toption.Interpret_file(const filename : TPathStr);
  1753. procedure RemoveSep(var fn:TPathStr);
  1754. var
  1755. i : longint;
  1756. begin
  1757. i:=0;
  1758. while (i<length(fn)) and (fn[i+1] in [',',' ',#9]) do
  1759. inc(i);
  1760. Delete(fn,1,i);
  1761. i:=length(fn);
  1762. while (i>0) and (fn[i] in [',',' ',#9]) do
  1763. dec(i);
  1764. fn:=copy(fn,1,i);
  1765. end;
  1766. function GetName(var fn:TPathStr):TPathStr;
  1767. var
  1768. i : longint;
  1769. begin
  1770. i:=0;
  1771. while (i<length(fn)) and (fn[i+1] in ['a'..'z','A'..'Z','0'..'9','_','-']) do
  1772. inc(i);
  1773. GetName:=Copy(fn,1,i);
  1774. Delete(fn,1,i);
  1775. end;
  1776. const
  1777. maxlevel = 15;
  1778. var
  1779. f : text;
  1780. s, tmp,
  1781. opts : TCmdStr;
  1782. skip : array[0..maxlevel] of boolean;
  1783. line,
  1784. level : longint;
  1785. option_read : boolean;
  1786. begin
  1787. { avoid infinite loop }
  1788. Inc(FileLevel);
  1789. Option_read:=false;
  1790. If FileLevel>MaxLevel then
  1791. Message(option_too_many_cfg_files);
  1792. { Maybe It's Directory ?} //Jaro Change:
  1793. if PathExists(filename,false) then
  1794. begin
  1795. Message1(option_config_is_dir,filename);
  1796. exit;
  1797. end;
  1798. { open file }
  1799. Message1(option_using_file,filename);
  1800. assign(f,ExpandFileName(filename));
  1801. {$push}{$I-}
  1802. reset(f);
  1803. {$pop}
  1804. if ioresult<>0 then
  1805. begin
  1806. Message1(option_unable_open_file,filename);
  1807. exit;
  1808. end;
  1809. Message1(option_start_reading_configfile,filename);
  1810. fillchar(skip,sizeof(skip),0);
  1811. level:=0;
  1812. line:=0;
  1813. while not eof(f) do
  1814. begin
  1815. readln(f,opts);
  1816. inc(line);
  1817. RemoveSep(opts);
  1818. if (opts<>'') and (opts[1]<>';') then
  1819. begin
  1820. if opts[1]='#' then
  1821. begin
  1822. Message1(option_interpreting_file_option,opts);
  1823. Delete(opts,1,1);
  1824. s:=upper(GetName(opts));
  1825. if (s='SECTION') then
  1826. begin
  1827. RemoveSep(opts);
  1828. s:=upper(GetName(opts));
  1829. if level=0 then
  1830. skip[level]:=not defined_macro(s) or (s='COMMON');
  1831. end
  1832. else
  1833. if (s='IFDEF') then
  1834. begin
  1835. RemoveSep(opts);
  1836. if Level>=maxlevel then
  1837. begin
  1838. Message2(option_too_many_ifdef,filename,tostr(line));
  1839. stopOptions(1);
  1840. end;
  1841. inc(Level);
  1842. skip[level]:=(skip[level-1] or not defined_macro(upper(GetName(opts))));
  1843. end
  1844. else
  1845. if (s='IFNDEF') then
  1846. begin
  1847. RemoveSep(opts);
  1848. if Level>=maxlevel then
  1849. begin
  1850. Message2(option_too_many_ifdef,filename,tostr(line));
  1851. stopOptions(1);
  1852. end;
  1853. inc(Level);
  1854. skip[level]:=(skip[level-1] or defined_macro(upper(GetName(opts))));
  1855. end
  1856. else
  1857. if (s='ELSE') then
  1858. begin
  1859. if Level=0 then
  1860. begin
  1861. Message2(option_else_without_if,filename,tostr(line));
  1862. stopOptions(1);
  1863. end
  1864. else
  1865. skip[level]:=skip[level-1] or (not skip[level])
  1866. end
  1867. else
  1868. if (s='ENDIF') then
  1869. begin
  1870. skip[level]:=false;
  1871. if Level=0 then
  1872. begin
  1873. Message2(option_too_many_endif,filename,tostr(line));
  1874. stopOptions(1);
  1875. end;
  1876. dec(level);
  1877. end
  1878. else
  1879. if (not skip[level]) then
  1880. begin
  1881. if (s='DEFINE') then
  1882. begin
  1883. RemoveSep(opts);
  1884. tmp:= GetName(opts);
  1885. if tmp <> '' then
  1886. def_system_macro(tmp);
  1887. end
  1888. else
  1889. if (s='UNDEF') then
  1890. begin
  1891. RemoveSep(opts);
  1892. tmp:= GetName(opts);
  1893. if tmp <> '' then
  1894. undef_system_macro(tmp);
  1895. end
  1896. else
  1897. if (s='WRITE') then
  1898. begin
  1899. Delete(opts,1,1);
  1900. WriteLn(opts);
  1901. end
  1902. else
  1903. if (s='INCLUDE') then
  1904. begin
  1905. Delete(opts,1,1);
  1906. Interpret_file(opts);
  1907. end;
  1908. end;
  1909. end
  1910. else
  1911. begin
  1912. if (opts[1]='-') or (opts[1]='@') then
  1913. begin
  1914. if (not skip[level]) then
  1915. interpret_option(opts,false);
  1916. Option_read:=true;
  1917. end
  1918. else
  1919. Message1(option_illegal_para,opts);
  1920. end;
  1921. end;
  1922. end;
  1923. if Level>0 then
  1924. Message(option_too_less_endif);
  1925. if Not Option_read then
  1926. Message1(option_no_option_found,filename)
  1927. else
  1928. Message1(option_end_reading_configfile,filename);
  1929. Close(f);
  1930. Dec(FileLevel);
  1931. end;
  1932. procedure Toption.Interpret_envvar(const envname : TCmdStr);
  1933. var
  1934. argstart,
  1935. env,
  1936. pc : pchar;
  1937. arglen : longint;
  1938. quote : set of char;
  1939. hs : TCmdStr;
  1940. begin
  1941. Message1(option_using_env,envname);
  1942. env:=GetEnvPChar(envname);
  1943. pc:=env;
  1944. if assigned(pc) then
  1945. begin
  1946. repeat
  1947. { skip leading spaces }
  1948. while pc^ in [' ',#9,#13] do
  1949. inc(pc);
  1950. case pc^ of
  1951. #0 :
  1952. break;
  1953. '"' :
  1954. begin
  1955. quote:=['"'];
  1956. inc(pc);
  1957. end;
  1958. '''' :
  1959. begin
  1960. quote:=[''''];
  1961. inc(pc);
  1962. end;
  1963. else
  1964. quote:=[' ',#9,#13];
  1965. end;
  1966. { scan until the end of the argument }
  1967. argstart:=pc;
  1968. while (pc^<>#0) and not(pc^ in quote) do
  1969. inc(pc);
  1970. { create argument }
  1971. arglen:=pc-argstart;
  1972. { TODO: FIXME: silent truncation of environment parameters }
  1973. if (arglen > 255) then
  1974. arglen := 255;
  1975. setlength(hs,arglen);
  1976. move(argstart^,hs[1],arglen);
  1977. interpret_option(hs,true);
  1978. { skip quote }
  1979. if pc^ in quote then
  1980. inc(pc);
  1981. until false;
  1982. end
  1983. else
  1984. Message1(option_no_option_found,'(env) '+envname);
  1985. FreeEnvPChar(env);
  1986. end;
  1987. procedure toption.read_parameters;
  1988. var
  1989. opts : TCmdStr;
  1990. paramindex : longint;
  1991. begin
  1992. paramindex:=0;
  1993. while paramindex<paramcount do
  1994. begin
  1995. inc(paramindex);
  1996. opts:=objpas.paramstr(paramindex);
  1997. if length(opts)>0 then
  1998. case opts[1] of
  1999. '@' :
  2000. if not firstpass then
  2001. begin
  2002. Delete(opts,1,1);
  2003. Message1(option_reading_further_from,opts);
  2004. interpret_file(opts);
  2005. end;
  2006. '!' :
  2007. if not firstpass then
  2008. begin
  2009. Delete(opts,1,1);
  2010. Message1(option_reading_further_from,'(env) '+opts);
  2011. interpret_envvar(opts);
  2012. end;
  2013. else
  2014. interpret_option(opts,true);
  2015. end;
  2016. end;
  2017. end;
  2018. procedure toption.parsecmd(cmd:TCmdStr);
  2019. var
  2020. i,ps : longint;
  2021. opts : TCmdStr;
  2022. begin
  2023. while (cmd<>'') do
  2024. begin
  2025. while cmd[1]=' ' do
  2026. delete(cmd,1,1);
  2027. i:=pos(' ',cmd);
  2028. if i=0 then
  2029. i:=2147483647;
  2030. opts:=Copy(cmd,1,i-1);
  2031. Delete(cmd,1,i);
  2032. case opts[1] of
  2033. '@' :
  2034. if not firstpass then
  2035. begin
  2036. Delete(opts,1,1);
  2037. Message1(option_reading_further_from,opts);
  2038. interpret_file(opts);
  2039. end;
  2040. '!' :
  2041. if not firstpass then
  2042. begin
  2043. Delete(opts,1,1);
  2044. Message1(option_reading_further_from,'(env) '+opts);
  2045. interpret_envvar(opts);
  2046. end;
  2047. '"' :
  2048. begin
  2049. Delete(opts,1,1);
  2050. ps:=pos('"',cmd);
  2051. if (i<>256) and (ps>0) then
  2052. begin
  2053. opts:=opts + ' '+ copy(cmd,1,ps-1);
  2054. cmd:=copy(cmd,ps+1,255);
  2055. end;
  2056. interpret_option(opts,true);
  2057. end;
  2058. else
  2059. interpret_option(opts,true);
  2060. end;
  2061. end;
  2062. end;
  2063. procedure toption.writequickinfo;
  2064. var
  2065. s : string;
  2066. i : longint;
  2067. procedure addinfo(const hs:string);
  2068. begin
  2069. if s<>'' then
  2070. s:=s+' '+hs
  2071. else
  2072. s:=hs;
  2073. end;
  2074. begin
  2075. s:='';
  2076. i:=0;
  2077. while (i<length(quickinfo)) do
  2078. begin
  2079. inc(i);
  2080. case quickinfo[i] of
  2081. 'S' :
  2082. begin
  2083. inc(i);
  2084. case quickinfo[i] of
  2085. 'O' :
  2086. addinfo(lower(source_info.shortname));
  2087. 'P' :
  2088. addinfo(source_cpu_string);
  2089. else
  2090. IllegalPara('-i'+QuickInfo);
  2091. end;
  2092. end;
  2093. 'T' :
  2094. begin
  2095. inc(i);
  2096. case quickinfo[i] of
  2097. 'O' :
  2098. addinfo(lower(target_info.shortname));
  2099. 'P' :
  2100. AddInfo(target_cpu_string);
  2101. else
  2102. IllegalPara('-i'+QuickInfo);
  2103. end;
  2104. end;
  2105. 'V' :
  2106. AddInfo(version_string);
  2107. 'W' :
  2108. AddInfo(full_version_string);
  2109. 'D' :
  2110. AddInfo(date_string);
  2111. '_' :
  2112. ;
  2113. else
  2114. IllegalPara('-i'+QuickInfo);
  2115. end;
  2116. end;
  2117. if s<>'' then
  2118. begin
  2119. writeln(s);
  2120. stopoptions(0);
  2121. end;
  2122. end;
  2123. procedure TOption.TargetOptions(def:boolean);
  2124. var
  2125. s : string;
  2126. i : integer;
  2127. target_unsup_features : tfeatures;
  2128. begin
  2129. if def then
  2130. def_system_macro(target_info.shortname)
  2131. else
  2132. undef_system_macro(target_info.shortname);
  2133. s:=target_info.extradefines;
  2134. while (s<>'') do
  2135. begin
  2136. i:=pos(';',s);
  2137. if i=0 then
  2138. i:=length(s)+1;
  2139. if def then
  2140. def_system_macro(Copy(s,1,i-1))
  2141. else
  2142. undef_system_macro(Copy(s,1,i-1));
  2143. delete(s,1,i);
  2144. end;
  2145. if (tf_winlikewidestring in target_info.flags) then
  2146. if def then
  2147. def_system_macro('FPC_WINLIKEWIDESTRING')
  2148. else
  2149. undef_system_macro('FPC_WINLIKEWIDESTRING');
  2150. if (tf_requires_proper_alignment in target_info.flags) then
  2151. if def then
  2152. def_system_macro('FPC_REQUIRES_PROPER_ALIGNMENT')
  2153. else
  2154. undef_system_macro('FPC_REQUIRES_PROPER_ALIGNMENT');
  2155. if source_info.system<>target_info.system then
  2156. if def then
  2157. def_system_macro('FPC_CROSSCOMPILING')
  2158. else
  2159. undef_system_macro('FPC_CROSSCOMPILING');
  2160. if source_info.cpu<>target_info.cpu then
  2161. if def then
  2162. def_system_macro('FPC_CPUCROSSCOMPILING')
  2163. else
  2164. def_system_macro('FPC_CPUCROSSCOMPILING');
  2165. if (tf_no_generic_stackcheck in target_info.flags) then
  2166. if def then
  2167. def_system_macro('FPC_NO_GENERIC_STACK_CHECK')
  2168. else
  2169. undef_system_macro('FPC_NO_GENERIC_STACK_CHECK');
  2170. { Code generation flags }
  2171. if def and
  2172. (tf_pic_default in target_info.flags) then
  2173. include(init_settings.moduleswitches,cs_create_pic)
  2174. else
  2175. exclude(init_settings.moduleswitches,cs_create_pic);
  2176. { Resources support }
  2177. if (tf_has_winlike_resources in target_info.flags) then
  2178. if def then
  2179. def_system_macro('FPC_HAS_WINLIKERESOURCES')
  2180. else
  2181. undef_system_macro('FPC_HAS_WINLIKERESOURCES');
  2182. { Features }
  2183. case target_info.system of
  2184. system_arm_gba:
  2185. target_unsup_features:=[f_threading,f_commandargs,f_fileio,f_textio,f_consoleio,f_dynlibs];
  2186. system_arm_nds:
  2187. target_unsup_features:=[f_threading,f_commandargs,f_fileio,f_textio,f_consoleio,f_dynlibs];
  2188. system_i386_nativent:
  2189. // until these features are implemented, they are disabled in the compiler
  2190. target_unsup_features:=[f_stackcheck];
  2191. else
  2192. target_unsup_features:=[];
  2193. end;
  2194. if def then
  2195. features:=features-target_unsup_features
  2196. else
  2197. features:=features+target_unsup_features;
  2198. end;
  2199. procedure TOption.checkoptionscompatibility;
  2200. begin
  2201. if (paratargetdbg in [dbg_dwarf2,dbg_dwarf3]) and
  2202. not(target_info.system in systems_darwin) then
  2203. begin
  2204. { smartlink creation does not yet work with DWARF
  2205. debug info on most targets, but it works in internal assembler }
  2206. if (cs_create_smart in init_settings.moduleswitches) and
  2207. not (af_outputbinary in target_asm.flags) then
  2208. begin
  2209. Message(option_dwarf_smartlink_creation);
  2210. exclude(init_settings.moduleswitches,cs_create_smart);
  2211. end;
  2212. { smart linking does not yet work with DWARF debug info on most targets }
  2213. if (cs_link_smart in init_settings.globalswitches) then
  2214. begin
  2215. Message(option_dwarf_smart_linking);
  2216. ForceStaticLinking;
  2217. end;
  2218. end;
  2219. { external debug info is only supported for DWARF on darwin }
  2220. if (target_info.system in systems_darwin) and
  2221. (cs_link_separate_dbg_file in init_settings.globalswitches) and
  2222. not(paratargetdbg in [dbg_dwarf2,dbg_dwarf3]) then
  2223. begin
  2224. Message(option_debug_external_unsupported);
  2225. exclude(init_settings.globalswitches,cs_link_separate_dbg_file);
  2226. end;
  2227. end;
  2228. constructor TOption.create;
  2229. begin
  2230. LogoWritten:=false;
  2231. NoPressEnter:=false;
  2232. FirstPass:=false;
  2233. FPUSetExplicitly:=false;
  2234. CPUSetExplicitly:=false;
  2235. OptCPUSetExplicitly:=false;
  2236. FileLevel:=0;
  2237. Quickinfo:='';
  2238. ParaIncludePath:=TSearchPathList.Create;
  2239. ParaObjectPath:=TSearchPathList.Create;
  2240. ParaUnitPath:=TSearchPathList.Create;
  2241. ParaLibraryPath:=TSearchPathList.Create;
  2242. ParaFrameworkPath:=TSearchPathList.Create;
  2243. FillChar(ParaAlignment,sizeof(ParaAlignment),0);
  2244. end;
  2245. destructor TOption.destroy;
  2246. begin
  2247. ParaIncludePath.Free;
  2248. ParaObjectPath.Free;
  2249. ParaUnitPath.Free;
  2250. ParaLibraryPath.Free;
  2251. ParaFrameworkPath.Free;
  2252. end;
  2253. {****************************************************************************
  2254. Callable Routines
  2255. ****************************************************************************}
  2256. function check_configfile(const fn:string;var foundfn:string):boolean;
  2257. function CfgFileExists(const fn:string):boolean;
  2258. begin
  2259. Comment(V_Tried,'Configfile search: '+fn);
  2260. CfgFileExists:=FileExists(fn);
  2261. end;
  2262. var
  2263. {$ifdef Unix}
  2264. hs,
  2265. {$endif Unix}
  2266. configpath : string;
  2267. begin
  2268. foundfn:=fn;
  2269. check_configfile:=true;
  2270. { retrieve configpath }
  2271. configpath:=FixPath(GetEnvironmentVariable('PPC_CONFIG_PATH'),false);
  2272. {$ifdef Unix}
  2273. if configpath='' then
  2274. configpath:=ExpandFileName(FixPath(exepath+'../etc/',false));
  2275. {$endif}
  2276. {
  2277. Order to read configuration file :
  2278. try reading fpc.cfg in :
  2279. 1 - current dir
  2280. 2 - configpath
  2281. 3 - compiler path
  2282. }
  2283. if not FileExists(fn) then
  2284. begin
  2285. {$ifdef Unix}
  2286. hs:=GetEnvironmentVariable('HOME');
  2287. if (hs<>'') and CfgFileExists(FixPath(hs,false)+'.'+fn) then
  2288. foundfn:=FixPath(hs,false)+'.'+fn
  2289. else
  2290. {$endif}
  2291. if CfgFileExists(configpath+fn) then
  2292. foundfn:=configpath+fn
  2293. else
  2294. {$ifndef Unix}
  2295. if CfgFileExists(exepath+fn) then
  2296. foundfn:=exepath+fn
  2297. else
  2298. {$else}
  2299. if CfgFileExists('/etc/'+fn) then
  2300. foundfn:='/etc/'+fn
  2301. else
  2302. {$endif}
  2303. check_configfile:=false;
  2304. end;
  2305. end;
  2306. procedure read_arguments(cmd:TCmdStr);
  2307. var
  2308. env: ansistring;
  2309. i : tfeature;
  2310. abi : tabi;
  2311. begin
  2312. option:=coption.create;
  2313. disable_configfile:=false;
  2314. { Non-core target defines }
  2315. Option.TargetOptions(true);
  2316. { get default messagefile }
  2317. msgfilename:=GetEnvironmentVariable('PPC_ERROR_FILE');
  2318. { default configfile can be specified on the commandline,
  2319. remove it first }
  2320. if (cmd<>'') and (cmd[1]='[') then
  2321. begin
  2322. ppccfg:=Copy(cmd,2,pos(']',cmd)-2);
  2323. Delete(cmd,1,pos(']',cmd));
  2324. end
  2325. else
  2326. ppccfg:='fpc.cfg';
  2327. { first pass reading of parameters, only -i -v -T etc.}
  2328. option.firstpass:=true;
  2329. if cmd<>'' then
  2330. option.parsecmd(cmd)
  2331. else
  2332. begin
  2333. option.read_parameters;
  2334. { Write only quickinfo }
  2335. if option.quickinfo<>'' then
  2336. option.writequickinfo;
  2337. end;
  2338. option.firstpass:=false;
  2339. { redefine target options so all defines are written even if no -Txxx is passed on the command line }
  2340. Option.TargetOptions(true);
  2341. { target is set here, for wince the default app type is gui }
  2342. if target_info.system in systems_wince then
  2343. apptype:=app_gui;
  2344. { default defines }
  2345. def_system_macro(target_info.shortname);
  2346. def_system_macro('FPC');
  2347. def_system_macro('VER'+version_nr);
  2348. def_system_macro('VER'+version_nr+'_'+release_nr);
  2349. def_system_macro('VER'+version_nr+'_'+release_nr+'_'+patch_nr);
  2350. { Temporary defines, until things settle down }
  2351. def_system_macro('RESSTRSECTIONS');
  2352. def_system_macro('FPC_HASFIXED64BITVARIANT');
  2353. def_system_macro('FPC_HASINTERNALOLEVARIANT2VARIANTCAST');
  2354. def_system_macro('FPC_HAS_VARSETS');
  2355. def_system_macro('FPC_HAS_VALGRINDBOOL');
  2356. def_system_macro('FPC_HAS_STR_CURRENCY');
  2357. def_system_macro('FPC_REAL2REAL_FIXED');
  2358. def_system_macro('FPC_STRTOCHARARRAYPROC');
  2359. def_system_macro('FPC_STRTOSHORTSTRINGPROC');
  2360. def_system_macro('FPC_OBJFPC_EXTENDED_IF');
  2361. def_system_macro('FPC_HAS_OPERATOR_ENUMERATOR');
  2362. def_system_macro('FPC_HAS_CONSTREF');
  2363. def_system_macro('FPC_STATICRIPFIXED');
  2364. {$if defined(x86) or defined(powerpc) or defined(powerpc64)}
  2365. def_system_macro('FPC_HAS_INTERNAL_ABS_LONG');
  2366. {$endif}
  2367. def_system_macro('FPC_HAS_UNICODESTRING');
  2368. def_system_macro('FPC_RTTI_PACKSET1');
  2369. def_system_macro('FPC_HAS_CPSTRING');
  2370. {$ifdef x86_64}
  2371. def_system_macro('FPC_HAS_RIP_RELATIVE');
  2372. {$endif x86_64}
  2373. def_system_macro('FPC_HAS_CEXTENDED');
  2374. def_system_macro('FPC_HAS_RESSTRINITS');
  2375. { these cpus have an inline rol/ror implementaion }
  2376. {$ifdef cpurox}
  2377. def_system_macro('FPC_HAS_INTERNAL_ROX');
  2378. {$endif}
  2379. { these cpus have an inline sar implementaion }
  2380. { currently, all supported CPUs have an internal sar implementation }
  2381. { $if defined(x86) or defined(arm) or defined(powerpc) or defined(powerpc64) or defined(sparc)}
  2382. def_system_macro('FPC_HAS_INTERNAL_SAR');
  2383. { $endif}
  2384. { inline bsf/bsr implementation }
  2385. {$if defined(x86) or defined(x86_64)}
  2386. def_system_macro('FPC_HAS_INTERNAL_BSX');
  2387. {$endif}
  2388. {$ifdef powerpc64}
  2389. def_system_macro('FPC_HAS_LWSYNC');
  2390. {$endif}
  2391. def_system_macro('FPC_HAS_MEMBAR');
  2392. def_system_macro('FPC_SETBASE_USED');
  2393. {$if defined(x86) or defined(arm)}
  2394. def_system_macro('INTERNAL_BACKTRACE');
  2395. {$endif}
  2396. def_system_macro('STR_CONCAT_PROCS');
  2397. {$warnings off}
  2398. if pocall_default = pocall_register then
  2399. def_system_macro('REGCALL');
  2400. {$warnings on}
  2401. { don't remove this, it's also for fpdoc necessary (FK) }
  2402. def_system_macro('FPC_HAS_FEATURE_SUPPORT');
  2403. { using a case is pretty useless here (FK) }
  2404. { some stuff for TP compatibility }
  2405. {$ifdef i386}
  2406. def_system_macro('CPU86');
  2407. def_system_macro('CPU87');
  2408. def_system_macro('CPU386');
  2409. {$endif}
  2410. { new processor stuff }
  2411. {$ifdef i386}
  2412. def_system_macro('CPUI386');
  2413. def_system_macro('CPU32');
  2414. def_system_macro('FPC_HAS_TYPE_EXTENDED');
  2415. def_system_macro('FPC_HAS_TYPE_DOUBLE');
  2416. def_system_macro('FPC_HAS_TYPE_SINGLE');
  2417. {$endif}
  2418. {$ifdef m68k}
  2419. def_system_macro('CPU68');
  2420. def_system_macro('CPU68K');
  2421. def_system_macro('CPUM68K');
  2422. def_system_macro('CPU32');
  2423. def_system_macro('FPC_CURRENCY_IS_INT64');
  2424. def_system_macro('FPC_COMP_IS_INT64');
  2425. {$endif}
  2426. {$ifdef ALPHA}
  2427. def_system_macro('CPUALPHA');
  2428. def_system_macro('CPU64');
  2429. {$endif}
  2430. {$ifdef powerpc}
  2431. def_system_macro('CPUPOWERPC');
  2432. def_system_macro('CPUPOWERPC32');
  2433. def_system_macro('CPU32');
  2434. def_system_macro('FPC_CURRENCY_IS_INT64');
  2435. def_system_macro('FPC_COMP_IS_INT64');
  2436. {$endif}
  2437. {$ifdef POWERPC64}
  2438. def_system_macro('CPUPOWERPC');
  2439. def_system_macro('CPUPOWERPC64');
  2440. def_system_macro('CPU64');
  2441. def_system_macro('FPC_CURRENCY_IS_INT64');
  2442. def_system_macro('FPC_COMP_IS_INT64');
  2443. {$endif}
  2444. {$ifdef iA64}
  2445. def_system_macro('CPUIA64');
  2446. def_system_macro('CPU64');
  2447. {$endif}
  2448. {$ifdef x86_64}
  2449. def_system_macro('CPUX86_64');
  2450. def_system_macro('CPUAMD64');
  2451. def_system_macro('CPU64');
  2452. { not supported for now, afaik (FK)
  2453. def_system_macro('FPC_HAS_TYPE_FLOAT128'); }
  2454. { win64 doesn't support the legacy fpu }
  2455. if target_info.system=system_x86_64_win64 then
  2456. begin
  2457. def_system_macro('FPC_CURRENCY_IS_INT64');
  2458. def_system_macro('FPC_COMP_IS_INT64');
  2459. end;
  2460. {$endif}
  2461. {$ifdef sparc}
  2462. def_system_macro('CPUSPARC');
  2463. def_system_macro('CPUSPARC32');
  2464. def_system_macro('CPU32');
  2465. def_system_macro('FPC_CURRENCY_IS_INT64');
  2466. def_system_macro('FPC_COMP_IS_INT64');
  2467. {$endif}
  2468. {$ifdef vis}
  2469. def_system_macro('CPUVIS');
  2470. def_system_macro('CPU32');
  2471. {$endif}
  2472. {$ifdef arm}
  2473. def_system_macro('CPUARM');
  2474. def_system_macro('CPU32');
  2475. def_system_macro('FPC_CURRENCY_IS_INT64');
  2476. def_system_macro('FPC_COMP_IS_INT64');
  2477. {$endif arm}
  2478. {$ifdef avr}
  2479. def_system_macro('CPUAVR');
  2480. def_system_macro('CPU16');
  2481. def_system_macro('FPC_CURRENCY_IS_INT64');
  2482. def_system_macro('FPC_COMP_IS_INT64');
  2483. {$endif avr}
  2484. { read configuration file }
  2485. if (not disable_configfile) and
  2486. (ppccfg<>'') then
  2487. read_configfile:=check_configfile(ppccfg,ppccfg)
  2488. else
  2489. read_configfile := false;
  2490. { Read commandline and configfile }
  2491. param_file:='';
  2492. { read configfile }
  2493. if read_configfile then
  2494. option.interpret_file(ppccfg);
  2495. { read parameters again to override config file }
  2496. if cmd<>'' then
  2497. option.parsecmd(cmd)
  2498. else
  2499. begin
  2500. { Write help pages if no parameters are passed }
  2501. if (paramcount=0) then
  2502. Option.WriteHelpPages;
  2503. option.read_parameters;
  2504. { Write only quickinfo }
  2505. if option.quickinfo<>'' then
  2506. option.writequickinfo;
  2507. end;
  2508. { check the compatibility of different options and adjust them if necessary
  2509. (and print possible errors)
  2510. }
  2511. option.checkoptionscompatibility;
  2512. { Stop if errors in options }
  2513. if ErrorCount>0 then
  2514. StopOptions(1);
  2515. { endian define }
  2516. case target_info.endian of
  2517. endian_little :
  2518. begin
  2519. def_system_macro('ENDIAN_LITTLE');
  2520. def_system_macro('FPC_LITTLE_ENDIAN');
  2521. end;
  2522. endian_big :
  2523. begin
  2524. def_system_macro('ENDIAN_BIG');
  2525. def_system_macro('FPC_BIG_ENDIAN');
  2526. end;
  2527. end;
  2528. { define abi }
  2529. for abi:=low(tabi) to high(tabi) do
  2530. undef_system_macro('FPC_ABI_'+abi2str[abi]);
  2531. def_system_macro('FPC_ABI_'+abi2str[target_info.abi]);
  2532. { Write logo }
  2533. if option.ParaLogo then
  2534. option.writelogo;
  2535. { Check file to compile }
  2536. if param_file='' then
  2537. begin
  2538. Message(option_no_source_found);
  2539. StopOptions(1);
  2540. end;
  2541. {$ifndef Unix}
  2542. param_file:=FixFileName(param_file);
  2543. {$endif not unix}
  2544. inputfilepath:=ExtractFilePath(param_file);
  2545. inputfilename:=ExtractFileName(param_file);
  2546. if ExtractFileExt(inputfilename)='' then
  2547. begin
  2548. if FileExists(inputfilepath+ChangeFileExt(inputfilename,sourceext)) then
  2549. inputfilename:=ChangeFileExt(inputfilename,sourceext)
  2550. else if FileExists(inputfilepath+ChangeFileExt(inputfilename,pasext)) then
  2551. inputfilename:=ChangeFileExt(inputfilename,pasext)
  2552. else if ((m_mac in current_settings.modeswitches) or
  2553. (tf_p_ext_support in target_info.flags))
  2554. and FileExists(inputfilepath+ChangeFileExt(inputfilename,pext)) then
  2555. inputfilename:=ChangeFileExt(inputfilename,pext);
  2556. end;
  2557. { Check output dir }
  2558. if (OutputExeDir<>'') and
  2559. not PathExists(OutputExeDir,false) then
  2560. begin
  2561. Message1(general_e_path_does_not_exist,OutputExeDir);
  2562. StopOptions(1);
  2563. end;
  2564. { Add paths specified with parameters to the searchpaths }
  2565. UnitSearchPath.AddList(option.ParaUnitPath,true);
  2566. ObjectSearchPath.AddList(option.ParaObjectPath,true);
  2567. IncludeSearchPath.AddList(option.ParaIncludePath,true);
  2568. LibrarySearchPath.AddList(option.ParaLibraryPath,true);
  2569. FrameworkSearchPath.AddList(option.ParaFrameworkPath,true);
  2570. { add unit environment and exepath to the unit search path }
  2571. if inputfilepath<>'' then
  2572. Unitsearchpath.AddPath(inputfilepath,true);
  2573. if not disable_configfile then
  2574. begin
  2575. env:=GetEnvironmentVariable(target_info.unit_env);
  2576. if env<>'' then
  2577. UnitSearchPath.AddPath(GetEnvironmentVariable(target_info.unit_env),false);
  2578. end;
  2579. {$ifdef Unix}
  2580. fpcdir:=FixPath(GetEnvironmentVariable('FPCDIR'),false);
  2581. if fpcdir='' then
  2582. begin
  2583. if PathExists('/usr/local/lib/fpc/'+version_string,true) then
  2584. fpcdir:='/usr/local/lib/fpc/'+version_string+'/'
  2585. else
  2586. fpcdir:='/usr/lib/fpc/'+version_string+'/';
  2587. end;
  2588. {$else unix}
  2589. fpcdir:=FixPath(GetEnvironmentVariable('FPCDIR'),false);
  2590. if fpcdir='' then
  2591. begin
  2592. fpcdir:=ExePath+'../';
  2593. if not(PathExists(fpcdir+'units',true)) and
  2594. not(PathExists(fpcdir+'rtl',true)) then
  2595. fpcdir:=fpcdir+'../';
  2596. end;
  2597. {$endif unix}
  2598. { first try development RTL, else use the default installation path }
  2599. if not disable_configfile then
  2600. begin
  2601. if PathExists(FpcDir+'rtl',true) then
  2602. if tf_use_8_3 in Source_Info.Flags then
  2603. UnitSearchPath.AddPath(FpcDir+'rtl/'+target_os_string,false)
  2604. else
  2605. UnitSearchPath.AddPath(FpcDir+'rtl/'+target_full_string,false)
  2606. else
  2607. if tf_use_8_3 in Source_Info.Flags then
  2608. UnitSearchPath.AddPath(FpcDir+'units/'+target_os_string+'/rtl',false)
  2609. else
  2610. UnitSearchPath.AddPath(FpcDir+'units/'+target_full_string+'/rtl',false);
  2611. end;
  2612. { Add exepath if the exe is not in the current dir, because that is always searched already.
  2613. Do not add it when linking on the target because then we can maybe already find
  2614. .o files that are not for the target }
  2615. if (ExePath<>GetCurrentDir) and
  2616. not(cs_link_on_target in init_settings.globalswitches) then
  2617. UnitSearchPath.AddPath(ExePath,false);
  2618. { Add unit dir to the object and library path }
  2619. objectsearchpath.AddList(unitsearchpath,false);
  2620. librarysearchpath.AddList(unitsearchpath,false);
  2621. { maybe override assembler }
  2622. if (paratargetasm<>as_none) then
  2623. begin
  2624. if not set_target_asm(paratargetasm) then
  2625. begin
  2626. Message2(option_incompatible_asm,asminfos[paratargetasm]^.idtxt,target_info.name);
  2627. set_target_asm(target_info.assemextern);
  2628. Message1(option_asm_forced,target_asm.idtxt);
  2629. end;
  2630. if (af_no_debug in asminfos[paratargetasm]^.flags) and
  2631. (paratargetdbg<>dbg_none) then
  2632. begin
  2633. Message1(option_confict_asm_debug,
  2634. asminfos[paratargetasm]^.idtxt);
  2635. paratargetdbg:=dbg_none;
  2636. exclude(init_settings.moduleswitches,cs_debuginfo);
  2637. end;
  2638. end;
  2639. {TOptionheck a second time as we might have changed assembler just above }
  2640. option.checkoptionscompatibility;
  2641. { maybe override debug info format }
  2642. if (paratargetdbg<>dbg_none) then
  2643. set_target_dbg(paratargetdbg);
  2644. { switch assembler if it's binary and we got -a on the cmdline }
  2645. if (cs_asm_leave in init_settings.globalswitches) and
  2646. (af_outputbinary in target_asm.flags) then
  2647. begin
  2648. Message(option_switch_bin_to_src_assembler);
  2649. set_target_asm(target_info.assemextern);
  2650. end;
  2651. { Force use of external linker if there is no
  2652. internal linker or the linking is skipped }
  2653. if not(cs_link_extern in init_settings.globalswitches) and
  2654. (not assigned(target_info.link) or
  2655. (cs_link_nolink in init_settings.globalswitches)) then
  2656. include(init_settings.globalswitches,cs_link_extern);
  2657. { turn off stripping if compiling with debuginfo or profile }
  2658. if (
  2659. (cs_debuginfo in init_settings.moduleswitches) or
  2660. (cs_profile in init_settings.moduleswitches)
  2661. ) and
  2662. not(cs_link_separate_dbg_file in init_settings.globalswitches) then
  2663. exclude(init_settings.globalswitches,cs_link_strip);
  2664. { force fpu emulation on arm/wince, arm/gba, arm/embedded, arm/nds and
  2665. arm/darwin if fpu type not explicitly set }
  2666. if not(option.FPUSetExplicitly) and
  2667. ((target_info.system in [system_arm_wince,system_arm_gba,system_m68k_amiga,
  2668. system_m68k_linux,system_arm_nds,system_arm_embedded,system_arm_darwin])
  2669. {$ifdef arm}
  2670. or (target_info.abi=abi_eabi)
  2671. {$endif arm}
  2672. )
  2673. {$ifdef arm}
  2674. or (init_settings.fputype=fpu_soft)
  2675. {$endif arm}
  2676. then
  2677. begin
  2678. {$ifdef cpufpemu}
  2679. include(init_settings.moduleswitches,cs_fp_emulation);
  2680. { cs_fp_emulation and fpu_soft are equal on arm }
  2681. init_settings.fputype:=fpu_soft;
  2682. {$endif cpufpemu}
  2683. end;
  2684. {$ifdef arm}
  2685. { set default cpu type to ARMv6 for Darwin unless specified otherwise }
  2686. if (target_info.system=system_arm_darwin) then
  2687. begin
  2688. if not option.CPUSetExplicitly then
  2689. init_settings.cputype:=cpu_armv6;
  2690. if not option.OptCPUSetExplicitly then
  2691. init_settings.optimizecputype:=cpu_armv6;
  2692. end;
  2693. {$endif arm}
  2694. { now we can define cpu and fpu type }
  2695. def_system_macro('CPU'+Cputypestr[init_settings.cputype]);
  2696. def_system_macro('FPU'+fputypestr[init_settings.fputype]);
  2697. if init_settings.fputype<>fpu_none then
  2698. begin
  2699. {$if defined(i386)}
  2700. def_system_macro('FPC_HAS_TYPE_EXTENDED');
  2701. {$endif}
  2702. def_system_macro('FPC_HAS_TYPE_SINGLE');
  2703. def_system_macro('FPC_HAS_TYPE_DOUBLE');
  2704. {$if not defined(i386) and not defined(x86_64)}
  2705. def_system_macro('FPC_INCLUDE_SOFTWARE_INT64_TO_DOUBLE');
  2706. {$endif}
  2707. {$ifdef x86_64}
  2708. { win64 doesn't support the legacy fpu }
  2709. if target_info.system=system_x86_64_win64 then
  2710. undef_system_macro('FPC_HAS_TYPE_EXTENDED')
  2711. else
  2712. def_system_macro('FPC_HAS_TYPE_EXTENDED');
  2713. {$endif}
  2714. end;
  2715. { Enable now for testing }
  2716. {$ifndef DISABLE_TLS_DIRECTORY}
  2717. if target_info.system in systems_windows then
  2718. def_system_macro('FPC_USE_TLS_DIRECTORY');
  2719. {$endif not DISABLE_TLS_DIRECTORY}
  2720. {$ifdef ARM}
  2721. { define FPC_DOUBLE_HILO_SWAPPED if needed to properly handle doubles in RTL }
  2722. if (init_settings.fputype in [fpu_fpa,fpu_fpa10,fpu_fpa11]) and
  2723. not(cs_fp_emulation in init_settings.moduleswitches) then
  2724. def_system_macro('FPC_DOUBLE_HILO_SWAPPED');
  2725. {$endif ARM}
  2726. { Section smartlinking conflicts with import sections on Windows }
  2727. if GenerateImportSection and
  2728. (target_info.system in [system_i386_win32,system_x86_64_win64]) then
  2729. exclude(target_info.flags,tf_smartlink_sections);
  2730. if not LinkTypeSetExplicitly then
  2731. set_default_link_type;
  2732. { Default alignment settings,
  2733. 1. load the defaults for the target
  2734. 2. override with generic optimizer setting (little size)
  2735. 3. override with the user specified -Oa }
  2736. UpdateAlignment(init_settings.alignment,target_info.alignment);
  2737. if (cs_opt_size in current_settings.optimizerswitches) then
  2738. begin
  2739. init_settings.alignment.procalign:=1;
  2740. init_settings.alignment.jumpalign:=1;
  2741. init_settings.alignment.loopalign:=1;
  2742. end;
  2743. UpdateAlignment(init_settings.alignment,option.paraalignment);
  2744. set_system_macro('FPC_VERSION',version_nr);
  2745. set_system_macro('FPC_RELEASE',release_nr);
  2746. set_system_macro('FPC_PATCH',patch_nr);
  2747. set_system_macro('FPC_FULLVERSION',Format('%d%.02d%.02d',[StrToInt(version_nr),StrToInt(release_nr),StrToInt(patch_nr)]));
  2748. if not(target_info.system in systems_windows) then
  2749. def_system_macro('FPC_WIDESTRING_EQUAL_UNICODESTRING');
  2750. for i:=low(tfeature) to high(tfeature) do
  2751. if i in features then
  2752. def_system_macro('FPC_HAS_FEATURE_'+featurestr[i]);
  2753. option.free;
  2754. Option:=nil;
  2755. clearstack_pocalls := [pocall_cdecl,pocall_cppdecl,pocall_syscall,pocall_mwpascal];
  2756. cdecl_pocalls := [pocall_cdecl, pocall_cppdecl];
  2757. if (tf_safecall_clearstack in target_info.flags) then
  2758. begin
  2759. include (cdecl_pocalls, pocall_safecall);
  2760. include (clearstack_pocalls, pocall_safecall)
  2761. end;
  2762. end;
  2763. initialization
  2764. coption:=toption;
  2765. finalization
  2766. if assigned(option) then
  2767. option.free;
  2768. end.