options.pas 154 KB

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