options.pas 123 KB

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