options.pas 149 KB

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