options.pas 151 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463
  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. j:=1;
  1366. while j<=length(more) do
  1367. begin
  1368. case more[j] of
  1369. 'd' :
  1370. begin
  1371. include(init_settings.globalswitches,cs_link_deffile);
  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. include(init_settings.globalswitches,cs_link_deffile);
  1388. dllversion:=Copy(more,j+1,255);
  1389. l:=pos('.',dllversion);
  1390. dllminor:=0;
  1391. error:=0;
  1392. if l>0 then
  1393. begin
  1394. val(copy(dllversion,l+1,255),minor,error);
  1395. if (error=0) and
  1396. (minor>=0) and (minor<=$ffff) then
  1397. dllminor:=minor
  1398. else
  1399. if error=0 then
  1400. error:=1;
  1401. end;
  1402. if l=0 then
  1403. l:=256;
  1404. dllmajor:=1;
  1405. major:=0;
  1406. if error=0 then
  1407. val(copy(dllversion,1,l-1),major,error);
  1408. if (error=0) and (major>=0) and (major<=$ffff) then
  1409. dllmajor:=major
  1410. else
  1411. if error=0 then
  1412. error:=1;
  1413. if error<>0 then
  1414. Message1(scan_w_wrong_version_ignored,dllversion);
  1415. break;
  1416. end;
  1417. 'w' :
  1418. begin
  1419. include(init_settings.globalswitches,cs_link_deffile);
  1420. usewindowapi:=true;
  1421. end;
  1422. '-' :
  1423. begin
  1424. exclude(init_settings.globalswitches,cs_link_deffile);
  1425. usewindowapi:=false;
  1426. end;
  1427. else
  1428. IllegalPara(opt);
  1429. end;
  1430. inc(j);
  1431. end;
  1432. end;
  1433. 'e' :
  1434. exepath:=FixPath(More,true);
  1435. 'E' :
  1436. begin
  1437. if UnsetBool(More, 0, opt, true) then
  1438. exclude(init_settings.globalswitches,cs_link_nolink)
  1439. else
  1440. include(init_settings.globalswitches,cs_link_nolink);
  1441. end;
  1442. 'f' :
  1443. begin
  1444. if more='PIC' then
  1445. begin
  1446. if tf_no_pic_supported in target_info.flags then
  1447. message(scan_w_pic_ignored)
  1448. else
  1449. include(init_settings.moduleswitches,cs_create_pic)
  1450. end
  1451. else
  1452. IllegalPara(opt);
  1453. end;
  1454. 'F' :
  1455. begin
  1456. if more='' then
  1457. IllegalPara(opt);
  1458. c:=more[1];
  1459. Delete(more,1,1);
  1460. DefaultReplacements(More);
  1461. case c of
  1462. 'a' :
  1463. autoloadunits:=more;
  1464. 'c' :
  1465. begin
  1466. { if we first specify that the system code page should be
  1467. used and then explicitly specify a code page, unset the
  1468. flag that we're using the system code page again }
  1469. SetCompileModeSwitch('SYSTEMCODEPAGE-',true);
  1470. if (upper(more)='UTF8') or (upper(more)='UTF-8') then
  1471. init_settings.sourcecodepage:=CP_UTF8
  1472. else if not(cpavailable(more)) then
  1473. Message1(option_code_page_not_available,more)
  1474. else
  1475. init_settings.sourcecodepage:=codepagebyname(more);
  1476. include(init_settings.moduleswitches,cs_explicit_codepage);
  1477. end;
  1478. 'C' :
  1479. RCCompiler:=More;
  1480. 'd' :
  1481. if UnsetBool(more, 0, opt, true) then
  1482. init_settings.disabledircache:=false
  1483. else
  1484. init_settings.disabledircache:=true;
  1485. 'D' :
  1486. utilsdirectory:=FixPath(More,true);
  1487. 'e' :
  1488. SetRedirectFile(More);
  1489. 'E' :
  1490. OutputExeDir:=FixPath(More,true);
  1491. 'f' :
  1492. if (target_info.system in systems_darwin) then
  1493. if ispara then
  1494. ParaFrameworkPath.AddPath(More,false)
  1495. else
  1496. frameworksearchpath.AddPath(More,true)
  1497. else
  1498. IllegalPara(opt);
  1499. 'i' :
  1500. begin
  1501. if ispara then
  1502. ParaIncludePath.AddPath(More,false)
  1503. else
  1504. includesearchpath.AddPath(More,true);
  1505. end;
  1506. 'm' :
  1507. begin
  1508. s:=ExtractFileDir(more);
  1509. if TryStrToInt(ExtractFileName(more),j) then
  1510. begin
  1511. unicodemapping:=loadunicodemapping(More,More+'.txt',j);
  1512. if assigned(unicodemapping) then
  1513. registermapping(unicodemapping)
  1514. else
  1515. IllegalPara(opt);
  1516. end
  1517. else
  1518. IllegalPara(opt);
  1519. end;
  1520. 'M' :
  1521. unicodepath:=FixPath(More,true);
  1522. 'g' :
  1523. Message2(option_obsolete_switch_use_new,'-Fg','-Fl');
  1524. 'l' :
  1525. begin
  1526. if ispara then
  1527. ParaLibraryPath.AddLibraryPath(sysrootpath,More,false)
  1528. else
  1529. LibrarySearchPath.AddLibraryPath(sysrootpath,More,true)
  1530. end;
  1531. 'L' :
  1532. begin
  1533. if More<>'' then
  1534. ParaDynamicLinker:=More
  1535. else
  1536. IllegalPara(opt);
  1537. end;
  1538. 'N' :
  1539. begin
  1540. if more<>'' then
  1541. paranamespaces.insert(more)
  1542. else
  1543. illegalpara(opt);
  1544. end;
  1545. 'o' :
  1546. begin
  1547. if ispara then
  1548. ParaObjectPath.AddPath(More,false)
  1549. else
  1550. ObjectSearchPath.AddPath(More,true);
  1551. end;
  1552. 'P' :
  1553. begin
  1554. if ispara then
  1555. parapackages.add(more,nil)
  1556. else
  1557. add_package(more,true,true);
  1558. end;
  1559. 'p' :
  1560. begin
  1561. if ispara then
  1562. parapackagepath.AddPath(More,false)
  1563. else
  1564. packagesearchpath.AddPath(More,true);
  1565. end;
  1566. 'r' :
  1567. Msgfilename:=More;
  1568. 'R' :
  1569. ResCompiler:=More;
  1570. 'u' :
  1571. begin
  1572. if ispara then
  1573. ParaUnitPath.AddPath(More,false)
  1574. else
  1575. unitsearchpath.AddPath(More,true);
  1576. end;
  1577. 'U' :
  1578. OutputUnitDir:=FixPath(More,true);
  1579. 'W',
  1580. 'w':
  1581. begin
  1582. if More<>'' then
  1583. begin
  1584. DefaultReplacements(More);
  1585. D:=ExtractFilePath(More);
  1586. if (D<>'') then
  1587. D:=FixPath(D,True);
  1588. D:=D+ExtractFileName(More);
  1589. if (c='W') then
  1590. WpoFeedbackOutput:=D
  1591. else
  1592. WpoFeedbackInput:=D;
  1593. end
  1594. else
  1595. IllegalPara(opt);
  1596. end;
  1597. else
  1598. IllegalPara(opt);
  1599. end;
  1600. end;
  1601. 'g' :
  1602. begin
  1603. if UnsetBool(More, 0, opt, false) then
  1604. begin
  1605. exclude(init_settings.moduleswitches,cs_debuginfo);
  1606. exclude(init_settings.globalswitches,cs_use_heaptrc);
  1607. exclude(init_settings.globalswitches,cs_use_lineinfo);
  1608. exclude(init_settings.localswitches,cs_checkpointer);
  1609. localvartrashing := -1;
  1610. end
  1611. else
  1612. begin
  1613. include(init_settings.moduleswitches,cs_debuginfo);
  1614. if paratargetdbg=dbg_none then
  1615. paratargetdbg:=target_info.dbg;
  1616. end;
  1617. if not RelocSectionSetExplicitly then
  1618. RelocSection:=false;
  1619. j:=1;
  1620. while j<=length(more) do
  1621. begin
  1622. case more[j] of
  1623. 'c' :
  1624. begin
  1625. if UnsetBool(More, j, opt, false) then
  1626. exclude(init_settings.localswitches,cs_checkpointer)
  1627. else if (target_info.system in systems_support_checkpointer) then
  1628. begin
  1629. if do_release then
  1630. Message(option_gc_incompatible_with_release_flag)
  1631. else
  1632. include(init_settings.localswitches,cs_checkpointer);
  1633. end
  1634. else
  1635. UnsupportedPara('-gc');
  1636. end;
  1637. 'h' :
  1638. begin
  1639. if UnsetBool(More, j, opt, false) then
  1640. exclude(init_settings.globalswitches,cs_use_heaptrc)
  1641. else begin
  1642. if cs_gdb_valgrind in init_settings.globalswitches then
  1643. Message2(option_valgrind_heaptrc_mismatch,'-gh', '-gv');
  1644. include(init_settings.globalswitches,cs_use_heaptrc);
  1645. end;
  1646. end;
  1647. 'l' :
  1648. begin
  1649. if UnsetBool(More, j, opt, false) then
  1650. exclude(init_settings.globalswitches,cs_use_lineinfo)
  1651. else
  1652. include(init_settings.globalswitches,cs_use_lineinfo);
  1653. end;
  1654. 'm' :
  1655. begin
  1656. paratargetdbg:=dbg_codeview;
  1657. end;
  1658. 'o' :
  1659. begin
  1660. if not UpdateDebugStr(copy(more,j+1,length(more)),init_settings.debugswitches) then
  1661. IllegalPara(opt);
  1662. break;
  1663. end;
  1664. 'p' :
  1665. begin
  1666. if UnsetBool(More, j, opt, false) then
  1667. exclude(init_settings.globalswitches,cs_stabs_preservecase)
  1668. else
  1669. include(init_settings.globalswitches,cs_stabs_preservecase);
  1670. end;
  1671. 's' :
  1672. begin
  1673. paratargetdbg:=dbg_stabs;
  1674. end;
  1675. 't' :
  1676. begin
  1677. if UnsetBool(More, j, opt, false) then
  1678. localvartrashing := -1
  1679. else
  1680. localvartrashing := (localvartrashing + 1) mod nroftrashvalues;
  1681. end;
  1682. 'v' :
  1683. begin
  1684. if UnsetBool(More, j, opt, false) then
  1685. exclude(init_settings.globalswitches,cs_gdb_valgrind)
  1686. else begin
  1687. if cs_use_heaptrc in init_settings.globalswitches then
  1688. Message2(option_valgrind_heaptrc_mismatch,'-gh', '-gv');
  1689. include(init_settings.globalswitches,cs_gdb_valgrind);
  1690. end;
  1691. end;
  1692. 'w' :
  1693. begin
  1694. if (j<length(more)) and (more[j+1] in ['2','3','4']) then
  1695. begin
  1696. case more[j+1] of
  1697. '2': paratargetdbg:=dbg_dwarf2;
  1698. '3': paratargetdbg:=dbg_dwarf3;
  1699. '4': paratargetdbg:=dbg_dwarf4;
  1700. end;
  1701. inc(j);
  1702. end
  1703. else
  1704. paratargetdbg:=dbg_dwarf2;
  1705. end;
  1706. else
  1707. IllegalPara(opt);
  1708. end;
  1709. inc(j);
  1710. end;
  1711. end;
  1712. 'h' :
  1713. begin
  1714. NoPressEnter:=true;
  1715. if (More <> '') and (More [1] = 'F') then
  1716. begin
  1717. FPCHelpLines := true;
  1718. Delete (More, 1, 1);
  1719. FPCBinaryPath := More;
  1720. end;
  1721. WriteHelpPages;
  1722. end;
  1723. 'i' :
  1724. begin
  1725. if (More='') or
  1726. (More [1] in ['a', 'c', 'f', 'i', 'o', 'r', 't', 'u', 'w']) then
  1727. WriteInfo (More)
  1728. else
  1729. QuickInfo:=QuickInfo+More;
  1730. end;
  1731. 'I' :
  1732. begin
  1733. if ispara then
  1734. ParaIncludePath.AddPath(More,false)
  1735. else
  1736. includesearchpath.AddPath(More,false);
  1737. end;
  1738. 'k' :
  1739. begin
  1740. if more<>'' then
  1741. ParaLinkOptions:=ParaLinkOptions+' '+More
  1742. else
  1743. IllegalPara(opt);
  1744. end;
  1745. 'l' :
  1746. ParaLogo:=not UnSetBool(more,0,opt,true);
  1747. {$ifdef PREPROCWRITE}
  1748. 'm' :
  1749. parapreprocess:=not UnSetBool(more,0,opt,true);
  1750. {$endif PREPROCWRITE}
  1751. 'M' :
  1752. begin
  1753. more:=Upper(more);
  1754. if not SetCompileMode(more, true) then
  1755. if not SetCompileModeSwitch(more, true) then
  1756. IllegalPara(opt);
  1757. end;
  1758. 'n' :
  1759. begin
  1760. if More='' then
  1761. disable_configfile:=true
  1762. else
  1763. IllegalPara(opt);
  1764. end;
  1765. 'o' :
  1766. begin
  1767. if More<>'' then
  1768. begin
  1769. DefaultReplacements(More);
  1770. D:=ExtractFilePath(More);
  1771. if (D<>'') then
  1772. OutputExeDir:=FixPath(D,True);
  1773. OutputFileName:=ExtractFileName(More);
  1774. end
  1775. else
  1776. IllegalPara(opt);
  1777. end;
  1778. 'O' :
  1779. begin
  1780. j:=1;
  1781. while j<=length(more) do
  1782. begin
  1783. case more[j] of
  1784. '1' :
  1785. init_settings.optimizerswitches:=init_settings.optimizerswitches+level1optimizerswitches;
  1786. '2' :
  1787. init_settings.optimizerswitches:=init_settings.optimizerswitches+level2optimizerswitches;
  1788. '3' :
  1789. init_settings.optimizerswitches:=init_settings.optimizerswitches+level3optimizerswitches;
  1790. '4' :
  1791. init_settings.optimizerswitches:=init_settings.optimizerswitches+level4optimizerswitches;
  1792. 'a' :
  1793. begin
  1794. if not(UpdateAlignmentStr(Copy(Opt,j+3,255),ParaAlignment)) then
  1795. IllegalPara(opt);
  1796. break;
  1797. end;
  1798. 's' :
  1799. include(init_settings.optimizerswitches,cs_opt_size);
  1800. 'p' :
  1801. begin
  1802. if not Setoptimizecputype(copy(more,j+1,length(more)),init_settings.optimizecputype) then
  1803. begin
  1804. OptCPUSetExplicitly:=true;
  1805. { Give warning for old i386 switches }
  1806. if (Length(More)-j=1) and
  1807. (More[j+1]>='1') and (More[j+1]<='5')then
  1808. Message2(option_obsolete_switch_use_new,'-Op<nr>','-Op<name>')
  1809. else
  1810. IllegalPara(opt);
  1811. end;
  1812. break;
  1813. end;
  1814. 'o' :
  1815. begin
  1816. if not UpdateOptimizerStr(copy(more,j+1,length(more)),init_settings.optimizerswitches) then
  1817. IllegalPara(opt);
  1818. break;
  1819. end;
  1820. '-' :
  1821. begin
  1822. init_settings.optimizerswitches:=[];
  1823. FillChar(ParaAlignment,sizeof(ParaAlignment),0);
  1824. end;
  1825. { Obsolete switches }
  1826. 'g' :
  1827. Message2(option_obsolete_switch_use_new,'-Og','-Os');
  1828. 'G' :
  1829. Message1(option_obsolete_switch,'-OG');
  1830. 'r' :
  1831. Message2(option_obsolete_switch_use_new,'-Or','-O2 or -Ooregvar');
  1832. 'u' :
  1833. Message2(option_obsolete_switch_use_new,'-Ou','-Oouncertain');
  1834. 'w' :
  1835. begin
  1836. if not UpdateWpoStr(copy(more,j+1,length(more)),init_settings.dowpoptimizerswitches) then
  1837. IllegalPara(opt);
  1838. break;
  1839. end;
  1840. 'W' :
  1841. begin
  1842. if not UpdateWpoStr(copy(more,j+1,length(more)),init_settings.genwpoptimizerswitches) then
  1843. IllegalPara(opt);
  1844. break;
  1845. end;
  1846. else
  1847. IllegalPara(opt);
  1848. end;
  1849. inc(j);
  1850. end;
  1851. end;
  1852. 'p' :
  1853. begin
  1854. if UnsetBool(More, 0, opt, false) then
  1855. begin
  1856. init_settings.moduleswitches:=init_settings.moduleswitches-[cs_profile];
  1857. undef_system_macro('FPC_PROFILE');
  1858. end
  1859. else
  1860. if Length(More)=0 then
  1861. IllegalPara(opt)
  1862. else
  1863. case more[1] of
  1864. 'g' : if UnsetBool(more, 1, opt, false) then
  1865. begin
  1866. exclude(init_settings.moduleswitches,cs_profile);
  1867. undef_system_macro('FPC_PROFILE');
  1868. end
  1869. else if (target_info.system in supported_targets_pg) then
  1870. begin
  1871. include(init_settings.moduleswitches,cs_profile);
  1872. def_system_macro('FPC_PROFILE');
  1873. end
  1874. else
  1875. UnsupportedPara('-pg');
  1876. else
  1877. IllegalPara(opt);
  1878. end;
  1879. end;
  1880. 'P' :
  1881. begin
  1882. { used to select the target processor with the "fpc" binary;
  1883. give an error if it's not the target architecture supported by
  1884. this compiler binary (will be verified after the target_info
  1885. is set) }
  1886. processorstr:=More;
  1887. end;
  1888. 'R' :
  1889. begin
  1890. if not SetAsmReadMode(More,init_settings.asmmode) then
  1891. IllegalPara(opt);
  1892. end;
  1893. 's' :
  1894. begin
  1895. if UnsetBool(More, 0, opt, false) then
  1896. begin
  1897. init_settings.globalswitches:=init_settings.globalswitches-[cs_asm_extern,cs_link_extern,cs_link_nolink];
  1898. if more<>'' then
  1899. IllegalPara(opt);
  1900. end
  1901. else
  1902. begin
  1903. init_settings.globalswitches:=init_settings.globalswitches+[cs_asm_extern,cs_link_extern,cs_link_nolink];
  1904. if more='h' then
  1905. init_settings.globalswitches:=init_settings.globalswitches-[cs_link_on_target]
  1906. else if more='t' then
  1907. init_settings.globalswitches:=init_settings.globalswitches+[cs_link_on_target]
  1908. else if more='r' then
  1909. init_settings.globalswitches:=init_settings.globalswitches+[cs_asm_leave,cs_no_regalloc]
  1910. else if more<>'' then
  1911. IllegalPara(opt);
  1912. end;
  1913. end;
  1914. 'S' :
  1915. begin
  1916. if more='' then
  1917. IllegalPara(opt);
  1918. if more[1]='I' then
  1919. begin
  1920. {$ifdef jvm}
  1921. UnsupportedPara('-SI');
  1922. {$endif}
  1923. if upper(more)='ICOM' then
  1924. init_settings.interfacetype:=it_interfacecom
  1925. else if upper(more)='ICORBA' then
  1926. init_settings.interfacetype:=it_interfacecorba
  1927. else
  1928. IllegalPara(opt);
  1929. end
  1930. else
  1931. begin
  1932. j:=1;
  1933. while j<=length(more) do
  1934. begin
  1935. case more[j] of
  1936. '2' : //an alternative to -Mobjfpc
  1937. SetCompileMode('OBJFPC',true);
  1938. 'a' :
  1939. If UnsetBool(More, j, opt, false) then
  1940. exclude(init_settings.localswitches,cs_do_assertion)
  1941. else
  1942. include(init_settings.localswitches,cs_do_assertion);
  1943. 'c' :
  1944. If UnsetBool(More, j, opt, false) then
  1945. exclude(init_settings.moduleswitches,cs_support_c_operators)
  1946. else
  1947. include(init_settings.moduleswitches,cs_support_c_operators);
  1948. 'd' : //an alternative to -Mdelphi
  1949. SetCompileMode('DELPHI',true);
  1950. 'e' :
  1951. begin
  1952. SetErrorFlags(copy(more,j+1,length(more)));
  1953. break;
  1954. end;
  1955. 'f' :
  1956. begin
  1957. if not(cs_compilesystem in init_settings.moduleswitches) then
  1958. Message(option_features_only_for_system_unit);
  1959. inc(j);
  1960. if more[j]='-' then
  1961. begin
  1962. if length(more)>j then
  1963. IllegalPara(opt)
  1964. else
  1965. features:=[];
  1966. end
  1967. else
  1968. begin
  1969. if (HandleFeature(upper(copy(more,j,length(more)-j+1)))) then
  1970. j:=length(more)
  1971. else
  1972. IllegalPara(opt);
  1973. end;
  1974. end;
  1975. 'g' :
  1976. If UnsetBool(More, j, opt, false) then
  1977. exclude(init_settings.moduleswitches,cs_support_goto)
  1978. else
  1979. include(init_settings.moduleswitches,cs_support_goto);
  1980. 'h' :
  1981. If UnsetBool(More, j, opt, false) then
  1982. exclude(init_settings.localswitches,cs_refcountedstrings)
  1983. else
  1984. include(init_settings.localswitches,cs_refcountedstrings);
  1985. 'i' :
  1986. If UnsetBool(More, j, opt, false) then
  1987. exclude(init_settings.localswitches,cs_do_inline)
  1988. else
  1989. include(init_settings.localswitches,cs_do_inline);
  1990. 'j' :
  1991. If UnsetBool(More, j, opt, false) then
  1992. exclude(init_settings.localswitches,cs_typed_const_writable)
  1993. else
  1994. include(init_settings.localswitches,cs_typed_const_writable);
  1995. 'k' :
  1996. If UnsetBool(More, j, opt, false) then
  1997. exclude(init_settings.globalswitches,cs_load_fpcylix_unit)
  1998. else
  1999. include(init_settings.globalswitches,cs_load_fpcylix_unit);
  2000. 'm' :
  2001. If UnsetBool(More, j, opt, false) then
  2002. exclude(init_settings.moduleswitches,cs_support_macro)
  2003. else
  2004. include(init_settings.moduleswitches,cs_support_macro);
  2005. 'o' : //an alternative to -Mtp
  2006. SetCompileMode('TP',true);
  2007. 'r' :
  2008. If UnsetBool(More, j, opt, false) then
  2009. exclude(init_settings.globalswitches,cs_transparent_file_names)
  2010. else
  2011. include(init_settings.globalswitches,cs_transparent_file_names);
  2012. {$ifdef gpc_mode}
  2013. 'p' : //an alternative to -Mgpc
  2014. SetCompileMode('GPC',true);
  2015. {$endif}
  2016. 's' :
  2017. If UnsetBool(More, j, opt, false) then
  2018. exclude(init_settings.globalswitches,cs_constructor_name)
  2019. else
  2020. include(init_settings.globalswitches,cs_constructor_name);
  2021. 't' :
  2022. Message1(option_obsolete_switch,'-St');
  2023. 'v' :
  2024. If UnsetBool(More, j, opt, false) then
  2025. exclude(init_settings.globalswitches,cs_support_vectors)
  2026. else
  2027. include(init_settings.globalswitches,cs_support_vectors);
  2028. 'x' :
  2029. If UnsetBool(More, j, opt, false) then
  2030. SetCompileModeSwitch('EXCEPTIONS-',true)
  2031. else
  2032. SetCompileModeSwitch('EXCEPTIONS',true);
  2033. 'y' :
  2034. If UnsetBool(More, j, opt, false) then
  2035. exclude(init_settings.localswitches,cs_typed_addresses)
  2036. else
  2037. include(init_settings.localswitches,cs_typed_addresses);
  2038. '-' :
  2039. begin
  2040. init_settings.globalswitches:=init_settings.globalswitches - [cs_constructor_name,cs_support_exceptions,
  2041. cs_support_vectors,cs_load_fpcylix_unit];
  2042. init_settings.localswitches:=init_settings.localswitches - [cs_do_assertion,cs_do_inline, cs_refcountedstrings,
  2043. cs_typed_addresses];
  2044. init_settings.moduleswitches:=init_settings.moduleswitches - [cs_support_c_operators, cs_support_goto,
  2045. cs_support_macro];
  2046. end;
  2047. else
  2048. IllegalPara(opt);
  2049. end;
  2050. inc(j);
  2051. end;
  2052. end;
  2053. end;
  2054. 'T' :
  2055. begin
  2056. more:=Upper(More);
  2057. if paratarget=system_none then
  2058. begin
  2059. { remove old target define }
  2060. TargetOptions(false);
  2061. { load new target }
  2062. paratarget:=find_system_by_string(More);
  2063. if paratarget<>system_none then
  2064. set_target(paratarget)
  2065. else
  2066. IllegalPara(opt);
  2067. { set new define }
  2068. TargetOptions(true);
  2069. end
  2070. else
  2071. if More<>upper(target_info.shortname) then
  2072. Message1(option_target_is_already_set,target_info.shortname);
  2073. end;
  2074. 'u' :
  2075. if is_identifier(more) then
  2076. undef_system_macro(more)
  2077. else
  2078. begin
  2079. if (more='') then
  2080. Message1(option_missing_arg,'-u')
  2081. else
  2082. Message1(option_malformed_para,opt);
  2083. StopOptions(1);
  2084. end;
  2085. 'U' :
  2086. begin
  2087. j:=1;
  2088. while j<=length(more) do
  2089. begin
  2090. case more[j] of
  2091. {$ifdef UNITALIASES}
  2092. 'a' :
  2093. begin
  2094. AddUnitAlias(Copy(More,j+1,255));
  2095. break;
  2096. end;
  2097. {$endif UNITALIASES}
  2098. 'n' :
  2099. exclude(init_settings.globalswitches,cs_check_unit_name);
  2100. 'p' :
  2101. begin
  2102. Message2(option_obsolete_switch_use_new,'-Up','-Fu');
  2103. break;
  2104. end;
  2105. 'r' :
  2106. begin
  2107. do_release:=true;
  2108. if (cs_checkpointer in init_settings.localswitches) then
  2109. begin
  2110. Message(option_gc_incompatible_with_release_flag);
  2111. exclude(init_settings.localswitches,cs_checkpointer);
  2112. end;
  2113. end;
  2114. 's' :
  2115. include(init_settings.moduleswitches,cs_compilesystem);
  2116. '-' :
  2117. begin
  2118. exclude(init_settings.moduleswitches,cs_compilesystem);
  2119. exclude(init_settings.globalswitches,cs_check_unit_name);
  2120. end;
  2121. else
  2122. IllegalPara(opt);
  2123. end;
  2124. inc(j);
  2125. end;
  2126. end;
  2127. 'v' :
  2128. begin
  2129. if not setverbosity(More) then
  2130. IllegalPara(opt);
  2131. end;
  2132. 'V' : ; { Ignore used by fpc }
  2133. 'W' :
  2134. begin
  2135. j:=1;
  2136. while j<=length(More) do
  2137. begin
  2138. case More[j] of
  2139. 'A':
  2140. begin
  2141. if target_info.system in systems_all_windows then
  2142. begin
  2143. if UnsetBool(More, j, opt, false) then
  2144. SetApptype(app_cui)
  2145. else
  2146. SetApptype(app_native);
  2147. end
  2148. else
  2149. IllegalPara(opt);
  2150. end;
  2151. 'b':
  2152. begin
  2153. if target_info.system in systems_darwin then
  2154. begin
  2155. if UnsetBool(More, j, opt, false) then
  2156. SetApptype(app_cui)
  2157. else
  2158. SetApptype(app_bundle)
  2159. end
  2160. else
  2161. IllegalPara(opt);
  2162. end;
  2163. 'B':
  2164. begin
  2165. if target_info.system in systems_all_windows+systems_symbian then
  2166. begin
  2167. { -WB200000 means set trefered base address
  2168. to $200000, but does not change relocsection boolean
  2169. this way we can create both relocatble and
  2170. non relocatable DLL at a specific base address PM }
  2171. if (length(More)>j) then
  2172. begin
  2173. val('$'+Copy(More,j+1,255),imagebase,code);
  2174. if code<>0 then
  2175. IllegalPara(opt);
  2176. ImageBaseSetExplicity:=true;
  2177. end
  2178. else
  2179. begin
  2180. RelocSection:=true;
  2181. RelocSectionSetExplicitly:=true;
  2182. end;
  2183. break;
  2184. end
  2185. else
  2186. IllegalPara(opt);
  2187. end;
  2188. 'C':
  2189. begin
  2190. if target_info.system in systems_all_windows+systems_os2+systems_macos then
  2191. begin
  2192. if UnsetBool(More, j, opt, false) then
  2193. SetApptype(app_gui)
  2194. else
  2195. SetApptype(app_cui);
  2196. end
  2197. else
  2198. IllegalPara(opt);
  2199. end;
  2200. 'D':
  2201. begin
  2202. if target_info.system in systems_all_windows then
  2203. begin
  2204. UseDeffileForExports:=not UnsetBool(More, j, opt, false);
  2205. UseDeffileForExportsSetExplicitly:=true;
  2206. end
  2207. else
  2208. IllegalPara(opt);
  2209. end;
  2210. 'e':
  2211. begin
  2212. if (target_info.system in systems_darwin) then
  2213. begin
  2214. set_target_res(res_ext);
  2215. target_info.resobjext:='.fpcres';
  2216. end
  2217. else
  2218. IllegalPara(opt);
  2219. end;
  2220. 'F':
  2221. begin
  2222. {$if defined(m68k)}
  2223. if target_info.system in [system_m68k_atari] then
  2224. begin
  2225. if (length(More)>j) then
  2226. begin
  2227. val(Copy(More,j+1,255),ataritos_exe_flags,code);
  2228. if code<>0 then
  2229. IllegalPara(opt);
  2230. end
  2231. else
  2232. IllegalPara(opt);
  2233. break;
  2234. end;
  2235. {$endif defined(m68k)}
  2236. if target_info.system in systems_os2 then
  2237. begin
  2238. if UnsetBool(More, j, opt, false) then
  2239. SetApptype(app_cui)
  2240. else
  2241. SetApptype(app_fs);
  2242. end
  2243. else
  2244. IllegalPara(opt);
  2245. end;
  2246. 'G':
  2247. begin
  2248. if target_info.system in systems_all_windows+systems_os2+systems_macos then
  2249. begin
  2250. if UnsetBool(More, j, opt, false) then
  2251. SetApptype(app_cui)
  2252. else
  2253. SetApptype(app_gui);
  2254. end
  2255. else
  2256. IllegalPara(opt);
  2257. end;
  2258. {$if defined(i8086)}
  2259. 'h':
  2260. begin
  2261. if UnsetBool(More, j, opt, false) then
  2262. exclude(init_settings.moduleswitches,cs_huge_code)
  2263. else
  2264. include(init_settings.moduleswitches,cs_huge_code);
  2265. end;
  2266. {$endif defined(i8086)}
  2267. 'I':
  2268. begin
  2269. if target_info.system in systems_all_windows then
  2270. begin
  2271. GenerateImportSection:=not UnsetBool(More,j,opt,false);
  2272. GenerateImportSectionSetExplicitly:=true;
  2273. end
  2274. else
  2275. IllegalPara(opt);
  2276. end;
  2277. 'i':
  2278. begin
  2279. if (target_info.system in systems_darwin) then
  2280. begin
  2281. set_target_res(res_macho);
  2282. target_info.resobjext:=
  2283. targetinfos[target_info.system]^.resobjext;
  2284. end
  2285. else
  2286. IllegalPara(opt);
  2287. end;
  2288. 'm':
  2289. begin
  2290. {$if defined(i8086)}
  2291. if (target_info.system in [system_i8086_msdos,system_i8086_win16,system_i8086_embedded]) then
  2292. begin
  2293. case Upper(Copy(More,j+1,255)) of
  2294. 'TINY': init_settings.x86memorymodel:=mm_tiny;
  2295. 'SMALL': init_settings.x86memorymodel:=mm_small;
  2296. 'MEDIUM': init_settings.x86memorymodel:=mm_medium;
  2297. 'COMPACT': init_settings.x86memorymodel:=mm_compact;
  2298. 'LARGE': init_settings.x86memorymodel:=mm_large;
  2299. 'HUGE': init_settings.x86memorymodel:=mm_huge;
  2300. else
  2301. IllegalPara(opt);
  2302. end;
  2303. break;
  2304. end
  2305. else
  2306. {$endif defined(i8086)}
  2307. IllegalPara(opt);
  2308. end;
  2309. 'M':
  2310. begin
  2311. if (target_info.system in (systems_darwin-[system_i386_iphonesim,system_arm_ios,system_aarch64_ios,system_x86_64_iphonesim])) and
  2312. ParseMacVersionMin(MacOSXVersionMin,iPhoneOSVersionMin,'MAC_OS_X_VERSION_MIN_REQUIRED',copy(More,2,255),false) then
  2313. begin
  2314. break;
  2315. end
  2316. else
  2317. IllegalPara(opt);
  2318. end;
  2319. 'N':
  2320. begin
  2321. if target_info.system in systems_all_windows then
  2322. begin
  2323. RelocSection:=UnsetBool(More,j,opt,false);
  2324. RelocSectionSetExplicitly:=true;
  2325. end
  2326. else
  2327. IllegalPara(opt);
  2328. end;
  2329. 'p':
  2330. begin
  2331. {$push}
  2332. {$warn 6018 off} { Unreachable code due to compile time evaluation }
  2333. if (target_info.system in systems_embedded) and
  2334. ControllerSupport then
  2335. begin
  2336. s:=upper(copy(more,j+1,length(more)-j));
  2337. if not(SetControllerType(s,init_settings.controllertype)) then
  2338. IllegalPara(opt)
  2339. else
  2340. begin
  2341. if init_settings.cputype<>embedded_controllers[init_settings.controllertype].cputype then
  2342. begin
  2343. Message(scan_n_changecputype);
  2344. init_settings.cputype:=embedded_controllers[init_settings.controllertype].cputype;
  2345. end;
  2346. end;
  2347. break;
  2348. end
  2349. else
  2350. IllegalPara(opt);
  2351. {$pop}
  2352. end;
  2353. 'P':
  2354. begin
  2355. if (target_info.system in [system_i386_iphonesim,system_arm_ios,system_aarch64_ios,system_x86_64_iphonesim]) and
  2356. ParseMacVersionMin(iPhoneOSVersionMin,MacOSXVersionMin,'IPHONE_OS_VERSION_MIN_REQUIRED',copy(More,2,255),true) then
  2357. begin
  2358. break;
  2359. end
  2360. else
  2361. IllegalPara(opt);
  2362. end;
  2363. 'R':
  2364. begin
  2365. if target_info.system in systems_all_windows then
  2366. begin
  2367. { support -WR+ / -WR- as synonyms to -WR / -WN }
  2368. RelocSection:=not UnsetBool(More,j,opt,false);
  2369. RelocSectionSetExplicitly:=true;
  2370. end
  2371. else
  2372. IllegalPara(opt);
  2373. end;
  2374. 't':
  2375. begin
  2376. {$if defined(i8086)}
  2377. if (target_info.system in [system_i8086_msdos,system_i8086_embedded]) then
  2378. begin
  2379. case Upper(Copy(More,j+1,255)) of
  2380. 'EXE': SetAppType(app_cui);
  2381. 'COM': SetAppType(app_com);
  2382. else
  2383. IllegalPara(opt);
  2384. end;
  2385. break;
  2386. end
  2387. else
  2388. {$endif defined(i8086)}
  2389. IllegalPara(opt);
  2390. end;
  2391. 'T':
  2392. begin
  2393. if target_info.system in systems_macos then
  2394. begin
  2395. if UnsetBool(More, j, opt, false) then
  2396. SetApptype(app_cui)
  2397. else
  2398. SetApptype(app_tool);
  2399. end
  2400. else
  2401. IllegalPara(opt);
  2402. end;
  2403. 'X':
  2404. begin
  2405. if (target_info.system in systems_linux) then
  2406. begin
  2407. if UnsetBool(More, j, opt, false) then
  2408. exclude(init_settings.moduleswitches,cs_executable_stack)
  2409. else
  2410. include(init_settings.moduleswitches,cs_executable_stack)
  2411. end
  2412. else
  2413. IllegalPara(opt);
  2414. end;
  2415. else
  2416. IllegalPara(opt);
  2417. end;
  2418. inc(j);
  2419. end;
  2420. end;
  2421. 'X' :
  2422. begin
  2423. j:=1;
  2424. while j<=length(more) do
  2425. begin
  2426. case More[j] of
  2427. '9' :
  2428. begin
  2429. if target_info.system in systems_linux then
  2430. begin
  2431. if UnsetBool(More, j, opt, false) then
  2432. exclude(init_settings.globalswitches,cs_link_pre_binutils_2_19)
  2433. else
  2434. include(init_settings.globalswitches,cs_link_pre_binutils_2_19);
  2435. end
  2436. else
  2437. IllegalPara(opt);
  2438. end;
  2439. 'c' : Cshared:=TRUE;
  2440. 'd' : Dontlinkstdlibpath:=TRUE;
  2441. 'e' :
  2442. begin
  2443. If UnsetBool(More, j, opt, false) then
  2444. exclude(init_settings.globalswitches,cs_link_extern)
  2445. else
  2446. include(init_settings.globalswitches,cs_link_extern);
  2447. end;
  2448. 'f' :
  2449. include(init_settings.globalswitches,cs_link_pthread);
  2450. 'g' :
  2451. begin
  2452. If UnsetBool(More, j, opt, false) then
  2453. exclude(init_settings.globalswitches,cs_link_separate_dbg_file)
  2454. else
  2455. include(init_settings.globalswitches,cs_link_separate_dbg_file);
  2456. end;
  2457. 'i' :
  2458. begin
  2459. If UnsetBool(More, j, opt, false) then
  2460. include(init_settings.globalswitches,cs_link_extern)
  2461. else
  2462. exclude(init_settings.globalswitches,cs_link_extern);
  2463. end;
  2464. 'n' :
  2465. begin
  2466. If UnsetBool(More, j, opt, false) then
  2467. exclude(init_settings.globalswitches,cs_link_native)
  2468. else
  2469. include(init_settings.globalswitches,cs_link_native);
  2470. end;
  2471. 'm' :
  2472. begin
  2473. If UnsetBool(More, j, opt, false) then
  2474. exclude(init_settings.globalswitches,cs_link_map)
  2475. else
  2476. include(init_settings.globalswitches,cs_link_map);
  2477. end;
  2478. 'p' : ; { Ignore used by fpc.pp }
  2479. 'r' :
  2480. begin
  2481. if (target_info.system in suppported_targets_x_smallr) then
  2482. begin
  2483. rlinkpath:=Copy(more,2,length(More)-1);
  2484. DefaultReplacements(rlinkpath);
  2485. end
  2486. else
  2487. IgnoredPara('-Xr');
  2488. more:='';
  2489. end;
  2490. 'R' :
  2491. begin
  2492. sysrootpath:=copy(more,2,length(more)-1);
  2493. defaultreplacements(sysrootpath);
  2494. more:='';
  2495. end;
  2496. 's' :
  2497. begin
  2498. If UnsetBool(More, j, opt, false) then
  2499. exclude(init_settings.globalswitches,cs_link_strip)
  2500. else
  2501. include(init_settings.globalswitches,cs_link_strip);
  2502. end;
  2503. 't' :
  2504. include(init_settings.globalswitches,cs_link_staticflag);
  2505. 'v' :
  2506. begin
  2507. If UnsetBool(More, j, opt, false) then
  2508. exclude(init_settings.globalswitches,cs_link_opt_vtable)
  2509. else
  2510. include(init_settings.globalswitches,cs_link_opt_vtable);
  2511. end;
  2512. 'D' :
  2513. begin
  2514. def_system_macro('FPC_LINK_DYNAMIC');
  2515. undef_system_macro('FPC_LINK_SMART');
  2516. undef_system_macro('FPC_LINK_STATIC');
  2517. exclude(init_settings.globalswitches,cs_link_static);
  2518. exclude(init_settings.globalswitches,cs_link_smart);
  2519. include(init_settings.globalswitches,cs_link_shared);
  2520. LinkTypeSetExplicitly:=true;
  2521. end;
  2522. 'M' :
  2523. begin
  2524. mainaliasname:=Copy(more,2,length(More)-1);
  2525. More:='';
  2526. end;
  2527. 'P' :
  2528. begin
  2529. utilsprefix:=Copy(more,2,length(More)-1);
  2530. DefaultReplacements(utilsprefix);
  2531. More:='';
  2532. end;
  2533. 'L' : begin // -XLO is link order -XLA is link alias. -XLD avoids load defaults.
  2534. // these are not aggregable.
  2535. if (j=length(more)) or not (more[j+1] in ['O','A','D']) then
  2536. IllegalPara(opt)
  2537. else
  2538. begin
  2539. case more[j+1] of
  2540. 'A' : begin
  2541. s:=Copy(more,3,length(More)-2);
  2542. if not LinkLibraryAliases.AddDep(s) Then
  2543. IllegalPara(opt);
  2544. end;
  2545. 'O' : begin
  2546. s:=Copy(more,3,length(More)-2);
  2547. if not LinkLibraryOrder.AddWeight(s) Then
  2548. IllegalPara(opt);
  2549. end;
  2550. 'D' : include(init_settings.globalswitches,cs_link_no_default_lib_order)
  2551. else
  2552. IllegalPara(opt);
  2553. end; {case}
  2554. j:=length(more);
  2555. end; {else begin}
  2556. end;
  2557. 'S' :
  2558. begin
  2559. ForceStaticLinking;
  2560. end;
  2561. 'V' :
  2562. begin
  2563. if UnsetBool(More, j, opt, false) then
  2564. exclude(init_settings.globalswitches,cs_link_vlink)
  2565. else
  2566. begin
  2567. include(init_settings.globalswitches,cs_link_vlink);
  2568. include(init_settings.globalswitches,cs_link_extern);
  2569. end;
  2570. LinkerSetExplicitly:=true;
  2571. end;
  2572. 'X' :
  2573. begin
  2574. def_system_macro('FPC_LINK_SMART');
  2575. undef_system_macro('FPC_LINK_STATIC');
  2576. undef_system_macro('FPC_LINK_DYNAMIC');
  2577. exclude(init_settings.globalswitches,cs_link_static);
  2578. include(init_settings.globalswitches,cs_link_smart);
  2579. exclude(init_settings.globalswitches,cs_link_shared);
  2580. LinkTypeSetExplicitly:=true;
  2581. end;
  2582. '-' :
  2583. begin
  2584. exclude(init_settings.globalswitches,cs_link_staticflag);
  2585. exclude(init_settings.globalswitches,cs_link_strip);
  2586. exclude(init_settings.globalswitches,cs_link_map);
  2587. set_default_link_type;
  2588. end;
  2589. else
  2590. IllegalPara(opt);
  2591. end;
  2592. inc(j);
  2593. end;
  2594. end;
  2595. else
  2596. IllegalPara(opt);
  2597. end;
  2598. end;
  2599. '@' :
  2600. begin
  2601. Message(option_no_nested_response_file);
  2602. StopOptions(1);
  2603. end;
  2604. else
  2605. begin
  2606. if (length(param_file)<>0) then
  2607. Message2(option_only_one_source_support,param_file,opt);
  2608. param_file:=opt;
  2609. Message1(option_found_file,opt);
  2610. end;
  2611. end;
  2612. end;
  2613. procedure Toption.Interpret_file(const filename : TPathStr);
  2614. procedure RemoveSep(var fn:TPathStr);
  2615. var
  2616. i : longint;
  2617. begin
  2618. i:=0;
  2619. while (i<length(fn)) and (fn[i+1] in [',',' ',#9]) do
  2620. inc(i);
  2621. Delete(fn,1,i);
  2622. i:=length(fn);
  2623. while (i>0) and (fn[i] in [',',' ',#9]) do
  2624. dec(i);
  2625. fn:=copy(fn,1,i);
  2626. end;
  2627. function GetName(var fn:TPathStr):TPathStr;
  2628. var
  2629. i : longint;
  2630. begin
  2631. i:=0;
  2632. while (i<length(fn)) and (fn[i+1] in ['a'..'z','A'..'Z','0'..'9','_','-']) do
  2633. inc(i);
  2634. GetName:=Copy(fn,1,i);
  2635. Delete(fn,1,i);
  2636. end;
  2637. const
  2638. maxlevel = 15;
  2639. var
  2640. f : text;
  2641. s, tmp,
  2642. opts : TCmdStr;
  2643. skip : array[0..maxlevel] of boolean;
  2644. line,
  2645. level : longint;
  2646. option_read : boolean;
  2647. oldfilemode : byte;
  2648. ConfigFile: TPathStr;
  2649. begin
  2650. { avoid infinite loop }
  2651. Inc(FileLevel);
  2652. Option_read:=false;
  2653. If FileLevel>MaxLevel then
  2654. Message(option_too_many_cfg_files);
  2655. if not ParaIncludeCfgPath.FindFile(fileName,true,ConfigFile) then
  2656. ConfigFile := ExpandFileName(filename);
  2657. { Maybe It's Directory ?} //Jaro Change:
  2658. if PathExists(ConfigFile,false) then
  2659. begin
  2660. Message1(option_config_is_dir,filename);
  2661. exit;
  2662. end;
  2663. { open file }
  2664. Message1(option_using_file,filename);
  2665. oldfilemode:=filemode;
  2666. filemode:=0;
  2667. assign(f,ConfigFile);
  2668. {$push}{$I-}
  2669. reset(f);
  2670. {$pop}
  2671. filemode:=oldfilemode;
  2672. if ioresult<>0 then
  2673. begin
  2674. Message1(option_unable_open_file,filename);
  2675. exit;
  2676. end;
  2677. Message1(option_start_reading_configfile,filename);
  2678. fillchar(skip,sizeof(skip),0);
  2679. level:=0;
  2680. line:=0;
  2681. while not eof(f) do
  2682. begin
  2683. readln(f,opts);
  2684. inc(line);
  2685. RemoveSep(opts);
  2686. if (opts<>'') and (opts[1]<>';') then
  2687. begin
  2688. if opts[1]='#' then
  2689. begin
  2690. Message1(option_interpreting_file_option,opts);
  2691. Delete(opts,1,1);
  2692. s:=upper(GetName(opts));
  2693. if (s='SECTION') then
  2694. begin
  2695. RemoveSep(opts);
  2696. s:=upper(GetName(opts));
  2697. if level=0 then
  2698. skip[level]:=not defined_macro(s) or (s='COMMON');
  2699. end
  2700. else
  2701. if (s='IFDEF') then
  2702. begin
  2703. RemoveSep(opts);
  2704. if Level>=maxlevel then
  2705. begin
  2706. Message2(option_too_many_ifdef,filename,tostr(line));
  2707. stopOptions(1);
  2708. end;
  2709. inc(Level);
  2710. skip[level]:=(skip[level-1] or not defined_macro(upper(GetName(opts))));
  2711. end
  2712. else
  2713. if (s='IFNDEF') then
  2714. begin
  2715. RemoveSep(opts);
  2716. if Level>=maxlevel then
  2717. begin
  2718. Message2(option_too_many_ifdef,filename,tostr(line));
  2719. stopOptions(1);
  2720. end;
  2721. inc(Level);
  2722. skip[level]:=(skip[level-1] or defined_macro(upper(GetName(opts))));
  2723. end
  2724. else
  2725. if (s='ELSE') then
  2726. begin
  2727. if Level=0 then
  2728. begin
  2729. Message2(option_else_without_if,filename,tostr(line));
  2730. stopOptions(1);
  2731. end
  2732. else
  2733. skip[level]:=skip[level-1] or (not skip[level])
  2734. end
  2735. else
  2736. if (s='ENDIF') then
  2737. begin
  2738. skip[level]:=false;
  2739. if Level=0 then
  2740. begin
  2741. Message2(option_too_many_endif,filename,tostr(line));
  2742. stopOptions(1);
  2743. end;
  2744. dec(level);
  2745. end
  2746. else
  2747. if (not skip[level]) then
  2748. begin
  2749. if (s='DEFINE') then
  2750. begin
  2751. RemoveSep(opts);
  2752. tmp:= GetName(opts);
  2753. if tmp <> '' then
  2754. def_system_macro(tmp);
  2755. Option_read:=true;
  2756. end
  2757. else
  2758. if (s='UNDEF') then
  2759. begin
  2760. RemoveSep(opts);
  2761. tmp:= GetName(opts);
  2762. if tmp <> '' then
  2763. undef_system_macro(tmp);
  2764. Option_read:=true;
  2765. end
  2766. else
  2767. if (s='WRITE') then
  2768. begin
  2769. Delete(opts,1,1);
  2770. DefaultReplacements(opts);
  2771. WriteLn(opts);
  2772. Option_read:=true;
  2773. end
  2774. else
  2775. if (s='INCLUDE') then
  2776. begin
  2777. Delete(opts,1,1);
  2778. DefaultReplacements(opts);
  2779. Interpret_file(opts);
  2780. Option_read:=true;
  2781. end
  2782. else
  2783. if (s='CFGDIR') then
  2784. begin
  2785. Delete(opts,1,1);
  2786. DefaultReplacements(opts);
  2787. ParaIncludeCfgPath.AddPath(opts,false);
  2788. Option_read:=true;
  2789. end;
  2790. end;
  2791. end
  2792. else
  2793. begin
  2794. if (opts[1]='-') or (opts[1]='@') then
  2795. begin
  2796. if (not skip[level]) then
  2797. interpret_option(opts,false);
  2798. Option_read:=true;
  2799. end
  2800. else
  2801. Message1(option_illegal_para,opts);
  2802. end;
  2803. end;
  2804. end;
  2805. if Level>0 then
  2806. Message(option_too_less_endif);
  2807. if Not Option_read then
  2808. Message1(option_no_option_found,filename)
  2809. else
  2810. Message1(option_end_reading_configfile,filename);
  2811. Close(f);
  2812. Dec(FileLevel);
  2813. end;
  2814. procedure Toption.Interpret_envvar(const envname : TCmdStr);
  2815. var
  2816. argstart,
  2817. env,
  2818. pc : pchar;
  2819. arglen : longint;
  2820. quote : set of char;
  2821. hs : TCmdStr;
  2822. begin
  2823. Message1(option_using_env,envname);
  2824. env:=GetEnvPChar(envname);
  2825. pc:=env;
  2826. hs:='';
  2827. if assigned(pc) then
  2828. begin
  2829. repeat
  2830. { skip leading spaces }
  2831. while pc^ in [' ',#9,#13] do
  2832. inc(pc);
  2833. case pc^ of
  2834. #0 :
  2835. break;
  2836. '"' :
  2837. begin
  2838. quote:=['"'];
  2839. inc(pc);
  2840. end;
  2841. '''' :
  2842. begin
  2843. quote:=[''''];
  2844. inc(pc);
  2845. end;
  2846. else
  2847. quote:=[' ',#9,#13];
  2848. end;
  2849. { scan until the end of the argument }
  2850. argstart:=pc;
  2851. while (pc^<>#0) and not(pc^ in quote) do
  2852. inc(pc);
  2853. { create argument }
  2854. arglen:=pc-argstart;
  2855. { TODO: FIXME: silent truncation of environment parameters }
  2856. if (arglen > 255) then
  2857. arglen := 255;
  2858. setlength(hs,arglen);
  2859. move(argstart^,hs[1],arglen);
  2860. interpret_option(hs,true);
  2861. { skip quote }
  2862. if pc^ in quote then
  2863. inc(pc);
  2864. until false;
  2865. end
  2866. else
  2867. Message1(option_no_option_found,'(env) '+envname);
  2868. FreeEnvPChar(env);
  2869. end;
  2870. procedure toption.read_parameters;
  2871. var
  2872. opts : TCmdStr;
  2873. paramindex : longint;
  2874. begin
  2875. paramindex:=0;
  2876. while paramindex<paramcount do
  2877. begin
  2878. inc(paramindex);
  2879. opts:=objpas.paramstr(paramindex);
  2880. if length(opts)>0 then
  2881. case opts[1] of
  2882. '@' :
  2883. if not firstpass then
  2884. begin
  2885. Delete(opts,1,1);
  2886. Message1(option_reading_further_from,opts);
  2887. interpret_file(opts);
  2888. end;
  2889. '!' :
  2890. if not firstpass then
  2891. begin
  2892. Delete(opts,1,1);
  2893. Message1(option_reading_further_from,'(env) '+opts);
  2894. interpret_envvar(opts);
  2895. end;
  2896. else
  2897. interpret_option(opts,true);
  2898. end;
  2899. end;
  2900. end;
  2901. procedure toption.parsecmd(cmd:TCmdStr);
  2902. var
  2903. i,ps : longint;
  2904. opts : TCmdStr;
  2905. begin
  2906. while (cmd<>'') do
  2907. begin
  2908. while cmd[1]=' ' do
  2909. delete(cmd,1,1);
  2910. i:=pos(' ',cmd);
  2911. if i=0 then
  2912. i:=2147483647;
  2913. opts:=Copy(cmd,1,i-1);
  2914. Delete(cmd,1,i);
  2915. case opts[1] of
  2916. '@' :
  2917. if not firstpass then
  2918. begin
  2919. Delete(opts,1,1);
  2920. Message1(option_reading_further_from,opts);
  2921. interpret_file(opts);
  2922. end;
  2923. '!' :
  2924. if not firstpass then
  2925. begin
  2926. Delete(opts,1,1);
  2927. Message1(option_reading_further_from,'(env) '+opts);
  2928. interpret_envvar(opts);
  2929. end;
  2930. '"' :
  2931. begin
  2932. Delete(opts,1,1);
  2933. ps:=pos('"',cmd);
  2934. if (i<>256) and (ps>0) then
  2935. begin
  2936. opts:=opts + ' '+ copy(cmd,1,ps-1);
  2937. cmd:=copy(cmd,ps+1,255);
  2938. end;
  2939. interpret_option(opts,true);
  2940. end;
  2941. else
  2942. interpret_option(opts,true);
  2943. end;
  2944. end;
  2945. end;
  2946. procedure toption.writequickinfo;
  2947. var
  2948. s : string;
  2949. i : longint;
  2950. procedure addinfo(const hs:string);
  2951. begin
  2952. if s<>'' then
  2953. s:=s+' '+hs
  2954. else
  2955. s:=hs;
  2956. end;
  2957. begin
  2958. s:='';
  2959. i:=0;
  2960. while (i<length(quickinfo)) do
  2961. begin
  2962. inc(i);
  2963. case quickinfo[i] of
  2964. 'S' :
  2965. begin
  2966. inc(i);
  2967. case quickinfo[i] of
  2968. 'O' :
  2969. addinfo(lower(source_info.shortname));
  2970. 'P' :
  2971. addinfo(source_cpu_string);
  2972. else
  2973. IllegalPara('-i'+QuickInfo);
  2974. end;
  2975. end;
  2976. 'T' :
  2977. begin
  2978. inc(i);
  2979. case quickinfo[i] of
  2980. 'O' :
  2981. addinfo(lower(target_info.shortname));
  2982. 'P' :
  2983. AddInfo(target_cpu_string);
  2984. else
  2985. IllegalPara('-i'+QuickInfo);
  2986. end;
  2987. end;
  2988. 'V' :
  2989. AddInfo(version_string);
  2990. 'W' :
  2991. AddInfo(full_version_string);
  2992. 'D' :
  2993. AddInfo(date_string);
  2994. '_' :
  2995. ;
  2996. else
  2997. IllegalPara('-i'+QuickInfo);
  2998. end;
  2999. end;
  3000. if s<>'' then
  3001. begin
  3002. writeln(s);
  3003. stopoptions(0);
  3004. end;
  3005. end;
  3006. procedure TOption.TargetOptions(def:boolean);
  3007. var
  3008. s : string;
  3009. i : integer;
  3010. target_unsup_features : tfeatures;
  3011. begin
  3012. if def then
  3013. def_system_macro(target_info.shortname)
  3014. else
  3015. undef_system_macro(target_info.shortname);
  3016. s:=target_info.extradefines;
  3017. while (s<>'') do
  3018. begin
  3019. i:=pos(';',s);
  3020. if i=0 then
  3021. i:=length(s)+1;
  3022. if def then
  3023. def_system_macro(Copy(s,1,i-1))
  3024. else
  3025. undef_system_macro(Copy(s,1,i-1));
  3026. delete(s,1,i);
  3027. end;
  3028. if (tf_winlikewidestring in target_info.flags) then
  3029. if def then
  3030. def_system_macro('FPC_WINLIKEWIDESTRING')
  3031. else
  3032. undef_system_macro('FPC_WINLIKEWIDESTRING');
  3033. if (tf_requires_proper_alignment in target_info.flags) then
  3034. if def then
  3035. def_system_macro('FPC_REQUIRES_PROPER_ALIGNMENT')
  3036. else
  3037. undef_system_macro('FPC_REQUIRES_PROPER_ALIGNMENT');
  3038. if source_info.system<>target_info.system then
  3039. if def then
  3040. def_system_macro('FPC_CROSSCOMPILING')
  3041. else
  3042. undef_system_macro('FPC_CROSSCOMPILING');
  3043. if source_info.cpu<>target_info.cpu then
  3044. if def then
  3045. def_system_macro('FPC_CPUCROSSCOMPILING')
  3046. else
  3047. def_system_macro('FPC_CPUCROSSCOMPILING');
  3048. if (tf_no_generic_stackcheck in target_info.flags) then
  3049. if def then
  3050. def_system_macro('FPC_NO_GENERIC_STACK_CHECK')
  3051. else
  3052. undef_system_macro('FPC_NO_GENERIC_STACK_CHECK');
  3053. if (tf_section_threadvars in target_info.flags) then
  3054. if def then
  3055. def_system_macro('FPC_SECTION_THREADVARS')
  3056. else
  3057. undef_system_macro('FPC_SECTION_THREADVARS');
  3058. { Code generation flags }
  3059. if (tf_pic_default in target_info.flags) then
  3060. if def then
  3061. include(init_settings.moduleswitches,cs_create_pic)
  3062. else
  3063. exclude(init_settings.moduleswitches,cs_create_pic);
  3064. { Resources support }
  3065. if (tf_has_winlike_resources in target_info.flags) then
  3066. if def then
  3067. def_system_macro('FPC_HAS_WINLIKERESOURCES')
  3068. else
  3069. undef_system_macro('FPC_HAS_WINLIKERESOURCES');
  3070. { Features }
  3071. case target_info.system of
  3072. system_arm_gba:
  3073. target_unsup_features:=[f_dynlibs];
  3074. system_arm_nds:
  3075. target_unsup_features:=[f_threading,f_commandargs,f_fileio,f_textio,f_consoleio,f_dynlibs];
  3076. system_i386_nativent:
  3077. // until these features are implemented, they are disabled in the compiler
  3078. target_unsup_features:=[f_stackcheck];
  3079. system_i8086_msdos:
  3080. target_unsup_features:=[f_threading,f_dynlibs];
  3081. system_i8086_win16:
  3082. target_unsup_features:=[f_threading];
  3083. system_jvm_java32,
  3084. system_jvm_android32:
  3085. target_unsup_features:=[f_heap,f_textio,f_consoleio,f_fileio,
  3086. f_variants,f_objects,f_commandargs,
  3087. f_processes,f_stackcheck,f_dynlibs,f_softfpu,f_objectivec1,f_resources];
  3088. system_arm_palmos,
  3089. system_m68k_palmos:
  3090. target_unsup_features:=[f_threading];
  3091. system_m68k_atari:
  3092. target_unsup_features:=[f_threading];
  3093. { classic amiga has dynamic libraries, but they cannot be integrated in the
  3094. normal dynlibs infrastructure due to architectural differences, so therefore
  3095. lets disable the feature. }
  3096. system_m68k_amiga:
  3097. target_unsup_features:=[f_dynlibs];
  3098. else
  3099. target_unsup_features:=[];
  3100. end;
  3101. if def then
  3102. features:=features-target_unsup_features
  3103. else
  3104. features:=features+target_unsup_features;
  3105. {$if defined(atari) or defined(hasamiga)}
  3106. { enable vlink as default linker on Atari, Amiga, and MorphOS, but not for cross compilers (for now) }
  3107. if (target_info.system in [system_m68k_amiga,system_m68k_atari,
  3108. system_powerpc_amiga,system_powerpc_morphos]) and
  3109. not LinkerSetExplicitly then
  3110. include(init_settings.globalswitches,cs_link_vlink);
  3111. {$endif}
  3112. end;
  3113. procedure TOption.checkoptionscompatibility;
  3114. begin
  3115. {$ifdef i8086}
  3116. if (apptype=app_com) and (init_settings.x86memorymodel<>mm_tiny) then
  3117. begin
  3118. Message(option_com_files_require_tiny_model);
  3119. StopOptions(1);
  3120. end;
  3121. {$endif i8086}
  3122. {$ifndef i8086_link_intern_debuginfo}
  3123. if (cs_debuginfo in init_settings.moduleswitches) and
  3124. (target_info.system in [system_i8086_msdos,system_i8086_win16,system_i8086_embedded]) and
  3125. not (cs_link_extern in init_settings.globalswitches) then
  3126. begin
  3127. Message(option_debug_info_requires_external_linker);
  3128. include(init_settings.globalswitches,cs_link_extern);
  3129. end;
  3130. {$endif i8086_link_intern_debuginfo}
  3131. if (paratargetdbg in [dbg_dwarf2,dbg_dwarf3]) and
  3132. not(target_info.system in (systems_darwin+[system_i8086_msdos,system_i8086_embedded])) then
  3133. begin
  3134. { smartlink creation does not yet work with DWARF
  3135. debug info on most targets, but it works in internal assembler }
  3136. if (cs_create_smart in init_settings.moduleswitches) and
  3137. not (af_outputbinary in target_asm.flags) then
  3138. begin
  3139. Message(option_dwarf_smartlink_creation);
  3140. exclude(init_settings.moduleswitches,cs_create_smart);
  3141. end;
  3142. { smart linking does not yet work with DWARF debug info on most targets }
  3143. if (cs_link_smart in init_settings.globalswitches) then
  3144. begin
  3145. Message(option_dwarf_smart_linking);
  3146. ForceStaticLinking;
  3147. end;
  3148. end;
  3149. { external debug info is only supported for DWARF on darwin }
  3150. if (target_info.system in systems_darwin) and
  3151. (cs_link_separate_dbg_file in init_settings.globalswitches) and
  3152. not(paratargetdbg in [dbg_dwarf2,dbg_dwarf3]) then
  3153. begin
  3154. Message(option_debug_external_unsupported);
  3155. exclude(init_settings.globalswitches,cs_link_separate_dbg_file);
  3156. end;
  3157. { Also create a smartlinked version, on an assembler that
  3158. does not support smartlink sections like nasm?
  3159. This is not compatible with using internal linker. }
  3160. if ((cs_link_smart in init_settings.globalswitches) or
  3161. (cs_create_smart in init_settings.moduleswitches)) and
  3162. (af_needar in target_asm.flags) and
  3163. not (af_smartlink_sections in target_asm.flags) and
  3164. not (cs_link_extern in init_settings.globalswitches) and
  3165. (target_info.link<>ld_none) and
  3166. not (cs_link_nolink in init_settings.globalswitches) then
  3167. begin
  3168. Message(option_smart_link_requires_external_linker);
  3169. include(init_settings.globalswitches,cs_link_extern);
  3170. end;
  3171. end;
  3172. constructor TOption.create;
  3173. begin
  3174. LogoWritten:=false;
  3175. NoPressEnter:=false;
  3176. FirstPass:=false;
  3177. ABISetExplicitly:=false;
  3178. FPUSetExplicitly:=false;
  3179. CPUSetExplicitly:=false;
  3180. OptCPUSetExplicitly:=false;
  3181. FileLevel:=0;
  3182. Quickinfo:='';
  3183. ParaIncludeCfgPath:=TSearchPathList.Create;
  3184. ParaIncludePath:=TSearchPathList.Create;
  3185. ParaObjectPath:=TSearchPathList.Create;
  3186. ParaUnitPath:=TSearchPathList.Create;
  3187. ParaLibraryPath:=TSearchPathList.Create;
  3188. ParaFrameworkPath:=TSearchPathList.Create;
  3189. parapackagepath:=TSearchPathList.Create;
  3190. parapackages:=TFPHashObjectList.Create;
  3191. paranamespaces:=TCmdStrList.Create;
  3192. FillChar(ParaAlignment,sizeof(ParaAlignment),0);
  3193. MacVersionSet:=false;
  3194. paratarget:=system_none;
  3195. paratargetasm:=as_none;
  3196. paratargetdbg:=dbg_none;
  3197. LinkTypeSetExplicitly:=false;
  3198. LinkerSetExplicitly:=false;
  3199. end;
  3200. destructor TOption.destroy;
  3201. begin
  3202. ParaIncludeCfgPath.Free;
  3203. ParaIncludePath.Free;
  3204. ParaObjectPath.Free;
  3205. ParaUnitPath.Free;
  3206. ParaLibraryPath.Free;
  3207. ParaFrameworkPath.Free;
  3208. parapackagepath.Free;
  3209. ParaPackages.Free;
  3210. paranamespaces.free;
  3211. end;
  3212. {****************************************************************************
  3213. Callable Routines
  3214. ****************************************************************************}
  3215. function check_configfile(fn:string; var foundfn:string):boolean;
  3216. function CfgFileExists(const fn:string):boolean;
  3217. begin
  3218. Comment(V_Tried,'Configfile search: '+fn);
  3219. CfgFileExists:=FileExists(fn);
  3220. end;
  3221. var
  3222. {$ifdef Unix}
  3223. hs,
  3224. {$endif Unix}
  3225. configpath : string;
  3226. begin
  3227. foundfn:=fn;
  3228. check_configfile:=true;
  3229. { retrieve configpath }
  3230. configpath:=FixPath(GetEnvironmentVariable('PPC_CONFIG_PATH'),false);
  3231. {$ifdef Unix}
  3232. if configpath='' then
  3233. configpath:=ExpandFileName(FixPath(exepath+'../etc/',false));
  3234. {$endif}
  3235. {
  3236. Order to read configuration file :
  3237. try reading fpc.cfg in :
  3238. 1 - current dir
  3239. 2 - configpath
  3240. 3 - compiler path
  3241. }
  3242. if not FileExists(fn) then
  3243. begin
  3244. {$ifdef Unix}
  3245. hs:=GetEnvironmentVariable('HOME');
  3246. if (hs<>'') and CfgFileExists(FixPath(hs,false)+'.'+fn) then
  3247. foundfn:=FixPath(hs,false)+'.'+fn
  3248. else
  3249. {$endif}
  3250. if CfgFileExists(configpath+fn) then
  3251. foundfn:=configpath+fn
  3252. else
  3253. {$ifdef WINDOWS}
  3254. if (GetEnvironmentVariable('USERPROFILE')<>'') and CfgFileExists(FixPath(GetEnvironmentVariable('USERPROFILE'),false)+fn) then
  3255. foundfn:=FixPath(GetEnvironmentVariable('USERPROFILE'),false)+fn
  3256. else
  3257. if (GetEnvironmentVariable('ALLUSERSPROFILE')<>'') and CfgFileExists(FixPath(GetEnvironmentVariable('ALLUSERSPROFILE'),false)+fn) then
  3258. foundfn:=FixPath(GetEnvironmentVariable('ALLUSERSPROFILE'),false)+fn
  3259. else
  3260. {$endif WINDOWS}
  3261. {$ifndef Unix}
  3262. if CfgFileExists(exepath+fn) then
  3263. foundfn:=exepath+fn
  3264. else
  3265. {$else}
  3266. if CfgFileExists('/etc/'+fn) then
  3267. foundfn:='/etc/'+fn
  3268. else
  3269. {$endif}
  3270. check_configfile:=false;
  3271. end;
  3272. end;
  3273. procedure read_arguments(cmd:TCmdStr);
  3274. procedure def_cpu_macros;
  3275. var
  3276. abi : tabi;
  3277. fputype : tfputype;
  3278. cputype : tcputype;
  3279. controller: tcontrollertype;
  3280. s: string;
  3281. begin
  3282. for cputype:=low(tcputype) to high(tcputype) do
  3283. undef_system_macro('CPU'+Cputypestr[cputype]);
  3284. def_system_macro('CPU'+Cputypestr[init_settings.cputype]);
  3285. for fputype:=low(tfputype) to high(tfputype) do
  3286. undef_system_macro('FPU'+fputypestr[fputype]);
  3287. def_system_macro('FPU'+fputypestr[init_settings.fputype]);
  3288. {$PUSH}
  3289. {$WARN 6018 OFF} { Unreachable code due to compile time evaluation }
  3290. if ControllerSupport then
  3291. begin
  3292. for controller:=low(tcontrollertype) to high(tcontrollertype) do
  3293. begin
  3294. s:=embedded_controllers[controller].controllertypestr;
  3295. if s<>'' then
  3296. undef_system_macro('FPC_MCU_'+s);
  3297. end;
  3298. s:=embedded_controllers[init_settings.controllertype].controllertypestr;
  3299. if s<>'' then
  3300. def_system_macro('FPC_MCU_'+s);
  3301. end;
  3302. {$POP}
  3303. { define abi }
  3304. for abi:=low(tabi) to high(tabi) do
  3305. undef_system_macro('FPC_ABI_'+abiinfo[abi].name);
  3306. def_system_macro('FPC_ABI_'+abiinfo[target_info.abi].name);
  3307. { Define FPC_ABI_EABI in addition to FPC_ABI_EABIHF on EABI VFP hardfloat
  3308. systems since most code needs to behave the same on both}
  3309. if target_info.abi = abi_eabihf then
  3310. def_system_macro('FPC_ABI_EABI');
  3311. { using a case is pretty useless here (FK) }
  3312. { some stuff for TP compatibility }
  3313. {$ifdef i386}
  3314. def_system_macro('CPU86');
  3315. def_system_macro('CPU87');
  3316. def_system_macro('CPU386');
  3317. {$endif}
  3318. { new processor stuff }
  3319. {$ifdef i386}
  3320. def_system_macro('CPUI386');
  3321. def_system_macro('CPU32');
  3322. def_system_macro('CPUX86');
  3323. def_system_macro('FPC_HAS_TYPE_EXTENDED');
  3324. def_system_macro('FPC_HAS_TYPE_DOUBLE');
  3325. def_system_macro('FPC_HAS_TYPE_SINGLE');
  3326. {$endif}
  3327. {$ifdef m68k}
  3328. def_system_macro('CPU68');
  3329. def_system_macro('CPU68K');
  3330. def_system_macro('CPUM68K');
  3331. def_system_macro('CPU32');
  3332. def_system_macro('FPC_CURRENCY_IS_INT64');
  3333. def_system_macro('FPC_COMP_IS_INT64');
  3334. {$endif}
  3335. {$ifdef powerpc}
  3336. def_system_macro('CPUPOWERPC');
  3337. def_system_macro('CPUPOWERPC32');
  3338. def_system_macro('CPU32');
  3339. def_system_macro('FPC_CURRENCY_IS_INT64');
  3340. def_system_macro('FPC_COMP_IS_INT64');
  3341. {$endif}
  3342. {$ifdef POWERPC64}
  3343. def_system_macro('CPUPOWERPC');
  3344. def_system_macro('CPUPOWERPC64');
  3345. def_system_macro('CPU64');
  3346. def_system_macro('FPC_CURRENCY_IS_INT64');
  3347. def_system_macro('FPC_COMP_IS_INT64');
  3348. {$endif}
  3349. {$ifdef x86_64}
  3350. def_system_macro('CPUX86_64');
  3351. def_system_macro('CPUAMD64');
  3352. def_system_macro('CPU64');
  3353. def_system_macro('CPUX64');
  3354. { not supported for now, afaik (FK)
  3355. def_system_macro('FPC_HAS_TYPE_FLOAT128'); }
  3356. {$ifndef FPC_SUPPORT_X87_TYPES_ON_WIN64}
  3357. { normally, win64 doesn't support the legacy fpu }
  3358. if target_info.system=system_x86_64_win64 then
  3359. begin
  3360. def_system_macro('FPC_CURRENCY_IS_INT64');
  3361. def_system_macro('FPC_COMP_IS_INT64');
  3362. end;
  3363. {$endif FPC_SUPPORT_X87_TYPES_ON_WIN64}
  3364. {$endif}
  3365. {$ifdef sparc}
  3366. def_system_macro('CPUSPARCGEN');
  3367. def_system_macro('CPUSPARC');
  3368. def_system_macro('CPUSPARC32');
  3369. def_system_macro('CPU32');
  3370. def_system_macro('FPC_CURRENCY_IS_INT64');
  3371. def_system_macro('FPC_COMP_IS_INT64');
  3372. {$endif}
  3373. {$ifdef sparc64}
  3374. def_system_macro('CPUSPARCGEN');
  3375. def_system_macro('CPUSPARC64');
  3376. def_system_macro('CPU64');
  3377. def_system_macro('FPC_CURRENCY_IS_INT64');
  3378. def_system_macro('FPC_COMP_IS_INT64');
  3379. {$endif}
  3380. {$ifdef arm}
  3381. def_system_macro('CPUARM');
  3382. def_system_macro('CPU32');
  3383. def_system_macro('FPC_CURRENCY_IS_INT64');
  3384. def_system_macro('FPC_COMP_IS_INT64');
  3385. {$endif arm}
  3386. {$ifdef avr}
  3387. def_system_macro('CPUAVR');
  3388. def_system_macro('CPU16');
  3389. def_system_macro('FPC_CURRENCY_IS_INT64');
  3390. def_system_macro('FPC_COMP_IS_INT64');
  3391. {$endif avr}
  3392. {$ifdef jvm}
  3393. def_system_macro('CPUJVM');
  3394. def_system_macro('CPU32');
  3395. def_system_macro('FPC_CURRENCY_IS_INT64');
  3396. def_system_macro('FPC_COMP_IS_INT64');
  3397. {$endif jvm}
  3398. {$ifdef mipsel}
  3399. def_system_macro('CPUMIPS');
  3400. def_system_macro('CPUMIPS32');
  3401. def_system_macro('CPUMIPSEL');
  3402. def_system_macro('CPUMIPSEL32');
  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. { On most systems, locals are accessed relative to base pointer,
  3411. but for MIPS cpu, they are accessed relative to stack pointer.
  3412. This needs adaptation for so low level routines,
  3413. like MethodPointerLocal and related objects unit functions. }
  3414. def_system_macro('FPC_LOCALS_ARE_STACK_REG_RELATIVE');
  3415. {$endif mipsel}
  3416. {$ifdef mipseb}
  3417. def_system_macro('CPUMIPS');
  3418. def_system_macro('CPUMIPS32');
  3419. def_system_macro('CPUMIPSEB');
  3420. def_system_macro('CPUMIPSEB32');
  3421. def_system_macro('CPU32');
  3422. def_system_macro('FPC_HAS_TYPE_DOUBLE');
  3423. def_system_macro('FPC_HAS_TYPE_SINGLE');
  3424. def_system_macro('FPC_INCLUDE_SOFTWARE_INT64_TO_DOUBLE');
  3425. def_system_macro('FPC_CURRENCY_IS_INT64');
  3426. def_system_macro('FPC_COMP_IS_INT64');
  3427. def_system_macro('FPC_REQUIRES_PROPER_ALIGNMENT');
  3428. { See comment above for mipsel }
  3429. def_system_macro('FPC_LOCALS_ARE_STACK_REG_RELATIVE');
  3430. {$endif}
  3431. {$ifdef i8086}
  3432. def_system_macro('CPU86'); { Borland compatibility }
  3433. def_system_macro('CPU87'); { Borland compatibility }
  3434. def_system_macro('CPUI8086');
  3435. def_system_macro('CPU16');
  3436. def_system_macro('FPC_HAS_TYPE_EXTENDED');
  3437. def_system_macro('FPC_HAS_TYPE_DOUBLE');
  3438. def_system_macro('FPC_HAS_TYPE_SINGLE');
  3439. case init_settings.x86memorymodel of
  3440. mm_tiny: def_system_macro('FPC_MM_TINY');
  3441. mm_small: def_system_macro('FPC_MM_SMALL');
  3442. mm_medium: def_system_macro('FPC_MM_MEDIUM');
  3443. mm_compact: def_system_macro('FPC_MM_COMPACT');
  3444. mm_large: def_system_macro('FPC_MM_LARGE');
  3445. mm_huge: def_system_macro('FPC_MM_HUGE');
  3446. end;
  3447. {$endif i8086}
  3448. {$ifdef aarch64}
  3449. def_system_macro('CPUAARCH64');
  3450. def_system_macro('CPU64');
  3451. def_system_macro('FPC_CURRENCY_IS_INT64');
  3452. def_system_macro('FPC_COMP_IS_INT64');
  3453. {$endif aarch64}
  3454. {$if defined(cpu8bitalu)}
  3455. def_system_macro('CPUINT8');
  3456. {$elseif defined(cpu16bitalu)}
  3457. def_system_macro('CPUINT16');
  3458. {$elseif defined(cpu32bitalu)}
  3459. def_system_macro('CPUINT32');
  3460. {$elseif defined(cpu64bitalu)}
  3461. def_system_macro('CPUINT64');
  3462. {$endif defined(cpu64bitalu)}
  3463. {$if defined(avr)}
  3464. def_system_macro('FPC_HAS_INTERNAL_ABS_SHORTINT');
  3465. {$endif}
  3466. {$if defined(i8086) or defined(avr)}
  3467. def_system_macro('FPC_HAS_INTERNAL_ABS_SMALLINT');
  3468. {$endif i8086 or avr}
  3469. { abs(long) is handled internally on all CPUs }
  3470. def_system_macro('FPC_HAS_INTERNAL_ABS_LONG');
  3471. {$if defined(i8086) or defined(i386) or defined(x86_64) or defined(powerpc64) or defined(aarch64)}
  3472. def_system_macro('FPC_HAS_INTERNAL_ABS_INT64');
  3473. {$endif i8086 or i386 or x86_64 or powerpc64 or aarch64}
  3474. def_system_macro('FPC_HAS_UNICODESTRING');
  3475. def_system_macro('FPC_RTTI_PACKSET1');
  3476. def_system_macro('FPC_HAS_CPSTRING');
  3477. {$ifdef x86_64}
  3478. def_system_macro('FPC_HAS_RIP_RELATIVE');
  3479. {$endif x86_64}
  3480. def_system_macro('FPC_HAS_CEXTENDED');
  3481. def_system_macro('FPC_HAS_RESSTRINITS');
  3482. { these cpus have an inline rol/ror implementaion }
  3483. {$ifdef cpurox}
  3484. {$ifdef m68k}
  3485. if CPUM68K_HAS_ROLROR in cpu_capabilities[init_settings.cputype] then
  3486. def_system_macro('FPC_HAS_INTERNAL_ROX');
  3487. {$else}
  3488. def_system_macro('FPC_HAS_INTERNAL_ROX');
  3489. {$endif}
  3490. {$endif}
  3491. {$ifdef powerpc64}
  3492. def_system_macro('FPC_HAS_LWSYNC');
  3493. {$endif}
  3494. { currently, all supported CPUs have an internal sar implementation }
  3495. def_system_macro('FPC_HAS_INTERNAL_SAR');
  3496. {$ifdef SUPPORT_GET_FRAME}
  3497. def_system_macro('INTERNAL_BACKTRACE');
  3498. {$endif SUPPORT_GET_FRAME}
  3499. def_system_macro('STR_CONCAT_PROCS');
  3500. {$warnings off}
  3501. if pocall_default = pocall_register then
  3502. def_system_macro('REGCALL');
  3503. {$warnings on}
  3504. end;
  3505. var
  3506. env: ansistring;
  3507. i : tfeature;
  3508. j : longint;
  3509. abi : tabi;
  3510. tmplist : TCmdStrList;
  3511. cmditem,
  3512. tmpcmditem : TCmdStrListItem;
  3513. cmdstr : TCmdStr;
  3514. {$if defined(cpucapabilities)}
  3515. cpuflag : tcpuflags;
  3516. hs : string;
  3517. {$endif defined(cpucapabilities)}
  3518. begin
  3519. option:=coption.create;
  3520. disable_configfile:=false;
  3521. { Non-core target defines }
  3522. Option.TargetOptions(true);
  3523. { get default messagefile }
  3524. msgfilename:=GetEnvironmentVariable('PPC_ERROR_FILE');
  3525. { default configfile can be specified on the commandline,
  3526. remove it first }
  3527. if (cmd<>'') and (cmd[1]='[') then
  3528. begin
  3529. ppccfg:=Copy(cmd,2,pos(']',cmd)-2);
  3530. Delete(cmd,1,pos(']',cmd));
  3531. end
  3532. else
  3533. ppccfg:='fpc.cfg';
  3534. { first pass reading of parameters, only -i -v -T etc.}
  3535. option.firstpass:=true;
  3536. if cmd<>'' then
  3537. option.parsecmd(cmd)
  3538. else
  3539. begin
  3540. option.read_parameters;
  3541. { Write only quickinfo }
  3542. if option.quickinfo<>'' then
  3543. option.writequickinfo;
  3544. end;
  3545. option.firstpass:=false;
  3546. { redefine target options so all defines are written even if no -Txxx is passed on the command line }
  3547. Option.TargetOptions(true);
  3548. { target is set here, for wince the default app type is gui }
  3549. if target_info.system in systems_wince then
  3550. SetApptype(app_gui)
  3551. else
  3552. SetApptype(apptype);
  3553. { default defines }
  3554. def_system_macro(target_info.shortname);
  3555. def_system_macro('FPC');
  3556. def_system_macro('VER'+version_nr);
  3557. def_system_macro('VER'+version_nr+'_'+release_nr);
  3558. def_system_macro('VER'+version_nr+'_'+release_nr+'_'+patch_nr);
  3559. { Temporary defines, until things settle down }
  3560. def_system_macro('FPC_HAS_OPERATOR_ENUMERATOR');
  3561. def_system_macro('FPC_HAS_CONSTREF');
  3562. def_system_macro('FPC_STATICRIPFIXED');
  3563. def_system_macro('FPC_VARIANTCOPY_FIXED');
  3564. def_system_macro('FPC_DYNARRAYCOPY_FIXED');
  3565. def_system_macro('FPC_HAS_MEMBAR');
  3566. def_system_macro('FPC_SETBASE_USED');
  3567. { don't remove this, it's also for fpdoc necessary (FK) }
  3568. def_system_macro('FPC_HAS_FEATURE_SUPPORT');
  3569. { make cpu makros available when reading the config files the second time }
  3570. def_cpu_macros;
  3571. if tf_cld in target_info.flags then
  3572. if not UpdateTargetSwitchStr('CLD', init_settings.targetswitches, true) then
  3573. InternalError(2013092801);
  3574. if tf_x86_far_procs_push_odd_bp in target_info.flags then
  3575. if not UpdateTargetSwitchStr('FARPROCSPUSHODDBP', init_settings.targetswitches, true) then
  3576. InternalError(2013092801);
  3577. { Use standard Android NDK prefixes when cross-compiling }
  3578. if (source_info.system<>target_info.system) and (target_info.system in systems_android) then
  3579. case target_info.system of
  3580. system_arm_android:
  3581. utilsprefix:='arm-linux-androideabi-';
  3582. system_i386_android:
  3583. utilsprefix:='i686-linux-android-';
  3584. else
  3585. utilsprefix:=target_cpu_string + '-linux-android-';
  3586. end;
  3587. { Set up default value for the heap }
  3588. if target_info.system in systems_embedded then
  3589. begin
  3590. case target_info.system of
  3591. {$ifdef AVR}
  3592. system_avr_embedded:
  3593. if init_settings.controllertype=ct_avrsim then
  3594. heapsize:=8192
  3595. else
  3596. heapsize:=128;
  3597. {$endif AVR}
  3598. system_arm_embedded:
  3599. heapsize:=256;
  3600. system_mipsel_embedded:
  3601. heapsize:=256;
  3602. else
  3603. heapsize:=256;
  3604. end;
  3605. end;
  3606. { read configuration file }
  3607. if (not disable_configfile) and
  3608. (ppccfg<>'') then
  3609. read_configfile:=check_configfile(ppccfg,ppccfg)
  3610. else
  3611. read_configfile := false;
  3612. { Read commandline and configfile }
  3613. param_file:='';
  3614. { read configfile }
  3615. if read_configfile then
  3616. option.interpret_file(ppccfg);
  3617. { read parameters again to override config file }
  3618. if cmd<>'' then
  3619. option.parsecmd(cmd)
  3620. else
  3621. begin
  3622. { Write help pages if no parameters are passed }
  3623. if (paramcount=0) then
  3624. Option.WriteHelpPages;
  3625. option.read_parameters;
  3626. { Write only quickinfo }
  3627. if option.quickinfo<>'' then
  3628. option.writequickinfo;
  3629. end;
  3630. { check the compatibility of different options and adjust them if necessary
  3631. (and print possible errors)
  3632. }
  3633. option.checkoptionscompatibility;
  3634. { uses the CPUXXX-defines and target_info to determine whether the selected
  3635. target processor, if any, is supported }
  3636. Option.VerifyTargetProcessor;
  3637. { Stop if errors in options }
  3638. if ErrorCount>0 then
  3639. StopOptions(1);
  3640. { endian define }
  3641. case target_info.endian of
  3642. endian_little :
  3643. begin
  3644. def_system_macro('ENDIAN_LITTLE');
  3645. def_system_macro('FPC_LITTLE_ENDIAN');
  3646. end;
  3647. endian_big :
  3648. begin
  3649. def_system_macro('ENDIAN_BIG');
  3650. def_system_macro('FPC_BIG_ENDIAN');
  3651. end;
  3652. end;
  3653. { Write logo }
  3654. if option.ParaLogo then
  3655. option.writelogo;
  3656. { Check file to compile }
  3657. if param_file='' then
  3658. begin
  3659. Message(option_no_source_found);
  3660. StopOptions(1);
  3661. end;
  3662. {$ifndef Unix}
  3663. param_file:=FixFileName(param_file);
  3664. {$endif not unix}
  3665. inputfilepath:=ExtractFilePath(param_file);
  3666. inputfilename:=ExtractFileName(param_file);
  3667. if ExtractFileExt(inputfilename)='' then
  3668. begin
  3669. if FileExists(inputfilepath+ChangeFileExt(inputfilename,sourceext)) then
  3670. inputfilename:=ChangeFileExt(inputfilename,sourceext)
  3671. else if FileExists(inputfilepath+ChangeFileExt(inputfilename,pasext)) then
  3672. inputfilename:=ChangeFileExt(inputfilename,pasext)
  3673. else if ((m_mac in current_settings.modeswitches) or
  3674. (tf_p_ext_support in target_info.flags))
  3675. and FileExists(inputfilepath+ChangeFileExt(inputfilename,pext)) then
  3676. inputfilename:=ChangeFileExt(inputfilename,pext);
  3677. end;
  3678. { Check output dir }
  3679. if (OutputExeDir<>'') and
  3680. not PathExists(OutputExeDir,false) then
  3681. begin
  3682. Message1(general_e_path_does_not_exist,OutputExeDir);
  3683. StopOptions(1);
  3684. end;
  3685. { Add paths specified with parameters to the searchpaths }
  3686. UnitSearchPath.AddList(option.ParaUnitPath,true);
  3687. ObjectSearchPath.AddList(option.ParaObjectPath,true);
  3688. IncludeSearchPath.AddList(option.ParaIncludePath,true);
  3689. LibrarySearchPath.AddList(option.ParaLibraryPath,true);
  3690. FrameworkSearchPath.AddList(option.ParaFrameworkPath,true);
  3691. packagesearchpath.addlist(option.parapackagepath,true);
  3692. for j:=0 to option.parapackages.count-1 do
  3693. add_package(option.parapackages.NameOfIndex(j),true,true);
  3694. { add default namespaces }
  3695. tmplist:=TCmdStrList.Create;
  3696. cmditem:=TCmdStrListItem(option.paranamespaces.First);
  3697. while assigned(cmditem) do
  3698. begin
  3699. { use a temporary list cause if ";" are involved we need to reverse the
  3700. order due to how TCmdStrList behaves }
  3701. cmdstr:=cmditem.str;
  3702. repeat
  3703. j:=Pos(';',cmdstr);
  3704. if j>0 then
  3705. begin
  3706. tmplist.insert(copy(cmdstr,1,j-1));
  3707. delete(cmdstr,1,j);
  3708. end
  3709. else
  3710. tmplist.insert(cmdstr);
  3711. until j=0;
  3712. tmpcmditem:=TCmdStrListItem(tmplist.First);
  3713. while assigned(tmpcmditem) do
  3714. begin
  3715. namespacelist.insert(tmpcmditem.Str);
  3716. tmpcmditem:=TCmdStrListItem(tmpcmditem.Next);
  3717. end;
  3718. tmplist.clear;
  3719. cmditem:=TCmdStrListItem(cmditem.Next);
  3720. end;
  3721. tmplist.Free;
  3722. { add unit environment and exepath to the unit search path }
  3723. if inputfilepath<>'' then
  3724. Unitsearchpath.AddPath(inputfilepath,true);
  3725. if not disable_configfile then
  3726. begin
  3727. env:=GetEnvironmentVariable(target_info.unit_env);
  3728. if env<>'' then
  3729. UnitSearchPath.AddPath(GetEnvironmentVariable(target_info.unit_env),false);
  3730. end;
  3731. {$ifdef Unix}
  3732. fpcdir:=FixPath(GetEnvironmentVariable('FPCDIR'),false);
  3733. if fpcdir='' then
  3734. begin
  3735. if PathExists('/usr/local/lib/fpc/'+version_string,true) then
  3736. fpcdir:='/usr/local/lib/fpc/'+version_string+'/'
  3737. else
  3738. fpcdir:='/usr/lib/fpc/'+version_string+'/';
  3739. end;
  3740. {$else unix}
  3741. fpcdir:=FixPath(GetEnvironmentVariable('FPCDIR'),false);
  3742. if fpcdir='' then
  3743. begin
  3744. fpcdir:=ExePath+'../';
  3745. if not(PathExists(fpcdir+'units',true)) and
  3746. not(PathExists(fpcdir+'rtl',true)) then
  3747. fpcdir:=fpcdir+'../';
  3748. end;
  3749. {$endif unix}
  3750. { first try development RTL, else use the default installation path }
  3751. if not disable_configfile then
  3752. begin
  3753. if PathExists(FpcDir+'rtl',true) then
  3754. if (tf_use_8_3 in Source_Info.Flags) or
  3755. (tf_use_8_3 in Target_Info.Flags) then
  3756. UnitSearchPath.AddPath(FpcDir+'rtl/'+target_os_string,false)
  3757. else
  3758. UnitSearchPath.AddPath(FpcDir+'rtl/'+target_full_string,false)
  3759. else
  3760. if (tf_use_8_3 in Source_Info.Flags) or
  3761. (tf_use_8_3 in Target_Info.Flags) then
  3762. UnitSearchPath.AddPath(FpcDir+'units/'+target_os_string+'/rtl',false)
  3763. else
  3764. UnitSearchPath.AddPath(FpcDir+'units/'+target_full_string+'/rtl',false);
  3765. end;
  3766. { Add exepath if the exe is not in the current dir, because that is always searched already.
  3767. Do not add it when linking on the target because then we can maybe already find
  3768. .o files that are not for the target }
  3769. if (ExePath<>cfileutl.GetCurrentDir) and
  3770. not(cs_link_on_target in init_settings.globalswitches) then
  3771. UnitSearchPath.AddPath(ExePath,false);
  3772. { Add unit dir to the object and library path }
  3773. objectsearchpath.AddList(unitsearchpath,false);
  3774. librarysearchpath.AddList(unitsearchpath,false);
  3775. {$ifdef llvm}
  3776. { default to clang }
  3777. if (option.paratargetasm=as_none) then
  3778. begin
  3779. option.paratargetasm:=as_clang_llvm;
  3780. end;
  3781. {$endif llvm}
  3782. { maybe override assembler }
  3783. if (option.paratargetasm<>as_none) then
  3784. begin
  3785. if not set_target_asm(option.paratargetasm) then
  3786. begin
  3787. if assigned(asminfos[option.paratargetasm]) then
  3788. Message2(option_incompatible_asm,asminfos[option.paratargetasm]^.idtxt,target_info.name)
  3789. else
  3790. Message2(option_incompatible_asm,'<invalid assembler>',target_info.name);
  3791. set_target_asm(target_info.assemextern);
  3792. Message1(option_asm_forced,target_asm.idtxt);
  3793. end;
  3794. if (af_no_debug in asminfos[option.paratargetasm]^.flags) and
  3795. (option.paratargetdbg<>dbg_none) then
  3796. begin
  3797. Message1(option_confict_asm_debug,
  3798. asminfos[option.paratargetasm]^.idtxt);
  3799. option.paratargetdbg:=dbg_none;
  3800. exclude(init_settings.moduleswitches,cs_debuginfo);
  3801. end;
  3802. { Some assemblers, like clang, do not support
  3803. stabs debugging format, switch to dwardé in that case }
  3804. if (af_no_stabs in asminfos[option.paratargetasm]^.flags) and
  3805. (option.paratargetdbg=dbg_stabs) then
  3806. begin
  3807. option.paratargetdbg:=dbg_dwarf2;
  3808. end;
  3809. end;
  3810. {TOptionheck a second time as we might have changed assembler just above }
  3811. option.checkoptionscompatibility;
  3812. { maybe override debug info format }
  3813. if (option.paratargetdbg<>dbg_none) then
  3814. if not set_target_dbg(option.paratargetdbg) then
  3815. Message(option_w_unsupported_debug_format);
  3816. { switch assembler if it's binary and we got -a on the cmdline }
  3817. if (cs_asm_leave in init_settings.globalswitches) and
  3818. (af_outputbinary in target_asm.flags) then
  3819. begin
  3820. Message(option_switch_bin_to_src_assembler);
  3821. {$ifdef llvm}
  3822. set_target_asm(as_clang_llvm);
  3823. {$else}
  3824. set_target_asm(target_info.assemextern);
  3825. {$endif}
  3826. { At least i8086 needs that for nasm and -CX
  3827. which is incompatible with internal linker }
  3828. option.checkoptionscompatibility;
  3829. end;
  3830. { Force use of external linker if there is no
  3831. internal linker or the linking is skipped }
  3832. if not(cs_link_extern in init_settings.globalswitches) and
  3833. ((target_info.link=ld_none) or
  3834. (cs_link_nolink in init_settings.globalswitches)) then
  3835. begin
  3836. include(init_settings.globalswitches,cs_link_extern);
  3837. end;
  3838. { turn off stripping if compiling with debuginfo or profile }
  3839. if (
  3840. (cs_debuginfo in init_settings.moduleswitches) or
  3841. (cs_profile in init_settings.moduleswitches)
  3842. ) and
  3843. not(cs_link_separate_dbg_file in init_settings.globalswitches) then
  3844. exclude(init_settings.globalswitches,cs_link_strip);
  3845. { set Mac OS X version default macros if not specified explicitly }
  3846. option.MaybeSetDefaultMacVersionMacro;
  3847. { force fpu emulation on arm/wince, arm/gba, arm/embedded and arm/nds
  3848. if fpu type not explicitly set }
  3849. if not(option.FPUSetExplicitly) and
  3850. ((target_info.system in [system_arm_wince,system_arm_gba,
  3851. system_m68k_amiga,system_m68k_atari,
  3852. system_arm_nds,system_arm_embedded])
  3853. {$ifdef arm}
  3854. or (target_info.abi=abi_eabi)
  3855. {$endif arm}
  3856. )
  3857. {$if defined(arm) or defined (m68k)}
  3858. or (init_settings.fputype=fpu_soft)
  3859. {$endif arm or m68k}
  3860. then
  3861. begin
  3862. {$ifdef cpufpemu}
  3863. include(init_settings.moduleswitches,cs_fp_emulation);
  3864. { cs_fp_emulation and fpu_soft are equal on arm and m68k }
  3865. init_settings.fputype:=fpu_soft;
  3866. {$endif cpufpemu}
  3867. end;
  3868. {$ifdef i386}
  3869. case target_info.system of
  3870. system_i386_android:
  3871. begin
  3872. { set default cpu type to PentiumM for Android unless specified otherwise }
  3873. if not option.CPUSetExplicitly then
  3874. init_settings.cputype:=cpu_PentiumM;
  3875. if not option.OptCPUSetExplicitly then
  3876. init_settings.optimizecputype:=cpu_PentiumM;
  3877. { set default fpu type to SSSE3 for Android unless specified otherwise }
  3878. if not option.FPUSetExplicitly then
  3879. init_settings.fputype:=fpu_ssse3;
  3880. end;
  3881. end;
  3882. {$endif i386}
  3883. {$ifdef arm}
  3884. case target_info.system of
  3885. system_arm_ios:
  3886. begin
  3887. { set default cpu type to ARMv7 for Darwin unless specified otherwise, and fpu
  3888. to VFPv3 (that's what all 32 bit ARM iOS devices use nowadays)
  3889. }
  3890. if not option.CPUSetExplicitly then
  3891. init_settings.cputype:=cpu_armv7;
  3892. if not option.OptCPUSetExplicitly then
  3893. init_settings.optimizecputype:=cpu_armv7;
  3894. if not option.FPUSetExplicitly then
  3895. init_settings.fputype:=fpu_vfpv3;
  3896. end;
  3897. system_arm_android:
  3898. begin
  3899. { set default cpu type to ARMv5T for Android unless specified otherwise }
  3900. if not option.CPUSetExplicitly then
  3901. init_settings.cputype:=cpu_armv5t;
  3902. if not option.OptCPUSetExplicitly then
  3903. init_settings.optimizecputype:=cpu_armv5t;
  3904. end;
  3905. end;
  3906. { ARMHF defaults }
  3907. if (target_info.abi = abi_eabihf) then
  3908. { set default cpu type to ARMv7a for ARMHF unless specified otherwise }
  3909. begin
  3910. {$ifdef CPUARMV6}
  3911. { if the compiler is built for armv6, then
  3912. inherit this setting, e.g. Raspian is armhf but
  3913. only armv6, this makes rebuilds of the compiler
  3914. easier }
  3915. if not option.CPUSetExplicitly then
  3916. init_settings.cputype:=cpu_armv6;
  3917. if not option.OptCPUSetExplicitly then
  3918. init_settings.optimizecputype:=cpu_armv6;
  3919. {$else CPUARMV6}
  3920. if not option.CPUSetExplicitly then
  3921. init_settings.cputype:=cpu_armv7a;
  3922. if not option.OptCPUSetExplicitly then
  3923. init_settings.optimizecputype:=cpu_armv7a;
  3924. {$endif CPUARMV6}
  3925. { Set FPU type }
  3926. if not(option.FPUSetExplicitly) then
  3927. begin
  3928. if init_settings.cputype < cpu_armv7 then
  3929. init_settings.fputype:=fpu_vfpv2
  3930. else
  3931. init_settings.fputype:=fpu_vfpv3_d16;
  3932. end
  3933. else
  3934. begin
  3935. if not (init_settings.fputype in [fpu_vfpv2,fpu_vfpv3,fpu_vfpv3_d16,fpu_vfpv4])
  3936. or (target_info.system = system_arm_ios) then
  3937. begin
  3938. Message(option_illegal_fpu_eabihf);
  3939. StopOptions(1);
  3940. end;
  3941. end;
  3942. end;
  3943. if (init_settings.instructionset=is_thumb) and not(CPUARM_HAS_THUMB2 in cpu_capabilities[init_settings.cputype]) then
  3944. begin
  3945. def_system_macro('CPUTHUMB');
  3946. if not option.FPUSetExplicitly then
  3947. init_settings.fputype:=fpu_soft;
  3948. {$if defined(FPC_ARMEL) or defined(FPC_ARMHF)}
  3949. 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';
  3950. {$else FPC_ARMAL or FPC_ARMHF}
  3951. if target_info.endian=endian_little then
  3952. 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';
  3953. {$endif FPC_ARMAL or FPC_ARMHF}
  3954. end;
  3955. if (init_settings.instructionset=is_thumb) and (CPUARM_HAS_THUMB2 in cpu_capabilities[init_settings.cputype]) then
  3956. def_system_macro('CPUTHUMB2');
  3957. {$endif arm}
  3958. {$ifdef jvm}
  3959. { set default CPU type to Dalvik when targeting Android }
  3960. if target_info.system=system_jvm_android32 then
  3961. begin
  3962. if not option.CPUSetExplicitly then
  3963. init_settings.cputype:=cpu_dalvik;
  3964. end;
  3965. {$endif jvm}
  3966. {$ifdef llvm}
  3967. { standard extension for llvm bitcode files }
  3968. target_info.asmext:='.ll';
  3969. { don't generate dwarf cfi, llvm will do that }
  3970. exclude(target_info.flags,tf_needs_dwarf_cfi);
  3971. {$endif llvm}
  3972. {$ifdef mipsel}
  3973. case target_info.system of
  3974. system_mipsel_android:
  3975. begin
  3976. { set default cpu type to MIPS32 rev. 1 and hard float for MIPS-Android unless specified otherwise }
  3977. if not option.CPUSetExplicitly then
  3978. init_settings.cputype:=cpu_mips32;
  3979. if not option.OptCPUSetExplicitly then
  3980. init_settings.optimizecputype:=cpu_mips32;
  3981. if not option.FPUSetExplicitly then
  3982. init_settings.fputype:=fpu_mips2;
  3983. end;
  3984. system_mipsel_embedded:
  3985. begin
  3986. { set default cpu type to PIC32MX and softfloat for MIPSEL-EMBEDDED target unless specified otherwise }
  3987. if not option.CPUSetExplicitly then
  3988. init_settings.cputype:=cpu_pic32mx;
  3989. if not option.OptCPUSetExplicitly then
  3990. init_settings.optimizecputype:=cpu_pic32mx;
  3991. if not option.FPUSetExplicitly then
  3992. init_settings.fputype:=fpu_soft;
  3993. end;
  3994. end;
  3995. {$endif mipsel}
  3996. {$ifdef m68k}
  3997. if init_settings.cputype in cpu_coldfire then
  3998. def_system_macro('CPUCOLDFIRE');
  3999. case target_info.system of
  4000. system_m68k_linux,
  4001. system_m68k_netbsd:
  4002. begin
  4003. if not (option.FPUSetExplicitly) and
  4004. not (init_settings.cputype in cpu_coldfire) then
  4005. begin
  4006. { enable HW FPU for UNIX by default, but only for
  4007. original 68k, not Coldfire }
  4008. exclude(init_settings.moduleswitches,cs_fp_emulation);
  4009. init_settings.fputype:=fpu_68881;
  4010. end;
  4011. end;
  4012. system_m68k_palmos:
  4013. begin
  4014. if not option.CPUSetExplicitly then
  4015. init_settings.cputype:=cpu_mc68000;
  4016. if not (option.FPUSetExplicitly) then
  4017. begin
  4018. { No FPU for PalmOS by default }
  4019. exclude(init_settings.moduleswitches,cs_fp_emulation);
  4020. init_settings.fputype:=fpu_none;
  4021. end;
  4022. end;
  4023. end;
  4024. {$endif m68k}
  4025. { now we can define cpu and fpu type }
  4026. def_cpu_macros;
  4027. { Use init_settings cpu type for asm cpu type,
  4028. if asmcputype is cpu_none,
  4029. at least as long as there is no explicit
  4030. option to set it on command line PM }
  4031. if init_settings.asmcputype = cpu_none then
  4032. init_settings.asmcputype:=init_settings.cputype;
  4033. {$ifdef llvm}
  4034. def_system_macro('CPULLVM');
  4035. {$endif llvm}
  4036. {$if defined(cpucapabilities)}
  4037. for cpuflag:=low(cpuflag) to high(cpuflag) do
  4038. begin
  4039. str(cpuflag,hs);
  4040. if cpuflag in cpu_capabilities[init_settings.cputype] then
  4041. def_system_macro(hs)
  4042. else
  4043. undef_system_macro(hs);
  4044. end;
  4045. {$endif defined(cpucapabilities)}
  4046. if init_settings.fputype<>fpu_none then
  4047. begin
  4048. {$if defined(i386) or defined(i8086)}
  4049. def_system_macro('FPC_HAS_TYPE_EXTENDED');
  4050. {$endif}
  4051. def_system_macro('FPC_HAS_TYPE_SINGLE');
  4052. def_system_macro('FPC_HAS_TYPE_DOUBLE');
  4053. {$if not defined(i386) and not defined(x86_64) and not defined(i8086) and not defined(aarch64)}
  4054. def_system_macro('FPC_INCLUDE_SOFTWARE_INT64_TO_DOUBLE');
  4055. {$endif}
  4056. {$if defined(m68k)}
  4057. def_system_macro('FPC_INCLUDE_SOFTWARE_LONGWORD_TO_DOUBLE');
  4058. {$endif}
  4059. {$ifdef x86_64}
  4060. {$ifndef FPC_SUPPORT_X87_TYPES_ON_WIN64}
  4061. { normally, win64 doesn't support the legacy fpu }
  4062. if target_info.system=system_x86_64_win64 then
  4063. undef_system_macro('FPC_HAS_TYPE_EXTENDED')
  4064. else
  4065. {$endif FPC_SUPPORT_X87_TYPES_ON_WIN64}
  4066. def_system_macro('FPC_HAS_TYPE_EXTENDED');
  4067. {$endif}
  4068. end;
  4069. { Enable now for testing }
  4070. {$ifndef DISABLE_TLS_DIRECTORY}
  4071. if target_info.system in systems_windows then
  4072. def_system_macro('FPC_USE_TLS_DIRECTORY');
  4073. {$endif not DISABLE_TLS_DIRECTORY}
  4074. {$ifndef DISABLE_WIN64_SEH}
  4075. if target_info.system=system_x86_64_win64 then
  4076. def_system_macro('FPC_USE_WIN64_SEH');
  4077. {$endif DISABLE_WIN64_SEH}
  4078. {$ifndef DISABLE_WIN32_SEH}
  4079. if target_info.system=system_i386_win32 then
  4080. def_system_macro('FPC_USE_WIN32_SEH');
  4081. {$endif not DISABLE_WIN32_SEH}
  4082. {$ifdef ARM}
  4083. { define FPC_DOUBLE_HILO_SWAPPED if needed to properly handle doubles in RTL }
  4084. if (init_settings.fputype in [fpu_fpa,fpu_fpa10,fpu_fpa11]) and
  4085. not(cs_fp_emulation in init_settings.moduleswitches) then
  4086. def_system_macro('FPC_DOUBLE_HILO_SWAPPED');
  4087. {$endif ARM}
  4088. { inline bsf/bsr implementation }
  4089. {$if not defined(llvm) and (defined(i386) or defined(x86_64) or defined(aarch64) or defined(powerpc) or defined(powerpc64))}
  4090. def_system_macro('FPC_HAS_INTERNAL_BSF');
  4091. def_system_macro('FPC_HAS_INTERNAL_BSR');
  4092. {$endif}
  4093. { hardware FMA support }
  4094. {$if defined(i386) or defined(x86_64)}
  4095. if (cpu_capabilities[current_settings.cputype]*[CPUX86_HAS_FMA,CPUX86_HAS_FMA4])<>[] then
  4096. begin
  4097. def_system_macro('FPC_HAS_FAST_FMA_SINGLE');
  4098. def_system_macro('FPC_HAS_FAST_FMA_DOUBLE');
  4099. end;
  4100. {$endif defined(i386) or defined(x86_64)}
  4101. {$if defined(arm)}
  4102. { it is determined during system unit compilation if clz is used for bsf or not,
  4103. this is not perfect but the current implementation bsf/bsr does not allow another
  4104. solution }
  4105. if (CPUARM_HAS_CLZ in cpu_capabilities[init_settings.cputype]) and
  4106. ((init_settings.instructionset=is_arm) or
  4107. (CPUARM_HAS_THUMB2 in cpu_capabilities[init_settings.cputype])) then
  4108. begin
  4109. def_system_macro('FPC_HAS_INTERNAL_BSR');
  4110. if CPUARM_HAS_RBIT in cpu_capabilities[init_settings.cputype] then
  4111. def_system_macro('FPC_HAS_INTERNAL_BSF');
  4112. end;
  4113. {$endif}
  4114. {$if defined(powerpc64)}
  4115. { on sysv targets, default to elfv2 for little endian and to elfv1 for
  4116. big endian (unless specified otherwise). As the gcc man page says:
  4117. "Overriding the default ABI requires special system support and is
  4118. likely to fail in spectacular ways" }
  4119. if not option.ABISetExplicitly then
  4120. begin
  4121. if (target_info.abi=abi_powerpc_sysv) and
  4122. (target_info.endian=endian_little) then
  4123. target_info.abi:=abi_powerpc_elfv2
  4124. else
  4125. if (target_info.abi=abi_powerpc_elfv2) and
  4126. (target_info.endian=endian_big) then
  4127. target_info.abi:=abi_powerpc_sysv
  4128. end;
  4129. {$endif}
  4130. {$if defined(powerpc) or defined(powerpc64)}
  4131. { define _CALL_ELF symbol like gcc }
  4132. case target_info.abi of
  4133. abi_powerpc_sysv:
  4134. set_system_compvar('_CALL_ELF','1');
  4135. abi_powerpc_elfv2:
  4136. set_system_compvar('_CALL_ELF','2');
  4137. end;
  4138. {$endif}
  4139. { Section smartlinking conflicts with import sections on Windows }
  4140. if GenerateImportSection and
  4141. (target_info.system in [system_i386_win32,system_x86_64_win64]) then
  4142. exclude(target_info.flags,tf_smartlink_sections);
  4143. if not option.LinkTypeSetExplicitly then
  4144. set_default_link_type;
  4145. { Default alignment settings,
  4146. 1. load the defaults for the target
  4147. 2. override with generic optimizer setting (little size)
  4148. 3. override with the user specified -Oa }
  4149. UpdateAlignment(init_settings.alignment,target_info.alignment);
  4150. if (cs_opt_size in init_settings.optimizerswitches) then
  4151. begin
  4152. init_settings.alignment.procalign:=1;
  4153. init_settings.alignment.jumpalign:=1;
  4154. init_settings.alignment.loopalign:=1;
  4155. {$ifdef x86}
  4156. { constalignmax=1 keeps the executable and thus the memory foot print small but
  4157. all processors except x86 are really hurt by this or might even crash }
  4158. init_settings.alignment.constalignmax:=1;
  4159. {$endif x86}
  4160. end;
  4161. UpdateAlignment(init_settings.alignment,option.paraalignment);
  4162. set_system_macro('FPC_VERSION',version_nr);
  4163. set_system_macro('FPC_RELEASE',release_nr);
  4164. set_system_macro('FPC_PATCH',patch_nr);
  4165. set_system_macro('FPC_FULLVERSION',Format('%d%.02d%.02d',[StrToInt(version_nr),StrToInt(release_nr),StrToInt(patch_nr)]));
  4166. if target_info.system in systems_indirect_entry_information then
  4167. def_system_macro('FPC_HAS_INDIRECT_ENTRY_INFORMATION');
  4168. if not (tf_winlikewidestring in target_info.flags) then
  4169. def_system_macro('FPC_WIDESTRING_EQUAL_UNICODESTRING');
  4170. if tf_supports_packages in target_info.flags then
  4171. def_system_macro('FPC_HAS_DYNAMIC_PACKAGES');
  4172. if target_info.system in systems_indirect_var_imports then
  4173. def_system_macro('FPC_HAS_INDIRECT_VAR_ACCESS');
  4174. if cs_compilesystem in init_settings.moduleswitches then
  4175. for i:=low(tfeature) to high(tfeature) do
  4176. if i in features then
  4177. def_system_macro('FPC_HAS_FEATURE_'+featurestr[i]);
  4178. {$push}
  4179. {$warn 6018 off} { Unreachable code due to compile time evaluation }
  4180. if ControllerSupport and (target_info.system in systems_embedded) and
  4181. (init_settings.controllertype<>ct_none) then
  4182. begin
  4183. with embedded_controllers[init_settings.controllertype] do
  4184. begin
  4185. set_system_macro('FPC_FLASHBASE',tostr(flashbase));
  4186. set_system_macro('FPC_FLASHSIZE',tostr(flashsize));
  4187. set_system_macro('FPC_SRAMBASE',tostr(srambase));
  4188. set_system_macro('FPC_SRAMSIZE',tostr(sramsize));
  4189. set_system_macro('FPC_EEPROMBASE',tostr(eeprombase));
  4190. set_system_macro('FPC_EEPROMSIZE',tostr(eepromsize));
  4191. set_system_macro('FPC_BOOTBASE',tostr(bootbase));
  4192. set_system_macro('FPC_BOOTSIZE',tostr(bootsize));
  4193. end;
  4194. end;
  4195. {$pop}
  4196. { as stackalign is not part of the alignment record, we do not need to define the others alignments for symmetry yet }
  4197. set_system_macro('FPC_STACKALIGNMENT',tostr(target_info.stackalign));
  4198. option.free;
  4199. Option:=nil;
  4200. clearstack_pocalls := [pocall_cdecl,pocall_cppdecl,pocall_syscall,pocall_mwpascal,pocall_sysv_abi_cdecl,pocall_ms_abi_cdecl];
  4201. cdecl_pocalls := [pocall_cdecl, pocall_cppdecl, pocall_mwpascal, pocall_sysv_abi_cdecl, pocall_ms_abi_cdecl];
  4202. if (tf_safecall_clearstack in target_info.flags) then
  4203. begin
  4204. include (cdecl_pocalls, pocall_safecall);
  4205. include (clearstack_pocalls, pocall_safecall)
  4206. end;
  4207. end;
  4208. initialization
  4209. coption:=toption;
  4210. finalization
  4211. if assigned(option) then
  4212. option.free;
  4213. end.