options.pas 137 KB

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