options.pas 105 KB

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