options.pas 73 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322
  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. 's' :
  747. begin
  748. paratargetdbg:=dbg_stabs;
  749. end;
  750. 't' :
  751. begin
  752. if UnsetBool(More, j) then
  753. localvartrashing := -1
  754. else
  755. localvartrashing := (localvartrashing + 1) mod nroftrashvalues;
  756. end;
  757. 'v' :
  758. begin
  759. if UnsetBool(More, j) then
  760. exclude(init_settings.globalswitches,cs_gdb_valgrind)
  761. else
  762. include(init_settings.globalswitches,cs_gdb_valgrind);
  763. end;
  764. 'w' :
  765. begin
  766. if (j<length(more)) and (more[j+1] in ['2','3']) then
  767. begin
  768. case more[j+1] of
  769. '2': paratargetdbg:=dbg_dwarf2;
  770. '3': paratargetdbg:=dbg_dwarf3;
  771. end;
  772. inc(j);
  773. end
  774. else
  775. paratargetdbg:=dbg_dwarf2;
  776. end;
  777. else
  778. IllegalPara(opt);
  779. end;
  780. inc(j);
  781. end;
  782. end;
  783. 'h' :
  784. begin
  785. NoPressEnter:=true;
  786. WriteHelpPages;
  787. end;
  788. 'i' :
  789. begin
  790. if More='' then
  791. WriteInfo
  792. else
  793. QuickInfo:=QuickInfo+More;
  794. end;
  795. 'I' :
  796. begin
  797. if ispara then
  798. ParaIncludePath.AddPath(More,false)
  799. else
  800. includesearchpath.AddPath(More,false);
  801. end;
  802. 'k' :
  803. begin
  804. if more<>'' then
  805. ParaLinkOptions:=ParaLinkOptions+' '+More
  806. else
  807. IllegalPara(opt);
  808. end;
  809. 'l' :
  810. if not UnSetBool(more,0) then
  811. ParaLogo:=true;
  812. 'm' :
  813. parapreprocess:=not UnSetBool(more,0);
  814. 'M' :
  815. begin
  816. more:=Upper(more);
  817. if not SetCompileMode(more, true) then
  818. IllegalPara(opt);
  819. end;
  820. 'n' :
  821. begin
  822. if More='' then
  823. disable_configfile:=true
  824. else
  825. IllegalPara(opt);
  826. end;
  827. 'o' :
  828. begin
  829. if More<>'' then
  830. begin
  831. DefaultReplacements(More);
  832. D:=ExtractFilePath(More);
  833. if (D<>'') then
  834. OutputExeDir:=FixPath(D,True);
  835. OutputFileName:=ExtractFileName(More);
  836. end
  837. else
  838. IllegalPara(opt);
  839. end;
  840. 'O' :
  841. begin
  842. j:=1;
  843. while j<=length(more) do
  844. begin
  845. case more[j] of
  846. '1' :
  847. init_settings.optimizerswitches:=init_settings.optimizerswitches+level1optimizerswitches;
  848. '2' :
  849. init_settings.optimizerswitches:=init_settings.optimizerswitches+level2optimizerswitches;
  850. '3' :
  851. init_settings.optimizerswitches:=init_settings.optimizerswitches+level3optimizerswitches;
  852. 'a' :
  853. begin
  854. if not(UpdateAlignmentStr(Copy(Opt,j+3,255),ParaAlignment)) then
  855. IllegalPara(opt);
  856. break;
  857. end;
  858. 's' :
  859. include(init_settings.optimizerswitches,cs_opt_size);
  860. 'p' :
  861. begin
  862. if not Setcputype(copy(more,j+1,length(more)),init_settings.optimizecputype) then
  863. begin
  864. { Give warning for old i386 switches }
  865. if (Length(More)-j=1) and
  866. (More[j+1]>='1') and (More[j+1]<='5')then
  867. Message2(option_obsolete_switch_use_new,'-Op<nr>','-Op<name>')
  868. else
  869. IllegalPara(opt);
  870. end;
  871. break;
  872. end;
  873. 'o' :
  874. begin
  875. if not UpdateOptimizerStr(copy(more,j+1,length(more)),init_settings.optimizerswitches) then
  876. IllegalPara(opt);
  877. break;
  878. end;
  879. '-' :
  880. begin
  881. init_settings.optimizerswitches:=[];
  882. FillChar(ParaAlignment,sizeof(ParaAlignment),0);
  883. end;
  884. { Obsolete switches }
  885. 'g' :
  886. Message2(option_obsolete_switch_use_new,'-Og','-Os');
  887. 'G' :
  888. Message1(option_obsolete_switch,'-OG');
  889. 'r' :
  890. Message2(option_obsolete_switch_use_new,'-Or','-O2 or -Ooregvar');
  891. 'u' :
  892. Message2(option_obsolete_switch_use_new,'-Ou','-Oouncertain');
  893. else
  894. IllegalPara(opt);
  895. end;
  896. inc(j);
  897. end;
  898. end;
  899. 'p' :
  900. begin
  901. if UnsetBool(More, 0) then
  902. begin
  903. init_settings.moduleswitches:=init_settings.moduleswitches-[cs_profile];
  904. undef_system_macro('FPC_PROFILE');
  905. end
  906. else
  907. if Length(More)=0 then
  908. IllegalPara(opt)
  909. else
  910. case more[1] of
  911. 'g' : if UnsetBool(more, 1) then
  912. begin
  913. exclude(init_settings.moduleswitches,cs_profile);
  914. undef_system_macro('FPC_PROFILE');
  915. end
  916. else
  917. begin
  918. include(init_settings.moduleswitches,cs_profile);
  919. def_system_macro('FPC_PROFILE');
  920. end;
  921. else
  922. IllegalPara(opt);
  923. end;
  924. end;
  925. 'P' : ; { Ignore used by fpc.pp }
  926. 'R' :
  927. begin
  928. if not SetAsmReadMode(More,init_settings.asmmode) then
  929. IllegalPara(opt);
  930. end;
  931. 's' :
  932. begin
  933. if UnsetBool(More, 0) then
  934. begin
  935. init_settings.globalswitches:=init_settings.globalswitches-[cs_asm_extern,cs_link_extern,cs_link_nolink];
  936. if more<>'' then
  937. IllegalPara(opt);
  938. end
  939. else
  940. begin
  941. init_settings.globalswitches:=init_settings.globalswitches+[cs_asm_extern,cs_link_extern,cs_link_nolink];
  942. if more='h' then
  943. init_settings.globalswitches:=init_settings.globalswitches-[cs_link_on_target]
  944. else if more='t' then
  945. init_settings.globalswitches:=init_settings.globalswitches+[cs_link_on_target]
  946. else if more='r' then
  947. init_settings.globalswitches:=init_settings.globalswitches+[cs_asm_leave,cs_no_regalloc]
  948. else if more<>'' then
  949. IllegalPara(opt);
  950. end;
  951. end;
  952. 'S' :
  953. begin
  954. if more[1]='I' then
  955. begin
  956. if upper(more)='ICOM' then
  957. init_settings.interfacetype:=it_interfacecom
  958. else if upper(more)='ICORBA' then
  959. init_settings.interfacetype:=it_interfacecorba
  960. else
  961. IllegalPara(opt);
  962. end
  963. else
  964. begin
  965. j:=1;
  966. while j<=length(more) do
  967. begin
  968. case more[j] of
  969. '2' : //an alternative to -Mobjfpc
  970. SetCompileMode('OBJFPC',true);
  971. 'a' :
  972. include(init_settings.localswitches,cs_do_assertion);
  973. 'c' :
  974. include(init_settings.moduleswitches,cs_support_c_operators);
  975. 'd' : //an alternative to -Mdelphi
  976. SetCompileMode('DELPHI',true);
  977. 'e' :
  978. begin
  979. SetErrorFlags(copy(more,j+1,length(more)));
  980. break;
  981. end;
  982. 'f' :
  983. begin
  984. inc(j);
  985. if more[j]='-' then
  986. begin
  987. features:=[];
  988. if length(more)>j then
  989. IllegalPara(opt);
  990. end
  991. else
  992. begin
  993. if not(IncludeFeature(upper(copy(more,j,length(more)-j+1)))) then
  994. IllegalPara(opt);
  995. end;
  996. end;
  997. 'g' :
  998. include(init_settings.moduleswitches,cs_support_goto);
  999. 'h' :
  1000. include(init_settings.localswitches,cs_ansistrings);
  1001. 'i' :
  1002. include(init_settings.localswitches,cs_do_inline);
  1003. 'k' :
  1004. include(init_settings.globalswitches,cs_load_fpcylix_unit);
  1005. 'm' :
  1006. include(init_settings.moduleswitches,cs_support_macro);
  1007. 'o' : //an alternative to -Mtp
  1008. SetCompileMode('TP',true);
  1009. {$ifdef gpc_mode}
  1010. 'p' : //an alternative to -Mgpc
  1011. SetCompileMode('GPC',true);
  1012. {$endif}
  1013. 's' :
  1014. include(init_settings.globalswitches,cs_constructor_name);
  1015. 't' :
  1016. include(init_settings.moduleswitches,cs_static_keyword);
  1017. 'v' :
  1018. include(init_settings.globalswitches,cs_support_vectors);
  1019. 'x' :
  1020. include(init_settings.globalswitches,cs_support_exceptions);
  1021. '-' :
  1022. begin
  1023. init_settings.globalswitches:=init_settings.globalswitches - [cs_constructor_name,cs_support_exceptions];
  1024. init_settings.localswitches:=init_settings.localswitches - [cs_do_assertion, cs_do_inline, cs_ansistrings];
  1025. init_settings.moduleswitches:=init_settings.moduleswitches - [cs_support_c_operators, cs_support_goto,
  1026. cs_support_macro,
  1027. cs_static_keyword];
  1028. end;
  1029. else
  1030. IllegalPara(opt);
  1031. end;
  1032. inc(j);
  1033. end;
  1034. end;
  1035. end;
  1036. 'T' :
  1037. begin
  1038. more:=Upper(More);
  1039. if paratarget=system_none then
  1040. begin
  1041. { remove old target define }
  1042. TargetDefines(false);
  1043. { load new target }
  1044. paratarget:=find_system_by_string(More);
  1045. if paratarget<>system_none then
  1046. set_target(paratarget)
  1047. else
  1048. IllegalPara(opt);
  1049. { set new define }
  1050. TargetDefines(true);
  1051. end
  1052. else
  1053. if More<>upper(target_info.shortname) then
  1054. Message1(option_target_is_already_set,target_info.shortname);
  1055. end;
  1056. 'u' :
  1057. if more <> '' then
  1058. undef_system_macro(more);
  1059. 'U' :
  1060. begin
  1061. j:=1;
  1062. while j<=length(more) do
  1063. begin
  1064. case more[j] of
  1065. {$ifdef UNITALIASES}
  1066. 'a' :
  1067. begin
  1068. AddUnitAlias(Copy(More,j+1,255));
  1069. break;
  1070. end;
  1071. {$endif UNITALIASES}
  1072. 'n' :
  1073. exclude(init_settings.globalswitches,cs_check_unit_name);
  1074. 'p' :
  1075. begin
  1076. Message2(option_obsolete_switch_use_new,'-Up','-Fu');
  1077. break;
  1078. end;
  1079. 'r' :
  1080. do_release:=true;
  1081. 's' :
  1082. include(init_settings.moduleswitches,cs_compilesystem);
  1083. '-' :
  1084. begin
  1085. exclude(init_settings.moduleswitches,cs_compilesystem);
  1086. exclude(init_settings.globalswitches,cs_check_unit_name);
  1087. end;
  1088. else
  1089. IllegalPara(opt);
  1090. end;
  1091. inc(j);
  1092. end;
  1093. end;
  1094. 'v' :
  1095. begin
  1096. if not setverbosity(More) then
  1097. IllegalPara(opt);
  1098. end;
  1099. 'V' : ; { Ignore used by fpc }
  1100. 'W' :
  1101. begin
  1102. j:=1;
  1103. while j<=length(More) do
  1104. begin
  1105. case More[j] of
  1106. 'A':
  1107. begin
  1108. if UnsetBool(More, j) then
  1109. apptype:=app_native
  1110. else
  1111. apptype:=app_cui;
  1112. end;
  1113. 'B':
  1114. begin
  1115. { -WB200000 means set trefered base address
  1116. to $200000, but does not change relocsection boolean
  1117. this way we can create both relocatble and
  1118. non relocatable DLL at a specific base address PM }
  1119. if (length(More)>j) then
  1120. begin
  1121. if DLLImageBase=nil then
  1122. DLLImageBase:=StringDup(Copy(More,j+1,255));
  1123. end
  1124. else
  1125. begin
  1126. RelocSection:=true;
  1127. RelocSectionSetExplicitly:=true;
  1128. end;
  1129. break;
  1130. end;
  1131. 'C':
  1132. begin
  1133. if UnsetBool(More, j) then
  1134. apptype:=app_gui
  1135. else
  1136. apptype:=app_cui;
  1137. end;
  1138. 'D':
  1139. begin
  1140. UseDeffileForExports:=not UnsetBool(More, j);
  1141. UseDeffileForExportsSetExplicitly:=true;
  1142. end;
  1143. 'F':
  1144. begin
  1145. if UnsetBool(More, j) then
  1146. apptype:=app_cui
  1147. else
  1148. apptype:=app_fs;
  1149. end;
  1150. 'G':
  1151. begin
  1152. if UnsetBool(More, j) then
  1153. apptype:=app_cui
  1154. else
  1155. apptype:=app_gui;
  1156. end;
  1157. 'I':
  1158. begin
  1159. GenerateImportSection:=not UnsetBool(More,j);
  1160. GenerateImportSectionSetExplicitly:=true;
  1161. end;
  1162. 'N':
  1163. begin
  1164. RelocSection:=UnsetBool(More,j);
  1165. RelocSectionSetExplicitly:=true;
  1166. end;
  1167. 'R':
  1168. begin
  1169. { support -WR+ / -WR- as synonyms to -WR / -WN }
  1170. RelocSection:=not UnsetBool(More,j);
  1171. RelocSectionSetExplicitly:=true;
  1172. end;
  1173. 'T':
  1174. begin
  1175. if UnsetBool(More, j) then
  1176. apptype:=app_cui
  1177. else
  1178. apptype:=app_tool;
  1179. end;
  1180. else
  1181. IllegalPara(opt);
  1182. end;
  1183. inc(j);
  1184. end;
  1185. end;
  1186. 'X' :
  1187. begin
  1188. j:=1;
  1189. while j<=length(more) do
  1190. begin
  1191. case More[j] of
  1192. 'c' : Cshared:=TRUE;
  1193. 'd' : Dontlinkstdlibpath:=TRUE;
  1194. 'e' :
  1195. begin
  1196. If UnsetBool(More, j) then
  1197. exclude(init_settings.globalswitches,cs_link_extern)
  1198. else
  1199. include(init_settings.globalswitches,cs_link_extern);
  1200. end;
  1201. 'f' :
  1202. include(init_settings.globalswitches,cs_link_pthread);
  1203. 'i' :
  1204. begin
  1205. If UnsetBool(More, j) then
  1206. include(init_settings.globalswitches,cs_link_extern)
  1207. else
  1208. exclude(init_settings.globalswitches,cs_link_extern);
  1209. end;
  1210. 'm' :
  1211. begin
  1212. If UnsetBool(More, j) then
  1213. exclude(init_settings.globalswitches,cs_link_map)
  1214. else
  1215. include(init_settings.globalswitches,cs_link_map);
  1216. end;
  1217. 'p' : ; { Ignore used by fpc.pp }
  1218. 'r' :
  1219. begin
  1220. rlinkpath:=Copy(more,2,length(More)-1);
  1221. DefaultReplacements(rlinkpath);
  1222. More:='';
  1223. end;
  1224. 's' :
  1225. begin
  1226. If UnsetBool(More, j) then
  1227. exclude(init_settings.globalswitches,cs_link_strip)
  1228. else
  1229. include(init_settings.globalswitches,cs_link_strip);
  1230. end;
  1231. 't' :
  1232. include(init_settings.globalswitches,cs_link_staticflag);
  1233. 'v' :
  1234. begin
  1235. If UnsetBool(More, j) then
  1236. exclude(init_settings.globalswitches,cs_link_opt_vtable)
  1237. else
  1238. include(init_settings.globalswitches,cs_link_opt_vtable);
  1239. end;
  1240. 'D' :
  1241. begin
  1242. def_system_macro('FPC_LINK_DYNAMIC');
  1243. undef_system_macro('FPC_LINK_SMART');
  1244. undef_system_macro('FPC_LINK_STATIC');
  1245. exclude(init_settings.globalswitches,cs_link_static);
  1246. exclude(init_settings.globalswitches,cs_link_smart);
  1247. include(init_settings.globalswitches,cs_link_shared);
  1248. LinkTypeSetExplicitly:=true;
  1249. end;
  1250. 'M' :
  1251. begin
  1252. mainaliasname:=Copy(more,2,length(More)-1);
  1253. More:='';
  1254. end;
  1255. 'P' :
  1256. begin
  1257. utilsprefix:=Copy(more,2,length(More)-1);
  1258. DefaultReplacements(utilsprefix);
  1259. More:='';
  1260. end;
  1261. 'L' : begin // -XLO is link order -XLA is link alias. -XLD avoids load defaults.
  1262. // these are not aggregable.
  1263. if (j=length(more)) or not (more[j+1] in ['O','A','D']) then
  1264. IllegalPara(opt)
  1265. else
  1266. begin
  1267. case more[j+1] of
  1268. 'A' : begin
  1269. s:=Copy(more,3,length(More)-2);
  1270. if not LinkLibraryAliases.AddDep(s) Then
  1271. IllegalPara(opt);
  1272. end;
  1273. 'O' : begin
  1274. s:=Copy(more,3,length(More)-2);
  1275. if not LinkLibraryOrder.AddWeight(s) Then
  1276. IllegalPara(opt);
  1277. end;
  1278. 'D' : include(init_settings.globalswitches,cs_link_no_default_lib_order)
  1279. else
  1280. IllegalPara(opt);
  1281. end; {case}
  1282. j:=length(more);
  1283. end; {else begin}
  1284. end;
  1285. 'S' :
  1286. begin
  1287. def_system_macro('FPC_LINK_STATIC');
  1288. undef_system_macro('FPC_LINK_SMART');
  1289. undef_system_macro('FPC_LINK_DYNAMIC');
  1290. include(init_settings.globalswitches,cs_link_static);
  1291. exclude(init_settings.globalswitches,cs_link_smart);
  1292. exclude(init_settings.globalswitches,cs_link_shared);
  1293. LinkTypeSetExplicitly:=true;
  1294. end;
  1295. 'X' :
  1296. begin
  1297. def_system_macro('FPC_LINK_SMART');
  1298. undef_system_macro('FPC_LINK_STATIC');
  1299. undef_system_macro('FPC_LINK_DYNAMIC');
  1300. exclude(init_settings.globalswitches,cs_link_static);
  1301. include(init_settings.globalswitches,cs_link_smart);
  1302. exclude(init_settings.globalswitches,cs_link_shared);
  1303. LinkTypeSetExplicitly:=true;
  1304. end;
  1305. '-' :
  1306. begin
  1307. exclude(init_settings.globalswitches,cs_link_staticflag);
  1308. exclude(init_settings.globalswitches,cs_link_strip);
  1309. exclude(init_settings.globalswitches,cs_link_map);
  1310. set_default_link_type;
  1311. end;
  1312. else
  1313. IllegalPara(opt);
  1314. end;
  1315. inc(j);
  1316. end;
  1317. end;
  1318. end;
  1319. end;
  1320. '@' :
  1321. begin
  1322. Message(option_no_nested_response_file);
  1323. StopOptions(1);
  1324. end;
  1325. else
  1326. begin
  1327. if (length(param_file)<>0) then
  1328. Message(option_only_one_source_support);
  1329. param_file:=opt;
  1330. Message1(option_found_file,opt);
  1331. end;
  1332. end;
  1333. end;
  1334. procedure Toption.Interpret_file(const filename : string);
  1335. procedure RemoveSep(var fn:string);
  1336. var
  1337. i : longint;
  1338. begin
  1339. i:=0;
  1340. while (i<length(fn)) and (fn[i+1] in [',',' ',#9]) do
  1341. inc(i);
  1342. Delete(fn,1,i);
  1343. i:=length(fn);
  1344. while (i>0) and (fn[i] in [',',' ',#9]) do
  1345. dec(i);
  1346. fn:=copy(fn,1,i);
  1347. end;
  1348. function GetName(var fn:string):string;
  1349. var
  1350. i : longint;
  1351. begin
  1352. i:=0;
  1353. while (i<length(fn)) and (fn[i+1] in ['a'..'z','A'..'Z','0'..'9','_','-']) do
  1354. inc(i);
  1355. GetName:=Copy(fn,1,i);
  1356. Delete(fn,1,i);
  1357. end;
  1358. const
  1359. maxlevel=16;
  1360. var
  1361. f : text;
  1362. s, tmp,
  1363. opts : string;
  1364. skip : array[0..maxlevel-1] of boolean;
  1365. level : longint;
  1366. option_read : boolean;
  1367. begin
  1368. { avoid infinite loop }
  1369. Inc(FileLevel);
  1370. Option_read:=false;
  1371. If FileLevel>MaxLevel then
  1372. Message(option_too_many_cfg_files);
  1373. { Maybe It's Directory ?} //Jaro Change:
  1374. if PathExists(filename,false) then
  1375. begin
  1376. Message1(option_config_is_dir,filename);
  1377. exit;
  1378. end;
  1379. { open file }
  1380. Message1(option_using_file,filename);
  1381. assign(f,ExpandFileName(filename));
  1382. {$I-}
  1383. reset(f);
  1384. {$I+}
  1385. if ioresult<>0 then
  1386. begin
  1387. Message1(option_unable_open_file,filename);
  1388. exit;
  1389. end;
  1390. Message1(option_start_reading_configfile,filename);
  1391. fillchar(skip,sizeof(skip),0);
  1392. level:=0;
  1393. while not eof(f) do
  1394. begin
  1395. readln(f,opts);
  1396. RemoveSep(opts);
  1397. if (opts<>'') and (opts[1]<>';') then
  1398. begin
  1399. if opts[1]='#' then
  1400. begin
  1401. Message1(option_interpreting_file_option,opts);
  1402. Delete(opts,1,1);
  1403. s:=upper(GetName(opts));
  1404. if (s='SECTION') then
  1405. begin
  1406. RemoveSep(opts);
  1407. s:=upper(GetName(opts));
  1408. if level=0 then
  1409. skip[level]:=not (assigned(search_macro(s)) or (s='COMMON'));
  1410. end
  1411. else
  1412. if (s='IFDEF') then
  1413. begin
  1414. RemoveSep(opts);
  1415. if Level>=maxlevel then
  1416. begin
  1417. Message(option_too_many_ifdef);
  1418. stopOptions(1);
  1419. end;
  1420. inc(Level);
  1421. skip[level]:=(skip[level-1] or not assigned(search_macro(upper(GetName(opts)))));
  1422. end
  1423. else
  1424. if (s='IFNDEF') then
  1425. begin
  1426. RemoveSep(opts);
  1427. if Level>=maxlevel then
  1428. begin
  1429. Message(option_too_many_ifdef);
  1430. stopOptions(1);
  1431. end;
  1432. inc(Level);
  1433. skip[level]:=(skip[level-1] or assigned(search_macro(upper(GetName(opts)))));
  1434. end
  1435. else
  1436. if (s='ELSE') then
  1437. skip[level]:=skip[level-1] or (not skip[level])
  1438. else
  1439. if (s='ENDIF') then
  1440. begin
  1441. skip[level]:=false;
  1442. if Level=0 then
  1443. begin
  1444. Message(option_too_many_endif);
  1445. stopOptions(1);
  1446. end;
  1447. dec(level);
  1448. end
  1449. else
  1450. if (not skip[level]) then
  1451. begin
  1452. if (s='DEFINE') then
  1453. begin
  1454. RemoveSep(opts);
  1455. tmp:= GetName(opts);
  1456. if tmp <> '' then
  1457. def_system_macro(tmp);
  1458. end
  1459. else
  1460. if (s='UNDEF') then
  1461. begin
  1462. RemoveSep(opts);
  1463. tmp:= GetName(opts);
  1464. if tmp <> '' then
  1465. undef_system_macro(tmp);
  1466. end
  1467. else
  1468. if (s='WRITE') then
  1469. begin
  1470. Delete(opts,1,1);
  1471. WriteLn(opts);
  1472. end
  1473. else
  1474. if (s='INCLUDE') then
  1475. begin
  1476. Delete(opts,1,1);
  1477. Interpret_file(opts);
  1478. end;
  1479. end;
  1480. end
  1481. else
  1482. begin
  1483. if (opts[1]='-') or (opts[1]='@') then
  1484. begin
  1485. if (not skip[level]) then
  1486. interpret_option(opts,false);
  1487. Option_read:=true;
  1488. end
  1489. else
  1490. Message1(option_illegal_para,opts);
  1491. end;
  1492. end;
  1493. end;
  1494. if Level>0 then
  1495. Message(option_too_less_endif);
  1496. if Not Option_read then
  1497. Message1(option_no_option_found,filename)
  1498. else
  1499. Message1(option_end_reading_configfile,filename);
  1500. Close(f);
  1501. Dec(FileLevel);
  1502. end;
  1503. procedure Toption.Interpret_envvar(const envname : string);
  1504. var
  1505. argstart,
  1506. env,
  1507. pc : pchar;
  1508. arglen : longint;
  1509. quote : set of char;
  1510. hs : string;
  1511. begin
  1512. Message1(option_using_env,envname);
  1513. env:=GetEnvPChar(envname);
  1514. pc:=env;
  1515. if assigned(pc) then
  1516. begin
  1517. repeat
  1518. { skip leading spaces }
  1519. while pc^ in [' ',#9,#13] do
  1520. inc(pc);
  1521. case pc^ of
  1522. #0 :
  1523. break;
  1524. '"' :
  1525. begin
  1526. quote:=['"'];
  1527. inc(pc);
  1528. end;
  1529. '''' :
  1530. begin
  1531. quote:=[''''];
  1532. inc(pc);
  1533. end;
  1534. else
  1535. quote:=[' ',#9,#13];
  1536. end;
  1537. { scan until the end of the argument }
  1538. argstart:=pc;
  1539. while (pc^<>#0) and not(pc^ in quote) do
  1540. inc(pc);
  1541. { create argument }
  1542. arglen:=pc-argstart;
  1543. {$warning FIXME: silent truncation of environment parameters }
  1544. if (arglen > 255) then
  1545. arglen := 255;
  1546. setlength(hs,arglen);
  1547. move(argstart^,hs[1],arglen);
  1548. interpret_option(hs,true);
  1549. { skip quote }
  1550. if pc^ in quote then
  1551. inc(pc);
  1552. until false;
  1553. end
  1554. else
  1555. Message1(option_no_option_found,'(env) '+envname);
  1556. FreeEnvPChar(env);
  1557. end;
  1558. procedure toption.read_parameters;
  1559. var
  1560. opts : string;
  1561. paramindex : longint;
  1562. begin
  1563. paramindex:=0;
  1564. while paramindex<paramcount do
  1565. begin
  1566. inc(paramindex);
  1567. opts:=system.paramstr(paramindex);
  1568. case opts[1] of
  1569. '@' :
  1570. if not firstpass then
  1571. begin
  1572. Delete(opts,1,1);
  1573. Message1(option_reading_further_from,opts);
  1574. interpret_file(opts);
  1575. end;
  1576. '!' :
  1577. if not firstpass then
  1578. begin
  1579. Delete(opts,1,1);
  1580. Message1(option_reading_further_from,'(env) '+opts);
  1581. interpret_envvar(opts);
  1582. end;
  1583. else
  1584. interpret_option(opts,true);
  1585. end;
  1586. end;
  1587. end;
  1588. procedure toption.parsecmd(cmd:string);
  1589. var
  1590. i,ps : longint;
  1591. opts : string;
  1592. begin
  1593. while (cmd<>'') do
  1594. begin
  1595. while cmd[1]=' ' do
  1596. delete(cmd,1,1);
  1597. i:=pos(' ',cmd);
  1598. if i=0 then
  1599. i:=256;
  1600. opts:=Copy(cmd,1,i-1);
  1601. Delete(cmd,1,i);
  1602. case opts[1] of
  1603. '@' :
  1604. if not firstpass then
  1605. begin
  1606. Delete(opts,1,1);
  1607. Message1(option_reading_further_from,opts);
  1608. interpret_file(opts);
  1609. end;
  1610. '!' :
  1611. if not firstpass then
  1612. begin
  1613. Delete(opts,1,1);
  1614. Message1(option_reading_further_from,'(env) '+opts);
  1615. interpret_envvar(opts);
  1616. end;
  1617. '"' :
  1618. begin
  1619. Delete(opts,1,1);
  1620. ps:=pos('"',cmd);
  1621. if (i<>256) and (ps>0) then
  1622. begin
  1623. opts:=opts + ' '+ copy(cmd,1,ps-1);
  1624. cmd:=copy(cmd,ps+1,255);
  1625. end;
  1626. interpret_option(opts,true);
  1627. end;
  1628. else
  1629. interpret_option(opts,true);
  1630. end;
  1631. end;
  1632. end;
  1633. procedure toption.writequickinfo;
  1634. var
  1635. s : string;
  1636. i : longint;
  1637. procedure addinfo(const hs:string);
  1638. begin
  1639. if s<>'' then
  1640. s:=s+' '+hs
  1641. else
  1642. s:=hs;
  1643. end;
  1644. begin
  1645. s:='';
  1646. i:=0;
  1647. while (i<length(quickinfo)) do
  1648. begin
  1649. inc(i);
  1650. case quickinfo[i] of
  1651. 'S' :
  1652. begin
  1653. inc(i);
  1654. case quickinfo[i] of
  1655. 'O' :
  1656. addinfo(lower(source_info.shortname));
  1657. 'P' :
  1658. addinfo(source_cpu_string);
  1659. else
  1660. IllegalPara('-i'+QuickInfo);
  1661. end;
  1662. end;
  1663. 'T' :
  1664. begin
  1665. inc(i);
  1666. case quickinfo[i] of
  1667. 'O' :
  1668. addinfo(lower(target_info.shortname));
  1669. 'P' :
  1670. AddInfo(target_cpu_string);
  1671. else
  1672. IllegalPara('-i'+QuickInfo);
  1673. end;
  1674. end;
  1675. 'V' :
  1676. AddInfo(version_string);
  1677. 'W' :
  1678. AddInfo(full_version_string);
  1679. 'D' :
  1680. AddInfo(date_string);
  1681. '_' :
  1682. ;
  1683. else
  1684. IllegalPara('-i'+QuickInfo);
  1685. end;
  1686. end;
  1687. if s<>'' then
  1688. begin
  1689. writeln(s);
  1690. stopoptions(0);
  1691. end;
  1692. end;
  1693. procedure TOption.TargetDefines(def:boolean);
  1694. var
  1695. s : string;
  1696. i : integer;
  1697. begin
  1698. if def then
  1699. def_system_macro(target_info.shortname)
  1700. else
  1701. undef_system_macro(target_info.shortname);
  1702. s:=target_info.extradefines;
  1703. while (s<>'') do
  1704. begin
  1705. i:=pos(';',s);
  1706. if i=0 then
  1707. i:=length(s)+1;
  1708. if def then
  1709. def_system_macro(Copy(s,1,i-1))
  1710. else
  1711. undef_system_macro(Copy(s,1,i-1));
  1712. delete(s,1,i);
  1713. end;
  1714. end;
  1715. constructor TOption.create;
  1716. begin
  1717. LogoWritten:=false;
  1718. NoPressEnter:=false;
  1719. FirstPass:=false;
  1720. FileLevel:=0;
  1721. Quickinfo:='';
  1722. ParaIncludePath:=TSearchPathList.Create;
  1723. ParaObjectPath:=TSearchPathList.Create;
  1724. ParaUnitPath:=TSearchPathList.Create;
  1725. ParaLibraryPath:=TSearchPathList.Create;
  1726. FillChar(ParaAlignment,sizeof(ParaAlignment),0);
  1727. end;
  1728. destructor TOption.destroy;
  1729. begin
  1730. ParaIncludePath.Free;
  1731. ParaObjectPath.Free;
  1732. ParaUnitPath.Free;
  1733. ParaLibraryPath.Free;
  1734. end;
  1735. {****************************************************************************
  1736. Callable Routines
  1737. ****************************************************************************}
  1738. function check_configfile(const fn:string;var foundfn:string):boolean;
  1739. function CfgFileExists(const fn:string):boolean;
  1740. begin
  1741. Comment(V_Tried,'Configfile search: '+fn);
  1742. CfgFileExists:=FileExists(fn);
  1743. end;
  1744. var
  1745. hs,
  1746. configpath : string;
  1747. begin
  1748. foundfn:=fn;
  1749. check_configfile:=true;
  1750. { retrieve configpath }
  1751. configpath:=FixPath(GetEnvironmentVariable('PPC_CONFIG_PATH'),false);
  1752. {$ifdef Unix}
  1753. if configpath='' then
  1754. configpath:=ExpandFileName(FixPath(exepath+'../etc/',false));
  1755. {$endif}
  1756. {
  1757. Order to read configuration file :
  1758. try reading fpc.cfg in :
  1759. 1 - current dir
  1760. 2 - configpath
  1761. 3 - compiler path
  1762. }
  1763. if not FileExists(fn) then
  1764. begin
  1765. {$ifdef Unix}
  1766. hs:=GetEnvironmentVariable('HOME');
  1767. if (hs<>'') and CfgFileExists(FixPath(hs,false)+'.'+fn) then
  1768. foundfn:=FixPath(hs,false)+'.'+fn
  1769. else
  1770. {$endif}
  1771. if CfgFileExists(configpath+fn) then
  1772. foundfn:=configpath+fn
  1773. else
  1774. {$ifndef Unix}
  1775. if CfgFileExists(exepath+fn) then
  1776. foundfn:=exepath+fn
  1777. else
  1778. {$else}
  1779. if CfgFileExists('/etc/'+fn) then
  1780. foundfn:='/etc/'+fn
  1781. else
  1782. {$endif}
  1783. check_configfile:=false;
  1784. end;
  1785. end;
  1786. procedure read_arguments(cmd:string);
  1787. var
  1788. i : tfeature;
  1789. begin
  1790. option:=coption.create;
  1791. disable_configfile:=false;
  1792. { get default messagefile }
  1793. msgfilename:=GetEnvironmentVariable('PPC_ERROR_FILE');
  1794. { default configfile can be specified on the commandline,
  1795. remove it first }
  1796. if (cmd<>'') and (cmd[1]='[') then
  1797. begin
  1798. ppccfg:=Copy(cmd,2,pos(']',cmd)-2);
  1799. Delete(cmd,1,pos(']',cmd));
  1800. end
  1801. else
  1802. begin
  1803. ppccfg:='fpc.cfg';
  1804. ppcaltcfg:='ppc386.cfg';
  1805. end;
  1806. { first pass reading of parameters, only -i -v -T etc.}
  1807. option.firstpass:=true;
  1808. if cmd<>'' then
  1809. option.parsecmd(cmd)
  1810. else
  1811. begin
  1812. option.read_parameters;
  1813. { Write only quickinfo }
  1814. if option.quickinfo<>'' then
  1815. option.writequickinfo;
  1816. end;
  1817. option.firstpass:=false;
  1818. { target is set here, for wince the default app type is gui }
  1819. if target_info.system in system_wince then
  1820. apptype:=app_gui;
  1821. { default defines }
  1822. def_system_macro(target_info.shortname);
  1823. def_system_macro('FPC');
  1824. def_system_macro('VER'+version_nr);
  1825. def_system_macro('VER'+version_nr+'_'+release_nr);
  1826. def_system_macro('VER'+version_nr+'_'+release_nr+'_'+patch_nr);
  1827. { Temporary defines, until things settle down }
  1828. { "main" symbol is generated in the main program, and left out of the system unit }
  1829. def_system_macro('FPC_DARWIN_PASCALMAIN');
  1830. def_system_macro('FPC_DARWIN_JMP_MAIN');
  1831. def_system_macro('COMPPROCINLINEFIXED');
  1832. def_system_macro('PARAOUTFILE');
  1833. def_system_macro('RESSTRSECTIONS');
  1834. def_system_macro('FPC_HASFIXED64BITVARIANT');
  1835. def_system_macro('FPC_HASINTERNALOLEVARIANT2VARIANTCAST');
  1836. def_system_macro('FPC_HAS_VARSETS');
  1837. def_system_macro('FPC_HAS_VALGRINDBOOL');
  1838. def_system_macro('FPC_HAS_STR_CURRENCY');
  1839. def_system_macro('FPC_REAL2REAL_FIXED');
  1840. {$if defined(x86) or defined(arm)}
  1841. def_system_macro('INTERNAL_BACKTRACE');
  1842. {$endif}
  1843. def_system_macro('STR_CONCAT_PROCS');
  1844. if pocall_default = pocall_register then
  1845. def_system_macro('REGCALL');
  1846. { don't remove this, it's also for fpdoc necessary (FK) }
  1847. def_system_macro('FPC_HAS_FEATURE_SUPPORT');
  1848. { using a case is pretty useless here (FK) }
  1849. { some stuff for TP compatibility }
  1850. {$ifdef i386}
  1851. def_system_macro('CPU86');
  1852. def_system_macro('CPU87');
  1853. def_system_macro('CPU386');
  1854. {$endif}
  1855. {$ifdef m68k}
  1856. def_system_macro('CPU68');
  1857. {$endif}
  1858. { new processor stuff }
  1859. {$ifdef i386}
  1860. def_system_macro('CPUI386');
  1861. def_system_macro('CPU32');
  1862. def_system_macro('FPC_HAS_TYPE_EXTENDED');
  1863. def_system_macro('FPC_HAS_TYPE_DOUBLE');
  1864. def_system_macro('FPC_HAS_TYPE_SINGLE');
  1865. def_system_macro('FPC_HAS_RESOURCES');
  1866. {$endif}
  1867. {$ifdef m68k}
  1868. def_system_macro('CPU68K');
  1869. def_system_macro('CPUM68K');
  1870. def_system_macro('CPU32');
  1871. def_system_macro('FPC_HAS_TYPE_DOUBLE');
  1872. def_system_macro('FPC_HAS_TYPE_SINGLE');
  1873. def_system_macro('FPC_INCLUDE_SOFTWARE_INT64_TO_DOUBLE');
  1874. def_system_macro('FPC_CURRENCY_IS_INT64');
  1875. def_system_macro('FPC_COMP_IS_INT64');
  1876. {$endif}
  1877. {$ifdef ALPHA}
  1878. def_system_macro('CPUALPHA');
  1879. def_system_macro('CPU64');
  1880. {$endif}
  1881. {$ifdef powerpc}
  1882. def_system_macro('CPUPOWERPC');
  1883. def_system_macro('CPUPOWERPC32');
  1884. def_system_macro('CPU32');
  1885. def_system_macro('FPC_HAS_TYPE_DOUBLE');
  1886. def_system_macro('FPC_HAS_TYPE_SINGLE');
  1887. def_system_macro('FPC_INCLUDE_SOFTWARE_INT64_TO_DOUBLE');
  1888. def_system_macro('FPC_CURRENCY_IS_INT64');
  1889. def_system_macro('FPC_COMP_IS_INT64');
  1890. {$endif}
  1891. {$ifdef POWERPC64}
  1892. def_system_macro('CPUPOWERPC');
  1893. def_system_macro('CPUPOWERPC64');
  1894. def_system_macro('CPU64');
  1895. def_system_macro('FPC_HAS_TYPE_DOUBLE');
  1896. def_system_macro('FPC_HAS_TYPE_SINGLE');
  1897. def_system_macro('FPC_INCLUDE_SOFTWARE_INT64_TO_DOUBLE');
  1898. def_system_macro('FPC_CURRENCY_IS_INT64');
  1899. def_system_macro('FPC_COMP_IS_INT64');
  1900. def_system_macro('FPC_REQUIRES_PROPER_ALIGNMENT');
  1901. {$endif}
  1902. {$ifdef iA64}
  1903. def_system_macro('CPUIA64');
  1904. def_system_macro('CPU64');
  1905. {$endif}
  1906. {$ifdef x86_64}
  1907. def_system_macro('CPUX86_64');
  1908. def_system_macro('CPUAMD64');
  1909. def_system_macro('CPU64');
  1910. { not supported for now, afaik (FK)
  1911. def_system_macro('FPC_HAS_TYPE_FLOAT128'); }
  1912. { win64 doesn't support the legacy fpu }
  1913. if target_info.system<>system_x86_64_win64 then
  1914. def_system_macro('FPC_HAS_TYPE_EXTENDED')
  1915. else
  1916. begin
  1917. def_system_macro('FPC_CURRENCY_IS_INT64');
  1918. def_system_macro('FPC_COMP_IS_INT64');
  1919. undef_system_macro('FPC_HAS_TYPE_EXTENDED');
  1920. end;
  1921. def_system_macro('FPC_HAS_TYPE_DOUBLE');
  1922. def_system_macro('FPC_HAS_TYPE_SINGLE');
  1923. {$endif}
  1924. {$ifdef sparc}
  1925. def_system_macro('CPUSPARC');
  1926. def_system_macro('CPUSPARC32');
  1927. def_system_macro('CPU32');
  1928. def_system_macro('FPC_HAS_TYPE_DOUBLE');
  1929. def_system_macro('FPC_HAS_TYPE_SINGLE');
  1930. def_system_macro('FPC_INCLUDE_SOFTWARE_INT64_TO_DOUBLE');
  1931. def_system_macro('FPC_CURRENCY_IS_INT64');
  1932. def_system_macro('FPC_COMP_IS_INT64');
  1933. def_system_macro('FPC_REQUIRES_PROPER_ALIGNMENT');
  1934. {$endif}
  1935. {$ifdef vis}
  1936. def_system_macro('CPUVIS');
  1937. def_system_macro('CPU32');
  1938. {$endif}
  1939. {$ifdef arm}
  1940. def_system_macro('CPUARM');
  1941. def_system_macro('FPUFPA');
  1942. def_system_macro('CPU32');
  1943. def_system_macro('FPC_HAS_TYPE_DOUBLE');
  1944. def_system_macro('FPC_HAS_TYPE_SINGLE');
  1945. def_system_macro('FPC_INCLUDE_SOFTWARE_INT64_TO_DOUBLE');
  1946. def_system_macro('FPC_CURRENCY_IS_INT64');
  1947. def_system_macro('FPC_COMP_IS_INT64');
  1948. def_system_macro('FPC_REQUIRES_PROPER_ALIGNMENT');
  1949. {$endif arm}
  1950. if source_info.system<>target_info.system then
  1951. def_system_macro('FPC_CROSSCOMPILING');
  1952. if source_info.cpu<>target_info.cpu then
  1953. def_system_macro('FPC_CPUCROSSCOMPILING');
  1954. if tf_winlikewidestring in target_info.flags then
  1955. def_system_macro('FPC_WINLIKEWIDESTRING');
  1956. { read configuration file }
  1957. if (not disable_configfile) and
  1958. (ppccfg<>'') then
  1959. begin
  1960. read_configfile:=check_configfile(ppccfg,ppccfg);
  1961. { Maybe alternative configfile ? }
  1962. if (not read_configfile) and
  1963. (ppcaltcfg<>'') then
  1964. read_configfile:=check_configfile(ppcaltcfg,ppccfg);
  1965. end
  1966. else
  1967. read_configfile := false;
  1968. { Read commandline and configfile }
  1969. param_file:='';
  1970. { read configfile }
  1971. if read_configfile then
  1972. option.interpret_file(ppccfg);
  1973. { read parameters again to override config file }
  1974. if cmd<>'' then
  1975. option.parsecmd(cmd)
  1976. else
  1977. begin
  1978. { Write help pages if no parameters are passed }
  1979. if (paramcount=0) then
  1980. Option.WriteHelpPages;
  1981. option.read_parameters;
  1982. { Write only quickinfo }
  1983. if option.quickinfo<>'' then
  1984. option.writequickinfo;
  1985. end;
  1986. { Stop if errors in options }
  1987. if ErrorCount>0 then
  1988. StopOptions(1);
  1989. { Write logo }
  1990. if option.ParaLogo then
  1991. option.writelogo;
  1992. { Non-core target defines }
  1993. Option.TargetDefines(true);
  1994. { endian define }
  1995. case target_info.endian of
  1996. endian_little :
  1997. begin
  1998. def_system_macro('ENDIAN_LITTLE');
  1999. def_system_macro('FPC_LITTLE_ENDIAN');
  2000. end;
  2001. endian_big :
  2002. begin
  2003. def_system_macro('ENDIAN_BIG');
  2004. def_system_macro('FPC_BIG_ENDIAN');
  2005. end;
  2006. end;
  2007. { abi define }
  2008. case target_info.abi of
  2009. abi_powerpc_sysv :
  2010. def_system_macro('FPC_ABI_SYSV');
  2011. abi_powerpc_aix :
  2012. def_system_macro('FPC_ABI_AIX');
  2013. end;
  2014. { CPU Define }
  2015. def_system_macro('CPU'+Cputypestr[init_settings.cputype]);
  2016. { Check file to compile }
  2017. if param_file='' then
  2018. begin
  2019. Message(option_no_source_found);
  2020. StopOptions(1);
  2021. end;
  2022. {$ifndef Unix}
  2023. param_file:=FixFileName(param_file);
  2024. {$endif not unix}
  2025. inputfilepath:=ExtractFilePath(param_file);
  2026. inputfilename:=ExtractFileName(param_file);
  2027. if ExtractFileExt(inputfilename)='' then
  2028. begin
  2029. if FileExists(inputfilepath+ChangeFileExt(inputfilename,sourceext)) then
  2030. inputfilename:=ChangeFileExt(inputfilename,sourceext)
  2031. else if FileExists(inputfilepath+ChangeFileExt(inputfilename,pasext)) then
  2032. inputfilename:=ChangeFileExt(inputfilename,pasext)
  2033. else if ((m_mac in current_settings.modeswitches) or
  2034. (tf_p_ext_support in target_info.flags))
  2035. and FileExists(inputfilepath+ChangeFileExt(inputfilename,pext)) then
  2036. inputfilename:=ChangeFileExt(inputfilename,pext);
  2037. end;
  2038. { Check output dir }
  2039. if (OutputExeDir<>'') and
  2040. not PathExists(OutputExeDir,false) then
  2041. begin
  2042. Message1(general_e_path_does_not_exist,OutputExeDir);
  2043. StopOptions(1);
  2044. end;
  2045. { Add paths specified with parameters to the searchpaths }
  2046. UnitSearchPath.AddList(option.ParaUnitPath,true);
  2047. ObjectSearchPath.AddList(option.ParaObjectPath,true);
  2048. IncludeSearchPath.AddList(option.ParaIncludePath,true);
  2049. LibrarySearchPath.AddList(option.ParaLibraryPath,true);
  2050. { add unit environment and exepath to the unit search path }
  2051. if inputfilepath<>'' then
  2052. Unitsearchpath.AddPath(inputfilepath,true);
  2053. if not disable_configfile then
  2054. UnitSearchPath.AddPath(GetEnvironmentVariable(target_info.unit_env),false);
  2055. {$ifdef Unix}
  2056. fpcdir:=FixPath(GetEnvironmentVariable('FPCDIR'),false);
  2057. if fpcdir='' then
  2058. begin
  2059. if PathExists('/usr/local/lib/fpc/'+version_string,true) then
  2060. fpcdir:='/usr/local/lib/fpc/'+version_string+'/'
  2061. else
  2062. fpcdir:='/usr/lib/fpc/'+version_string+'/';
  2063. end;
  2064. {$else unix}
  2065. fpcdir:=FixPath(GetEnvironmentVariable('FPCDIR'),false);
  2066. if fpcdir='' then
  2067. begin
  2068. fpcdir:=ExePath+'../';
  2069. if not(PathExists(fpcdir+'/units',true)) and
  2070. not(PathExists(fpcdir+'/rtl',true)) then
  2071. fpcdir:=fpcdir+'../';
  2072. end;
  2073. {$endif unix}
  2074. { first try development RTL, else use the default installation path }
  2075. if not disable_configfile then
  2076. begin
  2077. if PathExists(FpcDir+'rtl',true) then
  2078. if tf_use_8_3 in Source_Info.Flags then
  2079. UnitSearchPath.AddPath(FpcDir+'rtl/'+target_os_string,false)
  2080. else
  2081. UnitSearchPath.AddPath(FpcDir+'rtl/'+target_full_string,false)
  2082. else
  2083. if tf_use_8_3 in Source_Info.Flags then
  2084. UnitSearchPath.AddPath(FpcDir+'units/'+target_os_string+'/rtl',false)
  2085. else
  2086. UnitSearchPath.AddPath(FpcDir+'units/'+target_full_string+'/rtl',false);
  2087. end;
  2088. { Add exepath if the exe is not in the current dir, because that is always searched already.
  2089. Do not add it when linking on the target because then we can maybe already find
  2090. .o files that are not for the target }
  2091. if (ExePath<>GetCurrentDir) and
  2092. not(cs_link_on_target in init_settings.globalswitches) then
  2093. UnitSearchPath.AddPath(ExePath,false);
  2094. { Add unit dir to the object and library path }
  2095. objectsearchpath.AddList(unitsearchpath,false);
  2096. librarysearchpath.AddList(unitsearchpath,false);
  2097. { maybe override assembler }
  2098. if (paratargetasm<>as_none) then
  2099. begin
  2100. if not set_target_asm(paratargetasm) then
  2101. begin
  2102. Message2(option_incompatible_asm,asminfos[paratargetasm]^.idtxt,target_info.name);
  2103. set_target_asm(target_info.assemextern);
  2104. Message1(option_asm_forced,target_asm.idtxt);
  2105. end;
  2106. if (af_no_debug in asminfos[paratargetasm]^.flags) and
  2107. (paratargetdbg<>dbg_none) then
  2108. begin
  2109. Message1(option_confict_asm_debug,
  2110. asminfos[paratargetasm]^.idtxt);
  2111. paratargetdbg:=dbg_none;
  2112. exclude(init_settings.moduleswitches,cs_debuginfo);
  2113. end;
  2114. end;
  2115. { maybe override debug info format }
  2116. if (paratargetdbg<>dbg_none) then
  2117. set_target_dbg(paratargetdbg);
  2118. { switch assembler if it's binary and we got -a on the cmdline }
  2119. if (cs_asm_leave in init_settings.globalswitches) and
  2120. (af_outputbinary in target_asm.flags) then
  2121. begin
  2122. Message(option_switch_bin_to_src_assembler);
  2123. set_target_asm(target_info.assemextern);
  2124. end;
  2125. { Force use of external linker if there is no
  2126. internal linker or the linking is skipped }
  2127. if not(cs_link_extern in init_settings.globalswitches) and
  2128. (not assigned(target_info.link) or
  2129. (cs_link_nolink in init_settings.globalswitches)) then
  2130. include(init_settings.globalswitches,cs_link_extern);
  2131. { turn off stripping if compiling with debuginfo or profile }
  2132. if (cs_debuginfo in init_settings.moduleswitches) or
  2133. (cs_profile in init_settings.moduleswitches) then
  2134. exclude(init_settings.globalswitches,cs_link_strip);
  2135. { force fpu emulation on arm/wince, arm/gba and arm/nds}
  2136. if target_info.system in [system_arm_wince,system_arm_gba,system_m68k_amiga,
  2137. system_m68k_linux,system_arm_nds] then
  2138. include(init_settings.moduleswitches,cs_fp_emulation);
  2139. {$ifdef ARM}
  2140. { define FPC_DOUBLE_HILO_SWAPPED if needed to properly handle doubles in RTL }
  2141. if (init_settings.fputype in [fpu_fpa,fpu_fpa10,fpu_fpa11]) and
  2142. not(cs_fp_emulation in init_settings.moduleswitches) then
  2143. def_system_macro('FPC_DOUBLE_HILO_SWAPPED');
  2144. {$endif ARM}
  2145. { Section smartlinking conflicts with import sections on Windows }
  2146. if GenerateImportSection and
  2147. (target_info.system in [system_i386_win32,system_x86_64_win64]) then
  2148. exclude(target_info.flags,tf_smartlink_sections);
  2149. {$ifdef x86_64}
  2150. {$warning HACK: turn off smartlinking}
  2151. exclude(init_settings.moduleswitches,cs_create_smart);
  2152. {$endif}
  2153. if not LinkTypeSetExplicitly then
  2154. set_default_link_type;
  2155. { Default alignment settings,
  2156. 1. load the defaults for the target
  2157. 2. override with generic optimizer setting (little size)
  2158. 3. override with the user specified -Oa }
  2159. UpdateAlignment(init_settings.alignment,target_info.alignment);
  2160. if (cs_opt_size in current_settings.optimizerswitches) then
  2161. begin
  2162. init_settings.alignment.procalign:=1;
  2163. init_settings.alignment.jumpalign:=1;
  2164. init_settings.alignment.loopalign:=1;
  2165. end;
  2166. UpdateAlignment(init_settings.alignment,option.paraalignment);
  2167. set_system_macro('FPC_VERSION',version_nr);
  2168. set_system_macro('FPC_RELEASE',release_nr);
  2169. set_system_macro('FPC_PATCH',patch_nr);
  2170. for i:=low(tfeature) to high(tfeature) do
  2171. if i in features then
  2172. def_system_macro('FPC_HAS_FEATURE_'+featurestr[i]);
  2173. option.free;
  2174. Option:=nil;
  2175. end;
  2176. initialization
  2177. coption:=toption;
  2178. finalization
  2179. if assigned(option) then
  2180. option.free;
  2181. end.