options.pas 73 KB

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