options.pas 120 KB

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