2
0

options.pas 114 KB

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