options.pas 139 KB

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