options.pas 174 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123
  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. break;
  1546. end;
  1547. end;
  1548. end;
  1549. {$endif cpucapabilities}
  1550. CPUSetExplicitly:=true;
  1551. break;
  1552. end;
  1553. 'P':
  1554. begin
  1555. delete(more,1,1);
  1556. case upper(copy(more,1,pos('=',more)-1)) of
  1557. 'PACKSET':
  1558. begin
  1559. delete(more,1,pos('=',more));
  1560. case more of
  1561. '0','DEFAULT','NORMAL':
  1562. init_settings.setalloc:=0;
  1563. '1','2','4','8':
  1564. init_settings.setalloc:=StrToInt(more);
  1565. else
  1566. IllegalPara(opt);
  1567. end
  1568. end;
  1569. 'PACKENUM':
  1570. begin
  1571. delete(more,1,pos('=',more));
  1572. case more of
  1573. '0','DEFAULT','NORMAL':
  1574. init_settings.packenum:=4;
  1575. '1','2','4':
  1576. init_settings.packenum:=StrToInt(more);
  1577. else
  1578. IllegalPara(opt);
  1579. end;
  1580. end;
  1581. 'PACKRECORD':
  1582. begin
  1583. delete(more,1,pos('=',more));
  1584. case more of
  1585. '0','DEFAULT','NORMAL':
  1586. init_settings.packrecords:=default_settings.packrecords;
  1587. '1','2','4','8','16','32':
  1588. init_settings.packrecords:=StrToInt(more);
  1589. else
  1590. IllegalPara(opt);
  1591. end;
  1592. end
  1593. else
  1594. IllegalPara(opt);
  1595. end;
  1596. end;
  1597. 'r' :
  1598. If UnsetBool(More, j, opt, false) then
  1599. exclude(init_settings.localswitches,cs_check_range)
  1600. Else
  1601. include(init_settings.localswitches,cs_check_range);
  1602. 'R' :
  1603. If UnsetBool(More, j, opt, false) then
  1604. begin
  1605. exclude(init_settings.localswitches,cs_check_range);
  1606. exclude(init_settings.localswitches,cs_check_object);
  1607. end
  1608. Else
  1609. begin
  1610. include(init_settings.localswitches,cs_check_range);
  1611. include(init_settings.localswitches,cs_check_object);
  1612. end;
  1613. 's' :
  1614. begin
  1615. val(copy(more,j+1,length(more)-j),stacksize,code);
  1616. if (code<>0)
  1617. {$ifdef cpu16bitaddr}
  1618. or (stacksize>=65521)
  1619. {$else cpu16bitaddr}
  1620. or (stacksize>=67107840)
  1621. {$endif cpu16bitaddr}
  1622. or (stacksize<1024) then
  1623. IllegalPara(opt);
  1624. break;
  1625. end;
  1626. 't' :
  1627. If UnsetBool(More, j, opt, false) then
  1628. exclude(init_settings.localswitches,cs_check_stack)
  1629. Else
  1630. include(init_settings.localswitches,cs_check_stack);
  1631. 'D' :
  1632. If UnsetBool(More, j, opt, false) then
  1633. exclude(init_settings.moduleswitches,cs_create_dynamic)
  1634. Else
  1635. include(init_settings.moduleswitches,cs_create_dynamic);
  1636. 'X' :
  1637. If UnsetBool(More, j, opt, false) then
  1638. exclude(init_settings.moduleswitches,cs_create_smart)
  1639. Else
  1640. include(init_settings.moduleswitches,cs_create_smart);
  1641. 'T' :
  1642. begin
  1643. if not UpdateTargetSwitchStr(copy(more,j+1,length(more)),init_settings.targetswitches,true) then
  1644. IllegalPara(opt);
  1645. break;
  1646. end;
  1647. 'v' :
  1648. If target_info.system in systems_jvm then
  1649. If UnsetBool(More, j, opt, false) then
  1650. exclude(init_settings.localswitches,cs_check_var_copyout)
  1651. Else
  1652. include(init_settings.localswitches,cs_check_var_copyout)
  1653. else
  1654. IllegalPara(opt);
  1655. 'V':
  1656. begin
  1657. s:=upper(copy(more,j+1,length(more)-j));
  1658. if s='GLOBAL-DYNAMIC' then
  1659. init_settings.tlsmodel:=tlsm_global_dynamic
  1660. else if s='LOCAL-EXEC' then
  1661. init_settings.tlsmodel:=tlsm_local_exec
  1662. else
  1663. IllegalPara(opt);
  1664. break;
  1665. end;
  1666. else
  1667. IllegalPara(opt);
  1668. end;
  1669. inc(j);
  1670. end;
  1671. end;
  1672. 'd' :
  1673. begin
  1674. l:=Pos(':=',more);
  1675. if l>0 then
  1676. hs:=copy(more,1,l-1)
  1677. else
  1678. hs:=more;
  1679. if (not is_identifier(hs)) then
  1680. begin
  1681. if hs='' then
  1682. Message1(option_missing_arg,'-d')
  1683. else
  1684. Message1(option_malformed_para,opt);
  1685. StopOptions(1);
  1686. end;
  1687. if l>0 then
  1688. begin
  1689. if cs_support_macro in init_settings.moduleswitches then
  1690. set_system_macro(hs,Copy(more,l+2,255))
  1691. else
  1692. set_system_compvar(hs,Copy(more,l+2,255));
  1693. end
  1694. else
  1695. def_system_macro(hs);
  1696. end;
  1697. 'D' :
  1698. begin
  1699. j:=1;
  1700. while j<=length(more) do
  1701. begin
  1702. case more[j] of
  1703. 'd' :
  1704. begin
  1705. include(init_settings.globalswitches,cs_link_deffile);
  1706. description:=Copy(more,j+1,255);
  1707. break;
  1708. end;
  1709. 'D' :
  1710. begin
  1711. datestr:=Copy(more,j+1,255);
  1712. break;
  1713. end;
  1714. 'T' :
  1715. begin
  1716. timestr:=Copy(more,j+1,255);
  1717. break;
  1718. end;
  1719. 'v' :
  1720. begin
  1721. include(init_settings.globalswitches,cs_link_deffile);
  1722. dllversion:=Copy(more,j+1,255);
  1723. l:=pos('.',dllversion);
  1724. dllminor:=0;
  1725. error:=0;
  1726. if l>0 then
  1727. begin
  1728. val(copy(dllversion,l+1,255),minor,error);
  1729. if (error=0) and
  1730. (minor>=0) and (minor<=$ffff) then
  1731. dllminor:=minor
  1732. else
  1733. if error=0 then
  1734. error:=1;
  1735. end;
  1736. if l=0 then
  1737. l:=256;
  1738. dllmajor:=1;
  1739. major:=0;
  1740. if error=0 then
  1741. val(copy(dllversion,1,l-1),major,error);
  1742. if (error=0) and (major>=0) and (major<=$ffff) then
  1743. dllmajor:=major
  1744. else
  1745. if error=0 then
  1746. error:=1;
  1747. if error<>0 then
  1748. Message1(scan_w_wrong_version_ignored,dllversion);
  1749. break;
  1750. end;
  1751. 'w' :
  1752. begin
  1753. include(init_settings.globalswitches,cs_link_deffile);
  1754. usewindowapi:=true;
  1755. end;
  1756. '-' :
  1757. begin
  1758. exclude(init_settings.globalswitches,cs_link_deffile);
  1759. usewindowapi:=false;
  1760. end;
  1761. else
  1762. IllegalPara(opt);
  1763. end;
  1764. inc(j);
  1765. end;
  1766. end;
  1767. 'e' :
  1768. exepath:=FixPath(More,true);
  1769. 'E' :
  1770. begin
  1771. if UnsetBool(More, 0, opt, true) then
  1772. exclude(init_settings.globalswitches,cs_link_nolink)
  1773. else
  1774. include(init_settings.globalswitches,cs_link_nolink);
  1775. end;
  1776. 'f' :
  1777. begin
  1778. if more='PIC' then
  1779. begin
  1780. if tf_no_pic_supported in target_info.flags then
  1781. message(scan_w_pic_ignored)
  1782. else
  1783. include(init_settings.moduleswitches,cs_create_pic)
  1784. end
  1785. else
  1786. IllegalPara(opt);
  1787. end;
  1788. 'F' :
  1789. begin
  1790. if more='' then
  1791. IllegalPara(opt);
  1792. c:=more[1];
  1793. Delete(more,1,1);
  1794. DefaultReplacements(More);
  1795. case c of
  1796. 'a' :
  1797. autoloadunits:=more;
  1798. 'c' :
  1799. begin
  1800. { if we first specify that the system code page should be
  1801. used and then explicitly specify a code page, unset the
  1802. flag that we're using the system code page again }
  1803. SetCompileModeSwitch('SYSTEMCODEPAGE-',true);
  1804. if (upper(more)='UTF8') or (upper(more)='UTF-8') then
  1805. init_settings.sourcecodepage:=CP_UTF8
  1806. else if not(cpavailable(more)) then
  1807. Message1(option_code_page_not_available,more)
  1808. else
  1809. init_settings.sourcecodepage:=codepagebyname(more);
  1810. include(init_settings.moduleswitches,cs_explicit_codepage);
  1811. end;
  1812. 'C' :
  1813. RCCompiler:=More;
  1814. 'd' :
  1815. if UnsetBool(more, 0, opt, true) then
  1816. init_settings.disabledircache:=false
  1817. else
  1818. init_settings.disabledircache:=true;
  1819. 'D' :
  1820. utilsdirectory:=FixPath(More,true);
  1821. 'e' :
  1822. SetRedirectFile(More);
  1823. 'E' :
  1824. OutputExeDir:=FixPath(More,true);
  1825. 'f' :
  1826. if (target_info.system in systems_darwin) then
  1827. if ispara then
  1828. ParaFrameworkPath.AddPath(More,false)
  1829. else
  1830. frameworksearchpath.AddPath(More,true)
  1831. {$ifdef XTENSA}
  1832. else if (target_info.system=system_xtensa_freertos) then
  1833. idfpath:=FixPath(More,true)
  1834. {$endif XTENSA}
  1835. else
  1836. IllegalPara(opt);
  1837. 'F' :
  1838. RCForceFPCRes:=true;
  1839. 'i' :
  1840. begin
  1841. if ispara then
  1842. ParaIncludePath.AddPath(More,false)
  1843. else
  1844. includesearchpath.AddPath(More,true);
  1845. end;
  1846. 'm' :
  1847. begin
  1848. s:=ExtractFileDir(more);
  1849. if TryStrToInt(ExtractFileName(more),j) then
  1850. begin
  1851. unicodemapping:=loadunicodemapping(More,More+'.txt',j);
  1852. if assigned(unicodemapping) then
  1853. registermapping(unicodemapping)
  1854. else
  1855. IllegalPara(opt);
  1856. end
  1857. else
  1858. IllegalPara(opt);
  1859. end;
  1860. 'M' :
  1861. unicodepath:=FixPath(More,true);
  1862. 'g' :
  1863. Message2(option_obsolete_switch_use_new,'-Fg','-Fl');
  1864. 'l' :
  1865. begin
  1866. if ispara then
  1867. ParaLibraryPath.AddLibraryPath(sysrootpath,More,false)
  1868. else
  1869. LibrarySearchPath.AddLibraryPath(sysrootpath,More,true)
  1870. end;
  1871. 'L' :
  1872. begin
  1873. if More<>'' then
  1874. ParaDynamicLinker:=More
  1875. else
  1876. IllegalPara(opt);
  1877. end;
  1878. 'N' :
  1879. begin
  1880. if more<>'' then
  1881. paranamespaces.insert(more)
  1882. else
  1883. illegalpara(opt);
  1884. end;
  1885. 'o' :
  1886. begin
  1887. if ispara then
  1888. ParaObjectPath.AddPath(More,false)
  1889. else
  1890. ObjectSearchPath.AddPath(More,true);
  1891. end;
  1892. 'P' :
  1893. begin
  1894. if ispara then
  1895. parapackages.add(more,nil)
  1896. else
  1897. add_package(more,true,true);
  1898. end;
  1899. 'p' :
  1900. begin
  1901. if ispara then
  1902. parapackagepath.AddPath(More,false)
  1903. else
  1904. packagesearchpath.AddPath(More,true);
  1905. end;
  1906. 'r' :
  1907. Msgfilename:=More;
  1908. 'R' :
  1909. ResCompiler:=More;
  1910. 'u' :
  1911. begin
  1912. if ispara then
  1913. ParaUnitPath.AddPath(More,false)
  1914. else
  1915. unitsearchpath.AddPath(More,true);
  1916. end;
  1917. 'U' :
  1918. OutputUnitDir:=FixPath(More,true);
  1919. 'W',
  1920. 'w':
  1921. begin
  1922. if More<>'' then
  1923. begin
  1924. DefaultReplacements(More);
  1925. D:=ExtractFilePath(More);
  1926. if (D<>'') then
  1927. D:=FixPath(D,True);
  1928. D:=D+ExtractFileName(More);
  1929. if (c='W') then
  1930. WpoFeedbackOutput:=D
  1931. else
  1932. WpoFeedbackInput:=D;
  1933. end
  1934. else
  1935. IllegalPara(opt);
  1936. end;
  1937. else
  1938. IllegalPara(opt);
  1939. end;
  1940. end;
  1941. 'g' :
  1942. begin
  1943. if UnsetBool(More, 0, opt, false) then
  1944. begin
  1945. exclude(init_settings.moduleswitches,cs_debuginfo);
  1946. exclude(init_settings.globalswitches,cs_use_heaptrc);
  1947. exclude(init_settings.globalswitches,cs_use_lineinfo);
  1948. exclude(init_settings.localswitches,cs_checkpointer);
  1949. paratargetdbg:=dbg_none;
  1950. localvartrashing := -1;
  1951. end
  1952. else
  1953. begin
  1954. include(init_settings.moduleswitches,cs_debuginfo);
  1955. if paratargetdbg=dbg_none then
  1956. paratargetdbg:=target_info.dbg;
  1957. end;
  1958. if not RelocSectionSetExplicitly then
  1959. RelocSection:=false;
  1960. j:=1;
  1961. while j<=length(more) do
  1962. begin
  1963. case more[j] of
  1964. 'c' :
  1965. begin
  1966. if UnsetBool(More, j, opt, false) then
  1967. exclude(init_settings.localswitches,cs_checkpointer)
  1968. else if (target_info.system in systems_support_checkpointer) then
  1969. begin
  1970. if do_release then
  1971. Message(option_gc_incompatible_with_release_flag)
  1972. else
  1973. include(init_settings.localswitches,cs_checkpointer);
  1974. end
  1975. else
  1976. UnsupportedPara('-gc');
  1977. end;
  1978. 'h' :
  1979. begin
  1980. if UnsetBool(More, j, opt, false) then
  1981. exclude(init_settings.globalswitches,cs_use_heaptrc)
  1982. else
  1983. begin
  1984. if cs_gdb_valgrind in init_settings.globalswitches then
  1985. Message2(option_valgrind_heaptrc_mismatch,'-gh', '-gv');
  1986. include(init_settings.globalswitches,cs_use_heaptrc);
  1987. end;
  1988. end;
  1989. 'l' :
  1990. begin
  1991. if UnsetBool(More, j, opt, false) then
  1992. exclude(init_settings.globalswitches,cs_use_lineinfo)
  1993. else
  1994. include(init_settings.globalswitches,cs_use_lineinfo);
  1995. end;
  1996. 'm' :
  1997. begin
  1998. paratargetdbg:=dbg_codeview;
  1999. end;
  2000. 'o' :
  2001. begin
  2002. if not UpdateDebugStr(copy(more,j+1,length(more)),init_settings.debugswitches) then
  2003. IllegalPara(opt);
  2004. break;
  2005. end;
  2006. 'p' :
  2007. begin
  2008. if UnsetBool(More, j, opt, false) then
  2009. exclude(init_settings.globalswitches,cs_stabs_preservecase)
  2010. else
  2011. include(init_settings.globalswitches,cs_stabs_preservecase);
  2012. end;
  2013. 's' :
  2014. begin
  2015. paratargetdbg:=dbg_stabs;
  2016. end;
  2017. 't' :
  2018. begin
  2019. if UnsetBool(More, j, opt, false) then
  2020. localvartrashing := -1
  2021. else
  2022. localvartrashing := (localvartrashing + 1) mod nroftrashvalues;
  2023. end;
  2024. 'v' :
  2025. begin
  2026. if UnsetBool(More, j, opt, false) then
  2027. exclude(init_settings.globalswitches,cs_gdb_valgrind)
  2028. else
  2029. begin
  2030. if cs_use_heaptrc in init_settings.globalswitches then
  2031. Message2(option_valgrind_heaptrc_mismatch,'-gh', '-gv');
  2032. include(init_settings.globalswitches,cs_gdb_valgrind);
  2033. end;
  2034. end;
  2035. 'w' :
  2036. begin
  2037. if (j<length(more)) and (more[j+1] in ['2','3','4']) then
  2038. begin
  2039. case more[j+1] of
  2040. '2': paratargetdbg:=dbg_dwarf2;
  2041. '3': paratargetdbg:=dbg_dwarf3;
  2042. '4': paratargetdbg:=dbg_dwarf4;
  2043. end;
  2044. inc(j);
  2045. end
  2046. else
  2047. paratargetdbg:=dbg_dwarf2;
  2048. end;
  2049. else
  2050. IllegalPara(opt);
  2051. end;
  2052. inc(j);
  2053. end;
  2054. end;
  2055. 'h' :
  2056. begin
  2057. NoPressEnter:=true;
  2058. if (More <> '') and (More [1] = 'F') then
  2059. begin
  2060. FPCHelpLines := true;
  2061. Delete (More, 1, 1);
  2062. FPCBinaryPath := More;
  2063. end;
  2064. WriteHelpPages;
  2065. end;
  2066. 'i' :
  2067. begin
  2068. if (More='') or
  2069. (More [1] in ['a', 'b', 'c', 'f', 'i', 'm', 'o', 'r', 't', 'u', 'w', 'x']) then
  2070. WriteInfo (More)
  2071. else
  2072. QuickInfo:=QuickInfo+More;
  2073. end;
  2074. 'I' :
  2075. begin
  2076. if ispara then
  2077. ParaIncludePath.AddPath(More,false)
  2078. else
  2079. includesearchpath.AddPath(More,false);
  2080. end;
  2081. 'k' :
  2082. begin
  2083. if more<>'' then
  2084. ParaLinkOptions:=ParaLinkOptions+' '+More
  2085. else
  2086. IllegalPara(opt);
  2087. end;
  2088. 'l' :
  2089. ParaLogo:=not UnSetBool(more,0,opt,true);
  2090. {$ifdef PREPROCWRITE}
  2091. 'm' :
  2092. parapreprocess:=not UnSetBool(more,0,opt,true);
  2093. {$endif PREPROCWRITE}
  2094. 'M' :
  2095. begin
  2096. more:=Upper(more);
  2097. if not SetCompileMode(more, true) then
  2098. if not SetCompileModeSwitch(more, true) then
  2099. IllegalPara(opt);
  2100. end;
  2101. 'n' :
  2102. begin
  2103. if More='' then
  2104. disable_configfile:=true
  2105. else
  2106. IllegalPara(opt);
  2107. end;
  2108. 'o' :
  2109. begin
  2110. if More<>'' then
  2111. begin
  2112. DefaultReplacements(More);
  2113. D:=ExtractFilePath(More);
  2114. if (D<>'') then
  2115. OutputExeDir:=FixPath(D,True);
  2116. OutputFileName:=ExtractFileName(More);
  2117. end
  2118. else
  2119. IllegalPara(opt);
  2120. end;
  2121. 'O' :
  2122. begin
  2123. j:=1;
  2124. while j<=length(more) do
  2125. begin
  2126. case more[j] of
  2127. '1' :
  2128. init_settings.optimizerswitches:=init_settings.optimizerswitches+level1optimizerswitches;
  2129. '2' :
  2130. init_settings.optimizerswitches:=init_settings.optimizerswitches+level2optimizerswitches;
  2131. '3' :
  2132. init_settings.optimizerswitches:=init_settings.optimizerswitches+level3optimizerswitches;
  2133. '4' :
  2134. init_settings.optimizerswitches:=init_settings.optimizerswitches+level4optimizerswitches;
  2135. 'a' :
  2136. begin
  2137. if not(UpdateAlignmentStr(Copy(Opt,j+3,255),ParaAlignment)) then
  2138. IllegalPara(opt);
  2139. break;
  2140. end;
  2141. 's' :
  2142. include(init_settings.optimizerswitches,cs_opt_size);
  2143. 'p' :
  2144. begin
  2145. if not Setoptimizecputype(copy(more,j+1,length(more)),init_settings.optimizecputype) then
  2146. begin
  2147. OptCPUSetExplicitly:=true;
  2148. { Give warning for old i386 switches }
  2149. if (Length(More)-j=1) and
  2150. (More[j+1]>='1') and (More[j+1]<='5')then
  2151. Message2(option_obsolete_switch_use_new,'-Op<nr>','-Op<name>')
  2152. else
  2153. IllegalPara(opt);
  2154. end;
  2155. break;
  2156. end;
  2157. 'o' :
  2158. begin
  2159. if not UpdateOptimizerStr(copy(more,j+1,length(more)),init_settings.optimizerswitches) then
  2160. IllegalPara(opt);
  2161. break;
  2162. end;
  2163. '-' :
  2164. begin
  2165. init_settings.optimizerswitches:=[];
  2166. FillChar(ParaAlignment,sizeof(ParaAlignment),0);
  2167. end;
  2168. { Obsolete switches }
  2169. 'g' :
  2170. Message2(option_obsolete_switch_use_new,'-Og','-Os');
  2171. 'G' :
  2172. Message1(option_obsolete_switch,'-OG');
  2173. 'r' :
  2174. Message2(option_obsolete_switch_use_new,'-Or','-O2 or -Ooregvar');
  2175. 'u' :
  2176. Message2(option_obsolete_switch_use_new,'-Ou','-Oouncertain');
  2177. 'w' :
  2178. begin
  2179. if not UpdateWpoStr(copy(more,j+1,length(more)),init_settings.dowpoptimizerswitches) then
  2180. IllegalPara(opt);
  2181. break;
  2182. end;
  2183. 'W' :
  2184. begin
  2185. if not UpdateWpoStr(copy(more,j+1,length(more)),init_settings.genwpoptimizerswitches) then
  2186. IllegalPara(opt);
  2187. break;
  2188. end;
  2189. else
  2190. IllegalPara(opt);
  2191. end;
  2192. inc(j);
  2193. end;
  2194. end;
  2195. 'p' :
  2196. begin
  2197. if UnsetBool(More, 0, opt, false) then
  2198. begin
  2199. init_settings.moduleswitches:=init_settings.moduleswitches-[cs_profile];
  2200. undef_system_macro('FPC_PROFILE');
  2201. end
  2202. else
  2203. if Length(More)=0 then
  2204. IllegalPara(opt)
  2205. else
  2206. case more[1] of
  2207. 'g' : if UnsetBool(more, 1, opt, false) then
  2208. begin
  2209. exclude(init_settings.moduleswitches,cs_profile);
  2210. undef_system_macro('FPC_PROFILE');
  2211. end
  2212. else if (target_info.system in supported_targets_pg) then
  2213. begin
  2214. include(init_settings.moduleswitches,cs_profile);
  2215. def_system_macro('FPC_PROFILE');
  2216. end
  2217. else
  2218. UnsupportedPara('-pg');
  2219. else
  2220. IllegalPara(opt);
  2221. end;
  2222. end;
  2223. 'P' :
  2224. begin
  2225. { used to select the target processor with the "fpc" binary;
  2226. give an error if it's not the target architecture supported by
  2227. this compiler binary (will be verified after the target_info
  2228. is set) }
  2229. processorstr:=More;
  2230. end;
  2231. 'R' :
  2232. begin
  2233. if not SetAsmReadMode(More,init_settings.asmmode) then
  2234. IllegalPara(opt);
  2235. end;
  2236. 's' :
  2237. begin
  2238. if UnsetBool(More, 0, opt, false) then
  2239. begin
  2240. init_settings.globalswitches:=init_settings.globalswitches-[cs_asm_extern,cs_link_extern,cs_link_nolink];
  2241. if more<>'' then
  2242. IllegalPara(opt);
  2243. end
  2244. else
  2245. begin
  2246. init_settings.globalswitches:=init_settings.globalswitches+[cs_asm_extern,cs_link_extern,cs_link_nolink];
  2247. if more='h' then
  2248. init_settings.globalswitches:=init_settings.globalswitches-[cs_link_on_target,cs_assemble_on_target]
  2249. else if more='t' then
  2250. init_settings.globalswitches:=init_settings.globalswitches+[cs_link_on_target,cs_assemble_on_target]
  2251. else if more='T' then
  2252. init_settings.globalswitches:=init_settings.globalswitches+[cs_link_on_target]-[cs_asm_extern]
  2253. else if more='r' then
  2254. init_settings.globalswitches:=init_settings.globalswitches+[cs_asm_leave,cs_no_regalloc]
  2255. else if more<>'' then
  2256. IllegalPara(opt);
  2257. end;
  2258. end;
  2259. 'S' :
  2260. begin
  2261. if more='' then
  2262. IllegalPara(opt);
  2263. if more[1]='I' then
  2264. begin
  2265. {$ifdef jvm}
  2266. UnsupportedPara('-SI');
  2267. {$endif}
  2268. if upper(more)='ICOM' then
  2269. init_settings.interfacetype:=it_interfacecom
  2270. else if upper(more)='ICORBA' then
  2271. init_settings.interfacetype:=it_interfacecorba
  2272. else
  2273. IllegalPara(opt);
  2274. end
  2275. else
  2276. begin
  2277. j:=1;
  2278. while j<=length(more) do
  2279. begin
  2280. case more[j] of
  2281. '2' : //an alternative to -Mobjfpc
  2282. SetCompileMode('OBJFPC',true);
  2283. 'a' :
  2284. If UnsetBool(More, j, opt, false) then
  2285. exclude(init_settings.localswitches,cs_do_assertion)
  2286. else
  2287. include(init_settings.localswitches,cs_do_assertion);
  2288. 'c' :
  2289. If UnsetBool(More, j, opt, false) then
  2290. exclude(init_settings.moduleswitches,cs_support_c_operators)
  2291. else
  2292. include(init_settings.moduleswitches,cs_support_c_operators);
  2293. 'C':
  2294. If UnsetBool(More, j, opt, false) then
  2295. exclude(init_settings.localswitches,cs_check_all_case_coverage)
  2296. else
  2297. include(init_settings.localswitches,cs_check_all_case_coverage);
  2298. 'd' : //an alternative to -Mdelphi
  2299. SetCompileMode('DELPHI',true);
  2300. 'e' :
  2301. begin
  2302. SetErrorFlags(copy(more,j+1,length(more)));
  2303. break;
  2304. end;
  2305. 'f' :
  2306. begin
  2307. if not(cs_compilesystem in init_settings.moduleswitches) then
  2308. Message(option_features_only_for_system_unit);
  2309. inc(j);
  2310. if more[j]='-' then
  2311. begin
  2312. if length(more)>j then
  2313. IllegalPara(opt)
  2314. else
  2315. features:=[];
  2316. end
  2317. else
  2318. begin
  2319. if (HandleFeature(upper(copy(more,j,length(more)-j+1)))) then
  2320. j:=length(more)
  2321. else
  2322. IllegalPara(opt);
  2323. end;
  2324. end;
  2325. 'g' :
  2326. If UnsetBool(More, j, opt, false) then
  2327. exclude(init_settings.moduleswitches,cs_support_goto)
  2328. else
  2329. include(init_settings.moduleswitches,cs_support_goto);
  2330. 'h' :
  2331. If UnsetBool(More, j, opt, false) then
  2332. exclude(init_settings.localswitches,cs_refcountedstrings)
  2333. else
  2334. include(init_settings.localswitches,cs_refcountedstrings);
  2335. 'i' :
  2336. If UnsetBool(More, j, opt, false) then
  2337. exclude(init_settings.localswitches,cs_do_inline)
  2338. else
  2339. include(init_settings.localswitches,cs_do_inline);
  2340. 'j' :
  2341. If UnsetBool(More, j, opt, false) then
  2342. exclude(init_settings.localswitches,cs_typed_const_writable)
  2343. else
  2344. include(init_settings.localswitches,cs_typed_const_writable);
  2345. 'k' :
  2346. If UnsetBool(More, j, opt, false) then
  2347. exclude(init_settings.globalswitches,cs_load_fpcylix_unit)
  2348. else
  2349. include(init_settings.globalswitches,cs_load_fpcylix_unit);
  2350. 'm' :
  2351. If UnsetBool(More, j, opt, false) then
  2352. exclude(init_settings.moduleswitches,cs_support_macro)
  2353. else
  2354. include(init_settings.moduleswitches,cs_support_macro);
  2355. 'o' : //an alternative to -Mtp
  2356. SetCompileMode('TP',true);
  2357. 'r' :
  2358. If UnsetBool(More, j, opt, false) then
  2359. exclude(init_settings.globalswitches,cs_transparent_file_names)
  2360. else
  2361. include(init_settings.globalswitches,cs_transparent_file_names);
  2362. {$ifdef gpc_mode}
  2363. 'p' : //an alternative to -Mgpc
  2364. SetCompileMode('GPC',true);
  2365. {$endif}
  2366. 's' :
  2367. If UnsetBool(More, j, opt, false) then
  2368. exclude(init_settings.globalswitches,cs_constructor_name)
  2369. else
  2370. include(init_settings.globalswitches,cs_constructor_name);
  2371. 't' :
  2372. Message1(option_obsolete_switch,'-St');
  2373. 'v' :
  2374. If UnsetBool(More, j, opt, false) then
  2375. exclude(init_settings.globalswitches,cs_support_vectors)
  2376. else
  2377. include(init_settings.globalswitches,cs_support_vectors);
  2378. 'x' :
  2379. If UnsetBool(More, j, opt, false) then
  2380. SetCompileModeSwitch('EXCEPTIONS-',true)
  2381. else
  2382. SetCompileModeSwitch('EXCEPTIONS',true);
  2383. 'y' :
  2384. If UnsetBool(More, j, opt, false) then
  2385. exclude(init_settings.localswitches,cs_typed_addresses)
  2386. else
  2387. include(init_settings.localswitches,cs_typed_addresses);
  2388. '-' :
  2389. begin
  2390. init_settings.globalswitches:=init_settings.globalswitches - [cs_constructor_name,cs_support_exceptions,
  2391. cs_support_vectors,cs_load_fpcylix_unit];
  2392. init_settings.localswitches:=init_settings.localswitches - [cs_do_assertion,cs_do_inline, cs_refcountedstrings,
  2393. cs_typed_addresses];
  2394. init_settings.moduleswitches:=init_settings.moduleswitches - [cs_support_c_operators, cs_support_goto,
  2395. cs_support_macro];
  2396. end;
  2397. else
  2398. IllegalPara(opt);
  2399. end;
  2400. inc(j);
  2401. end;
  2402. end;
  2403. end;
  2404. 'T' :
  2405. begin
  2406. more:=Upper(More);
  2407. if paratarget=system_none then
  2408. begin
  2409. { remove old target define }
  2410. TargetOptions(false);
  2411. { load new target }
  2412. paratarget:=find_system_by_string(More);
  2413. if paratarget<>system_none then
  2414. set_target(paratarget)
  2415. else
  2416. IllegalPara(opt);
  2417. { set new define }
  2418. TargetOptions(true);
  2419. end
  2420. else
  2421. if More<>upper(target_info.shortname) then
  2422. Message1(option_target_is_already_set,target_info.shortname);
  2423. end;
  2424. 'u' :
  2425. if is_identifier(more) then
  2426. undef_system_macro(more)
  2427. else
  2428. begin
  2429. if (more='') then
  2430. Message1(option_missing_arg,'-u')
  2431. else
  2432. Message1(option_malformed_para,opt);
  2433. StopOptions(1);
  2434. end;
  2435. 'U' :
  2436. begin
  2437. j:=1;
  2438. while j<=length(more) do
  2439. begin
  2440. case more[j] of
  2441. {$ifdef UNITALIASES}
  2442. 'a' :
  2443. begin
  2444. AddUnitAlias(Copy(More,j+1,255));
  2445. break;
  2446. end;
  2447. {$endif UNITALIASES}
  2448. 'n' :
  2449. exclude(init_settings.globalswitches,cs_check_unit_name);
  2450. 'p' :
  2451. begin
  2452. Message2(option_obsolete_switch_use_new,'-Up','-Fu');
  2453. break;
  2454. end;
  2455. 'r' :
  2456. begin
  2457. do_release:=true;
  2458. if (cs_checkpointer in init_settings.localswitches) then
  2459. begin
  2460. Message(option_gc_incompatible_with_release_flag);
  2461. exclude(init_settings.localswitches,cs_checkpointer);
  2462. end;
  2463. end;
  2464. 's' :
  2465. include(init_settings.moduleswitches,cs_compilesystem);
  2466. '-' :
  2467. begin
  2468. exclude(init_settings.moduleswitches,cs_compilesystem);
  2469. exclude(init_settings.globalswitches,cs_check_unit_name);
  2470. end;
  2471. else
  2472. IllegalPara(opt);
  2473. end;
  2474. inc(j);
  2475. end;
  2476. end;
  2477. 'v' :
  2478. begin
  2479. if not setverbosity(More) then
  2480. IllegalPara(opt);
  2481. end;
  2482. 'V' : ; { Ignore used by fpc }
  2483. 'W' :
  2484. begin
  2485. j:=1;
  2486. while j<=length(More) do
  2487. begin
  2488. case More[j] of
  2489. 'A':
  2490. begin
  2491. if target_info.system in systems_all_windows then
  2492. begin
  2493. if UnsetBool(More, j, opt, false) then
  2494. SetApptype(app_cui)
  2495. else
  2496. SetApptype(app_native);
  2497. end
  2498. else
  2499. IllegalPara(opt);
  2500. end;
  2501. 'b':
  2502. begin
  2503. if target_info.system in systems_darwin then
  2504. begin
  2505. if UnsetBool(More, j, opt, false) then
  2506. SetApptype(app_cui)
  2507. else
  2508. SetApptype(app_bundle)
  2509. end
  2510. else
  2511. IllegalPara(opt);
  2512. end;
  2513. 'B':
  2514. begin
  2515. if target_info.system in systems_all_windows+systems_symbian+[system_z80_zxspectrum] then
  2516. begin
  2517. { -WB200000 means set trefered base address
  2518. to $200000, but does not change relocsection boolean
  2519. this way we can create both relocatble and
  2520. non relocatable DLL at a specific base address PM }
  2521. if (length(More)>j) then
  2522. begin
  2523. val('$'+Copy(More,j+1,255),imagebase,code);
  2524. if code<>0 then
  2525. IllegalPara(opt);
  2526. ImageBaseSetExplicity:=true;
  2527. end
  2528. else
  2529. begin
  2530. RelocSection:=true;
  2531. RelocSectionSetExplicitly:=true;
  2532. end;
  2533. break;
  2534. end
  2535. else
  2536. IllegalPara(opt);
  2537. end;
  2538. 'C':
  2539. begin
  2540. if target_info.system in systems_all_windows+systems_os2+systems_macos then
  2541. begin
  2542. if UnsetBool(More, j, opt, false) then
  2543. SetApptype(app_gui)
  2544. else
  2545. SetApptype(app_cui);
  2546. end
  2547. else
  2548. IllegalPara(opt);
  2549. end;
  2550. 'D':
  2551. begin
  2552. if target_info.system in systems_all_windows then
  2553. begin
  2554. UseDeffileForExports:=not UnsetBool(More, j, opt, false);
  2555. UseDeffileForExportsSetExplicitly:=true;
  2556. end
  2557. else
  2558. IllegalPara(opt);
  2559. end;
  2560. 'e':
  2561. begin
  2562. if (target_info.system in systems_darwin) then
  2563. begin
  2564. set_target_res(res_ext);
  2565. target_info.resobjext:='.fpcres';
  2566. end
  2567. else
  2568. IllegalPara(opt);
  2569. end;
  2570. 'F':
  2571. begin
  2572. if target_info.system in systems_os2 then
  2573. begin
  2574. if UnsetBool(More, j, opt, false) then
  2575. SetApptype(app_cui)
  2576. else
  2577. SetApptype(app_fs);
  2578. end
  2579. else
  2580. IllegalPara(opt);
  2581. end;
  2582. 'G':
  2583. begin
  2584. if target_info.system in systems_all_windows+systems_os2+systems_macos then
  2585. begin
  2586. if UnsetBool(More, j, opt, false) then
  2587. SetApptype(app_cui)
  2588. else
  2589. SetApptype(app_gui);
  2590. end
  2591. else
  2592. IllegalPara(opt);
  2593. end;
  2594. {$if defined(i8086)}
  2595. 'h':
  2596. begin
  2597. if UnsetBool(More, j, opt, false) then
  2598. exclude(init_settings.moduleswitches,cs_huge_code)
  2599. else
  2600. include(init_settings.moduleswitches,cs_huge_code);
  2601. end;
  2602. {$endif defined(i8086)}
  2603. 'I':
  2604. begin
  2605. if target_info.system in systems_all_windows then
  2606. begin
  2607. GenerateImportSection:=not UnsetBool(More,j,opt,false);
  2608. GenerateImportSectionSetExplicitly:=true;
  2609. end
  2610. else
  2611. IllegalPara(opt);
  2612. end;
  2613. 'i':
  2614. begin
  2615. if (target_info.system in systems_darwin) then
  2616. begin
  2617. set_target_res(res_macho);
  2618. target_info.resobjext:=
  2619. targetinfos[target_info.system]^.resobjext;
  2620. end
  2621. else
  2622. IllegalPara(opt);
  2623. end;
  2624. 'm':
  2625. begin
  2626. {$if defined(i8086)}
  2627. if (target_info.system in [system_i8086_msdos,system_i8086_win16,system_i8086_embedded]) then
  2628. begin
  2629. case Upper(Copy(More,j+1,255)) of
  2630. 'TINY': init_settings.x86memorymodel:=mm_tiny;
  2631. 'SMALL': init_settings.x86memorymodel:=mm_small;
  2632. 'MEDIUM': init_settings.x86memorymodel:=mm_medium;
  2633. 'COMPACT': init_settings.x86memorymodel:=mm_compact;
  2634. 'LARGE': init_settings.x86memorymodel:=mm_large;
  2635. 'HUGE': init_settings.x86memorymodel:=mm_huge;
  2636. else
  2637. IllegalPara(opt);
  2638. end;
  2639. break;
  2640. end
  2641. else
  2642. {$endif defined(i8086)}
  2643. IllegalPara(opt);
  2644. end;
  2645. 'M':
  2646. begin
  2647. if (target_info.system in (systems_darwin-[system_i386_iphonesim,system_arm_ios,system_aarch64_ios,system_x86_64_iphonesim])) and
  2648. ParseMacVersionMin(MacOSXVersionMin,iPhoneOSVersionMin,'MAC_OS_X_VERSION_MIN_REQUIRED',copy(More,2,255),false) then
  2649. begin
  2650. break;
  2651. end
  2652. else
  2653. IllegalPara(opt);
  2654. end;
  2655. 'N':
  2656. begin
  2657. if target_info.system in systems_all_windows then
  2658. begin
  2659. RelocSection:=UnsetBool(More,j,opt,false);
  2660. RelocSectionSetExplicitly:=true;
  2661. end
  2662. else
  2663. IllegalPara(opt);
  2664. end;
  2665. 'p':
  2666. begin
  2667. {$push}
  2668. {$warn 6018 off} { Unreachable code due to compile time evaluation }
  2669. if ((target_info.system in systems_embedded) or (target_info.system in systems_freertos)) and
  2670. ControllerSupport then
  2671. begin
  2672. s:=upper(copy(more,j+1,length(more)-j));
  2673. if not(SetControllerType(s,init_settings.controllertype)) then
  2674. IllegalPara(opt)
  2675. else
  2676. begin
  2677. if init_settings.cputype<>embedded_controllers[init_settings.controllertype].cputype then
  2678. begin
  2679. Message(scan_n_changecputype);
  2680. init_settings.cputype:=embedded_controllers[init_settings.controllertype].cputype;
  2681. end;
  2682. end;
  2683. break;
  2684. end
  2685. else
  2686. IllegalPara(opt);
  2687. {$pop}
  2688. end;
  2689. 'P':
  2690. begin
  2691. if (target_info.system in [system_i386_iphonesim,system_arm_ios,system_aarch64_ios,system_x86_64_iphonesim]) and
  2692. ParseMacVersionMin(iPhoneOSVersionMin,MacOSXVersionMin,'IPHONE_OS_VERSION_MIN_REQUIRED',copy(More,2,255),true) then
  2693. begin
  2694. break;
  2695. end
  2696. else
  2697. IllegalPara(opt);
  2698. end;
  2699. {$if defined(m68k)}
  2700. 'L':
  2701. begin
  2702. if (target_info.system in [system_m68k_sinclairql]) then
  2703. sinclairql_vlink_experimental:=false
  2704. else
  2705. IllegalPara(opt);
  2706. end;
  2707. 'Q':
  2708. begin
  2709. if (target_info.system in [system_m68k_sinclairql]) then
  2710. begin
  2711. sinclairql_metadata_format:=Upper(Copy(More,j+1,255));
  2712. case sinclairql_metadata_format of
  2713. 'QHDR', 'XTCC': ; { allowed formats }
  2714. else
  2715. IllegalPara(opt);
  2716. end;
  2717. break;
  2718. end
  2719. else
  2720. IllegalPara(opt);
  2721. end;
  2722. {$endif defined(m68k)}
  2723. 'R':
  2724. begin
  2725. if target_info.system in systems_all_windows then
  2726. begin
  2727. { support -WR+ / -WR- as synonyms to -WR / -WN }
  2728. RelocSection:=not UnsetBool(More,j,opt,false);
  2729. RelocSectionSetExplicitly:=true;
  2730. end
  2731. else
  2732. IllegalPara(opt);
  2733. end;
  2734. 't':
  2735. begin
  2736. {$if defined(i8086)}
  2737. if (target_info.system in [system_i8086_msdos,system_i8086_embedded]) then
  2738. begin
  2739. case Upper(Copy(More,j+1,255)) of
  2740. 'EXE': SetAppType(app_cui);
  2741. 'COM': SetAppType(app_com);
  2742. else
  2743. IllegalPara(opt);
  2744. end;
  2745. break;
  2746. end
  2747. else
  2748. {$endif defined(i8086)}
  2749. IllegalPara(opt);
  2750. end;
  2751. 'T':
  2752. begin
  2753. if target_info.system in systems_macos then
  2754. begin
  2755. if UnsetBool(More, j, opt, false) then
  2756. SetApptype(app_cui)
  2757. else
  2758. SetApptype(app_tool);
  2759. end
  2760. else
  2761. IllegalPara(opt);
  2762. end;
  2763. 'X':
  2764. begin
  2765. if (target_info.system in systems_linux) then
  2766. begin
  2767. if UnsetBool(More, j, opt, false) then
  2768. exclude(init_settings.moduleswitches,cs_executable_stack)
  2769. else
  2770. include(init_settings.moduleswitches,cs_executable_stack)
  2771. end
  2772. else
  2773. IllegalPara(opt);
  2774. end;
  2775. else
  2776. IllegalPara(opt);
  2777. end;
  2778. inc(j);
  2779. end;
  2780. end;
  2781. 'X' :
  2782. begin
  2783. j:=1;
  2784. while j<=length(more) do
  2785. begin
  2786. case More[j] of
  2787. '9' :
  2788. begin
  2789. if target_info.system in systems_linux then
  2790. begin
  2791. if UnsetBool(More, j, opt, false) then
  2792. exclude(init_settings.globalswitches,cs_link_pre_binutils_2_19)
  2793. else
  2794. include(init_settings.globalswitches,cs_link_pre_binutils_2_19);
  2795. end
  2796. else
  2797. IllegalPara(opt);
  2798. end;
  2799. 'a' :
  2800. begin
  2801. If UnsetBool(More, j, opt, false) then
  2802. exclude(init_settings.globalswitches,cs_large)
  2803. else
  2804. include(init_settings.globalswitches,cs_large);
  2805. end;
  2806. 'c' : Cshared:=TRUE;
  2807. 'd' : Dontlinkstdlibpath:=TRUE;
  2808. 'e' :
  2809. begin
  2810. If UnsetBool(More, j, opt, false) then
  2811. exclude(init_settings.globalswitches,cs_link_extern)
  2812. else
  2813. include(init_settings.globalswitches,cs_link_extern);
  2814. end;
  2815. 'f' :
  2816. include(init_settings.globalswitches,cs_link_pthread);
  2817. 'g' :
  2818. begin
  2819. If UnsetBool(More, j, opt, false) then
  2820. exclude(init_settings.globalswitches,cs_link_separate_dbg_file)
  2821. else
  2822. include(init_settings.globalswitches,cs_link_separate_dbg_file);
  2823. end;
  2824. 'i' :
  2825. begin
  2826. If UnsetBool(More, j, opt, false) then
  2827. include(init_settings.globalswitches,cs_link_extern)
  2828. else
  2829. exclude(init_settings.globalswitches,cs_link_extern);
  2830. end;
  2831. 'n' :
  2832. begin
  2833. If UnsetBool(More, j, opt, false) then
  2834. exclude(init_settings.globalswitches,cs_link_native)
  2835. else
  2836. include(init_settings.globalswitches,cs_link_native);
  2837. end;
  2838. {$ifdef llvm}
  2839. 'l' :
  2840. begin
  2841. if j=length(more) then
  2842. IllegalPara(opt)
  2843. else
  2844. begin
  2845. case more[j+1] of
  2846. 'S':
  2847. begin
  2848. llvmutilssuffix:=copy(more,j+2,length(more));
  2849. j:=length(more);
  2850. end
  2851. else
  2852. IllegalPara(opt);
  2853. end;
  2854. end;
  2855. end;
  2856. {$endif}
  2857. 'm' :
  2858. begin
  2859. If UnsetBool(More, j, opt, false) then
  2860. exclude(init_settings.globalswitches,cs_link_map)
  2861. else
  2862. include(init_settings.globalswitches,cs_link_map);
  2863. end;
  2864. 'p' : ; { Ignore used by fpc.pp }
  2865. 'r' :
  2866. begin
  2867. if (target_info.system in suppported_targets_x_smallr) then
  2868. begin
  2869. rlinkpath:=Copy(more,2,length(More)-1);
  2870. DefaultReplacements(rlinkpath);
  2871. end
  2872. else
  2873. IgnoredPara('-Xr');
  2874. more:='';
  2875. end;
  2876. 'R' :
  2877. begin
  2878. sysrootpath:=copy(more,2,length(more)-1);
  2879. defaultreplacements(sysrootpath);
  2880. more:='';
  2881. end;
  2882. 's' :
  2883. begin
  2884. If UnsetBool(More, j, opt, false) then
  2885. exclude(init_settings.globalswitches,cs_link_strip)
  2886. else
  2887. include(init_settings.globalswitches,cs_link_strip);
  2888. end;
  2889. 't' :
  2890. include(init_settings.globalswitches,cs_link_staticflag);
  2891. 'u' :
  2892. begin
  2893. if target_info.system in systems_support_uf2 then
  2894. begin
  2895. if UnsetBool(More, j, opt, false) then
  2896. exclude(init_settings.globalswitches,cs_generate_uf2)
  2897. else
  2898. include(init_settings.globalswitches,cs_generate_uf2);
  2899. end
  2900. else
  2901. IgnoredPara('-Xu');
  2902. end;
  2903. 'v' :
  2904. begin
  2905. If UnsetBool(More, j, opt, false) then
  2906. exclude(init_settings.globalswitches,cs_link_opt_vtable)
  2907. else
  2908. include(init_settings.globalswitches,cs_link_opt_vtable);
  2909. end;
  2910. 'D' :
  2911. begin
  2912. def_system_macro('FPC_LINK_DYNAMIC');
  2913. undef_system_macro('FPC_LINK_SMART');
  2914. undef_system_macro('FPC_LINK_STATIC');
  2915. exclude(init_settings.globalswitches,cs_link_static);
  2916. exclude(init_settings.globalswitches,cs_link_smart);
  2917. include(init_settings.globalswitches,cs_link_shared);
  2918. LinkTypeSetExplicitly:=true;
  2919. end;
  2920. 'M' :
  2921. begin
  2922. mainaliasname:=Copy(more,2,length(More)-1);
  2923. More:='';
  2924. end;
  2925. 'P' :
  2926. begin
  2927. utilsprefix:=Copy(more,2,length(More)-1);
  2928. DefaultReplacements(utilsprefix);
  2929. More:='';
  2930. end;
  2931. 'L' : begin // -XLO is link order -XLA is link alias. -XLD avoids load defaults.
  2932. // these are not aggregable.
  2933. if (j=length(more)) or not (more[j+1] in ['O','A','D']) then
  2934. IllegalPara(opt)
  2935. else
  2936. begin
  2937. case more[j+1] of
  2938. 'A' : begin
  2939. s:=Copy(more,3,length(More)-2);
  2940. if not LinkLibraryAliases.AddDep(s) Then
  2941. IllegalPara(opt);
  2942. end;
  2943. 'O' : begin
  2944. s:=Copy(more,3,length(More)-2);
  2945. if not LinkLibraryOrder.AddWeight(s) Then
  2946. IllegalPara(opt);
  2947. end;
  2948. 'D' : include(init_settings.globalswitches,cs_link_no_default_lib_order)
  2949. else
  2950. IllegalPara(opt);
  2951. end; {case}
  2952. j:=length(more);
  2953. end; {else begin}
  2954. end;
  2955. 'S' :
  2956. begin
  2957. ForceStaticLinking;
  2958. end;
  2959. 'V' :
  2960. begin
  2961. if UnsetBool(More, j, opt, false) then
  2962. exclude(init_settings.globalswitches,cs_link_vlink)
  2963. else
  2964. begin
  2965. include(init_settings.globalswitches,cs_link_vlink);
  2966. include(init_settings.globalswitches,cs_link_extern);
  2967. end;
  2968. LinkerSetExplicitly:=true;
  2969. end;
  2970. 'X' :
  2971. begin
  2972. def_system_macro('FPC_LINK_SMART');
  2973. undef_system_macro('FPC_LINK_STATIC');
  2974. undef_system_macro('FPC_LINK_DYNAMIC');
  2975. exclude(init_settings.globalswitches,cs_link_static);
  2976. include(init_settings.globalswitches,cs_link_smart);
  2977. exclude(init_settings.globalswitches,cs_link_shared);
  2978. LinkTypeSetExplicitly:=true;
  2979. end;
  2980. '-' :
  2981. begin
  2982. exclude(init_settings.globalswitches,cs_link_staticflag);
  2983. exclude(init_settings.globalswitches,cs_link_strip);
  2984. exclude(init_settings.globalswitches,cs_link_map);
  2985. set_default_link_type;
  2986. end;
  2987. else
  2988. IllegalPara(opt);
  2989. end;
  2990. inc(j);
  2991. end;
  2992. end;
  2993. else
  2994. IllegalPara(opt);
  2995. end;
  2996. end;
  2997. '@' :
  2998. begin
  2999. Message(option_no_nested_response_file);
  3000. StopOptions(1);
  3001. end;
  3002. else
  3003. begin
  3004. if (length(param_file)<>0) then
  3005. Message2(option_only_one_source_support,param_file,opt);
  3006. param_file:=opt;
  3007. Message1(option_found_file,opt);
  3008. end;
  3009. end;
  3010. end;
  3011. procedure Toption.Interpret_file(const filename : TPathStr);
  3012. procedure RemoveSep(var fn:TPathStr);
  3013. var
  3014. i : longint;
  3015. begin
  3016. i:=0;
  3017. while (i<length(fn)) and (fn[i+1] in [',',' ',#9]) do
  3018. inc(i);
  3019. Delete(fn,1,i);
  3020. i:=length(fn);
  3021. while (i>0) and (fn[i] in [',',' ',#9]) do
  3022. dec(i);
  3023. fn:=copy(fn,1,i);
  3024. end;
  3025. function GetName(var fn:TPathStr):TPathStr;
  3026. var
  3027. i : longint;
  3028. begin
  3029. i:=0;
  3030. while (i<length(fn)) and (fn[i+1] in ['a'..'z','A'..'Z','0'..'9','_','-']) do
  3031. inc(i);
  3032. GetName:=Copy(fn,1,i);
  3033. Delete(fn,1,i);
  3034. end;
  3035. const
  3036. maxlevel = 15;
  3037. var
  3038. f : text;
  3039. s, tmp,
  3040. opts : TCmdStr;
  3041. skip : array[0..maxlevel] of boolean;
  3042. line,
  3043. level : longint;
  3044. option_read : boolean;
  3045. oldfilemode : byte;
  3046. ConfigFile: TPathStr;
  3047. begin
  3048. { avoid infinite loop }
  3049. Inc(FileLevel);
  3050. Option_read:=false;
  3051. If FileLevel>MaxLevel then
  3052. Message(option_too_many_cfg_files);
  3053. if not ParaIncludeCfgPath.FindFile(fileName,true,ConfigFile) then
  3054. ConfigFile := ExpandFileName(filename);
  3055. { Maybe It's Directory ?} //Jaro Change:
  3056. if PathExists(ConfigFile,false) then
  3057. begin
  3058. Message1(option_config_is_dir,filename);
  3059. exit;
  3060. end;
  3061. { open file }
  3062. Message1(option_using_file,filename);
  3063. oldfilemode:=filemode;
  3064. filemode:=0;
  3065. assign(f,ConfigFile);
  3066. {$push}{$I-}
  3067. reset(f);
  3068. {$pop}
  3069. filemode:=oldfilemode;
  3070. if ioresult<>0 then
  3071. begin
  3072. Message1(option_unable_open_file,filename);
  3073. exit;
  3074. end;
  3075. Message1(option_start_reading_configfile,filename);
  3076. fillchar(skip,sizeof(skip),0);
  3077. level:=0;
  3078. line:=0;
  3079. while not eof(f) do
  3080. begin
  3081. readln(f,opts);
  3082. inc(line);
  3083. RemoveSep(opts);
  3084. if (opts<>'') and (opts[1]<>';') then
  3085. begin
  3086. if opts[1]='#' then
  3087. begin
  3088. Message1(option_interpreting_file_option,opts);
  3089. Delete(opts,1,1);
  3090. s:=upper(GetName(opts));
  3091. if (s='SECTION') then
  3092. begin
  3093. RemoveSep(opts);
  3094. s:=upper(GetName(opts));
  3095. if level=0 then
  3096. skip[level]:=not defined_macro(s) or (s='COMMON');
  3097. end
  3098. else
  3099. if (s='IFDEF') then
  3100. begin
  3101. RemoveSep(opts);
  3102. if Level>=maxlevel then
  3103. begin
  3104. Message2(option_too_many_ifdef,filename,tostr(line));
  3105. stopOptions(1);
  3106. end;
  3107. inc(Level);
  3108. skip[level]:=(skip[level-1] or not defined_macro(upper(GetName(opts))));
  3109. end
  3110. else
  3111. if (s='IFNDEF') then
  3112. begin
  3113. RemoveSep(opts);
  3114. if Level>=maxlevel then
  3115. begin
  3116. Message2(option_too_many_ifdef,filename,tostr(line));
  3117. stopOptions(1);
  3118. end;
  3119. inc(Level);
  3120. skip[level]:=(skip[level-1] or defined_macro(upper(GetName(opts))));
  3121. end
  3122. else
  3123. if (s='ELSE') then
  3124. begin
  3125. if Level=0 then
  3126. begin
  3127. Message2(option_else_without_if,filename,tostr(line));
  3128. stopOptions(1);
  3129. end
  3130. else
  3131. skip[level]:=skip[level-1] or (not skip[level])
  3132. end
  3133. else
  3134. if (s='ENDIF') then
  3135. begin
  3136. skip[level]:=false;
  3137. if Level=0 then
  3138. begin
  3139. Message2(option_too_many_endif,filename,tostr(line));
  3140. stopOptions(1);
  3141. end;
  3142. dec(level);
  3143. end
  3144. else
  3145. if (not skip[level]) then
  3146. begin
  3147. if (s='DEFINE') then
  3148. begin
  3149. RemoveSep(opts);
  3150. tmp:= GetName(opts);
  3151. if tmp <> '' then
  3152. def_system_macro(tmp);
  3153. Option_read:=true;
  3154. end
  3155. else
  3156. if (s='UNDEF') then
  3157. begin
  3158. RemoveSep(opts);
  3159. tmp:= GetName(opts);
  3160. if tmp <> '' then
  3161. undef_system_macro(tmp);
  3162. Option_read:=true;
  3163. end
  3164. else
  3165. if (s='WRITE') then
  3166. begin
  3167. Delete(opts,1,1);
  3168. DefaultReplacements(opts);
  3169. WriteLn(opts);
  3170. Option_read:=true;
  3171. end
  3172. else
  3173. if (s='INCLUDE') then
  3174. begin
  3175. Delete(opts,1,1);
  3176. DefaultReplacements(opts);
  3177. Interpret_file(opts);
  3178. Option_read:=true;
  3179. end
  3180. else
  3181. if (s='CFGDIR') then
  3182. begin
  3183. Delete(opts,1,1);
  3184. DefaultReplacements(opts);
  3185. ParaIncludeCfgPath.AddPath(opts,false);
  3186. Option_read:=true;
  3187. end;
  3188. end;
  3189. end
  3190. else
  3191. begin
  3192. if (opts[1]='-') or (opts[1]='@') then
  3193. begin
  3194. if (not skip[level]) then
  3195. interpret_option(opts,false);
  3196. Option_read:=true;
  3197. end
  3198. else
  3199. Message1(option_illegal_para,opts);
  3200. end;
  3201. end;
  3202. end;
  3203. if Level>0 then
  3204. Message(option_too_less_endif);
  3205. if Not Option_read then
  3206. Message1(option_no_option_found,filename)
  3207. else
  3208. Message1(option_end_reading_configfile,filename);
  3209. Close(f);
  3210. Dec(FileLevel);
  3211. end;
  3212. procedure Toption.Interpret_envvar(const envname : TCmdStr);
  3213. var
  3214. argstart,
  3215. env,
  3216. pc : pchar;
  3217. arglen : longint;
  3218. quote : set of char;
  3219. hs : TCmdStr;
  3220. begin
  3221. Message1(option_using_env,envname);
  3222. env:=GetEnvPChar(envname);
  3223. pc:=env;
  3224. hs:='';
  3225. if assigned(pc) then
  3226. begin
  3227. repeat
  3228. { skip leading spaces }
  3229. while pc^ in [' ',#9,#13] do
  3230. inc(pc);
  3231. case pc^ of
  3232. #0 :
  3233. break;
  3234. '"' :
  3235. begin
  3236. quote:=['"'];
  3237. inc(pc);
  3238. end;
  3239. '''' :
  3240. begin
  3241. quote:=[''''];
  3242. inc(pc);
  3243. end;
  3244. else
  3245. quote:=[' ',#9,#13];
  3246. end;
  3247. { scan until the end of the argument }
  3248. argstart:=pc;
  3249. while (pc^<>#0) and not(pc^ in quote) do
  3250. inc(pc);
  3251. { create argument }
  3252. arglen:=pc-argstart;
  3253. { TODO: FIXME: silent truncation of environment parameters }
  3254. if (arglen > 255) then
  3255. arglen := 255;
  3256. setlength(hs,arglen);
  3257. move(argstart^,hs[1],arglen);
  3258. interpret_option(hs,true);
  3259. { skip quote }
  3260. if pc^ in quote then
  3261. inc(pc);
  3262. until false;
  3263. end
  3264. else
  3265. Message1(option_no_option_found,'(env) '+envname);
  3266. FreeEnvPChar(env);
  3267. end;
  3268. procedure toption.read_parameters;
  3269. var
  3270. opts : TCmdStr;
  3271. paramindex : longint;
  3272. begin
  3273. paramindex:=0;
  3274. while paramindex<paramcount do
  3275. begin
  3276. inc(paramindex);
  3277. opts:=objpas.paramstr(paramindex);
  3278. if length(opts)>0 then
  3279. case opts[1] of
  3280. '@' :
  3281. if not firstpass then
  3282. begin
  3283. Delete(opts,1,1);
  3284. Message1(option_reading_further_from,opts);
  3285. interpret_file(opts);
  3286. end;
  3287. '!' :
  3288. if not firstpass then
  3289. begin
  3290. Delete(opts,1,1);
  3291. Message1(option_reading_further_from,'(env) '+opts);
  3292. interpret_envvar(opts);
  3293. end;
  3294. else
  3295. interpret_option(opts,true);
  3296. end;
  3297. end;
  3298. end;
  3299. procedure toption.parsecmd(cmd:TCmdStr);
  3300. var
  3301. i,ps : longint;
  3302. opts : TCmdStr;
  3303. begin
  3304. while (cmd<>'') do
  3305. begin
  3306. while cmd[1]=' ' do
  3307. delete(cmd,1,1);
  3308. i:=pos(' ',cmd);
  3309. if i=0 then
  3310. i:=2147483647;
  3311. opts:=Copy(cmd,1,i-1);
  3312. Delete(cmd,1,i);
  3313. case opts[1] of
  3314. '@' :
  3315. if not firstpass then
  3316. begin
  3317. Delete(opts,1,1);
  3318. Message1(option_reading_further_from,opts);
  3319. interpret_file(opts);
  3320. end;
  3321. '!' :
  3322. if not firstpass then
  3323. begin
  3324. Delete(opts,1,1);
  3325. Message1(option_reading_further_from,'(env) '+opts);
  3326. interpret_envvar(opts);
  3327. end;
  3328. '"' :
  3329. begin
  3330. Delete(opts,1,1);
  3331. ps:=pos('"',cmd);
  3332. if (i<>256) and (ps>0) then
  3333. begin
  3334. opts:=opts + ' '+ copy(cmd,1,ps-1);
  3335. cmd:=copy(cmd,ps+1,255);
  3336. end;
  3337. interpret_option(opts,true);
  3338. end;
  3339. else
  3340. interpret_option(opts,true);
  3341. end;
  3342. end;
  3343. end;
  3344. procedure toption.writequickinfo;
  3345. var
  3346. s : string;
  3347. i : longint;
  3348. procedure addinfo(const hs:string);
  3349. begin
  3350. if s<>'' then
  3351. s:=s+' '+hs
  3352. else
  3353. s:=hs;
  3354. end;
  3355. begin
  3356. s:='';
  3357. i:=0;
  3358. while (i<length(quickinfo)) do
  3359. begin
  3360. inc(i);
  3361. case quickinfo[i] of
  3362. 'S' :
  3363. begin
  3364. inc(i);
  3365. case quickinfo[i] of
  3366. 'O' :
  3367. addinfo(lower(source_info.shortname));
  3368. 'P' :
  3369. addinfo(source_cpu_string);
  3370. else
  3371. IllegalPara('-i'+QuickInfo);
  3372. end;
  3373. end;
  3374. 'T' :
  3375. begin
  3376. inc(i);
  3377. case quickinfo[i] of
  3378. 'O' :
  3379. addinfo(lower(target_info.shortname));
  3380. 'P' :
  3381. AddInfo(target_cpu_string);
  3382. else
  3383. IllegalPara('-i'+QuickInfo);
  3384. end;
  3385. end;
  3386. 'V' :
  3387. AddInfo(version_string);
  3388. 'W' :
  3389. AddInfo(full_version_string);
  3390. 'D' :
  3391. AddInfo(date_string);
  3392. '_' :
  3393. ;
  3394. else
  3395. IllegalPara('-i'+QuickInfo);
  3396. end;
  3397. end;
  3398. if s<>'' then
  3399. begin
  3400. writeln(s);
  3401. stopoptions(0);
  3402. end;
  3403. end;
  3404. procedure TOption.TargetOptions(def:boolean);
  3405. var
  3406. s : string;
  3407. i : integer;
  3408. target_unsup_features : tfeatures;
  3409. begin
  3410. if def then
  3411. def_system_macro(target_info.shortname)
  3412. else
  3413. undef_system_macro(target_info.shortname);
  3414. s:=target_info.extradefines;
  3415. while (s<>'') do
  3416. begin
  3417. i:=pos(';',s);
  3418. if i=0 then
  3419. i:=length(s)+1;
  3420. if def then
  3421. def_system_macro(Copy(s,1,i-1))
  3422. else
  3423. undef_system_macro(Copy(s,1,i-1));
  3424. delete(s,1,i);
  3425. end;
  3426. if (tf_winlikewidestring in target_info.flags) then
  3427. if def then
  3428. def_system_macro('FPC_WINLIKEWIDESTRING')
  3429. else
  3430. undef_system_macro('FPC_WINLIKEWIDESTRING');
  3431. if (tf_requires_proper_alignment in target_info.flags) then
  3432. if def then
  3433. def_system_macro('FPC_REQUIRES_PROPER_ALIGNMENT')
  3434. else
  3435. undef_system_macro('FPC_REQUIRES_PROPER_ALIGNMENT');
  3436. if (tf_init_final_units_by_calls in target_info.flags) then
  3437. if def then
  3438. def_system_macro('FPC_INIT_FINAL_UNITS_BY_CALLS')
  3439. else
  3440. undef_system_macro('FPC_INIT_FINAL_UNITS_BY_CALLS');
  3441. if source_info.system<>target_info.system then
  3442. if def then
  3443. def_system_macro('FPC_CROSSCOMPILING')
  3444. else
  3445. undef_system_macro('FPC_CROSSCOMPILING');
  3446. if source_info.cpu<>target_info.cpu then
  3447. if def then
  3448. def_system_macro('FPC_CPUCROSSCOMPILING')
  3449. else
  3450. def_system_macro('FPC_CPUCROSSCOMPILING');
  3451. if (tf_no_generic_stackcheck in target_info.flags) then
  3452. if def then
  3453. def_system_macro('FPC_NO_GENERIC_STACK_CHECK')
  3454. else
  3455. undef_system_macro('FPC_NO_GENERIC_STACK_CHECK');
  3456. if (tf_section_threadvars in target_info.flags) then
  3457. if def then
  3458. def_system_macro('FPC_SECTION_THREADVARS')
  3459. else
  3460. undef_system_macro('FPC_SECTION_THREADVARS');
  3461. if (tf_use_psabieh in target_info.flags) then
  3462. if def then
  3463. def_system_macro('FPC_USE_PSABIEH')
  3464. else
  3465. undef_system_macro('FPC_USE_PSABIEH');
  3466. { Code generation flags }
  3467. if (tf_pic_default in target_info.flags) then
  3468. if def then
  3469. include(init_settings.moduleswitches,cs_create_pic)
  3470. else
  3471. exclude(init_settings.moduleswitches,cs_create_pic);
  3472. { Resources support }
  3473. if (tf_has_winlike_resources in target_info.flags) then
  3474. if def then
  3475. def_system_macro('FPC_HAS_WINLIKERESOURCES')
  3476. else
  3477. undef_system_macro('FPC_HAS_WINLIKERESOURCES');
  3478. { Features }
  3479. case target_info.system of
  3480. system_arm_gba:
  3481. target_unsup_features:=[f_dynlibs];
  3482. system_arm_nds:
  3483. target_unsup_features:=[f_threading,f_commandargs,f_fileio,f_textio,f_consoleio,f_dynlibs];
  3484. system_i386_nativent:
  3485. // until these features are implemented, they are disabled in the compiler
  3486. target_unsup_features:=[f_stackcheck];
  3487. system_i8086_msdos:
  3488. target_unsup_features:=[f_threading,f_dynlibs];
  3489. system_i8086_win16:
  3490. target_unsup_features:=[f_threading];
  3491. system_jvm_java32,
  3492. system_jvm_android32:
  3493. target_unsup_features:=[f_heap,f_textio,f_consoleio,f_fileio,
  3494. f_variants,f_objects,f_commandargs,
  3495. f_processes,f_stackcheck,f_dynlibs,f_softfpu,f_objectivec1,f_resources];
  3496. system_arm_palmos,
  3497. system_m68k_palmos:
  3498. target_unsup_features:=[f_threading];
  3499. system_m68k_atari:
  3500. target_unsup_features:=[f_threading];
  3501. { classic amiga has dynamic libraries, but they cannot be integrated in the
  3502. normal dynlibs infrastructure due to architectural differences, so therefore
  3503. lets disable the feature. }
  3504. system_m68k_amiga:
  3505. target_unsup_features:=[f_dynlibs];
  3506. system_m68k_sinclairql:
  3507. target_unsup_features:=[f_threading,f_dynlibs];
  3508. system_z80_zxspectrum:
  3509. target_unsup_features:=[f_threading,f_dynlibs{,f_fileio,f_textio},f_commandargs,f_exitcode];
  3510. system_z80_msxdos:
  3511. target_unsup_features:=[f_threading,f_dynlibs];
  3512. else
  3513. target_unsup_features:=[];
  3514. end;
  3515. if def then
  3516. features:=features-target_unsup_features
  3517. else
  3518. features:=features+target_unsup_features;
  3519. {$if defined(atari) or defined(hasamiga)}
  3520. { enable vlink as default linker on Atari and Amiga but not for cross compilers (for now) }
  3521. if (target_info.system in [system_m68k_amiga,system_m68k_atari,system_powerpc_amiga]) and
  3522. not LinkerSetExplicitly then
  3523. include(init_settings.globalswitches,cs_link_vlink);
  3524. {$endif}
  3525. {$ifdef m68k}
  3526. if (target_info.system in [system_m68k_sinclairql]) and
  3527. not LinkerSetExplicitly then
  3528. include(init_settings.globalswitches,cs_link_vlink);
  3529. {$endif m68k}
  3530. end;
  3531. procedure TOption.checkoptionscompatibility;
  3532. begin
  3533. {$ifdef wasm}
  3534. if (Ord(ts_wasm_no_exceptions in init_settings.targetswitches)+
  3535. Ord(ts_wasm_js_exceptions in init_settings.targetswitches)+
  3536. Ord(ts_wasm_native_exceptions in init_settings.targetswitches)+
  3537. Ord(ts_wasm_bf_exceptions in init_settings.targetswitches))>1 then
  3538. begin
  3539. Message(option_too_many_exception_modes);
  3540. StopOptions(1);
  3541. end;
  3542. {$endif}
  3543. {$ifdef i8086}
  3544. if (apptype=app_com) and (init_settings.x86memorymodel<>mm_tiny) then
  3545. begin
  3546. Message(option_com_files_require_tiny_model);
  3547. StopOptions(1);
  3548. end;
  3549. {$endif i8086}
  3550. {$ifndef i8086_link_intern_debuginfo}
  3551. if (cs_debuginfo in init_settings.moduleswitches) and
  3552. (target_info.system in [system_i8086_msdos,system_i8086_win16,system_i8086_embedded]) and
  3553. not (cs_link_extern in init_settings.globalswitches) then
  3554. begin
  3555. Message(option_debug_info_requires_external_linker);
  3556. include(init_settings.globalswitches,cs_link_extern);
  3557. end;
  3558. {$endif i8086_link_intern_debuginfo}
  3559. if (paratargetdbg in [dbg_dwarf2,dbg_dwarf3]) and
  3560. not(target_info.system in (systems_darwin+[system_i8086_msdos,system_i8086_embedded])) then
  3561. begin
  3562. { smartlink creation does not yet work with DWARF
  3563. debug info on most targets, but it works in internal assembler }
  3564. if (cs_create_smart in init_settings.moduleswitches) and
  3565. not (af_outputbinary in target_asm.flags) then
  3566. begin
  3567. Message(option_dwarf_smartlink_creation);
  3568. exclude(init_settings.moduleswitches,cs_create_smart);
  3569. end;
  3570. { smart linking does not yet work with DWARF debug info on most targets }
  3571. if (cs_link_smart in init_settings.globalswitches) then
  3572. begin
  3573. Message(option_dwarf_smart_linking);
  3574. ForceStaticLinking;
  3575. end;
  3576. end;
  3577. { external debug info is only supported for DWARF on darwin }
  3578. if (target_info.system in systems_darwin) and
  3579. (cs_link_separate_dbg_file in init_settings.globalswitches) and
  3580. not(paratargetdbg in [dbg_dwarf2,dbg_dwarf3]) then
  3581. begin
  3582. Message(option_debug_external_unsupported);
  3583. exclude(init_settings.globalswitches,cs_link_separate_dbg_file);
  3584. end;
  3585. { Also create a smartlinked version, on an assembler that
  3586. does not support smartlink sections like nasm?
  3587. This is not compatible with using internal linker. }
  3588. if ((cs_link_smart in init_settings.globalswitches) or
  3589. (cs_create_smart in init_settings.moduleswitches)) and
  3590. (af_needar in target_asm.flags) and
  3591. not (af_smartlink_sections in target_asm.flags) and
  3592. not (cs_link_extern in init_settings.globalswitches) and
  3593. (target_info.link<>ld_none) and
  3594. not (cs_link_nolink in init_settings.globalswitches) then
  3595. begin
  3596. Message(option_smart_link_requires_external_linker);
  3597. include(init_settings.globalswitches,cs_link_extern);
  3598. end;
  3599. end;
  3600. constructor TOption.create;
  3601. begin
  3602. LogoWritten:=false;
  3603. NoPressEnter:=false;
  3604. FirstPass:=false;
  3605. ABISetExplicitly:=false;
  3606. FPUSetExplicitly:=false;
  3607. CPUSetExplicitly:=false;
  3608. OptCPUSetExplicitly:=false;
  3609. FileLevel:=0;
  3610. Quickinfo:='';
  3611. ParaIncludeCfgPath:=TSearchPathList.Create;
  3612. ParaIncludePath:=TSearchPathList.Create;
  3613. ParaObjectPath:=TSearchPathList.Create;
  3614. ParaUnitPath:=TSearchPathList.Create;
  3615. ParaLibraryPath:=TSearchPathList.Create;
  3616. ParaFrameworkPath:=TSearchPathList.Create;
  3617. parapackagepath:=TSearchPathList.Create;
  3618. parapackages:=TFPHashObjectList.Create;
  3619. paranamespaces:=TCmdStrList.Create;
  3620. FillChar(ParaAlignment,sizeof(ParaAlignment),0);
  3621. MacVersionSet:=false;
  3622. paratarget:=system_none;
  3623. paratargetasm:=as_none;
  3624. paratargetdbg:=dbg_none;
  3625. LinkTypeSetExplicitly:=false;
  3626. LinkerSetExplicitly:=false;
  3627. end;
  3628. destructor TOption.destroy;
  3629. begin
  3630. ParaIncludeCfgPath.Free;
  3631. ParaIncludePath.Free;
  3632. ParaObjectPath.Free;
  3633. ParaUnitPath.Free;
  3634. ParaLibraryPath.Free;
  3635. ParaFrameworkPath.Free;
  3636. parapackagepath.Free;
  3637. ParaPackages.Free;
  3638. paranamespaces.free;
  3639. end;
  3640. {****************************************************************************
  3641. Callable Routines
  3642. ****************************************************************************}
  3643. function check_configfile(fn:string; var foundfn:string):boolean;
  3644. function CfgFileExists(const fn:string):boolean;
  3645. begin
  3646. Comment(V_Tried,'Configfile search: '+fn);
  3647. CfgFileExists:=FileExists(fn);
  3648. end;
  3649. var
  3650. {$ifdef Unix}
  3651. hs,
  3652. {$endif Unix}
  3653. configpath : string;
  3654. begin
  3655. foundfn:=fn;
  3656. check_configfile:=true;
  3657. { retrieve configpath }
  3658. configpath:=FixPath(GetEnvironmentVariable('PPC_CONFIG_PATH'),false);
  3659. {$ifdef Unix}
  3660. if configpath='' then
  3661. configpath:=ExpandFileName(FixPath(exepath+'../etc/',false));
  3662. {$endif}
  3663. {
  3664. Order to read configuration file :
  3665. try reading fpc.cfg in :
  3666. 1 - current dir
  3667. 2 - configpath
  3668. 3 - compiler path
  3669. }
  3670. if not FileExists(fn) then
  3671. begin
  3672. {$ifdef Unix}
  3673. hs:=GetEnvironmentVariable('HOME');
  3674. if (hs<>'') and CfgFileExists(FixPath(hs,false)+'.'+fn) then
  3675. foundfn:=FixPath(hs,false)+'.'+fn
  3676. else
  3677. {$endif}
  3678. if CfgFileExists(configpath+fn) then
  3679. foundfn:=configpath+fn
  3680. else
  3681. {$ifdef WINDOWS}
  3682. if (GetEnvironmentVariable('USERPROFILE')<>'') and CfgFileExists(FixPath(GetEnvironmentVariable('USERPROFILE'),false)+fn) then
  3683. foundfn:=FixPath(GetEnvironmentVariable('USERPROFILE'),false)+fn
  3684. else
  3685. if (GetEnvironmentVariable('ALLUSERSPROFILE')<>'') and CfgFileExists(FixPath(GetEnvironmentVariable('ALLUSERSPROFILE'),false)+fn) then
  3686. foundfn:=FixPath(GetEnvironmentVariable('ALLUSERSPROFILE'),false)+fn
  3687. else
  3688. {$endif WINDOWS}
  3689. {$ifndef Unix}
  3690. if CfgFileExists(exepath+fn) then
  3691. foundfn:=exepath+fn
  3692. else
  3693. {$else}
  3694. if CfgFileExists('/etc/'+fn) then
  3695. foundfn:='/etc/'+fn
  3696. else
  3697. {$endif}
  3698. check_configfile:=false;
  3699. end;
  3700. end;
  3701. procedure read_arguments(cmd:TCmdStr);
  3702. procedure def_cpu_macros;
  3703. var
  3704. abi : tabi;
  3705. fputype : tfputype;
  3706. cputype : tcputype;
  3707. controller: tcontrollertype;
  3708. s: string;
  3709. begin
  3710. {$ifdef llvm}
  3711. def_system_macro('CPULLVM');
  3712. {$endif}
  3713. for cputype:=low(tcputype) to high(tcputype) do
  3714. undef_system_macro('CPU'+Cputypestr[cputype]);
  3715. def_system_macro('CPU'+Cputypestr[init_settings.cputype]);
  3716. for fputype:=low(tfputype) to high(tfputype) do
  3717. undef_system_macro('FPU'+fputypestr[fputype]);
  3718. def_system_macro('FPU'+fputypestr[init_settings.fputype]);
  3719. {$PUSH}
  3720. {$WARN 6018 OFF} { Unreachable code due to compile time evaluation }
  3721. if ControllerSupport then
  3722. begin
  3723. for controller:=low(tcontrollertype) to high(tcontrollertype) do
  3724. begin
  3725. s:=embedded_controllers[controller].controllertypestr;
  3726. if s<>'' then
  3727. undef_system_macro('FPC_MCU_'+s);
  3728. end;
  3729. s:=embedded_controllers[init_settings.controllertype].controllertypestr;
  3730. if s<>'' then
  3731. def_system_macro('FPC_MCU_'+s);
  3732. end;
  3733. {$POP}
  3734. { define abi }
  3735. for abi:=low(tabi) to high(tabi) do
  3736. undef_system_macro('FPC_ABI_'+abiinfo[abi].name);
  3737. def_system_macro('FPC_ABI_'+abiinfo[target_info.abi].name);
  3738. { Define FPC_ABI_EABI in addition to FPC_ABI_EABIHF on EABI VFP hardfloat
  3739. systems since most code needs to behave the same on both}
  3740. if target_info.abi = abi_eabihf then
  3741. def_system_macro('FPC_ABI_EABI');
  3742. { using a case is pretty useless here (FK) }
  3743. { some stuff for TP compatibility }
  3744. {$ifdef i386}
  3745. def_system_macro('CPU86');
  3746. def_system_macro('CPU87');
  3747. def_system_macro('CPU386');
  3748. {$endif}
  3749. { new processor stuff }
  3750. {$ifdef i386}
  3751. def_system_macro('CPUI386');
  3752. def_system_macro('CPU32');
  3753. def_system_macro('CPUX86');
  3754. def_system_macro('FPC_HAS_TYPE_EXTENDED');
  3755. def_system_macro('FPC_HAS_TYPE_DOUBLE');
  3756. def_system_macro('FPC_HAS_TYPE_SINGLE');
  3757. {$endif}
  3758. {$ifdef m68k}
  3759. def_system_macro('CPU68');
  3760. def_system_macro('CPU68K');
  3761. def_system_macro('CPUM68K');
  3762. def_system_macro('CPU32');
  3763. def_system_macro('FPC_CURRENCY_IS_INT64');
  3764. def_system_macro('FPC_COMP_IS_INT64');
  3765. {$endif}
  3766. {$ifdef powerpc}
  3767. def_system_macro('CPUPOWERPC');
  3768. def_system_macro('CPUPOWERPC32');
  3769. def_system_macro('CPU32');
  3770. def_system_macro('FPC_CURRENCY_IS_INT64');
  3771. def_system_macro('FPC_COMP_IS_INT64');
  3772. {$endif}
  3773. {$ifdef POWERPC64}
  3774. def_system_macro('CPUPOWERPC');
  3775. def_system_macro('CPUPOWERPC64');
  3776. def_system_macro('CPU64');
  3777. def_system_macro('FPC_CURRENCY_IS_INT64');
  3778. def_system_macro('FPC_COMP_IS_INT64');
  3779. {$endif}
  3780. {$ifdef x86_64}
  3781. def_system_macro('CPUX86_64');
  3782. def_system_macro('CPUAMD64');
  3783. def_system_macro('CPU64');
  3784. def_system_macro('CPUX64');
  3785. { not supported for now, afaik (FK)
  3786. def_system_macro('FPC_HAS_TYPE_FLOAT128'); }
  3787. {$ifndef FPC_SUPPORT_X87_TYPES_ON_WIN64}
  3788. { normally, win64 doesn't support the legacy fpu }
  3789. if target_info.system=system_x86_64_win64 then
  3790. begin
  3791. def_system_macro('FPC_CURRENCY_IS_INT64');
  3792. def_system_macro('FPC_COMP_IS_INT64');
  3793. end;
  3794. {$endif FPC_SUPPORT_X87_TYPES_ON_WIN64}
  3795. {$endif}
  3796. {$ifdef sparc}
  3797. def_system_macro('CPUSPARCGEN');
  3798. def_system_macro('CPUSPARC');
  3799. def_system_macro('CPUSPARC32');
  3800. def_system_macro('CPU32');
  3801. def_system_macro('FPC_CURRENCY_IS_INT64');
  3802. def_system_macro('FPC_COMP_IS_INT64');
  3803. {$endif}
  3804. {$ifdef sparc64}
  3805. def_system_macro('CPUSPARCGEN');
  3806. def_system_macro('CPUSPARC64');
  3807. def_system_macro('CPU64');
  3808. def_system_macro('FPC_CURRENCY_IS_INT64');
  3809. def_system_macro('FPC_COMP_IS_INT64');
  3810. {$endif}
  3811. {$ifdef arm}
  3812. def_system_macro('CPUARM');
  3813. def_system_macro('CPU32');
  3814. def_system_macro('FPC_CURRENCY_IS_INT64');
  3815. def_system_macro('FPC_COMP_IS_INT64');
  3816. {$endif arm}
  3817. {$ifdef avr}
  3818. def_system_macro('CPUAVR');
  3819. def_system_macro('CPU16');
  3820. def_system_macro('FPC_CURRENCY_IS_INT64');
  3821. def_system_macro('FPC_COMP_IS_INT64');
  3822. {$endif avr}
  3823. {$ifdef jvm}
  3824. def_system_macro('CPUJVM');
  3825. def_system_macro('CPU32');
  3826. def_system_macro('FPC_CURRENCY_IS_INT64');
  3827. def_system_macro('FPC_COMP_IS_INT64');
  3828. {$endif jvm}
  3829. {$ifdef mipsel}
  3830. def_system_macro('CPUMIPS');
  3831. def_system_macro('CPUMIPS32');
  3832. def_system_macro('CPUMIPSEL');
  3833. def_system_macro('CPUMIPSEL32');
  3834. def_system_macro('CPU32');
  3835. def_system_macro('FPC_HAS_TYPE_DOUBLE');
  3836. def_system_macro('FPC_HAS_TYPE_SINGLE');
  3837. def_system_macro('FPC_INCLUDE_SOFTWARE_INT64_TO_DOUBLE');
  3838. def_system_macro('FPC_CURRENCY_IS_INT64');
  3839. def_system_macro('FPC_COMP_IS_INT64');
  3840. def_system_macro('FPC_REQUIRES_PROPER_ALIGNMENT');
  3841. { On most systems, locals are accessed relative to base pointer,
  3842. but for MIPS cpu, they are accessed relative to stack pointer.
  3843. This needs adaptation for so low level routines,
  3844. like MethodPointerLocal and related objects unit functions. }
  3845. def_system_macro('FPC_LOCALS_ARE_STACK_REG_RELATIVE');
  3846. {$endif mipsel}
  3847. {$ifdef mipseb}
  3848. def_system_macro('CPUMIPS');
  3849. def_system_macro('CPUMIPS32');
  3850. def_system_macro('CPUMIPSEB');
  3851. def_system_macro('CPUMIPSEB32');
  3852. def_system_macro('CPU32');
  3853. def_system_macro('FPC_HAS_TYPE_DOUBLE');
  3854. def_system_macro('FPC_HAS_TYPE_SINGLE');
  3855. def_system_macro('FPC_INCLUDE_SOFTWARE_INT64_TO_DOUBLE');
  3856. def_system_macro('FPC_CURRENCY_IS_INT64');
  3857. def_system_macro('FPC_COMP_IS_INT64');
  3858. def_system_macro('FPC_REQUIRES_PROPER_ALIGNMENT');
  3859. { See comment above for mipsel }
  3860. def_system_macro('FPC_LOCALS_ARE_STACK_REG_RELATIVE');
  3861. {$endif}
  3862. {$ifdef i8086}
  3863. def_system_macro('CPU86'); { Borland compatibility }
  3864. def_system_macro('CPU87'); { Borland compatibility }
  3865. def_system_macro('CPUI8086');
  3866. def_system_macro('CPU16');
  3867. def_system_macro('FPC_HAS_TYPE_EXTENDED');
  3868. def_system_macro('FPC_HAS_TYPE_DOUBLE');
  3869. def_system_macro('FPC_HAS_TYPE_SINGLE');
  3870. case init_settings.x86memorymodel of
  3871. mm_tiny: def_system_macro('FPC_MM_TINY');
  3872. mm_small: def_system_macro('FPC_MM_SMALL');
  3873. mm_medium: def_system_macro('FPC_MM_MEDIUM');
  3874. mm_compact: def_system_macro('FPC_MM_COMPACT');
  3875. mm_large: def_system_macro('FPC_MM_LARGE');
  3876. mm_huge: def_system_macro('FPC_MM_HUGE');
  3877. end;
  3878. {$endif i8086}
  3879. {$ifdef aarch64}
  3880. def_system_macro('CPUAARCH64');
  3881. def_system_macro('CPU64');
  3882. def_system_macro('FPC_CURRENCY_IS_INT64');
  3883. def_system_macro('FPC_COMP_IS_INT64');
  3884. {$endif aarch64}
  3885. {$ifdef riscv32}
  3886. def_system_macro('CPURISCV');
  3887. def_system_macro('CPURISCV32');
  3888. def_system_macro('CPU32');
  3889. def_system_macro('FPC_CURRENCY_IS_INT64');
  3890. def_system_macro('FPC_COMP_IS_INT64');
  3891. def_system_macro('FPC_REQUIRES_PROPER_ALIGNMENT');
  3892. {$endif riscv32}
  3893. {$ifdef riscv64}
  3894. def_system_macro('CPURISCV');
  3895. def_system_macro('CPURISCV64');
  3896. def_system_macro('CPU64');
  3897. def_system_macro('FPC_CURRENCY_IS_INT64');
  3898. def_system_macro('FPC_COMP_IS_INT64');
  3899. def_system_macro('FPC_REQUIRES_PROPER_ALIGNMENT');
  3900. {$endif riscv64}
  3901. {$ifdef xtensa}
  3902. def_system_macro('CPUXTENSA');
  3903. def_system_macro('CPU32');
  3904. def_system_macro('FPC_CURRENCY_IS_INT64');
  3905. def_system_macro('FPC_COMP_IS_INT64');
  3906. def_system_macro('FPC_REQUIRES_PROPER_ALIGNMENT');
  3907. {$endif xtensa}
  3908. {$ifdef z80}
  3909. def_system_macro('CPUZ80');
  3910. def_system_macro('CPU16');
  3911. def_system_macro('FPC_CURRENCY_IS_INT64');
  3912. def_system_macro('FPC_COMP_IS_INT64');
  3913. {$endif z80}
  3914. {$ifdef wasm32}
  3915. def_system_macro('CPUWASM');
  3916. def_system_macro('CPUWASM32');
  3917. def_system_macro('CPU32');
  3918. def_system_macro('FPC_CURRENCY_IS_INT64');
  3919. def_system_macro('FPC_COMP_IS_INT64');
  3920. {$endif wasm32}
  3921. {$if defined(cpu8bitalu)}
  3922. def_system_macro('CPUINT8');
  3923. {$elseif defined(cpu16bitalu)}
  3924. def_system_macro('CPUINT16');
  3925. {$elseif defined(cpu32bitalu)}
  3926. def_system_macro('CPUINT32');
  3927. {$elseif defined(cpu64bitalu)}
  3928. def_system_macro('CPUINT64');
  3929. {$endif defined(cpu64bitalu)}
  3930. {$if defined(avr)}
  3931. def_system_macro('FPC_HAS_INTERNAL_ABS_SHORTINT');
  3932. {$endif}
  3933. {$if defined(i8086) or defined(avr)}
  3934. def_system_macro('FPC_HAS_INTERNAL_ABS_SMALLINT');
  3935. {$endif i8086 or avr}
  3936. { abs(long) is handled internally on all CPUs }
  3937. def_system_macro('FPC_HAS_INTERNAL_ABS_LONG');
  3938. {$if defined(i8086) or defined(i386) or defined(x86_64) or defined(powerpc64) or defined(aarch64)}
  3939. def_system_macro('FPC_HAS_INTERNAL_ABS_INT64');
  3940. {$endif i8086 or i386 or x86_64 or powerpc64 or aarch64}
  3941. def_system_macro('FPC_HAS_UNICODESTRING');
  3942. def_system_macro('FPC_RTTI_PACKSET1');
  3943. def_system_macro('FPC_HAS_CPSTRING');
  3944. {$ifdef x86_64}
  3945. def_system_macro('FPC_HAS_RIP_RELATIVE');
  3946. {$endif x86_64}
  3947. def_system_macro('FPC_HAS_CEXTENDED');
  3948. def_system_macro('FPC_HAS_RESSTRINITS');
  3949. { these cpus have an inline rol/ror implementaion }
  3950. {$ifdef cpurox}
  3951. {$ifdef m68k}
  3952. if CPUM68K_HAS_ROLROR in cpu_capabilities[init_settings.cputype] then
  3953. def_system_macro('FPC_HAS_INTERNAL_ROX');
  3954. {$else}
  3955. def_system_macro('FPC_HAS_INTERNAL_ROX');
  3956. {$endif}
  3957. {$endif}
  3958. {$ifdef powerpc64}
  3959. def_system_macro('FPC_HAS_LWSYNC');
  3960. {$endif}
  3961. { currently, all supported CPUs have an internal sar implementation }
  3962. def_system_macro('FPC_HAS_INTERNAL_SAR');
  3963. {$ifdef SUPPORT_GET_FRAME}
  3964. def_system_macro('INTERNAL_BACKTRACE');
  3965. {$endif SUPPORT_GET_FRAME}
  3966. def_system_macro('STR_CONCAT_PROCS');
  3967. {$warnings off}
  3968. if pocall_default = pocall_register then
  3969. def_system_macro('REGCALL');
  3970. {$warnings on}
  3971. end;
  3972. var
  3973. env: ansistring;
  3974. i : tfeature;
  3975. j : longint;
  3976. tmplist : TCmdStrList;
  3977. cmditem,
  3978. tmpcmditem : TCmdStrListItem;
  3979. cmdstr : TCmdStr;
  3980. {$if defined(cpucapabilities)}
  3981. cpuflag : tcpuflags;
  3982. {$endif defined(cpucapabilities)}
  3983. {$if defined(fpucapabilities)}
  3984. fpuflag : tfpuflags;
  3985. {$endif defined(fpucapabilities)}
  3986. {$if defined(cpucapabilities) or defined(fpucapabilities)}
  3987. hs : string;
  3988. {$endif defined(cpucapabilities) or defined(fpucapabilities)}
  3989. begin
  3990. option:=coption.create;
  3991. disable_configfile:=false;
  3992. { Non-core target defines }
  3993. Option.TargetOptions(true);
  3994. { get default messagefile }
  3995. msgfilename:=GetEnvironmentVariable('PPC_ERROR_FILE');
  3996. { default configfile can be specified on the commandline,
  3997. remove it first }
  3998. if (cmd<>'') and (cmd[1]='[') then
  3999. begin
  4000. ppccfg:=Copy(cmd,2,pos(']',cmd)-2);
  4001. Delete(cmd,1,pos(']',cmd));
  4002. end
  4003. else
  4004. ppccfg:='fpc.cfg';
  4005. { first pass reading of parameters, only -i -v -T etc.}
  4006. option.firstpass:=true;
  4007. if cmd<>'' then
  4008. option.parsecmd(cmd)
  4009. else
  4010. begin
  4011. option.read_parameters;
  4012. { Write only quickinfo }
  4013. if option.quickinfo<>'' then
  4014. option.writequickinfo;
  4015. end;
  4016. option.firstpass:=false;
  4017. { redefine target options so all defines are written even if no -Txxx is passed on the command line }
  4018. Option.TargetOptions(true);
  4019. { target is set here, for wince the default app type is gui }
  4020. if target_info.system in systems_wince then
  4021. SetApptype(app_gui)
  4022. else
  4023. SetApptype(apptype);
  4024. { default defines }
  4025. def_system_macro(target_info.shortname);
  4026. def_system_macro('FPC');
  4027. def_system_macro('VER'+version_nr);
  4028. def_system_macro('VER'+version_nr+'_'+release_nr);
  4029. def_system_macro('VER'+version_nr+'_'+release_nr+'_'+patch_nr);
  4030. { Temporary defines, until things settle down }
  4031. def_system_macro('FPC_HAS_OPERATOR_ENUMERATOR');
  4032. def_system_macro('FPC_HAS_CONSTREF');
  4033. def_system_macro('FPC_STATICRIPFIXED');
  4034. def_system_macro('FPC_VARIANTCOPY_FIXED');
  4035. def_system_macro('FPC_DYNARRAYCOPY_FIXED');
  4036. def_system_macro('FPC_HAS_MEMBAR');
  4037. def_system_macro('FPC_SETBASE_USED');
  4038. def_system_macro('FPC_ALIGNED_THREADVARTABLES');
  4039. { don't remove this, it's also for fpdoc necessary (FK) }
  4040. def_system_macro('FPC_HAS_FEATURE_SUPPORT');
  4041. { make cpu makros available when reading the config files the second time }
  4042. def_cpu_macros;
  4043. if tf_cld in target_info.flags then
  4044. if not UpdateTargetSwitchStr('CLD', init_settings.targetswitches, true) then
  4045. InternalError(2013092801);
  4046. if tf_x86_far_procs_push_odd_bp in target_info.flags then
  4047. if not UpdateTargetSwitchStr('FARPROCSPUSHODDBP', init_settings.targetswitches, true) then
  4048. InternalError(2013092802);
  4049. { Use standard Android NDK prefixes when cross-compiling }
  4050. if (source_info.system<>target_info.system) and (target_info.system in systems_android) then
  4051. case target_info.system of
  4052. system_arm_android:
  4053. utilsprefix:='arm-linux-androideabi-';
  4054. system_i386_android:
  4055. utilsprefix:='i686-linux-android-';
  4056. else
  4057. utilsprefix:=target_cpu_string + '-linux-android-';
  4058. end;
  4059. { Set up default value for the heap }
  4060. if target_info.system in (systems_embedded+systems_freertos+[system_z80_zxspectrum,system_z80_msxdos]) then
  4061. begin
  4062. case target_info.system of
  4063. {$ifdef AVR}
  4064. system_avr_embedded:
  4065. if init_settings.controllertype=ct_avrsim then
  4066. heapsize:=8192
  4067. else
  4068. heapsize:=128;
  4069. {$endif AVR}
  4070. system_arm_freertos:
  4071. heapsize:=8192;
  4072. system_xtensa_freertos:
  4073. { keep default value }
  4074. ;
  4075. system_arm_embedded:
  4076. heapsize:=256;
  4077. system_mipsel_embedded:
  4078. heapsize:=256;
  4079. else
  4080. heapsize:=256;
  4081. end;
  4082. end;
  4083. { read configuration file }
  4084. if (not disable_configfile) and
  4085. (ppccfg<>'') then
  4086. read_configfile:=check_configfile(ppccfg,ppccfg)
  4087. else
  4088. read_configfile := false;
  4089. { Read commandline and configfile }
  4090. param_file:='';
  4091. { read configfile }
  4092. if read_configfile then
  4093. option.interpret_file(ppccfg);
  4094. { read parameters again to override config file }
  4095. if cmd<>'' then
  4096. option.parsecmd(cmd)
  4097. else
  4098. begin
  4099. { Write help pages if no parameters are passed }
  4100. if (paramcount=0) then
  4101. Option.WriteHelpPages;
  4102. option.read_parameters;
  4103. { Write only quickinfo }
  4104. if option.quickinfo<>'' then
  4105. option.writequickinfo;
  4106. end;
  4107. { check the compatibility of different options and adjust them if necessary
  4108. (and print possible errors)
  4109. }
  4110. option.checkoptionscompatibility;
  4111. { uses the CPUXXX-defines and target_info to determine whether the selected
  4112. target processor, if any, is supported }
  4113. Option.VerifyTargetProcessor;
  4114. { Stop if errors in options }
  4115. if ErrorCount>0 then
  4116. StopOptions(1);
  4117. { endian define }
  4118. case target_info.endian of
  4119. endian_little :
  4120. begin
  4121. def_system_macro('ENDIAN_LITTLE');
  4122. def_system_macro('FPC_LITTLE_ENDIAN');
  4123. end;
  4124. endian_big :
  4125. begin
  4126. def_system_macro('ENDIAN_BIG');
  4127. def_system_macro('FPC_BIG_ENDIAN');
  4128. end;
  4129. end;
  4130. { Write logo }
  4131. if option.ParaLogo then
  4132. option.writelogo;
  4133. { Check file to compile }
  4134. if param_file='' then
  4135. begin
  4136. Message(option_no_source_found);
  4137. StopOptions(1);
  4138. end;
  4139. {$ifndef Unix}
  4140. param_file:=FixFileName(param_file);
  4141. {$endif not unix}
  4142. inputfilepath:=ExtractFilePath(param_file);
  4143. inputfilename:=ExtractFileName(param_file);
  4144. if ExtractFileExt(inputfilename)='' then
  4145. begin
  4146. if FileExists(inputfilepath+ChangeFileExt(inputfilename,sourceext)) then
  4147. inputfilename:=ChangeFileExt(inputfilename,sourceext)
  4148. else if FileExists(inputfilepath+ChangeFileExt(inputfilename,pasext)) then
  4149. inputfilename:=ChangeFileExt(inputfilename,pasext)
  4150. else if ((m_mac in current_settings.modeswitches) or
  4151. (tf_p_ext_support in target_info.flags))
  4152. and FileExists(inputfilepath+ChangeFileExt(inputfilename,pext)) then
  4153. inputfilename:=ChangeFileExt(inputfilename,pext);
  4154. end;
  4155. { Check output dir }
  4156. if (OutputExeDir<>'') and
  4157. not PathExists(OutputExeDir,false) then
  4158. begin
  4159. Message1(general_e_path_does_not_exist,OutputExeDir);
  4160. StopOptions(1);
  4161. end;
  4162. { Add paths specified with parameters to the searchpaths }
  4163. UnitSearchPath.AddList(option.ParaUnitPath,true);
  4164. ObjectSearchPath.AddList(option.ParaObjectPath,true);
  4165. IncludeSearchPath.AddList(option.ParaIncludePath,true);
  4166. LibrarySearchPath.AddList(option.ParaLibraryPath,true);
  4167. FrameworkSearchPath.AddList(option.ParaFrameworkPath,true);
  4168. packagesearchpath.addlist(option.parapackagepath,true);
  4169. for j:=0 to option.parapackages.count-1 do
  4170. add_package(option.parapackages.NameOfIndex(j),true,true);
  4171. { add default namespaces }
  4172. tmplist:=TCmdStrList.Create;
  4173. cmditem:=TCmdStrListItem(option.paranamespaces.First);
  4174. while assigned(cmditem) do
  4175. begin
  4176. { use a temporary list cause if ";" are involved we need to reverse the
  4177. order due to how TCmdStrList behaves }
  4178. cmdstr:=cmditem.str;
  4179. repeat
  4180. j:=Pos(';',cmdstr);
  4181. if j>0 then
  4182. begin
  4183. tmplist.insert(copy(cmdstr,1,j-1));
  4184. delete(cmdstr,1,j);
  4185. end
  4186. else
  4187. tmplist.insert(cmdstr);
  4188. until j=0;
  4189. tmpcmditem:=TCmdStrListItem(tmplist.First);
  4190. while assigned(tmpcmditem) do
  4191. begin
  4192. namespacelist.insert(tmpcmditem.Str);
  4193. tmpcmditem:=TCmdStrListItem(tmpcmditem.Next);
  4194. end;
  4195. tmplist.clear;
  4196. cmditem:=TCmdStrListItem(cmditem.Next);
  4197. end;
  4198. tmplist.Free;
  4199. { add unit environment and exepath to the unit search path }
  4200. if inputfilepath<>'' then
  4201. Unitsearchpath.AddPath(inputfilepath,true);
  4202. if not disable_configfile then
  4203. begin
  4204. env:=GetEnvironmentVariable(target_info.unit_env);
  4205. if env<>'' then
  4206. UnitSearchPath.AddPath(GetEnvironmentVariable(target_info.unit_env),false);
  4207. end;
  4208. {$ifdef Unix}
  4209. fpcdir:=FixPath(GetEnvironmentVariable('FPCDIR'),false);
  4210. if fpcdir='' then
  4211. begin
  4212. if PathExists('/usr/local/lib/fpc/'+version_string,true) then
  4213. fpcdir:='/usr/local/lib/fpc/'+version_string+'/'
  4214. else
  4215. fpcdir:='/usr/lib/fpc/'+version_string+'/';
  4216. end;
  4217. {$else unix}
  4218. fpcdir:=FixPath(GetEnvironmentVariable('FPCDIR'),false);
  4219. if fpcdir='' then
  4220. begin
  4221. fpcdir:=ExePath+'../';
  4222. if not(PathExists(fpcdir+'units',true)) and
  4223. not(PathExists(fpcdir+'rtl',true)) then
  4224. fpcdir:=fpcdir+'../';
  4225. end;
  4226. {$endif unix}
  4227. { first try development RTL, else use the default installation path }
  4228. if not disable_configfile then
  4229. begin
  4230. if PathExists(FpcDir+'rtl',true) then
  4231. if (tf_use_8_3 in Source_Info.Flags) or
  4232. (tf_use_8_3 in Target_Info.Flags) then
  4233. UnitSearchPath.AddPath(FpcDir+'rtl/'+target_os_string,false)
  4234. else
  4235. UnitSearchPath.AddPath(FpcDir+'rtl/'+target_full_string,false)
  4236. else
  4237. if (tf_use_8_3 in Source_Info.Flags) or
  4238. (tf_use_8_3 in Target_Info.Flags) then
  4239. UnitSearchPath.AddPath(FpcDir+'units/'+target_os_string+'/rtl',false)
  4240. else
  4241. UnitSearchPath.AddPath(FpcDir+'units/'+target_full_string+'/rtl',false);
  4242. end;
  4243. { Add exepath if the exe is not in the current dir, because that is always searched already.
  4244. Do not add it when linking on the target because then we can maybe already find
  4245. .o files that are not for the target }
  4246. if (ExePath<>cfileutl.GetCurrentDir) and
  4247. not(cs_link_on_target in init_settings.globalswitches) then
  4248. UnitSearchPath.AddPath(ExePath,false);
  4249. { Add unit dir to the object and library path }
  4250. objectsearchpath.AddList(unitsearchpath,false);
  4251. librarysearchpath.AddList(unitsearchpath,false);
  4252. {$ifdef llvm}
  4253. { default to clang }
  4254. if (option.paratargetasm=as_none) then
  4255. begin
  4256. option.paratargetasm:=as_clang_llvm;
  4257. end;
  4258. {$endif llvm}
  4259. { maybe override assembler }
  4260. if (option.paratargetasm<>as_none) then
  4261. begin
  4262. if (option.paratargetasm=as_default) then
  4263. begin
  4264. option.paratargetasm:=target_info.assem;
  4265. end;
  4266. if not set_target_asm(option.paratargetasm) then
  4267. begin
  4268. if assigned(asminfos[option.paratargetasm]) then
  4269. Message2(option_incompatible_asm,asminfos[option.paratargetasm]^.idtxt,target_info.name)
  4270. else
  4271. Message2(option_incompatible_asm,'<invalid assembler>',target_info.name);
  4272. set_target_asm(target_info.assemextern);
  4273. Message1(option_asm_forced,target_asm.idtxt);
  4274. end;
  4275. if (af_no_debug in asminfos[option.paratargetasm]^.flags) and
  4276. (option.paratargetdbg<>dbg_none) then
  4277. begin
  4278. Message1(option_confict_asm_debug,
  4279. asminfos[option.paratargetasm]^.idtxt);
  4280. option.paratargetdbg:=dbg_none;
  4281. exclude(init_settings.moduleswitches,cs_debuginfo);
  4282. end;
  4283. { Some assemblers, like clang, do not support
  4284. stabs debugging format, switch to dwardé in that case }
  4285. if (af_no_stabs in asminfos[option.paratargetasm]^.flags) and
  4286. (option.paratargetdbg=dbg_stabs) then
  4287. begin
  4288. option.paratargetdbg:=dbg_dwarf2;
  4289. end;
  4290. end;
  4291. {TOptionheck a second time as we might have changed assembler just above }
  4292. option.checkoptionscompatibility;
  4293. { maybe override debug info format }
  4294. if (option.paratargetdbg<>dbg_none) then
  4295. if not set_target_dbg(option.paratargetdbg) then
  4296. Message(option_w_unsupported_debug_format);
  4297. { switch assembler if it's binary and we got -a on the cmdline }
  4298. if (af_outputbinary in target_asm.flags) and
  4299. ((cs_asm_leave in init_settings.globalswitches) or
  4300. { if -s is passed, we shouldn't call the internal assembler }
  4301. (cs_asm_extern in init_settings.globalswitches)) then
  4302. begin
  4303. Message(option_switch_bin_to_src_assembler);
  4304. {$ifdef llvm}
  4305. set_target_asm(as_clang_llvm);
  4306. {$else}
  4307. set_target_asm(target_info.assemextern);
  4308. {$endif}
  4309. { At least i8086 needs that for nasm and -CX
  4310. which is incompatible with internal linker }
  4311. option.checkoptionscompatibility;
  4312. end;
  4313. { Force use of external linker if there is no
  4314. internal linker or the linking is skipped }
  4315. if not(cs_link_extern in init_settings.globalswitches) and
  4316. ((target_info.link=ld_none) or
  4317. (cs_link_nolink in init_settings.globalswitches)) then
  4318. begin
  4319. include(init_settings.globalswitches,cs_link_extern);
  4320. end;
  4321. { turn off stripping if compiling with debuginfo or profile }
  4322. if (
  4323. (cs_debuginfo in init_settings.moduleswitches) or
  4324. (cs_profile in init_settings.moduleswitches)
  4325. ) and
  4326. not(cs_link_separate_dbg_file in init_settings.globalswitches) then
  4327. exclude(init_settings.globalswitches,cs_link_strip);
  4328. { choose a reasonable tls model }
  4329. if (tf_section_threadvars in target_info.flags) and (init_settings.tlsmodel=tlsm_none) then
  4330. begin
  4331. if cs_create_pic in init_settings.moduleswitches then
  4332. init_settings.tlsmodel:=tlsm_global_dynamic
  4333. else
  4334. init_settings.tlsmodel:=tlsm_local_exec;
  4335. end;
  4336. { set Mac OS X version default macros if not specified explicitly }
  4337. option.MaybeSetDefaultMacVersionMacro;
  4338. {$ifdef cpufpemu}
  4339. { force fpu emulation on arm/wince, arm/gba, arm/embedded and arm/nds
  4340. if fpu type not explicitly set }
  4341. if not(option.FPUSetExplicitly) and
  4342. ((target_info.system in [system_arm_wince,system_arm_gba,
  4343. system_m68k_amiga,system_m68k_atari,
  4344. system_arm_nds,system_arm_embedded,system_arm_freertos,
  4345. system_riscv32_embedded,system_riscv64_embedded,system_xtensa_linux,
  4346. system_z80_embedded,system_z80_zxspectrum])
  4347. {$ifdef arm}
  4348. or (target_info.abi=abi_eabi)
  4349. {$endif arm}
  4350. )
  4351. or (init_settings.fputype=fpu_soft)
  4352. then
  4353. begin
  4354. include(init_settings.moduleswitches,cs_fp_emulation);
  4355. { cs_fp_emulation and fpu_soft are equal on arm and m68k }
  4356. init_settings.fputype:=fpu_soft;
  4357. end;
  4358. {$endif cpufpemu}
  4359. {$ifdef i386}
  4360. if target_info.system in systems_i386_default_486 then
  4361. begin
  4362. { Avoid use of MMX/CMOVcc instructions on older systems.
  4363. Some systems might not handle these instructions correctly,
  4364. Used emulators might also be problematic. PM }
  4365. if not option.CPUSetExplicitly then
  4366. init_settings.cputype:=cpu_486;
  4367. end;
  4368. case target_info.system of
  4369. system_i386_android:
  4370. begin
  4371. { set default cpu type to PentiumM for Android unless specified otherwise }
  4372. if not option.CPUSetExplicitly then
  4373. init_settings.cputype:=cpu_PentiumM;
  4374. if not option.OptCPUSetExplicitly then
  4375. init_settings.optimizecputype:=cpu_PentiumM;
  4376. { set default fpu type to SSSE3 for Android unless specified otherwise }
  4377. if not option.FPUSetExplicitly then
  4378. init_settings.fputype:=fpu_ssse3;
  4379. end;
  4380. else
  4381. ;
  4382. end;
  4383. {$endif i386}
  4384. {$ifdef xtensa}
  4385. { xtensa-linux target does not support controller setting option -Wp }
  4386. if not(option.FPUSetExplicitly) and not(target_info.system = system_xtensa_linux) then
  4387. begin
  4388. init_settings.fputype:=embedded_controllers[init_settings.controllertype].fputype;
  4389. if (init_settings.fputype=fpu_soft) then
  4390. include(init_settings.moduleswitches,cs_fp_emulation);
  4391. end;
  4392. if not(option.CPUSetExplicitly) and (target_info.system=system_xtensa_linux) then
  4393. init_settings.cputype:=cpu_lx6;
  4394. if (target_info.system in [system_xtensa_embedded,system_xtensa_freertos]) and not(option.ABISetExplicitly) then
  4395. begin
  4396. if CPUXTENSA_REGWINDOW in cpu_capabilities[init_settings.cputype] then
  4397. target_info.abi:=abi_xtensa_windowed
  4398. else
  4399. target_info.abi:=abi_xtensa_call0;
  4400. end;
  4401. {$endif xtensa}
  4402. {$ifdef arm}
  4403. case target_info.system of
  4404. system_arm_ios:
  4405. begin
  4406. { set default cpu type to ARMv7 for Darwin unless specified otherwise, and fpu
  4407. to VFPv3 (that's what all 32 bit ARM iOS devices use nowadays)
  4408. }
  4409. if not option.CPUSetExplicitly then
  4410. init_settings.cputype:=cpu_armv7;
  4411. if not option.OptCPUSetExplicitly then
  4412. init_settings.optimizecputype:=cpu_armv7;
  4413. if not option.FPUSetExplicitly then
  4414. init_settings.fputype:=fpu_vfpv3;
  4415. end;
  4416. system_arm_android:
  4417. begin
  4418. { set default cpu type to ARMv5T for Android unless specified otherwise }
  4419. if not option.CPUSetExplicitly then
  4420. init_settings.cputype:=cpu_armv5t;
  4421. if not option.OptCPUSetExplicitly then
  4422. init_settings.optimizecputype:=cpu_armv5t;
  4423. end;
  4424. else
  4425. ;
  4426. end;
  4427. { set ABI defaults }
  4428. case target_info.abi of
  4429. abi_eabihf:
  4430. { set default cpu type to ARMv7a for ARMHF unless specified otherwise }
  4431. begin
  4432. {$ifdef CPUARMV6}
  4433. { if the compiler is built for armv6, then
  4434. inherit this setting, e.g. Raspian is armhf but
  4435. only armv6, this makes rebuilds of the compiler
  4436. easier }
  4437. if not option.CPUSetExplicitly then
  4438. init_settings.cputype:=cpu_armv6;
  4439. if not option.OptCPUSetExplicitly then
  4440. init_settings.optimizecputype:=cpu_armv6;
  4441. {$else CPUARMV6}
  4442. if not option.CPUSetExplicitly then
  4443. init_settings.cputype:=cpu_armv7a;
  4444. if not option.OptCPUSetExplicitly then
  4445. init_settings.optimizecputype:=cpu_armv7a;
  4446. {$endif CPUARMV6}
  4447. { Set FPU type }
  4448. if not(option.FPUSetExplicitly) then
  4449. begin
  4450. if init_settings.cputype < cpu_armv7 then
  4451. init_settings.fputype:=fpu_vfpv2
  4452. else
  4453. init_settings.fputype:=fpu_vfpv3_d16;
  4454. end
  4455. else
  4456. begin
  4457. if (not(FPUARM_HAS_VFP_EXTENSION in fpu_capabilities[init_settings.fputype]))
  4458. or (target_info.system = system_arm_ios) then
  4459. begin
  4460. Message(option_illegal_fpu_eabihf);
  4461. StopOptions(1);
  4462. end;
  4463. end;
  4464. end;
  4465. abi_eabi:
  4466. begin
  4467. if target_info.system=system_arm_linux then
  4468. begin
  4469. { this is what Debian uses }
  4470. if not option.CPUSetExplicitly then
  4471. init_settings.cputype:=cpu_armv4t;
  4472. if not option.OptCPUSetExplicitly then
  4473. init_settings.optimizecputype:=cpu_armv4t;
  4474. if not(option.FPUSetExplicitly) then
  4475. init_settings.fputype:=fpu_soft;
  4476. end;
  4477. end;
  4478. else
  4479. ;
  4480. end;
  4481. if (init_settings.instructionset=is_thumb) and not(CPUARM_HAS_THUMB2 in cpu_capabilities[init_settings.cputype]) then
  4482. begin
  4483. def_system_macro('CPUTHUMB');
  4484. if not option.FPUSetExplicitly then
  4485. init_settings.fputype:=fpu_soft;
  4486. if not(init_settings.fputype in [fpu_none,fpu_soft,fpu_libgcc]) then
  4487. Message2(option_unsupported_fpu,fputypestr[init_settings.fputype],'Thumb');
  4488. {$if defined(FPC_ARMEL) or defined(FPC_ARMHF)}
  4489. 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';
  4490. {$else FPC_ARMAL or FPC_ARMHF}
  4491. if target_info.endian=endian_little then
  4492. 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';
  4493. {$endif FPC_ARMAL or FPC_ARMHF}
  4494. end;
  4495. if (init_settings.instructionset=is_thumb) and (CPUARM_HAS_THUMB2 in cpu_capabilities[init_settings.cputype]) then
  4496. def_system_macro('CPUTHUMB2');
  4497. {$endif arm}
  4498. {$ifdef aarch64}
  4499. case target_info.system of
  4500. system_aarch64_darwin:
  4501. begin
  4502. if not option.CPUSetExplicitly then
  4503. init_settings.cputype:=cpu_armv84a;
  4504. if not option.OptCPUSetExplicitly then
  4505. init_settings.optimizecputype:=cpu_armv84a;
  4506. end;
  4507. else
  4508. ;
  4509. end;
  4510. {$endif aarch64}
  4511. {$if defined(riscv32) or defined(riscv64)}
  4512. { RISC-V defaults }
  4513. if (target_info.abi = abi_riscv_hf) then
  4514. begin
  4515. {$ifdef riscv32}
  4516. if not option.CPUSetExplicitly then
  4517. init_settings.cputype:=cpu_rv32ima;
  4518. if not option.OptCPUSetExplicitly then
  4519. init_settings.optimizecputype:=cpu_rv32ima;
  4520. {$else}
  4521. if not option.CPUSetExplicitly then
  4522. init_settings.cputype:=cpu_rv64imac;
  4523. if not option.OptCPUSetExplicitly then
  4524. init_settings.optimizecputype:=cpu_rv64imac;
  4525. {$endif}
  4526. { Set FPU type }
  4527. if not(option.FPUSetExplicitly) then
  4528. init_settings.fputype:=fpu_fd
  4529. else
  4530. begin
  4531. if not (init_settings.fputype in [fpu_fd]) then
  4532. begin
  4533. Message(option_illegal_fpu_eabihf);
  4534. StopOptions(1);
  4535. end;
  4536. end;
  4537. end;
  4538. {$endif defined(riscv32) or defined(riscv64)}
  4539. {$ifdef jvm}
  4540. { set default CPU type to Dalvik when targeting Android }
  4541. if target_info.system=system_jvm_android32 then
  4542. begin
  4543. if not option.CPUSetExplicitly then
  4544. init_settings.cputype:=cpu_dalvik;
  4545. end;
  4546. {$endif jvm}
  4547. {$ifdef llvm}
  4548. { standard extension for llvm bitcode files }
  4549. target_info.asmext:='.ll';
  4550. { don't generate dwarf cfi, llvm will do that }
  4551. exclude(target_info.flags,tf_needs_dwarf_cfi);
  4552. {$endif llvm}
  4553. {$ifdef mipsel}
  4554. case target_info.system of
  4555. system_mipsel_android:
  4556. begin
  4557. { set default cpu type to MIPS32 rev. 1 and hard float for MIPS-Android unless specified otherwise }
  4558. if not option.CPUSetExplicitly then
  4559. init_settings.cputype:=cpu_mips32;
  4560. if not option.OptCPUSetExplicitly then
  4561. init_settings.optimizecputype:=cpu_mips32;
  4562. if not option.FPUSetExplicitly then
  4563. init_settings.fputype:=fpu_mips2;
  4564. end;
  4565. system_mipsel_embedded:
  4566. begin
  4567. { set default cpu type to PIC32MX and softfloat for MIPSEL-EMBEDDED target unless specified otherwise }
  4568. if not option.CPUSetExplicitly then
  4569. init_settings.cputype:=cpu_pic32mx;
  4570. if not option.OptCPUSetExplicitly then
  4571. init_settings.optimizecputype:=cpu_pic32mx;
  4572. if not option.FPUSetExplicitly then
  4573. init_settings.fputype:=fpu_soft;
  4574. end;
  4575. else
  4576. ;
  4577. end;
  4578. {$endif mipsel}
  4579. {$ifdef m68k}
  4580. if init_settings.cputype in cpu_coldfire then
  4581. def_system_macro('CPUCOLDFIRE');
  4582. case target_info.system of
  4583. system_m68k_linux,
  4584. system_m68k_netbsd:
  4585. begin
  4586. if not (option.FPUSetExplicitly) and
  4587. not (init_settings.cputype in cpu_coldfire) then
  4588. begin
  4589. { enable HW FPU for UNIX by default, but only for
  4590. original 68k, not Coldfire }
  4591. exclude(init_settings.moduleswitches,cs_fp_emulation);
  4592. init_settings.fputype:=fpu_68881;
  4593. end;
  4594. end;
  4595. system_m68k_sinclairql:
  4596. begin
  4597. if not option.CPUSetExplicitly then
  4598. init_settings.cputype:=cpu_mc68000;
  4599. end;
  4600. system_m68k_palmos:
  4601. begin
  4602. if not option.CPUSetExplicitly then
  4603. init_settings.cputype:=cpu_mc68000;
  4604. if not (option.FPUSetExplicitly) then
  4605. begin
  4606. { No FPU for PalmOS by default }
  4607. exclude(init_settings.moduleswitches,cs_fp_emulation);
  4608. init_settings.fputype:=fpu_none;
  4609. end;
  4610. end;
  4611. else
  4612. ;
  4613. end;
  4614. {$endif m68k}
  4615. {$ifdef wasm}
  4616. { if no explicit exception handling mode is set for WebAssembly, assume no exceptions }
  4617. if init_settings.targetswitches*[ts_wasm_no_exceptions,ts_wasm_js_exceptions,ts_wasm_native_exceptions,ts_wasm_bf_exceptions]=[] then
  4618. begin
  4619. def_system_macro(TargetSwitchStr[ts_wasm_no_exceptions].define);
  4620. include(init_settings.targetswitches,ts_wasm_no_exceptions);
  4621. end;
  4622. {$endif wasm}
  4623. { now we can define cpu and fpu type }
  4624. def_cpu_macros;
  4625. { Use init_settings cpu type for asm cpu type,
  4626. if asmcputype is cpu_none,
  4627. at least as long as there is no explicit
  4628. option to set it on command line PM }
  4629. if init_settings.asmcputype = cpu_none then
  4630. init_settings.asmcputype:=init_settings.cputype;
  4631. {$ifdef llvm}
  4632. def_system_macro('CPULLVM');
  4633. {$endif llvm}
  4634. {$if defined(cpucapabilities)}
  4635. for cpuflag:=low(cpuflag) to high(cpuflag) do
  4636. begin
  4637. str(cpuflag,hs);
  4638. if cpuflag in cpu_capabilities[init_settings.cputype] then
  4639. def_system_macro(hs)
  4640. else
  4641. undef_system_macro(hs);
  4642. end;
  4643. {$endif defined(cpucapabilities)}
  4644. {$if defined(fpucapabilities)}
  4645. for fpuflag:=low(fpuflag) to high(fpuflag) do
  4646. begin
  4647. str(fpuflag,hs);
  4648. if fpuflag in fpu_capabilities[init_settings.fputype] then
  4649. def_system_macro(hs)
  4650. else
  4651. undef_system_macro(hs);
  4652. end;
  4653. {$endif defined(fpucapabilities)}
  4654. if init_settings.fputype<>fpu_none then
  4655. begin
  4656. {$if defined(i386) or defined(i8086)}
  4657. def_system_macro('FPC_HAS_TYPE_EXTENDED');
  4658. {$endif}
  4659. def_system_macro('FPC_HAS_TYPE_SINGLE');
  4660. def_system_macro('FPC_HAS_TYPE_DOUBLE');
  4661. {$if not defined(i386) and not defined(x86_64) and not defined(i8086) and not defined(aarch64)}
  4662. def_system_macro('FPC_INCLUDE_SOFTWARE_INT64_TO_DOUBLE');
  4663. {$endif}
  4664. {$if defined(m68k)}
  4665. def_system_macro('FPC_INCLUDE_SOFTWARE_LONGWORD_TO_DOUBLE');
  4666. {$endif}
  4667. {$ifdef x86_64}
  4668. {$ifndef FPC_SUPPORT_X87_TYPES_ON_WIN64}
  4669. { normally, win64 doesn't support the legacy fpu }
  4670. if target_info.system=system_x86_64_win64 then
  4671. undef_system_macro('FPC_HAS_TYPE_EXTENDED')
  4672. else
  4673. {$endif FPC_SUPPORT_X87_TYPES_ON_WIN64}
  4674. def_system_macro('FPC_HAS_TYPE_EXTENDED');
  4675. {$endif}
  4676. end;
  4677. { Enable now for testing }
  4678. {$ifndef DISABLE_TLS_DIRECTORY}
  4679. if target_info.system in systems_windows then
  4680. def_system_macro('FPC_USE_TLS_DIRECTORY');
  4681. {$endif not DISABLE_TLS_DIRECTORY}
  4682. {$ifndef DISABLE_WIN64_SEH}
  4683. if target_info.system=system_x86_64_win64 then
  4684. def_system_macro('FPC_USE_WIN64_SEH');
  4685. {$endif DISABLE_WIN64_SEH}
  4686. {$ifndef DISABLE_WIN32_SEH}
  4687. if target_info.system=system_i386_win32 then
  4688. def_system_macro('FPC_USE_WIN32_SEH');
  4689. {$endif not DISABLE_WIN32_SEH}
  4690. {$ifdef ARM}
  4691. { define FPC_DOUBLE_HILO_SWAPPED if needed to properly handle doubles in RTL }
  4692. if (init_settings.fputype in [fpu_fpa,fpu_fpa10,fpu_fpa11]) and
  4693. not(cs_fp_emulation in init_settings.moduleswitches) then
  4694. def_system_macro('FPC_DOUBLE_HILO_SWAPPED');
  4695. {$endif ARM}
  4696. { inline bsf/bsr implementation }
  4697. {$if defined(i386) or defined(x86_64) or defined(aarch64) or defined(powerpc) or defined(powerpc64)}
  4698. def_system_macro('FPC_HAS_INTERNAL_BSF');
  4699. def_system_macro('FPC_HAS_INTERNAL_BSR');
  4700. {$endif}
  4701. { hardware FMA support }
  4702. {$if defined(i386) or defined(x86_64)}
  4703. if (fpu_capabilities[current_settings.fputype]*[FPUX86_HAS_FMA,FPUX86_HAS_FMA4])<>[] then
  4704. begin
  4705. def_system_macro('FPC_HAS_FAST_FMA_SINGLE');
  4706. def_system_macro('FPC_HAS_FAST_FMA_DOUBLE');
  4707. end;
  4708. {$endif defined(i386) or defined(x86_64)}
  4709. {$if defined(arm)}
  4710. { it is determined during system unit compilation if clz is used for bsf or not,
  4711. this is not perfect but the current implementation bsf/bsr does not allow another
  4712. solution }
  4713. if (CPUARM_HAS_CLZ in cpu_capabilities[init_settings.cputype]) and
  4714. ((init_settings.instructionset=is_arm) or
  4715. (CPUARM_HAS_THUMB2 in cpu_capabilities[init_settings.cputype])) then
  4716. begin
  4717. def_system_macro('FPC_HAS_INTERNAL_BSR');
  4718. if CPUARM_HAS_RBIT in cpu_capabilities[init_settings.cputype] then
  4719. def_system_macro('FPC_HAS_INTERNAL_BSF');
  4720. end;
  4721. {$endif}
  4722. {$if defined(xtensa)}
  4723. { it is determined during system unit compilation if nsau is used for bsr or not,
  4724. this is not perfect but the current implementation bsf/bsr does not allow another
  4725. solution }
  4726. if CPUXTENSA_HAS_NSAx in cpu_capabilities[init_settings.cputype] then
  4727. begin
  4728. def_system_macro('FPC_HAS_INTERNAL_BSR');
  4729. end;
  4730. {$endif}
  4731. {$if defined(powerpc64)}
  4732. { on sysv targets, default to elfv2 for little endian and to elfv1 for
  4733. big endian (unless specified otherwise). As the gcc man page says:
  4734. "Overriding the default ABI requires special system support and is
  4735. likely to fail in spectacular ways" }
  4736. if not option.ABISetExplicitly then
  4737. begin
  4738. if (target_info.abi=abi_powerpc_sysv) and
  4739. (target_info.endian=endian_little) then
  4740. target_info.abi:=abi_powerpc_elfv2
  4741. else
  4742. if (target_info.abi=abi_powerpc_elfv2) and
  4743. (target_info.endian=endian_big) then
  4744. target_info.abi:=abi_powerpc_sysv
  4745. end;
  4746. {$endif}
  4747. {$if defined(powerpc) or defined(powerpc64)}
  4748. { define _CALL_ELF symbol like gcc }
  4749. case target_info.abi of
  4750. abi_powerpc_sysv:
  4751. set_system_compvar('_CALL_ELF','1');
  4752. abi_powerpc_elfv2:
  4753. set_system_compvar('_CALL_ELF','2');
  4754. else
  4755. ;
  4756. end;
  4757. {$endif}
  4758. { Section smartlinking conflicts with import sections on Windows }
  4759. if GenerateImportSection and
  4760. (target_info.system in [system_i386_win32,system_x86_64_win64,system_aarch64_win64]) then
  4761. exclude(target_info.flags,tf_smartlink_sections);
  4762. if not option.LinkTypeSetExplicitly then
  4763. set_default_link_type;
  4764. { Default alignment settings,
  4765. 1. load the defaults for the target
  4766. 2. adapt defaults specifically for the target
  4767. 3. override with generic optimizer setting (little size)
  4768. 4. override with the user specified -Oa }
  4769. UpdateAlignment(init_settings.alignment,target_info.alignment);
  4770. {$ifdef arm}
  4771. if (init_settings.instructionset=is_thumb) and not(CPUARM_HAS_THUMB2 in cpu_capabilities[init_settings.cputype]) then
  4772. begin
  4773. init_settings.alignment.procalign:=2;
  4774. init_settings.alignment.jumpalign:=2;
  4775. init_settings.alignment.coalescealign:=2;
  4776. init_settings.alignment.loopalign:=2;
  4777. end;
  4778. {$endif arm}
  4779. if (cs_opt_size in init_settings.optimizerswitches) then
  4780. begin
  4781. init_settings.alignment.procalign:=1;
  4782. init_settings.alignment.jumpalign:=1;
  4783. init_settings.alignment.coalescealign:=1;
  4784. init_settings.alignment.loopalign:=1;
  4785. {$ifdef x86}
  4786. { constalignmax=1 keeps the executable and thus the memory foot print small but
  4787. all processors except x86 are really hurt by this or might even crash }
  4788. init_settings.alignment.constalignmax:=1;
  4789. {$endif x86}
  4790. end;
  4791. UpdateAlignment(init_settings.alignment,option.paraalignment);
  4792. set_system_macro('FPC_VERSION',version_nr);
  4793. set_system_macro('FPC_RELEASE',release_nr);
  4794. set_system_macro('FPC_PATCH',patch_nr);
  4795. set_system_macro('FPC_FULLVERSION',Format('%d%.02d%.02d',[StrToInt(version_nr),StrToInt(release_nr),StrToInt(patch_nr)]));
  4796. if target_info.system in systems_indirect_entry_information then
  4797. def_system_macro('FPC_HAS_INDIRECT_ENTRY_INFORMATION');
  4798. if not (tf_winlikewidestring in target_info.flags) then
  4799. def_system_macro('FPC_WIDESTRING_EQUAL_UNICODESTRING');
  4800. if tf_supports_packages in target_info.flags then
  4801. def_system_macro('FPC_HAS_DYNAMIC_PACKAGES');
  4802. if target_info.system in systems_indirect_var_imports then
  4803. def_system_macro('FPC_HAS_INDIRECT_VAR_ACCESS');
  4804. if cs_compilesystem in init_settings.moduleswitches then
  4805. for i:=low(tfeature) to high(tfeature) do
  4806. if i in features then
  4807. def_system_macro('FPC_HAS_FEATURE_'+featurestr[i]);
  4808. {$push}
  4809. {$warn 6018 off} { Unreachable code due to compile time evaluation }
  4810. if ControllerSupport and (target_info.system in (systems_embedded+systems_freertos)) and
  4811. (init_settings.controllertype<>ct_none) then
  4812. begin
  4813. with embedded_controllers[init_settings.controllertype] do
  4814. begin
  4815. set_system_macro('FPC_FLASHBASE',tostr(flashbase));
  4816. set_system_macro('FPC_FLASHSIZE',tostr(flashsize));
  4817. set_system_macro('FPC_SRAMBASE',tostr(srambase));
  4818. set_system_macro('FPC_SRAMSIZE',tostr(sramsize));
  4819. set_system_macro('FPC_EEPROMBASE',tostr(eeprombase));
  4820. set_system_macro('FPC_EEPROMSIZE',tostr(eepromsize));
  4821. set_system_macro('FPC_BOOTBASE',tostr(bootbase));
  4822. set_system_macro('FPC_BOOTSIZE',tostr(bootsize));
  4823. end;
  4824. end;
  4825. {$pop}
  4826. { as stackalign is not part of the alignment record, we do not need to define the others alignments for symmetry yet }
  4827. set_system_macro('FPC_STACKALIGNMENT',tostr(target_info.stackalign));
  4828. option.free;
  4829. Option:=nil;
  4830. clearstack_pocalls := [pocall_cdecl,pocall_cppdecl,pocall_syscall,pocall_mwpascal,pocall_sysv_abi_cdecl,pocall_ms_abi_cdecl{$ifdef z80},pocall_stdcall{$endif}];
  4831. cdecl_pocalls := [pocall_cdecl, pocall_cppdecl, pocall_mwpascal, pocall_sysv_abi_cdecl, pocall_ms_abi_cdecl];
  4832. if (tf_safecall_clearstack in target_info.flags) then
  4833. begin
  4834. include (cdecl_pocalls, pocall_safecall);
  4835. include (clearstack_pocalls, pocall_safecall)
  4836. end;
  4837. end;
  4838. initialization
  4839. coption:=toption;
  4840. finalization
  4841. if assigned(option) then
  4842. option.free;
  4843. end.