options.pas 71 KB

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