options.pas 170 KB

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