options.pas 77 KB

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