options.pas 150 KB

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