options.pas 76 KB

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