options.pas 83 KB

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