options.pas 120 KB

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