options.pas 76 KB

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