options.pas 115 KB

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