options.pas 77 KB

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