options.pas 79 KB

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