options.pas 150 KB

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