options.pas 76 KB

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