options.pas 129 KB

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