options.pas 83 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595
  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. CClasses,cfileutl,
  22. globtype,globals,verbose,systems,cpuinfo, comprsrc;
  23. Type
  24. TOption=class
  25. FirstPass,
  26. ParaLogo,
  27. NoPressEnter,
  28. LogoWritten : boolean;
  29. FileLevel : longint;
  30. QuickInfo : string;
  31. ParaIncludePath,
  32. ParaUnitPath,
  33. ParaObjectPath,
  34. ParaLibraryPath,
  35. ParaFrameworkPath : TSearchPathList;
  36. ParaAlignment : TAlignmentInfo;
  37. Constructor Create;
  38. Destructor Destroy;override;
  39. procedure WriteLogo;
  40. procedure WriteInfo;
  41. procedure WriteHelpPages;
  42. procedure WriteQuickInfo;
  43. procedure IllegalPara(const opt:string);
  44. function Unsetbool(var Opts:TCmdStr; Pos: Longint):boolean;
  45. procedure interpret_option(const opt :string;ispara:boolean);
  46. procedure Interpret_envvar(const envname : string);
  47. procedure Interpret_file(const filename : string);
  48. procedure Read_Parameters;
  49. procedure parsecmd(cmd:string);
  50. procedure TargetOptions(def:boolean);
  51. end;
  52. TOptionClass=class of toption;
  53. var
  54. coption : TOptionClass;
  55. procedure read_arguments(cmd:string);
  56. implementation
  57. uses
  58. widestr,
  59. charset,
  60. SysUtils,
  61. version,
  62. cutils,cmsgs,
  63. comphook,
  64. symtable,scanner,rabase,
  65. i_bsd
  66. ;
  67. const
  68. page_size = 24;
  69. var
  70. option : toption;
  71. read_configfile, { read config file, set when a cfgfile is found }
  72. disable_configfile : boolean;
  73. fpcdir,
  74. ppccfg,
  75. ppcaltcfg,
  76. param_file : string; { file to compile specified on the commandline }
  77. {****************************************************************************
  78. Defines
  79. ****************************************************************************}
  80. procedure set_default_link_type;
  81. begin
  82. undef_system_macro('FPC_LINK_SMART');
  83. def_system_macro('FPC_LINK_STATIC');
  84. undef_system_macro('FPC_LINK_DYNAMIC');
  85. init_settings.globalswitches:=init_settings.globalswitches+[cs_link_static];
  86. init_settings.globalswitches:=init_settings.globalswitches-[cs_link_shared,cs_link_smart];
  87. end;
  88. {****************************************************************************
  89. Toption
  90. ****************************************************************************}
  91. procedure StopOptions(err:longint);
  92. begin
  93. if assigned(Option) then
  94. begin
  95. Option.free;
  96. Option:=nil;
  97. end;
  98. raise ECompilerAbortSilent.Create;
  99. end;
  100. procedure Toption.WriteLogo;
  101. var
  102. p : pchar;
  103. begin
  104. if not LogoWritten then
  105. begin
  106. p:=MessagePchar(option_logo);
  107. while assigned(p) do
  108. Comment(V_Normal,GetMsgLine(p));
  109. LogoWritten:= true;
  110. end;
  111. end;
  112. procedure Toption.WriteInfo;
  113. var
  114. p : pchar;
  115. hs,hs1,s : TCmdStr;
  116. target : tsystem;
  117. cpu : tcputype;
  118. fpu : tfputype;
  119. opt : toptimizerswitch;
  120. abi : tabi;
  121. begin
  122. p:=MessagePchar(option_info);
  123. while assigned(p) do
  124. begin
  125. s:=GetMsgLine(p);
  126. { list OS Targets }
  127. if pos('$OSTARGETS',s)>0 then
  128. begin
  129. for target:=low(tsystem) to high(tsystem) do
  130. if assigned(targetinfos[target]) then
  131. begin
  132. hs:=s;
  133. hs1:=targetinfos[target]^.name;
  134. if tf_under_development in targetinfos[target]^.flags then
  135. hs1:=hs1+' (under development)';
  136. Replace(hs,'$OSTARGETS',hs1);
  137. Comment(V_Normal,hs);
  138. end;
  139. end
  140. else if pos('$INSTRUCTIONSETS',s)>0 then
  141. begin
  142. for cpu:=low(tcputype) to high(tcputype) do
  143. begin
  144. hs:=s;
  145. hs1:=cputypestr[cpu];
  146. if hs1<>'' then
  147. begin
  148. Replace(hs,'$INSTRUCTIONSETS',hs1);
  149. Comment(V_Normal,hs);
  150. end;
  151. end;
  152. end
  153. else if pos('$FPUINSTRUCTIONSETS',s)>0 then
  154. begin
  155. for fpu:=low(tfputype) to high(tfputype) do
  156. begin
  157. hs:=s;
  158. hs1:=fputypestr[fpu];
  159. if hs1<>'' then
  160. begin
  161. Replace(hs,'$FPUINSTRUCTIONSETS',hs1);
  162. Comment(V_Normal,hs);
  163. end;
  164. end;
  165. end
  166. else if pos('$ABITARGETS',s)>0 then
  167. begin
  168. for abi:=low(abi) to high(abi) do
  169. begin
  170. hs:=s;
  171. hs1:=abi2str[abi];
  172. if hs1<>'' then
  173. begin
  174. Replace(hs,'$ABITARGETS',hs1);
  175. Comment(V_Normal,hs);
  176. end;
  177. end;
  178. end
  179. else if pos('$OPTIMIZATIONS',s)>0 then
  180. begin
  181. for opt:=low(toptimizerswitch) to high(toptimizerswitch) do
  182. begin
  183. if opt in supported_optimizerswitches then
  184. begin
  185. hs:=s;
  186. hs1:=OptimizerSwitchStr[opt];
  187. if hs1<>'' then
  188. begin
  189. Replace(hs,'$OPTIMIZATIONS',hs1);
  190. Comment(V_Normal,hs);
  191. end;
  192. end;
  193. end;
  194. end
  195. else
  196. Comment(V_Normal,s);
  197. end;
  198. StopOptions(0);
  199. end;
  200. procedure Toption.WriteHelpPages;
  201. function PadEnd(s:string;i:longint):string;
  202. begin
  203. while (length(s)<i) do
  204. s:=s+' ';
  205. PadEnd:=s;
  206. end;
  207. var
  208. lastident,
  209. j,outline,
  210. ident,
  211. lines : longint;
  212. show : boolean;
  213. opt : string[32];
  214. input,
  215. s : string;
  216. p : pchar;
  217. begin
  218. WriteLogo;
  219. Lines:=4;
  220. Message1(option_usage,FixFileName(system.paramstr(0)));
  221. lastident:=0;
  222. p:=MessagePChar(option_help_pages);
  223. while assigned(p) do
  224. begin
  225. { get a line and reset }
  226. s:=GetMsgLine(p);
  227. ident:=0;
  228. show:=false;
  229. { parse options }
  230. case s[1] of
  231. {$ifdef UNITALIASES}
  232. 'a',
  233. {$endif}
  234. {$ifdef EXTDEBUG}
  235. 'e',
  236. {$endif EXTDEBUG}
  237. {$ifdef i386}
  238. '3',
  239. {$endif}
  240. {$ifdef x86_64}
  241. '4',
  242. {$endif}
  243. {$ifdef m68k}
  244. '6',
  245. {$endif}
  246. {$ifdef arm}
  247. 'A',
  248. {$endif}
  249. {$ifdef powerpc}
  250. 'P',
  251. {$endif}
  252. {$ifdef powerpc64}
  253. 'p',
  254. {$endif}
  255. {$ifdef sparc}
  256. 'S',
  257. {$endif}
  258. {$ifdef vis}
  259. 'V',
  260. {$endif}
  261. '*' : show:=true;
  262. end;
  263. if show then
  264. begin
  265. case s[2] of
  266. 'g',
  267. {$ifdef Unix}
  268. 'L',
  269. {$endif}
  270. {$ifdef os2}
  271. 'O',
  272. {$endif}
  273. '*' : show:=true;
  274. else
  275. show:=false;
  276. end;
  277. end;
  278. { now we may show the message or not }
  279. if show then
  280. begin
  281. case s[3] of
  282. '0' : begin
  283. ident:=0;
  284. outline:=0;
  285. end;
  286. '1' : begin
  287. ident:=2;
  288. outline:=7;
  289. end;
  290. '2' : begin
  291. ident:=6;
  292. outline:=11;
  293. end;
  294. '3' : begin
  295. ident:=9;
  296. outline:=11;
  297. end;
  298. end;
  299. j:=pos('_',s);
  300. opt:=Copy(s,4,j-4);
  301. if opt='*' then
  302. opt:=''
  303. else
  304. if opt=' ' then
  305. opt:=PadEnd(opt,outline)
  306. else
  307. opt:=PadEnd('-'+opt,outline);
  308. if (ident=0) and (lastident<>0) then
  309. begin
  310. Comment(V_Normal,'');
  311. inc(Lines);
  312. end;
  313. { page full ? }
  314. if (lines >= page_size - 1) then
  315. begin
  316. if not NoPressEnter then
  317. begin
  318. Message(option_help_press_enter);
  319. readln(input);
  320. if upper(input)='Q' then
  321. StopOptions(0);
  322. end;
  323. lines:=0;
  324. end;
  325. Comment(V_Normal,PadEnd('',ident)+opt+Copy(s,j+1,255));
  326. LastIdent:=Ident;
  327. inc(Lines);
  328. end;
  329. end;
  330. StopOptions(0);
  331. end;
  332. procedure Toption.IllegalPara(const opt:string);
  333. begin
  334. Message1(option_illegal_para,opt);
  335. Message(option_help_pages_para);
  336. StopOptions(1);
  337. end;
  338. function Toption.Unsetbool(var Opts:TCmdStr; Pos: Longint):boolean;
  339. { checks if the character after pos in Opts is a + or a - and returns resp.
  340. false or true. If it is another character (or none), it also returns false }
  341. begin
  342. UnsetBool := false;
  343. if Length(Opts)>Pos then
  344. begin
  345. inc(Pos);
  346. UnsetBool := Opts[Pos] = '-';
  347. if Opts[Pos] in ['-','+']then
  348. delete(Opts,Pos,1);
  349. end;
  350. end;
  351. procedure TOption.interpret_option(const opt:string;ispara:boolean);
  352. var
  353. code : integer;
  354. c : char;
  355. more : TCmdStr;
  356. major,minor : longint;
  357. error : integer;
  358. j,l : longint;
  359. d,s : TCmdStr;
  360. unicodemapping : punicodemap;
  361. begin
  362. if opt='' then
  363. exit;
  364. { only parse define,undef,target,verbosity,link etc options the firsttime }
  365. if firstpass and
  366. not(
  367. (opt[1]='-') and
  368. (
  369. ((length(opt)>1) and (opt[2] in ['i','d','v','T','u','n','X','l'])) or
  370. ((length(opt)>3) and (opt[2]='F') and (opt[3]='e'))
  371. )
  372. ) then
  373. exit;
  374. Message1(option_handling_option,opt);
  375. case opt[1] of
  376. '-' :
  377. begin
  378. more:=Copy(opt,3,255);
  379. if firstpass then
  380. Message1(option_interpreting_firstpass_option,opt)
  381. else
  382. Message1(option_interpreting_option,opt);
  383. case opt[2] of
  384. '?' :
  385. WriteHelpPages;
  386. 'a' :
  387. begin
  388. include(init_settings.globalswitches,cs_asm_leave);
  389. j:=1;
  390. while j<=length(more) do
  391. begin
  392. case more[j] of
  393. 'l' :
  394. include(init_settings.globalswitches,cs_asm_source);
  395. 'r' :
  396. include(init_settings.globalswitches,cs_asm_regalloc);
  397. 't' :
  398. include(init_settings.globalswitches,cs_asm_tempalloc);
  399. 'n' :
  400. include(init_settings.globalswitches,cs_asm_nodes);
  401. 'p' :
  402. begin
  403. exclude(init_settings.globalswitches,cs_asm_leave);
  404. if UnsetBool(More, 0) then
  405. exclude(init_settings.globalswitches,cs_asm_pipe)
  406. else
  407. include(init_settings.globalswitches,cs_asm_pipe);
  408. end;
  409. '-' :
  410. init_settings.globalswitches:=init_settings.globalswitches -
  411. [cs_asm_leave, cs_asm_source,cs_asm_regalloc, cs_asm_tempalloc,
  412. cs_asm_nodes, cs_asm_pipe];
  413. else
  414. IllegalPara(opt);
  415. end;
  416. inc(j);
  417. end;
  418. end;
  419. 'A' :
  420. begin
  421. paratargetasm:=find_asm_by_string(More);
  422. if paratargetasm=as_none then
  423. IllegalPara(opt);
  424. end;
  425. 'b' :
  426. begin
  427. // Message1(option_obsolete_switch,'-b');
  428. if UnsetBool(More,0) then
  429. begin
  430. init_settings.moduleswitches:=init_settings.moduleswitches-[cs_browser];
  431. init_settings.moduleswitches:=init_settings.moduleswitches-[cs_local_browser];
  432. end
  433. else
  434. begin
  435. init_settings.moduleswitches:=init_settings.moduleswitches+[cs_browser];
  436. end;
  437. if More<>'' then
  438. if (More='l') or (More='l+') then
  439. init_settings.moduleswitches:=init_settings.moduleswitches+[cs_local_browser]
  440. else if More='l-' then
  441. init_settings.moduleswitches:=init_settings.moduleswitches-[cs_local_browser]
  442. else
  443. IllegalPara(opt);
  444. end;
  445. 'B' :
  446. do_build:=not UnSetBool(more,0);
  447. 'C' :
  448. begin
  449. j:=1;
  450. while j<=length(more) do
  451. begin
  452. case more[j] of
  453. 'a' :
  454. begin
  455. s:=upper(copy(more,j+1,length(more)-j));
  456. if not(SetAbiType(s,target_info.abi)) then
  457. IllegalPara(opt);
  458. break;
  459. end;
  460. 'b' :
  461. begin
  462. if UnsetBool(More, j) then
  463. target_info.endian:=endian_little
  464. else
  465. target_info.endian:=endian_big;
  466. end;
  467. 'c' :
  468. begin
  469. if not SetAktProcCall(upper(copy(more,j+1,length(more)-j)),init_settings.defproccall) then
  470. IllegalPara(opt);
  471. break;
  472. end;
  473. {$ifdef cpufpemu}
  474. 'e' :
  475. begin
  476. If UnsetBool(More, j) then
  477. exclude(init_settings.moduleswitches,cs_fp_emulation)
  478. Else
  479. include(init_settings.moduleswitches,cs_fp_emulation);
  480. end;
  481. {$endif cpufpemu}
  482. 'f' :
  483. begin
  484. s:=upper(copy(more,j+1,length(more)-j));
  485. if not(SetFpuType(s,init_settings.fputype)) then
  486. IllegalPara(opt);
  487. break;
  488. end;
  489. 'F' :
  490. begin
  491. if not SetMinFPConstPrec(copy(more,j+1,length(more)-j),init_settings.minfpconstprec) then
  492. IllegalPara(opt);
  493. break;
  494. end;
  495. 'g' :
  496. begin
  497. if tf_no_pic_supported in target_info.flags then
  498. begin
  499. { consume a possible '-' coming after it }
  500. UnsetBool(More, j);
  501. message(scan_w_pic_ignored);
  502. end
  503. else if UnsetBool(More, j) then
  504. exclude(init_settings.moduleswitches,cs_create_pic)
  505. else
  506. include(init_settings.moduleswitches,cs_create_pic);
  507. end;
  508. 'h' :
  509. begin
  510. val(copy(more,j+1,length(more)-j),heapsize,code);
  511. if (code<>0) or (heapsize<1024) then
  512. IllegalPara(opt);
  513. break;
  514. end;
  515. 'i' :
  516. If UnsetBool(More, j) then
  517. exclude(init_settings.localswitches,cs_check_io)
  518. else
  519. include(init_settings.localswitches,cs_check_io);
  520. 'n' :
  521. If UnsetBool(More, j) then
  522. exclude(init_settings.globalswitches,cs_link_nolink)
  523. Else
  524. include(init_settings.globalswitches,cs_link_nolink);
  525. 'o' :
  526. If UnsetBool(More, j) then
  527. exclude(init_settings.localswitches,cs_check_overflow)
  528. Else
  529. include(init_settings.localswitches,cs_check_overflow);
  530. 'O' :
  531. If UnsetBool(More, j) then
  532. exclude(init_settings.localswitches,cs_check_ordinal_size)
  533. Else
  534. include(init_settings.localswitches,cs_check_ordinal_size);
  535. 'p' :
  536. begin
  537. s:=upper(copy(more,j+1,length(more)-j));
  538. if not(Setcputype(s,init_settings.cputype)) then
  539. IllegalPara(opt);
  540. break;
  541. end;
  542. 'P':
  543. begin
  544. delete(more,1,1);
  545. if upper(copy(more,1,pos('=',more)-1))='PACKSET' then
  546. begin
  547. delete(more,1,pos('=',more));
  548. if more='0' then
  549. init_settings.setalloc:=0
  550. else if (more='1') or (more='DEFAULT') or (more='NORMAL') then
  551. init_settings.setalloc:=1
  552. else if more='2' then
  553. init_settings.setalloc:=2
  554. else if more='4' then
  555. init_settings.setalloc:=4
  556. else if more='8' then
  557. init_settings.setalloc:=8
  558. else
  559. IllegalPara(opt);
  560. end
  561. else
  562. IllegalPara(opt);
  563. end;
  564. 'r' :
  565. If UnsetBool(More, j) then
  566. exclude(init_settings.localswitches,cs_check_range)
  567. Else
  568. include(init_settings.localswitches,cs_check_range);
  569. 'R' :
  570. If UnsetBool(More, j) then
  571. begin
  572. exclude(init_settings.localswitches,cs_check_range);
  573. exclude(init_settings.localswitches,cs_check_object);
  574. end
  575. Else
  576. begin
  577. include(init_settings.localswitches,cs_check_range);
  578. include(init_settings.localswitches,cs_check_object);
  579. end;
  580. 's' :
  581. begin
  582. val(copy(more,j+1,length(more)-j),stacksize,code);
  583. if (code<>0) or (stacksize>=67107840) or (stacksize<1024) then
  584. IllegalPara(opt);
  585. break;
  586. end;
  587. 't' :
  588. If UnsetBool(More, j) then
  589. exclude(init_settings.localswitches,cs_check_stack)
  590. Else
  591. include(init_settings.localswitches,cs_check_stack);
  592. 'D' :
  593. If UnsetBool(More, j) then
  594. exclude(init_settings.moduleswitches,cs_create_dynamic)
  595. Else
  596. include(init_settings.moduleswitches,cs_create_dynamic);
  597. 'X' :
  598. If UnsetBool(More, j) then
  599. exclude(init_settings.moduleswitches,cs_create_smart)
  600. Else
  601. include(init_settings.moduleswitches,cs_create_smart);
  602. else
  603. IllegalPara(opt);
  604. end;
  605. inc(j);
  606. end;
  607. end;
  608. 'd' :
  609. if more <> '' then
  610. begin
  611. l:=Pos(':=',more);
  612. if l>0 then
  613. set_system_compvar(Copy(more,1,l-1),Copy(more,l+2,255))
  614. else
  615. def_system_macro(more);
  616. end;
  617. 'D' :
  618. begin
  619. include(init_settings.globalswitches,cs_link_deffile);
  620. j:=1;
  621. while j<=length(more) do
  622. begin
  623. case more[j] of
  624. 'd' :
  625. begin
  626. description:=Copy(more,j+1,255);
  627. break;
  628. end;
  629. 'v' :
  630. begin
  631. dllversion:=Copy(more,j+1,255);
  632. l:=pos('.',dllversion);
  633. dllminor:=0;
  634. error:=0;
  635. if l>0 then
  636. begin
  637. val(copy(dllversion,l+1,255),minor,error);
  638. if (error=0) and
  639. (minor>=0) and (minor<=$ffff) then
  640. dllminor:=minor
  641. else
  642. if error=0 then
  643. error:=1;
  644. end;
  645. if l=0 then
  646. l:=256;
  647. dllmajor:=1;
  648. if error=0 then
  649. val(copy(dllversion,1,l-1),major,error);
  650. if (error=0) and (major>=0) and (major<=$ffff) then
  651. dllmajor:=major
  652. else
  653. if error=0 then
  654. error:=1;
  655. if error<>0 then
  656. Message1(scan_w_wrong_version_ignored,dllversion);
  657. break;
  658. end;
  659. 'w' :
  660. usewindowapi:=true;
  661. '-' :
  662. begin
  663. exclude(init_settings.globalswitches,cs_link_deffile);
  664. usewindowapi:=false;
  665. end;
  666. else
  667. IllegalPara(opt);
  668. end;
  669. inc(j);
  670. end;
  671. end;
  672. 'e' :
  673. exepath:=FixPath(More,true);
  674. 'E' :
  675. begin
  676. if UnsetBool(More, 0) then
  677. exclude(init_settings.globalswitches,cs_link_nolink)
  678. else
  679. include(init_settings.globalswitches,cs_link_nolink);
  680. end;
  681. 'f' :
  682. begin
  683. if more='PIC' then
  684. begin
  685. if tf_no_pic_supported in target_info.flags then
  686. message(scan_w_pic_ignored)
  687. else
  688. include(init_settings.moduleswitches,cs_create_pic)
  689. end
  690. else
  691. IllegalPara(opt);
  692. end;
  693. 'F' :
  694. begin
  695. if more='' then
  696. IllegalPara(opt);
  697. c:=more[1];
  698. Delete(more,1,1);
  699. DefaultReplacements(More);
  700. case c of
  701. 'a' :
  702. autoloadunits:=more;
  703. 'c' :
  704. begin
  705. if (upper(more)='UTF8') or (upper(more)='UTF-8') then
  706. init_settings.sourcecodepage:='utf8'
  707. else if not(cpavailable(more)) then
  708. Message1(option_code_page_not_available,more)
  709. else
  710. init_settings.sourcecodepage:=more;
  711. end;
  712. 'C' :
  713. RCCompiler := More;
  714. 'D' :
  715. utilsdirectory:=FixPath(More,true);
  716. 'e' :
  717. SetRedirectFile(More);
  718. 'E' :
  719. OutputExeDir:=FixPath(More,true);
  720. 'f' :
  721. if (target_info.system in systems_darwin) then
  722. if ispara then
  723. ParaFrameworkPath.AddPath(More,false)
  724. else
  725. frameworksearchpath.AddPath(More,true)
  726. else
  727. IllegalPara(opt);
  728. 'i' :
  729. begin
  730. if ispara then
  731. ParaIncludePath.AddPath(More,false)
  732. else
  733. includesearchpath.AddPath(More,true);
  734. end;
  735. 'm' :
  736. begin
  737. unicodemapping:=loadunicodemapping(More,More+'.txt');
  738. if assigned(unicodemapping) then
  739. registermapping(unicodemapping)
  740. else
  741. IllegalPara(opt);
  742. end;
  743. 'g' :
  744. Message2(option_obsolete_switch_use_new,'-Fg','-Fl');
  745. 'l' :
  746. begin
  747. if ispara then
  748. ParaLibraryPath.AddPath(sysrootpath,More,false)
  749. else
  750. LibrarySearchPath.AddPath(sysrootpath,More,true);
  751. end;
  752. 'L' :
  753. begin
  754. if More<>'' then
  755. ParaDynamicLinker:=More
  756. else
  757. IllegalPara(opt);
  758. end;
  759. 'o' :
  760. begin
  761. if ispara then
  762. ParaObjectPath.AddPath(More,false)
  763. else
  764. ObjectSearchPath.AddPath(More,true);
  765. end;
  766. 'r' :
  767. Msgfilename:=More;
  768. 'R' :
  769. ResCompiler := More;
  770. 'u' :
  771. begin
  772. if ispara then
  773. ParaUnitPath.AddPath(More,false)
  774. else
  775. unitsearchpath.AddPath(More,true);
  776. end;
  777. 'U' :
  778. OutputUnitDir:=FixPath(More,true);
  779. else
  780. IllegalPara(opt);
  781. end;
  782. end;
  783. 'g' :
  784. begin
  785. if UnsetBool(More, 0) then
  786. begin
  787. exclude(init_settings.moduleswitches,cs_debuginfo);
  788. exclude(init_settings.globalswitches,cs_use_heaptrc);
  789. exclude(init_settings.globalswitches,cs_use_lineinfo);
  790. exclude(init_settings.localswitches,cs_checkpointer);
  791. localvartrashing := -1;
  792. end
  793. else
  794. begin
  795. include(init_settings.moduleswitches,cs_debuginfo);
  796. if paratargetdbg=dbg_none then
  797. paratargetdbg:=target_info.dbg;
  798. end;
  799. if not RelocSectionSetExplicitly then
  800. RelocSection:=false;
  801. j:=1;
  802. while j<=length(more) do
  803. begin
  804. case more[j] of
  805. 'c' :
  806. begin
  807. if UnsetBool(More, j) then
  808. exclude(init_settings.localswitches,cs_checkpointer)
  809. else
  810. include(init_settings.localswitches,cs_checkpointer);
  811. end;
  812. 'h' :
  813. begin
  814. if UnsetBool(More, j) then
  815. exclude(init_settings.globalswitches,cs_use_heaptrc)
  816. else
  817. include(init_settings.globalswitches,cs_use_heaptrc);
  818. end;
  819. 'l' :
  820. begin
  821. if UnsetBool(More, j) then
  822. exclude(init_settings.globalswitches,cs_use_lineinfo)
  823. else
  824. include(init_settings.globalswitches,cs_use_lineinfo);
  825. end;
  826. 'o' :
  827. begin
  828. if not UpdateDebugStr(copy(more,j+1,length(more)),init_settings.debugswitches) then
  829. IllegalPara(opt);
  830. break;
  831. end;
  832. 'p' :
  833. begin
  834. if UnsetBool(More, j) then
  835. exclude(init_settings.globalswitches,cs_stabs_preservecase)
  836. else
  837. include(init_settings.globalswitches,cs_stabs_preservecase);
  838. end;
  839. 's' :
  840. begin
  841. paratargetdbg:=dbg_stabs;
  842. end;
  843. 't' :
  844. begin
  845. if UnsetBool(More, j) then
  846. localvartrashing := -1
  847. else
  848. localvartrashing := (localvartrashing + 1) mod nroftrashvalues;
  849. end;
  850. 'v' :
  851. begin
  852. if UnsetBool(More, j) then
  853. exclude(init_settings.globalswitches,cs_gdb_valgrind)
  854. else
  855. include(init_settings.globalswitches,cs_gdb_valgrind);
  856. end;
  857. 'w' :
  858. begin
  859. if (j<length(more)) and (more[j+1] in ['2','3']) then
  860. begin
  861. case more[j+1] of
  862. '2': paratargetdbg:=dbg_dwarf2;
  863. '3': paratargetdbg:=dbg_dwarf3;
  864. end;
  865. inc(j);
  866. end
  867. else
  868. paratargetdbg:=dbg_dwarf2;
  869. end;
  870. else
  871. IllegalPara(opt);
  872. end;
  873. inc(j);
  874. end;
  875. end;
  876. 'h' :
  877. begin
  878. NoPressEnter:=true;
  879. WriteHelpPages;
  880. end;
  881. 'i' :
  882. begin
  883. if More='' then
  884. WriteInfo
  885. else
  886. QuickInfo:=QuickInfo+More;
  887. end;
  888. 'I' :
  889. begin
  890. if ispara then
  891. ParaIncludePath.AddPath(More,false)
  892. else
  893. includesearchpath.AddPath(More,false);
  894. end;
  895. 'k' :
  896. begin
  897. if more<>'' then
  898. ParaLinkOptions:=ParaLinkOptions+' '+More
  899. else
  900. IllegalPara(opt);
  901. end;
  902. 'l' :
  903. ParaLogo:=not UnSetBool(more,0);
  904. 'm' :
  905. parapreprocess:=not UnSetBool(more,0);
  906. 'M' :
  907. begin
  908. more:=Upper(more);
  909. if not SetCompileMode(more, true) then
  910. if not SetCompileModeSwitch(more, true) then
  911. IllegalPara(opt);
  912. end;
  913. 'n' :
  914. begin
  915. if More='' then
  916. disable_configfile:=true
  917. else
  918. IllegalPara(opt);
  919. end;
  920. 'o' :
  921. begin
  922. if More<>'' then
  923. begin
  924. DefaultReplacements(More);
  925. D:=ExtractFilePath(More);
  926. if (D<>'') then
  927. OutputExeDir:=FixPath(D,True);
  928. OutputFileName:=ExtractFileName(More);
  929. end
  930. else
  931. IllegalPara(opt);
  932. end;
  933. 'O' :
  934. begin
  935. j:=1;
  936. while j<=length(more) do
  937. begin
  938. case more[j] of
  939. '1' :
  940. init_settings.optimizerswitches:=init_settings.optimizerswitches+level1optimizerswitches;
  941. '2' :
  942. init_settings.optimizerswitches:=init_settings.optimizerswitches+level2optimizerswitches;
  943. '3' :
  944. init_settings.optimizerswitches:=init_settings.optimizerswitches+level3optimizerswitches;
  945. 'a' :
  946. begin
  947. if not(UpdateAlignmentStr(Copy(Opt,j+3,255),ParaAlignment)) then
  948. IllegalPara(opt);
  949. break;
  950. end;
  951. 's' :
  952. include(init_settings.optimizerswitches,cs_opt_size);
  953. 'p' :
  954. begin
  955. if not Setcputype(copy(more,j+1,length(more)),init_settings.optimizecputype) then
  956. begin
  957. { Give warning for old i386 switches }
  958. if (Length(More)-j=1) and
  959. (More[j+1]>='1') and (More[j+1]<='5')then
  960. Message2(option_obsolete_switch_use_new,'-Op<nr>','-Op<name>')
  961. else
  962. IllegalPara(opt);
  963. end;
  964. break;
  965. end;
  966. 'o' :
  967. begin
  968. if not UpdateOptimizerStr(copy(more,j+1,length(more)),init_settings.optimizerswitches) then
  969. IllegalPara(opt);
  970. break;
  971. end;
  972. '-' :
  973. begin
  974. init_settings.optimizerswitches:=[];
  975. FillChar(ParaAlignment,sizeof(ParaAlignment),0);
  976. end;
  977. { Obsolete switches }
  978. 'g' :
  979. Message2(option_obsolete_switch_use_new,'-Og','-Os');
  980. 'G' :
  981. Message1(option_obsolete_switch,'-OG');
  982. 'r' :
  983. Message2(option_obsolete_switch_use_new,'-Or','-O2 or -Ooregvar');
  984. 'u' :
  985. Message2(option_obsolete_switch_use_new,'-Ou','-Oouncertain');
  986. else
  987. IllegalPara(opt);
  988. end;
  989. inc(j);
  990. end;
  991. end;
  992. 'p' :
  993. begin
  994. if UnsetBool(More, 0) then
  995. begin
  996. init_settings.moduleswitches:=init_settings.moduleswitches-[cs_profile];
  997. undef_system_macro('FPC_PROFILE');
  998. end
  999. else
  1000. if Length(More)=0 then
  1001. IllegalPara(opt)
  1002. else
  1003. case more[1] of
  1004. 'g' : if UnsetBool(more, 1) then
  1005. begin
  1006. exclude(init_settings.moduleswitches,cs_profile);
  1007. undef_system_macro('FPC_PROFILE');
  1008. end
  1009. else
  1010. begin
  1011. include(init_settings.moduleswitches,cs_profile);
  1012. def_system_macro('FPC_PROFILE');
  1013. end;
  1014. else
  1015. IllegalPara(opt);
  1016. end;
  1017. end;
  1018. 'P' : ; { Ignore used by fpc.pp }
  1019. 'R' :
  1020. begin
  1021. if not SetAsmReadMode(More,init_settings.asmmode) then
  1022. IllegalPara(opt);
  1023. end;
  1024. 's' :
  1025. begin
  1026. if UnsetBool(More, 0) then
  1027. begin
  1028. init_settings.globalswitches:=init_settings.globalswitches-[cs_asm_extern,cs_link_extern,cs_link_nolink];
  1029. if more<>'' then
  1030. IllegalPara(opt);
  1031. end
  1032. else
  1033. begin
  1034. init_settings.globalswitches:=init_settings.globalswitches+[cs_asm_extern,cs_link_extern,cs_link_nolink];
  1035. if more='h' then
  1036. init_settings.globalswitches:=init_settings.globalswitches-[cs_link_on_target]
  1037. else if more='t' then
  1038. init_settings.globalswitches:=init_settings.globalswitches+[cs_link_on_target]
  1039. else if more='r' then
  1040. init_settings.globalswitches:=init_settings.globalswitches+[cs_asm_leave,cs_no_regalloc]
  1041. else if more<>'' then
  1042. IllegalPara(opt);
  1043. end;
  1044. end;
  1045. 'S' :
  1046. begin
  1047. if more='' then
  1048. IllegalPara(opt);
  1049. if more[1]='I' then
  1050. begin
  1051. if upper(more)='ICOM' then
  1052. init_settings.interfacetype:=it_interfacecom
  1053. else if upper(more)='ICORBA' then
  1054. init_settings.interfacetype:=it_interfacecorba
  1055. else
  1056. IllegalPara(opt);
  1057. end
  1058. else
  1059. begin
  1060. j:=1;
  1061. while j<=length(more) do
  1062. begin
  1063. case more[j] of
  1064. '2' : //an alternative to -Mobjfpc
  1065. SetCompileMode('OBJFPC',true);
  1066. 'a' :
  1067. If UnsetBool(More, j) then
  1068. exclude(init_settings.localswitches,cs_do_assertion)
  1069. else
  1070. include(init_settings.localswitches,cs_do_assertion);
  1071. 'c' :
  1072. If UnsetBool(More, j) then
  1073. include(init_settings.moduleswitches,cs_support_c_operators)
  1074. else
  1075. include(init_settings.moduleswitches,cs_support_c_operators);
  1076. 'd' : //an alternative to -Mdelphi
  1077. SetCompileMode('DELPHI',true);
  1078. 'e' :
  1079. begin
  1080. SetErrorFlags(copy(more,j+1,length(more)));
  1081. break;
  1082. end;
  1083. 'f' :
  1084. begin
  1085. inc(j);
  1086. if more[j]='-' then
  1087. begin
  1088. features:=[];
  1089. if length(more)>j then
  1090. IllegalPara(opt);
  1091. end
  1092. else
  1093. begin
  1094. if (IncludeFeature(upper(copy(more,j,length(more)-j+1)))) then
  1095. j:=length(more)
  1096. else
  1097. IllegalPara(opt);
  1098. end;
  1099. end;
  1100. 'g' :
  1101. If UnsetBool(More, j) then
  1102. exclude(init_settings.moduleswitches,cs_support_goto)
  1103. else
  1104. include(init_settings.moduleswitches,cs_support_goto);
  1105. 'h' :
  1106. If UnsetBool(More, j) then
  1107. exclude(init_settings.localswitches,cs_ansistrings)
  1108. else
  1109. include(init_settings.localswitches,cs_ansistrings);
  1110. 'i' :
  1111. If UnsetBool(More, j) then
  1112. exclude(init_settings.localswitches,cs_do_inline)
  1113. else
  1114. include(init_settings.localswitches,cs_do_inline);
  1115. 'k' :
  1116. If UnsetBool(More, j) then
  1117. exclude(init_settings.globalswitches,cs_load_fpcylix_unit)
  1118. else
  1119. include(init_settings.globalswitches,cs_load_fpcylix_unit);
  1120. 'm' :
  1121. If UnsetBool(More, j) then
  1122. exclude(init_settings.moduleswitches,cs_support_macro)
  1123. else
  1124. include(init_settings.moduleswitches,cs_support_macro);
  1125. 'o' : //an alternative to -Mtp
  1126. SetCompileMode('TP',true);
  1127. {$ifdef gpc_mode}
  1128. 'p' : //an alternative to -Mgpc
  1129. SetCompileMode('GPC',true);
  1130. {$endif}
  1131. 's' :
  1132. If UnsetBool(More, j) then
  1133. exclude(init_settings.globalswitches,cs_constructor_name)
  1134. else
  1135. include(init_settings.globalswitches,cs_constructor_name);
  1136. 't' :
  1137. If UnsetBool(More, j) then
  1138. exclude(init_settings.moduleswitches,cs_static_keyword)
  1139. else
  1140. include(init_settings.moduleswitches,cs_static_keyword);
  1141. 'v' :
  1142. If UnsetBool(More, j) then
  1143. exclude(init_settings.globalswitches,cs_support_vectors)
  1144. else
  1145. include(init_settings.globalswitches,cs_support_vectors);
  1146. 'x' :
  1147. If UnsetBool(More, j) then
  1148. exclude(init_settings.globalswitches,cs_support_exceptions)
  1149. else
  1150. include(init_settings.globalswitches,cs_support_exceptions);
  1151. '-' :
  1152. begin
  1153. init_settings.globalswitches:=init_settings.globalswitches - [cs_constructor_name,cs_support_exceptions];
  1154. init_settings.localswitches:=init_settings.localswitches - [cs_do_assertion, cs_do_inline, cs_ansistrings];
  1155. init_settings.moduleswitches:=init_settings.moduleswitches - [cs_support_c_operators, cs_support_goto,
  1156. cs_support_macro,
  1157. cs_static_keyword];
  1158. end;
  1159. else
  1160. IllegalPara(opt);
  1161. end;
  1162. inc(j);
  1163. end;
  1164. end;
  1165. end;
  1166. 'T' :
  1167. begin
  1168. more:=Upper(More);
  1169. if paratarget=system_none then
  1170. begin
  1171. { remove old target define }
  1172. TargetOptions(false);
  1173. { load new target }
  1174. paratarget:=find_system_by_string(More);
  1175. if paratarget<>system_none then
  1176. set_target(paratarget)
  1177. else
  1178. IllegalPara(opt);
  1179. { set new define }
  1180. TargetOptions(true);
  1181. end
  1182. else
  1183. if More<>upper(target_info.shortname) then
  1184. Message1(option_target_is_already_set,target_info.shortname);
  1185. end;
  1186. 'u' :
  1187. if more <> '' then
  1188. undef_system_macro(more);
  1189. 'U' :
  1190. begin
  1191. j:=1;
  1192. while j<=length(more) do
  1193. begin
  1194. case more[j] of
  1195. {$ifdef UNITALIASES}
  1196. 'a' :
  1197. begin
  1198. AddUnitAlias(Copy(More,j+1,255));
  1199. break;
  1200. end;
  1201. {$endif UNITALIASES}
  1202. 'n' :
  1203. exclude(init_settings.globalswitches,cs_check_unit_name);
  1204. 'p' :
  1205. begin
  1206. Message2(option_obsolete_switch_use_new,'-Up','-Fu');
  1207. break;
  1208. end;
  1209. 'r' :
  1210. do_release:=true;
  1211. 's' :
  1212. include(init_settings.moduleswitches,cs_compilesystem);
  1213. '-' :
  1214. begin
  1215. exclude(init_settings.moduleswitches,cs_compilesystem);
  1216. exclude(init_settings.globalswitches,cs_check_unit_name);
  1217. end;
  1218. else
  1219. IllegalPara(opt);
  1220. end;
  1221. inc(j);
  1222. end;
  1223. end;
  1224. 'v' :
  1225. begin
  1226. if not setverbosity(More) then
  1227. IllegalPara(opt);
  1228. end;
  1229. 'V' : ; { Ignore used by fpc }
  1230. 'W' :
  1231. begin
  1232. j:=1;
  1233. while j<=length(More) do
  1234. begin
  1235. case More[j] of
  1236. 'A':
  1237. begin
  1238. if UnsetBool(More, j) then
  1239. apptype:=app_native
  1240. else
  1241. apptype:=app_cui;
  1242. end;
  1243. 'b':
  1244. begin
  1245. if (target_info.system in systems_darwin) then
  1246. begin
  1247. if not UnsetBool(More, j) then
  1248. apptype:=app_bundle
  1249. else
  1250. apptype:=app_cui
  1251. end
  1252. else
  1253. IllegalPara(opt);
  1254. end;
  1255. 'B':
  1256. begin
  1257. { -WB200000 means set trefered base address
  1258. to $200000, but does not change relocsection boolean
  1259. this way we can create both relocatble and
  1260. non relocatable DLL at a specific base address PM }
  1261. if (length(More)>j) then
  1262. begin
  1263. if DLLImageBase=nil then
  1264. DLLImageBase:=StringDup(Copy(More,j+1,255));
  1265. end
  1266. else
  1267. begin
  1268. RelocSection:=true;
  1269. RelocSectionSetExplicitly:=true;
  1270. end;
  1271. break;
  1272. end;
  1273. 'C':
  1274. begin
  1275. if UnsetBool(More, j) then
  1276. apptype:=app_gui
  1277. else
  1278. apptype:=app_cui;
  1279. end;
  1280. 'D':
  1281. begin
  1282. UseDeffileForExports:=not UnsetBool(More, j);
  1283. UseDeffileForExportsSetExplicitly:=true;
  1284. end;
  1285. 'e':
  1286. begin
  1287. if (target_info.system in systems_darwin) then
  1288. begin
  1289. RegisterRes(res_macosx_ext_info,TWinLikeResourceFile);
  1290. set_target_res(res_ext);
  1291. target_info.resobjext:='.fpcres';
  1292. end
  1293. else
  1294. IllegalPara(opt);
  1295. end;
  1296. 'F':
  1297. begin
  1298. if UnsetBool(More, j) then
  1299. apptype:=app_cui
  1300. else
  1301. apptype:=app_fs;
  1302. end;
  1303. 'G':
  1304. begin
  1305. if UnsetBool(More, j) then
  1306. apptype:=app_cui
  1307. else
  1308. apptype:=app_gui;
  1309. end;
  1310. 'I':
  1311. begin
  1312. GenerateImportSection:=not UnsetBool(More,j);
  1313. GenerateImportSectionSetExplicitly:=true;
  1314. end;
  1315. 'i':
  1316. begin
  1317. if (target_info.system in systems_darwin) then
  1318. begin
  1319. set_target_res(res_macho);
  1320. target_info.resobjext:=
  1321. targetinfos[target_info.system]^.resobjext;
  1322. end
  1323. else
  1324. IllegalPara(opt);
  1325. end;
  1326. 'N':
  1327. begin
  1328. RelocSection:=UnsetBool(More,j);
  1329. RelocSectionSetExplicitly:=true;
  1330. end;
  1331. 'R':
  1332. begin
  1333. { support -WR+ / -WR- as synonyms to -WR / -WN }
  1334. RelocSection:=not UnsetBool(More,j);
  1335. RelocSectionSetExplicitly:=true;
  1336. end;
  1337. 'T':
  1338. begin
  1339. if UnsetBool(More, j) then
  1340. apptype:=app_cui
  1341. else
  1342. apptype:=app_tool;
  1343. end;
  1344. else
  1345. IllegalPara(opt);
  1346. end;
  1347. inc(j);
  1348. end;
  1349. end;
  1350. 'X' :
  1351. begin
  1352. j:=1;
  1353. while j<=length(more) do
  1354. begin
  1355. case More[j] of
  1356. 'c' : Cshared:=TRUE;
  1357. 'd' : Dontlinkstdlibpath:=TRUE;
  1358. 'e' :
  1359. begin
  1360. If UnsetBool(More, j) then
  1361. exclude(init_settings.globalswitches,cs_link_extern)
  1362. else
  1363. include(init_settings.globalswitches,cs_link_extern);
  1364. end;
  1365. 'f' :
  1366. include(init_settings.globalswitches,cs_link_pthread);
  1367. 'g' :
  1368. begin
  1369. If UnsetBool(More, j) then
  1370. exclude(init_settings.globalswitches,cs_link_separate_dbg_file)
  1371. else
  1372. include(init_settings.globalswitches,cs_link_separate_dbg_file);
  1373. end;
  1374. 'i' :
  1375. begin
  1376. If UnsetBool(More, j) then
  1377. include(init_settings.globalswitches,cs_link_extern)
  1378. else
  1379. exclude(init_settings.globalswitches,cs_link_extern);
  1380. end;
  1381. 'm' :
  1382. begin
  1383. If UnsetBool(More, j) then
  1384. exclude(init_settings.globalswitches,cs_link_map)
  1385. else
  1386. include(init_settings.globalswitches,cs_link_map);
  1387. end;
  1388. 'p' : ; { Ignore used by fpc.pp }
  1389. 'r' :
  1390. begin
  1391. rlinkpath:=Copy(more,2,length(More)-1);
  1392. DefaultReplacements(rlinkpath);
  1393. More:='';
  1394. end;
  1395. 'R' :
  1396. begin
  1397. sysrootpath:=copy(more,2,length(more)-1);
  1398. defaultreplacements(sysrootpath);
  1399. more:='';
  1400. end;
  1401. 's' :
  1402. begin
  1403. If UnsetBool(More, j) then
  1404. exclude(init_settings.globalswitches,cs_link_strip)
  1405. else
  1406. include(init_settings.globalswitches,cs_link_strip);
  1407. end;
  1408. 't' :
  1409. include(init_settings.globalswitches,cs_link_staticflag);
  1410. 'v' :
  1411. begin
  1412. If UnsetBool(More, j) then
  1413. exclude(init_settings.globalswitches,cs_link_opt_vtable)
  1414. else
  1415. include(init_settings.globalswitches,cs_link_opt_vtable);
  1416. end;
  1417. 'D' :
  1418. begin
  1419. def_system_macro('FPC_LINK_DYNAMIC');
  1420. undef_system_macro('FPC_LINK_SMART');
  1421. undef_system_macro('FPC_LINK_STATIC');
  1422. exclude(init_settings.globalswitches,cs_link_static);
  1423. exclude(init_settings.globalswitches,cs_link_smart);
  1424. include(init_settings.globalswitches,cs_link_shared);
  1425. LinkTypeSetExplicitly:=true;
  1426. end;
  1427. 'M' :
  1428. begin
  1429. mainaliasname:=Copy(more,2,length(More)-1);
  1430. More:='';
  1431. end;
  1432. 'P' :
  1433. begin
  1434. utilsprefix:=Copy(more,2,length(More)-1);
  1435. DefaultReplacements(utilsprefix);
  1436. More:='';
  1437. end;
  1438. 'L' : begin // -XLO is link order -XLA is link alias. -XLD avoids load defaults.
  1439. // these are not aggregable.
  1440. if (j=length(more)) or not (more[j+1] in ['O','A','D']) then
  1441. IllegalPara(opt)
  1442. else
  1443. begin
  1444. case more[j+1] of
  1445. 'A' : begin
  1446. s:=Copy(more,3,length(More)-2);
  1447. if not LinkLibraryAliases.AddDep(s) Then
  1448. IllegalPara(opt);
  1449. end;
  1450. 'O' : begin
  1451. s:=Copy(more,3,length(More)-2);
  1452. if not LinkLibraryOrder.AddWeight(s) Then
  1453. IllegalPara(opt);
  1454. end;
  1455. 'D' : include(init_settings.globalswitches,cs_link_no_default_lib_order)
  1456. else
  1457. IllegalPara(opt);
  1458. end; {case}
  1459. j:=length(more);
  1460. end; {else begin}
  1461. end;
  1462. 'S' :
  1463. begin
  1464. def_system_macro('FPC_LINK_STATIC');
  1465. undef_system_macro('FPC_LINK_SMART');
  1466. undef_system_macro('FPC_LINK_DYNAMIC');
  1467. include(init_settings.globalswitches,cs_link_static);
  1468. exclude(init_settings.globalswitches,cs_link_smart);
  1469. exclude(init_settings.globalswitches,cs_link_shared);
  1470. LinkTypeSetExplicitly:=true;
  1471. end;
  1472. 'X' :
  1473. begin
  1474. def_system_macro('FPC_LINK_SMART');
  1475. undef_system_macro('FPC_LINK_STATIC');
  1476. undef_system_macro('FPC_LINK_DYNAMIC');
  1477. exclude(init_settings.globalswitches,cs_link_static);
  1478. include(init_settings.globalswitches,cs_link_smart);
  1479. exclude(init_settings.globalswitches,cs_link_shared);
  1480. LinkTypeSetExplicitly:=true;
  1481. end;
  1482. '-' :
  1483. begin
  1484. exclude(init_settings.globalswitches,cs_link_staticflag);
  1485. exclude(init_settings.globalswitches,cs_link_strip);
  1486. exclude(init_settings.globalswitches,cs_link_map);
  1487. set_default_link_type;
  1488. end;
  1489. else
  1490. IllegalPara(opt);
  1491. end;
  1492. inc(j);
  1493. end;
  1494. end;
  1495. end;
  1496. end;
  1497. '@' :
  1498. begin
  1499. Message(option_no_nested_response_file);
  1500. StopOptions(1);
  1501. end;
  1502. else
  1503. begin
  1504. if (length(param_file)<>0) then
  1505. Message(option_only_one_source_support);
  1506. param_file:=opt;
  1507. Message1(option_found_file,opt);
  1508. end;
  1509. end;
  1510. end;
  1511. procedure Toption.Interpret_file(const filename : string);
  1512. procedure RemoveSep(var fn:string);
  1513. var
  1514. i : longint;
  1515. begin
  1516. i:=0;
  1517. while (i<length(fn)) and (fn[i+1] in [',',' ',#9]) do
  1518. inc(i);
  1519. Delete(fn,1,i);
  1520. i:=length(fn);
  1521. while (i>0) and (fn[i] in [',',' ',#9]) do
  1522. dec(i);
  1523. fn:=copy(fn,1,i);
  1524. end;
  1525. function GetName(var fn:string):string;
  1526. var
  1527. i : longint;
  1528. begin
  1529. i:=0;
  1530. while (i<length(fn)) and (fn[i+1] in ['a'..'z','A'..'Z','0'..'9','_','-']) do
  1531. inc(i);
  1532. GetName:=Copy(fn,1,i);
  1533. Delete(fn,1,i);
  1534. end;
  1535. const
  1536. maxlevel=16;
  1537. var
  1538. f : text;
  1539. s, tmp,
  1540. opts : string;
  1541. skip : array[0..maxlevel-1] of boolean;
  1542. level : longint;
  1543. option_read : boolean;
  1544. begin
  1545. { avoid infinite loop }
  1546. Inc(FileLevel);
  1547. Option_read:=false;
  1548. If FileLevel>MaxLevel then
  1549. Message(option_too_many_cfg_files);
  1550. { Maybe It's Directory ?} //Jaro Change:
  1551. if PathExists(filename,false) then
  1552. begin
  1553. Message1(option_config_is_dir,filename);
  1554. exit;
  1555. end;
  1556. { open file }
  1557. Message1(option_using_file,filename);
  1558. assign(f,ExpandFileName(filename));
  1559. {$I-}
  1560. reset(f);
  1561. {$I+}
  1562. if ioresult<>0 then
  1563. begin
  1564. Message1(option_unable_open_file,filename);
  1565. exit;
  1566. end;
  1567. Message1(option_start_reading_configfile,filename);
  1568. fillchar(skip,sizeof(skip),0);
  1569. level:=0;
  1570. while not eof(f) do
  1571. begin
  1572. readln(f,opts);
  1573. RemoveSep(opts);
  1574. if (opts<>'') and (opts[1]<>';') then
  1575. begin
  1576. if opts[1]='#' then
  1577. begin
  1578. Message1(option_interpreting_file_option,opts);
  1579. Delete(opts,1,1);
  1580. s:=upper(GetName(opts));
  1581. if (s='SECTION') then
  1582. begin
  1583. RemoveSep(opts);
  1584. s:=upper(GetName(opts));
  1585. if level=0 then
  1586. skip[level]:=not defined_macro(s) or (s='COMMON');
  1587. end
  1588. else
  1589. if (s='IFDEF') then
  1590. begin
  1591. RemoveSep(opts);
  1592. if Level>=maxlevel then
  1593. begin
  1594. Message(option_too_many_ifdef);
  1595. stopOptions(1);
  1596. end;
  1597. inc(Level);
  1598. skip[level]:=(skip[level-1] or not defined_macro(upper(GetName(opts))));
  1599. end
  1600. else
  1601. if (s='IFNDEF') then
  1602. begin
  1603. RemoveSep(opts);
  1604. if Level>=maxlevel then
  1605. begin
  1606. Message(option_too_many_ifdef);
  1607. stopOptions(1);
  1608. end;
  1609. inc(Level);
  1610. skip[level]:=(skip[level-1] or defined_macro(upper(GetName(opts))));
  1611. end
  1612. else
  1613. if (s='ELSE') then
  1614. skip[level]:=skip[level-1] or (not skip[level])
  1615. else
  1616. if (s='ENDIF') then
  1617. begin
  1618. skip[level]:=false;
  1619. if Level=0 then
  1620. begin
  1621. Message(option_too_many_endif);
  1622. stopOptions(1);
  1623. end;
  1624. dec(level);
  1625. end
  1626. else
  1627. if (not skip[level]) then
  1628. begin
  1629. if (s='DEFINE') then
  1630. begin
  1631. RemoveSep(opts);
  1632. tmp:= GetName(opts);
  1633. if tmp <> '' then
  1634. def_system_macro(tmp);
  1635. end
  1636. else
  1637. if (s='UNDEF') then
  1638. begin
  1639. RemoveSep(opts);
  1640. tmp:= GetName(opts);
  1641. if tmp <> '' then
  1642. undef_system_macro(tmp);
  1643. end
  1644. else
  1645. if (s='WRITE') then
  1646. begin
  1647. Delete(opts,1,1);
  1648. WriteLn(opts);
  1649. end
  1650. else
  1651. if (s='INCLUDE') then
  1652. begin
  1653. Delete(opts,1,1);
  1654. Interpret_file(opts);
  1655. end;
  1656. end;
  1657. end
  1658. else
  1659. begin
  1660. if (opts[1]='-') or (opts[1]='@') then
  1661. begin
  1662. if (not skip[level]) then
  1663. interpret_option(opts,false);
  1664. Option_read:=true;
  1665. end
  1666. else
  1667. Message1(option_illegal_para,opts);
  1668. end;
  1669. end;
  1670. end;
  1671. if Level>0 then
  1672. Message(option_too_less_endif);
  1673. if Not Option_read then
  1674. Message1(option_no_option_found,filename)
  1675. else
  1676. Message1(option_end_reading_configfile,filename);
  1677. Close(f);
  1678. Dec(FileLevel);
  1679. end;
  1680. procedure Toption.Interpret_envvar(const envname : string);
  1681. var
  1682. argstart,
  1683. env,
  1684. pc : pchar;
  1685. arglen : longint;
  1686. quote : set of char;
  1687. hs : string;
  1688. begin
  1689. Message1(option_using_env,envname);
  1690. env:=GetEnvPChar(envname);
  1691. pc:=env;
  1692. if assigned(pc) then
  1693. begin
  1694. repeat
  1695. { skip leading spaces }
  1696. while pc^ in [' ',#9,#13] do
  1697. inc(pc);
  1698. case pc^ of
  1699. #0 :
  1700. break;
  1701. '"' :
  1702. begin
  1703. quote:=['"'];
  1704. inc(pc);
  1705. end;
  1706. '''' :
  1707. begin
  1708. quote:=[''''];
  1709. inc(pc);
  1710. end;
  1711. else
  1712. quote:=[' ',#9,#13];
  1713. end;
  1714. { scan until the end of the argument }
  1715. argstart:=pc;
  1716. while (pc^<>#0) and not(pc^ in quote) do
  1717. inc(pc);
  1718. { create argument }
  1719. arglen:=pc-argstart;
  1720. { TODO: FIXME: silent truncation of environment parameters }
  1721. if (arglen > 255) then
  1722. arglen := 255;
  1723. setlength(hs,arglen);
  1724. move(argstart^,hs[1],arglen);
  1725. interpret_option(hs,true);
  1726. { skip quote }
  1727. if pc^ in quote then
  1728. inc(pc);
  1729. until false;
  1730. end
  1731. else
  1732. Message1(option_no_option_found,'(env) '+envname);
  1733. FreeEnvPChar(env);
  1734. end;
  1735. procedure toption.read_parameters;
  1736. var
  1737. opts : string;
  1738. paramindex : longint;
  1739. begin
  1740. paramindex:=0;
  1741. while paramindex<paramcount do
  1742. begin
  1743. inc(paramindex);
  1744. opts:=system.paramstr(paramindex);
  1745. case opts[1] of
  1746. '@' :
  1747. if not firstpass then
  1748. begin
  1749. Delete(opts,1,1);
  1750. Message1(option_reading_further_from,opts);
  1751. interpret_file(opts);
  1752. end;
  1753. '!' :
  1754. if not firstpass then
  1755. begin
  1756. Delete(opts,1,1);
  1757. Message1(option_reading_further_from,'(env) '+opts);
  1758. interpret_envvar(opts);
  1759. end;
  1760. else
  1761. interpret_option(opts,true);
  1762. end;
  1763. end;
  1764. end;
  1765. procedure toption.parsecmd(cmd:string);
  1766. var
  1767. i,ps : longint;
  1768. opts : string;
  1769. begin
  1770. while (cmd<>'') do
  1771. begin
  1772. while cmd[1]=' ' do
  1773. delete(cmd,1,1);
  1774. i:=pos(' ',cmd);
  1775. if i=0 then
  1776. i:=256;
  1777. opts:=Copy(cmd,1,i-1);
  1778. Delete(cmd,1,i);
  1779. case opts[1] of
  1780. '@' :
  1781. if not firstpass then
  1782. begin
  1783. Delete(opts,1,1);
  1784. Message1(option_reading_further_from,opts);
  1785. interpret_file(opts);
  1786. end;
  1787. '!' :
  1788. if not firstpass then
  1789. begin
  1790. Delete(opts,1,1);
  1791. Message1(option_reading_further_from,'(env) '+opts);
  1792. interpret_envvar(opts);
  1793. end;
  1794. '"' :
  1795. begin
  1796. Delete(opts,1,1);
  1797. ps:=pos('"',cmd);
  1798. if (i<>256) and (ps>0) then
  1799. begin
  1800. opts:=opts + ' '+ copy(cmd,1,ps-1);
  1801. cmd:=copy(cmd,ps+1,255);
  1802. end;
  1803. interpret_option(opts,true);
  1804. end;
  1805. else
  1806. interpret_option(opts,true);
  1807. end;
  1808. end;
  1809. end;
  1810. procedure toption.writequickinfo;
  1811. var
  1812. s : string;
  1813. i : longint;
  1814. procedure addinfo(const hs:string);
  1815. begin
  1816. if s<>'' then
  1817. s:=s+' '+hs
  1818. else
  1819. s:=hs;
  1820. end;
  1821. begin
  1822. s:='';
  1823. i:=0;
  1824. while (i<length(quickinfo)) do
  1825. begin
  1826. inc(i);
  1827. case quickinfo[i] of
  1828. 'S' :
  1829. begin
  1830. inc(i);
  1831. case quickinfo[i] of
  1832. 'O' :
  1833. addinfo(lower(source_info.shortname));
  1834. 'P' :
  1835. addinfo(source_cpu_string);
  1836. else
  1837. IllegalPara('-i'+QuickInfo);
  1838. end;
  1839. end;
  1840. 'T' :
  1841. begin
  1842. inc(i);
  1843. case quickinfo[i] of
  1844. 'O' :
  1845. addinfo(lower(target_info.shortname));
  1846. 'P' :
  1847. AddInfo(target_cpu_string);
  1848. else
  1849. IllegalPara('-i'+QuickInfo);
  1850. end;
  1851. end;
  1852. 'V' :
  1853. AddInfo(version_string);
  1854. 'W' :
  1855. AddInfo(full_version_string);
  1856. 'D' :
  1857. AddInfo(date_string);
  1858. '_' :
  1859. ;
  1860. else
  1861. IllegalPara('-i'+QuickInfo);
  1862. end;
  1863. end;
  1864. if s<>'' then
  1865. begin
  1866. writeln(s);
  1867. stopoptions(0);
  1868. end;
  1869. end;
  1870. procedure TOption.TargetOptions(def:boolean);
  1871. var
  1872. s : string;
  1873. i : integer;
  1874. target_unsup_features : tfeatures;
  1875. begin
  1876. if def then
  1877. def_system_macro(target_info.shortname)
  1878. else
  1879. undef_system_macro(target_info.shortname);
  1880. s:=target_info.extradefines;
  1881. while (s<>'') do
  1882. begin
  1883. i:=pos(';',s);
  1884. if i=0 then
  1885. i:=length(s)+1;
  1886. if def then
  1887. def_system_macro(Copy(s,1,i-1))
  1888. else
  1889. undef_system_macro(Copy(s,1,i-1));
  1890. delete(s,1,i);
  1891. end;
  1892. if (tf_winlikewidestring in target_info.flags) then
  1893. if def then
  1894. def_system_macro('FPC_WINLIKEWIDESTRING')
  1895. else
  1896. undef_system_macro('FPC_WINLIKEWIDESTRING');
  1897. if (tf_requires_proper_alignment in target_info.flags) then
  1898. if def then
  1899. def_system_macro('FPC_REQUIRES_PROPER_ALIGNMENT')
  1900. else
  1901. undef_system_macro('FPC_REQUIRES_PROPER_ALIGNMENT');
  1902. if source_info.system<>target_info.system then
  1903. if def then
  1904. def_system_macro('FPC_CROSSCOMPILING')
  1905. else
  1906. undef_system_macro('FPC_CROSSCOMPILING');
  1907. if source_info.cpu<>target_info.cpu then
  1908. if def then
  1909. def_system_macro('FPC_CPUCROSSCOMPILING')
  1910. else
  1911. def_system_macro('FPC_CPUCROSSCOMPILING');
  1912. if (tf_no_generic_stackcheck in target_info.flags) then
  1913. if def then
  1914. def_system_macro('FPC_NO_GENERIC_STACK_CHECK')
  1915. else
  1916. undef_system_macro('FPC_NO_GENERIC_STACK_CHECK');
  1917. { Code generation flags }
  1918. if def and
  1919. (tf_pic_default in target_info.flags) then
  1920. include(init_settings.moduleswitches,cs_create_pic)
  1921. else
  1922. exclude(init_settings.moduleswitches,cs_create_pic);
  1923. { Resources support }
  1924. if (tf_has_winlike_resources in target_info.flags) then
  1925. if def then
  1926. def_system_macro('FPC_HAS_WINLIKERESOURCES')
  1927. else
  1928. undef_system_macro('FPC_HAS_WINLIKERESOURCES');
  1929. { Features }
  1930. case target_info.system of
  1931. system_arm_gba:
  1932. target_unsup_features:=[f_threading,f_commandargs,f_fileio,f_textio,f_consoleio,f_dynlibs];
  1933. system_arm_nds:
  1934. target_unsup_features:=[f_threading,f_commandargs,f_fileio,f_textio,f_consoleio,f_dynlibs]
  1935. else
  1936. target_unsup_features:=[];
  1937. end;
  1938. if def then
  1939. features:=features-target_unsup_features
  1940. else
  1941. features:=features+target_unsup_features;
  1942. end;
  1943. constructor TOption.create;
  1944. begin
  1945. LogoWritten:=false;
  1946. NoPressEnter:=false;
  1947. FirstPass:=false;
  1948. FileLevel:=0;
  1949. Quickinfo:='';
  1950. ParaIncludePath:=TSearchPathList.Create;
  1951. ParaObjectPath:=TSearchPathList.Create;
  1952. ParaUnitPath:=TSearchPathList.Create;
  1953. ParaLibraryPath:=TSearchPathList.Create;
  1954. ParaFrameworkPath:=TSearchPathList.Create;
  1955. FillChar(ParaAlignment,sizeof(ParaAlignment),0);
  1956. end;
  1957. destructor TOption.destroy;
  1958. begin
  1959. ParaIncludePath.Free;
  1960. ParaObjectPath.Free;
  1961. ParaUnitPath.Free;
  1962. ParaLibraryPath.Free;
  1963. ParaFrameworkPath.Free;
  1964. end;
  1965. {****************************************************************************
  1966. Callable Routines
  1967. ****************************************************************************}
  1968. function check_configfile(const fn:string;var foundfn:string):boolean;
  1969. function CfgFileExists(const fn:string):boolean;
  1970. begin
  1971. Comment(V_Tried,'Configfile search: '+fn);
  1972. CfgFileExists:=FileExists(fn);
  1973. end;
  1974. var
  1975. {$ifdef Unix}
  1976. hs,
  1977. {$endif Unix}
  1978. configpath : string;
  1979. begin
  1980. foundfn:=fn;
  1981. check_configfile:=true;
  1982. { retrieve configpath }
  1983. configpath:=FixPath(GetEnvironmentVariable('PPC_CONFIG_PATH'),false);
  1984. {$ifdef Unix}
  1985. if configpath='' then
  1986. configpath:=ExpandFileName(FixPath(exepath+'../etc/',false));
  1987. {$endif}
  1988. {
  1989. Order to read configuration file :
  1990. try reading fpc.cfg in :
  1991. 1 - current dir
  1992. 2 - configpath
  1993. 3 - compiler path
  1994. }
  1995. if not FileExists(fn) then
  1996. begin
  1997. {$ifdef Unix}
  1998. hs:=GetEnvironmentVariable('HOME');
  1999. if (hs<>'') and CfgFileExists(FixPath(hs,false)+'.'+fn) then
  2000. foundfn:=FixPath(hs,false)+'.'+fn
  2001. else
  2002. {$endif}
  2003. if CfgFileExists(configpath+fn) then
  2004. foundfn:=configpath+fn
  2005. else
  2006. {$ifndef Unix}
  2007. if CfgFileExists(exepath+fn) then
  2008. foundfn:=exepath+fn
  2009. else
  2010. {$else}
  2011. if CfgFileExists('/etc/'+fn) then
  2012. foundfn:='/etc/'+fn
  2013. else
  2014. {$endif}
  2015. check_configfile:=false;
  2016. end;
  2017. end;
  2018. procedure read_arguments(cmd:string);
  2019. var
  2020. env: ansistring;
  2021. i : tfeature;
  2022. abi : tabi;
  2023. begin
  2024. option:=coption.create;
  2025. disable_configfile:=false;
  2026. { Non-core target defines }
  2027. Option.TargetOptions(true);
  2028. { get default messagefile }
  2029. msgfilename:=GetEnvironmentVariable('PPC_ERROR_FILE');
  2030. { default configfile can be specified on the commandline,
  2031. remove it first }
  2032. if (cmd<>'') and (cmd[1]='[') then
  2033. begin
  2034. ppccfg:=Copy(cmd,2,pos(']',cmd)-2);
  2035. Delete(cmd,1,pos(']',cmd));
  2036. end
  2037. else
  2038. begin
  2039. ppccfg:='fpc.cfg';
  2040. ppcaltcfg:='ppc386.cfg';
  2041. end;
  2042. { first pass reading of parameters, only -i -v -T etc.}
  2043. option.firstpass:=true;
  2044. if cmd<>'' then
  2045. option.parsecmd(cmd)
  2046. else
  2047. begin
  2048. option.read_parameters;
  2049. { Write only quickinfo }
  2050. if option.quickinfo<>'' then
  2051. option.writequickinfo;
  2052. end;
  2053. option.firstpass:=false;
  2054. { target is set here, for wince the default app type is gui }
  2055. if target_info.system in system_wince then
  2056. apptype:=app_gui;
  2057. { default defines }
  2058. def_system_macro(target_info.shortname);
  2059. def_system_macro('FPC');
  2060. def_system_macro('VER'+version_nr);
  2061. def_system_macro('VER'+version_nr+'_'+release_nr);
  2062. def_system_macro('VER'+version_nr+'_'+release_nr+'_'+patch_nr);
  2063. { Temporary defines, until things settle down }
  2064. { "main" symbol is generated in the main program, and left out of the system unit }
  2065. def_system_macro('FPC_DARWIN_PASCALMAIN');
  2066. def_system_macro('FPC_DARWIN_JMP_MAIN');
  2067. def_system_macro('PARAOUTFILE');
  2068. def_system_macro('RESSTRSECTIONS');
  2069. def_system_macro('FPC_HASFIXED64BITVARIANT');
  2070. def_system_macro('FPC_HASINTERNALOLEVARIANT2VARIANTCAST');
  2071. def_system_macro('FPC_HAS_VARSETS');
  2072. def_system_macro('FPC_HAS_VALGRINDBOOL');
  2073. def_system_macro('FPC_HAS_STR_CURRENCY');
  2074. def_system_macro('FPC_REAL2REAL_FIXED');
  2075. def_system_macro('FPC_STRTOCHARARRAYPROC');
  2076. def_system_macro('FPC_NEW_BIGENDIAN_SETS');
  2077. def_system_macro('FPC_STRTOSHORTSTRINGPROC');
  2078. def_system_macro('FPC_OBJFPC_EXTENDED_IF');
  2079. {$if defined(x86) or defined(powerpc) or defined(powerpc64)}
  2080. def_system_macro('FPC_HAS_INTERNAL_ABS_LONG');
  2081. {$endif}
  2082. { these cpus have an inline rol/ror implementaion }
  2083. {$if defined(x86) or defined(arm)}
  2084. def_system_macro('FPC_HAS_INTERNAL_ROX');
  2085. {$endif}
  2086. {$ifdef SUPPORT_UNALIGNED}
  2087. def_system_macro('FPC_SUPPORTS_UNALIGNED');
  2088. def_system_macro('FPC_UNALIGNED_FIXED');
  2089. {$endif SUPPORT_UNALIGNED}
  2090. {$ifdef powerpc64}
  2091. def_system_macro('FPC_HAS_LWSYNC');
  2092. {$endif}
  2093. def_system_macro('FPC_HAS_MEMBAR');
  2094. def_system_macro('FPC_SETBASE_USED');
  2095. {$if defined(x86) or defined(arm)}
  2096. def_system_macro('INTERNAL_BACKTRACE');
  2097. {$endif}
  2098. def_system_macro('STR_CONCAT_PROCS');
  2099. {$warnings off}
  2100. if pocall_default = pocall_register then
  2101. def_system_macro('REGCALL');
  2102. {$warnings on}
  2103. { don't remove this, it's also for fpdoc necessary (FK) }
  2104. def_system_macro('FPC_HAS_FEATURE_SUPPORT');
  2105. { using a case is pretty useless here (FK) }
  2106. { some stuff for TP compatibility }
  2107. {$ifdef i386}
  2108. def_system_macro('CPU86');
  2109. def_system_macro('CPU87');
  2110. def_system_macro('CPU386');
  2111. {$endif}
  2112. { new processor stuff }
  2113. {$ifdef i386}
  2114. def_system_macro('CPUI386');
  2115. def_system_macro('CPU32');
  2116. def_system_macro('FPC_HAS_TYPE_EXTENDED');
  2117. def_system_macro('FPC_HAS_TYPE_DOUBLE');
  2118. def_system_macro('FPC_HAS_TYPE_SINGLE');
  2119. {$endif}
  2120. {$ifdef m68k}
  2121. def_system_macro('CPU68');
  2122. def_system_macro('CPU68K');
  2123. def_system_macro('CPUM68K');
  2124. def_system_macro('CPU32');
  2125. def_system_macro('FPC_CURRENCY_IS_INT64');
  2126. def_system_macro('FPC_COMP_IS_INT64');
  2127. {$endif}
  2128. {$ifdef ALPHA}
  2129. def_system_macro('CPUALPHA');
  2130. def_system_macro('CPU64');
  2131. {$endif}
  2132. {$ifdef powerpc}
  2133. def_system_macro('CPUPOWERPC');
  2134. def_system_macro('CPUPOWERPC32');
  2135. def_system_macro('CPU32');
  2136. def_system_macro('FPC_CURRENCY_IS_INT64');
  2137. def_system_macro('FPC_COMP_IS_INT64');
  2138. {$endif}
  2139. {$ifdef POWERPC64}
  2140. def_system_macro('CPUPOWERPC');
  2141. def_system_macro('CPUPOWERPC64');
  2142. def_system_macro('CPU64');
  2143. def_system_macro('FPC_CURRENCY_IS_INT64');
  2144. def_system_macro('FPC_COMP_IS_INT64');
  2145. {$endif}
  2146. {$ifdef iA64}
  2147. def_system_macro('CPUIA64');
  2148. def_system_macro('CPU64');
  2149. {$endif}
  2150. {$ifdef x86_64}
  2151. def_system_macro('CPUX86_64');
  2152. def_system_macro('CPUAMD64');
  2153. def_system_macro('CPU64');
  2154. { not supported for now, afaik (FK)
  2155. def_system_macro('FPC_HAS_TYPE_FLOAT128'); }
  2156. { win64 doesn't support the legacy fpu }
  2157. if target_info.system=system_x86_64_win64 then
  2158. begin
  2159. def_system_macro('FPC_CURRENCY_IS_INT64');
  2160. def_system_macro('FPC_COMP_IS_INT64');
  2161. end;
  2162. {$endif}
  2163. {$ifdef sparc}
  2164. def_system_macro('CPUSPARC');
  2165. def_system_macro('CPUSPARC32');
  2166. def_system_macro('CPU32');
  2167. def_system_macro('FPC_CURRENCY_IS_INT64');
  2168. def_system_macro('FPC_COMP_IS_INT64');
  2169. {$endif}
  2170. {$ifdef vis}
  2171. def_system_macro('CPUVIS');
  2172. def_system_macro('CPU32');
  2173. {$endif}
  2174. {$ifdef arm}
  2175. def_system_macro('CPUARM');
  2176. def_system_macro('CPU32');
  2177. def_system_macro('FPC_CURRENCY_IS_INT64');
  2178. def_system_macro('FPC_COMP_IS_INT64');
  2179. {$endif arm}
  2180. {$ifdef avr}
  2181. def_system_macro('CPUAVR');
  2182. def_system_macro('CPU16');
  2183. def_system_macro('FPC_CURRENCY_IS_INT64');
  2184. def_system_macro('FPC_COMP_IS_INT64');
  2185. {$endif avr}
  2186. { read configuration file }
  2187. if (not disable_configfile) and
  2188. (ppccfg<>'') then
  2189. begin
  2190. read_configfile:=check_configfile(ppccfg,ppccfg);
  2191. { Maybe alternative configfile ? }
  2192. if (not read_configfile) and
  2193. (ppcaltcfg<>'') then
  2194. begin
  2195. read_configfile:=check_configfile(ppcaltcfg,ppccfg);
  2196. if read_configfile then
  2197. message(option_ppc386_deprecated);
  2198. end;
  2199. end
  2200. else
  2201. read_configfile := false;
  2202. { Read commandline and configfile }
  2203. param_file:='';
  2204. { read configfile }
  2205. if read_configfile then
  2206. option.interpret_file(ppccfg);
  2207. { read parameters again to override config file }
  2208. if cmd<>'' then
  2209. option.parsecmd(cmd)
  2210. else
  2211. begin
  2212. { Write help pages if no parameters are passed }
  2213. if (paramcount=0) then
  2214. Option.WriteHelpPages;
  2215. option.read_parameters;
  2216. { Write only quickinfo }
  2217. if option.quickinfo<>'' then
  2218. option.writequickinfo;
  2219. end;
  2220. { Stop if errors in options }
  2221. if ErrorCount>0 then
  2222. StopOptions(1);
  2223. { endian define }
  2224. case target_info.endian of
  2225. endian_little :
  2226. begin
  2227. def_system_macro('ENDIAN_LITTLE');
  2228. def_system_macro('FPC_LITTLE_ENDIAN');
  2229. end;
  2230. endian_big :
  2231. begin
  2232. def_system_macro('ENDIAN_BIG');
  2233. def_system_macro('FPC_BIG_ENDIAN');
  2234. end;
  2235. end;
  2236. { define abi }
  2237. for abi:=low(tabi) to high(tabi) do
  2238. undef_system_macro('FPC_ABI_'+abi2str[abi]);
  2239. def_system_macro('FPC_ABI_'+abi2str[target_info.abi]);
  2240. { Write logo }
  2241. if option.ParaLogo then
  2242. option.writelogo;
  2243. { Check file to compile }
  2244. if param_file='' then
  2245. begin
  2246. Message(option_no_source_found);
  2247. StopOptions(1);
  2248. end;
  2249. {$ifndef Unix}
  2250. param_file:=FixFileName(param_file);
  2251. {$endif not unix}
  2252. inputfilepath:=ExtractFilePath(param_file);
  2253. inputfilename:=ExtractFileName(param_file);
  2254. if ExtractFileExt(inputfilename)='' then
  2255. begin
  2256. if FileExists(inputfilepath+ChangeFileExt(inputfilename,sourceext)) then
  2257. inputfilename:=ChangeFileExt(inputfilename,sourceext)
  2258. else if FileExists(inputfilepath+ChangeFileExt(inputfilename,pasext)) then
  2259. inputfilename:=ChangeFileExt(inputfilename,pasext)
  2260. else if ((m_mac in current_settings.modeswitches) or
  2261. (tf_p_ext_support in target_info.flags))
  2262. and FileExists(inputfilepath+ChangeFileExt(inputfilename,pext)) then
  2263. inputfilename:=ChangeFileExt(inputfilename,pext);
  2264. end;
  2265. { Check output dir }
  2266. if (OutputExeDir<>'') and
  2267. not PathExists(OutputExeDir,false) then
  2268. begin
  2269. Message1(general_e_path_does_not_exist,OutputExeDir);
  2270. StopOptions(1);
  2271. end;
  2272. { Add paths specified with parameters to the searchpaths }
  2273. UnitSearchPath.AddList(option.ParaUnitPath,true);
  2274. ObjectSearchPath.AddList(option.ParaObjectPath,true);
  2275. IncludeSearchPath.AddList(option.ParaIncludePath,true);
  2276. LibrarySearchPath.AddList(option.ParaLibraryPath,true);
  2277. FrameworkSearchPath.AddList(option.ParaFrameworkPath,true);
  2278. { add unit environment and exepath to the unit search path }
  2279. if inputfilepath<>'' then
  2280. Unitsearchpath.AddPath(inputfilepath,true);
  2281. if not disable_configfile then
  2282. begin
  2283. env:=GetEnvironmentVariable(target_info.unit_env);
  2284. if env<>'' then
  2285. UnitSearchPath.AddPath(GetEnvironmentVariable(target_info.unit_env),false);
  2286. end;
  2287. {$ifdef Unix}
  2288. fpcdir:=FixPath(GetEnvironmentVariable('FPCDIR'),false);
  2289. if fpcdir='' then
  2290. begin
  2291. if PathExists('/usr/local/lib/fpc/'+version_string,true) then
  2292. fpcdir:='/usr/local/lib/fpc/'+version_string+'/'
  2293. else
  2294. fpcdir:='/usr/lib/fpc/'+version_string+'/';
  2295. end;
  2296. {$else unix}
  2297. fpcdir:=FixPath(GetEnvironmentVariable('FPCDIR'),false);
  2298. if fpcdir='' then
  2299. begin
  2300. fpcdir:=ExePath+'../';
  2301. if not(PathExists(fpcdir+'units',true)) and
  2302. not(PathExists(fpcdir+'rtl',true)) then
  2303. fpcdir:=fpcdir+'../';
  2304. end;
  2305. {$endif unix}
  2306. { first try development RTL, else use the default installation path }
  2307. if not disable_configfile then
  2308. begin
  2309. if PathExists(FpcDir+'rtl',true) then
  2310. if tf_use_8_3 in Source_Info.Flags then
  2311. UnitSearchPath.AddPath(FpcDir+'rtl/'+target_os_string,false)
  2312. else
  2313. UnitSearchPath.AddPath(FpcDir+'rtl/'+target_full_string,false)
  2314. else
  2315. if tf_use_8_3 in Source_Info.Flags then
  2316. UnitSearchPath.AddPath(FpcDir+'units/'+target_os_string+'/rtl',false)
  2317. else
  2318. UnitSearchPath.AddPath(FpcDir+'units/'+target_full_string+'/rtl',false);
  2319. end;
  2320. { Add exepath if the exe is not in the current dir, because that is always searched already.
  2321. Do not add it when linking on the target because then we can maybe already find
  2322. .o files that are not for the target }
  2323. if (ExePath<>GetCurrentDir) and
  2324. not(cs_link_on_target in init_settings.globalswitches) then
  2325. UnitSearchPath.AddPath(ExePath,false);
  2326. { Add unit dir to the object and library path }
  2327. objectsearchpath.AddList(unitsearchpath,false);
  2328. librarysearchpath.AddList(unitsearchpath,false);
  2329. { maybe override assembler }
  2330. if (paratargetasm<>as_none) then
  2331. begin
  2332. if not set_target_asm(paratargetasm) then
  2333. begin
  2334. Message2(option_incompatible_asm,asminfos[paratargetasm]^.idtxt,target_info.name);
  2335. set_target_asm(target_info.assemextern);
  2336. Message1(option_asm_forced,target_asm.idtxt);
  2337. end;
  2338. if (af_no_debug in asminfos[paratargetasm]^.flags) and
  2339. (paratargetdbg<>dbg_none) then
  2340. begin
  2341. Message1(option_confict_asm_debug,
  2342. asminfos[paratargetasm]^.idtxt);
  2343. paratargetdbg:=dbg_none;
  2344. exclude(init_settings.moduleswitches,cs_debuginfo);
  2345. end;
  2346. end;
  2347. { maybe override debug info format }
  2348. if (paratargetdbg<>dbg_none) then
  2349. set_target_dbg(paratargetdbg);
  2350. { switch assembler if it's binary and we got -a on the cmdline }
  2351. if (cs_asm_leave in init_settings.globalswitches) and
  2352. (af_outputbinary in target_asm.flags) then
  2353. begin
  2354. Message(option_switch_bin_to_src_assembler);
  2355. set_target_asm(target_info.assemextern);
  2356. end;
  2357. { Force use of external linker if there is no
  2358. internal linker or the linking is skipped }
  2359. if not(cs_link_extern in init_settings.globalswitches) and
  2360. (not assigned(target_info.link) or
  2361. (cs_link_nolink in init_settings.globalswitches)) then
  2362. include(init_settings.globalswitches,cs_link_extern);
  2363. { turn off stripping if compiling with debuginfo or profile }
  2364. if (
  2365. (cs_debuginfo in init_settings.moduleswitches) or
  2366. (cs_profile in init_settings.moduleswitches)
  2367. ) and
  2368. not(cs_link_separate_dbg_file in init_settings.globalswitches) then
  2369. exclude(init_settings.globalswitches,cs_link_strip);
  2370. { force fpu emulation on arm/wince, arm/gba and arm/nds}
  2371. if (target_info.system in [system_arm_wince,system_arm_gba,system_m68k_amiga,
  2372. system_m68k_linux,system_arm_nds])
  2373. {$ifdef arm}
  2374. or (init_settings.fputype=fpu_soft)
  2375. or (target_info.abi=abi_eabi)
  2376. {$endif arm}
  2377. then
  2378. begin
  2379. {$ifdef cpufpemu}
  2380. include(init_settings.moduleswitches,cs_fp_emulation);
  2381. { cs_fp_emulation and fpu_soft are equal on arm }
  2382. init_settings.fputype:=fpu_soft;
  2383. {$endif cpufpemu}
  2384. end;
  2385. { now we can define cpu and fpu type }
  2386. def_system_macro('CPU'+Cputypestr[init_settings.cputype]);
  2387. def_system_macro('FPU'+fputypestr[init_settings.fputype]);
  2388. if init_settings.fputype<>fpu_none then
  2389. begin
  2390. {$if defined(i386)}
  2391. def_system_macro('FPC_HAS_TYPE_EXTENDED');
  2392. {$endif}
  2393. def_system_macro('FPC_HAS_TYPE_SINGLE');
  2394. def_system_macro('FPC_HAS_TYPE_DOUBLE');
  2395. {$if not defined(i386) and not defined(x86_64)}
  2396. def_system_macro('FPC_INCLUDE_SOFTWARE_INT64_TO_DOUBLE');
  2397. {$endif}
  2398. {$ifdef x86_64}
  2399. { win64 doesn't support the legacy fpu }
  2400. if target_info.system=system_x86_64_win64 then
  2401. undef_system_macro('FPC_HAS_TYPE_EXTENDED')
  2402. else
  2403. def_system_macro('FPC_HAS_TYPE_EXTENDED');
  2404. {$endif}
  2405. end;
  2406. {$ifdef ARM}
  2407. { define FPC_DOUBLE_HILO_SWAPPED if needed to properly handle doubles in RTL }
  2408. if (init_settings.fputype in [fpu_fpa,fpu_fpa10,fpu_fpa11]) and
  2409. not(cs_fp_emulation in init_settings.moduleswitches) then
  2410. def_system_macro('FPC_DOUBLE_HILO_SWAPPED');
  2411. {$endif ARM}
  2412. { Section smartlinking conflicts with import sections on Windows }
  2413. if GenerateImportSection and
  2414. (target_info.system in [system_i386_win32,system_x86_64_win64]) then
  2415. exclude(target_info.flags,tf_smartlink_sections);
  2416. if not LinkTypeSetExplicitly then
  2417. set_default_link_type;
  2418. { Default alignment settings,
  2419. 1. load the defaults for the target
  2420. 2. override with generic optimizer setting (little size)
  2421. 3. override with the user specified -Oa }
  2422. UpdateAlignment(init_settings.alignment,target_info.alignment);
  2423. if (cs_opt_size in current_settings.optimizerswitches) then
  2424. begin
  2425. init_settings.alignment.procalign:=1;
  2426. init_settings.alignment.jumpalign:=1;
  2427. init_settings.alignment.loopalign:=1;
  2428. end;
  2429. UpdateAlignment(init_settings.alignment,option.paraalignment);
  2430. set_system_macro('FPC_VERSION',version_nr);
  2431. set_system_macro('FPC_RELEASE',release_nr);
  2432. set_system_macro('FPC_PATCH',patch_nr);
  2433. for i:=low(tfeature) to high(tfeature) do
  2434. if i in features then
  2435. def_system_macro('FPC_HAS_FEATURE_'+featurestr[i]);
  2436. option.free;
  2437. Option:=nil;
  2438. end;
  2439. initialization
  2440. coption:=toption;
  2441. finalization
  2442. if assigned(option) then
  2443. option.free;
  2444. end.