options.pas 77 KB

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