options.pas 131 KB

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