options.pas 170 KB

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