options.pas 79 KB

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