options.pas 80 KB

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