options.pas 78 KB

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