options.pas 79 KB

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