options.pas 127 KB

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