options.pas 129 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926
  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,system_aarch64_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. system_aarch64_darwin:
  873. begin
  874. set_system_compvar('IPHONE_OS_VERSION_MIN_REQUIRED','70000');
  875. iPhoneOSVersionMin:='7.0';
  876. end
  877. else
  878. internalerror(2012031001);
  879. end;
  880. end;
  881. function Toption.Unsetbool(var Opts:TCmdStr; Pos: Longint; const FullPara: TCmdStr; RequireBoolPara: boolean):boolean;
  882. { checks if the character after pos in Opts is a + or a - and returns resp.
  883. false or true. If it is another character (or none), it also returns false }
  884. begin
  885. UnsetBool := false;
  886. if Length(Opts)>Pos then
  887. begin
  888. inc(Pos);
  889. UnsetBool := Opts[Pos] = '-';
  890. if Opts[Pos] in ['-','+']then
  891. delete(Opts,Pos,1)
  892. else if RequireBoolPara then
  893. IllegalPara(FullPara);
  894. end;
  895. end;
  896. procedure TOption.interpret_option(const opt:TCmdStr;ispara:boolean);
  897. var
  898. code : integer;
  899. c : char;
  900. more : TCmdStr;
  901. major,minor : longint;
  902. error : integer;
  903. j,l : longint;
  904. d,s : TCmdStr;
  905. hs : TCmdStr;
  906. unicodemapping : punicodemap;
  907. begin
  908. if opt='' then
  909. exit;
  910. { only parse define,undef,target,verbosity,link etc options the firsttime }
  911. if firstpass and
  912. not(
  913. (opt[1]='-') and
  914. (
  915. ((length(opt)>1) and (opt[2] in ['i','d','v','T','u','n','X','l'])) or
  916. ((length(opt)>3) and (opt[2]='F') and (opt[3]='e')) or
  917. ((length(opt)>3) and (opt[2]='C') and (opt[3]='p')) or
  918. ((length(opt)>3) and (opt[2]='W') and (opt[3]='m'))
  919. )
  920. ) then
  921. exit;
  922. Message1(option_handling_option,opt);
  923. case opt[1] of
  924. '-' :
  925. begin
  926. more:=Copy(opt,3,2147483647);
  927. if firstpass then
  928. Message1(option_interpreting_firstpass_option,opt)
  929. else
  930. Message1(option_interpreting_option,opt);
  931. case opt[2] of
  932. '?' :
  933. begin
  934. if (More <> '') and (More [1] = 'F') then
  935. begin
  936. FPCHelpLines := true;
  937. Delete (More, 1, 1);
  938. FPCBinaryPath := More;
  939. end;
  940. WriteHelpPages;
  941. end;
  942. 'a' :
  943. begin
  944. include(init_settings.globalswitches,cs_asm_leave);
  945. j:=1;
  946. while j<=length(more) do
  947. begin
  948. case more[j] of
  949. 'l' :
  950. include(init_settings.globalswitches,cs_asm_source);
  951. 'r' :
  952. include(init_settings.globalswitches,cs_asm_regalloc);
  953. 't' :
  954. include(init_settings.globalswitches,cs_asm_tempalloc);
  955. 'n' :
  956. include(init_settings.globalswitches,cs_asm_nodes);
  957. { -ao option must be the last, everything behind it is passed directly to
  958. external assembler, it is ignored if internal assembler is used. }
  959. 'o' :
  960. begin
  961. asmextraopt:=copy(more,j+1,length(more)-j);
  962. break;
  963. end;
  964. 'p' :
  965. begin
  966. exclude(init_settings.globalswitches,cs_asm_leave);
  967. if UnsetBool(More, 0, opt, false) then
  968. exclude(init_settings.globalswitches,cs_asm_pipe)
  969. else
  970. include(init_settings.globalswitches,cs_asm_pipe);
  971. end;
  972. '-' :
  973. init_settings.globalswitches:=init_settings.globalswitches -
  974. [cs_asm_leave, cs_asm_source,cs_asm_regalloc, cs_asm_tempalloc,
  975. cs_asm_nodes, cs_asm_pipe];
  976. else
  977. IllegalPara(opt);
  978. end;
  979. inc(j);
  980. end;
  981. end;
  982. 'A' :
  983. begin
  984. paratargetasm:=find_asm_by_string(More);
  985. if paratargetasm=as_none then
  986. IllegalPara(opt);
  987. end;
  988. 'b' :
  989. begin
  990. // Message1(option_obsolete_switch,'-b');
  991. if UnsetBool(More,0,opt,false) then
  992. begin
  993. init_settings.moduleswitches:=init_settings.moduleswitches-[cs_browser];
  994. init_settings.moduleswitches:=init_settings.moduleswitches-[cs_local_browser];
  995. end
  996. else
  997. begin
  998. init_settings.moduleswitches:=init_settings.moduleswitches+[cs_browser];
  999. end;
  1000. if More<>'' then
  1001. if (More='l') or (More='l+') then
  1002. init_settings.moduleswitches:=init_settings.moduleswitches+[cs_local_browser]
  1003. else if More='l-' then
  1004. init_settings.moduleswitches:=init_settings.moduleswitches-[cs_local_browser]
  1005. else
  1006. IllegalPara(opt);
  1007. end;
  1008. 'B' :
  1009. do_build:=not UnSetBool(more,0,opt,true);
  1010. 'C' :
  1011. begin
  1012. j:=1;
  1013. while j<=length(more) do
  1014. begin
  1015. case more[j] of
  1016. '3' :
  1017. If UnsetBool(More, j, opt, false) then
  1018. exclude(init_settings.localswitches,cs_ieee_errors)
  1019. Else
  1020. include(init_settings.localswitches,cs_ieee_errors);
  1021. 'a' :
  1022. begin
  1023. s:=upper(copy(more,j+1,length(more)-j));
  1024. if not(SetAbiType(s,target_info.abi)) then
  1025. IllegalPara(opt);
  1026. break;
  1027. end;
  1028. 'b' :
  1029. begin
  1030. if UnsetBool(More, j, opt, false) then
  1031. target_info.endian:=endian_little
  1032. else
  1033. target_info.endian:=endian_big;
  1034. end;
  1035. 'c' :
  1036. begin
  1037. if not SetAktProcCall(upper(copy(more,j+1,length(more)-j)),init_settings.defproccall) then
  1038. IllegalPara(opt);
  1039. break;
  1040. end;
  1041. {$ifdef cpufpemu}
  1042. 'e' :
  1043. begin
  1044. If UnsetBool(More, j, opt, false) then
  1045. exclude(init_settings.moduleswitches,cs_fp_emulation)
  1046. Else
  1047. include(init_settings.moduleswitches,cs_fp_emulation);
  1048. end;
  1049. {$endif cpufpemu}
  1050. 'f' :
  1051. begin
  1052. s:=upper(copy(more,j+1,length(more)-j));
  1053. if not(SetFpuType(s,init_settings.fputype)) then
  1054. IllegalPara(opt);
  1055. FPUSetExplicitly:=True;
  1056. break;
  1057. end;
  1058. 'F' :
  1059. begin
  1060. if not SetMinFPConstPrec(copy(more,j+1,length(more)-j),init_settings.minfpconstprec) then
  1061. IllegalPara(opt);
  1062. break;
  1063. end;
  1064. 'g' :
  1065. begin
  1066. if tf_no_pic_supported in target_info.flags then
  1067. begin
  1068. { consume a possible '-' coming after it }
  1069. UnsetBool(More, j, opt, false);
  1070. message(scan_w_pic_ignored);
  1071. end
  1072. else if UnsetBool(More, j, opt, false) then
  1073. exclude(init_settings.moduleswitches,cs_create_pic)
  1074. else
  1075. include(init_settings.moduleswitches,cs_create_pic);
  1076. end;
  1077. 'h' :
  1078. begin
  1079. val(copy(more,j+1,length(more)-j),heapsize,code);
  1080. if (code<>0) or (heapsize<1024) then
  1081. IllegalPara(opt);
  1082. break;
  1083. end;
  1084. 'i' :
  1085. If UnsetBool(More, j, opt, false) then
  1086. exclude(init_settings.localswitches,cs_check_io)
  1087. else
  1088. include(init_settings.localswitches,cs_check_io);
  1089. {$ifdef arm}
  1090. 'I' :
  1091. begin
  1092. if (upper(copy(more,j+1,length(more)-j))='THUMB') and
  1093. { does selected CPU really understand thumb? }
  1094. (init_settings.cputype in cpu_has_thumb) then
  1095. init_settings.instructionset:=is_thumb
  1096. else if upper(copy(more,j+1,length(more)-j))='ARM' then
  1097. init_settings.instructionset:=is_arm
  1098. else
  1099. IllegalPara(opt);
  1100. break;
  1101. end;
  1102. {$endif arm}
  1103. 'n' :
  1104. If UnsetBool(More, j, opt, false) then
  1105. exclude(init_settings.globalswitches,cs_link_nolink)
  1106. Else
  1107. include(init_settings.globalswitches,cs_link_nolink);
  1108. 'N' :
  1109. If UnsetBool(More, j, opt, false) then
  1110. exclude(init_settings.localswitches,cs_check_low_addr_load)
  1111. Else
  1112. include(init_settings.localswitches,cs_check_low_addr_load);
  1113. 'o' :
  1114. If UnsetBool(More, j, opt, false) then
  1115. exclude(init_settings.localswitches,cs_check_overflow)
  1116. Else
  1117. include(init_settings.localswitches,cs_check_overflow);
  1118. 'O' :
  1119. If UnsetBool(More, j, opt, false) then
  1120. exclude(init_settings.localswitches,cs_check_ordinal_size)
  1121. Else
  1122. include(init_settings.localswitches,cs_check_ordinal_size);
  1123. 'p' :
  1124. begin
  1125. s:=upper(copy(more,j+1,length(more)-j));
  1126. if not(Setcputype(s,init_settings)) then
  1127. IllegalPara(opt);
  1128. CPUSetExplicitly:=true;
  1129. break;
  1130. end;
  1131. 'P':
  1132. begin
  1133. delete(more,1,1);
  1134. case upper(copy(more,1,pos('=',more)-1)) of
  1135. 'PACKSET':
  1136. begin
  1137. delete(more,1,pos('=',more));
  1138. case more of
  1139. '0','DEFAULT','NORMAL':
  1140. init_settings.setalloc:=0;
  1141. '1','2','4','8':
  1142. init_settings.setalloc:=StrToInt(more);
  1143. else
  1144. IllegalPara(opt);
  1145. end
  1146. end;
  1147. 'PACKENUM':
  1148. begin
  1149. delete(more,1,pos('=',more));
  1150. case more of
  1151. '0','DEFAULT','NORMAL':
  1152. init_settings.packenum:=4;
  1153. '1','2','4':
  1154. init_settings.packenum:=StrToInt(more);
  1155. else
  1156. IllegalPara(opt);
  1157. end;
  1158. end;
  1159. 'PACKRECORD':
  1160. begin
  1161. delete(more,1,pos('=',more));
  1162. case more of
  1163. '0','DEFAULT','NORMAL':
  1164. init_settings.packrecords:=default_settings.packrecords;
  1165. '1','2','4','8','16','32':
  1166. init_settings.packrecords:=StrToInt(more);
  1167. else
  1168. IllegalPara(opt);
  1169. end;
  1170. end
  1171. else
  1172. IllegalPara(opt);
  1173. end;
  1174. end;
  1175. 'r' :
  1176. If UnsetBool(More, j, opt, false) then
  1177. exclude(init_settings.localswitches,cs_check_range)
  1178. Else
  1179. include(init_settings.localswitches,cs_check_range);
  1180. 'R' :
  1181. If UnsetBool(More, j, opt, false) then
  1182. begin
  1183. exclude(init_settings.localswitches,cs_check_range);
  1184. exclude(init_settings.localswitches,cs_check_object);
  1185. end
  1186. Else
  1187. begin
  1188. include(init_settings.localswitches,cs_check_range);
  1189. include(init_settings.localswitches,cs_check_object);
  1190. end;
  1191. 's' :
  1192. begin
  1193. val(copy(more,j+1,length(more)-j),stacksize,code);
  1194. if (code<>0)
  1195. {$ifdef cpu16bitaddr}
  1196. or (stacksize>=65521)
  1197. {$else cpu16bitaddr}
  1198. or (stacksize>=67107840)
  1199. {$endif cpu16bitaddr}
  1200. or (stacksize<1024) then
  1201. IllegalPara(opt);
  1202. break;
  1203. end;
  1204. 't' :
  1205. If UnsetBool(More, j, opt, false) then
  1206. exclude(init_settings.localswitches,cs_check_stack)
  1207. Else
  1208. include(init_settings.localswitches,cs_check_stack);
  1209. 'D' :
  1210. If UnsetBool(More, j, opt, false) then
  1211. exclude(init_settings.moduleswitches,cs_create_dynamic)
  1212. Else
  1213. include(init_settings.moduleswitches,cs_create_dynamic);
  1214. 'X' :
  1215. If UnsetBool(More, j, opt, false) then
  1216. exclude(init_settings.moduleswitches,cs_create_smart)
  1217. Else
  1218. include(init_settings.moduleswitches,cs_create_smart);
  1219. 'T' :
  1220. begin
  1221. if not UpdateTargetSwitchStr(copy(more,j+1,length(more)),init_settings.targetswitches,true) then
  1222. IllegalPara(opt);
  1223. break;
  1224. end;
  1225. 'v' :
  1226. If target_info.system in systems_jvm then
  1227. If UnsetBool(More, j, opt, false) then
  1228. exclude(init_settings.localswitches,cs_check_var_copyout)
  1229. Else
  1230. include(init_settings.localswitches,cs_check_var_copyout)
  1231. else
  1232. IllegalPara(opt)
  1233. else
  1234. IllegalPara(opt);
  1235. end;
  1236. inc(j);
  1237. end;
  1238. end;
  1239. 'd' :
  1240. begin
  1241. l:=Pos(':=',more);
  1242. if l>0 then
  1243. hs:=copy(more,1,l-1)
  1244. else
  1245. hs:=more;
  1246. if (not is_identifier(hs)) then
  1247. begin
  1248. if hs='' then
  1249. Message1(option_missing_arg,'-d')
  1250. else
  1251. Message1(option_malformed_para,opt);
  1252. StopOptions(1);
  1253. end;
  1254. if l>0 then
  1255. set_system_compvar(hs,Copy(more,l+2,255))
  1256. else
  1257. def_system_macro(hs);
  1258. end;
  1259. 'D' :
  1260. begin
  1261. include(init_settings.globalswitches,cs_link_deffile);
  1262. j:=1;
  1263. while j<=length(more) do
  1264. begin
  1265. case more[j] of
  1266. 'd' :
  1267. begin
  1268. description:=Copy(more,j+1,255);
  1269. break;
  1270. end;
  1271. 'v' :
  1272. begin
  1273. dllversion:=Copy(more,j+1,255);
  1274. l:=pos('.',dllversion);
  1275. dllminor:=0;
  1276. error:=0;
  1277. if l>0 then
  1278. begin
  1279. val(copy(dllversion,l+1,255),minor,error);
  1280. if (error=0) and
  1281. (minor>=0) and (minor<=$ffff) then
  1282. dllminor:=minor
  1283. else
  1284. if error=0 then
  1285. error:=1;
  1286. end;
  1287. if l=0 then
  1288. l:=256;
  1289. dllmajor:=1;
  1290. major:=0;
  1291. if error=0 then
  1292. val(copy(dllversion,1,l-1),major,error);
  1293. if (error=0) and (major>=0) and (major<=$ffff) then
  1294. dllmajor:=major
  1295. else
  1296. if error=0 then
  1297. error:=1;
  1298. if error<>0 then
  1299. Message1(scan_w_wrong_version_ignored,dllversion);
  1300. break;
  1301. end;
  1302. 'w' :
  1303. usewindowapi:=true;
  1304. '-' :
  1305. begin
  1306. exclude(init_settings.globalswitches,cs_link_deffile);
  1307. usewindowapi:=false;
  1308. end;
  1309. else
  1310. IllegalPara(opt);
  1311. end;
  1312. inc(j);
  1313. end;
  1314. end;
  1315. 'e' :
  1316. exepath:=FixPath(More,true);
  1317. 'E' :
  1318. begin
  1319. if UnsetBool(More, 0, opt, true) then
  1320. exclude(init_settings.globalswitches,cs_link_nolink)
  1321. else
  1322. include(init_settings.globalswitches,cs_link_nolink);
  1323. end;
  1324. 'f' :
  1325. begin
  1326. if more='PIC' then
  1327. begin
  1328. if tf_no_pic_supported in target_info.flags then
  1329. message(scan_w_pic_ignored)
  1330. else
  1331. include(init_settings.moduleswitches,cs_create_pic)
  1332. end
  1333. else
  1334. IllegalPara(opt);
  1335. end;
  1336. 'F' :
  1337. begin
  1338. if more='' then
  1339. IllegalPara(opt);
  1340. c:=more[1];
  1341. Delete(more,1,1);
  1342. DefaultReplacements(More);
  1343. case c of
  1344. 'a' :
  1345. autoloadunits:=more;
  1346. 'c' :
  1347. begin
  1348. if (upper(more)='UTF8') or (upper(more)='UTF-8') then
  1349. init_settings.sourcecodepage:=CP_UTF8
  1350. else if not(cpavailable(more)) then
  1351. Message1(option_code_page_not_available,more)
  1352. else
  1353. init_settings.sourcecodepage:=codepagebyname(more);
  1354. include(init_settings.moduleswitches,cs_explicit_codepage);
  1355. end;
  1356. 'C' :
  1357. RCCompiler:=More;
  1358. 'd' :
  1359. if UnsetBool(more, 0, opt, true) then
  1360. init_settings.disabledircache:=false
  1361. else
  1362. init_settings.disabledircache:=true;
  1363. 'D' :
  1364. utilsdirectory:=FixPath(More,true);
  1365. 'e' :
  1366. SetRedirectFile(More);
  1367. 'E' :
  1368. OutputExeDir:=FixPath(More,true);
  1369. 'f' :
  1370. if (target_info.system in systems_darwin) then
  1371. if ispara then
  1372. ParaFrameworkPath.AddPath(More,false)
  1373. else
  1374. frameworksearchpath.AddPath(More,true)
  1375. else
  1376. IllegalPara(opt);
  1377. 'i' :
  1378. begin
  1379. if ispara then
  1380. ParaIncludePath.AddPath(More,false)
  1381. else
  1382. includesearchpath.AddPath(More,true);
  1383. end;
  1384. 'm' :
  1385. begin
  1386. s:=ExtractFileDir(more);
  1387. if TryStrToInt(ExtractFileName(more),j) then
  1388. begin
  1389. unicodemapping:=loadunicodemapping(More,More+'.txt',j);
  1390. if assigned(unicodemapping) then
  1391. registermapping(unicodemapping)
  1392. else
  1393. IllegalPara(opt);
  1394. end
  1395. else
  1396. IllegalPara(opt);
  1397. end;
  1398. 'M' :
  1399. unicodepath:=FixPath(More,true);
  1400. 'g' :
  1401. Message2(option_obsolete_switch_use_new,'-Fg','-Fl');
  1402. 'l' :
  1403. begin
  1404. if path_absolute(More) then
  1405. if ispara then
  1406. ParaLibraryPath.AddPath(sysrootpath,More,false)
  1407. else
  1408. LibrarySearchPath.AddPath(sysrootpath,More,true)
  1409. else
  1410. if ispara then
  1411. ParaLibraryPath.AddPath('',More,false)
  1412. else
  1413. LibrarySearchPath.AddPath('',More,true);
  1414. end;
  1415. 'L' :
  1416. begin
  1417. if More<>'' then
  1418. ParaDynamicLinker:=More
  1419. else
  1420. IllegalPara(opt);
  1421. end;
  1422. 'o' :
  1423. begin
  1424. if ispara then
  1425. ParaObjectPath.AddPath(More,false)
  1426. else
  1427. ObjectSearchPath.AddPath(More,true);
  1428. end;
  1429. 'r' :
  1430. Msgfilename:=More;
  1431. 'R' :
  1432. ResCompiler:=More;
  1433. 'u' :
  1434. begin
  1435. if ispara then
  1436. ParaUnitPath.AddPath(More,false)
  1437. else
  1438. unitsearchpath.AddPath(More,true);
  1439. end;
  1440. 'U' :
  1441. OutputUnitDir:=FixPath(More,true);
  1442. 'W',
  1443. 'w':
  1444. begin
  1445. if More<>'' then
  1446. begin
  1447. DefaultReplacements(More);
  1448. D:=ExtractFilePath(More);
  1449. if (D<>'') then
  1450. D:=FixPath(D,True);
  1451. D:=D+ExtractFileName(More);
  1452. if (c='W') then
  1453. WpoFeedbackOutput:=D
  1454. else
  1455. WpoFeedbackInput:=D;
  1456. end
  1457. else
  1458. IllegalPara(opt);
  1459. end;
  1460. else
  1461. IllegalPara(opt);
  1462. end;
  1463. end;
  1464. 'g' :
  1465. begin
  1466. if UnsetBool(More, 0, opt, false) then
  1467. begin
  1468. exclude(init_settings.moduleswitches,cs_debuginfo);
  1469. exclude(init_settings.globalswitches,cs_use_heaptrc);
  1470. exclude(init_settings.globalswitches,cs_use_lineinfo);
  1471. exclude(init_settings.localswitches,cs_checkpointer);
  1472. localvartrashing := -1;
  1473. end
  1474. else
  1475. begin
  1476. include(init_settings.moduleswitches,cs_debuginfo);
  1477. if paratargetdbg=dbg_none then
  1478. paratargetdbg:=target_info.dbg;
  1479. end;
  1480. if not RelocSectionSetExplicitly then
  1481. RelocSection:=false;
  1482. j:=1;
  1483. while j<=length(more) do
  1484. begin
  1485. case more[j] of
  1486. 'c' :
  1487. begin
  1488. if UnsetBool(More, j, opt, false) then
  1489. exclude(init_settings.localswitches,cs_checkpointer)
  1490. else if (target_info.system in systems_support_checkpointer) then
  1491. include(init_settings.localswitches,cs_checkpointer)
  1492. else
  1493. UnsupportedPara('-gc');
  1494. end;
  1495. 'h' :
  1496. begin
  1497. if UnsetBool(More, j, opt, false) then
  1498. exclude(init_settings.globalswitches,cs_use_heaptrc)
  1499. else
  1500. include(init_settings.globalswitches,cs_use_heaptrc);
  1501. end;
  1502. 'l' :
  1503. begin
  1504. if UnsetBool(More, j, opt, false) then
  1505. exclude(init_settings.globalswitches,cs_use_lineinfo)
  1506. else
  1507. include(init_settings.globalswitches,cs_use_lineinfo);
  1508. end;
  1509. 'o' :
  1510. begin
  1511. if not UpdateDebugStr(copy(more,j+1,length(more)),init_settings.debugswitches) then
  1512. IllegalPara(opt);
  1513. break;
  1514. end;
  1515. 'p' :
  1516. begin
  1517. if UnsetBool(More, j, opt, false) then
  1518. exclude(init_settings.globalswitches,cs_stabs_preservecase)
  1519. else
  1520. include(init_settings.globalswitches,cs_stabs_preservecase);
  1521. end;
  1522. 's' :
  1523. begin
  1524. paratargetdbg:=dbg_stabs;
  1525. end;
  1526. 't' :
  1527. begin
  1528. if UnsetBool(More, j, opt, false) then
  1529. localvartrashing := -1
  1530. else
  1531. localvartrashing := (localvartrashing + 1) mod nroftrashvalues;
  1532. end;
  1533. 'v' :
  1534. begin
  1535. if UnsetBool(More, j, opt, false) then
  1536. exclude(init_settings.globalswitches,cs_gdb_valgrind)
  1537. else
  1538. include(init_settings.globalswitches,cs_gdb_valgrind);
  1539. end;
  1540. 'w' :
  1541. begin
  1542. if (j<length(more)) and (more[j+1] in ['2','3','4']) then
  1543. begin
  1544. case more[j+1] of
  1545. '2': paratargetdbg:=dbg_dwarf2;
  1546. '3': paratargetdbg:=dbg_dwarf3;
  1547. '4': paratargetdbg:=dbg_dwarf4;
  1548. end;
  1549. inc(j);
  1550. end
  1551. else
  1552. paratargetdbg:=dbg_dwarf2;
  1553. end;
  1554. else
  1555. IllegalPara(opt);
  1556. end;
  1557. inc(j);
  1558. end;
  1559. end;
  1560. 'h' :
  1561. begin
  1562. NoPressEnter:=true;
  1563. if (More <> '') and (More [1] = 'F') then
  1564. begin
  1565. FPCHelpLines := true;
  1566. Delete (More, 1, 1);
  1567. FPCBinaryPath := More;
  1568. end;
  1569. WriteHelpPages;
  1570. end;
  1571. 'i' :
  1572. begin
  1573. if (More='') or
  1574. (More [1] in ['a', 'c', 'f', 'i', 'o', 'r', 't', 'u', 'w']) then
  1575. WriteInfo (More)
  1576. else
  1577. QuickInfo:=QuickInfo+More;
  1578. end;
  1579. 'I' :
  1580. begin
  1581. if ispara then
  1582. ParaIncludePath.AddPath(More,false)
  1583. else
  1584. includesearchpath.AddPath(More,false);
  1585. end;
  1586. 'k' :
  1587. begin
  1588. if more<>'' then
  1589. ParaLinkOptions:=ParaLinkOptions+' '+More
  1590. else
  1591. IllegalPara(opt);
  1592. end;
  1593. 'l' :
  1594. ParaLogo:=not UnSetBool(more,0,opt,true);
  1595. {$ifdef PREPROCWRITE}
  1596. 'm' :
  1597. parapreprocess:=not UnSetBool(more,0,opt,true);
  1598. {$endif PREPROCWRITE}
  1599. 'M' :
  1600. begin
  1601. more:=Upper(more);
  1602. if not SetCompileMode(more, true) then
  1603. if not SetCompileModeSwitch(more, true) then
  1604. IllegalPara(opt);
  1605. end;
  1606. 'n' :
  1607. begin
  1608. if More='' then
  1609. disable_configfile:=true
  1610. else
  1611. IllegalPara(opt);
  1612. end;
  1613. 'o' :
  1614. begin
  1615. if More<>'' then
  1616. begin
  1617. DefaultReplacements(More);
  1618. D:=ExtractFilePath(More);
  1619. if (D<>'') then
  1620. OutputExeDir:=FixPath(D,True);
  1621. OutputFileName:=ExtractFileName(More);
  1622. end
  1623. else
  1624. IllegalPara(opt);
  1625. end;
  1626. 'O' :
  1627. begin
  1628. j:=1;
  1629. while j<=length(more) do
  1630. begin
  1631. case more[j] of
  1632. '1' :
  1633. init_settings.optimizerswitches:=init_settings.optimizerswitches+level1optimizerswitches;
  1634. '2' :
  1635. init_settings.optimizerswitches:=init_settings.optimizerswitches+level2optimizerswitches;
  1636. '3' :
  1637. init_settings.optimizerswitches:=init_settings.optimizerswitches+level3optimizerswitches;
  1638. '4' :
  1639. init_settings.optimizerswitches:=init_settings.optimizerswitches+level4optimizerswitches;
  1640. 'a' :
  1641. begin
  1642. if not(UpdateAlignmentStr(Copy(Opt,j+3,255),ParaAlignment)) then
  1643. IllegalPara(opt);
  1644. break;
  1645. end;
  1646. 's' :
  1647. include(init_settings.optimizerswitches,cs_opt_size);
  1648. 'p' :
  1649. begin
  1650. if not Setoptimizecputype(copy(more,j+1,length(more)),init_settings.optimizecputype) then
  1651. begin
  1652. OptCPUSetExplicitly:=true;
  1653. { Give warning for old i386 switches }
  1654. if (Length(More)-j=1) and
  1655. (More[j+1]>='1') and (More[j+1]<='5')then
  1656. Message2(option_obsolete_switch_use_new,'-Op<nr>','-Op<name>')
  1657. else
  1658. IllegalPara(opt);
  1659. end;
  1660. break;
  1661. end;
  1662. 'o' :
  1663. begin
  1664. if not UpdateOptimizerStr(copy(more,j+1,length(more)),init_settings.optimizerswitches) then
  1665. IllegalPara(opt);
  1666. break;
  1667. end;
  1668. '-' :
  1669. begin
  1670. init_settings.optimizerswitches:=[];
  1671. FillChar(ParaAlignment,sizeof(ParaAlignment),0);
  1672. end;
  1673. { Obsolete switches }
  1674. 'g' :
  1675. Message2(option_obsolete_switch_use_new,'-Og','-Os');
  1676. 'G' :
  1677. Message1(option_obsolete_switch,'-OG');
  1678. 'r' :
  1679. Message2(option_obsolete_switch_use_new,'-Or','-O2 or -Ooregvar');
  1680. 'u' :
  1681. Message2(option_obsolete_switch_use_new,'-Ou','-Oouncertain');
  1682. 'w' :
  1683. begin
  1684. if not UpdateWpoStr(copy(more,j+1,length(more)),init_settings.dowpoptimizerswitches) then
  1685. IllegalPara(opt);
  1686. break;
  1687. end;
  1688. 'W' :
  1689. begin
  1690. if not UpdateWpoStr(copy(more,j+1,length(more)),init_settings.genwpoptimizerswitches) then
  1691. IllegalPara(opt);
  1692. break;
  1693. end;
  1694. else
  1695. IllegalPara(opt);
  1696. end;
  1697. inc(j);
  1698. end;
  1699. end;
  1700. 'p' :
  1701. begin
  1702. if UnsetBool(More, 0, opt, false) then
  1703. begin
  1704. init_settings.moduleswitches:=init_settings.moduleswitches-[cs_profile];
  1705. undef_system_macro('FPC_PROFILE');
  1706. end
  1707. else
  1708. if Length(More)=0 then
  1709. IllegalPara(opt)
  1710. else
  1711. case more[1] of
  1712. 'g' : if UnsetBool(more, 1, opt, false) then
  1713. begin
  1714. exclude(init_settings.moduleswitches,cs_profile);
  1715. undef_system_macro('FPC_PROFILE');
  1716. end
  1717. else if (target_info.system in supported_targets_pg) then
  1718. begin
  1719. include(init_settings.moduleswitches,cs_profile);
  1720. def_system_macro('FPC_PROFILE');
  1721. end
  1722. else
  1723. UnsupportedPara('-pg');
  1724. else
  1725. IllegalPara(opt);
  1726. end;
  1727. end;
  1728. 'P' : ; { Ignore used by fpc.pp }
  1729. 'R' :
  1730. begin
  1731. if not SetAsmReadMode(More,init_settings.asmmode) then
  1732. IllegalPara(opt);
  1733. end;
  1734. 's' :
  1735. begin
  1736. if UnsetBool(More, 0, opt, false) then
  1737. begin
  1738. init_settings.globalswitches:=init_settings.globalswitches-[cs_asm_extern,cs_link_extern,cs_link_nolink];
  1739. if more<>'' then
  1740. IllegalPara(opt);
  1741. end
  1742. else
  1743. begin
  1744. init_settings.globalswitches:=init_settings.globalswitches+[cs_asm_extern,cs_link_extern,cs_link_nolink];
  1745. if more='h' then
  1746. init_settings.globalswitches:=init_settings.globalswitches-[cs_link_on_target]
  1747. else if more='t' then
  1748. init_settings.globalswitches:=init_settings.globalswitches+[cs_link_on_target]
  1749. else if more='r' then
  1750. init_settings.globalswitches:=init_settings.globalswitches+[cs_asm_leave,cs_no_regalloc]
  1751. else if more<>'' then
  1752. IllegalPara(opt);
  1753. end;
  1754. end;
  1755. 'S' :
  1756. begin
  1757. if more='' then
  1758. IllegalPara(opt);
  1759. if more[1]='I' then
  1760. begin
  1761. {$ifdef jvm}
  1762. UnsupportedPara('-SI');
  1763. {$endif}
  1764. if upper(more)='ICOM' then
  1765. init_settings.interfacetype:=it_interfacecom
  1766. else if upper(more)='ICORBA' then
  1767. init_settings.interfacetype:=it_interfacecorba
  1768. else
  1769. IllegalPara(opt);
  1770. end
  1771. else
  1772. begin
  1773. j:=1;
  1774. while j<=length(more) do
  1775. begin
  1776. case more[j] of
  1777. '2' : //an alternative to -Mobjfpc
  1778. SetCompileMode('OBJFPC',true);
  1779. 'a' :
  1780. If UnsetBool(More, j, opt, false) then
  1781. exclude(init_settings.localswitches,cs_do_assertion)
  1782. else
  1783. include(init_settings.localswitches,cs_do_assertion);
  1784. 'c' :
  1785. If UnsetBool(More, j, opt, false) then
  1786. exclude(init_settings.moduleswitches,cs_support_c_operators)
  1787. else
  1788. include(init_settings.moduleswitches,cs_support_c_operators);
  1789. 'd' : //an alternative to -Mdelphi
  1790. SetCompileMode('DELPHI',true);
  1791. 'e' :
  1792. begin
  1793. SetErrorFlags(copy(more,j+1,length(more)));
  1794. break;
  1795. end;
  1796. 'f' :
  1797. begin
  1798. inc(j);
  1799. if more[j]='-' then
  1800. begin
  1801. features:=[];
  1802. if length(more)>j then
  1803. IllegalPara(opt);
  1804. end
  1805. else
  1806. begin
  1807. if (IncludeFeature(upper(copy(more,j,length(more)-j+1)))) then
  1808. j:=length(more)
  1809. else
  1810. IllegalPara(opt);
  1811. end;
  1812. end;
  1813. 'g' :
  1814. If UnsetBool(More, j, opt, false) then
  1815. exclude(init_settings.moduleswitches,cs_support_goto)
  1816. else
  1817. include(init_settings.moduleswitches,cs_support_goto);
  1818. 'h' :
  1819. If UnsetBool(More, j, opt, false) then
  1820. exclude(init_settings.localswitches,cs_refcountedstrings)
  1821. else
  1822. include(init_settings.localswitches,cs_refcountedstrings);
  1823. 'i' :
  1824. If UnsetBool(More, j, opt, false) then
  1825. exclude(init_settings.localswitches,cs_do_inline)
  1826. else
  1827. include(init_settings.localswitches,cs_do_inline);
  1828. 'k' :
  1829. If UnsetBool(More, j, opt, false) then
  1830. exclude(init_settings.globalswitches,cs_load_fpcylix_unit)
  1831. else
  1832. include(init_settings.globalswitches,cs_load_fpcylix_unit);
  1833. 'm' :
  1834. If UnsetBool(More, j, opt, false) then
  1835. exclude(init_settings.moduleswitches,cs_support_macro)
  1836. else
  1837. include(init_settings.moduleswitches,cs_support_macro);
  1838. 'o' : //an alternative to -Mtp
  1839. SetCompileMode('TP',true);
  1840. {$ifdef gpc_mode}
  1841. 'p' : //an alternative to -Mgpc
  1842. SetCompileMode('GPC',true);
  1843. {$endif}
  1844. 's' :
  1845. If UnsetBool(More, j, opt, false) then
  1846. exclude(init_settings.globalswitches,cs_constructor_name)
  1847. else
  1848. include(init_settings.globalswitches,cs_constructor_name);
  1849. 't' :
  1850. Message1(option_obsolete_switch,'-St');
  1851. 'v' :
  1852. If UnsetBool(More, j, opt, false) then
  1853. exclude(init_settings.globalswitches,cs_support_vectors)
  1854. else
  1855. include(init_settings.globalswitches,cs_support_vectors);
  1856. 'x' :
  1857. If UnsetBool(More, j, opt, false) then
  1858. SetCompileModeSwitch('EXCEPTIONS-',true)
  1859. else
  1860. SetCompileModeSwitch('EXCEPTIONS',true);
  1861. 'y' :
  1862. If UnsetBool(More, j, opt, false) then
  1863. exclude(init_settings.localswitches,cs_typed_addresses)
  1864. else
  1865. include(init_settings.localswitches,cs_typed_addresses);
  1866. '-' :
  1867. begin
  1868. init_settings.globalswitches:=init_settings.globalswitches - [cs_constructor_name,cs_support_exceptions,
  1869. cs_support_vectors,cs_load_fpcylix_unit];
  1870. init_settings.localswitches:=init_settings.localswitches - [cs_do_assertion,cs_do_inline, cs_refcountedstrings,
  1871. cs_typed_addresses];
  1872. init_settings.moduleswitches:=init_settings.moduleswitches - [cs_support_c_operators, cs_support_goto,
  1873. cs_support_macro];
  1874. end;
  1875. else
  1876. IllegalPara(opt);
  1877. end;
  1878. inc(j);
  1879. end;
  1880. end;
  1881. end;
  1882. 'T' :
  1883. begin
  1884. more:=Upper(More);
  1885. if paratarget=system_none then
  1886. begin
  1887. { remove old target define }
  1888. TargetOptions(false);
  1889. { load new target }
  1890. paratarget:=find_system_by_string(More);
  1891. if paratarget<>system_none then
  1892. set_target(paratarget)
  1893. else
  1894. IllegalPara(opt);
  1895. { set new define }
  1896. TargetOptions(true);
  1897. end
  1898. else
  1899. if More<>upper(target_info.shortname) then
  1900. Message1(option_target_is_already_set,target_info.shortname);
  1901. end;
  1902. 'u' :
  1903. if is_identifier(more) then
  1904. undef_system_macro(more)
  1905. else
  1906. begin
  1907. if (more='') then
  1908. Message1(option_missing_arg,'-u')
  1909. else
  1910. Message1(option_malformed_para,opt);
  1911. StopOptions(1);
  1912. end;
  1913. 'U' :
  1914. begin
  1915. j:=1;
  1916. while j<=length(more) do
  1917. begin
  1918. case more[j] of
  1919. {$ifdef UNITALIASES}
  1920. 'a' :
  1921. begin
  1922. AddUnitAlias(Copy(More,j+1,255));
  1923. break;
  1924. end;
  1925. {$endif UNITALIASES}
  1926. 'n' :
  1927. exclude(init_settings.globalswitches,cs_check_unit_name);
  1928. 'p' :
  1929. begin
  1930. Message2(option_obsolete_switch_use_new,'-Up','-Fu');
  1931. break;
  1932. end;
  1933. 'r' :
  1934. do_release:=true;
  1935. 's' :
  1936. include(init_settings.moduleswitches,cs_compilesystem);
  1937. '-' :
  1938. begin
  1939. exclude(init_settings.moduleswitches,cs_compilesystem);
  1940. exclude(init_settings.globalswitches,cs_check_unit_name);
  1941. end;
  1942. else
  1943. IllegalPara(opt);
  1944. end;
  1945. inc(j);
  1946. end;
  1947. end;
  1948. 'v' :
  1949. begin
  1950. if not setverbosity(More) then
  1951. IllegalPara(opt);
  1952. end;
  1953. 'V' : ; { Ignore used by fpc }
  1954. 'W' :
  1955. begin
  1956. j:=1;
  1957. while j<=length(More) do
  1958. begin
  1959. case More[j] of
  1960. 'A':
  1961. begin
  1962. if target_info.system in systems_all_windows then
  1963. begin
  1964. if UnsetBool(More, j, opt, false) then
  1965. SetApptype(app_cui)
  1966. else
  1967. SetApptype(app_native);
  1968. end
  1969. else
  1970. IllegalPara(opt);
  1971. end;
  1972. 'b':
  1973. begin
  1974. if target_info.system in systems_darwin then
  1975. begin
  1976. if UnsetBool(More, j, opt, false) then
  1977. SetApptype(app_cui)
  1978. else
  1979. SetApptype(app_bundle)
  1980. end
  1981. else
  1982. IllegalPara(opt);
  1983. end;
  1984. 'B':
  1985. begin
  1986. if target_info.system in systems_all_windows+systems_symbian then
  1987. begin
  1988. { -WB200000 means set trefered base address
  1989. to $200000, but does not change relocsection boolean
  1990. this way we can create both relocatble and
  1991. non relocatable DLL at a specific base address PM }
  1992. if (length(More)>j) then
  1993. begin
  1994. val('$'+Copy(More,j+1,255),imagebase,code);
  1995. if code<>0 then
  1996. IllegalPara(opt);
  1997. ImageBaseSetExplicity:=true;
  1998. end
  1999. else
  2000. begin
  2001. RelocSection:=true;
  2002. RelocSectionSetExplicitly:=true;
  2003. end;
  2004. break;
  2005. end
  2006. else
  2007. IllegalPara(opt);
  2008. end;
  2009. 'C':
  2010. begin
  2011. if target_info.system in systems_all_windows+systems_os2+systems_macos then
  2012. begin
  2013. if UnsetBool(More, j, opt, false) then
  2014. SetApptype(app_gui)
  2015. else
  2016. SetApptype(app_cui);
  2017. end
  2018. else
  2019. IllegalPara(opt);
  2020. end;
  2021. 'D':
  2022. begin
  2023. if target_info.system in systems_all_windows then
  2024. begin
  2025. UseDeffileForExports:=not UnsetBool(More, j, opt, false);
  2026. UseDeffileForExportsSetExplicitly:=true;
  2027. end
  2028. else
  2029. IllegalPara(opt);
  2030. end;
  2031. 'e':
  2032. begin
  2033. if (target_info.system in systems_darwin) then
  2034. begin
  2035. RegisterRes(res_macosx_ext_info,TWinLikeResourceFile);
  2036. set_target_res(res_ext);
  2037. target_info.resobjext:='.fpcres';
  2038. end
  2039. else
  2040. IllegalPara(opt);
  2041. end;
  2042. 'F':
  2043. begin
  2044. if target_info.system in systems_os2 then
  2045. begin
  2046. if UnsetBool(More, j, opt, false) then
  2047. SetApptype(app_cui)
  2048. else
  2049. SetApptype(app_fs);
  2050. end
  2051. else
  2052. IllegalPara(opt);
  2053. end;
  2054. 'G':
  2055. begin
  2056. if target_info.system in systems_all_windows+systems_os2+systems_macos then
  2057. begin
  2058. if UnsetBool(More, j, opt, false) then
  2059. SetApptype(app_cui)
  2060. else
  2061. SetApptype(app_gui);
  2062. end
  2063. else
  2064. IllegalPara(opt);
  2065. end;
  2066. 'I':
  2067. begin
  2068. if target_info.system in systems_all_windows then
  2069. begin
  2070. GenerateImportSection:=not UnsetBool(More,j,opt,false);
  2071. GenerateImportSectionSetExplicitly:=true;
  2072. end
  2073. else
  2074. IllegalPara(opt);
  2075. end;
  2076. 'i':
  2077. begin
  2078. if (target_info.system in systems_darwin) then
  2079. begin
  2080. set_target_res(res_macho);
  2081. target_info.resobjext:=
  2082. targetinfos[target_info.system]^.resobjext;
  2083. end
  2084. else
  2085. IllegalPara(opt);
  2086. end;
  2087. 'm':
  2088. begin
  2089. {$if defined(i8086)}
  2090. if (target_info.system in [system_i8086_msdos]) then
  2091. begin
  2092. case Upper(Copy(More,j+1,255)) of
  2093. 'TINY': init_settings.x86memorymodel:=mm_tiny;
  2094. 'SMALL': init_settings.x86memorymodel:=mm_small;
  2095. 'MEDIUM': init_settings.x86memorymodel:=mm_medium;
  2096. 'COMPACT': init_settings.x86memorymodel:=mm_compact;
  2097. 'LARGE': init_settings.x86memorymodel:=mm_large;
  2098. 'HUGE': IllegalPara(opt); { these are not implemented yet }
  2099. else
  2100. IllegalPara(opt);
  2101. end;
  2102. break;
  2103. end
  2104. else
  2105. {$endif defined(i8086)}
  2106. IllegalPara(opt);
  2107. end;
  2108. 'M':
  2109. begin
  2110. if (target_info.system in (systems_darwin-[system_i386_iphonesim,system_arm_darwin,system_aarch64_darwin])) and
  2111. ParseMacVersionMin(MacOSXVersionMin,iPhoneOSVersionMin,'MAC_OS_X_VERSION_MIN_REQUIRED',copy(More,2,255),false) then
  2112. begin
  2113. break;
  2114. end
  2115. else
  2116. IllegalPara(opt);
  2117. end;
  2118. 'N':
  2119. begin
  2120. if target_info.system in systems_all_windows then
  2121. begin
  2122. RelocSection:=UnsetBool(More,j,opt,false);
  2123. RelocSectionSetExplicitly:=true;
  2124. end
  2125. else
  2126. IllegalPara(opt);
  2127. end;
  2128. 'p':
  2129. begin
  2130. if (target_info.system in systems_embedded) and
  2131. ControllerSupport then
  2132. begin
  2133. s:=upper(copy(more,j+1,length(more)-j));
  2134. if not(SetControllerType(s,init_settings.controllertype)) then
  2135. IllegalPara(opt);
  2136. break;
  2137. end
  2138. else
  2139. IllegalPara(opt);
  2140. end;
  2141. 'P':
  2142. begin
  2143. if (target_info.system in [system_i386_iphonesim,system_arm_darwin,system_aarch64_darwin]) and
  2144. ParseMacVersionMin(iPhoneOSVersionMin,MacOSXVersionMin,'IPHONE_OS_VERSION_MIN_REQUIRED',copy(More,2,255),true) then
  2145. begin
  2146. break;
  2147. end
  2148. else
  2149. IllegalPara(opt);
  2150. end;
  2151. 'R':
  2152. begin
  2153. if target_info.system in systems_all_windows then
  2154. begin
  2155. { support -WR+ / -WR- as synonyms to -WR / -WN }
  2156. RelocSection:=not UnsetBool(More,j,opt,false);
  2157. RelocSectionSetExplicitly:=true;
  2158. end
  2159. else
  2160. IllegalPara(opt);
  2161. end;
  2162. 't':
  2163. begin
  2164. {$if defined(i8086)}
  2165. if (target_info.system in [system_i8086_msdos]) then
  2166. begin
  2167. case Upper(Copy(More,j+1,255)) of
  2168. 'EXE': SetAppType(app_cui);
  2169. 'COM': SetAppType(app_com);
  2170. else
  2171. IllegalPara(opt);
  2172. end;
  2173. break;
  2174. end
  2175. else
  2176. {$endif defined(i8086)}
  2177. IllegalPara(opt);
  2178. end;
  2179. 'T':
  2180. begin
  2181. if target_info.system in systems_macos then
  2182. begin
  2183. if UnsetBool(More, j, opt, false) then
  2184. SetApptype(app_cui)
  2185. else
  2186. SetApptype(app_tool);
  2187. end
  2188. else
  2189. IllegalPara(opt);
  2190. end;
  2191. 'X':
  2192. begin
  2193. if (target_info.system in systems_linux) then
  2194. begin
  2195. if UnsetBool(More, j, opt, false) then
  2196. exclude(init_settings.moduleswitches,cs_executable_stack)
  2197. else
  2198. include(init_settings.moduleswitches,cs_executable_stack)
  2199. end
  2200. else
  2201. IllegalPara(opt);
  2202. end;
  2203. else
  2204. IllegalPara(opt);
  2205. end;
  2206. inc(j);
  2207. end;
  2208. end;
  2209. 'X' :
  2210. begin
  2211. j:=1;
  2212. while j<=length(more) do
  2213. begin
  2214. case More[j] of
  2215. 'c' : Cshared:=TRUE;
  2216. 'd' : Dontlinkstdlibpath:=TRUE;
  2217. 'e' :
  2218. begin
  2219. If UnsetBool(More, j, opt, false) then
  2220. exclude(init_settings.globalswitches,cs_link_extern)
  2221. else
  2222. include(init_settings.globalswitches,cs_link_extern);
  2223. end;
  2224. 'f' :
  2225. include(init_settings.globalswitches,cs_link_pthread);
  2226. 'g' :
  2227. begin
  2228. If UnsetBool(More, j, opt, false) then
  2229. exclude(init_settings.globalswitches,cs_link_separate_dbg_file)
  2230. else
  2231. include(init_settings.globalswitches,cs_link_separate_dbg_file);
  2232. end;
  2233. 'i' :
  2234. begin
  2235. If UnsetBool(More, j, opt, false) then
  2236. include(init_settings.globalswitches,cs_link_extern)
  2237. else
  2238. exclude(init_settings.globalswitches,cs_link_extern);
  2239. end;
  2240. 'n' :
  2241. begin
  2242. If UnsetBool(More, j, opt, false) then
  2243. exclude(init_settings.globalswitches,cs_link_native)
  2244. else
  2245. include(init_settings.globalswitches,cs_link_native);
  2246. end;
  2247. 'm' :
  2248. begin
  2249. If UnsetBool(More, j, opt, false) then
  2250. exclude(init_settings.globalswitches,cs_link_map)
  2251. else
  2252. include(init_settings.globalswitches,cs_link_map);
  2253. end;
  2254. 'p' : ; { Ignore used by fpc.pp }
  2255. 'r' :
  2256. begin
  2257. if (target_info.system in suppported_targets_x_smallr) then
  2258. begin
  2259. rlinkpath:=Copy(more,2,length(More)-1);
  2260. DefaultReplacements(rlinkpath);
  2261. end
  2262. else
  2263. IgnoredPara('-Xr');
  2264. more:='';
  2265. end;
  2266. 'R' :
  2267. begin
  2268. sysrootpath:=copy(more,2,length(more)-1);
  2269. defaultreplacements(sysrootpath);
  2270. more:='';
  2271. end;
  2272. 's' :
  2273. begin
  2274. If UnsetBool(More, j, opt, false) then
  2275. exclude(init_settings.globalswitches,cs_link_strip)
  2276. else
  2277. include(init_settings.globalswitches,cs_link_strip);
  2278. end;
  2279. 't' :
  2280. include(init_settings.globalswitches,cs_link_staticflag);
  2281. 'v' :
  2282. begin
  2283. If UnsetBool(More, j, opt, false) then
  2284. exclude(init_settings.globalswitches,cs_link_opt_vtable)
  2285. else
  2286. include(init_settings.globalswitches,cs_link_opt_vtable);
  2287. end;
  2288. 'D' :
  2289. begin
  2290. def_system_macro('FPC_LINK_DYNAMIC');
  2291. undef_system_macro('FPC_LINK_SMART');
  2292. undef_system_macro('FPC_LINK_STATIC');
  2293. exclude(init_settings.globalswitches,cs_link_static);
  2294. exclude(init_settings.globalswitches,cs_link_smart);
  2295. include(init_settings.globalswitches,cs_link_shared);
  2296. LinkTypeSetExplicitly:=true;
  2297. end;
  2298. 'M' :
  2299. begin
  2300. mainaliasname:=Copy(more,2,length(More)-1);
  2301. More:='';
  2302. end;
  2303. 'P' :
  2304. begin
  2305. utilsprefix:=Copy(more,2,length(More)-1);
  2306. DefaultReplacements(utilsprefix);
  2307. More:='';
  2308. end;
  2309. 'L' : begin // -XLO is link order -XLA is link alias. -XLD avoids load defaults.
  2310. // these are not aggregable.
  2311. if (j=length(more)) or not (more[j+1] in ['O','A','D']) then
  2312. IllegalPara(opt)
  2313. else
  2314. begin
  2315. case more[j+1] of
  2316. 'A' : begin
  2317. s:=Copy(more,3,length(More)-2);
  2318. if not LinkLibraryAliases.AddDep(s) Then
  2319. IllegalPara(opt);
  2320. end;
  2321. 'O' : begin
  2322. s:=Copy(more,3,length(More)-2);
  2323. if not LinkLibraryOrder.AddWeight(s) Then
  2324. IllegalPara(opt);
  2325. end;
  2326. 'D' : include(init_settings.globalswitches,cs_link_no_default_lib_order)
  2327. else
  2328. IllegalPara(opt);
  2329. end; {case}
  2330. j:=length(more);
  2331. end; {else begin}
  2332. end;
  2333. 'S' :
  2334. begin
  2335. ForceStaticLinking;
  2336. end;
  2337. 'X' :
  2338. begin
  2339. def_system_macro('FPC_LINK_SMART');
  2340. undef_system_macro('FPC_LINK_STATIC');
  2341. undef_system_macro('FPC_LINK_DYNAMIC');
  2342. exclude(init_settings.globalswitches,cs_link_static);
  2343. include(init_settings.globalswitches,cs_link_smart);
  2344. exclude(init_settings.globalswitches,cs_link_shared);
  2345. LinkTypeSetExplicitly:=true;
  2346. end;
  2347. '-' :
  2348. begin
  2349. exclude(init_settings.globalswitches,cs_link_staticflag);
  2350. exclude(init_settings.globalswitches,cs_link_strip);
  2351. exclude(init_settings.globalswitches,cs_link_map);
  2352. set_default_link_type;
  2353. end;
  2354. else
  2355. IllegalPara(opt);
  2356. end;
  2357. inc(j);
  2358. end;
  2359. end;
  2360. else
  2361. IllegalPara(opt);
  2362. end;
  2363. end;
  2364. '@' :
  2365. begin
  2366. Message(option_no_nested_response_file);
  2367. StopOptions(1);
  2368. end;
  2369. else
  2370. begin
  2371. if (length(param_file)<>0) then
  2372. Message2(option_only_one_source_support,param_file,opt);
  2373. param_file:=opt;
  2374. Message1(option_found_file,opt);
  2375. end;
  2376. end;
  2377. end;
  2378. procedure Toption.Interpret_file(const filename : TPathStr);
  2379. procedure RemoveSep(var fn:TPathStr);
  2380. var
  2381. i : longint;
  2382. begin
  2383. i:=0;
  2384. while (i<length(fn)) and (fn[i+1] in [',',' ',#9]) do
  2385. inc(i);
  2386. Delete(fn,1,i);
  2387. i:=length(fn);
  2388. while (i>0) and (fn[i] in [',',' ',#9]) do
  2389. dec(i);
  2390. fn:=copy(fn,1,i);
  2391. end;
  2392. function GetName(var fn:TPathStr):TPathStr;
  2393. var
  2394. i : longint;
  2395. begin
  2396. i:=0;
  2397. while (i<length(fn)) and (fn[i+1] in ['a'..'z','A'..'Z','0'..'9','_','-']) do
  2398. inc(i);
  2399. GetName:=Copy(fn,1,i);
  2400. Delete(fn,1,i);
  2401. end;
  2402. const
  2403. maxlevel = 15;
  2404. var
  2405. f : text;
  2406. s, tmp,
  2407. opts : TCmdStr;
  2408. skip : array[0..maxlevel] of boolean;
  2409. line,
  2410. level : longint;
  2411. option_read : boolean;
  2412. oldfilemode : byte;
  2413. ConfigFile: TPathStr;
  2414. begin
  2415. { avoid infinite loop }
  2416. Inc(FileLevel);
  2417. Option_read:=false;
  2418. If FileLevel>MaxLevel then
  2419. Message(option_too_many_cfg_files);
  2420. if not ParaIncludeCfgPath.FindFile(fileName,true,ConfigFile) then
  2421. ConfigFile := ExpandFileName(filename);
  2422. { Maybe It's Directory ?} //Jaro Change:
  2423. if PathExists(ConfigFile,false) then
  2424. begin
  2425. Message1(option_config_is_dir,filename);
  2426. exit;
  2427. end;
  2428. { open file }
  2429. Message1(option_using_file,filename);
  2430. oldfilemode:=filemode;
  2431. filemode:=0;
  2432. assign(f,ConfigFile);
  2433. {$push}{$I-}
  2434. reset(f);
  2435. {$pop}
  2436. filemode:=oldfilemode;
  2437. if ioresult<>0 then
  2438. begin
  2439. Message1(option_unable_open_file,filename);
  2440. exit;
  2441. end;
  2442. Message1(option_start_reading_configfile,filename);
  2443. fillchar(skip,sizeof(skip),0);
  2444. level:=0;
  2445. line:=0;
  2446. while not eof(f) do
  2447. begin
  2448. readln(f,opts);
  2449. inc(line);
  2450. RemoveSep(opts);
  2451. if (opts<>'') and (opts[1]<>';') then
  2452. begin
  2453. if opts[1]='#' then
  2454. begin
  2455. Message1(option_interpreting_file_option,opts);
  2456. Delete(opts,1,1);
  2457. s:=upper(GetName(opts));
  2458. if (s='SECTION') then
  2459. begin
  2460. RemoveSep(opts);
  2461. s:=upper(GetName(opts));
  2462. if level=0 then
  2463. skip[level]:=not defined_macro(s) or (s='COMMON');
  2464. end
  2465. else
  2466. if (s='IFDEF') then
  2467. begin
  2468. RemoveSep(opts);
  2469. if Level>=maxlevel then
  2470. begin
  2471. Message2(option_too_many_ifdef,filename,tostr(line));
  2472. stopOptions(1);
  2473. end;
  2474. inc(Level);
  2475. skip[level]:=(skip[level-1] or not defined_macro(upper(GetName(opts))));
  2476. end
  2477. else
  2478. if (s='IFNDEF') then
  2479. begin
  2480. RemoveSep(opts);
  2481. if Level>=maxlevel then
  2482. begin
  2483. Message2(option_too_many_ifdef,filename,tostr(line));
  2484. stopOptions(1);
  2485. end;
  2486. inc(Level);
  2487. skip[level]:=(skip[level-1] or defined_macro(upper(GetName(opts))));
  2488. end
  2489. else
  2490. if (s='ELSE') then
  2491. begin
  2492. if Level=0 then
  2493. begin
  2494. Message2(option_else_without_if,filename,tostr(line));
  2495. stopOptions(1);
  2496. end
  2497. else
  2498. skip[level]:=skip[level-1] or (not skip[level])
  2499. end
  2500. else
  2501. if (s='ENDIF') then
  2502. begin
  2503. skip[level]:=false;
  2504. if Level=0 then
  2505. begin
  2506. Message2(option_too_many_endif,filename,tostr(line));
  2507. stopOptions(1);
  2508. end;
  2509. dec(level);
  2510. end
  2511. else
  2512. if (not skip[level]) then
  2513. begin
  2514. if (s='DEFINE') then
  2515. begin
  2516. RemoveSep(opts);
  2517. tmp:= GetName(opts);
  2518. if tmp <> '' then
  2519. def_system_macro(tmp);
  2520. Option_read:=true;
  2521. end
  2522. else
  2523. if (s='UNDEF') then
  2524. begin
  2525. RemoveSep(opts);
  2526. tmp:= GetName(opts);
  2527. if tmp <> '' then
  2528. undef_system_macro(tmp);
  2529. Option_read:=true;
  2530. end
  2531. else
  2532. if (s='WRITE') then
  2533. begin
  2534. Delete(opts,1,1);
  2535. WriteLn(opts);
  2536. Option_read:=true;
  2537. end
  2538. else
  2539. if (s='INCLUDE') then
  2540. begin
  2541. Delete(opts,1,1);
  2542. Interpret_file(opts);
  2543. Option_read:=true;
  2544. end
  2545. else
  2546. if (s='CFGDIR') then
  2547. begin
  2548. Delete(opts,1,1);
  2549. DefaultReplacements(opts);
  2550. ParaIncludeCfgPath.AddPath(opts,false);
  2551. Option_read:=true;
  2552. end;
  2553. end;
  2554. end
  2555. else
  2556. begin
  2557. if (opts[1]='-') or (opts[1]='@') then
  2558. begin
  2559. if (not skip[level]) then
  2560. interpret_option(opts,false);
  2561. Option_read:=true;
  2562. end
  2563. else
  2564. Message1(option_illegal_para,opts);
  2565. end;
  2566. end;
  2567. end;
  2568. if Level>0 then
  2569. Message(option_too_less_endif);
  2570. if Not Option_read then
  2571. Message1(option_no_option_found,filename)
  2572. else
  2573. Message1(option_end_reading_configfile,filename);
  2574. Close(f);
  2575. Dec(FileLevel);
  2576. end;
  2577. procedure Toption.Interpret_envvar(const envname : TCmdStr);
  2578. var
  2579. argstart,
  2580. env,
  2581. pc : pchar;
  2582. arglen : longint;
  2583. quote : set of char;
  2584. hs : TCmdStr;
  2585. begin
  2586. Message1(option_using_env,envname);
  2587. env:=GetEnvPChar(envname);
  2588. pc:=env;
  2589. if assigned(pc) then
  2590. begin
  2591. repeat
  2592. { skip leading spaces }
  2593. while pc^ in [' ',#9,#13] do
  2594. inc(pc);
  2595. case pc^ of
  2596. #0 :
  2597. break;
  2598. '"' :
  2599. begin
  2600. quote:=['"'];
  2601. inc(pc);
  2602. end;
  2603. '''' :
  2604. begin
  2605. quote:=[''''];
  2606. inc(pc);
  2607. end;
  2608. else
  2609. quote:=[' ',#9,#13];
  2610. end;
  2611. { scan until the end of the argument }
  2612. argstart:=pc;
  2613. while (pc^<>#0) and not(pc^ in quote) do
  2614. inc(pc);
  2615. { create argument }
  2616. arglen:=pc-argstart;
  2617. { TODO: FIXME: silent truncation of environment parameters }
  2618. if (arglen > 255) then
  2619. arglen := 255;
  2620. setlength(hs,arglen);
  2621. move(argstart^,hs[1],arglen);
  2622. interpret_option(hs,true);
  2623. { skip quote }
  2624. if pc^ in quote then
  2625. inc(pc);
  2626. until false;
  2627. end
  2628. else
  2629. Message1(option_no_option_found,'(env) '+envname);
  2630. FreeEnvPChar(env);
  2631. end;
  2632. procedure toption.read_parameters;
  2633. var
  2634. opts : TCmdStr;
  2635. paramindex : longint;
  2636. begin
  2637. paramindex:=0;
  2638. while paramindex<paramcount do
  2639. begin
  2640. inc(paramindex);
  2641. opts:=objpas.paramstr(paramindex);
  2642. if length(opts)>0 then
  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. else
  2659. interpret_option(opts,true);
  2660. end;
  2661. end;
  2662. end;
  2663. procedure toption.parsecmd(cmd:TCmdStr);
  2664. var
  2665. i,ps : longint;
  2666. opts : TCmdStr;
  2667. begin
  2668. while (cmd<>'') do
  2669. begin
  2670. while cmd[1]=' ' do
  2671. delete(cmd,1,1);
  2672. i:=pos(' ',cmd);
  2673. if i=0 then
  2674. i:=2147483647;
  2675. opts:=Copy(cmd,1,i-1);
  2676. Delete(cmd,1,i);
  2677. case opts[1] of
  2678. '@' :
  2679. if not firstpass then
  2680. begin
  2681. Delete(opts,1,1);
  2682. Message1(option_reading_further_from,opts);
  2683. interpret_file(opts);
  2684. end;
  2685. '!' :
  2686. if not firstpass then
  2687. begin
  2688. Delete(opts,1,1);
  2689. Message1(option_reading_further_from,'(env) '+opts);
  2690. interpret_envvar(opts);
  2691. end;
  2692. '"' :
  2693. begin
  2694. Delete(opts,1,1);
  2695. ps:=pos('"',cmd);
  2696. if (i<>256) and (ps>0) then
  2697. begin
  2698. opts:=opts + ' '+ copy(cmd,1,ps-1);
  2699. cmd:=copy(cmd,ps+1,255);
  2700. end;
  2701. interpret_option(opts,true);
  2702. end;
  2703. else
  2704. interpret_option(opts,true);
  2705. end;
  2706. end;
  2707. end;
  2708. procedure toption.writequickinfo;
  2709. var
  2710. s : string;
  2711. i : longint;
  2712. procedure addinfo(const hs:string);
  2713. begin
  2714. if s<>'' then
  2715. s:=s+' '+hs
  2716. else
  2717. s:=hs;
  2718. end;
  2719. begin
  2720. s:='';
  2721. i:=0;
  2722. while (i<length(quickinfo)) do
  2723. begin
  2724. inc(i);
  2725. case quickinfo[i] of
  2726. 'S' :
  2727. begin
  2728. inc(i);
  2729. case quickinfo[i] of
  2730. 'O' :
  2731. addinfo(lower(source_info.shortname));
  2732. 'P' :
  2733. addinfo(source_cpu_string);
  2734. else
  2735. IllegalPara('-i'+QuickInfo);
  2736. end;
  2737. end;
  2738. 'T' :
  2739. begin
  2740. inc(i);
  2741. case quickinfo[i] of
  2742. 'O' :
  2743. addinfo(lower(target_info.shortname));
  2744. 'P' :
  2745. AddInfo(target_cpu_string);
  2746. else
  2747. IllegalPara('-i'+QuickInfo);
  2748. end;
  2749. end;
  2750. 'V' :
  2751. AddInfo(version_string);
  2752. 'W' :
  2753. AddInfo(full_version_string);
  2754. 'D' :
  2755. AddInfo(date_string);
  2756. '_' :
  2757. ;
  2758. else
  2759. IllegalPara('-i'+QuickInfo);
  2760. end;
  2761. end;
  2762. if s<>'' then
  2763. begin
  2764. writeln(s);
  2765. stopoptions(0);
  2766. end;
  2767. end;
  2768. procedure TOption.TargetOptions(def:boolean);
  2769. var
  2770. s : string;
  2771. i : integer;
  2772. target_unsup_features : tfeatures;
  2773. begin
  2774. if def then
  2775. def_system_macro(target_info.shortname)
  2776. else
  2777. undef_system_macro(target_info.shortname);
  2778. s:=target_info.extradefines;
  2779. while (s<>'') do
  2780. begin
  2781. i:=pos(';',s);
  2782. if i=0 then
  2783. i:=length(s)+1;
  2784. if def then
  2785. def_system_macro(Copy(s,1,i-1))
  2786. else
  2787. undef_system_macro(Copy(s,1,i-1));
  2788. delete(s,1,i);
  2789. end;
  2790. if (tf_winlikewidestring in target_info.flags) then
  2791. if def then
  2792. def_system_macro('FPC_WINLIKEWIDESTRING')
  2793. else
  2794. undef_system_macro('FPC_WINLIKEWIDESTRING');
  2795. if (tf_requires_proper_alignment in target_info.flags) then
  2796. if def then
  2797. def_system_macro('FPC_REQUIRES_PROPER_ALIGNMENT')
  2798. else
  2799. undef_system_macro('FPC_REQUIRES_PROPER_ALIGNMENT');
  2800. if source_info.system<>target_info.system then
  2801. if def then
  2802. def_system_macro('FPC_CROSSCOMPILING')
  2803. else
  2804. undef_system_macro('FPC_CROSSCOMPILING');
  2805. if source_info.cpu<>target_info.cpu then
  2806. if def then
  2807. def_system_macro('FPC_CPUCROSSCOMPILING')
  2808. else
  2809. def_system_macro('FPC_CPUCROSSCOMPILING');
  2810. if (tf_no_generic_stackcheck in target_info.flags) then
  2811. if def then
  2812. def_system_macro('FPC_NO_GENERIC_STACK_CHECK')
  2813. else
  2814. undef_system_macro('FPC_NO_GENERIC_STACK_CHECK');
  2815. if (tf_section_threadvars in target_info.flags) then
  2816. if def then
  2817. def_system_macro('FPC_SECTION_THREADVARS')
  2818. else
  2819. undef_system_macro('FPC_SECTION_THREADVARS');
  2820. { Code generation flags }
  2821. if (tf_pic_default in target_info.flags) then
  2822. if def then
  2823. include(init_settings.moduleswitches,cs_create_pic)
  2824. else
  2825. exclude(init_settings.moduleswitches,cs_create_pic);
  2826. { Resources support }
  2827. if (tf_has_winlike_resources in target_info.flags) then
  2828. if def then
  2829. def_system_macro('FPC_HAS_WINLIKERESOURCES')
  2830. else
  2831. undef_system_macro('FPC_HAS_WINLIKERESOURCES');
  2832. { Features }
  2833. case target_info.system of
  2834. system_arm_gba:
  2835. target_unsup_features:=[f_dynlibs];
  2836. system_arm_nds:
  2837. target_unsup_features:=[f_threading,f_commandargs,f_fileio,f_textio,f_consoleio,f_dynlibs];
  2838. system_i386_nativent:
  2839. // until these features are implemented, they are disabled in the compiler
  2840. target_unsup_features:=[f_stackcheck];
  2841. system_jvm_java32,
  2842. system_jvm_android32:
  2843. target_unsup_features:=[f_heap,f_textio,f_consoleio,f_fileio,
  2844. f_variants,f_objects,f_commandargs,
  2845. f_processes,f_stackcheck,f_dynlibs,f_softfpu,f_objectivec1,f_resources];
  2846. else
  2847. target_unsup_features:=[];
  2848. end;
  2849. if def then
  2850. features:=features-target_unsup_features
  2851. else
  2852. features:=features+target_unsup_features;
  2853. end;
  2854. procedure TOption.checkoptionscompatibility;
  2855. begin
  2856. {$ifdef i8086}
  2857. if (apptype=app_com) and (init_settings.x86memorymodel<>mm_tiny) then
  2858. begin
  2859. Message(option_com_files_require_tiny_model);
  2860. StopOptions(1);
  2861. end;
  2862. {$endif i8086}
  2863. if (paratargetdbg in [dbg_dwarf2,dbg_dwarf3]) and
  2864. not(target_info.system in (systems_darwin+[system_i8086_msdos])) then
  2865. begin
  2866. { smartlink creation does not yet work with DWARF
  2867. debug info on most targets, but it works in internal assembler }
  2868. if (cs_create_smart in init_settings.moduleswitches) and
  2869. not (af_outputbinary in target_asm.flags) then
  2870. begin
  2871. Message(option_dwarf_smartlink_creation);
  2872. exclude(init_settings.moduleswitches,cs_create_smart);
  2873. end;
  2874. { smart linking does not yet work with DWARF debug info on most targets }
  2875. if (cs_link_smart in init_settings.globalswitches) then
  2876. begin
  2877. Message(option_dwarf_smart_linking);
  2878. ForceStaticLinking;
  2879. end;
  2880. end;
  2881. { external debug info is only supported for DWARF on darwin }
  2882. if (target_info.system in systems_darwin) and
  2883. (cs_link_separate_dbg_file in init_settings.globalswitches) and
  2884. not(paratargetdbg in [dbg_dwarf2,dbg_dwarf3]) then
  2885. begin
  2886. Message(option_debug_external_unsupported);
  2887. exclude(init_settings.globalswitches,cs_link_separate_dbg_file);
  2888. end;
  2889. { Also create a smartlinked version, on an assembler that
  2890. does not support smartlink sections like nasm?
  2891. This is not compatible with using internal linker. }
  2892. if ((cs_link_smart in init_settings.globalswitches) or
  2893. (cs_create_smart in init_settings.moduleswitches)) and
  2894. (af_needar in target_asm.flags) and
  2895. not (af_smartlink_sections in target_asm.flags) and
  2896. not (cs_link_extern in init_settings.globalswitches) and
  2897. (target_info.link<>ld_none) and
  2898. not (cs_link_nolink in init_settings.globalswitches) then
  2899. begin
  2900. Message(option_smart_link_requires_external_linker);
  2901. include(init_settings.globalswitches,cs_link_extern);
  2902. end;
  2903. end;
  2904. constructor TOption.create;
  2905. begin
  2906. LogoWritten:=false;
  2907. NoPressEnter:=false;
  2908. FirstPass:=false;
  2909. FPUSetExplicitly:=false;
  2910. CPUSetExplicitly:=false;
  2911. OptCPUSetExplicitly:=false;
  2912. FileLevel:=0;
  2913. Quickinfo:='';
  2914. ParaIncludeCfgPath:=TSearchPathList.Create;
  2915. ParaIncludePath:=TSearchPathList.Create;
  2916. ParaObjectPath:=TSearchPathList.Create;
  2917. ParaUnitPath:=TSearchPathList.Create;
  2918. ParaLibraryPath:=TSearchPathList.Create;
  2919. ParaFrameworkPath:=TSearchPathList.Create;
  2920. FillChar(ParaAlignment,sizeof(ParaAlignment),0);
  2921. MacVersionSet:=false;
  2922. end;
  2923. destructor TOption.destroy;
  2924. begin
  2925. ParaIncludeCfgPath.Free;
  2926. ParaIncludePath.Free;
  2927. ParaObjectPath.Free;
  2928. ParaUnitPath.Free;
  2929. ParaLibraryPath.Free;
  2930. ParaFrameworkPath.Free;
  2931. end;
  2932. {****************************************************************************
  2933. Callable Routines
  2934. ****************************************************************************}
  2935. function check_configfile(const fn:string;var foundfn:string):boolean;
  2936. function CfgFileExists(const fn:string):boolean;
  2937. begin
  2938. Comment(V_Tried,'Configfile search: '+fn);
  2939. CfgFileExists:=FileExists(fn);
  2940. end;
  2941. var
  2942. {$ifdef Unix}
  2943. hs,
  2944. {$endif Unix}
  2945. configpath : string;
  2946. begin
  2947. foundfn:=fn;
  2948. check_configfile:=true;
  2949. { retrieve configpath }
  2950. configpath:=FixPath(GetEnvironmentVariable('PPC_CONFIG_PATH'),false);
  2951. {$ifdef Unix}
  2952. if configpath='' then
  2953. configpath:=ExpandFileName(FixPath(exepath+'../etc/',false));
  2954. {$endif}
  2955. {
  2956. Order to read configuration file :
  2957. try reading fpc.cfg in :
  2958. 1 - current dir
  2959. 2 - configpath
  2960. 3 - compiler path
  2961. }
  2962. if not FileExists(fn) then
  2963. begin
  2964. {$ifdef Unix}
  2965. hs:=GetEnvironmentVariable('HOME');
  2966. if (hs<>'') and CfgFileExists(FixPath(hs,false)+'.'+fn) then
  2967. foundfn:=FixPath(hs,false)+'.'+fn
  2968. else
  2969. {$endif}
  2970. if CfgFileExists(configpath+fn) then
  2971. foundfn:=configpath+fn
  2972. else
  2973. {$ifdef WINDOWS}
  2974. if (GetEnvironmentVariable('USERPROFILE')<>'') and CfgFileExists(FixPath(GetEnvironmentVariable('USERPROFILE'),false)+fn) then
  2975. foundfn:=FixPath(GetEnvironmentVariable('USERPROFILE'),false)+fn
  2976. else
  2977. if (GetEnvironmentVariable('ALLUSERSPROFILE')<>'') and CfgFileExists(FixPath(GetEnvironmentVariable('ALLUSERSPROFILE'),false)+fn) then
  2978. foundfn:=FixPath(GetEnvironmentVariable('ALLUSERSPROFILE'),false)+fn
  2979. else
  2980. {$endif WINDOWS}
  2981. {$ifndef Unix}
  2982. if CfgFileExists(exepath+fn) then
  2983. foundfn:=exepath+fn
  2984. else
  2985. {$else}
  2986. if CfgFileExists('/etc/'+fn) then
  2987. foundfn:='/etc/'+fn
  2988. else
  2989. {$endif}
  2990. check_configfile:=false;
  2991. end;
  2992. end;
  2993. procedure read_arguments(cmd:TCmdStr);
  2994. var
  2995. env: ansistring;
  2996. i : tfeature;
  2997. abi : tabi;
  2998. {$if defined(cpucapabilities)}
  2999. cpuflag : tcpuflags;
  3000. hs : string;
  3001. {$endif defined(cpucapabilities)}
  3002. begin
  3003. option:=coption.create;
  3004. disable_configfile:=false;
  3005. { Non-core target defines }
  3006. Option.TargetOptions(true);
  3007. { get default messagefile }
  3008. msgfilename:=GetEnvironmentVariable('PPC_ERROR_FILE');
  3009. { default configfile can be specified on the commandline,
  3010. remove it first }
  3011. if (cmd<>'') and (cmd[1]='[') then
  3012. begin
  3013. ppccfg:=Copy(cmd,2,pos(']',cmd)-2);
  3014. Delete(cmd,1,pos(']',cmd));
  3015. end
  3016. else
  3017. ppccfg:='fpc.cfg';
  3018. { first pass reading of parameters, only -i -v -T etc.}
  3019. option.firstpass:=true;
  3020. if cmd<>'' then
  3021. option.parsecmd(cmd)
  3022. else
  3023. begin
  3024. option.read_parameters;
  3025. { Write only quickinfo }
  3026. if option.quickinfo<>'' then
  3027. option.writequickinfo;
  3028. end;
  3029. option.firstpass:=false;
  3030. { redefine target options so all defines are written even if no -Txxx is passed on the command line }
  3031. Option.TargetOptions(true);
  3032. { target is set here, for wince the default app type is gui }
  3033. if target_info.system in systems_wince then
  3034. SetApptype(app_gui)
  3035. else
  3036. SetApptype(apptype);
  3037. { default defines }
  3038. def_system_macro(target_info.shortname);
  3039. def_system_macro('FPC');
  3040. def_system_macro('VER'+version_nr);
  3041. def_system_macro('VER'+version_nr+'_'+release_nr);
  3042. def_system_macro('VER'+version_nr+'_'+release_nr+'_'+patch_nr);
  3043. { Temporary defines, until things settle down }
  3044. def_system_macro('RESSTRSECTIONS');
  3045. def_system_macro('FPC_HASFIXED64BITVARIANT');
  3046. def_system_macro('FPC_HASINTERNALOLEVARIANT2VARIANTCAST');
  3047. def_system_macro('FPC_HAS_VARSETS');
  3048. def_system_macro('FPC_HAS_VALGRINDBOOL');
  3049. def_system_macro('FPC_HAS_STR_CURRENCY');
  3050. def_system_macro('FPC_REAL2REAL_FIXED');
  3051. def_system_macro('FPC_STRTOCHARARRAYPROC');
  3052. def_system_macro('FPC_STRTOSHORTSTRINGPROC');
  3053. def_system_macro('FPC_OBJFPC_EXTENDED_IF');
  3054. def_system_macro('FPC_HAS_OPERATOR_ENUMERATOR');
  3055. def_system_macro('FPC_HAS_CONSTREF');
  3056. def_system_macro('FPC_STATICRIPFIXED');
  3057. def_system_macro('FPC_VARIANTCOPY_FIXED');
  3058. def_system_macro('FPC_DYNARRAYCOPY_FIXED');
  3059. { abs(long) is handled internally on all CPUs }
  3060. def_system_macro('FPC_HAS_INTERNAL_ABS_LONG');
  3061. {$if defined(x86_64) or defined(powerpc64)}
  3062. def_system_macro('FPC_HAS_INTERNAL_ABS_INT64');
  3063. {$endif x86_64 or powerpc64}
  3064. def_system_macro('FPC_HAS_UNICODESTRING');
  3065. def_system_macro('FPC_RTTI_PACKSET1');
  3066. def_system_macro('FPC_HAS_CPSTRING');
  3067. {$ifdef x86_64}
  3068. def_system_macro('FPC_HAS_RIP_RELATIVE');
  3069. {$endif x86_64}
  3070. def_system_macro('FPC_HAS_CEXTENDED');
  3071. def_system_macro('FPC_HAS_RESSTRINITS');
  3072. { these cpus have an inline rol/ror implementaion }
  3073. {$ifdef cpurox}
  3074. def_system_macro('FPC_HAS_INTERNAL_ROX');
  3075. {$endif}
  3076. { these cpus have an inline sar implementaion }
  3077. { currently, all supported CPUs have an internal sar implementation }
  3078. { $if defined(x86) or defined(arm) or defined(powerpc) or defined(powerpc64) or defined(sparc) or defined(mips)}
  3079. def_system_macro('FPC_HAS_INTERNAL_SAR');
  3080. { $endif}
  3081. {$ifdef powerpc64}
  3082. def_system_macro('FPC_HAS_LWSYNC');
  3083. {$endif}
  3084. def_system_macro('FPC_HAS_MEMBAR');
  3085. def_system_macro('FPC_SETBASE_USED');
  3086. {$ifdef SUPPORT_GET_FRAME}
  3087. def_system_macro('INTERNAL_BACKTRACE');
  3088. {$endif SUPPORT_GET_FRAME}
  3089. def_system_macro('STR_CONCAT_PROCS');
  3090. {$warnings off}
  3091. if pocall_default = pocall_register then
  3092. def_system_macro('REGCALL');
  3093. {$warnings on}
  3094. { don't remove this, it's also for fpdoc necessary (FK) }
  3095. def_system_macro('FPC_HAS_FEATURE_SUPPORT');
  3096. { using a case is pretty useless here (FK) }
  3097. { some stuff for TP compatibility }
  3098. {$ifdef i386}
  3099. def_system_macro('CPU86');
  3100. def_system_macro('CPU87');
  3101. def_system_macro('CPU386');
  3102. {$endif}
  3103. { new processor stuff }
  3104. {$ifdef i386}
  3105. def_system_macro('CPUI386');
  3106. def_system_macro('CPU32');
  3107. def_system_macro('CPUX86');
  3108. def_system_macro('FPC_HAS_TYPE_EXTENDED');
  3109. def_system_macro('FPC_HAS_TYPE_DOUBLE');
  3110. def_system_macro('FPC_HAS_TYPE_SINGLE');
  3111. {$endif}
  3112. {$ifdef m68k}
  3113. def_system_macro('CPU68');
  3114. def_system_macro('CPU68K');
  3115. def_system_macro('CPUM68K');
  3116. def_system_macro('CPU32');
  3117. def_system_macro('FPC_CURRENCY_IS_INT64');
  3118. def_system_macro('FPC_COMP_IS_INT64');
  3119. {$endif}
  3120. {$ifdef ALPHA}
  3121. def_system_macro('CPUALPHA');
  3122. def_system_macro('CPU64');
  3123. {$endif}
  3124. {$ifdef powerpc}
  3125. def_system_macro('CPUPOWERPC');
  3126. def_system_macro('CPUPOWERPC32');
  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 POWERPC64}
  3132. def_system_macro('CPUPOWERPC');
  3133. def_system_macro('CPUPOWERPC64');
  3134. def_system_macro('CPU64');
  3135. def_system_macro('FPC_CURRENCY_IS_INT64');
  3136. def_system_macro('FPC_COMP_IS_INT64');
  3137. {$endif}
  3138. {$ifdef iA64}
  3139. def_system_macro('CPUIA64');
  3140. def_system_macro('CPU64');
  3141. {$endif}
  3142. {$ifdef x86_64}
  3143. def_system_macro('CPUX86_64');
  3144. def_system_macro('CPUAMD64');
  3145. def_system_macro('CPU64');
  3146. def_system_macro('CPUX64');
  3147. { not supported for now, afaik (FK)
  3148. def_system_macro('FPC_HAS_TYPE_FLOAT128'); }
  3149. {$ifndef FPC_SUPPORT_X87_TYPES_ON_WIN64}
  3150. { normally, win64 doesn't support the legacy fpu }
  3151. if target_info.system=system_x86_64_win64 then
  3152. begin
  3153. def_system_macro('FPC_CURRENCY_IS_INT64');
  3154. def_system_macro('FPC_COMP_IS_INT64');
  3155. end;
  3156. {$endif FPC_SUPPORT_X87_TYPES_ON_WIN64}
  3157. {$endif}
  3158. {$ifdef sparc}
  3159. def_system_macro('CPUSPARC');
  3160. def_system_macro('CPUSPARC32');
  3161. def_system_macro('CPU32');
  3162. def_system_macro('FPC_CURRENCY_IS_INT64');
  3163. def_system_macro('FPC_COMP_IS_INT64');
  3164. {$endif}
  3165. {$ifdef vis}
  3166. def_system_macro('CPUVIS');
  3167. def_system_macro('CPU32');
  3168. {$endif}
  3169. {$ifdef arm}
  3170. def_system_macro('CPUARM');
  3171. def_system_macro('CPU32');
  3172. def_system_macro('FPC_CURRENCY_IS_INT64');
  3173. def_system_macro('FPC_COMP_IS_INT64');
  3174. {$endif arm}
  3175. {$ifdef avr}
  3176. def_system_macro('CPUAVR');
  3177. def_system_macro('CPU16');
  3178. def_system_macro('FPC_CURRENCY_IS_INT64');
  3179. def_system_macro('FPC_COMP_IS_INT64');
  3180. {$endif avr}
  3181. {$ifdef jvm}
  3182. def_system_macro('CPUJVM');
  3183. def_system_macro('CPU32');
  3184. def_system_macro('FPC_CURRENCY_IS_INT64');
  3185. def_system_macro('FPC_COMP_IS_INT64');
  3186. {$endif jvm}
  3187. {$ifdef mipsel}
  3188. def_system_macro('CPUMIPS');
  3189. def_system_macro('CPUMIPS32');
  3190. def_system_macro('CPUMIPSEL');
  3191. def_system_macro('CPUMIPSEL32');
  3192. def_system_macro('CPU32');
  3193. def_system_macro('FPC_HAS_TYPE_DOUBLE');
  3194. def_system_macro('FPC_HAS_TYPE_SINGLE');
  3195. def_system_macro('FPC_INCLUDE_SOFTWARE_INT64_TO_DOUBLE');
  3196. def_system_macro('FPC_CURRENCY_IS_INT64');
  3197. def_system_macro('FPC_COMP_IS_INT64');
  3198. def_system_macro('FPC_REQUIRES_PROPER_ALIGNMENT');
  3199. { On most systems, locals are accessed relative to base pointer,
  3200. but for MIPS cpu, they are accessed relative to stack pointer.
  3201. This needs adaptation for so low level routines,
  3202. like MethodPointerLocal and related objects unit functions. }
  3203. def_system_macro('FPC_LOCALS_ARE_STACK_REG_RELATIVE');
  3204. {$endif mipsel}
  3205. {$ifdef mipseb}
  3206. def_system_macro('CPUMIPS');
  3207. def_system_macro('CPUMIPS32');
  3208. def_system_macro('CPUMIPSEB');
  3209. def_system_macro('CPUMIPSEB32');
  3210. def_system_macro('CPU32');
  3211. def_system_macro('FPC_HAS_TYPE_DOUBLE');
  3212. def_system_macro('FPC_HAS_TYPE_SINGLE');
  3213. def_system_macro('FPC_INCLUDE_SOFTWARE_INT64_TO_DOUBLE');
  3214. def_system_macro('FPC_CURRENCY_IS_INT64');
  3215. def_system_macro('FPC_COMP_IS_INT64');
  3216. def_system_macro('FPC_REQUIRES_PROPER_ALIGNMENT');
  3217. { See comment above for mipsel }
  3218. def_system_macro('FPC_LOCALS_ARE_STACK_REG_RELATIVE');
  3219. {$endif}
  3220. {$ifdef i8086}
  3221. def_system_macro('CPU86'); { Borland compatibility }
  3222. def_system_macro('CPU87'); { Borland compatibility }
  3223. def_system_macro('CPU8086');
  3224. def_system_macro('CPUI8086');
  3225. def_system_macro('CPU16');
  3226. def_system_macro('FPC_HAS_TYPE_EXTENDED');
  3227. def_system_macro('FPC_HAS_TYPE_DOUBLE');
  3228. def_system_macro('FPC_HAS_TYPE_SINGLE');
  3229. case init_settings.x86memorymodel of
  3230. mm_tiny: def_system_macro('FPC_MM_TINY');
  3231. mm_small: def_system_macro('FPC_MM_SMALL');
  3232. mm_medium: def_system_macro('FPC_MM_MEDIUM');
  3233. mm_compact: def_system_macro('FPC_MM_COMPACT');
  3234. mm_large: def_system_macro('FPC_MM_LARGE');
  3235. mm_huge: def_system_macro('FPC_MM_HUGE');
  3236. end;
  3237. {$endif i8086}
  3238. {$ifdef aarch64}
  3239. def_system_macro('CPUAARCH64');
  3240. def_system_macro('CPU64');
  3241. def_system_macro('FPC_CURRENCY_IS_INT64');
  3242. def_system_macro('FPC_COMP_IS_INT64');
  3243. {$endif aarch64}
  3244. if tf_cld in target_info.flags then
  3245. if not UpdateTargetSwitchStr('CLD', init_settings.targetswitches, true) then
  3246. InternalError(2013092801);
  3247. { Set up a default prefix for binutils when cross-compiling }
  3248. if source_info.system<>target_info.system then
  3249. case target_info.system of
  3250. { Use standard Android NDK prefixes }
  3251. system_arm_android:
  3252. utilsprefix:='arm-linux-androideabi-';
  3253. system_i386_android:
  3254. utilsprefix:='i686-linux-android-';
  3255. system_mipsel_android:
  3256. utilsprefix:='mipsel-linux-android-';
  3257. end;
  3258. { Set up default value for the heap }
  3259. if target_info.system in systems_embedded then
  3260. begin
  3261. case target_info.system of
  3262. system_avr_embedded:
  3263. heapsize:=128;
  3264. system_arm_embedded:
  3265. heapsize:=256;
  3266. system_mipsel_embedded:
  3267. heapsize:=256;
  3268. else
  3269. heapsize:=256;
  3270. end;
  3271. end;
  3272. { read configuration file }
  3273. if (not disable_configfile) and
  3274. (ppccfg<>'') then
  3275. read_configfile:=check_configfile(ppccfg,ppccfg)
  3276. else
  3277. read_configfile := false;
  3278. { Read commandline and configfile }
  3279. param_file:='';
  3280. { read configfile }
  3281. if read_configfile then
  3282. option.interpret_file(ppccfg);
  3283. { read parameters again to override config file }
  3284. if cmd<>'' then
  3285. option.parsecmd(cmd)
  3286. else
  3287. begin
  3288. { Write help pages if no parameters are passed }
  3289. if (paramcount=0) then
  3290. Option.WriteHelpPages;
  3291. option.read_parameters;
  3292. { Write only quickinfo }
  3293. if option.quickinfo<>'' then
  3294. option.writequickinfo;
  3295. end;
  3296. { check the compatibility of different options and adjust them if necessary
  3297. (and print possible errors)
  3298. }
  3299. option.checkoptionscompatibility;
  3300. { Stop if errors in options }
  3301. if ErrorCount>0 then
  3302. StopOptions(1);
  3303. { endian define }
  3304. case target_info.endian of
  3305. endian_little :
  3306. begin
  3307. def_system_macro('ENDIAN_LITTLE');
  3308. def_system_macro('FPC_LITTLE_ENDIAN');
  3309. end;
  3310. endian_big :
  3311. begin
  3312. def_system_macro('ENDIAN_BIG');
  3313. def_system_macro('FPC_BIG_ENDIAN');
  3314. end;
  3315. end;
  3316. { define abi }
  3317. for abi:=low(tabi) to high(tabi) do
  3318. undef_system_macro('FPC_ABI_'+abiinfo[abi].name);
  3319. def_system_macro('FPC_ABI_'+abiinfo[target_info.abi].name);
  3320. { Define FPC_ABI_EABI in addition to FPC_ABI_EABIHF on EABI VFP hardfloat
  3321. systems since most code needs to behave the same on both}
  3322. if target_info.abi = abi_eabihf then
  3323. def_system_macro('FPC_ABI_EABI');
  3324. { Write logo }
  3325. if option.ParaLogo then
  3326. option.writelogo;
  3327. { Check file to compile }
  3328. if param_file='' then
  3329. begin
  3330. Message(option_no_source_found);
  3331. StopOptions(1);
  3332. end;
  3333. {$ifndef Unix}
  3334. param_file:=FixFileName(param_file);
  3335. {$endif not unix}
  3336. inputfilepath:=ExtractFilePath(param_file);
  3337. inputfilename:=ExtractFileName(param_file);
  3338. if ExtractFileExt(inputfilename)='' then
  3339. begin
  3340. if FileExists(inputfilepath+ChangeFileExt(inputfilename,sourceext)) then
  3341. inputfilename:=ChangeFileExt(inputfilename,sourceext)
  3342. else if FileExists(inputfilepath+ChangeFileExt(inputfilename,pasext)) then
  3343. inputfilename:=ChangeFileExt(inputfilename,pasext)
  3344. else if ((m_mac in current_settings.modeswitches) or
  3345. (tf_p_ext_support in target_info.flags))
  3346. and FileExists(inputfilepath+ChangeFileExt(inputfilename,pext)) then
  3347. inputfilename:=ChangeFileExt(inputfilename,pext);
  3348. end;
  3349. { Check output dir }
  3350. if (OutputExeDir<>'') and
  3351. not PathExists(OutputExeDir,false) then
  3352. begin
  3353. Message1(general_e_path_does_not_exist,OutputExeDir);
  3354. StopOptions(1);
  3355. end;
  3356. { Add paths specified with parameters to the searchpaths }
  3357. UnitSearchPath.AddList(option.ParaUnitPath,true);
  3358. ObjectSearchPath.AddList(option.ParaObjectPath,true);
  3359. IncludeSearchPath.AddList(option.ParaIncludePath,true);
  3360. LibrarySearchPath.AddList(option.ParaLibraryPath,true);
  3361. FrameworkSearchPath.AddList(option.ParaFrameworkPath,true);
  3362. { add unit environment and exepath to the unit search path }
  3363. if inputfilepath<>'' then
  3364. Unitsearchpath.AddPath(inputfilepath,true);
  3365. if not disable_configfile then
  3366. begin
  3367. env:=GetEnvironmentVariable(target_info.unit_env);
  3368. if env<>'' then
  3369. UnitSearchPath.AddPath(GetEnvironmentVariable(target_info.unit_env),false);
  3370. end;
  3371. {$ifdef Unix}
  3372. fpcdir:=FixPath(GetEnvironmentVariable('FPCDIR'),false);
  3373. if fpcdir='' then
  3374. begin
  3375. if PathExists('/usr/local/lib/fpc/'+version_string,true) then
  3376. fpcdir:='/usr/local/lib/fpc/'+version_string+'/'
  3377. else
  3378. fpcdir:='/usr/lib/fpc/'+version_string+'/';
  3379. end;
  3380. {$else unix}
  3381. fpcdir:=FixPath(GetEnvironmentVariable('FPCDIR'),false);
  3382. if fpcdir='' then
  3383. begin
  3384. fpcdir:=ExePath+'../';
  3385. if not(PathExists(fpcdir+'units',true)) and
  3386. not(PathExists(fpcdir+'rtl',true)) then
  3387. fpcdir:=fpcdir+'../';
  3388. end;
  3389. {$endif unix}
  3390. { first try development RTL, else use the default installation path }
  3391. if not disable_configfile then
  3392. begin
  3393. if PathExists(FpcDir+'rtl',true) then
  3394. if (tf_use_8_3 in Source_Info.Flags) or
  3395. (tf_use_8_3 in Target_Info.Flags) then
  3396. UnitSearchPath.AddPath(FpcDir+'rtl/'+target_os_string,false)
  3397. else
  3398. UnitSearchPath.AddPath(FpcDir+'rtl/'+target_full_string,false)
  3399. else
  3400. if (tf_use_8_3 in Source_Info.Flags) or
  3401. (tf_use_8_3 in Target_Info.Flags) then
  3402. UnitSearchPath.AddPath(FpcDir+'units/'+target_os_string+'/rtl',false)
  3403. else
  3404. UnitSearchPath.AddPath(FpcDir+'units/'+target_full_string+'/rtl',false);
  3405. end;
  3406. { Add exepath if the exe is not in the current dir, because that is always searched already.
  3407. Do not add it when linking on the target because then we can maybe already find
  3408. .o files that are not for the target }
  3409. if (ExePath<>cfileutl.GetCurrentDir) and
  3410. not(cs_link_on_target in init_settings.globalswitches) then
  3411. UnitSearchPath.AddPath(ExePath,false);
  3412. { Add unit dir to the object and library path }
  3413. objectsearchpath.AddList(unitsearchpath,false);
  3414. librarysearchpath.AddList(unitsearchpath,false);
  3415. { maybe override assembler }
  3416. if (paratargetasm<>as_none) then
  3417. begin
  3418. if not set_target_asm(paratargetasm) then
  3419. begin
  3420. Message2(option_incompatible_asm,asminfos[paratargetasm]^.idtxt,target_info.name);
  3421. set_target_asm(target_info.assemextern);
  3422. Message1(option_asm_forced,target_asm.idtxt);
  3423. end;
  3424. if (af_no_debug in asminfos[paratargetasm]^.flags) and
  3425. (paratargetdbg<>dbg_none) then
  3426. begin
  3427. Message1(option_confict_asm_debug,
  3428. asminfos[paratargetasm]^.idtxt);
  3429. paratargetdbg:=dbg_none;
  3430. exclude(init_settings.moduleswitches,cs_debuginfo);
  3431. end;
  3432. end;
  3433. {TOptionheck a second time as we might have changed assembler just above }
  3434. option.checkoptionscompatibility;
  3435. { maybe override debug info format }
  3436. if (paratargetdbg<>dbg_none) then
  3437. if not set_target_dbg(paratargetdbg) then
  3438. Message(option_w_unsupported_debug_format);
  3439. { switch assembler if it's binary and we got -a on the cmdline }
  3440. if (cs_asm_leave in init_settings.globalswitches) and
  3441. (af_outputbinary in target_asm.flags) then
  3442. begin
  3443. Message(option_switch_bin_to_src_assembler);
  3444. set_target_asm(target_info.assemextern);
  3445. end;
  3446. { Force use of external linker if there is no
  3447. internal linker or the linking is skipped }
  3448. if not(cs_link_extern in init_settings.globalswitches) and
  3449. ((target_info.link=ld_none) or
  3450. (cs_link_nolink in init_settings.globalswitches)) then
  3451. include(init_settings.globalswitches,cs_link_extern);
  3452. { turn off stripping if compiling with debuginfo or profile }
  3453. if (
  3454. (cs_debuginfo in init_settings.moduleswitches) or
  3455. (cs_profile in init_settings.moduleswitches)
  3456. ) and
  3457. not(cs_link_separate_dbg_file in init_settings.globalswitches) then
  3458. exclude(init_settings.globalswitches,cs_link_strip);
  3459. { set Mac OS X version default macros if not specified explicitly }
  3460. option.MaybeSetDefaultMacVersionMacro;
  3461. { force fpu emulation on arm/wince, arm/gba, arm/embedded and arm/nds
  3462. if fpu type not explicitly set }
  3463. if not(option.FPUSetExplicitly) and
  3464. ((target_info.system in [system_arm_wince,system_arm_gba,
  3465. system_m68k_amiga,system_m68k_atari,system_m68k_linux,
  3466. system_arm_nds,system_arm_embedded])
  3467. {$ifdef arm}
  3468. or (target_info.abi=abi_eabi)
  3469. {$endif arm}
  3470. )
  3471. {$if defined(arm) or defined (m68k)}
  3472. or (init_settings.fputype=fpu_soft)
  3473. {$endif arm or m68k}
  3474. then
  3475. begin
  3476. {$ifdef cpufpemu}
  3477. include(init_settings.moduleswitches,cs_fp_emulation);
  3478. { cs_fp_emulation and fpu_soft are equal on arm and m68k }
  3479. init_settings.fputype:=fpu_soft;
  3480. {$endif cpufpemu}
  3481. end;
  3482. {$ifdef arm}
  3483. if target_info.abi = abi_eabihf then
  3484. begin
  3485. if not(option.FPUSetExplicitly) then
  3486. begin
  3487. init_settings.fputype:=fpu_vfpv3_d16
  3488. end
  3489. else
  3490. begin
  3491. if not (init_settings.fputype in [fpu_vfpv2,fpu_vfpv3,fpu_vfpv3_d16]) then
  3492. begin
  3493. Message(option_illegal_fpu_eabihf);
  3494. StopOptions(1);
  3495. end;
  3496. end;
  3497. end;
  3498. {$endif arm}
  3499. {$ifdef arm}
  3500. case target_info.system of
  3501. system_arm_darwin:
  3502. begin
  3503. { set default cpu type to ARMv6 for Darwin unless specified otherwise, and fpu
  3504. to VFPv2 }
  3505. if not option.CPUSetExplicitly then
  3506. init_settings.cputype:=cpu_armv6;
  3507. if not option.OptCPUSetExplicitly then
  3508. init_settings.optimizecputype:=cpu_armv6;
  3509. if not option.FPUSetExplicitly then
  3510. init_settings.fputype:=fpu_vfpv2;
  3511. end;
  3512. system_arm_android:
  3513. begin
  3514. { set default cpu type to ARMv5T for Android unless specified otherwise }
  3515. if not option.CPUSetExplicitly then
  3516. init_settings.cputype:=cpu_armv5t;
  3517. if not option.OptCPUSetExplicitly then
  3518. init_settings.optimizecputype:=cpu_armv5t;
  3519. end;
  3520. end;
  3521. { set default cpu type to ARMv7a for ARMHF unless specified otherwise }
  3522. if (target_info.abi = abi_eabihf) then
  3523. begin
  3524. {$ifdef CPUARMV6}
  3525. { if the compiler is built for armv6, then
  3526. inherit this setting, e.g. Raspian is armhf but
  3527. only armv6, this makes rebuilds of the compiler
  3528. easier }
  3529. if not option.CPUSetExplicitly then
  3530. init_settings.cputype:=cpu_armv6;
  3531. if not option.OptCPUSetExplicitly then
  3532. init_settings.optimizecputype:=cpu_armv6;
  3533. {$else CPUARMV6}
  3534. if not option.CPUSetExplicitly then
  3535. init_settings.cputype:=cpu_armv7a;
  3536. if not option.OptCPUSetExplicitly then
  3537. init_settings.optimizecputype:=cpu_armv7a;
  3538. {$endif CPUARMV6}
  3539. end;
  3540. if (init_settings.instructionset=is_thumb) and not(CPUARM_HAS_THUMB2 in cpu_capabilities[init_settings.cputype]) then
  3541. begin
  3542. def_system_macro('CPUTHUMB');
  3543. if not option.FPUSetExplicitly then
  3544. init_settings.fputype:=fpu_soft;
  3545. end;
  3546. if (init_settings.instructionset=is_thumb) and (CPUARM_HAS_THUMB2 in cpu_capabilities[init_settings.cputype]) then
  3547. def_system_macro('CPUTHUMB2');
  3548. {$endif arm}
  3549. {$ifdef jvm}
  3550. { set default CPU type to Dalvik when targeting Android }
  3551. if target_info.system=system_jvm_android32 then
  3552. begin
  3553. if not option.CPUSetExplicitly then
  3554. init_settings.cputype:=cpu_dalvik;
  3555. end;
  3556. {$endif jvm}
  3557. {$ifdef mipsel}
  3558. case target_info.system of
  3559. system_mipsel_android:
  3560. begin
  3561. { set default cpu type to MIPS32 rev. 1 and hard float for MIPS-Android unless specified otherwise }
  3562. if not option.CPUSetExplicitly then
  3563. init_settings.cputype:=cpu_mips32;
  3564. if not option.OptCPUSetExplicitly then
  3565. init_settings.optimizecputype:=cpu_mips32;
  3566. if not option.FPUSetExplicitly then
  3567. init_settings.fputype:=fpu_mips2;
  3568. end;
  3569. system_mipsel_embedded:
  3570. begin
  3571. { set default cpu type to PIC32MX and softfloat for MIPSEL-EMBEDDED target unless specified otherwise }
  3572. if not option.CPUSetExplicitly then
  3573. init_settings.cputype:=cpu_pic32mx;
  3574. if not option.OptCPUSetExplicitly then
  3575. init_settings.optimizecputype:=cpu_pic32mx;
  3576. if not option.FPUSetExplicitly then
  3577. init_settings.fputype:=fpu_soft;
  3578. end;
  3579. end;
  3580. {$endif mipsel}
  3581. { now we can define cpu and fpu type }
  3582. def_system_macro('CPU'+Cputypestr[init_settings.cputype]);
  3583. def_system_macro('FPU'+fputypestr[init_settings.fputype]);
  3584. {$if defined(cpucapabilities)}
  3585. for cpuflag:=low(cpuflag) to high(cpuflag) do
  3586. begin
  3587. str(cpuflag,hs);
  3588. if cpuflag in cpu_capabilities[init_settings.cputype] then
  3589. def_system_macro(hs)
  3590. else
  3591. undef_system_macro(hs);
  3592. end;
  3593. {$endif defined(cpucapabilities)}
  3594. if init_settings.fputype<>fpu_none then
  3595. begin
  3596. {$if defined(i386) or defined(i8086)}
  3597. def_system_macro('FPC_HAS_TYPE_EXTENDED');
  3598. {$endif}
  3599. def_system_macro('FPC_HAS_TYPE_SINGLE');
  3600. def_system_macro('FPC_HAS_TYPE_DOUBLE');
  3601. {$if not defined(i386) and not defined(x86_64) and not defined(i8086)}
  3602. def_system_macro('FPC_INCLUDE_SOFTWARE_INT64_TO_DOUBLE');
  3603. {$endif}
  3604. {$if defined(m68k)}
  3605. def_system_macro('FPC_INCLUDE_SOFTWARE_LONGWORD_TO_DOUBLE');
  3606. {$endif}
  3607. {$ifdef x86_64}
  3608. {$ifndef FPC_SUPPORT_X87_TYPES_ON_WIN64}
  3609. { normally, win64 doesn't support the legacy fpu }
  3610. if target_info.system=system_x86_64_win64 then
  3611. undef_system_macro('FPC_HAS_TYPE_EXTENDED')
  3612. else
  3613. {$endif FPC_SUPPORT_X87_TYPES_ON_WIN64}
  3614. def_system_macro('FPC_HAS_TYPE_EXTENDED');
  3615. {$endif}
  3616. end;
  3617. { Enable now for testing }
  3618. {$ifndef DISABLE_TLS_DIRECTORY}
  3619. if target_info.system in systems_windows then
  3620. def_system_macro('FPC_USE_TLS_DIRECTORY');
  3621. {$endif not DISABLE_TLS_DIRECTORY}
  3622. {$ifndef DISABLE_WIN64_SEH}
  3623. if target_info.system=system_x86_64_win64 then
  3624. def_system_macro('FPC_USE_WIN64_SEH');
  3625. {$endif DISABLE_WIN64_SEH}
  3626. {$ifdef TEST_WIN32_SEH}
  3627. if target_info.system=system_i386_win32 then
  3628. def_system_macro('FPC_USE_WIN32_SEH');
  3629. {$endif TEST_WIN32_SEH}
  3630. {$ifdef ARM}
  3631. { define FPC_DOUBLE_HILO_SWAPPED if needed to properly handle doubles in RTL }
  3632. if (init_settings.fputype in [fpu_fpa,fpu_fpa10,fpu_fpa11]) and
  3633. not(cs_fp_emulation in init_settings.moduleswitches) then
  3634. def_system_macro('FPC_DOUBLE_HILO_SWAPPED');
  3635. {$endif ARM}
  3636. { inline bsf/bsr implementation }
  3637. {$if defined(i386) or defined(x86_64)}
  3638. def_system_macro('FPC_HAS_INTERNAL_BSF');
  3639. def_system_macro('FPC_HAS_INTERNAL_BSR');
  3640. {$endif}
  3641. { hardware FMA support }
  3642. {$if defined(i386) or defined(x86_64)}
  3643. if (cpu_capabilities[current_settings.cputype]*[CPUX86_HAS_FMA,CPUX86_HAS_FMA4])<>[] then
  3644. begin
  3645. def_system_macro('FPC_HAS_FAST_FMA_SINGLE');
  3646. def_system_macro('FPC_HAS_FAST_FMA_DOUBLE');
  3647. end;
  3648. {$endif defined(i386) or defined(x86_64)}
  3649. {$if defined(arm)}
  3650. { it is determined during system unit compilation if clz is used for bsf or not,
  3651. this is not perfect but the current implementation bsf/bsr does not allow another
  3652. solution }
  3653. if (CPUARM_HAS_CLZ in cpu_capabilities[init_settings.cputype]) and
  3654. ((init_settings.instructionset=is_arm) or
  3655. (CPUARM_HAS_THUMB2 in cpu_capabilities[init_settings.cputype])) then
  3656. begin
  3657. def_system_macro('FPC_HAS_INTERNAL_BSR');
  3658. if CPUARM_HAS_RBIT in cpu_capabilities[init_settings.cputype] then
  3659. def_system_macro('FPC_HAS_INTERNAL_BSF');
  3660. end;
  3661. {$endif}
  3662. { Section smartlinking conflicts with import sections on Windows }
  3663. if GenerateImportSection and
  3664. (target_info.system in [system_i386_win32,system_x86_64_win64]) then
  3665. exclude(target_info.flags,tf_smartlink_sections);
  3666. if not LinkTypeSetExplicitly then
  3667. set_default_link_type;
  3668. { Default alignment settings,
  3669. 1. load the defaults for the target
  3670. 2. override with generic optimizer setting (little size)
  3671. 3. override with the user specified -Oa }
  3672. UpdateAlignment(init_settings.alignment,target_info.alignment);
  3673. if (cs_opt_size in init_settings.optimizerswitches) then
  3674. begin
  3675. init_settings.alignment.procalign:=1;
  3676. init_settings.alignment.jumpalign:=1;
  3677. init_settings.alignment.loopalign:=1;
  3678. {$ifdef x86}
  3679. { constalignmax=1 keeps the executable and thus the memory foot print small but
  3680. all processors except x86 are really hurt by this or might even crash }
  3681. init_settings.alignment.constalignmax:=1;
  3682. {$endif x86}
  3683. end;
  3684. UpdateAlignment(init_settings.alignment,option.paraalignment);
  3685. set_system_macro('FPC_VERSION',version_nr);
  3686. set_system_macro('FPC_RELEASE',release_nr);
  3687. set_system_macro('FPC_PATCH',patch_nr);
  3688. set_system_macro('FPC_FULLVERSION',Format('%d%.02d%.02d',[StrToInt(version_nr),StrToInt(release_nr),StrToInt(patch_nr)]));
  3689. if not(target_info.system in systems_windows) then
  3690. def_system_macro('FPC_WIDESTRING_EQUAL_UNICODESTRING');
  3691. for i:=low(tfeature) to high(tfeature) do
  3692. if i in features then
  3693. def_system_macro('FPC_HAS_FEATURE_'+featurestr[i]);
  3694. option.free;
  3695. Option:=nil;
  3696. clearstack_pocalls := [pocall_cdecl,pocall_cppdecl,pocall_syscall,pocall_mwpascal];
  3697. cdecl_pocalls := [pocall_cdecl, pocall_cppdecl, pocall_mwpascal];
  3698. if (tf_safecall_clearstack in target_info.flags) then
  3699. begin
  3700. include (cdecl_pocalls, pocall_safecall);
  3701. include (clearstack_pocalls, pocall_safecall)
  3702. end;
  3703. end;
  3704. initialization
  3705. coption:=toption;
  3706. finalization
  3707. if assigned(option) then
  3708. option.free;
  3709. end.