options.pas 122 KB

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