options.pas 153 KB

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