options.pas 120 KB

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