options.pas 142 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252
  1. {
  2. Copyright (c) 1998-2008 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. cfileutl,cclasses,
  22. globtype,globals,verbose,systems,cpuinfo,comprsrc;
  23. Type
  24. TOption=class
  25. FirstPass,
  26. ParaLogo,
  27. NoPressEnter,
  28. FPCHelpLines,
  29. LogoWritten,
  30. ABISetExplicitly,
  31. FPUSetExplicitly,
  32. CPUSetExplicitly,
  33. OptCPUSetExplicitly: boolean;
  34. FileLevel : longint;
  35. QuickInfo : string;
  36. FPCBinaryPath: string;
  37. ParaIncludeCfgPath,
  38. ParaIncludePath,
  39. ParaUnitPath,
  40. ParaObjectPath,
  41. ParaLibraryPath,
  42. ParaFrameworkPath,
  43. parapackagepath : TSearchPathList;
  44. ParaAlignment : TAlignmentInfo;
  45. parapackages : tfphashobjectlist;
  46. paratarget : tsystem;
  47. paratargetasm : tasm;
  48. paratargetdbg : tdbg;
  49. LinkTypeSetExplicitly : boolean;
  50. LinkerSetExplicitly : boolean;
  51. Constructor Create;
  52. Destructor Destroy;override;
  53. procedure WriteLogo;
  54. procedure WriteInfo (More: string);
  55. procedure WriteHelpPages;
  56. procedure WriteQuickInfo;
  57. procedure IllegalPara(const opt:TCmdStr);
  58. procedure UnsupportedPara(const opt:TCmdStr);
  59. procedure IgnoredPara(const opt:TCmdStr);
  60. function Unsetbool(var Opts:TCmdStr; Pos: Longint; const FullPara: TCmdStr; RequireBoolPara: Boolean):boolean;
  61. procedure interpret_option(const opt :TCmdStr;ispara:boolean);
  62. procedure Interpret_envvar(const envname : TCmdStr);
  63. procedure Interpret_file(const filename : TPathStr);
  64. procedure Read_Parameters;
  65. procedure parsecmd(cmd:TCmdStr);
  66. procedure TargetOptions(def:boolean);
  67. procedure CheckOptionsCompatibility;
  68. procedure ForceStaticLinking;
  69. protected
  70. MacVersionSet: boolean;
  71. processorstr: TCmdStr;
  72. function ParseMacVersionMin(out minstr, emptystr: string; const compvarname, value: string; ios: boolean): boolean;
  73. procedure MaybeSetDefaultMacVersionMacro;
  74. procedure VerifyTargetProcessor;
  75. end;
  76. TOptionClass=class of toption;
  77. var
  78. coption : TOptionClass;
  79. procedure read_arguments(cmd:TCmdStr);
  80. implementation
  81. uses
  82. widestr,
  83. {$if FPC_FULLVERSION<20700}ccharset{$else}charset{$endif},
  84. SysUtils,
  85. version,
  86. cutils,cmsgs,
  87. comphook,
  88. symtable,scanner,rabase,
  89. symconst,
  90. {$ifdef llvm}
  91. { override supported optimizer transformations at the compiler level }
  92. llvminfo,
  93. {$endif llvm}
  94. dirparse,
  95. pkgutil,
  96. i_bsd;
  97. const
  98. page_size = 24;
  99. page_width = 80;
  100. var
  101. option : toption;
  102. read_configfile, { read config file, set when a cfgfile is found }
  103. disable_configfile : boolean;
  104. fpcdir,
  105. ppccfg,
  106. param_file : string; { file to compile specified on the commandline }
  107. {****************************************************************************
  108. Options not supported on all platforms
  109. ****************************************************************************}
  110. const
  111. { gprof (requires implementation of g_profilecode in the code generator) }
  112. supported_targets_pg = [system_i386_linux,system_x86_64_linux,system_mipseb_linux,system_mipsel_linux,system_arm_linux]
  113. + [system_i386_win32]
  114. + [system_powerpc_darwin,system_x86_64_darwin]
  115. + [system_i386_GO32V2]
  116. + [system_i386_freebsd]
  117. + [system_i386_netbsd]
  118. + [system_i386_wdosx];
  119. suppported_targets_x_smallr = systems_linux + systems_solaris
  120. + [system_i386_haiku]
  121. + [system_i386_beos]
  122. + [system_m68k_amiga];
  123. {****************************************************************************
  124. Defines
  125. ****************************************************************************}
  126. procedure set_default_link_type;
  127. begin
  128. undef_system_macro('FPC_LINK_SMART');
  129. def_system_macro('FPC_LINK_STATIC');
  130. undef_system_macro('FPC_LINK_DYNAMIC');
  131. init_settings.globalswitches:=init_settings.globalswitches+[cs_link_static];
  132. init_settings.globalswitches:=init_settings.globalswitches-[cs_link_shared,cs_link_smart];
  133. {$ifdef AIX}
  134. init_settings.globalswitches:=init_settings.globalswitches+[cs_link_native];
  135. {$endif}
  136. end;
  137. {****************************************************************************
  138. Toption
  139. ****************************************************************************}
  140. procedure StopOptions(err:longint);
  141. begin
  142. if assigned(Option) then
  143. begin
  144. Option.free;
  145. Option:=nil;
  146. end;
  147. raise ECompilerAbortSilent.Create;
  148. end;
  149. function is_identifier(const s: TCmdStr): boolean;
  150. var
  151. i: longint;
  152. begin
  153. result:=false;
  154. if (s='') or not (s[1] in ['A'..'Z','a'..'z','_']) then
  155. exit;
  156. for i:=2 to length(s) do
  157. if not (s[I] in ['A'..'Z','a'..'z','0'..'9','_']) then
  158. exit;
  159. result:=true;
  160. end;
  161. procedure Toption.WriteLogo;
  162. var
  163. msg : TMsgStr;
  164. p : pchar;
  165. begin
  166. if not LogoWritten then
  167. begin
  168. msg:=MessageStr(option_logo);
  169. p:=pchar(msg);
  170. while assigned(p) do
  171. Comment(V_Normal,GetMsgLine(p));
  172. LogoWritten:= true;
  173. end;
  174. end;
  175. procedure Toption.WriteInfo (More: string);
  176. var
  177. msg_str: TMsgStr;
  178. p : pchar;
  179. hs,hs1,hs3,s : TCmdStr;
  180. J: longint;
  181. const
  182. NewLineStr = '$\n';
  183. OSTargetsPlaceholder = '$OSTARGETS';
  184. CPUListPlaceholder = '$INSTRUCTIONSETS';
  185. FPUListPlaceholder = '$FPUINSTRUCTIONSETS';
  186. ABIListPlaceholder = '$ABITARGETS';
  187. OptListPlaceholder = '$OPTIMIZATIONS';
  188. WPOListPlaceholder = '$WPOPTIMIZATIONS';
  189. AsmModeListPlaceholder = '$ASMMODES';
  190. ControllerListPlaceholder = '$CONTROLLERTYPES';
  191. FeatureListPlaceholder = '$FEATURELIST';
  192. procedure SplitLine (var OrigString: TCmdStr; const Placeholder: TCmdStr;
  193. var RemainderString: TCmdStr);
  194. var
  195. I: longint;
  196. HS2: TCmdStr;
  197. begin
  198. RemainderString := '';
  199. if OrigString = '' then
  200. Exit;
  201. repeat
  202. I := Pos (NewLineStr, OrigString);
  203. if I > 0 then
  204. begin
  205. HS2 := Copy (OrigString, 1, Pred (I));
  206. { Stop if this line contains the placeholder for list replacement }
  207. if Pos (Placeholder, HS2) > 0 then
  208. begin
  209. RemainderString := Copy (OrigString, I + Length (NewLineStr),
  210. Length (OrigString) - I - Length (NewLineStr));
  211. { Special case - NewLineStr at the end of the line }
  212. if RemainderString = '' then
  213. RemainderString := NewLineStr;
  214. OrigString := HS2;
  215. Exit;
  216. end;
  217. Comment (V_Normal, HS2);
  218. Delete (OrigString, 1, Pred (I) + Length (NewLineStr));
  219. end;
  220. until I = 0;
  221. if (OrigString <> '') and (Pos (Placeholder, OrigString) = 0) then
  222. Comment (V_Normal, OrigString);
  223. end;
  224. procedure ListOSTargets (OrigString: TCmdStr);
  225. var
  226. target : tsystem;
  227. begin
  228. SplitLine (OrigString, OSTargetsPlaceholder, HS3);
  229. for target:=low(tsystem) to high(tsystem) do
  230. if assigned(targetinfos[target]) then
  231. begin
  232. hs1:=targetinfos[target]^.shortname;
  233. if OrigString = '' then
  234. WriteLn (hs1)
  235. else
  236. begin
  237. hs := OrigString;
  238. hs1:=hs1 + ': ' + targetinfos[target]^.name;
  239. if tf_under_development in targetinfos[target]^.flags then
  240. hs1:=hs1+' {*}';
  241. Replace(hs,OSTargetsPlaceholder,hs1);
  242. Comment(V_Normal,hs);
  243. end;
  244. end;
  245. OrigString := HS3;
  246. SplitLine (OrigString, OSTargetsPlaceholder, HS3);
  247. end;
  248. procedure ListCPUInstructionSets (OrigString: TCmdStr);
  249. var
  250. cpu : tcputype;
  251. begin
  252. SplitLine (OrigString, CPUListPlaceholder, HS3);
  253. hs1:='';
  254. for cpu:=low(tcputype) to high(tcputype) do
  255. begin
  256. if (OrigString = '') then
  257. begin
  258. if CPUTypeStr [CPU] <> '' then
  259. WriteLn (CPUTypeStr [CPU]);
  260. end
  261. else
  262. begin
  263. if length(hs1+cputypestr[cpu])>70 then
  264. begin
  265. hs:=OrigString;
  266. Replace(hs,CPUListPlaceholder,hs1);
  267. Comment(V_Normal,hs);
  268. hs1:=''
  269. end
  270. else if hs1<>'' then
  271. hs1:=hs1+',';
  272. if cputypestr[cpu]<>'' then
  273. hs1:=hs1+cputypestr[cpu];
  274. end;
  275. end;
  276. if (OrigString <> '') and (hs1 <> '') then
  277. begin
  278. hs:=OrigString;
  279. Replace(hs,CPUListPlaceholder,hs1);
  280. Comment(V_Normal,hs);
  281. hs1:=''
  282. end;
  283. OrigString := HS3;
  284. SplitLine (OrigString, CPUListPlaceholder, HS3);
  285. end;
  286. procedure ListFPUInstructionSets (OrigString: TCmdStr);
  287. var
  288. fpu : tfputype;
  289. begin
  290. SplitLine (OrigString, FPUListPlaceholder, HS3);
  291. hs1:='';
  292. for fpu:=low(tfputype) to high(tfputype) do
  293. begin
  294. if (OrigString = '') then
  295. begin
  296. if FPUTypeStr [FPU] <> '' then
  297. WriteLn (FPUTypeStr [FPU]);
  298. end
  299. else
  300. begin
  301. if length(hs1+fputypestr[fpu])>70 then
  302. begin
  303. hs:=OrigString;
  304. Replace(hs,FPUListPlaceholder,hs1);
  305. Comment(V_Normal,hs);
  306. hs1:=''
  307. end
  308. else if hs1<>'' then
  309. hs1:=hs1+',';
  310. if fputypestr[fpu]<>'' then
  311. hs1:=hs1+fputypestr[fpu];
  312. end;
  313. end;
  314. if (OrigString <> '') and (hs1 <> '') then
  315. begin
  316. hs:=OrigString;
  317. Replace(hs,FPUListPlaceholder,hs1);
  318. Comment(V_Normal,hs);
  319. hs1:=''
  320. end;
  321. OrigString := HS3;
  322. SplitLine (OrigString, FPUListPlaceholder, HS3);
  323. end;
  324. procedure ListABITargets (OrigString: TCmdStr);
  325. var
  326. abi : tabi;
  327. begin
  328. SplitLine (OrigString, ABIListPlaceholder, HS3);
  329. for abi:=low(abi) to high(abi) do
  330. begin
  331. if not abiinfo[abi].supported then
  332. continue;
  333. hs1:=abiinfo[abi].name;
  334. if hs1<>'' then
  335. begin
  336. if OrigString = '' then
  337. WriteLn (HS1)
  338. else
  339. begin
  340. hs:=OrigString;
  341. Replace(hs,ABIListPlaceholder,hs1);
  342. Comment(V_Normal,hs);
  343. end;
  344. end;
  345. end;
  346. OrigString := HS3;
  347. SplitLine (OrigString, ABIListPlaceholder, HS3);
  348. end;
  349. procedure ListOptimizations (OrigString: TCmdStr);
  350. var
  351. opt : toptimizerswitch;
  352. begin
  353. SplitLine (OrigString, OptListPlaceholder, HS3);
  354. for opt:=low(toptimizerswitch) to high(toptimizerswitch) do
  355. begin
  356. if opt in supported_optimizerswitches then
  357. begin
  358. hs1:=OptimizerSwitchStr[opt];
  359. if hs1<>'' then
  360. begin
  361. if OrigString = '' then
  362. WriteLn (hs1)
  363. else
  364. begin
  365. hs:=OrigString;
  366. Replace(hs,OptListPlaceholder,hs1);
  367. Comment(V_Normal,hs);
  368. end;
  369. end;
  370. end;
  371. end;
  372. OrigString := HS3;
  373. SplitLine (OrigString, OptListPlaceholder, HS3);
  374. end;
  375. procedure ListWPOptimizations (OrigString: TCmdStr);
  376. var
  377. wpopt: twpoptimizerswitch;
  378. begin
  379. SplitLine (OrigString, WPOListPlaceholder, HS3);
  380. for wpopt:=low(twpoptimizerswitch) to high(twpoptimizerswitch) do
  381. begin
  382. { currently all whole program optimizations are platform-independent
  383. if opt in supported_wpoptimizerswitches then
  384. }
  385. begin
  386. hs1:=WPOptimizerSwitchStr[wpopt];
  387. if hs1<>'' then
  388. begin
  389. if OrigString = '' then
  390. WriteLn (hs1)
  391. else
  392. begin
  393. hs:=OrigString;
  394. Replace(hs,WPOListPlaceholder,hs1);
  395. Comment(V_Normal,hs);
  396. end;
  397. end;
  398. end;
  399. end;
  400. OrigString := HS3;
  401. SplitLine (OrigString, WPOListPlaceholder, HS3);
  402. end;
  403. procedure ListAsmModes (OrigString: TCmdStr);
  404. var
  405. asmmode : tasmmode;
  406. begin
  407. SplitLine (OrigString, AsmModeListPlaceholder, HS3);
  408. for asmmode:=low(tasmmode) to high(tasmmode) do
  409. if assigned(asmmodeinfos[asmmode]) then
  410. begin
  411. hs1:=asmmodeinfos[asmmode]^.idtxt;
  412. if hs1<>'' then
  413. begin
  414. if OrigString = '' then
  415. WriteLn (hs1)
  416. else
  417. begin
  418. hs:=OrigString;
  419. Replace(hs,AsmModeListPlaceholder,hs1);
  420. Comment(V_Normal,hs);
  421. end;
  422. end;
  423. end;
  424. OrigString := HS3;
  425. SplitLine (OrigString, AsmModeListPlaceholder, HS3);
  426. end;
  427. procedure ListControllerTypes (OrigString: TCmdStr);
  428. var
  429. controllertype : tcontrollertype;
  430. begin
  431. {$PUSH}
  432. {$WARN 6018 OFF} (* Unreachable code due to compile time evaluation *)
  433. if (ControllerSupport) then
  434. begin
  435. SplitLine (OrigString, ControllerListPlaceholder, HS3);
  436. hs1:='';
  437. for controllertype:=low(tcontrollertype) to high(tcontrollertype) do
  438. begin
  439. if (OrigString = '') then
  440. begin
  441. if Embedded_Controllers [ControllerType].ControllerTypeStr <> '' then
  442. WriteLn (Embedded_Controllers [ControllerType].ControllerTypeStr);
  443. end
  444. else
  445. begin
  446. if length(hs1+embedded_controllers[controllertype].ControllerTypeStr)
  447. >70 then
  448. begin
  449. hs:=OrigString;
  450. Replace(hs,ControllerListPlaceholder,hs1);
  451. Comment(V_Normal,hs);
  452. hs1:=''
  453. end
  454. else if hs1<>'' then
  455. hs1:=hs1+',';
  456. if embedded_controllers[controllertype].ControllerTypeStr<>'' then
  457. hs1:=hs1+embedded_controllers[controllertype].ControllerTypeStr;
  458. end;
  459. end;
  460. if (OrigString <> '') and (hs1<>'') then
  461. begin
  462. hs:=OrigString;
  463. Replace(hs,ControllerListPlaceholder,hs1);
  464. Comment(V_Normal,hs);
  465. hs1:=''
  466. end;
  467. OrigString := HS3;
  468. SplitLine (OrigString, ControllerListPlaceholder, HS3);
  469. end;
  470. {$POP}
  471. end;
  472. procedure ListFeatures (OrigString: TCmdStr);
  473. var
  474. Feature: TFeature;
  475. begin
  476. SplitLine (OrigString, FeatureListPlaceholder, HS3);
  477. HS1 := '';
  478. for Feature := Low (TFeature) to High (TFeature) do
  479. begin
  480. if (OrigString = '') then
  481. begin
  482. if FeatureStr [Feature] <> '' then
  483. WriteLn (FeatureStr [Feature]);
  484. end
  485. else
  486. begin
  487. if Length (HS1 + FeatureStr [Feature]) > 70 then
  488. begin
  489. HS := OrigString;
  490. Replace (HS, FeatureListPlaceholder, HS1);
  491. Comment (V_Normal, HS);
  492. HS1 := ''
  493. end
  494. else if HS1 <> '' then
  495. HS1 := HS1 + ',';
  496. if FeatureStr [Feature] <> '' then
  497. HS1 := HS1 + FeatureStr [Feature];
  498. end;
  499. end;
  500. if (OrigString <> '') and (HS1 <> '') then
  501. begin
  502. HS := OrigString;
  503. Replace (HS, FeatureListPlaceholder, HS1);
  504. Comment (V_Normal, HS);
  505. HS1 := ''
  506. end;
  507. OrigString := HS3;
  508. SplitLine (OrigString, FeatureListPlaceholder, HS3);
  509. end;
  510. begin
  511. if More = '' then
  512. begin
  513. msg_str:=MessageStr(option_info);
  514. p:=pchar(msg_str);
  515. while assigned(p) do
  516. begin
  517. s:=GetMsgLine(p);
  518. { list permitted values for certain options }
  519. if pos(OSTargetsPlaceholder,s)>0 then
  520. ListOSTargets (S)
  521. else if pos(CPUListPlaceholder,s)>0 then
  522. ListCPUInstructionSets (S)
  523. else if pos(FPUListPlaceholder,s)>0 then
  524. ListFPUInstructionSets (S)
  525. else if pos(ABIListPlaceholder,s)>0 then
  526. ListABITargets (S)
  527. else if pos(OptListPlaceholder,s)>0 then
  528. ListOptimizations (S)
  529. else if pos(WPOListPlaceholder,s)>0 then
  530. ListWPOptimizations (S)
  531. else if pos(AsmModeListPlaceholder,s)>0 then
  532. ListAsmModes (S)
  533. else if pos(ControllerListPlaceholder,s)>0 then
  534. ListControllerTypes (S)
  535. else if pos(FeatureListPlaceholder,s)>0 then
  536. ListFeatures (S)
  537. else
  538. Comment(V_Normal,s);
  539. end;
  540. end
  541. else
  542. begin
  543. J := 1;
  544. while J <= Length (More) do
  545. begin
  546. if J > 1 then
  547. WriteLn; (* Put empty line between multiple sections *)
  548. case More [J] of
  549. 'a': ListABITargets ('');
  550. 'c': ListCPUInstructionSets ('');
  551. 'f': ListFPUInstructionSets ('');
  552. 'i': ListAsmModes ('');
  553. 'o': ListOptimizations ('');
  554. 'r': ListFeatures ('');
  555. 't': ListOSTargets ('');
  556. 'u': ListControllerTypes ('');
  557. 'w': ListWPOptimizations ('');
  558. else
  559. IllegalPara ('-i' + More);
  560. end;
  561. Inc (J);
  562. end;
  563. end;
  564. StopOptions(0);
  565. end;
  566. procedure Toption.WriteHelpPages;
  567. function PadEnd(s:string;i:longint):string;
  568. begin
  569. if length(s) >= i then
  570. S := S + ' '
  571. else
  572. while (length(s)<i) do
  573. s:=s+' ';
  574. PadEnd:=s;
  575. end;
  576. var
  577. lastident,
  578. j,outline,
  579. ident,
  580. HelpLineHeight,
  581. lines : longint;
  582. show : boolean;
  583. opt : string[32];
  584. input,
  585. HelpLine,
  586. s : string;
  587. p : pchar;
  588. msg_str: TMsgStr;
  589. begin
  590. WriteLogo;
  591. Lines:=4;
  592. if FPCHelpLines then
  593. Message1(option_usage,FixFileName(FPCBinaryPath))
  594. else
  595. Message1(option_usage,FixFileName(system.paramstr(0)));
  596. lastident:=0;
  597. msg_str:=MessageStr(option_help_pages);
  598. p:=pchar(msg_str);
  599. while assigned(p) do
  600. begin
  601. { get a line and reset }
  602. s:=GetMsgLine(p);
  603. ident:=0;
  604. show:=false;
  605. { parse options }
  606. case s[1] of
  607. 'F': if FPCHelpLines then
  608. Show := true;
  609. {$ifdef UNITALIASES}
  610. 'a',
  611. {$endif}
  612. {$ifdef EXTDEBUG}
  613. 'e',
  614. {$endif EXTDEBUG}
  615. {$ifdef i386}
  616. '3',
  617. {$endif}
  618. {$ifdef x86_64}
  619. '4',
  620. {$endif}
  621. {$ifdef m68k}
  622. '6',
  623. {$endif}
  624. {$ifdef i8086}
  625. '8',
  626. {$endif}
  627. {$ifdef aarch64}
  628. 'a',
  629. {$endif}
  630. {$ifdef arm}
  631. 'A',
  632. {$endif}
  633. {$ifdef mipsel}
  634. 'm',
  635. {$endif}
  636. {$ifdef mipseb}
  637. 'M',
  638. {$endif}
  639. {$ifdef powerpc}
  640. 'P',
  641. {$endif}
  642. {$ifdef powerpc64}
  643. 'p',
  644. {$endif}
  645. {$ifdef sparc}
  646. 'S',
  647. {$endif}
  648. {$ifdef sparc64}
  649. 's',
  650. {$endif}
  651. {$ifdef avr}
  652. 'V',
  653. {$endif}
  654. {$ifdef jvm}
  655. 'J',
  656. {$endif}
  657. '*' : show:=true;
  658. end;
  659. if show then
  660. begin
  661. case s[2] of
  662. 'g',
  663. {$ifdef Unix}
  664. 'L',
  665. {$endif}
  666. {$ifdef os2}
  667. 'O',
  668. {$endif}
  669. '*' : show:=true;
  670. else
  671. show:=false;
  672. end;
  673. end;
  674. { now we may show the message or not }
  675. if show then
  676. begin
  677. case s[3] of
  678. '0' : begin
  679. ident:=0;
  680. outline:=0;
  681. end;
  682. '1' : begin
  683. ident:=2;
  684. outline:=7;
  685. end;
  686. '2' : begin
  687. ident:=6;
  688. outline:=11;
  689. end;
  690. '3' : begin
  691. ident:=9;
  692. outline:=11;
  693. end;
  694. else
  695. internalerror(2013112906);
  696. end;
  697. j:=pos('_',s);
  698. opt:=Copy(s,4,j-4);
  699. if opt='*' then
  700. opt:=''
  701. else
  702. if (opt=' ') or (opt[1]='@') then
  703. opt:=PadEnd(opt,outline)
  704. else
  705. opt:=PadEnd('-'+opt,outline);
  706. if (ident=0) and (lastident<>0) then
  707. begin
  708. Comment(V_Normal,'');
  709. inc(Lines);
  710. end;
  711. HelpLine := PadEnd('',ident)+opt+Copy(s,j+1,255);
  712. if HelpLine = '' then
  713. HelpLineHeight := 1
  714. else
  715. HelpLineHeight := Succ (CharLength (HelpLine) div Page_Width);
  716. { page full ? }
  717. if (lines + HelpLineHeight >= page_size - 1) then
  718. begin
  719. if not NoPressEnter then
  720. begin
  721. Message(option_help_press_enter);
  722. readln(input);
  723. if upper(input)='Q' then
  724. StopOptions(0);
  725. end;
  726. lines:=0;
  727. end;
  728. Comment(V_Normal,HelpLine);
  729. LastIdent:=Ident;
  730. Inc (Lines, HelpLineHeight);
  731. end;
  732. end;
  733. StopOptions(0);
  734. end;
  735. procedure Toption.IllegalPara(const opt:TCmdStr);
  736. begin
  737. Message1(option_illegal_para,opt);
  738. Message(option_help_pages_para);
  739. StopOptions(1);
  740. end;
  741. procedure toption.UnsupportedPara(const opt: TCmdStr);
  742. begin
  743. Message1(option_unsupported_target,opt);
  744. StopOptions(1);
  745. end;
  746. procedure toption.IgnoredPara(const opt: TCmdStr);
  747. begin
  748. Message1(option_ignored_target,opt);
  749. end;
  750. procedure toption.ForceStaticLinking;
  751. begin
  752. def_system_macro('FPC_LINK_STATIC');
  753. undef_system_macro('FPC_LINK_SMART');
  754. undef_system_macro('FPC_LINK_DYNAMIC');
  755. include(init_settings.globalswitches,cs_link_static);
  756. exclude(init_settings.globalswitches,cs_link_smart);
  757. exclude(init_settings.globalswitches,cs_link_shared);
  758. LinkTypeSetExplicitly:=true;
  759. end;
  760. function toption.ParseMacVersionMin(out minstr, emptystr: string; const compvarname, value: string; ios: boolean): boolean;
  761. function subval(start,maxlen: longint; out stop: longint): string;
  762. var
  763. i: longint;
  764. begin
  765. result:='';
  766. i:=start;
  767. while (i<=length(value)) and
  768. (value[i] in ['0'..'9']) do
  769. inc(i);
  770. { sufficient amount of digits? }
  771. if (i=start) or
  772. (i-start>maxlen) then
  773. exit;
  774. result:=copy(value,start,i-start);
  775. stop:=i;
  776. end;
  777. var
  778. temp,
  779. compvarvalue: string[15];
  780. i: longint;
  781. osx_minor_two_digits: boolean;
  782. begin
  783. minstr:=value;
  784. emptystr:='';
  785. MacVersionSet:=false;
  786. { check whether the value is a valid version number }
  787. if value='' then
  788. begin
  789. undef_system_macro(compvarname);
  790. exit(true);
  791. end;
  792. { major version number }
  793. compvarvalue:=subval(1,2,i);
  794. { not enough digits -> invalid }
  795. if compvarvalue='' then
  796. exit(false);
  797. { already end of string -> invalid }
  798. if (i>=length(value)) or
  799. (value[i]<>'.') then
  800. exit(false);
  801. { minor version number }
  802. temp:=subval(i+1,2,i);
  803. if temp='' then
  804. exit(false);
  805. { on Mac OS X, the minor version number was originally limited to 1 digit;
  806. with 10.10 the format changed and two digits were also supported; on iOS,
  807. the minor version number always takes up two digits }
  808. osx_minor_two_digits:=false;
  809. if not ios then
  810. begin
  811. { if the minor version number is two digits on OS X (the case since
  812. OS X 10.10), we also have to add two digits for the patch level}
  813. if length(temp)=2 then
  814. osx_minor_two_digits:=true;
  815. end
  816. { the minor version number always takes up two digits on iOS }
  817. else if length(temp)=1 then
  818. temp:='0'+temp;
  819. compvarvalue:=compvarvalue+temp;
  820. { optional patch level }
  821. if i<=length(value) then
  822. begin
  823. if value[i]<>'.' then
  824. exit(false);
  825. temp:=subval(i+1,2,i);
  826. if temp='' then
  827. exit(false);
  828. { there's only room for a single digit patch level in the version macro
  829. for Mac OS X. gcc sets it to zero if there are more digits, but that
  830. seems worse than clamping to 9 (don't declare as invalid like with
  831. minor version number, because there is a precedent like 10.4.11).
  832. As of OS X 10.10 there are two digits for the patch level
  833. }
  834. if not ios and
  835. not osx_minor_two_digits then
  836. begin
  837. if length(temp)<>1 then
  838. temp:='9';
  839. end
  840. else
  841. begin
  842. { on iOS, the patch level is always two digits }
  843. if length(temp)=1 then
  844. temp:='0'+temp;
  845. end;
  846. compvarvalue:=compvarvalue+temp;
  847. { must be the end }
  848. if i<=length(value) then
  849. exit(false);
  850. end
  851. else if not ios and
  852. not osx_minor_two_digits then
  853. compvarvalue:=compvarvalue+'0'
  854. else
  855. compvarvalue:=compvarvalue+'00';
  856. set_system_compvar(compvarname,compvarvalue);
  857. MacVersionSet:=true;
  858. result:=true;
  859. end;
  860. procedure TOption.MaybeSetDefaultMacVersionMacro;
  861. var
  862. envstr: ansistring;
  863. begin
  864. if not(target_info.system in systems_darwin) then
  865. exit;
  866. if MacVersionSet then
  867. exit;
  868. { check for deployment target set via environment variable }
  869. if not(target_info.system in [system_i386_iphonesim,system_arm_darwin,system_aarch64_darwin,system_x86_64_iphonesim]) then
  870. begin
  871. envstr:=GetEnvironmentVariable('MACOSX_DEPLOYMENT_TARGET');
  872. if envstr<>'' then
  873. if not ParseMacVersionMin(MacOSXVersionMin,iPhoneOSVersionMin,'MAC_OS_X_VERSION_MIN_REQUIRED',envstr,false) then
  874. Message1(option_invalid_macosx_deployment_target,envstr)
  875. else
  876. exit;
  877. end
  878. else
  879. begin
  880. envstr:=GetEnvironmentVariable('IPHONEOS_DEPLOYMENT_TARGET');
  881. if envstr<>'' then
  882. if not ParseMacVersionMin(iPhoneOSVersionMin,MacOSXVersionMin,'IPHONE_OS_VERSION_MIN_REQUIRED',envstr,true) then
  883. Message1(option_invalid_iphoneos_deployment_target,envstr)
  884. else
  885. exit;
  886. end;
  887. { nothing specified -> defaults }
  888. case target_info.system of
  889. system_powerpc_darwin:
  890. begin
  891. set_system_compvar('MAC_OS_X_VERSION_MIN_REQUIRED','1030');
  892. MacOSXVersionMin:='10.3';
  893. end;
  894. system_powerpc64_darwin,
  895. system_i386_darwin:
  896. begin
  897. set_system_compvar('MAC_OS_X_VERSION_MIN_REQUIRED','1040');
  898. MacOSXVersionMin:='10.4';
  899. end;
  900. system_x86_64_darwin:
  901. begin
  902. { actually already works on 10.4, but it's unlikely any 10.4 system
  903. with an x86-64 is still in use, so don't default to it }
  904. set_system_compvar('MAC_OS_X_VERSION_MIN_REQUIRED','1050');
  905. MacOSXVersionMin:='10.5';
  906. end;
  907. system_arm_darwin,
  908. system_i386_iphonesim:
  909. begin
  910. set_system_compvar('IPHONE_OS_VERSION_MIN_REQUIRED','30000');
  911. iPhoneOSVersionMin:='3.0';
  912. end;
  913. system_aarch64_darwin,
  914. system_x86_64_iphonesim:
  915. begin
  916. set_system_compvar('IPHONE_OS_VERSION_MIN_REQUIRED','70000');
  917. iPhoneOSVersionMin:='7.0';
  918. end
  919. else
  920. internalerror(2012031001);
  921. end;
  922. end;
  923. procedure TOption.VerifyTargetProcessor;
  924. begin
  925. { no custom target processor specified -> ok }
  926. if processorstr='' then
  927. exit;
  928. { custom target processor specified -> verify it's the one we support }
  929. if upcase(processorstr)<>upcase(target_cpu_string) then
  930. Message1(option_invalid_target_architecture,processorstr);
  931. end;
  932. function Toption.Unsetbool(var Opts:TCmdStr; Pos: Longint; const FullPara: TCmdStr; RequireBoolPara: boolean):boolean;
  933. { checks if the character after pos in Opts is a + or a - and returns resp.
  934. false or true. If it is another character (or none), it also returns false }
  935. begin
  936. UnsetBool := false;
  937. if Length(Opts)>Pos then
  938. begin
  939. inc(Pos);
  940. UnsetBool := Opts[Pos] = '-';
  941. if Opts[Pos] in ['-','+']then
  942. delete(Opts,Pos,1)
  943. else if RequireBoolPara then
  944. IllegalPara(FullPara);
  945. end;
  946. end;
  947. procedure TOption.interpret_option(const opt:TCmdStr;ispara:boolean);
  948. var
  949. code : integer;
  950. c : char;
  951. more : TCmdStr;
  952. major,minor : longint;
  953. error : integer;
  954. j,l : longint;
  955. d,s : TCmdStr;
  956. hs : TCmdStr;
  957. unicodemapping : punicodemap;
  958. begin
  959. if opt='' then
  960. exit;
  961. { only parse define,undef,target,verbosity,link etc options the firsttime }
  962. if firstpass and
  963. not(
  964. (opt[1]='-') and
  965. (
  966. ((length(opt)>1) and (opt[2] in ['i','d','v','T','u','n','X','l'])) or
  967. ((length(opt)>3) and (opt[2]='F') and (opt[3]='e')) or
  968. ((length(opt)>3) and (opt[2]='C') and (opt[3]='p')) or
  969. ((length(opt)>3) and (opt[2]='W') and (opt[3] in ['m','p']))
  970. )
  971. ) then
  972. exit;
  973. Message1(option_handling_option,opt);
  974. case opt[1] of
  975. '-' :
  976. begin
  977. more:=Copy(opt,3,2147483647);
  978. if firstpass then
  979. Message1(option_interpreting_firstpass_option,opt)
  980. else
  981. Message1(option_interpreting_option,opt);
  982. case opt[2] of
  983. '?' :
  984. begin
  985. if (More <> '') and (More [1] = 'F') then
  986. begin
  987. FPCHelpLines := true;
  988. Delete (More, 1, 1);
  989. FPCBinaryPath := More;
  990. end;
  991. WriteHelpPages;
  992. end;
  993. 'a' :
  994. begin
  995. include(init_settings.globalswitches,cs_asm_leave);
  996. j:=1;
  997. while j<=length(more) do
  998. begin
  999. case more[j] of
  1000. '5' :
  1001. if target_info.system in systems_all_windows+systems_nativent-[system_i8086_win16] then
  1002. begin
  1003. if UnsetBool(More, j, opt, false) then
  1004. exclude(init_settings.globalswitches,cs_asm_pre_binutils_2_25)
  1005. else
  1006. include(init_settings.globalswitches,cs_asm_pre_binutils_2_25);
  1007. end
  1008. else
  1009. IllegalPara(opt);
  1010. 'l' :
  1011. include(init_settings.globalswitches,cs_asm_source);
  1012. 'r' :
  1013. include(init_settings.globalswitches,cs_asm_regalloc);
  1014. 't' :
  1015. include(init_settings.globalswitches,cs_asm_tempalloc);
  1016. 'n' :
  1017. include(init_settings.globalswitches,cs_asm_nodes);
  1018. { -ao option must be the last, everything behind it is passed directly to
  1019. external assembler, it is ignored if internal assembler is used. }
  1020. 'o' :
  1021. begin
  1022. asmextraopt:=copy(more,j+1,length(more)-j);
  1023. break;
  1024. end;
  1025. 'p' :
  1026. begin
  1027. exclude(init_settings.globalswitches,cs_asm_leave);
  1028. if UnsetBool(More, 0, opt, false) then
  1029. exclude(init_settings.globalswitches,cs_asm_pipe)
  1030. else
  1031. include(init_settings.globalswitches,cs_asm_pipe);
  1032. end;
  1033. '-' :
  1034. init_settings.globalswitches:=init_settings.globalswitches -
  1035. [cs_asm_leave, cs_asm_source,cs_asm_regalloc, cs_asm_tempalloc,
  1036. cs_asm_nodes, cs_asm_pipe];
  1037. else
  1038. IllegalPara(opt);
  1039. end;
  1040. inc(j);
  1041. end;
  1042. end;
  1043. 'A' :
  1044. begin
  1045. paratargetasm:=find_asm_by_string(More);
  1046. if paratargetasm=as_none then
  1047. IllegalPara(opt);
  1048. end;
  1049. 'b' :
  1050. begin
  1051. // Message1(option_obsolete_switch,'-b');
  1052. if UnsetBool(More,0,opt,false) then
  1053. begin
  1054. init_settings.moduleswitches:=init_settings.moduleswitches-[cs_browser];
  1055. init_settings.moduleswitches:=init_settings.moduleswitches-[cs_local_browser];
  1056. end
  1057. else
  1058. begin
  1059. init_settings.moduleswitches:=init_settings.moduleswitches+[cs_browser];
  1060. end;
  1061. if More<>'' then
  1062. if (More='l') or (More='l+') then
  1063. init_settings.moduleswitches:=init_settings.moduleswitches+[cs_local_browser]
  1064. else if More='l-' then
  1065. init_settings.moduleswitches:=init_settings.moduleswitches-[cs_local_browser]
  1066. else
  1067. IllegalPara(opt);
  1068. end;
  1069. 'B' :
  1070. do_build:=not UnSetBool(more,0,opt,true);
  1071. 'C' :
  1072. begin
  1073. j:=1;
  1074. while j<=length(more) do
  1075. begin
  1076. case more[j] of
  1077. '3' :
  1078. If UnsetBool(More, j, opt, false) then
  1079. exclude(init_settings.localswitches,cs_ieee_errors)
  1080. Else
  1081. include(init_settings.localswitches,cs_ieee_errors);
  1082. 'a' :
  1083. begin
  1084. s:=upper(copy(more,j+1,length(more)-j));
  1085. if not(SetAbiType(s,target_info.abi)) then
  1086. IllegalPara(opt);
  1087. ABISetExplicitly:=true;
  1088. break;
  1089. end;
  1090. 'b' :
  1091. begin
  1092. if UnsetBool(More, j, opt, false) then
  1093. target_info.endian:=endian_little
  1094. else
  1095. target_info.endian:=endian_big;
  1096. end;
  1097. 'c' :
  1098. begin
  1099. if not SetAktProcCall(upper(copy(more,j+1,length(more)-j)),init_settings.defproccall) then
  1100. IllegalPara(opt);
  1101. break;
  1102. end;
  1103. {$ifdef cpufpemu}
  1104. 'e' :
  1105. begin
  1106. If UnsetBool(More, j, opt, false) then
  1107. exclude(init_settings.moduleswitches,cs_fp_emulation)
  1108. Else
  1109. include(init_settings.moduleswitches,cs_fp_emulation);
  1110. end;
  1111. {$endif cpufpemu}
  1112. 'f' :
  1113. begin
  1114. s:=upper(copy(more,j+1,length(more)-j));
  1115. if not(SetFpuType(s,init_settings.fputype)) then
  1116. IllegalPara(opt);
  1117. FPUSetExplicitly:=True;
  1118. break;
  1119. end;
  1120. 'F' :
  1121. begin
  1122. if not SetMinFPConstPrec(copy(more,j+1,length(more)-j),init_settings.minfpconstprec) then
  1123. IllegalPara(opt);
  1124. break;
  1125. end;
  1126. 'g' :
  1127. begin
  1128. if tf_no_pic_supported in target_info.flags then
  1129. begin
  1130. { consume a possible '-' coming after it }
  1131. UnsetBool(More, j, opt, false);
  1132. message(scan_w_pic_ignored);
  1133. end
  1134. else if UnsetBool(More, j, opt, false) then
  1135. exclude(init_settings.moduleswitches,cs_create_pic)
  1136. else
  1137. include(init_settings.moduleswitches,cs_create_pic);
  1138. end;
  1139. 'h' :
  1140. begin
  1141. l:=pos(',',copy(more,j+1,length(more)-j));
  1142. if l=0 then
  1143. l:=length(more)-j+1;
  1144. val(copy(more,j+1,l-1),heapsize,code);
  1145. if (code<>0)
  1146. {$ifdef AVR}
  1147. or (heapsize<32)
  1148. {$else AVR}
  1149. or (heapsize<1024)
  1150. {$endif AVR}
  1151. then
  1152. IllegalPara(opt)
  1153. else if l<=length(more)-j then
  1154. begin
  1155. val(copy(more,j+l+1,length(more)),maxheapsize,code);
  1156. if code<>0 then
  1157. IllegalPara(opt)
  1158. else if (maxheapsize<heapsize) then
  1159. begin
  1160. message(scan_w_heapmax_lessthan_heapmin);
  1161. maxheapsize:=heapsize;
  1162. end;
  1163. end;
  1164. break;
  1165. end;
  1166. 'i' :
  1167. If UnsetBool(More, j, opt, false) then
  1168. exclude(init_settings.localswitches,cs_check_io)
  1169. else
  1170. include(init_settings.localswitches,cs_check_io);
  1171. {$ifdef arm}
  1172. 'I' :
  1173. begin
  1174. if (upper(copy(more,j+1,length(more)-j))='THUMB') and
  1175. { does selected CPU really understand thumb? }
  1176. (init_settings.cputype in cpu_has_thumb) then
  1177. init_settings.instructionset:=is_thumb
  1178. else if upper(copy(more,j+1,length(more)-j))='ARM' then
  1179. init_settings.instructionset:=is_arm
  1180. else
  1181. IllegalPara(opt);
  1182. break;
  1183. end;
  1184. {$endif arm}
  1185. 'n' :
  1186. If UnsetBool(More, j, opt, false) then
  1187. exclude(init_settings.globalswitches,cs_link_nolink)
  1188. Else
  1189. include(init_settings.globalswitches,cs_link_nolink);
  1190. 'N' :
  1191. If UnsetBool(More, j, opt, false) then
  1192. exclude(init_settings.localswitches,cs_check_low_addr_load)
  1193. Else
  1194. include(init_settings.localswitches,cs_check_low_addr_load);
  1195. 'o' :
  1196. If UnsetBool(More, j, opt, false) then
  1197. exclude(init_settings.localswitches,cs_check_overflow)
  1198. Else
  1199. include(init_settings.localswitches,cs_check_overflow);
  1200. 'O' :
  1201. If UnsetBool(More, j, opt, false) then
  1202. exclude(init_settings.localswitches,cs_check_ordinal_size)
  1203. Else
  1204. include(init_settings.localswitches,cs_check_ordinal_size);
  1205. 'p' :
  1206. begin
  1207. s:=upper(copy(more,j+1,length(more)-j));
  1208. if not(Setcputype(s,init_settings)) then
  1209. IllegalPara(opt);
  1210. CPUSetExplicitly:=true;
  1211. break;
  1212. end;
  1213. 'P':
  1214. begin
  1215. delete(more,1,1);
  1216. case upper(copy(more,1,pos('=',more)-1)) of
  1217. 'PACKSET':
  1218. begin
  1219. delete(more,1,pos('=',more));
  1220. case more of
  1221. '0','DEFAULT','NORMAL':
  1222. init_settings.setalloc:=0;
  1223. '1','2','4','8':
  1224. init_settings.setalloc:=StrToInt(more);
  1225. else
  1226. IllegalPara(opt);
  1227. end
  1228. end;
  1229. 'PACKENUM':
  1230. begin
  1231. delete(more,1,pos('=',more));
  1232. case more of
  1233. '0','DEFAULT','NORMAL':
  1234. init_settings.packenum:=4;
  1235. '1','2','4':
  1236. init_settings.packenum:=StrToInt(more);
  1237. else
  1238. IllegalPara(opt);
  1239. end;
  1240. end;
  1241. 'PACKRECORD':
  1242. begin
  1243. delete(more,1,pos('=',more));
  1244. case more of
  1245. '0','DEFAULT','NORMAL':
  1246. init_settings.packrecords:=default_settings.packrecords;
  1247. '1','2','4','8','16','32':
  1248. init_settings.packrecords:=StrToInt(more);
  1249. else
  1250. IllegalPara(opt);
  1251. end;
  1252. end
  1253. else
  1254. IllegalPara(opt);
  1255. end;
  1256. end;
  1257. 'r' :
  1258. If UnsetBool(More, j, opt, false) then
  1259. exclude(init_settings.localswitches,cs_check_range)
  1260. Else
  1261. include(init_settings.localswitches,cs_check_range);
  1262. 'R' :
  1263. If UnsetBool(More, j, opt, false) then
  1264. begin
  1265. exclude(init_settings.localswitches,cs_check_range);
  1266. exclude(init_settings.localswitches,cs_check_object);
  1267. end
  1268. Else
  1269. begin
  1270. include(init_settings.localswitches,cs_check_range);
  1271. include(init_settings.localswitches,cs_check_object);
  1272. end;
  1273. 's' :
  1274. begin
  1275. val(copy(more,j+1,length(more)-j),stacksize,code);
  1276. if (code<>0)
  1277. {$ifdef cpu16bitaddr}
  1278. or (stacksize>=65521)
  1279. {$else cpu16bitaddr}
  1280. or (stacksize>=67107840)
  1281. {$endif cpu16bitaddr}
  1282. or (stacksize<1024) then
  1283. IllegalPara(opt);
  1284. break;
  1285. end;
  1286. 't' :
  1287. If UnsetBool(More, j, opt, false) then
  1288. exclude(init_settings.localswitches,cs_check_stack)
  1289. Else
  1290. include(init_settings.localswitches,cs_check_stack);
  1291. 'D' :
  1292. If UnsetBool(More, j, opt, false) then
  1293. exclude(init_settings.moduleswitches,cs_create_dynamic)
  1294. Else
  1295. include(init_settings.moduleswitches,cs_create_dynamic);
  1296. 'X' :
  1297. If UnsetBool(More, j, opt, false) then
  1298. exclude(init_settings.moduleswitches,cs_create_smart)
  1299. Else
  1300. include(init_settings.moduleswitches,cs_create_smart);
  1301. 'T' :
  1302. begin
  1303. if not UpdateTargetSwitchStr(copy(more,j+1,length(more)),init_settings.targetswitches,true) then
  1304. IllegalPara(opt);
  1305. break;
  1306. end;
  1307. 'v' :
  1308. If target_info.system in systems_jvm then
  1309. If UnsetBool(More, j, opt, false) then
  1310. exclude(init_settings.localswitches,cs_check_var_copyout)
  1311. Else
  1312. include(init_settings.localswitches,cs_check_var_copyout)
  1313. else
  1314. IllegalPara(opt)
  1315. else
  1316. IllegalPara(opt);
  1317. end;
  1318. inc(j);
  1319. end;
  1320. end;
  1321. 'd' :
  1322. begin
  1323. l:=Pos(':=',more);
  1324. if l>0 then
  1325. hs:=copy(more,1,l-1)
  1326. else
  1327. hs:=more;
  1328. if (not is_identifier(hs)) then
  1329. begin
  1330. if hs='' then
  1331. Message1(option_missing_arg,'-d')
  1332. else
  1333. Message1(option_malformed_para,opt);
  1334. StopOptions(1);
  1335. end;
  1336. if l>0 then
  1337. begin
  1338. if cs_support_macro in init_settings.moduleswitches then
  1339. set_system_macro(hs,Copy(more,l+2,255))
  1340. else
  1341. set_system_compvar(hs,Copy(more,l+2,255));
  1342. end
  1343. else
  1344. def_system_macro(hs);
  1345. end;
  1346. 'D' :
  1347. begin
  1348. include(init_settings.globalswitches,cs_link_deffile);
  1349. j:=1;
  1350. while j<=length(more) do
  1351. begin
  1352. case more[j] of
  1353. 'd' :
  1354. begin
  1355. description:=Copy(more,j+1,255);
  1356. break;
  1357. end;
  1358. 'v' :
  1359. begin
  1360. dllversion:=Copy(more,j+1,255);
  1361. l:=pos('.',dllversion);
  1362. dllminor:=0;
  1363. error:=0;
  1364. if l>0 then
  1365. begin
  1366. val(copy(dllversion,l+1,255),minor,error);
  1367. if (error=0) and
  1368. (minor>=0) and (minor<=$ffff) then
  1369. dllminor:=minor
  1370. else
  1371. if error=0 then
  1372. error:=1;
  1373. end;
  1374. if l=0 then
  1375. l:=256;
  1376. dllmajor:=1;
  1377. major:=0;
  1378. if error=0 then
  1379. val(copy(dllversion,1,l-1),major,error);
  1380. if (error=0) and (major>=0) and (major<=$ffff) then
  1381. dllmajor:=major
  1382. else
  1383. if error=0 then
  1384. error:=1;
  1385. if error<>0 then
  1386. Message1(scan_w_wrong_version_ignored,dllversion);
  1387. break;
  1388. end;
  1389. 'w' :
  1390. usewindowapi:=true;
  1391. '-' :
  1392. begin
  1393. exclude(init_settings.globalswitches,cs_link_deffile);
  1394. usewindowapi:=false;
  1395. end;
  1396. else
  1397. IllegalPara(opt);
  1398. end;
  1399. inc(j);
  1400. end;
  1401. end;
  1402. 'e' :
  1403. exepath:=FixPath(More,true);
  1404. 'E' :
  1405. begin
  1406. if UnsetBool(More, 0, opt, true) then
  1407. exclude(init_settings.globalswitches,cs_link_nolink)
  1408. else
  1409. include(init_settings.globalswitches,cs_link_nolink);
  1410. end;
  1411. 'f' :
  1412. begin
  1413. if more='PIC' then
  1414. begin
  1415. if tf_no_pic_supported in target_info.flags then
  1416. message(scan_w_pic_ignored)
  1417. else
  1418. include(init_settings.moduleswitches,cs_create_pic)
  1419. end
  1420. else
  1421. IllegalPara(opt);
  1422. end;
  1423. 'F' :
  1424. begin
  1425. if more='' then
  1426. IllegalPara(opt);
  1427. c:=more[1];
  1428. Delete(more,1,1);
  1429. DefaultReplacements(More);
  1430. case c of
  1431. 'a' :
  1432. autoloadunits:=more;
  1433. 'c' :
  1434. begin
  1435. { if we first specify that the system code page should be
  1436. used and then explicitly specify a code page, unset the
  1437. flag that we're using the system code page again }
  1438. SetCompileModeSwitch('SYSTEMCODEPAGE-',true);
  1439. if (upper(more)='UTF8') or (upper(more)='UTF-8') then
  1440. init_settings.sourcecodepage:=CP_UTF8
  1441. else if not(cpavailable(more)) then
  1442. Message1(option_code_page_not_available,more)
  1443. else
  1444. init_settings.sourcecodepage:=codepagebyname(more);
  1445. include(init_settings.moduleswitches,cs_explicit_codepage);
  1446. end;
  1447. 'C' :
  1448. RCCompiler:=More;
  1449. 'd' :
  1450. if UnsetBool(more, 0, opt, true) then
  1451. init_settings.disabledircache:=false
  1452. else
  1453. init_settings.disabledircache:=true;
  1454. 'D' :
  1455. utilsdirectory:=FixPath(More,true);
  1456. 'e' :
  1457. SetRedirectFile(More);
  1458. 'E' :
  1459. OutputExeDir:=FixPath(More,true);
  1460. 'f' :
  1461. if (target_info.system in systems_darwin) then
  1462. if ispara then
  1463. ParaFrameworkPath.AddPath(More,false)
  1464. else
  1465. frameworksearchpath.AddPath(More,true)
  1466. else
  1467. IllegalPara(opt);
  1468. 'i' :
  1469. begin
  1470. if ispara then
  1471. ParaIncludePath.AddPath(More,false)
  1472. else
  1473. includesearchpath.AddPath(More,true);
  1474. end;
  1475. 'm' :
  1476. begin
  1477. s:=ExtractFileDir(more);
  1478. if TryStrToInt(ExtractFileName(more),j) then
  1479. begin
  1480. unicodemapping:=loadunicodemapping(More,More+'.txt',j);
  1481. if assigned(unicodemapping) then
  1482. registermapping(unicodemapping)
  1483. else
  1484. IllegalPara(opt);
  1485. end
  1486. else
  1487. IllegalPara(opt);
  1488. end;
  1489. 'M' :
  1490. unicodepath:=FixPath(More,true);
  1491. 'g' :
  1492. Message2(option_obsolete_switch_use_new,'-Fg','-Fl');
  1493. 'l' :
  1494. begin
  1495. if path_absolute(More) then
  1496. if ispara then
  1497. ParaLibraryPath.AddPath(sysrootpath,More,false)
  1498. else
  1499. LibrarySearchPath.AddPath(sysrootpath,More,true)
  1500. else
  1501. if ispara then
  1502. ParaLibraryPath.AddPath('',More,false)
  1503. else
  1504. LibrarySearchPath.AddPath('',More,true);
  1505. end;
  1506. 'L' :
  1507. begin
  1508. if More<>'' then
  1509. ParaDynamicLinker:=More
  1510. else
  1511. IllegalPara(opt);
  1512. end;
  1513. 'o' :
  1514. begin
  1515. if ispara then
  1516. ParaObjectPath.AddPath(More,false)
  1517. else
  1518. ObjectSearchPath.AddPath(More,true);
  1519. end;
  1520. 'P' :
  1521. begin
  1522. if ispara then
  1523. parapackages.add(more,nil)
  1524. else
  1525. add_package(more,true,true);
  1526. end;
  1527. 'p' :
  1528. begin
  1529. if ispara then
  1530. parapackagepath.AddPath(More,false)
  1531. else
  1532. packagesearchpath.AddPath(More,true);
  1533. end;
  1534. 'r' :
  1535. Msgfilename:=More;
  1536. 'R' :
  1537. ResCompiler:=More;
  1538. 'u' :
  1539. begin
  1540. if ispara then
  1541. ParaUnitPath.AddPath(More,false)
  1542. else
  1543. unitsearchpath.AddPath(More,true);
  1544. end;
  1545. 'U' :
  1546. OutputUnitDir:=FixPath(More,true);
  1547. 'W',
  1548. 'w':
  1549. begin
  1550. if More<>'' then
  1551. begin
  1552. DefaultReplacements(More);
  1553. D:=ExtractFilePath(More);
  1554. if (D<>'') then
  1555. D:=FixPath(D,True);
  1556. D:=D+ExtractFileName(More);
  1557. if (c='W') then
  1558. WpoFeedbackOutput:=D
  1559. else
  1560. WpoFeedbackInput:=D;
  1561. end
  1562. else
  1563. IllegalPara(opt);
  1564. end;
  1565. else
  1566. IllegalPara(opt);
  1567. end;
  1568. end;
  1569. 'g' :
  1570. begin
  1571. if UnsetBool(More, 0, opt, false) then
  1572. begin
  1573. exclude(init_settings.moduleswitches,cs_debuginfo);
  1574. exclude(init_settings.globalswitches,cs_use_heaptrc);
  1575. exclude(init_settings.globalswitches,cs_use_lineinfo);
  1576. exclude(init_settings.localswitches,cs_checkpointer);
  1577. localvartrashing := -1;
  1578. end
  1579. else
  1580. begin
  1581. include(init_settings.moduleswitches,cs_debuginfo);
  1582. if paratargetdbg=dbg_none then
  1583. paratargetdbg:=target_info.dbg;
  1584. end;
  1585. if not RelocSectionSetExplicitly then
  1586. RelocSection:=false;
  1587. j:=1;
  1588. while j<=length(more) do
  1589. begin
  1590. case more[j] of
  1591. 'c' :
  1592. begin
  1593. if UnsetBool(More, j, opt, false) then
  1594. exclude(init_settings.localswitches,cs_checkpointer)
  1595. else if (target_info.system in systems_support_checkpointer) then
  1596. begin
  1597. if do_release then
  1598. Message(option_gc_incompatible_with_release_flag)
  1599. else
  1600. include(init_settings.localswitches,cs_checkpointer);
  1601. end
  1602. else
  1603. UnsupportedPara('-gc');
  1604. end;
  1605. 'h' :
  1606. begin
  1607. if UnsetBool(More, j, opt, false) then
  1608. exclude(init_settings.globalswitches,cs_use_heaptrc)
  1609. else
  1610. include(init_settings.globalswitches,cs_use_heaptrc);
  1611. end;
  1612. 'l' :
  1613. begin
  1614. if UnsetBool(More, j, opt, false) then
  1615. exclude(init_settings.globalswitches,cs_use_lineinfo)
  1616. else
  1617. include(init_settings.globalswitches,cs_use_lineinfo);
  1618. end;
  1619. 'o' :
  1620. begin
  1621. if not UpdateDebugStr(copy(more,j+1,length(more)),init_settings.debugswitches) then
  1622. IllegalPara(opt);
  1623. break;
  1624. end;
  1625. 'p' :
  1626. begin
  1627. if UnsetBool(More, j, opt, false) then
  1628. exclude(init_settings.globalswitches,cs_stabs_preservecase)
  1629. else
  1630. include(init_settings.globalswitches,cs_stabs_preservecase);
  1631. end;
  1632. 's' :
  1633. begin
  1634. paratargetdbg:=dbg_stabs;
  1635. end;
  1636. 't' :
  1637. begin
  1638. if UnsetBool(More, j, opt, false) then
  1639. localvartrashing := -1
  1640. else
  1641. localvartrashing := (localvartrashing + 1) mod nroftrashvalues;
  1642. end;
  1643. 'v' :
  1644. begin
  1645. if UnsetBool(More, j, opt, false) then
  1646. exclude(init_settings.globalswitches,cs_gdb_valgrind)
  1647. else
  1648. include(init_settings.globalswitches,cs_gdb_valgrind);
  1649. end;
  1650. 'w' :
  1651. begin
  1652. if (j<length(more)) and (more[j+1] in ['2','3','4']) then
  1653. begin
  1654. case more[j+1] of
  1655. '2': paratargetdbg:=dbg_dwarf2;
  1656. '3': paratargetdbg:=dbg_dwarf3;
  1657. '4': paratargetdbg:=dbg_dwarf4;
  1658. end;
  1659. inc(j);
  1660. end
  1661. else
  1662. paratargetdbg:=dbg_dwarf2;
  1663. end;
  1664. else
  1665. IllegalPara(opt);
  1666. end;
  1667. inc(j);
  1668. end;
  1669. end;
  1670. 'h' :
  1671. begin
  1672. NoPressEnter:=true;
  1673. if (More <> '') and (More [1] = 'F') then
  1674. begin
  1675. FPCHelpLines := true;
  1676. Delete (More, 1, 1);
  1677. FPCBinaryPath := More;
  1678. end;
  1679. WriteHelpPages;
  1680. end;
  1681. 'i' :
  1682. begin
  1683. if (More='') or
  1684. (More [1] in ['a', 'c', 'f', 'i', 'o', 'r', 't', 'u', 'w']) then
  1685. WriteInfo (More)
  1686. else
  1687. QuickInfo:=QuickInfo+More;
  1688. end;
  1689. 'I' :
  1690. begin
  1691. if ispara then
  1692. ParaIncludePath.AddPath(More,false)
  1693. else
  1694. includesearchpath.AddPath(More,false);
  1695. end;
  1696. 'k' :
  1697. begin
  1698. if more<>'' then
  1699. ParaLinkOptions:=ParaLinkOptions+' '+More
  1700. else
  1701. IllegalPara(opt);
  1702. end;
  1703. 'l' :
  1704. ParaLogo:=not UnSetBool(more,0,opt,true);
  1705. {$ifdef PREPROCWRITE}
  1706. 'm' :
  1707. parapreprocess:=not UnSetBool(more,0,opt,true);
  1708. {$endif PREPROCWRITE}
  1709. 'M' :
  1710. begin
  1711. more:=Upper(more);
  1712. if not SetCompileMode(more, true) then
  1713. if not SetCompileModeSwitch(more, true) then
  1714. IllegalPara(opt);
  1715. end;
  1716. 'n' :
  1717. begin
  1718. if More='' then
  1719. disable_configfile:=true
  1720. else
  1721. IllegalPara(opt);
  1722. end;
  1723. 'o' :
  1724. begin
  1725. if More<>'' then
  1726. begin
  1727. DefaultReplacements(More);
  1728. D:=ExtractFilePath(More);
  1729. if (D<>'') then
  1730. OutputExeDir:=FixPath(D,True);
  1731. OutputFileName:=ExtractFileName(More);
  1732. end
  1733. else
  1734. IllegalPara(opt);
  1735. end;
  1736. 'O' :
  1737. begin
  1738. j:=1;
  1739. while j<=length(more) do
  1740. begin
  1741. case more[j] of
  1742. '1' :
  1743. init_settings.optimizerswitches:=init_settings.optimizerswitches+level1optimizerswitches;
  1744. '2' :
  1745. init_settings.optimizerswitches:=init_settings.optimizerswitches+level2optimizerswitches;
  1746. '3' :
  1747. init_settings.optimizerswitches:=init_settings.optimizerswitches+level3optimizerswitches;
  1748. '4' :
  1749. init_settings.optimizerswitches:=init_settings.optimizerswitches+level4optimizerswitches;
  1750. 'a' :
  1751. begin
  1752. if not(UpdateAlignmentStr(Copy(Opt,j+3,255),ParaAlignment)) then
  1753. IllegalPara(opt);
  1754. break;
  1755. end;
  1756. 's' :
  1757. include(init_settings.optimizerswitches,cs_opt_size);
  1758. 'p' :
  1759. begin
  1760. if not Setoptimizecputype(copy(more,j+1,length(more)),init_settings.optimizecputype) then
  1761. begin
  1762. OptCPUSetExplicitly:=true;
  1763. { Give warning for old i386 switches }
  1764. if (Length(More)-j=1) and
  1765. (More[j+1]>='1') and (More[j+1]<='5')then
  1766. Message2(option_obsolete_switch_use_new,'-Op<nr>','-Op<name>')
  1767. else
  1768. IllegalPara(opt);
  1769. end;
  1770. break;
  1771. end;
  1772. 'o' :
  1773. begin
  1774. if not UpdateOptimizerStr(copy(more,j+1,length(more)),init_settings.optimizerswitches) then
  1775. IllegalPara(opt);
  1776. break;
  1777. end;
  1778. '-' :
  1779. begin
  1780. init_settings.optimizerswitches:=[];
  1781. FillChar(ParaAlignment,sizeof(ParaAlignment),0);
  1782. end;
  1783. { Obsolete switches }
  1784. 'g' :
  1785. Message2(option_obsolete_switch_use_new,'-Og','-Os');
  1786. 'G' :
  1787. Message1(option_obsolete_switch,'-OG');
  1788. 'r' :
  1789. Message2(option_obsolete_switch_use_new,'-Or','-O2 or -Ooregvar');
  1790. 'u' :
  1791. Message2(option_obsolete_switch_use_new,'-Ou','-Oouncertain');
  1792. 'w' :
  1793. begin
  1794. if not UpdateWpoStr(copy(more,j+1,length(more)),init_settings.dowpoptimizerswitches) then
  1795. IllegalPara(opt);
  1796. break;
  1797. end;
  1798. 'W' :
  1799. begin
  1800. if not UpdateWpoStr(copy(more,j+1,length(more)),init_settings.genwpoptimizerswitches) then
  1801. IllegalPara(opt);
  1802. break;
  1803. end;
  1804. else
  1805. IllegalPara(opt);
  1806. end;
  1807. inc(j);
  1808. end;
  1809. end;
  1810. 'p' :
  1811. begin
  1812. if UnsetBool(More, 0, opt, false) then
  1813. begin
  1814. init_settings.moduleswitches:=init_settings.moduleswitches-[cs_profile];
  1815. undef_system_macro('FPC_PROFILE');
  1816. end
  1817. else
  1818. if Length(More)=0 then
  1819. IllegalPara(opt)
  1820. else
  1821. case more[1] of
  1822. 'g' : if UnsetBool(more, 1, opt, false) then
  1823. begin
  1824. exclude(init_settings.moduleswitches,cs_profile);
  1825. undef_system_macro('FPC_PROFILE');
  1826. end
  1827. else if (target_info.system in supported_targets_pg) then
  1828. begin
  1829. include(init_settings.moduleswitches,cs_profile);
  1830. def_system_macro('FPC_PROFILE');
  1831. end
  1832. else
  1833. UnsupportedPara('-pg');
  1834. else
  1835. IllegalPara(opt);
  1836. end;
  1837. end;
  1838. 'P' :
  1839. begin
  1840. { used to select the target processor with the "fpc" binary;
  1841. give an error if it's not the target architecture supported by
  1842. this compiler binary (will be verified after the target_info
  1843. is set) }
  1844. processorstr:=More;
  1845. end;
  1846. 'R' :
  1847. begin
  1848. if not SetAsmReadMode(More,init_settings.asmmode) then
  1849. IllegalPara(opt);
  1850. end;
  1851. 's' :
  1852. begin
  1853. if UnsetBool(More, 0, opt, false) then
  1854. begin
  1855. init_settings.globalswitches:=init_settings.globalswitches-[cs_asm_extern,cs_link_extern,cs_link_nolink];
  1856. if more<>'' then
  1857. IllegalPara(opt);
  1858. end
  1859. else
  1860. begin
  1861. init_settings.globalswitches:=init_settings.globalswitches+[cs_asm_extern,cs_link_extern,cs_link_nolink];
  1862. if more='h' then
  1863. init_settings.globalswitches:=init_settings.globalswitches-[cs_link_on_target]
  1864. else if more='t' then
  1865. init_settings.globalswitches:=init_settings.globalswitches+[cs_link_on_target]
  1866. else if more='r' then
  1867. init_settings.globalswitches:=init_settings.globalswitches+[cs_asm_leave,cs_no_regalloc]
  1868. else if more<>'' then
  1869. IllegalPara(opt);
  1870. end;
  1871. end;
  1872. 'S' :
  1873. begin
  1874. if more='' then
  1875. IllegalPara(opt);
  1876. if more[1]='I' then
  1877. begin
  1878. {$ifdef jvm}
  1879. UnsupportedPara('-SI');
  1880. {$endif}
  1881. if upper(more)='ICOM' then
  1882. init_settings.interfacetype:=it_interfacecom
  1883. else if upper(more)='ICORBA' then
  1884. init_settings.interfacetype:=it_interfacecorba
  1885. else
  1886. IllegalPara(opt);
  1887. end
  1888. else
  1889. begin
  1890. j:=1;
  1891. while j<=length(more) do
  1892. begin
  1893. case more[j] of
  1894. '2' : //an alternative to -Mobjfpc
  1895. SetCompileMode('OBJFPC',true);
  1896. 'a' :
  1897. If UnsetBool(More, j, opt, false) then
  1898. exclude(init_settings.localswitches,cs_do_assertion)
  1899. else
  1900. include(init_settings.localswitches,cs_do_assertion);
  1901. 'c' :
  1902. If UnsetBool(More, j, opt, false) then
  1903. exclude(init_settings.moduleswitches,cs_support_c_operators)
  1904. else
  1905. include(init_settings.moduleswitches,cs_support_c_operators);
  1906. 'd' : //an alternative to -Mdelphi
  1907. SetCompileMode('DELPHI',true);
  1908. 'e' :
  1909. begin
  1910. SetErrorFlags(copy(more,j+1,length(more)));
  1911. break;
  1912. end;
  1913. 'f' :
  1914. begin
  1915. inc(j);
  1916. if more[j]='-' then
  1917. begin
  1918. if length(more)>j then
  1919. IllegalPara(opt)
  1920. else
  1921. features:=[];
  1922. end
  1923. else
  1924. begin
  1925. if (HandleFeature(upper(copy(more,j,length(more)-j+1)))) then
  1926. j:=length(more)
  1927. else
  1928. IllegalPara(opt);
  1929. end;
  1930. end;
  1931. 'g' :
  1932. If UnsetBool(More, j, opt, false) then
  1933. exclude(init_settings.moduleswitches,cs_support_goto)
  1934. else
  1935. include(init_settings.moduleswitches,cs_support_goto);
  1936. 'h' :
  1937. If UnsetBool(More, j, opt, false) then
  1938. exclude(init_settings.localswitches,cs_refcountedstrings)
  1939. else
  1940. include(init_settings.localswitches,cs_refcountedstrings);
  1941. 'i' :
  1942. If UnsetBool(More, j, opt, false) then
  1943. exclude(init_settings.localswitches,cs_do_inline)
  1944. else
  1945. include(init_settings.localswitches,cs_do_inline);
  1946. 'k' :
  1947. If UnsetBool(More, j, opt, false) then
  1948. exclude(init_settings.globalswitches,cs_load_fpcylix_unit)
  1949. else
  1950. include(init_settings.globalswitches,cs_load_fpcylix_unit);
  1951. 'm' :
  1952. If UnsetBool(More, j, opt, false) then
  1953. exclude(init_settings.moduleswitches,cs_support_macro)
  1954. else
  1955. include(init_settings.moduleswitches,cs_support_macro);
  1956. 'o' : //an alternative to -Mtp
  1957. SetCompileMode('TP',true);
  1958. 'r' :
  1959. If UnsetBool(More, j, opt, false) then
  1960. exclude(init_settings.globalswitches,cs_transparent_file_names)
  1961. else
  1962. include(init_settings.globalswitches,cs_transparent_file_names);
  1963. {$ifdef gpc_mode}
  1964. 'p' : //an alternative to -Mgpc
  1965. SetCompileMode('GPC',true);
  1966. {$endif}
  1967. 's' :
  1968. If UnsetBool(More, j, opt, false) then
  1969. exclude(init_settings.globalswitches,cs_constructor_name)
  1970. else
  1971. include(init_settings.globalswitches,cs_constructor_name);
  1972. 't' :
  1973. Message1(option_obsolete_switch,'-St');
  1974. 'v' :
  1975. If UnsetBool(More, j, opt, false) then
  1976. exclude(init_settings.globalswitches,cs_support_vectors)
  1977. else
  1978. include(init_settings.globalswitches,cs_support_vectors);
  1979. 'x' :
  1980. If UnsetBool(More, j, opt, false) then
  1981. SetCompileModeSwitch('EXCEPTIONS-',true)
  1982. else
  1983. SetCompileModeSwitch('EXCEPTIONS',true);
  1984. 'y' :
  1985. If UnsetBool(More, j, opt, false) then
  1986. exclude(init_settings.localswitches,cs_typed_addresses)
  1987. else
  1988. include(init_settings.localswitches,cs_typed_addresses);
  1989. '-' :
  1990. begin
  1991. init_settings.globalswitches:=init_settings.globalswitches - [cs_constructor_name,cs_support_exceptions,
  1992. cs_support_vectors,cs_load_fpcylix_unit];
  1993. init_settings.localswitches:=init_settings.localswitches - [cs_do_assertion,cs_do_inline, cs_refcountedstrings,
  1994. cs_typed_addresses];
  1995. init_settings.moduleswitches:=init_settings.moduleswitches - [cs_support_c_operators, cs_support_goto,
  1996. cs_support_macro];
  1997. end;
  1998. else
  1999. IllegalPara(opt);
  2000. end;
  2001. inc(j);
  2002. end;
  2003. end;
  2004. end;
  2005. 'T' :
  2006. begin
  2007. more:=Upper(More);
  2008. if paratarget=system_none then
  2009. begin
  2010. { remove old target define }
  2011. TargetOptions(false);
  2012. { load new target }
  2013. paratarget:=find_system_by_string(More);
  2014. if paratarget<>system_none then
  2015. set_target(paratarget)
  2016. else
  2017. IllegalPara(opt);
  2018. { set new define }
  2019. TargetOptions(true);
  2020. end
  2021. else
  2022. if More<>upper(target_info.shortname) then
  2023. Message1(option_target_is_already_set,target_info.shortname);
  2024. end;
  2025. 'u' :
  2026. if is_identifier(more) then
  2027. undef_system_macro(more)
  2028. else
  2029. begin
  2030. if (more='') then
  2031. Message1(option_missing_arg,'-u')
  2032. else
  2033. Message1(option_malformed_para,opt);
  2034. StopOptions(1);
  2035. end;
  2036. 'U' :
  2037. begin
  2038. j:=1;
  2039. while j<=length(more) do
  2040. begin
  2041. case more[j] of
  2042. {$ifdef UNITALIASES}
  2043. 'a' :
  2044. begin
  2045. AddUnitAlias(Copy(More,j+1,255));
  2046. break;
  2047. end;
  2048. {$endif UNITALIASES}
  2049. 'n' :
  2050. exclude(init_settings.globalswitches,cs_check_unit_name);
  2051. 'p' :
  2052. begin
  2053. Message2(option_obsolete_switch_use_new,'-Up','-Fu');
  2054. break;
  2055. end;
  2056. 'r' :
  2057. begin
  2058. do_release:=true;
  2059. if (cs_checkpointer in init_settings.localswitches) then
  2060. begin
  2061. Message(option_gc_incompatible_with_release_flag);
  2062. exclude(init_settings.localswitches,cs_checkpointer);
  2063. end;
  2064. end;
  2065. 's' :
  2066. include(init_settings.moduleswitches,cs_compilesystem);
  2067. '-' :
  2068. begin
  2069. exclude(init_settings.moduleswitches,cs_compilesystem);
  2070. exclude(init_settings.globalswitches,cs_check_unit_name);
  2071. end;
  2072. else
  2073. IllegalPara(opt);
  2074. end;
  2075. inc(j);
  2076. end;
  2077. end;
  2078. 'v' :
  2079. begin
  2080. if not setverbosity(More) then
  2081. IllegalPara(opt);
  2082. end;
  2083. 'V' : ; { Ignore used by fpc }
  2084. 'W' :
  2085. begin
  2086. j:=1;
  2087. while j<=length(More) do
  2088. begin
  2089. case More[j] of
  2090. 'A':
  2091. begin
  2092. if target_info.system in systems_all_windows then
  2093. begin
  2094. if UnsetBool(More, j, opt, false) then
  2095. SetApptype(app_cui)
  2096. else
  2097. SetApptype(app_native);
  2098. end
  2099. else
  2100. IllegalPara(opt);
  2101. end;
  2102. 'b':
  2103. begin
  2104. if target_info.system in systems_darwin then
  2105. begin
  2106. if UnsetBool(More, j, opt, false) then
  2107. SetApptype(app_cui)
  2108. else
  2109. SetApptype(app_bundle)
  2110. end
  2111. else
  2112. IllegalPara(opt);
  2113. end;
  2114. 'B':
  2115. begin
  2116. if target_info.system in systems_all_windows+systems_symbian then
  2117. begin
  2118. { -WB200000 means set trefered base address
  2119. to $200000, but does not change relocsection boolean
  2120. this way we can create both relocatble and
  2121. non relocatable DLL at a specific base address PM }
  2122. if (length(More)>j) then
  2123. begin
  2124. val('$'+Copy(More,j+1,255),imagebase,code);
  2125. if code<>0 then
  2126. IllegalPara(opt);
  2127. ImageBaseSetExplicity:=true;
  2128. end
  2129. else
  2130. begin
  2131. RelocSection:=true;
  2132. RelocSectionSetExplicitly:=true;
  2133. end;
  2134. break;
  2135. end
  2136. else
  2137. IllegalPara(opt);
  2138. end;
  2139. 'C':
  2140. begin
  2141. if target_info.system in systems_all_windows+systems_os2+systems_macos then
  2142. begin
  2143. if UnsetBool(More, j, opt, false) then
  2144. SetApptype(app_gui)
  2145. else
  2146. SetApptype(app_cui);
  2147. end
  2148. else
  2149. IllegalPara(opt);
  2150. end;
  2151. 'D':
  2152. begin
  2153. if target_info.system in systems_all_windows then
  2154. begin
  2155. UseDeffileForExports:=not UnsetBool(More, j, opt, false);
  2156. UseDeffileForExportsSetExplicitly:=true;
  2157. end
  2158. else
  2159. IllegalPara(opt);
  2160. end;
  2161. 'e':
  2162. begin
  2163. if (target_info.system in systems_darwin) then
  2164. begin
  2165. RegisterRes(res_macosx_ext_info,TWinLikeResourceFile);
  2166. set_target_res(res_ext);
  2167. target_info.resobjext:='.fpcres';
  2168. end
  2169. else
  2170. IllegalPara(opt);
  2171. end;
  2172. 'F':
  2173. begin
  2174. if target_info.system in systems_os2 then
  2175. begin
  2176. if UnsetBool(More, j, opt, false) then
  2177. SetApptype(app_cui)
  2178. else
  2179. SetApptype(app_fs);
  2180. end
  2181. else
  2182. IllegalPara(opt);
  2183. end;
  2184. 'G':
  2185. begin
  2186. if target_info.system in systems_all_windows+systems_os2+systems_macos then
  2187. begin
  2188. if UnsetBool(More, j, opt, false) then
  2189. SetApptype(app_cui)
  2190. else
  2191. SetApptype(app_gui);
  2192. end
  2193. else
  2194. IllegalPara(opt);
  2195. end;
  2196. {$if defined(i8086)}
  2197. 'h':
  2198. begin
  2199. if UnsetBool(More, j, opt, false) then
  2200. exclude(init_settings.moduleswitches,cs_huge_code)
  2201. else
  2202. include(init_settings.moduleswitches,cs_huge_code);
  2203. end;
  2204. {$endif defined(i8086)}
  2205. 'I':
  2206. begin
  2207. if target_info.system in systems_all_windows then
  2208. begin
  2209. GenerateImportSection:=not UnsetBool(More,j,opt,false);
  2210. GenerateImportSectionSetExplicitly:=true;
  2211. end
  2212. else
  2213. IllegalPara(opt);
  2214. end;
  2215. 'i':
  2216. begin
  2217. if (target_info.system in systems_darwin) then
  2218. begin
  2219. set_target_res(res_macho);
  2220. target_info.resobjext:=
  2221. targetinfos[target_info.system]^.resobjext;
  2222. end
  2223. else
  2224. IllegalPara(opt);
  2225. end;
  2226. 'm':
  2227. begin
  2228. {$if defined(i8086)}
  2229. if (target_info.system in [system_i8086_msdos,system_i8086_win16,system_i8086_embedded]) then
  2230. begin
  2231. case Upper(Copy(More,j+1,255)) of
  2232. 'TINY': init_settings.x86memorymodel:=mm_tiny;
  2233. 'SMALL': init_settings.x86memorymodel:=mm_small;
  2234. 'MEDIUM': init_settings.x86memorymodel:=mm_medium;
  2235. 'COMPACT': init_settings.x86memorymodel:=mm_compact;
  2236. 'LARGE': init_settings.x86memorymodel:=mm_large;
  2237. 'HUGE': init_settings.x86memorymodel:=mm_huge;
  2238. else
  2239. IllegalPara(opt);
  2240. end;
  2241. break;
  2242. end
  2243. else
  2244. {$endif defined(i8086)}
  2245. IllegalPara(opt);
  2246. end;
  2247. 'M':
  2248. begin
  2249. if (target_info.system in (systems_darwin-[system_i386_iphonesim,system_arm_darwin,system_aarch64_darwin,system_x86_64_iphonesim])) and
  2250. ParseMacVersionMin(MacOSXVersionMin,iPhoneOSVersionMin,'MAC_OS_X_VERSION_MIN_REQUIRED',copy(More,2,255),false) then
  2251. begin
  2252. break;
  2253. end
  2254. else
  2255. IllegalPara(opt);
  2256. end;
  2257. 'N':
  2258. begin
  2259. if target_info.system in systems_all_windows then
  2260. begin
  2261. RelocSection:=UnsetBool(More,j,opt,false);
  2262. RelocSectionSetExplicitly:=true;
  2263. end
  2264. else
  2265. IllegalPara(opt);
  2266. end;
  2267. 'p':
  2268. begin
  2269. {$push}
  2270. {$warn 6018 off} { Unreachable code due to compile time evaluation }
  2271. if (target_info.system in systems_embedded) and
  2272. ControllerSupport then
  2273. begin
  2274. s:=upper(copy(more,j+1,length(more)-j));
  2275. if not(SetControllerType(s,init_settings.controllertype)) then
  2276. IllegalPara(opt);
  2277. break;
  2278. end
  2279. else
  2280. IllegalPara(opt);
  2281. {$pop}
  2282. end;
  2283. 'P':
  2284. begin
  2285. if (target_info.system in [system_i386_iphonesim,system_arm_darwin,system_aarch64_darwin,system_x86_64_iphonesim]) and
  2286. ParseMacVersionMin(iPhoneOSVersionMin,MacOSXVersionMin,'IPHONE_OS_VERSION_MIN_REQUIRED',copy(More,2,255),true) then
  2287. begin
  2288. break;
  2289. end
  2290. else
  2291. IllegalPara(opt);
  2292. end;
  2293. 'R':
  2294. begin
  2295. if target_info.system in systems_all_windows then
  2296. begin
  2297. { support -WR+ / -WR- as synonyms to -WR / -WN }
  2298. RelocSection:=not UnsetBool(More,j,opt,false);
  2299. RelocSectionSetExplicitly:=true;
  2300. end
  2301. else
  2302. IllegalPara(opt);
  2303. end;
  2304. 't':
  2305. begin
  2306. {$if defined(i8086)}
  2307. if (target_info.system in [system_i8086_msdos,system_i8086_embedded]) then
  2308. begin
  2309. case Upper(Copy(More,j+1,255)) of
  2310. 'EXE': SetAppType(app_cui);
  2311. 'COM': SetAppType(app_com);
  2312. else
  2313. IllegalPara(opt);
  2314. end;
  2315. break;
  2316. end
  2317. else
  2318. {$endif defined(i8086)}
  2319. IllegalPara(opt);
  2320. end;
  2321. 'T':
  2322. begin
  2323. if target_info.system in systems_macos then
  2324. begin
  2325. if UnsetBool(More, j, opt, false) then
  2326. SetApptype(app_cui)
  2327. else
  2328. SetApptype(app_tool);
  2329. end
  2330. else
  2331. IllegalPara(opt);
  2332. end;
  2333. 'X':
  2334. begin
  2335. if (target_info.system in systems_linux) then
  2336. begin
  2337. if UnsetBool(More, j, opt, false) then
  2338. exclude(init_settings.moduleswitches,cs_executable_stack)
  2339. else
  2340. include(init_settings.moduleswitches,cs_executable_stack)
  2341. end
  2342. else
  2343. IllegalPara(opt);
  2344. end;
  2345. else
  2346. IllegalPara(opt);
  2347. end;
  2348. inc(j);
  2349. end;
  2350. end;
  2351. 'X' :
  2352. begin
  2353. j:=1;
  2354. while j<=length(more) do
  2355. begin
  2356. case More[j] of
  2357. '9' :
  2358. begin
  2359. if target_info.system in systems_linux then
  2360. begin
  2361. if UnsetBool(More, j, opt, false) then
  2362. exclude(init_settings.globalswitches,cs_link_pre_binutils_2_19)
  2363. else
  2364. include(init_settings.globalswitches,cs_link_pre_binutils_2_19);
  2365. end
  2366. else
  2367. IllegalPara(opt);
  2368. end;
  2369. 'c' : Cshared:=TRUE;
  2370. 'd' : Dontlinkstdlibpath:=TRUE;
  2371. 'e' :
  2372. begin
  2373. If UnsetBool(More, j, opt, false) then
  2374. exclude(init_settings.globalswitches,cs_link_extern)
  2375. else
  2376. include(init_settings.globalswitches,cs_link_extern);
  2377. end;
  2378. 'f' :
  2379. include(init_settings.globalswitches,cs_link_pthread);
  2380. 'g' :
  2381. begin
  2382. If UnsetBool(More, j, opt, false) then
  2383. exclude(init_settings.globalswitches,cs_link_separate_dbg_file)
  2384. else
  2385. include(init_settings.globalswitches,cs_link_separate_dbg_file);
  2386. end;
  2387. 'i' :
  2388. begin
  2389. If UnsetBool(More, j, opt, false) then
  2390. include(init_settings.globalswitches,cs_link_extern)
  2391. else
  2392. exclude(init_settings.globalswitches,cs_link_extern);
  2393. end;
  2394. 'n' :
  2395. begin
  2396. If UnsetBool(More, j, opt, false) then
  2397. exclude(init_settings.globalswitches,cs_link_native)
  2398. else
  2399. include(init_settings.globalswitches,cs_link_native);
  2400. end;
  2401. 'm' :
  2402. begin
  2403. If UnsetBool(More, j, opt, false) then
  2404. exclude(init_settings.globalswitches,cs_link_map)
  2405. else
  2406. include(init_settings.globalswitches,cs_link_map);
  2407. end;
  2408. 'p' : ; { Ignore used by fpc.pp }
  2409. 'r' :
  2410. begin
  2411. if (target_info.system in suppported_targets_x_smallr) then
  2412. begin
  2413. rlinkpath:=Copy(more,2,length(More)-1);
  2414. DefaultReplacements(rlinkpath);
  2415. end
  2416. else
  2417. IgnoredPara('-Xr');
  2418. more:='';
  2419. end;
  2420. 'R' :
  2421. begin
  2422. sysrootpath:=copy(more,2,length(more)-1);
  2423. defaultreplacements(sysrootpath);
  2424. more:='';
  2425. end;
  2426. 's' :
  2427. begin
  2428. If UnsetBool(More, j, opt, false) then
  2429. exclude(init_settings.globalswitches,cs_link_strip)
  2430. else
  2431. include(init_settings.globalswitches,cs_link_strip);
  2432. end;
  2433. 't' :
  2434. include(init_settings.globalswitches,cs_link_staticflag);
  2435. 'v' :
  2436. begin
  2437. If UnsetBool(More, j, opt, false) then
  2438. exclude(init_settings.globalswitches,cs_link_opt_vtable)
  2439. else
  2440. include(init_settings.globalswitches,cs_link_opt_vtable);
  2441. end;
  2442. 'D' :
  2443. begin
  2444. def_system_macro('FPC_LINK_DYNAMIC');
  2445. undef_system_macro('FPC_LINK_SMART');
  2446. undef_system_macro('FPC_LINK_STATIC');
  2447. exclude(init_settings.globalswitches,cs_link_static);
  2448. exclude(init_settings.globalswitches,cs_link_smart);
  2449. include(init_settings.globalswitches,cs_link_shared);
  2450. LinkTypeSetExplicitly:=true;
  2451. end;
  2452. 'M' :
  2453. begin
  2454. mainaliasname:=Copy(more,2,length(More)-1);
  2455. More:='';
  2456. end;
  2457. 'P' :
  2458. begin
  2459. utilsprefix:=Copy(more,2,length(More)-1);
  2460. DefaultReplacements(utilsprefix);
  2461. More:='';
  2462. end;
  2463. 'L' : begin // -XLO is link order -XLA is link alias. -XLD avoids load defaults.
  2464. // these are not aggregable.
  2465. if (j=length(more)) or not (more[j+1] in ['O','A','D']) then
  2466. IllegalPara(opt)
  2467. else
  2468. begin
  2469. case more[j+1] of
  2470. 'A' : begin
  2471. s:=Copy(more,3,length(More)-2);
  2472. if not LinkLibraryAliases.AddDep(s) Then
  2473. IllegalPara(opt);
  2474. end;
  2475. 'O' : begin
  2476. s:=Copy(more,3,length(More)-2);
  2477. if not LinkLibraryOrder.AddWeight(s) Then
  2478. IllegalPara(opt);
  2479. end;
  2480. 'D' : include(init_settings.globalswitches,cs_link_no_default_lib_order)
  2481. else
  2482. IllegalPara(opt);
  2483. end; {case}
  2484. j:=length(more);
  2485. end; {else begin}
  2486. end;
  2487. 'S' :
  2488. begin
  2489. ForceStaticLinking;
  2490. end;
  2491. 'V' :
  2492. begin
  2493. if UnsetBool(More, j, opt, false) then
  2494. exclude(init_settings.globalswitches,cs_link_vlink)
  2495. else
  2496. begin
  2497. include(init_settings.globalswitches,cs_link_vlink);
  2498. include(init_settings.globalswitches,cs_link_extern);
  2499. end;
  2500. LinkerSetExplicitly:=true;
  2501. end;
  2502. 'X' :
  2503. begin
  2504. def_system_macro('FPC_LINK_SMART');
  2505. undef_system_macro('FPC_LINK_STATIC');
  2506. undef_system_macro('FPC_LINK_DYNAMIC');
  2507. exclude(init_settings.globalswitches,cs_link_static);
  2508. include(init_settings.globalswitches,cs_link_smart);
  2509. exclude(init_settings.globalswitches,cs_link_shared);
  2510. LinkTypeSetExplicitly:=true;
  2511. end;
  2512. '-' :
  2513. begin
  2514. exclude(init_settings.globalswitches,cs_link_staticflag);
  2515. exclude(init_settings.globalswitches,cs_link_strip);
  2516. exclude(init_settings.globalswitches,cs_link_map);
  2517. set_default_link_type;
  2518. end;
  2519. else
  2520. IllegalPara(opt);
  2521. end;
  2522. inc(j);
  2523. end;
  2524. end;
  2525. else
  2526. IllegalPara(opt);
  2527. end;
  2528. end;
  2529. '@' :
  2530. begin
  2531. Message(option_no_nested_response_file);
  2532. StopOptions(1);
  2533. end;
  2534. else
  2535. begin
  2536. if (length(param_file)<>0) then
  2537. Message2(option_only_one_source_support,param_file,opt);
  2538. param_file:=opt;
  2539. Message1(option_found_file,opt);
  2540. end;
  2541. end;
  2542. end;
  2543. procedure Toption.Interpret_file(const filename : TPathStr);
  2544. procedure RemoveSep(var fn:TPathStr);
  2545. var
  2546. i : longint;
  2547. begin
  2548. i:=0;
  2549. while (i<length(fn)) and (fn[i+1] in [',',' ',#9]) do
  2550. inc(i);
  2551. Delete(fn,1,i);
  2552. i:=length(fn);
  2553. while (i>0) and (fn[i] in [',',' ',#9]) do
  2554. dec(i);
  2555. fn:=copy(fn,1,i);
  2556. end;
  2557. function GetName(var fn:TPathStr):TPathStr;
  2558. var
  2559. i : longint;
  2560. begin
  2561. i:=0;
  2562. while (i<length(fn)) and (fn[i+1] in ['a'..'z','A'..'Z','0'..'9','_','-']) do
  2563. inc(i);
  2564. GetName:=Copy(fn,1,i);
  2565. Delete(fn,1,i);
  2566. end;
  2567. const
  2568. maxlevel = 15;
  2569. var
  2570. f : text;
  2571. s, tmp,
  2572. opts : TCmdStr;
  2573. skip : array[0..maxlevel] of boolean;
  2574. line,
  2575. level : longint;
  2576. option_read : boolean;
  2577. oldfilemode : byte;
  2578. ConfigFile: TPathStr;
  2579. begin
  2580. { avoid infinite loop }
  2581. Inc(FileLevel);
  2582. Option_read:=false;
  2583. If FileLevel>MaxLevel then
  2584. Message(option_too_many_cfg_files);
  2585. if not ParaIncludeCfgPath.FindFile(fileName,true,ConfigFile) then
  2586. ConfigFile := ExpandFileName(filename);
  2587. { Maybe It's Directory ?} //Jaro Change:
  2588. if PathExists(ConfigFile,false) then
  2589. begin
  2590. Message1(option_config_is_dir,filename);
  2591. exit;
  2592. end;
  2593. { open file }
  2594. Message1(option_using_file,filename);
  2595. oldfilemode:=filemode;
  2596. filemode:=0;
  2597. assign(f,ConfigFile);
  2598. {$push}{$I-}
  2599. reset(f);
  2600. {$pop}
  2601. filemode:=oldfilemode;
  2602. if ioresult<>0 then
  2603. begin
  2604. Message1(option_unable_open_file,filename);
  2605. exit;
  2606. end;
  2607. Message1(option_start_reading_configfile,filename);
  2608. fillchar(skip,sizeof(skip),0);
  2609. level:=0;
  2610. line:=0;
  2611. while not eof(f) do
  2612. begin
  2613. readln(f,opts);
  2614. inc(line);
  2615. RemoveSep(opts);
  2616. if (opts<>'') and (opts[1]<>';') then
  2617. begin
  2618. if opts[1]='#' then
  2619. begin
  2620. Message1(option_interpreting_file_option,opts);
  2621. Delete(opts,1,1);
  2622. s:=upper(GetName(opts));
  2623. if (s='SECTION') then
  2624. begin
  2625. RemoveSep(opts);
  2626. s:=upper(GetName(opts));
  2627. if level=0 then
  2628. skip[level]:=not defined_macro(s) or (s='COMMON');
  2629. end
  2630. else
  2631. if (s='IFDEF') then
  2632. begin
  2633. RemoveSep(opts);
  2634. if Level>=maxlevel then
  2635. begin
  2636. Message2(option_too_many_ifdef,filename,tostr(line));
  2637. stopOptions(1);
  2638. end;
  2639. inc(Level);
  2640. skip[level]:=(skip[level-1] or not defined_macro(upper(GetName(opts))));
  2641. end
  2642. else
  2643. if (s='IFNDEF') then
  2644. begin
  2645. RemoveSep(opts);
  2646. if Level>=maxlevel then
  2647. begin
  2648. Message2(option_too_many_ifdef,filename,tostr(line));
  2649. stopOptions(1);
  2650. end;
  2651. inc(Level);
  2652. skip[level]:=(skip[level-1] or defined_macro(upper(GetName(opts))));
  2653. end
  2654. else
  2655. if (s='ELSE') then
  2656. begin
  2657. if Level=0 then
  2658. begin
  2659. Message2(option_else_without_if,filename,tostr(line));
  2660. stopOptions(1);
  2661. end
  2662. else
  2663. skip[level]:=skip[level-1] or (not skip[level])
  2664. end
  2665. else
  2666. if (s='ENDIF') then
  2667. begin
  2668. skip[level]:=false;
  2669. if Level=0 then
  2670. begin
  2671. Message2(option_too_many_endif,filename,tostr(line));
  2672. stopOptions(1);
  2673. end;
  2674. dec(level);
  2675. end
  2676. else
  2677. if (not skip[level]) then
  2678. begin
  2679. if (s='DEFINE') then
  2680. begin
  2681. RemoveSep(opts);
  2682. tmp:= GetName(opts);
  2683. if tmp <> '' then
  2684. def_system_macro(tmp);
  2685. Option_read:=true;
  2686. end
  2687. else
  2688. if (s='UNDEF') then
  2689. begin
  2690. RemoveSep(opts);
  2691. tmp:= GetName(opts);
  2692. if tmp <> '' then
  2693. undef_system_macro(tmp);
  2694. Option_read:=true;
  2695. end
  2696. else
  2697. if (s='WRITE') then
  2698. begin
  2699. Delete(opts,1,1);
  2700. DefaultReplacements(opts);
  2701. WriteLn(opts);
  2702. Option_read:=true;
  2703. end
  2704. else
  2705. if (s='INCLUDE') then
  2706. begin
  2707. Delete(opts,1,1);
  2708. DefaultReplacements(opts);
  2709. Interpret_file(opts);
  2710. Option_read:=true;
  2711. end
  2712. else
  2713. if (s='CFGDIR') then
  2714. begin
  2715. Delete(opts,1,1);
  2716. DefaultReplacements(opts);
  2717. ParaIncludeCfgPath.AddPath(opts,false);
  2718. Option_read:=true;
  2719. end;
  2720. end;
  2721. end
  2722. else
  2723. begin
  2724. if (opts[1]='-') or (opts[1]='@') then
  2725. begin
  2726. if (not skip[level]) then
  2727. interpret_option(opts,false);
  2728. Option_read:=true;
  2729. end
  2730. else
  2731. Message1(option_illegal_para,opts);
  2732. end;
  2733. end;
  2734. end;
  2735. if Level>0 then
  2736. Message(option_too_less_endif);
  2737. if Not Option_read then
  2738. Message1(option_no_option_found,filename)
  2739. else
  2740. Message1(option_end_reading_configfile,filename);
  2741. Close(f);
  2742. Dec(FileLevel);
  2743. end;
  2744. procedure Toption.Interpret_envvar(const envname : TCmdStr);
  2745. var
  2746. argstart,
  2747. env,
  2748. pc : pchar;
  2749. arglen : longint;
  2750. quote : set of char;
  2751. hs : TCmdStr;
  2752. begin
  2753. Message1(option_using_env,envname);
  2754. env:=GetEnvPChar(envname);
  2755. pc:=env;
  2756. if assigned(pc) then
  2757. begin
  2758. repeat
  2759. { skip leading spaces }
  2760. while pc^ in [' ',#9,#13] do
  2761. inc(pc);
  2762. case pc^ of
  2763. #0 :
  2764. break;
  2765. '"' :
  2766. begin
  2767. quote:=['"'];
  2768. inc(pc);
  2769. end;
  2770. '''' :
  2771. begin
  2772. quote:=[''''];
  2773. inc(pc);
  2774. end;
  2775. else
  2776. quote:=[' ',#9,#13];
  2777. end;
  2778. { scan until the end of the argument }
  2779. argstart:=pc;
  2780. while (pc^<>#0) and not(pc^ in quote) do
  2781. inc(pc);
  2782. { create argument }
  2783. arglen:=pc-argstart;
  2784. { TODO: FIXME: silent truncation of environment parameters }
  2785. if (arglen > 255) then
  2786. arglen := 255;
  2787. setlength(hs,arglen);
  2788. move(argstart^,hs[1],arglen);
  2789. interpret_option(hs,true);
  2790. { skip quote }
  2791. if pc^ in quote then
  2792. inc(pc);
  2793. until false;
  2794. end
  2795. else
  2796. Message1(option_no_option_found,'(env) '+envname);
  2797. FreeEnvPChar(env);
  2798. end;
  2799. procedure toption.read_parameters;
  2800. var
  2801. opts : TCmdStr;
  2802. paramindex : longint;
  2803. begin
  2804. paramindex:=0;
  2805. while paramindex<paramcount do
  2806. begin
  2807. inc(paramindex);
  2808. opts:=objpas.paramstr(paramindex);
  2809. if length(opts)>0 then
  2810. case opts[1] of
  2811. '@' :
  2812. if not firstpass then
  2813. begin
  2814. Delete(opts,1,1);
  2815. Message1(option_reading_further_from,opts);
  2816. interpret_file(opts);
  2817. end;
  2818. '!' :
  2819. if not firstpass then
  2820. begin
  2821. Delete(opts,1,1);
  2822. Message1(option_reading_further_from,'(env) '+opts);
  2823. interpret_envvar(opts);
  2824. end;
  2825. else
  2826. interpret_option(opts,true);
  2827. end;
  2828. end;
  2829. end;
  2830. procedure toption.parsecmd(cmd:TCmdStr);
  2831. var
  2832. i,ps : longint;
  2833. opts : TCmdStr;
  2834. begin
  2835. while (cmd<>'') do
  2836. begin
  2837. while cmd[1]=' ' do
  2838. delete(cmd,1,1);
  2839. i:=pos(' ',cmd);
  2840. if i=0 then
  2841. i:=2147483647;
  2842. opts:=Copy(cmd,1,i-1);
  2843. Delete(cmd,1,i);
  2844. case opts[1] of
  2845. '@' :
  2846. if not firstpass then
  2847. begin
  2848. Delete(opts,1,1);
  2849. Message1(option_reading_further_from,opts);
  2850. interpret_file(opts);
  2851. end;
  2852. '!' :
  2853. if not firstpass then
  2854. begin
  2855. Delete(opts,1,1);
  2856. Message1(option_reading_further_from,'(env) '+opts);
  2857. interpret_envvar(opts);
  2858. end;
  2859. '"' :
  2860. begin
  2861. Delete(opts,1,1);
  2862. ps:=pos('"',cmd);
  2863. if (i<>256) and (ps>0) then
  2864. begin
  2865. opts:=opts + ' '+ copy(cmd,1,ps-1);
  2866. cmd:=copy(cmd,ps+1,255);
  2867. end;
  2868. interpret_option(opts,true);
  2869. end;
  2870. else
  2871. interpret_option(opts,true);
  2872. end;
  2873. end;
  2874. end;
  2875. procedure toption.writequickinfo;
  2876. var
  2877. s : string;
  2878. i : longint;
  2879. procedure addinfo(const hs:string);
  2880. begin
  2881. if s<>'' then
  2882. s:=s+' '+hs
  2883. else
  2884. s:=hs;
  2885. end;
  2886. begin
  2887. s:='';
  2888. i:=0;
  2889. while (i<length(quickinfo)) do
  2890. begin
  2891. inc(i);
  2892. case quickinfo[i] of
  2893. 'S' :
  2894. begin
  2895. inc(i);
  2896. case quickinfo[i] of
  2897. 'O' :
  2898. addinfo(lower(source_info.shortname));
  2899. 'P' :
  2900. addinfo(source_cpu_string);
  2901. else
  2902. IllegalPara('-i'+QuickInfo);
  2903. end;
  2904. end;
  2905. 'T' :
  2906. begin
  2907. inc(i);
  2908. case quickinfo[i] of
  2909. 'O' :
  2910. addinfo(lower(target_info.shortname));
  2911. 'P' :
  2912. AddInfo(target_cpu_string);
  2913. else
  2914. IllegalPara('-i'+QuickInfo);
  2915. end;
  2916. end;
  2917. 'V' :
  2918. AddInfo(version_string);
  2919. 'W' :
  2920. AddInfo(full_version_string);
  2921. 'D' :
  2922. AddInfo(date_string);
  2923. '_' :
  2924. ;
  2925. else
  2926. IllegalPara('-i'+QuickInfo);
  2927. end;
  2928. end;
  2929. if s<>'' then
  2930. begin
  2931. writeln(s);
  2932. stopoptions(0);
  2933. end;
  2934. end;
  2935. procedure TOption.TargetOptions(def:boolean);
  2936. var
  2937. s : string;
  2938. i : integer;
  2939. target_unsup_features : tfeatures;
  2940. begin
  2941. if def then
  2942. def_system_macro(target_info.shortname)
  2943. else
  2944. undef_system_macro(target_info.shortname);
  2945. s:=target_info.extradefines;
  2946. while (s<>'') do
  2947. begin
  2948. i:=pos(';',s);
  2949. if i=0 then
  2950. i:=length(s)+1;
  2951. if def then
  2952. def_system_macro(Copy(s,1,i-1))
  2953. else
  2954. undef_system_macro(Copy(s,1,i-1));
  2955. delete(s,1,i);
  2956. end;
  2957. if (tf_winlikewidestring in target_info.flags) then
  2958. if def then
  2959. def_system_macro('FPC_WINLIKEWIDESTRING')
  2960. else
  2961. undef_system_macro('FPC_WINLIKEWIDESTRING');
  2962. if (tf_requires_proper_alignment in target_info.flags) then
  2963. if def then
  2964. def_system_macro('FPC_REQUIRES_PROPER_ALIGNMENT')
  2965. else
  2966. undef_system_macro('FPC_REQUIRES_PROPER_ALIGNMENT');
  2967. if source_info.system<>target_info.system then
  2968. if def then
  2969. def_system_macro('FPC_CROSSCOMPILING')
  2970. else
  2971. undef_system_macro('FPC_CROSSCOMPILING');
  2972. if source_info.cpu<>target_info.cpu then
  2973. if def then
  2974. def_system_macro('FPC_CPUCROSSCOMPILING')
  2975. else
  2976. def_system_macro('FPC_CPUCROSSCOMPILING');
  2977. if (tf_no_generic_stackcheck in target_info.flags) then
  2978. if def then
  2979. def_system_macro('FPC_NO_GENERIC_STACK_CHECK')
  2980. else
  2981. undef_system_macro('FPC_NO_GENERIC_STACK_CHECK');
  2982. if (tf_section_threadvars in target_info.flags) then
  2983. if def then
  2984. def_system_macro('FPC_SECTION_THREADVARS')
  2985. else
  2986. undef_system_macro('FPC_SECTION_THREADVARS');
  2987. { Code generation flags }
  2988. if (tf_pic_default in target_info.flags) then
  2989. if def then
  2990. include(init_settings.moduleswitches,cs_create_pic)
  2991. else
  2992. exclude(init_settings.moduleswitches,cs_create_pic);
  2993. { Resources support }
  2994. if (tf_has_winlike_resources in target_info.flags) then
  2995. if def then
  2996. def_system_macro('FPC_HAS_WINLIKERESOURCES')
  2997. else
  2998. undef_system_macro('FPC_HAS_WINLIKERESOURCES');
  2999. { Features }
  3000. case target_info.system of
  3001. system_arm_gba:
  3002. target_unsup_features:=[f_dynlibs];
  3003. system_arm_nds:
  3004. target_unsup_features:=[f_threading,f_commandargs,f_fileio,f_textio,f_consoleio,f_dynlibs];
  3005. system_i386_nativent:
  3006. // until these features are implemented, they are disabled in the compiler
  3007. target_unsup_features:=[f_stackcheck];
  3008. system_i8086_msdos:
  3009. target_unsup_features:=[f_threading,f_dynlibs];
  3010. system_jvm_java32,
  3011. system_jvm_android32:
  3012. target_unsup_features:=[f_heap,f_textio,f_consoleio,f_fileio,
  3013. f_variants,f_objects,f_commandargs,
  3014. f_processes,f_stackcheck,f_dynlibs,f_softfpu,f_objectivec1,f_resources];
  3015. system_arm_palmos,
  3016. system_m68k_palmos:
  3017. target_unsup_features:=[f_threading];
  3018. else
  3019. target_unsup_features:=[];
  3020. end;
  3021. if def then
  3022. features:=features-target_unsup_features
  3023. else
  3024. features:=features+target_unsup_features;
  3025. {$if defined(atari) or defined(hasamiga)}
  3026. { enable vlink as default linker on Atari, Amiga, and MorphOS, but not for cross compilers (for now) }
  3027. if (target_info.system in [system_m68k_amiga,system_m68k_atari,
  3028. system_powerpc_amiga,system_powerpc_morphos]) and
  3029. not LinkerSetExplicitly then
  3030. include(init_settings.globalswitches,cs_link_vlink);
  3031. {$endif}
  3032. end;
  3033. procedure TOption.checkoptionscompatibility;
  3034. begin
  3035. {$ifdef i8086}
  3036. if (apptype=app_com) and (init_settings.x86memorymodel<>mm_tiny) then
  3037. begin
  3038. Message(option_com_files_require_tiny_model);
  3039. StopOptions(1);
  3040. end;
  3041. {$endif i8086}
  3042. if (paratargetdbg in [dbg_dwarf2,dbg_dwarf3]) and
  3043. not(target_info.system in (systems_darwin+[system_i8086_msdos,system_i8086_embedded])) then
  3044. begin
  3045. { smartlink creation does not yet work with DWARF
  3046. debug info on most targets, but it works in internal assembler }
  3047. if (cs_create_smart in init_settings.moduleswitches) and
  3048. not (af_outputbinary in target_asm.flags) then
  3049. begin
  3050. Message(option_dwarf_smartlink_creation);
  3051. exclude(init_settings.moduleswitches,cs_create_smart);
  3052. end;
  3053. { smart linking does not yet work with DWARF debug info on most targets }
  3054. if (cs_link_smart in init_settings.globalswitches) then
  3055. begin
  3056. Message(option_dwarf_smart_linking);
  3057. ForceStaticLinking;
  3058. end;
  3059. end;
  3060. { external debug info is only supported for DWARF on darwin }
  3061. if (target_info.system in systems_darwin) and
  3062. (cs_link_separate_dbg_file in init_settings.globalswitches) and
  3063. not(paratargetdbg in [dbg_dwarf2,dbg_dwarf3]) then
  3064. begin
  3065. Message(option_debug_external_unsupported);
  3066. exclude(init_settings.globalswitches,cs_link_separate_dbg_file);
  3067. end;
  3068. { Also create a smartlinked version, on an assembler that
  3069. does not support smartlink sections like nasm?
  3070. This is not compatible with using internal linker. }
  3071. if ((cs_link_smart in init_settings.globalswitches) or
  3072. (cs_create_smart in init_settings.moduleswitches)) and
  3073. (af_needar in target_asm.flags) and
  3074. not (af_smartlink_sections in target_asm.flags) and
  3075. not (cs_link_extern in init_settings.globalswitches) and
  3076. (target_info.link<>ld_none) and
  3077. not (cs_link_nolink in init_settings.globalswitches) then
  3078. begin
  3079. Message(option_smart_link_requires_external_linker);
  3080. include(init_settings.globalswitches,cs_link_extern);
  3081. end;
  3082. end;
  3083. constructor TOption.create;
  3084. begin
  3085. LogoWritten:=false;
  3086. NoPressEnter:=false;
  3087. FirstPass:=false;
  3088. ABISetExplicitly:=false;
  3089. FPUSetExplicitly:=false;
  3090. CPUSetExplicitly:=false;
  3091. OptCPUSetExplicitly:=false;
  3092. FileLevel:=0;
  3093. Quickinfo:='';
  3094. ParaIncludeCfgPath:=TSearchPathList.Create;
  3095. ParaIncludePath:=TSearchPathList.Create;
  3096. ParaObjectPath:=TSearchPathList.Create;
  3097. ParaUnitPath:=TSearchPathList.Create;
  3098. ParaLibraryPath:=TSearchPathList.Create;
  3099. ParaFrameworkPath:=TSearchPathList.Create;
  3100. parapackagepath:=TSearchPathList.Create;
  3101. parapackages:=TFPHashObjectList.Create;
  3102. FillChar(ParaAlignment,sizeof(ParaAlignment),0);
  3103. MacVersionSet:=false;
  3104. paratarget:=system_none;
  3105. paratargetasm:=as_none;
  3106. paratargetdbg:=dbg_none;
  3107. LinkTypeSetExplicitly:=false;
  3108. LinkerSetExplicitly:=false;
  3109. end;
  3110. destructor TOption.destroy;
  3111. begin
  3112. ParaIncludeCfgPath.Free;
  3113. ParaIncludePath.Free;
  3114. ParaObjectPath.Free;
  3115. ParaUnitPath.Free;
  3116. ParaLibraryPath.Free;
  3117. ParaFrameworkPath.Free;
  3118. parapackagepath.Free;
  3119. ParaPackages.Free;
  3120. end;
  3121. {****************************************************************************
  3122. Callable Routines
  3123. ****************************************************************************}
  3124. function check_configfile(fn:string; var foundfn:string):boolean;
  3125. function CfgFileExists(const fn:string):boolean;
  3126. begin
  3127. Comment(V_Tried,'Configfile search: '+fn);
  3128. CfgFileExists:=FileExists(fn);
  3129. end;
  3130. var
  3131. {$ifdef Unix}
  3132. hs,
  3133. {$endif Unix}
  3134. configpath : string;
  3135. begin
  3136. foundfn:=fn;
  3137. check_configfile:=true;
  3138. { retrieve configpath }
  3139. configpath:=FixPath(GetEnvironmentVariable('PPC_CONFIG_PATH'),false);
  3140. {$ifdef Unix}
  3141. if configpath='' then
  3142. configpath:=ExpandFileName(FixPath(exepath+'../etc/',false));
  3143. {$endif}
  3144. {
  3145. Order to read configuration file :
  3146. try reading fpc.cfg in :
  3147. 1 - current dir
  3148. 2 - configpath
  3149. 3 - compiler path
  3150. }
  3151. if not FileExists(fn) then
  3152. begin
  3153. {$ifdef Unix}
  3154. hs:=GetEnvironmentVariable('HOME');
  3155. if (hs<>'') and CfgFileExists(FixPath(hs,false)+'.'+fn) then
  3156. foundfn:=FixPath(hs,false)+'.'+fn
  3157. else
  3158. {$endif}
  3159. if CfgFileExists(configpath+fn) then
  3160. foundfn:=configpath+fn
  3161. else
  3162. {$ifdef WINDOWS}
  3163. if (GetEnvironmentVariable('USERPROFILE')<>'') and CfgFileExists(FixPath(GetEnvironmentVariable('USERPROFILE'),false)+fn) then
  3164. foundfn:=FixPath(GetEnvironmentVariable('USERPROFILE'),false)+fn
  3165. else
  3166. if (GetEnvironmentVariable('ALLUSERSPROFILE')<>'') and CfgFileExists(FixPath(GetEnvironmentVariable('ALLUSERSPROFILE'),false)+fn) then
  3167. foundfn:=FixPath(GetEnvironmentVariable('ALLUSERSPROFILE'),false)+fn
  3168. else
  3169. {$endif WINDOWS}
  3170. {$ifndef Unix}
  3171. if CfgFileExists(exepath+fn) then
  3172. foundfn:=exepath+fn
  3173. else
  3174. {$else}
  3175. if CfgFileExists('/etc/'+fn) then
  3176. foundfn:='/etc/'+fn
  3177. else
  3178. {$endif}
  3179. check_configfile:=false;
  3180. end;
  3181. end;
  3182. procedure read_arguments(cmd:TCmdStr);
  3183. var
  3184. env: ansistring;
  3185. i : tfeature;
  3186. j : longint;
  3187. abi : tabi;
  3188. {$if defined(cpucapabilities)}
  3189. cpuflag : tcpuflags;
  3190. hs : string;
  3191. {$endif defined(cpucapabilities)}
  3192. begin
  3193. option:=coption.create;
  3194. disable_configfile:=false;
  3195. { Non-core target defines }
  3196. Option.TargetOptions(true);
  3197. { get default messagefile }
  3198. msgfilename:=GetEnvironmentVariable('PPC_ERROR_FILE');
  3199. { default configfile can be specified on the commandline,
  3200. remove it first }
  3201. if (cmd<>'') and (cmd[1]='[') then
  3202. begin
  3203. ppccfg:=Copy(cmd,2,pos(']',cmd)-2);
  3204. Delete(cmd,1,pos(']',cmd));
  3205. end
  3206. else
  3207. ppccfg:='fpc.cfg';
  3208. { first pass reading of parameters, only -i -v -T etc.}
  3209. option.firstpass:=true;
  3210. if cmd<>'' then
  3211. option.parsecmd(cmd)
  3212. else
  3213. begin
  3214. option.read_parameters;
  3215. { Write only quickinfo }
  3216. if option.quickinfo<>'' then
  3217. option.writequickinfo;
  3218. end;
  3219. option.firstpass:=false;
  3220. { redefine target options so all defines are written even if no -Txxx is passed on the command line }
  3221. Option.TargetOptions(true);
  3222. { target is set here, for wince the default app type is gui }
  3223. if target_info.system in systems_wince then
  3224. SetApptype(app_gui)
  3225. else
  3226. SetApptype(apptype);
  3227. { default defines }
  3228. def_system_macro(target_info.shortname);
  3229. def_system_macro('FPC');
  3230. def_system_macro('VER'+version_nr);
  3231. def_system_macro('VER'+version_nr+'_'+release_nr);
  3232. def_system_macro('VER'+version_nr+'_'+release_nr+'_'+patch_nr);
  3233. { Temporary defines, until things settle down }
  3234. def_system_macro('FPC_HAS_OPERATOR_ENUMERATOR');
  3235. def_system_macro('FPC_HAS_CONSTREF');
  3236. def_system_macro('FPC_STATICRIPFIXED');
  3237. def_system_macro('FPC_VARIANTCOPY_FIXED');
  3238. def_system_macro('FPC_DYNARRAYCOPY_FIXED');
  3239. {$if defined(avr)}
  3240. def_system_macro('FPC_HAS_INTERNAL_ABS_SHORTINT');
  3241. {$endif}
  3242. {$if defined(i8086) or defined(avr)}
  3243. def_system_macro('FPC_HAS_INTERNAL_ABS_SMALLINT');
  3244. {$endif i8086 or avr}
  3245. { abs(long) is handled internally on all CPUs }
  3246. def_system_macro('FPC_HAS_INTERNAL_ABS_LONG');
  3247. {$if defined(i8086) or defined(i386) or defined(x86_64) or defined(powerpc64) or defined(cpuaarch64)}
  3248. def_system_macro('FPC_HAS_INTERNAL_ABS_INT64');
  3249. {$endif i8086 or i386 or x86_64 or powerpc64 or aarch64}
  3250. def_system_macro('FPC_HAS_MANAGEMENT_OPERATORS');
  3251. def_system_macro('FPC_HAS_UNICODESTRING');
  3252. def_system_macro('FPC_RTTI_PACKSET1');
  3253. def_system_macro('FPC_HAS_CPSTRING');
  3254. {$ifdef x86_64}
  3255. def_system_macro('FPC_HAS_RIP_RELATIVE');
  3256. {$endif x86_64}
  3257. def_system_macro('FPC_HAS_CEXTENDED');
  3258. def_system_macro('FPC_HAS_RESSTRINITS');
  3259. { these cpus have an inline rol/ror implementaion }
  3260. {$ifdef cpurox}
  3261. {$ifdef m68k}
  3262. if CPUM68K_HAS_ROLROR in cpu_capabilities[init_settings.cputype] then
  3263. def_system_macro('FPC_HAS_INTERNAL_ROX');
  3264. {$else}
  3265. def_system_macro('FPC_HAS_INTERNAL_ROX');
  3266. {$endif}
  3267. {$endif}
  3268. { currently, all supported CPUs have an internal sar implementation }
  3269. def_system_macro('FPC_HAS_INTERNAL_SAR');
  3270. {$ifdef powerpc64}
  3271. def_system_macro('FPC_HAS_LWSYNC');
  3272. {$endif}
  3273. def_system_macro('FPC_HAS_MEMBAR');
  3274. def_system_macro('FPC_SETBASE_USED');
  3275. {$ifdef SUPPORT_GET_FRAME}
  3276. def_system_macro('INTERNAL_BACKTRACE');
  3277. {$endif SUPPORT_GET_FRAME}
  3278. def_system_macro('STR_CONCAT_PROCS');
  3279. {$warnings off}
  3280. if pocall_default = pocall_register then
  3281. def_system_macro('REGCALL');
  3282. {$warnings on}
  3283. { don't remove this, it's also for fpdoc necessary (FK) }
  3284. def_system_macro('FPC_HAS_FEATURE_SUPPORT');
  3285. { using a case is pretty useless here (FK) }
  3286. { some stuff for TP compatibility }
  3287. {$ifdef i386}
  3288. def_system_macro('CPU86');
  3289. def_system_macro('CPU87');
  3290. def_system_macro('CPU386');
  3291. {$endif}
  3292. { new processor stuff }
  3293. {$ifdef i386}
  3294. def_system_macro('CPUI386');
  3295. def_system_macro('CPU32');
  3296. def_system_macro('CPUX86');
  3297. def_system_macro('FPC_HAS_TYPE_EXTENDED');
  3298. def_system_macro('FPC_HAS_TYPE_DOUBLE');
  3299. def_system_macro('FPC_HAS_TYPE_SINGLE');
  3300. {$endif}
  3301. {$ifdef m68k}
  3302. def_system_macro('CPU68');
  3303. def_system_macro('CPU68K');
  3304. def_system_macro('CPUM68K');
  3305. def_system_macro('CPU32');
  3306. def_system_macro('FPC_CURRENCY_IS_INT64');
  3307. def_system_macro('FPC_COMP_IS_INT64');
  3308. {$endif}
  3309. {$ifdef powerpc}
  3310. def_system_macro('CPUPOWERPC');
  3311. def_system_macro('CPUPOWERPC32');
  3312. def_system_macro('CPU32');
  3313. def_system_macro('FPC_CURRENCY_IS_INT64');
  3314. def_system_macro('FPC_COMP_IS_INT64');
  3315. {$endif}
  3316. {$ifdef POWERPC64}
  3317. def_system_macro('CPUPOWERPC');
  3318. def_system_macro('CPUPOWERPC64');
  3319. def_system_macro('CPU64');
  3320. def_system_macro('FPC_CURRENCY_IS_INT64');
  3321. def_system_macro('FPC_COMP_IS_INT64');
  3322. {$endif}
  3323. {$ifdef x86_64}
  3324. def_system_macro('CPUX86_64');
  3325. def_system_macro('CPUAMD64');
  3326. def_system_macro('CPU64');
  3327. def_system_macro('CPUX64');
  3328. { not supported for now, afaik (FK)
  3329. def_system_macro('FPC_HAS_TYPE_FLOAT128'); }
  3330. {$ifndef FPC_SUPPORT_X87_TYPES_ON_WIN64}
  3331. { normally, win64 doesn't support the legacy fpu }
  3332. if target_info.system=system_x86_64_win64 then
  3333. begin
  3334. def_system_macro('FPC_CURRENCY_IS_INT64');
  3335. def_system_macro('FPC_COMP_IS_INT64');
  3336. end;
  3337. {$endif FPC_SUPPORT_X87_TYPES_ON_WIN64}
  3338. {$endif}
  3339. {$ifdef sparc}
  3340. def_system_macro('CPUSPARCGEN');
  3341. def_system_macro('CPUSPARC');
  3342. def_system_macro('CPUSPARC32');
  3343. def_system_macro('CPU32');
  3344. def_system_macro('FPC_CURRENCY_IS_INT64');
  3345. def_system_macro('FPC_COMP_IS_INT64');
  3346. {$endif}
  3347. {$ifdef sparc64}
  3348. def_system_macro('CPUSPARCGEN');
  3349. def_system_macro('CPUSPARC64');
  3350. def_system_macro('CPU64');
  3351. def_system_macro('FPC_CURRENCY_IS_INT64');
  3352. def_system_macro('FPC_COMP_IS_INT64');
  3353. {$endif}
  3354. {$ifdef arm}
  3355. def_system_macro('CPUARM');
  3356. def_system_macro('CPU32');
  3357. def_system_macro('FPC_CURRENCY_IS_INT64');
  3358. def_system_macro('FPC_COMP_IS_INT64');
  3359. {$endif arm}
  3360. {$ifdef avr}
  3361. def_system_macro('CPUAVR');
  3362. def_system_macro('CPU16');
  3363. def_system_macro('FPC_CURRENCY_IS_INT64');
  3364. def_system_macro('FPC_COMP_IS_INT64');
  3365. {$endif avr}
  3366. {$ifdef jvm}
  3367. def_system_macro('CPUJVM');
  3368. def_system_macro('CPU32');
  3369. def_system_macro('FPC_CURRENCY_IS_INT64');
  3370. def_system_macro('FPC_COMP_IS_INT64');
  3371. {$endif jvm}
  3372. {$ifdef mipsel}
  3373. def_system_macro('CPUMIPS');
  3374. def_system_macro('CPUMIPS32');
  3375. def_system_macro('CPUMIPSEL');
  3376. def_system_macro('CPUMIPSEL32');
  3377. def_system_macro('CPU32');
  3378. def_system_macro('FPC_HAS_TYPE_DOUBLE');
  3379. def_system_macro('FPC_HAS_TYPE_SINGLE');
  3380. def_system_macro('FPC_INCLUDE_SOFTWARE_INT64_TO_DOUBLE');
  3381. def_system_macro('FPC_CURRENCY_IS_INT64');
  3382. def_system_macro('FPC_COMP_IS_INT64');
  3383. def_system_macro('FPC_REQUIRES_PROPER_ALIGNMENT');
  3384. { On most systems, locals are accessed relative to base pointer,
  3385. but for MIPS cpu, they are accessed relative to stack pointer.
  3386. This needs adaptation for so low level routines,
  3387. like MethodPointerLocal and related objects unit functions. }
  3388. def_system_macro('FPC_LOCALS_ARE_STACK_REG_RELATIVE');
  3389. {$endif mipsel}
  3390. {$ifdef mipseb}
  3391. def_system_macro('CPUMIPS');
  3392. def_system_macro('CPUMIPS32');
  3393. def_system_macro('CPUMIPSEB');
  3394. def_system_macro('CPUMIPSEB32');
  3395. def_system_macro('CPU32');
  3396. def_system_macro('FPC_HAS_TYPE_DOUBLE');
  3397. def_system_macro('FPC_HAS_TYPE_SINGLE');
  3398. def_system_macro('FPC_INCLUDE_SOFTWARE_INT64_TO_DOUBLE');
  3399. def_system_macro('FPC_CURRENCY_IS_INT64');
  3400. def_system_macro('FPC_COMP_IS_INT64');
  3401. def_system_macro('FPC_REQUIRES_PROPER_ALIGNMENT');
  3402. { See comment above for mipsel }
  3403. def_system_macro('FPC_LOCALS_ARE_STACK_REG_RELATIVE');
  3404. {$endif}
  3405. {$ifdef i8086}
  3406. def_system_macro('CPU86'); { Borland compatibility }
  3407. def_system_macro('CPU87'); { Borland compatibility }
  3408. def_system_macro('CPUI8086');
  3409. def_system_macro('CPU16');
  3410. def_system_macro('FPC_HAS_TYPE_EXTENDED');
  3411. def_system_macro('FPC_HAS_TYPE_DOUBLE');
  3412. def_system_macro('FPC_HAS_TYPE_SINGLE');
  3413. case init_settings.x86memorymodel of
  3414. mm_tiny: def_system_macro('FPC_MM_TINY');
  3415. mm_small: def_system_macro('FPC_MM_SMALL');
  3416. mm_medium: def_system_macro('FPC_MM_MEDIUM');
  3417. mm_compact: def_system_macro('FPC_MM_COMPACT');
  3418. mm_large: def_system_macro('FPC_MM_LARGE');
  3419. mm_huge: def_system_macro('FPC_MM_HUGE');
  3420. end;
  3421. {$endif i8086}
  3422. {$ifdef aarch64}
  3423. def_system_macro('CPUAARCH64');
  3424. def_system_macro('CPU64');
  3425. def_system_macro('FPC_CURRENCY_IS_INT64');
  3426. def_system_macro('FPC_COMP_IS_INT64');
  3427. {$endif aarch64}
  3428. {$if defined(cpu8bitalu)}
  3429. def_system_macro('CPUINT8');
  3430. {$elseif defined(cpu16bitalu)}
  3431. def_system_macro('CPUINT16');
  3432. {$elseif defined(cpu32bitalu)}
  3433. def_system_macro('CPUINT32');
  3434. {$elseif defined(cpu64bitalu)}
  3435. def_system_macro('CPUINT64');
  3436. {$endif defined(cpu64bitalu)}
  3437. if tf_cld in target_info.flags then
  3438. if not UpdateTargetSwitchStr('CLD', init_settings.targetswitches, true) then
  3439. InternalError(2013092801);
  3440. if tf_x86_far_procs_push_odd_bp in target_info.flags then
  3441. if not UpdateTargetSwitchStr('FARPROCSPUSHODDBP', init_settings.targetswitches, true) then
  3442. InternalError(2013092801);
  3443. { Set up a default prefix for binutils when cross-compiling }
  3444. if source_info.system<>target_info.system then
  3445. case target_info.system of
  3446. { Use standard Android NDK prefixes }
  3447. system_arm_android:
  3448. utilsprefix:='arm-linux-androideabi-';
  3449. system_i386_android:
  3450. utilsprefix:='i686-linux-android-';
  3451. system_mipsel_android:
  3452. utilsprefix:='mipsel-linux-android-';
  3453. end;
  3454. { Set up default value for the heap }
  3455. if target_info.system in systems_embedded then
  3456. begin
  3457. case target_info.system of
  3458. {$ifdef AVR}
  3459. system_avr_embedded:
  3460. if init_settings.controllertype=ct_avrsim then
  3461. heapsize:=8192
  3462. else
  3463. heapsize:=128;
  3464. {$endif AVR}
  3465. system_arm_embedded:
  3466. heapsize:=256;
  3467. system_mipsel_embedded:
  3468. heapsize:=256;
  3469. else
  3470. heapsize:=256;
  3471. end;
  3472. end;
  3473. { read configuration file }
  3474. if (not disable_configfile) and
  3475. (ppccfg<>'') then
  3476. read_configfile:=check_configfile(ppccfg,ppccfg)
  3477. else
  3478. read_configfile := false;
  3479. { Read commandline and configfile }
  3480. param_file:='';
  3481. { read configfile }
  3482. if read_configfile then
  3483. option.interpret_file(ppccfg);
  3484. { read parameters again to override config file }
  3485. if cmd<>'' then
  3486. option.parsecmd(cmd)
  3487. else
  3488. begin
  3489. { Write help pages if no parameters are passed }
  3490. if (paramcount=0) then
  3491. Option.WriteHelpPages;
  3492. option.read_parameters;
  3493. { Write only quickinfo }
  3494. if option.quickinfo<>'' then
  3495. option.writequickinfo;
  3496. end;
  3497. { check the compatibility of different options and adjust them if necessary
  3498. (and print possible errors)
  3499. }
  3500. option.checkoptionscompatibility;
  3501. { uses the CPUXXX-defines and target_info to determine whether the selected
  3502. target processor, if any, is supported }
  3503. Option.VerifyTargetProcessor;
  3504. { Stop if errors in options }
  3505. if ErrorCount>0 then
  3506. StopOptions(1);
  3507. { endian define }
  3508. case target_info.endian of
  3509. endian_little :
  3510. begin
  3511. def_system_macro('ENDIAN_LITTLE');
  3512. def_system_macro('FPC_LITTLE_ENDIAN');
  3513. end;
  3514. endian_big :
  3515. begin
  3516. def_system_macro('ENDIAN_BIG');
  3517. def_system_macro('FPC_BIG_ENDIAN');
  3518. end;
  3519. end;
  3520. { define abi }
  3521. for abi:=low(tabi) to high(tabi) do
  3522. undef_system_macro('FPC_ABI_'+abiinfo[abi].name);
  3523. def_system_macro('FPC_ABI_'+abiinfo[target_info.abi].name);
  3524. { Define FPC_ABI_EABI in addition to FPC_ABI_EABIHF on EABI VFP hardfloat
  3525. systems since most code needs to behave the same on both}
  3526. if target_info.abi = abi_eabihf then
  3527. def_system_macro('FPC_ABI_EABI');
  3528. { Write logo }
  3529. if option.ParaLogo then
  3530. option.writelogo;
  3531. { Check file to compile }
  3532. if param_file='' then
  3533. begin
  3534. Message(option_no_source_found);
  3535. StopOptions(1);
  3536. end;
  3537. {$ifndef Unix}
  3538. param_file:=FixFileName(param_file);
  3539. {$endif not unix}
  3540. inputfilepath:=ExtractFilePath(param_file);
  3541. inputfilename:=ExtractFileName(param_file);
  3542. if ExtractFileExt(inputfilename)='' then
  3543. begin
  3544. if FileExists(inputfilepath+ChangeFileExt(inputfilename,sourceext)) then
  3545. inputfilename:=ChangeFileExt(inputfilename,sourceext)
  3546. else if FileExists(inputfilepath+ChangeFileExt(inputfilename,pasext)) then
  3547. inputfilename:=ChangeFileExt(inputfilename,pasext)
  3548. else if ((m_mac in current_settings.modeswitches) or
  3549. (tf_p_ext_support in target_info.flags))
  3550. and FileExists(inputfilepath+ChangeFileExt(inputfilename,pext)) then
  3551. inputfilename:=ChangeFileExt(inputfilename,pext);
  3552. end;
  3553. { Check output dir }
  3554. if (OutputExeDir<>'') and
  3555. not PathExists(OutputExeDir,false) then
  3556. begin
  3557. Message1(general_e_path_does_not_exist,OutputExeDir);
  3558. StopOptions(1);
  3559. end;
  3560. { Add paths specified with parameters to the searchpaths }
  3561. UnitSearchPath.AddList(option.ParaUnitPath,true);
  3562. ObjectSearchPath.AddList(option.ParaObjectPath,true);
  3563. IncludeSearchPath.AddList(option.ParaIncludePath,true);
  3564. LibrarySearchPath.AddList(option.ParaLibraryPath,true);
  3565. FrameworkSearchPath.AddList(option.ParaFrameworkPath,true);
  3566. packagesearchpath.addlist(option.parapackagepath,true);
  3567. for j:=0 to option.parapackages.count-1 do
  3568. add_package(option.parapackages.NameOfIndex(j),true,true);
  3569. { add unit environment and exepath to the unit search path }
  3570. if inputfilepath<>'' then
  3571. Unitsearchpath.AddPath(inputfilepath,true);
  3572. if not disable_configfile then
  3573. begin
  3574. env:=GetEnvironmentVariable(target_info.unit_env);
  3575. if env<>'' then
  3576. UnitSearchPath.AddPath(GetEnvironmentVariable(target_info.unit_env),false);
  3577. end;
  3578. {$ifdef Unix}
  3579. fpcdir:=FixPath(GetEnvironmentVariable('FPCDIR'),false);
  3580. if fpcdir='' then
  3581. begin
  3582. if PathExists('/usr/local/lib/fpc/'+version_string,true) then
  3583. fpcdir:='/usr/local/lib/fpc/'+version_string+'/'
  3584. else
  3585. fpcdir:='/usr/lib/fpc/'+version_string+'/';
  3586. end;
  3587. {$else unix}
  3588. fpcdir:=FixPath(GetEnvironmentVariable('FPCDIR'),false);
  3589. if fpcdir='' then
  3590. begin
  3591. fpcdir:=ExePath+'../';
  3592. if not(PathExists(fpcdir+'units',true)) and
  3593. not(PathExists(fpcdir+'rtl',true)) then
  3594. fpcdir:=fpcdir+'../';
  3595. end;
  3596. {$endif unix}
  3597. { first try development RTL, else use the default installation path }
  3598. if not disable_configfile then
  3599. begin
  3600. if PathExists(FpcDir+'rtl',true) then
  3601. if (tf_use_8_3 in Source_Info.Flags) or
  3602. (tf_use_8_3 in Target_Info.Flags) then
  3603. UnitSearchPath.AddPath(FpcDir+'rtl/'+target_os_string,false)
  3604. else
  3605. UnitSearchPath.AddPath(FpcDir+'rtl/'+target_full_string,false)
  3606. else
  3607. if (tf_use_8_3 in Source_Info.Flags) or
  3608. (tf_use_8_3 in Target_Info.Flags) then
  3609. UnitSearchPath.AddPath(FpcDir+'units/'+target_os_string+'/rtl',false)
  3610. else
  3611. UnitSearchPath.AddPath(FpcDir+'units/'+target_full_string+'/rtl',false);
  3612. end;
  3613. { Add exepath if the exe is not in the current dir, because that is always searched already.
  3614. Do not add it when linking on the target because then we can maybe already find
  3615. .o files that are not for the target }
  3616. if (ExePath<>cfileutl.GetCurrentDir) and
  3617. not(cs_link_on_target in init_settings.globalswitches) then
  3618. UnitSearchPath.AddPath(ExePath,false);
  3619. { Add unit dir to the object and library path }
  3620. objectsearchpath.AddList(unitsearchpath,false);
  3621. librarysearchpath.AddList(unitsearchpath,false);
  3622. {$ifdef llvm}
  3623. { force llvm assembler writer }
  3624. option.paratargetasm:=as_llvm;
  3625. {$endif llvm}
  3626. { maybe override assembler }
  3627. if (option.paratargetasm<>as_none) then
  3628. begin
  3629. if not set_target_asm(option.paratargetasm) then
  3630. begin
  3631. Message2(option_incompatible_asm,asminfos[option.paratargetasm]^.idtxt,target_info.name);
  3632. set_target_asm(target_info.assemextern);
  3633. Message1(option_asm_forced,target_asm.idtxt);
  3634. end;
  3635. if (af_no_debug in asminfos[option.paratargetasm]^.flags) and
  3636. (option.paratargetdbg<>dbg_none) then
  3637. begin
  3638. Message1(option_confict_asm_debug,
  3639. asminfos[option.paratargetasm]^.idtxt);
  3640. option.paratargetdbg:=dbg_none;
  3641. exclude(init_settings.moduleswitches,cs_debuginfo);
  3642. end;
  3643. end;
  3644. {TOptionheck a second time as we might have changed assembler just above }
  3645. option.checkoptionscompatibility;
  3646. { maybe override debug info format }
  3647. if (option.paratargetdbg<>dbg_none) then
  3648. if not set_target_dbg(option.paratargetdbg) then
  3649. Message(option_w_unsupported_debug_format);
  3650. { switch assembler if it's binary and we got -a on the cmdline }
  3651. if (cs_asm_leave in init_settings.globalswitches) and
  3652. (af_outputbinary in target_asm.flags) then
  3653. begin
  3654. Message(option_switch_bin_to_src_assembler);
  3655. set_target_asm(target_info.assemextern);
  3656. { At least i8086 needs that for nasm and -CX
  3657. which is incompatible with internal linker }
  3658. option.checkoptionscompatibility;
  3659. end;
  3660. { Force use of external linker if there is no
  3661. internal linker or the linking is skipped }
  3662. if not(cs_link_extern in init_settings.globalswitches) and
  3663. ((target_info.link=ld_none) or
  3664. (cs_link_nolink in init_settings.globalswitches)) then
  3665. begin
  3666. include(init_settings.globalswitches,cs_link_extern);
  3667. end;
  3668. { turn off stripping if compiling with debuginfo or profile }
  3669. if (
  3670. (cs_debuginfo in init_settings.moduleswitches) or
  3671. (cs_profile in init_settings.moduleswitches)
  3672. ) and
  3673. not(cs_link_separate_dbg_file in init_settings.globalswitches) then
  3674. exclude(init_settings.globalswitches,cs_link_strip);
  3675. { set Mac OS X version default macros if not specified explicitly }
  3676. option.MaybeSetDefaultMacVersionMacro;
  3677. { force fpu emulation on arm/wince, arm/gba, arm/embedded and arm/nds
  3678. if fpu type not explicitly set }
  3679. if not(option.FPUSetExplicitly) and
  3680. ((target_info.system in [system_arm_wince,system_arm_gba,
  3681. system_m68k_amiga,system_m68k_atari,
  3682. system_arm_nds,system_arm_embedded])
  3683. {$ifdef arm}
  3684. or (target_info.abi=abi_eabi)
  3685. {$endif arm}
  3686. )
  3687. {$if defined(arm) or defined (m68k)}
  3688. or (init_settings.fputype=fpu_soft)
  3689. {$endif arm or m68k}
  3690. then
  3691. begin
  3692. {$ifdef cpufpemu}
  3693. include(init_settings.moduleswitches,cs_fp_emulation);
  3694. { cs_fp_emulation and fpu_soft are equal on arm and m68k }
  3695. init_settings.fputype:=fpu_soft;
  3696. {$endif cpufpemu}
  3697. end;
  3698. {$ifdef i386}
  3699. case target_info.system of
  3700. system_i386_android:
  3701. begin
  3702. { set default cpu type to PentiumM for Android unless specified otherwise }
  3703. if not option.CPUSetExplicitly then
  3704. init_settings.cputype:=cpu_PentiumM;
  3705. if not option.OptCPUSetExplicitly then
  3706. init_settings.optimizecputype:=cpu_PentiumM;
  3707. { set default fpu type to SSSE3 for Android unless specified otherwise }
  3708. if not option.FPUSetExplicitly then
  3709. init_settings.fputype:=fpu_ssse3;
  3710. end;
  3711. end;
  3712. {$endif i386}
  3713. {$ifdef arm}
  3714. case target_info.system of
  3715. system_arm_darwin:
  3716. begin
  3717. { set default cpu type to ARMv7 for Darwin unless specified otherwise, and fpu
  3718. to VFPv3 (that's what all 32 bit ARM iOS devices use nowadays)
  3719. }
  3720. if not option.CPUSetExplicitly then
  3721. init_settings.cputype:=cpu_armv7;
  3722. if not option.OptCPUSetExplicitly then
  3723. init_settings.optimizecputype:=cpu_armv7;
  3724. if not option.FPUSetExplicitly then
  3725. init_settings.fputype:=fpu_vfpv3;
  3726. end;
  3727. system_arm_android:
  3728. begin
  3729. { set default cpu type to ARMv5T for Android unless specified otherwise }
  3730. if not option.CPUSetExplicitly then
  3731. init_settings.cputype:=cpu_armv5t;
  3732. if not option.OptCPUSetExplicitly then
  3733. init_settings.optimizecputype:=cpu_armv5t;
  3734. end;
  3735. end;
  3736. { ARMHF defaults }
  3737. if (target_info.abi = abi_eabihf) then
  3738. { set default cpu type to ARMv7a for ARMHF unless specified otherwise }
  3739. begin
  3740. {$ifdef CPUARMV6}
  3741. { if the compiler is built for armv6, then
  3742. inherit this setting, e.g. Raspian is armhf but
  3743. only armv6, this makes rebuilds of the compiler
  3744. easier }
  3745. if not option.CPUSetExplicitly then
  3746. init_settings.cputype:=cpu_armv6;
  3747. if not option.OptCPUSetExplicitly then
  3748. init_settings.optimizecputype:=cpu_armv6;
  3749. {$else CPUARMV6}
  3750. if not option.CPUSetExplicitly then
  3751. init_settings.cputype:=cpu_armv7a;
  3752. if not option.OptCPUSetExplicitly then
  3753. init_settings.optimizecputype:=cpu_armv7a;
  3754. {$endif CPUARMV6}
  3755. { Set FPU type }
  3756. if not(option.FPUSetExplicitly) then
  3757. begin
  3758. init_settings.fputype:=fpu_vfpv3_d16
  3759. end
  3760. else
  3761. begin
  3762. if not (init_settings.fputype in [fpu_vfpv2,fpu_vfpv3,fpu_vfpv3_d16,fpu_vfpv4]) then
  3763. begin
  3764. Message(option_illegal_fpu_eabihf);
  3765. StopOptions(1);
  3766. end;
  3767. end;
  3768. end;
  3769. if (init_settings.instructionset=is_thumb) and not(CPUARM_HAS_THUMB2 in cpu_capabilities[init_settings.cputype]) then
  3770. begin
  3771. def_system_macro('CPUTHUMB');
  3772. if not option.FPUSetExplicitly then
  3773. init_settings.fputype:=fpu_soft;
  3774. {$if defined(FPC_ARMEL) or defined(FPC_ARMHF)}
  3775. target_info.llvmdatalayout:='e-p:32:32:32-i1:8:32-i8:8:32-i16:16:32-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:64:128-a0:0:32-n32-S64';
  3776. {$else FPC_ARMAL or FPC_ARMHF}
  3777. if target_info.endian=endian_little then
  3778. target_info.llvmdatalayout:='e-p:32:32:32-i1:8:32-i8:8:32-i16:16:32-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:32:64-v128:32:128-a0:0:32-n32-S32';
  3779. {$endif FPC_ARMAL or FPC_ARMHF}
  3780. end;
  3781. if (init_settings.instructionset=is_thumb) and (CPUARM_HAS_THUMB2 in cpu_capabilities[init_settings.cputype]) then
  3782. def_system_macro('CPUTHUMB2');
  3783. {$endif arm}
  3784. {$ifdef jvm}
  3785. { set default CPU type to Dalvik when targeting Android }
  3786. if target_info.system=system_jvm_android32 then
  3787. begin
  3788. if not option.CPUSetExplicitly then
  3789. init_settings.cputype:=cpu_dalvik;
  3790. end;
  3791. {$endif jvm}
  3792. {$ifdef llvm}
  3793. { standard extension for llvm bitcode files }
  3794. target_info.asmext:='.ll';
  3795. { don't generate dwarf cfi, llvm will do that }
  3796. exclude(target_info.flags,tf_needs_dwarf_cfi);
  3797. {$endif llvm}
  3798. {$ifdef mipsel}
  3799. case target_info.system of
  3800. system_mipsel_android:
  3801. begin
  3802. { set default cpu type to MIPS32 rev. 1 and hard float for MIPS-Android unless specified otherwise }
  3803. if not option.CPUSetExplicitly then
  3804. init_settings.cputype:=cpu_mips32;
  3805. if not option.OptCPUSetExplicitly then
  3806. init_settings.optimizecputype:=cpu_mips32;
  3807. if not option.FPUSetExplicitly then
  3808. init_settings.fputype:=fpu_mips2;
  3809. end;
  3810. system_mipsel_embedded:
  3811. begin
  3812. { set default cpu type to PIC32MX and softfloat for MIPSEL-EMBEDDED target unless specified otherwise }
  3813. if not option.CPUSetExplicitly then
  3814. init_settings.cputype:=cpu_pic32mx;
  3815. if not option.OptCPUSetExplicitly then
  3816. init_settings.optimizecputype:=cpu_pic32mx;
  3817. if not option.FPUSetExplicitly then
  3818. init_settings.fputype:=fpu_soft;
  3819. end;
  3820. end;
  3821. {$endif mipsel}
  3822. {$ifdef m68k}
  3823. if init_settings.cputype in cpu_coldfire then
  3824. def_system_macro('CPUCOLDFIRE')
  3825. else
  3826. if (target_info.system in [system_m68k_linux,system_m68k_netbsd]) and
  3827. not (option.FPUSetExplicitly) then
  3828. begin
  3829. { enable HW FPU for UNIX by default, but only for
  3830. original 68k, not Coldfire }
  3831. exclude(init_settings.moduleswitches,cs_fp_emulation);
  3832. init_settings.fputype:=fpu_68881;
  3833. end;
  3834. {$endif m68k}
  3835. { now we can define cpu and fpu type }
  3836. def_system_macro('CPU'+Cputypestr[init_settings.cputype]);
  3837. { Use init_settings cpu type for asm cpu type,
  3838. if asmcputype is cpu_none,
  3839. at least as long as there is no explicit
  3840. option to set it on command line PM }
  3841. if init_settings.asmcputype = cpu_none then
  3842. init_settings.asmcputype:=init_settings.cputype;
  3843. def_system_macro('FPU'+fputypestr[init_settings.fputype]);
  3844. {$ifdef llvm}
  3845. def_system_macro('CPULLVM');
  3846. {$endif llvm}
  3847. {$if defined(cpucapabilities)}
  3848. for cpuflag:=low(cpuflag) to high(cpuflag) do
  3849. begin
  3850. str(cpuflag,hs);
  3851. if cpuflag in cpu_capabilities[init_settings.cputype] then
  3852. def_system_macro(hs)
  3853. else
  3854. undef_system_macro(hs);
  3855. end;
  3856. {$endif defined(cpucapabilities)}
  3857. if init_settings.fputype<>fpu_none then
  3858. begin
  3859. {$if defined(i386) or defined(i8086)}
  3860. def_system_macro('FPC_HAS_TYPE_EXTENDED');
  3861. {$endif}
  3862. def_system_macro('FPC_HAS_TYPE_SINGLE');
  3863. def_system_macro('FPC_HAS_TYPE_DOUBLE');
  3864. {$if not defined(i386) and not defined(x86_64) and not defined(i8086) and not defined(aarch64)}
  3865. def_system_macro('FPC_INCLUDE_SOFTWARE_INT64_TO_DOUBLE');
  3866. {$endif}
  3867. {$if defined(m68k)}
  3868. def_system_macro('FPC_INCLUDE_SOFTWARE_LONGWORD_TO_DOUBLE');
  3869. {$endif}
  3870. {$ifdef x86_64}
  3871. {$ifndef FPC_SUPPORT_X87_TYPES_ON_WIN64}
  3872. { normally, win64 doesn't support the legacy fpu }
  3873. if target_info.system=system_x86_64_win64 then
  3874. undef_system_macro('FPC_HAS_TYPE_EXTENDED')
  3875. else
  3876. {$endif FPC_SUPPORT_X87_TYPES_ON_WIN64}
  3877. def_system_macro('FPC_HAS_TYPE_EXTENDED');
  3878. {$endif}
  3879. end;
  3880. { Enable now for testing }
  3881. {$ifndef DISABLE_TLS_DIRECTORY}
  3882. if target_info.system in systems_windows then
  3883. def_system_macro('FPC_USE_TLS_DIRECTORY');
  3884. {$endif not DISABLE_TLS_DIRECTORY}
  3885. {$ifndef DISABLE_WIN64_SEH}
  3886. if target_info.system=system_x86_64_win64 then
  3887. def_system_macro('FPC_USE_WIN64_SEH');
  3888. {$endif DISABLE_WIN64_SEH}
  3889. {$ifdef TEST_WIN32_SEH}
  3890. if target_info.system=system_i386_win32 then
  3891. def_system_macro('FPC_USE_WIN32_SEH');
  3892. {$endif TEST_WIN32_SEH}
  3893. {$ifdef ARM}
  3894. { define FPC_DOUBLE_HILO_SWAPPED if needed to properly handle doubles in RTL }
  3895. if (init_settings.fputype in [fpu_fpa,fpu_fpa10,fpu_fpa11]) and
  3896. not(cs_fp_emulation in init_settings.moduleswitches) then
  3897. def_system_macro('FPC_DOUBLE_HILO_SWAPPED');
  3898. {$endif ARM}
  3899. { inline bsf/bsr implementation }
  3900. {$if not defined(llvm) and (defined(i386) or defined(x86_64) or defined(aarch64) or defined(powerpc) or defined(powerpc64))}
  3901. def_system_macro('FPC_HAS_INTERNAL_BSF');
  3902. def_system_macro('FPC_HAS_INTERNAL_BSR');
  3903. {$endif}
  3904. { hardware FMA support }
  3905. {$if defined(i386) or defined(x86_64)}
  3906. if (cpu_capabilities[current_settings.cputype]*[CPUX86_HAS_FMA,CPUX86_HAS_FMA4])<>[] then
  3907. begin
  3908. def_system_macro('FPC_HAS_FAST_FMA_SINGLE');
  3909. def_system_macro('FPC_HAS_FAST_FMA_DOUBLE');
  3910. end;
  3911. {$endif defined(i386) or defined(x86_64)}
  3912. {$if defined(arm)}
  3913. { it is determined during system unit compilation if clz is used for bsf or not,
  3914. this is not perfect but the current implementation bsf/bsr does not allow another
  3915. solution }
  3916. if (CPUARM_HAS_CLZ in cpu_capabilities[init_settings.cputype]) and
  3917. ((init_settings.instructionset=is_arm) or
  3918. (CPUARM_HAS_THUMB2 in cpu_capabilities[init_settings.cputype])) then
  3919. begin
  3920. def_system_macro('FPC_HAS_INTERNAL_BSR');
  3921. if CPUARM_HAS_RBIT in cpu_capabilities[init_settings.cputype] then
  3922. def_system_macro('FPC_HAS_INTERNAL_BSF');
  3923. end;
  3924. {$endif}
  3925. {$if defined(powerpc64)}
  3926. { on sysv targets, default to elfv2 for little endian and to elfv1 for
  3927. big endian (unless specified otherwise). As the gcc man page says:
  3928. "Overriding the default ABI requires special system support and is
  3929. likely to fail in spectacular ways" }
  3930. if not option.ABISetExplicitly then
  3931. begin
  3932. if (target_info.abi=abi_powerpc_sysv) and
  3933. (target_info.endian=endian_little) then
  3934. target_info.abi:=abi_powerpc_elfv2
  3935. else
  3936. if (target_info.abi=abi_powerpc_elfv2) and
  3937. (target_info.endian=endian_big) then
  3938. target_info.abi:=abi_powerpc_sysv
  3939. end;
  3940. {$endif}
  3941. {$if defined(powerpc) or defined(powerpc64)}
  3942. { define _CALL_ELF symbol like gcc }
  3943. case target_info.abi of
  3944. abi_powerpc_sysv:
  3945. set_system_compvar('_CALL_ELF','1');
  3946. abi_powerpc_elfv2:
  3947. set_system_compvar('_CALL_ELF','2');
  3948. end;
  3949. {$endif}
  3950. { Section smartlinking conflicts with import sections on Windows }
  3951. if GenerateImportSection and
  3952. (target_info.system in [system_i386_win32,system_x86_64_win64]) then
  3953. exclude(target_info.flags,tf_smartlink_sections);
  3954. if not option.LinkTypeSetExplicitly then
  3955. set_default_link_type;
  3956. { Default alignment settings,
  3957. 1. load the defaults for the target
  3958. 2. override with generic optimizer setting (little size)
  3959. 3. override with the user specified -Oa }
  3960. UpdateAlignment(init_settings.alignment,target_info.alignment);
  3961. if (cs_opt_size in init_settings.optimizerswitches) then
  3962. begin
  3963. init_settings.alignment.procalign:=1;
  3964. init_settings.alignment.jumpalign:=1;
  3965. init_settings.alignment.loopalign:=1;
  3966. {$ifdef x86}
  3967. { constalignmax=1 keeps the executable and thus the memory foot print small but
  3968. all processors except x86 are really hurt by this or might even crash }
  3969. init_settings.alignment.constalignmax:=1;
  3970. {$endif x86}
  3971. end;
  3972. UpdateAlignment(init_settings.alignment,option.paraalignment);
  3973. set_system_macro('FPC_VERSION',version_nr);
  3974. set_system_macro('FPC_RELEASE',release_nr);
  3975. set_system_macro('FPC_PATCH',patch_nr);
  3976. set_system_macro('FPC_FULLVERSION',Format('%d%.02d%.02d',[StrToInt(version_nr),StrToInt(release_nr),StrToInt(patch_nr)]));
  3977. if target_info.system in systems_indirect_entry_information then
  3978. def_system_macro('FPC_HAS_INDIRECT_ENTRY_INFORMATION');
  3979. if not (tf_winlikewidestring in target_info.flags) then
  3980. def_system_macro('FPC_WIDESTRING_EQUAL_UNICODESTRING');
  3981. if tf_supports_packages in target_info.flags then
  3982. def_system_macro('FPC_HAS_DYNAMIC_PACKAGES');
  3983. if target_info.system in systems_indirect_var_imports then
  3984. def_system_macro('FPC_HAS_INDIRECT_VAR_ACCESS');
  3985. for i:=low(tfeature) to high(tfeature) do
  3986. if i in features then
  3987. def_system_macro('FPC_HAS_FEATURE_'+featurestr[i]);
  3988. {$push}
  3989. {$warn 6018 off} { Unreachable code due to compile time evaluation }
  3990. if ControllerSupport and (target_info.system in systems_embedded) and
  3991. (init_settings.controllertype<>ct_none) then
  3992. begin
  3993. with embedded_controllers[init_settings.controllertype] do
  3994. begin
  3995. set_system_macro('FPC_FLASHBASE',tostr(flashbase));
  3996. set_system_macro('FPC_FLASHSIZE',tostr(flashsize));
  3997. set_system_macro('FPC_SRAMBASE',tostr(srambase));
  3998. set_system_macro('FPC_SRAMSIZE',tostr(sramsize));
  3999. set_system_macro('FPC_EEPROMBASE',tostr(eeprombase));
  4000. set_system_macro('FPC_EEPROMSIZE',tostr(eepromsize));
  4001. set_system_macro('FPC_BOOTBASE',tostr(bootbase));
  4002. set_system_macro('FPC_BOOTSIZE',tostr(bootsize));
  4003. end;
  4004. end;
  4005. {$pop}
  4006. option.free;
  4007. Option:=nil;
  4008. clearstack_pocalls := [pocall_cdecl,pocall_cppdecl,pocall_syscall,pocall_mwpascal,pocall_sysv_abi_cdecl,pocall_ms_abi_cdecl];
  4009. cdecl_pocalls := [pocall_cdecl, pocall_cppdecl, pocall_mwpascal, pocall_sysv_abi_cdecl, pocall_ms_abi_cdecl];
  4010. if (tf_safecall_clearstack in target_info.flags) then
  4011. begin
  4012. include (cdecl_pocalls, pocall_safecall);
  4013. include (clearstack_pocalls, pocall_safecall)
  4014. end;
  4015. end;
  4016. initialization
  4017. coption:=toption;
  4018. finalization
  4019. if assigned(option) then
  4020. option.free;
  4021. end.