options.pas 145 KB

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