options.pas 130 KB

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