options.pas 73 KB

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