options.pas 81 KB

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