options.pas 71 KB

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