options.pas 112 KB

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