options.pas 174 KB

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