options.pas 173 KB

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