options.pas 96 KB

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