options.pas 145 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291
  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. if not(cs_compilesystem in init_settings.moduleswitches) then
  1916. Message(option_features_only_for_system_unit);
  1917. inc(j);
  1918. if more[j]='-' then
  1919. begin
  1920. if length(more)>j then
  1921. IllegalPara(opt)
  1922. else
  1923. features:=[];
  1924. end
  1925. else
  1926. begin
  1927. if (HandleFeature(upper(copy(more,j,length(more)-j+1)))) then
  1928. j:=length(more)
  1929. else
  1930. IllegalPara(opt);
  1931. end;
  1932. end;
  1933. 'g' :
  1934. If UnsetBool(More, j, opt, false) then
  1935. exclude(init_settings.moduleswitches,cs_support_goto)
  1936. else
  1937. include(init_settings.moduleswitches,cs_support_goto);
  1938. 'h' :
  1939. If UnsetBool(More, j, opt, false) then
  1940. exclude(init_settings.localswitches,cs_refcountedstrings)
  1941. else
  1942. include(init_settings.localswitches,cs_refcountedstrings);
  1943. 'i' :
  1944. If UnsetBool(More, j, opt, false) then
  1945. exclude(init_settings.localswitches,cs_do_inline)
  1946. else
  1947. include(init_settings.localswitches,cs_do_inline);
  1948. 'j' :
  1949. If UnsetBool(More, j, opt, false) then
  1950. exclude(init_settings.localswitches,cs_typed_const_writable)
  1951. else
  1952. include(init_settings.localswitches,cs_typed_const_writable);
  1953. 'k' :
  1954. If UnsetBool(More, j, opt, false) then
  1955. exclude(init_settings.globalswitches,cs_load_fpcylix_unit)
  1956. else
  1957. include(init_settings.globalswitches,cs_load_fpcylix_unit);
  1958. 'm' :
  1959. If UnsetBool(More, j, opt, false) then
  1960. exclude(init_settings.moduleswitches,cs_support_macro)
  1961. else
  1962. include(init_settings.moduleswitches,cs_support_macro);
  1963. 'o' : //an alternative to -Mtp
  1964. SetCompileMode('TP',true);
  1965. 'r' :
  1966. If UnsetBool(More, j, opt, false) then
  1967. exclude(init_settings.globalswitches,cs_transparent_file_names)
  1968. else
  1969. include(init_settings.globalswitches,cs_transparent_file_names);
  1970. {$ifdef gpc_mode}
  1971. 'p' : //an alternative to -Mgpc
  1972. SetCompileMode('GPC',true);
  1973. {$endif}
  1974. 's' :
  1975. If UnsetBool(More, j, opt, false) then
  1976. exclude(init_settings.globalswitches,cs_constructor_name)
  1977. else
  1978. include(init_settings.globalswitches,cs_constructor_name);
  1979. 't' :
  1980. Message1(option_obsolete_switch,'-St');
  1981. 'v' :
  1982. If UnsetBool(More, j, opt, false) then
  1983. exclude(init_settings.globalswitches,cs_support_vectors)
  1984. else
  1985. include(init_settings.globalswitches,cs_support_vectors);
  1986. 'x' :
  1987. If UnsetBool(More, j, opt, false) then
  1988. SetCompileModeSwitch('EXCEPTIONS-',true)
  1989. else
  1990. SetCompileModeSwitch('EXCEPTIONS',true);
  1991. 'y' :
  1992. If UnsetBool(More, j, opt, false) then
  1993. exclude(init_settings.localswitches,cs_typed_addresses)
  1994. else
  1995. include(init_settings.localswitches,cs_typed_addresses);
  1996. '-' :
  1997. begin
  1998. init_settings.globalswitches:=init_settings.globalswitches - [cs_constructor_name,cs_support_exceptions,
  1999. cs_support_vectors,cs_load_fpcylix_unit];
  2000. init_settings.localswitches:=init_settings.localswitches - [cs_do_assertion,cs_do_inline, cs_refcountedstrings,
  2001. cs_typed_addresses];
  2002. init_settings.moduleswitches:=init_settings.moduleswitches - [cs_support_c_operators, cs_support_goto,
  2003. cs_support_macro];
  2004. end;
  2005. else
  2006. IllegalPara(opt);
  2007. end;
  2008. inc(j);
  2009. end;
  2010. end;
  2011. end;
  2012. 'T' :
  2013. begin
  2014. more:=Upper(More);
  2015. if paratarget=system_none then
  2016. begin
  2017. { remove old target define }
  2018. TargetOptions(false);
  2019. { load new target }
  2020. paratarget:=find_system_by_string(More);
  2021. if paratarget<>system_none then
  2022. set_target(paratarget)
  2023. else
  2024. IllegalPara(opt);
  2025. { set new define }
  2026. TargetOptions(true);
  2027. end
  2028. else
  2029. if More<>upper(target_info.shortname) then
  2030. Message1(option_target_is_already_set,target_info.shortname);
  2031. end;
  2032. 'u' :
  2033. if is_identifier(more) then
  2034. undef_system_macro(more)
  2035. else
  2036. begin
  2037. if (more='') then
  2038. Message1(option_missing_arg,'-u')
  2039. else
  2040. Message1(option_malformed_para,opt);
  2041. StopOptions(1);
  2042. end;
  2043. 'U' :
  2044. begin
  2045. j:=1;
  2046. while j<=length(more) do
  2047. begin
  2048. case more[j] of
  2049. {$ifdef UNITALIASES}
  2050. 'a' :
  2051. begin
  2052. AddUnitAlias(Copy(More,j+1,255));
  2053. break;
  2054. end;
  2055. {$endif UNITALIASES}
  2056. 'n' :
  2057. exclude(init_settings.globalswitches,cs_check_unit_name);
  2058. 'p' :
  2059. begin
  2060. Message2(option_obsolete_switch_use_new,'-Up','-Fu');
  2061. break;
  2062. end;
  2063. 'r' :
  2064. begin
  2065. do_release:=true;
  2066. if (cs_checkpointer in init_settings.localswitches) then
  2067. begin
  2068. Message(option_gc_incompatible_with_release_flag);
  2069. exclude(init_settings.localswitches,cs_checkpointer);
  2070. end;
  2071. end;
  2072. 's' :
  2073. include(init_settings.moduleswitches,cs_compilesystem);
  2074. '-' :
  2075. begin
  2076. exclude(init_settings.moduleswitches,cs_compilesystem);
  2077. exclude(init_settings.globalswitches,cs_check_unit_name);
  2078. end;
  2079. else
  2080. IllegalPara(opt);
  2081. end;
  2082. inc(j);
  2083. end;
  2084. end;
  2085. 'v' :
  2086. begin
  2087. if not setverbosity(More) then
  2088. IllegalPara(opt);
  2089. end;
  2090. 'V' : ; { Ignore used by fpc }
  2091. 'W' :
  2092. begin
  2093. j:=1;
  2094. while j<=length(More) do
  2095. begin
  2096. case More[j] of
  2097. 'A':
  2098. begin
  2099. if target_info.system in systems_all_windows then
  2100. begin
  2101. if UnsetBool(More, j, opt, false) then
  2102. SetApptype(app_cui)
  2103. else
  2104. SetApptype(app_native);
  2105. end
  2106. else
  2107. IllegalPara(opt);
  2108. end;
  2109. 'b':
  2110. begin
  2111. if target_info.system in systems_darwin then
  2112. begin
  2113. if UnsetBool(More, j, opt, false) then
  2114. SetApptype(app_cui)
  2115. else
  2116. SetApptype(app_bundle)
  2117. end
  2118. else
  2119. IllegalPara(opt);
  2120. end;
  2121. 'B':
  2122. begin
  2123. if target_info.system in systems_all_windows+systems_symbian then
  2124. begin
  2125. { -WB200000 means set trefered base address
  2126. to $200000, but does not change relocsection boolean
  2127. this way we can create both relocatble and
  2128. non relocatable DLL at a specific base address PM }
  2129. if (length(More)>j) then
  2130. begin
  2131. val('$'+Copy(More,j+1,255),imagebase,code);
  2132. if code<>0 then
  2133. IllegalPara(opt);
  2134. ImageBaseSetExplicity:=true;
  2135. end
  2136. else
  2137. begin
  2138. RelocSection:=true;
  2139. RelocSectionSetExplicitly:=true;
  2140. end;
  2141. break;
  2142. end
  2143. else
  2144. IllegalPara(opt);
  2145. end;
  2146. 'C':
  2147. begin
  2148. if target_info.system in systems_all_windows+systems_os2+systems_macos then
  2149. begin
  2150. if UnsetBool(More, j, opt, false) then
  2151. SetApptype(app_gui)
  2152. else
  2153. SetApptype(app_cui);
  2154. end
  2155. else
  2156. IllegalPara(opt);
  2157. end;
  2158. 'D':
  2159. begin
  2160. if target_info.system in systems_all_windows then
  2161. begin
  2162. UseDeffileForExports:=not UnsetBool(More, j, opt, false);
  2163. UseDeffileForExportsSetExplicitly:=true;
  2164. end
  2165. else
  2166. IllegalPara(opt);
  2167. end;
  2168. 'e':
  2169. begin
  2170. if (target_info.system in systems_darwin) then
  2171. begin
  2172. RegisterRes(res_macosx_ext_info,TWinLikeResourceFile);
  2173. set_target_res(res_ext);
  2174. target_info.resobjext:='.fpcres';
  2175. end
  2176. else
  2177. IllegalPara(opt);
  2178. end;
  2179. 'F':
  2180. begin
  2181. if target_info.system in systems_os2 then
  2182. begin
  2183. if UnsetBool(More, j, opt, false) then
  2184. SetApptype(app_cui)
  2185. else
  2186. SetApptype(app_fs);
  2187. end
  2188. else
  2189. IllegalPara(opt);
  2190. end;
  2191. 'G':
  2192. begin
  2193. if target_info.system in systems_all_windows+systems_os2+systems_macos then
  2194. begin
  2195. if UnsetBool(More, j, opt, false) then
  2196. SetApptype(app_cui)
  2197. else
  2198. SetApptype(app_gui);
  2199. end
  2200. else
  2201. IllegalPara(opt);
  2202. end;
  2203. {$if defined(i8086)}
  2204. 'h':
  2205. begin
  2206. if UnsetBool(More, j, opt, false) then
  2207. exclude(init_settings.moduleswitches,cs_huge_code)
  2208. else
  2209. include(init_settings.moduleswitches,cs_huge_code);
  2210. end;
  2211. {$endif defined(i8086)}
  2212. 'I':
  2213. begin
  2214. if target_info.system in systems_all_windows then
  2215. begin
  2216. GenerateImportSection:=not UnsetBool(More,j,opt,false);
  2217. GenerateImportSectionSetExplicitly:=true;
  2218. end
  2219. else
  2220. IllegalPara(opt);
  2221. end;
  2222. 'i':
  2223. begin
  2224. if (target_info.system in systems_darwin) then
  2225. begin
  2226. set_target_res(res_macho);
  2227. target_info.resobjext:=
  2228. targetinfos[target_info.system]^.resobjext;
  2229. end
  2230. else
  2231. IllegalPara(opt);
  2232. end;
  2233. 'm':
  2234. begin
  2235. {$if defined(i8086)}
  2236. if (target_info.system in [system_i8086_msdos,system_i8086_win16,system_i8086_embedded]) then
  2237. begin
  2238. case Upper(Copy(More,j+1,255)) of
  2239. 'TINY': init_settings.x86memorymodel:=mm_tiny;
  2240. 'SMALL': init_settings.x86memorymodel:=mm_small;
  2241. 'MEDIUM': init_settings.x86memorymodel:=mm_medium;
  2242. 'COMPACT': init_settings.x86memorymodel:=mm_compact;
  2243. 'LARGE': init_settings.x86memorymodel:=mm_large;
  2244. 'HUGE': init_settings.x86memorymodel:=mm_huge;
  2245. else
  2246. IllegalPara(opt);
  2247. end;
  2248. break;
  2249. end
  2250. else
  2251. {$endif defined(i8086)}
  2252. IllegalPara(opt);
  2253. end;
  2254. 'M':
  2255. begin
  2256. if (target_info.system in (systems_darwin-[system_i386_iphonesim,system_arm_darwin,system_aarch64_darwin,system_x86_64_iphonesim])) and
  2257. ParseMacVersionMin(MacOSXVersionMin,iPhoneOSVersionMin,'MAC_OS_X_VERSION_MIN_REQUIRED',copy(More,2,255),false) then
  2258. begin
  2259. break;
  2260. end
  2261. else
  2262. IllegalPara(opt);
  2263. end;
  2264. 'N':
  2265. begin
  2266. if target_info.system in systems_all_windows then
  2267. begin
  2268. RelocSection:=UnsetBool(More,j,opt,false);
  2269. RelocSectionSetExplicitly:=true;
  2270. end
  2271. else
  2272. IllegalPara(opt);
  2273. end;
  2274. 'p':
  2275. begin
  2276. {$push}
  2277. {$warn 6018 off} { Unreachable code due to compile time evaluation }
  2278. if (target_info.system in systems_embedded) and
  2279. ControllerSupport then
  2280. begin
  2281. s:=upper(copy(more,j+1,length(more)-j));
  2282. if not(SetControllerType(s,init_settings.controllertype)) then
  2283. IllegalPara(opt);
  2284. break;
  2285. end
  2286. else
  2287. IllegalPara(opt);
  2288. {$pop}
  2289. end;
  2290. 'P':
  2291. begin
  2292. if (target_info.system in [system_i386_iphonesim,system_arm_darwin,system_aarch64_darwin,system_x86_64_iphonesim]) and
  2293. ParseMacVersionMin(iPhoneOSVersionMin,MacOSXVersionMin,'IPHONE_OS_VERSION_MIN_REQUIRED',copy(More,2,255),true) then
  2294. begin
  2295. break;
  2296. end
  2297. else
  2298. IllegalPara(opt);
  2299. end;
  2300. 'R':
  2301. begin
  2302. if target_info.system in systems_all_windows then
  2303. begin
  2304. { support -WR+ / -WR- as synonyms to -WR / -WN }
  2305. RelocSection:=not UnsetBool(More,j,opt,false);
  2306. RelocSectionSetExplicitly:=true;
  2307. end
  2308. else
  2309. IllegalPara(opt);
  2310. end;
  2311. 't':
  2312. begin
  2313. {$if defined(i8086)}
  2314. if (target_info.system in [system_i8086_msdos,system_i8086_embedded]) then
  2315. begin
  2316. case Upper(Copy(More,j+1,255)) of
  2317. 'EXE': SetAppType(app_cui);
  2318. 'COM': SetAppType(app_com);
  2319. else
  2320. IllegalPara(opt);
  2321. end;
  2322. break;
  2323. end
  2324. else
  2325. {$endif defined(i8086)}
  2326. IllegalPara(opt);
  2327. end;
  2328. 'T':
  2329. begin
  2330. if target_info.system in systems_macos then
  2331. begin
  2332. if UnsetBool(More, j, opt, false) then
  2333. SetApptype(app_cui)
  2334. else
  2335. SetApptype(app_tool);
  2336. end
  2337. else
  2338. IllegalPara(opt);
  2339. end;
  2340. 'X':
  2341. begin
  2342. if (target_info.system in systems_linux) then
  2343. begin
  2344. if UnsetBool(More, j, opt, false) then
  2345. exclude(init_settings.moduleswitches,cs_executable_stack)
  2346. else
  2347. include(init_settings.moduleswitches,cs_executable_stack)
  2348. end
  2349. else
  2350. IllegalPara(opt);
  2351. end;
  2352. else
  2353. IllegalPara(opt);
  2354. end;
  2355. inc(j);
  2356. end;
  2357. end;
  2358. 'X' :
  2359. begin
  2360. j:=1;
  2361. while j<=length(more) do
  2362. begin
  2363. case More[j] of
  2364. '9' :
  2365. begin
  2366. if target_info.system in systems_linux then
  2367. begin
  2368. if UnsetBool(More, j, opt, false) then
  2369. exclude(init_settings.globalswitches,cs_link_pre_binutils_2_19)
  2370. else
  2371. include(init_settings.globalswitches,cs_link_pre_binutils_2_19);
  2372. end
  2373. else
  2374. IllegalPara(opt);
  2375. end;
  2376. 'c' : Cshared:=TRUE;
  2377. 'd' : Dontlinkstdlibpath:=TRUE;
  2378. 'e' :
  2379. begin
  2380. If UnsetBool(More, j, opt, false) then
  2381. exclude(init_settings.globalswitches,cs_link_extern)
  2382. else
  2383. include(init_settings.globalswitches,cs_link_extern);
  2384. end;
  2385. 'f' :
  2386. include(init_settings.globalswitches,cs_link_pthread);
  2387. 'g' :
  2388. begin
  2389. If UnsetBool(More, j, opt, false) then
  2390. exclude(init_settings.globalswitches,cs_link_separate_dbg_file)
  2391. else
  2392. include(init_settings.globalswitches,cs_link_separate_dbg_file);
  2393. end;
  2394. 'i' :
  2395. begin
  2396. If UnsetBool(More, j, opt, false) then
  2397. include(init_settings.globalswitches,cs_link_extern)
  2398. else
  2399. exclude(init_settings.globalswitches,cs_link_extern);
  2400. end;
  2401. 'n' :
  2402. begin
  2403. If UnsetBool(More, j, opt, false) then
  2404. exclude(init_settings.globalswitches,cs_link_native)
  2405. else
  2406. include(init_settings.globalswitches,cs_link_native);
  2407. end;
  2408. 'm' :
  2409. begin
  2410. If UnsetBool(More, j, opt, false) then
  2411. exclude(init_settings.globalswitches,cs_link_map)
  2412. else
  2413. include(init_settings.globalswitches,cs_link_map);
  2414. end;
  2415. 'p' : ; { Ignore used by fpc.pp }
  2416. 'r' :
  2417. begin
  2418. if (target_info.system in suppported_targets_x_smallr) then
  2419. begin
  2420. rlinkpath:=Copy(more,2,length(More)-1);
  2421. DefaultReplacements(rlinkpath);
  2422. end
  2423. else
  2424. IgnoredPara('-Xr');
  2425. more:='';
  2426. end;
  2427. 'R' :
  2428. begin
  2429. sysrootpath:=copy(more,2,length(more)-1);
  2430. defaultreplacements(sysrootpath);
  2431. more:='';
  2432. end;
  2433. 's' :
  2434. begin
  2435. If UnsetBool(More, j, opt, false) then
  2436. exclude(init_settings.globalswitches,cs_link_strip)
  2437. else
  2438. include(init_settings.globalswitches,cs_link_strip);
  2439. end;
  2440. 't' :
  2441. include(init_settings.globalswitches,cs_link_staticflag);
  2442. 'v' :
  2443. begin
  2444. If UnsetBool(More, j, opt, false) then
  2445. exclude(init_settings.globalswitches,cs_link_opt_vtable)
  2446. else
  2447. include(init_settings.globalswitches,cs_link_opt_vtable);
  2448. end;
  2449. 'D' :
  2450. begin
  2451. def_system_macro('FPC_LINK_DYNAMIC');
  2452. undef_system_macro('FPC_LINK_SMART');
  2453. undef_system_macro('FPC_LINK_STATIC');
  2454. exclude(init_settings.globalswitches,cs_link_static);
  2455. exclude(init_settings.globalswitches,cs_link_smart);
  2456. include(init_settings.globalswitches,cs_link_shared);
  2457. LinkTypeSetExplicitly:=true;
  2458. end;
  2459. 'M' :
  2460. begin
  2461. mainaliasname:=Copy(more,2,length(More)-1);
  2462. More:='';
  2463. end;
  2464. 'P' :
  2465. begin
  2466. utilsprefix:=Copy(more,2,length(More)-1);
  2467. DefaultReplacements(utilsprefix);
  2468. More:='';
  2469. end;
  2470. 'L' : begin // -XLO is link order -XLA is link alias. -XLD avoids load defaults.
  2471. // these are not aggregable.
  2472. if (j=length(more)) or not (more[j+1] in ['O','A','D']) then
  2473. IllegalPara(opt)
  2474. else
  2475. begin
  2476. case more[j+1] of
  2477. 'A' : begin
  2478. s:=Copy(more,3,length(More)-2);
  2479. if not LinkLibraryAliases.AddDep(s) Then
  2480. IllegalPara(opt);
  2481. end;
  2482. 'O' : begin
  2483. s:=Copy(more,3,length(More)-2);
  2484. if not LinkLibraryOrder.AddWeight(s) Then
  2485. IllegalPara(opt);
  2486. end;
  2487. 'D' : include(init_settings.globalswitches,cs_link_no_default_lib_order)
  2488. else
  2489. IllegalPara(opt);
  2490. end; {case}
  2491. j:=length(more);
  2492. end; {else begin}
  2493. end;
  2494. 'S' :
  2495. begin
  2496. ForceStaticLinking;
  2497. end;
  2498. 'V' :
  2499. begin
  2500. if UnsetBool(More, j, opt, false) then
  2501. exclude(init_settings.globalswitches,cs_link_vlink)
  2502. else
  2503. begin
  2504. include(init_settings.globalswitches,cs_link_vlink);
  2505. include(init_settings.globalswitches,cs_link_extern);
  2506. end;
  2507. LinkerSetExplicitly:=true;
  2508. end;
  2509. 'X' :
  2510. begin
  2511. def_system_macro('FPC_LINK_SMART');
  2512. undef_system_macro('FPC_LINK_STATIC');
  2513. undef_system_macro('FPC_LINK_DYNAMIC');
  2514. exclude(init_settings.globalswitches,cs_link_static);
  2515. include(init_settings.globalswitches,cs_link_smart);
  2516. exclude(init_settings.globalswitches,cs_link_shared);
  2517. LinkTypeSetExplicitly:=true;
  2518. end;
  2519. '-' :
  2520. begin
  2521. exclude(init_settings.globalswitches,cs_link_staticflag);
  2522. exclude(init_settings.globalswitches,cs_link_strip);
  2523. exclude(init_settings.globalswitches,cs_link_map);
  2524. set_default_link_type;
  2525. end;
  2526. else
  2527. IllegalPara(opt);
  2528. end;
  2529. inc(j);
  2530. end;
  2531. end;
  2532. else
  2533. IllegalPara(opt);
  2534. end;
  2535. end;
  2536. '@' :
  2537. begin
  2538. Message(option_no_nested_response_file);
  2539. StopOptions(1);
  2540. end;
  2541. else
  2542. begin
  2543. if (length(param_file)<>0) then
  2544. Message2(option_only_one_source_support,param_file,opt);
  2545. param_file:=opt;
  2546. Message1(option_found_file,opt);
  2547. end;
  2548. end;
  2549. end;
  2550. procedure Toption.Interpret_file(const filename : TPathStr);
  2551. procedure RemoveSep(var fn:TPathStr);
  2552. var
  2553. i : longint;
  2554. begin
  2555. i:=0;
  2556. while (i<length(fn)) and (fn[i+1] in [',',' ',#9]) do
  2557. inc(i);
  2558. Delete(fn,1,i);
  2559. i:=length(fn);
  2560. while (i>0) and (fn[i] in [',',' ',#9]) do
  2561. dec(i);
  2562. fn:=copy(fn,1,i);
  2563. end;
  2564. function GetName(var fn:TPathStr):TPathStr;
  2565. var
  2566. i : longint;
  2567. begin
  2568. i:=0;
  2569. while (i<length(fn)) and (fn[i+1] in ['a'..'z','A'..'Z','0'..'9','_','-']) do
  2570. inc(i);
  2571. GetName:=Copy(fn,1,i);
  2572. Delete(fn,1,i);
  2573. end;
  2574. const
  2575. maxlevel = 15;
  2576. var
  2577. f : text;
  2578. s, tmp,
  2579. opts : TCmdStr;
  2580. skip : array[0..maxlevel] of boolean;
  2581. line,
  2582. level : longint;
  2583. option_read : boolean;
  2584. oldfilemode : byte;
  2585. ConfigFile: TPathStr;
  2586. begin
  2587. { avoid infinite loop }
  2588. Inc(FileLevel);
  2589. Option_read:=false;
  2590. If FileLevel>MaxLevel then
  2591. Message(option_too_many_cfg_files);
  2592. if not ParaIncludeCfgPath.FindFile(fileName,true,ConfigFile) then
  2593. ConfigFile := ExpandFileName(filename);
  2594. { Maybe It's Directory ?} //Jaro Change:
  2595. if PathExists(ConfigFile,false) then
  2596. begin
  2597. Message1(option_config_is_dir,filename);
  2598. exit;
  2599. end;
  2600. { open file }
  2601. Message1(option_using_file,filename);
  2602. oldfilemode:=filemode;
  2603. filemode:=0;
  2604. assign(f,ConfigFile);
  2605. {$push}{$I-}
  2606. reset(f);
  2607. {$pop}
  2608. filemode:=oldfilemode;
  2609. if ioresult<>0 then
  2610. begin
  2611. Message1(option_unable_open_file,filename);
  2612. exit;
  2613. end;
  2614. Message1(option_start_reading_configfile,filename);
  2615. fillchar(skip,sizeof(skip),0);
  2616. level:=0;
  2617. line:=0;
  2618. while not eof(f) do
  2619. begin
  2620. readln(f,opts);
  2621. inc(line);
  2622. RemoveSep(opts);
  2623. if (opts<>'') and (opts[1]<>';') then
  2624. begin
  2625. if opts[1]='#' then
  2626. begin
  2627. Message1(option_interpreting_file_option,opts);
  2628. Delete(opts,1,1);
  2629. s:=upper(GetName(opts));
  2630. if (s='SECTION') then
  2631. begin
  2632. RemoveSep(opts);
  2633. s:=upper(GetName(opts));
  2634. if level=0 then
  2635. skip[level]:=not defined_macro(s) or (s='COMMON');
  2636. end
  2637. else
  2638. if (s='IFDEF') then
  2639. begin
  2640. RemoveSep(opts);
  2641. if Level>=maxlevel then
  2642. begin
  2643. Message2(option_too_many_ifdef,filename,tostr(line));
  2644. stopOptions(1);
  2645. end;
  2646. inc(Level);
  2647. skip[level]:=(skip[level-1] or not defined_macro(upper(GetName(opts))));
  2648. end
  2649. else
  2650. if (s='IFNDEF') then
  2651. begin
  2652. RemoveSep(opts);
  2653. if Level>=maxlevel then
  2654. begin
  2655. Message2(option_too_many_ifdef,filename,tostr(line));
  2656. stopOptions(1);
  2657. end;
  2658. inc(Level);
  2659. skip[level]:=(skip[level-1] or defined_macro(upper(GetName(opts))));
  2660. end
  2661. else
  2662. if (s='ELSE') then
  2663. begin
  2664. if Level=0 then
  2665. begin
  2666. Message2(option_else_without_if,filename,tostr(line));
  2667. stopOptions(1);
  2668. end
  2669. else
  2670. skip[level]:=skip[level-1] or (not skip[level])
  2671. end
  2672. else
  2673. if (s='ENDIF') then
  2674. begin
  2675. skip[level]:=false;
  2676. if Level=0 then
  2677. begin
  2678. Message2(option_too_many_endif,filename,tostr(line));
  2679. stopOptions(1);
  2680. end;
  2681. dec(level);
  2682. end
  2683. else
  2684. if (not skip[level]) then
  2685. begin
  2686. if (s='DEFINE') then
  2687. begin
  2688. RemoveSep(opts);
  2689. tmp:= GetName(opts);
  2690. if tmp <> '' then
  2691. def_system_macro(tmp);
  2692. Option_read:=true;
  2693. end
  2694. else
  2695. if (s='UNDEF') then
  2696. begin
  2697. RemoveSep(opts);
  2698. tmp:= GetName(opts);
  2699. if tmp <> '' then
  2700. undef_system_macro(tmp);
  2701. Option_read:=true;
  2702. end
  2703. else
  2704. if (s='WRITE') then
  2705. begin
  2706. Delete(opts,1,1);
  2707. DefaultReplacements(opts);
  2708. WriteLn(opts);
  2709. Option_read:=true;
  2710. end
  2711. else
  2712. if (s='INCLUDE') then
  2713. begin
  2714. Delete(opts,1,1);
  2715. DefaultReplacements(opts);
  2716. Interpret_file(opts);
  2717. Option_read:=true;
  2718. end
  2719. else
  2720. if (s='CFGDIR') then
  2721. begin
  2722. Delete(opts,1,1);
  2723. DefaultReplacements(opts);
  2724. ParaIncludeCfgPath.AddPath(opts,false);
  2725. Option_read:=true;
  2726. end;
  2727. end;
  2728. end
  2729. else
  2730. begin
  2731. if (opts[1]='-') or (opts[1]='@') then
  2732. begin
  2733. if (not skip[level]) then
  2734. interpret_option(opts,false);
  2735. Option_read:=true;
  2736. end
  2737. else
  2738. Message1(option_illegal_para,opts);
  2739. end;
  2740. end;
  2741. end;
  2742. if Level>0 then
  2743. Message(option_too_less_endif);
  2744. if Not Option_read then
  2745. Message1(option_no_option_found,filename)
  2746. else
  2747. Message1(option_end_reading_configfile,filename);
  2748. Close(f);
  2749. Dec(FileLevel);
  2750. end;
  2751. procedure Toption.Interpret_envvar(const envname : TCmdStr);
  2752. var
  2753. argstart,
  2754. env,
  2755. pc : pchar;
  2756. arglen : longint;
  2757. quote : set of char;
  2758. hs : TCmdStr;
  2759. begin
  2760. Message1(option_using_env,envname);
  2761. env:=GetEnvPChar(envname);
  2762. pc:=env;
  2763. if assigned(pc) then
  2764. begin
  2765. repeat
  2766. { skip leading spaces }
  2767. while pc^ in [' ',#9,#13] do
  2768. inc(pc);
  2769. case pc^ of
  2770. #0 :
  2771. break;
  2772. '"' :
  2773. begin
  2774. quote:=['"'];
  2775. inc(pc);
  2776. end;
  2777. '''' :
  2778. begin
  2779. quote:=[''''];
  2780. inc(pc);
  2781. end;
  2782. else
  2783. quote:=[' ',#9,#13];
  2784. end;
  2785. { scan until the end of the argument }
  2786. argstart:=pc;
  2787. while (pc^<>#0) and not(pc^ in quote) do
  2788. inc(pc);
  2789. { create argument }
  2790. arglen:=pc-argstart;
  2791. { TODO: FIXME: silent truncation of environment parameters }
  2792. if (arglen > 255) then
  2793. arglen := 255;
  2794. setlength(hs,arglen);
  2795. move(argstart^,hs[1],arglen);
  2796. interpret_option(hs,true);
  2797. { skip quote }
  2798. if pc^ in quote then
  2799. inc(pc);
  2800. until false;
  2801. end
  2802. else
  2803. Message1(option_no_option_found,'(env) '+envname);
  2804. FreeEnvPChar(env);
  2805. end;
  2806. procedure toption.read_parameters;
  2807. var
  2808. opts : TCmdStr;
  2809. paramindex : longint;
  2810. begin
  2811. paramindex:=0;
  2812. while paramindex<paramcount do
  2813. begin
  2814. inc(paramindex);
  2815. opts:=objpas.paramstr(paramindex);
  2816. if length(opts)>0 then
  2817. case opts[1] of
  2818. '@' :
  2819. if not firstpass then
  2820. begin
  2821. Delete(opts,1,1);
  2822. Message1(option_reading_further_from,opts);
  2823. interpret_file(opts);
  2824. end;
  2825. '!' :
  2826. if not firstpass then
  2827. begin
  2828. Delete(opts,1,1);
  2829. Message1(option_reading_further_from,'(env) '+opts);
  2830. interpret_envvar(opts);
  2831. end;
  2832. else
  2833. interpret_option(opts,true);
  2834. end;
  2835. end;
  2836. end;
  2837. procedure toption.parsecmd(cmd:TCmdStr);
  2838. var
  2839. i,ps : longint;
  2840. opts : TCmdStr;
  2841. begin
  2842. while (cmd<>'') do
  2843. begin
  2844. while cmd[1]=' ' do
  2845. delete(cmd,1,1);
  2846. i:=pos(' ',cmd);
  2847. if i=0 then
  2848. i:=2147483647;
  2849. opts:=Copy(cmd,1,i-1);
  2850. Delete(cmd,1,i);
  2851. case opts[1] of
  2852. '@' :
  2853. if not firstpass then
  2854. begin
  2855. Delete(opts,1,1);
  2856. Message1(option_reading_further_from,opts);
  2857. interpret_file(opts);
  2858. end;
  2859. '!' :
  2860. if not firstpass then
  2861. begin
  2862. Delete(opts,1,1);
  2863. Message1(option_reading_further_from,'(env) '+opts);
  2864. interpret_envvar(opts);
  2865. end;
  2866. '"' :
  2867. begin
  2868. Delete(opts,1,1);
  2869. ps:=pos('"',cmd);
  2870. if (i<>256) and (ps>0) then
  2871. begin
  2872. opts:=opts + ' '+ copy(cmd,1,ps-1);
  2873. cmd:=copy(cmd,ps+1,255);
  2874. end;
  2875. interpret_option(opts,true);
  2876. end;
  2877. else
  2878. interpret_option(opts,true);
  2879. end;
  2880. end;
  2881. end;
  2882. procedure toption.writequickinfo;
  2883. var
  2884. s : string;
  2885. i : longint;
  2886. procedure addinfo(const hs:string);
  2887. begin
  2888. if s<>'' then
  2889. s:=s+' '+hs
  2890. else
  2891. s:=hs;
  2892. end;
  2893. begin
  2894. s:='';
  2895. i:=0;
  2896. while (i<length(quickinfo)) do
  2897. begin
  2898. inc(i);
  2899. case quickinfo[i] of
  2900. 'S' :
  2901. begin
  2902. inc(i);
  2903. case quickinfo[i] of
  2904. 'O' :
  2905. addinfo(lower(source_info.shortname));
  2906. 'P' :
  2907. addinfo(source_cpu_string);
  2908. else
  2909. IllegalPara('-i'+QuickInfo);
  2910. end;
  2911. end;
  2912. 'T' :
  2913. begin
  2914. inc(i);
  2915. case quickinfo[i] of
  2916. 'O' :
  2917. addinfo(lower(target_info.shortname));
  2918. 'P' :
  2919. AddInfo(target_cpu_string);
  2920. else
  2921. IllegalPara('-i'+QuickInfo);
  2922. end;
  2923. end;
  2924. 'V' :
  2925. AddInfo(version_string);
  2926. 'W' :
  2927. AddInfo(full_version_string);
  2928. 'D' :
  2929. AddInfo(date_string);
  2930. '_' :
  2931. ;
  2932. else
  2933. IllegalPara('-i'+QuickInfo);
  2934. end;
  2935. end;
  2936. if s<>'' then
  2937. begin
  2938. writeln(s);
  2939. stopoptions(0);
  2940. end;
  2941. end;
  2942. procedure TOption.TargetOptions(def:boolean);
  2943. var
  2944. s : string;
  2945. i : integer;
  2946. target_unsup_features : tfeatures;
  2947. begin
  2948. if def then
  2949. def_system_macro(target_info.shortname)
  2950. else
  2951. undef_system_macro(target_info.shortname);
  2952. s:=target_info.extradefines;
  2953. while (s<>'') do
  2954. begin
  2955. i:=pos(';',s);
  2956. if i=0 then
  2957. i:=length(s)+1;
  2958. if def then
  2959. def_system_macro(Copy(s,1,i-1))
  2960. else
  2961. undef_system_macro(Copy(s,1,i-1));
  2962. delete(s,1,i);
  2963. end;
  2964. if (tf_winlikewidestring in target_info.flags) then
  2965. if def then
  2966. def_system_macro('FPC_WINLIKEWIDESTRING')
  2967. else
  2968. undef_system_macro('FPC_WINLIKEWIDESTRING');
  2969. if (tf_requires_proper_alignment in target_info.flags) then
  2970. if def then
  2971. def_system_macro('FPC_REQUIRES_PROPER_ALIGNMENT')
  2972. else
  2973. undef_system_macro('FPC_REQUIRES_PROPER_ALIGNMENT');
  2974. if source_info.system<>target_info.system then
  2975. if def then
  2976. def_system_macro('FPC_CROSSCOMPILING')
  2977. else
  2978. undef_system_macro('FPC_CROSSCOMPILING');
  2979. if source_info.cpu<>target_info.cpu then
  2980. if def then
  2981. def_system_macro('FPC_CPUCROSSCOMPILING')
  2982. else
  2983. def_system_macro('FPC_CPUCROSSCOMPILING');
  2984. if (tf_no_generic_stackcheck in target_info.flags) then
  2985. if def then
  2986. def_system_macro('FPC_NO_GENERIC_STACK_CHECK')
  2987. else
  2988. undef_system_macro('FPC_NO_GENERIC_STACK_CHECK');
  2989. if (tf_section_threadvars in target_info.flags) then
  2990. if def then
  2991. def_system_macro('FPC_SECTION_THREADVARS')
  2992. else
  2993. undef_system_macro('FPC_SECTION_THREADVARS');
  2994. { Code generation flags }
  2995. if (tf_pic_default in target_info.flags) then
  2996. if def then
  2997. include(init_settings.moduleswitches,cs_create_pic)
  2998. else
  2999. exclude(init_settings.moduleswitches,cs_create_pic);
  3000. { Resources support }
  3001. if (tf_has_winlike_resources in target_info.flags) then
  3002. if def then
  3003. def_system_macro('FPC_HAS_WINLIKERESOURCES')
  3004. else
  3005. undef_system_macro('FPC_HAS_WINLIKERESOURCES');
  3006. { Features }
  3007. case target_info.system of
  3008. system_arm_gba:
  3009. target_unsup_features:=[f_dynlibs];
  3010. system_arm_nds:
  3011. target_unsup_features:=[f_threading,f_commandargs,f_fileio,f_textio,f_consoleio,f_dynlibs];
  3012. system_i386_nativent:
  3013. // until these features are implemented, they are disabled in the compiler
  3014. target_unsup_features:=[f_stackcheck];
  3015. system_i8086_msdos:
  3016. target_unsup_features:=[f_threading,f_dynlibs];
  3017. system_i8086_win16:
  3018. target_unsup_features:=[f_threading];
  3019. system_jvm_java32,
  3020. system_jvm_android32:
  3021. target_unsup_features:=[f_heap,f_textio,f_consoleio,f_fileio,
  3022. f_variants,f_objects,f_commandargs,
  3023. f_processes,f_stackcheck,f_dynlibs,f_softfpu,f_objectivec1,f_resources];
  3024. system_arm_palmos,
  3025. system_m68k_palmos:
  3026. target_unsup_features:=[f_threading];
  3027. system_m68k_atari:
  3028. target_unsup_features:=[f_threading];
  3029. else
  3030. target_unsup_features:=[];
  3031. end;
  3032. if def then
  3033. features:=features-target_unsup_features
  3034. else
  3035. features:=features+target_unsup_features;
  3036. {$if defined(atari) or defined(hasamiga)}
  3037. { enable vlink as default linker on Atari, Amiga, and MorphOS, but not for cross compilers (for now) }
  3038. if (target_info.system in [system_m68k_amiga,system_m68k_atari,
  3039. system_powerpc_amiga,system_powerpc_morphos]) and
  3040. not LinkerSetExplicitly then
  3041. include(init_settings.globalswitches,cs_link_vlink);
  3042. {$endif}
  3043. end;
  3044. procedure TOption.checkoptionscompatibility;
  3045. begin
  3046. {$ifdef i8086}
  3047. if (apptype=app_com) and (init_settings.x86memorymodel<>mm_tiny) then
  3048. begin
  3049. Message(option_com_files_require_tiny_model);
  3050. StopOptions(1);
  3051. end;
  3052. {$endif i8086}
  3053. if (paratargetdbg in [dbg_dwarf2,dbg_dwarf3]) and
  3054. not(target_info.system in (systems_darwin+[system_i8086_msdos,system_i8086_embedded])) then
  3055. begin
  3056. { smartlink creation does not yet work with DWARF
  3057. debug info on most targets, but it works in internal assembler }
  3058. if (cs_create_smart in init_settings.moduleswitches) and
  3059. not (af_outputbinary in target_asm.flags) then
  3060. begin
  3061. Message(option_dwarf_smartlink_creation);
  3062. exclude(init_settings.moduleswitches,cs_create_smart);
  3063. end;
  3064. { smart linking does not yet work with DWARF debug info on most targets }
  3065. if (cs_link_smart in init_settings.globalswitches) then
  3066. begin
  3067. Message(option_dwarf_smart_linking);
  3068. ForceStaticLinking;
  3069. end;
  3070. end;
  3071. { external debug info is only supported for DWARF on darwin }
  3072. if (target_info.system in systems_darwin) and
  3073. (cs_link_separate_dbg_file in init_settings.globalswitches) and
  3074. not(paratargetdbg in [dbg_dwarf2,dbg_dwarf3]) then
  3075. begin
  3076. Message(option_debug_external_unsupported);
  3077. exclude(init_settings.globalswitches,cs_link_separate_dbg_file);
  3078. end;
  3079. { Also create a smartlinked version, on an assembler that
  3080. does not support smartlink sections like nasm?
  3081. This is not compatible with using internal linker. }
  3082. if ((cs_link_smart in init_settings.globalswitches) or
  3083. (cs_create_smart in init_settings.moduleswitches)) and
  3084. (af_needar in target_asm.flags) and
  3085. not (af_smartlink_sections in target_asm.flags) and
  3086. not (cs_link_extern in init_settings.globalswitches) and
  3087. (target_info.link<>ld_none) and
  3088. not (cs_link_nolink in init_settings.globalswitches) then
  3089. begin
  3090. Message(option_smart_link_requires_external_linker);
  3091. include(init_settings.globalswitches,cs_link_extern);
  3092. end;
  3093. end;
  3094. constructor TOption.create;
  3095. begin
  3096. LogoWritten:=false;
  3097. NoPressEnter:=false;
  3098. FirstPass:=false;
  3099. ABISetExplicitly:=false;
  3100. FPUSetExplicitly:=false;
  3101. CPUSetExplicitly:=false;
  3102. OptCPUSetExplicitly:=false;
  3103. FileLevel:=0;
  3104. Quickinfo:='';
  3105. ParaIncludeCfgPath:=TSearchPathList.Create;
  3106. ParaIncludePath:=TSearchPathList.Create;
  3107. ParaObjectPath:=TSearchPathList.Create;
  3108. ParaUnitPath:=TSearchPathList.Create;
  3109. ParaLibraryPath:=TSearchPathList.Create;
  3110. ParaFrameworkPath:=TSearchPathList.Create;
  3111. parapackagepath:=TSearchPathList.Create;
  3112. parapackages:=TFPHashObjectList.Create;
  3113. FillChar(ParaAlignment,sizeof(ParaAlignment),0);
  3114. MacVersionSet:=false;
  3115. paratarget:=system_none;
  3116. paratargetasm:=as_none;
  3117. paratargetdbg:=dbg_none;
  3118. LinkTypeSetExplicitly:=false;
  3119. LinkerSetExplicitly:=false;
  3120. end;
  3121. destructor TOption.destroy;
  3122. begin
  3123. ParaIncludeCfgPath.Free;
  3124. ParaIncludePath.Free;
  3125. ParaObjectPath.Free;
  3126. ParaUnitPath.Free;
  3127. ParaLibraryPath.Free;
  3128. ParaFrameworkPath.Free;
  3129. parapackagepath.Free;
  3130. ParaPackages.Free;
  3131. end;
  3132. {****************************************************************************
  3133. Callable Routines
  3134. ****************************************************************************}
  3135. function check_configfile(fn:string; var foundfn:string):boolean;
  3136. function CfgFileExists(const fn:string):boolean;
  3137. begin
  3138. Comment(V_Tried,'Configfile search: '+fn);
  3139. CfgFileExists:=FileExists(fn);
  3140. end;
  3141. var
  3142. {$ifdef Unix}
  3143. hs,
  3144. {$endif Unix}
  3145. configpath : string;
  3146. begin
  3147. foundfn:=fn;
  3148. check_configfile:=true;
  3149. { retrieve configpath }
  3150. configpath:=FixPath(GetEnvironmentVariable('PPC_CONFIG_PATH'),false);
  3151. {$ifdef Unix}
  3152. if configpath='' then
  3153. configpath:=ExpandFileName(FixPath(exepath+'../etc/',false));
  3154. {$endif}
  3155. {
  3156. Order to read configuration file :
  3157. try reading fpc.cfg in :
  3158. 1 - current dir
  3159. 2 - configpath
  3160. 3 - compiler path
  3161. }
  3162. if not FileExists(fn) then
  3163. begin
  3164. {$ifdef Unix}
  3165. hs:=GetEnvironmentVariable('HOME');
  3166. if (hs<>'') and CfgFileExists(FixPath(hs,false)+'.'+fn) then
  3167. foundfn:=FixPath(hs,false)+'.'+fn
  3168. else
  3169. {$endif}
  3170. if CfgFileExists(configpath+fn) then
  3171. foundfn:=configpath+fn
  3172. else
  3173. {$ifdef WINDOWS}
  3174. if (GetEnvironmentVariable('USERPROFILE')<>'') and CfgFileExists(FixPath(GetEnvironmentVariable('USERPROFILE'),false)+fn) then
  3175. foundfn:=FixPath(GetEnvironmentVariable('USERPROFILE'),false)+fn
  3176. else
  3177. if (GetEnvironmentVariable('ALLUSERSPROFILE')<>'') and CfgFileExists(FixPath(GetEnvironmentVariable('ALLUSERSPROFILE'),false)+fn) then
  3178. foundfn:=FixPath(GetEnvironmentVariable('ALLUSERSPROFILE'),false)+fn
  3179. else
  3180. {$endif WINDOWS}
  3181. {$ifndef Unix}
  3182. if CfgFileExists(exepath+fn) then
  3183. foundfn:=exepath+fn
  3184. else
  3185. {$else}
  3186. if CfgFileExists('/etc/'+fn) then
  3187. foundfn:='/etc/'+fn
  3188. else
  3189. {$endif}
  3190. check_configfile:=false;
  3191. end;
  3192. end;
  3193. procedure read_arguments(cmd:TCmdStr);
  3194. procedure def_cpu_macros;
  3195. var
  3196. abi : tabi;
  3197. fputype : tfputype;
  3198. cputype : tcputype;
  3199. begin
  3200. for cputype:=low(tcputype) to high(tcputype) do
  3201. undef_system_macro('CPU'+Cputypestr[cputype]);
  3202. def_system_macro('CPU'+Cputypestr[init_settings.cputype]);
  3203. for fputype:=low(tfputype) to high(tfputype) do
  3204. undef_system_macro('FPU'+fputypestr[fputype]);
  3205. def_system_macro('FPU'+fputypestr[init_settings.fputype]);
  3206. { define abi }
  3207. for abi:=low(tabi) to high(tabi) do
  3208. undef_system_macro('FPC_ABI_'+abiinfo[abi].name);
  3209. def_system_macro('FPC_ABI_'+abiinfo[target_info.abi].name);
  3210. { Define FPC_ABI_EABI in addition to FPC_ABI_EABIHF on EABI VFP hardfloat
  3211. systems since most code needs to behave the same on both}
  3212. if target_info.abi = abi_eabihf then
  3213. def_system_macro('FPC_ABI_EABI');
  3214. { using a case is pretty useless here (FK) }
  3215. { some stuff for TP compatibility }
  3216. {$ifdef i386}
  3217. def_system_macro('CPU86');
  3218. def_system_macro('CPU87');
  3219. def_system_macro('CPU386');
  3220. {$endif}
  3221. { new processor stuff }
  3222. {$ifdef i386}
  3223. def_system_macro('CPUI386');
  3224. def_system_macro('CPU32');
  3225. def_system_macro('CPUX86');
  3226. def_system_macro('FPC_HAS_TYPE_EXTENDED');
  3227. def_system_macro('FPC_HAS_TYPE_DOUBLE');
  3228. def_system_macro('FPC_HAS_TYPE_SINGLE');
  3229. {$endif}
  3230. {$ifdef m68k}
  3231. def_system_macro('CPU68');
  3232. def_system_macro('CPU68K');
  3233. def_system_macro('CPUM68K');
  3234. def_system_macro('CPU32');
  3235. def_system_macro('FPC_CURRENCY_IS_INT64');
  3236. def_system_macro('FPC_COMP_IS_INT64');
  3237. {$endif}
  3238. {$ifdef powerpc}
  3239. def_system_macro('CPUPOWERPC');
  3240. def_system_macro('CPUPOWERPC32');
  3241. def_system_macro('CPU32');
  3242. def_system_macro('FPC_CURRENCY_IS_INT64');
  3243. def_system_macro('FPC_COMP_IS_INT64');
  3244. {$endif}
  3245. {$ifdef POWERPC64}
  3246. def_system_macro('CPUPOWERPC');
  3247. def_system_macro('CPUPOWERPC64');
  3248. def_system_macro('CPU64');
  3249. def_system_macro('FPC_CURRENCY_IS_INT64');
  3250. def_system_macro('FPC_COMP_IS_INT64');
  3251. {$endif}
  3252. {$ifdef x86_64}
  3253. def_system_macro('CPUX86_64');
  3254. def_system_macro('CPUAMD64');
  3255. def_system_macro('CPU64');
  3256. def_system_macro('CPUX64');
  3257. { not supported for now, afaik (FK)
  3258. def_system_macro('FPC_HAS_TYPE_FLOAT128'); }
  3259. {$ifndef FPC_SUPPORT_X87_TYPES_ON_WIN64}
  3260. { normally, win64 doesn't support the legacy fpu }
  3261. if target_info.system=system_x86_64_win64 then
  3262. begin
  3263. def_system_macro('FPC_CURRENCY_IS_INT64');
  3264. def_system_macro('FPC_COMP_IS_INT64');
  3265. end;
  3266. {$endif FPC_SUPPORT_X87_TYPES_ON_WIN64}
  3267. {$endif}
  3268. {$ifdef sparc}
  3269. def_system_macro('CPUSPARCGEN');
  3270. def_system_macro('CPUSPARC');
  3271. def_system_macro('CPUSPARC32');
  3272. def_system_macro('CPU32');
  3273. def_system_macro('FPC_CURRENCY_IS_INT64');
  3274. def_system_macro('FPC_COMP_IS_INT64');
  3275. {$endif}
  3276. {$ifdef sparc64}
  3277. def_system_macro('CPUSPARCGEN');
  3278. def_system_macro('CPUSPARC64');
  3279. def_system_macro('CPU64');
  3280. def_system_macro('FPC_CURRENCY_IS_INT64');
  3281. def_system_macro('FPC_COMP_IS_INT64');
  3282. {$endif}
  3283. {$ifdef arm}
  3284. def_system_macro('CPUARM');
  3285. def_system_macro('CPU32');
  3286. def_system_macro('FPC_CURRENCY_IS_INT64');
  3287. def_system_macro('FPC_COMP_IS_INT64');
  3288. {$endif arm}
  3289. {$ifdef avr}
  3290. def_system_macro('CPUAVR');
  3291. def_system_macro('CPU16');
  3292. def_system_macro('FPC_CURRENCY_IS_INT64');
  3293. def_system_macro('FPC_COMP_IS_INT64');
  3294. {$endif avr}
  3295. {$ifdef jvm}
  3296. def_system_macro('CPUJVM');
  3297. def_system_macro('CPU32');
  3298. def_system_macro('FPC_CURRENCY_IS_INT64');
  3299. def_system_macro('FPC_COMP_IS_INT64');
  3300. {$endif jvm}
  3301. {$ifdef mipsel}
  3302. def_system_macro('CPUMIPS');
  3303. def_system_macro('CPUMIPS32');
  3304. def_system_macro('CPUMIPSEL');
  3305. def_system_macro('CPUMIPSEL32');
  3306. def_system_macro('CPU32');
  3307. def_system_macro('FPC_HAS_TYPE_DOUBLE');
  3308. def_system_macro('FPC_HAS_TYPE_SINGLE');
  3309. def_system_macro('FPC_INCLUDE_SOFTWARE_INT64_TO_DOUBLE');
  3310. def_system_macro('FPC_CURRENCY_IS_INT64');
  3311. def_system_macro('FPC_COMP_IS_INT64');
  3312. def_system_macro('FPC_REQUIRES_PROPER_ALIGNMENT');
  3313. { On most systems, locals are accessed relative to base pointer,
  3314. but for MIPS cpu, they are accessed relative to stack pointer.
  3315. This needs adaptation for so low level routines,
  3316. like MethodPointerLocal and related objects unit functions. }
  3317. def_system_macro('FPC_LOCALS_ARE_STACK_REG_RELATIVE');
  3318. {$endif mipsel}
  3319. {$ifdef mipseb}
  3320. def_system_macro('CPUMIPS');
  3321. def_system_macro('CPUMIPS32');
  3322. def_system_macro('CPUMIPSEB');
  3323. def_system_macro('CPUMIPSEB32');
  3324. def_system_macro('CPU32');
  3325. def_system_macro('FPC_HAS_TYPE_DOUBLE');
  3326. def_system_macro('FPC_HAS_TYPE_SINGLE');
  3327. def_system_macro('FPC_INCLUDE_SOFTWARE_INT64_TO_DOUBLE');
  3328. def_system_macro('FPC_CURRENCY_IS_INT64');
  3329. def_system_macro('FPC_COMP_IS_INT64');
  3330. def_system_macro('FPC_REQUIRES_PROPER_ALIGNMENT');
  3331. { See comment above for mipsel }
  3332. def_system_macro('FPC_LOCALS_ARE_STACK_REG_RELATIVE');
  3333. {$endif}
  3334. {$ifdef i8086}
  3335. def_system_macro('CPU86'); { Borland compatibility }
  3336. def_system_macro('CPU87'); { Borland compatibility }
  3337. def_system_macro('CPUI8086');
  3338. def_system_macro('CPU16');
  3339. def_system_macro('FPC_HAS_TYPE_EXTENDED');
  3340. def_system_macro('FPC_HAS_TYPE_DOUBLE');
  3341. def_system_macro('FPC_HAS_TYPE_SINGLE');
  3342. case init_settings.x86memorymodel of
  3343. mm_tiny: def_system_macro('FPC_MM_TINY');
  3344. mm_small: def_system_macro('FPC_MM_SMALL');
  3345. mm_medium: def_system_macro('FPC_MM_MEDIUM');
  3346. mm_compact: def_system_macro('FPC_MM_COMPACT');
  3347. mm_large: def_system_macro('FPC_MM_LARGE');
  3348. mm_huge: def_system_macro('FPC_MM_HUGE');
  3349. end;
  3350. {$endif i8086}
  3351. {$ifdef aarch64}
  3352. def_system_macro('CPUAARCH64');
  3353. def_system_macro('CPU64');
  3354. def_system_macro('FPC_CURRENCY_IS_INT64');
  3355. def_system_macro('FPC_COMP_IS_INT64');
  3356. {$endif aarch64}
  3357. {$if defined(cpu8bitalu)}
  3358. def_system_macro('CPUINT8');
  3359. {$elseif defined(cpu16bitalu)}
  3360. def_system_macro('CPUINT16');
  3361. {$elseif defined(cpu32bitalu)}
  3362. def_system_macro('CPUINT32');
  3363. {$elseif defined(cpu64bitalu)}
  3364. def_system_macro('CPUINT64');
  3365. {$endif defined(cpu64bitalu)}
  3366. {$if defined(avr)}
  3367. def_system_macro('FPC_HAS_INTERNAL_ABS_SHORTINT');
  3368. {$endif}
  3369. {$if defined(i8086) or defined(avr)}
  3370. def_system_macro('FPC_HAS_INTERNAL_ABS_SMALLINT');
  3371. {$endif i8086 or avr}
  3372. { abs(long) is handled internally on all CPUs }
  3373. def_system_macro('FPC_HAS_INTERNAL_ABS_LONG');
  3374. {$if defined(i8086) or defined(i386) or defined(x86_64) or defined(powerpc64) or defined(cpuaarch64)}
  3375. def_system_macro('FPC_HAS_INTERNAL_ABS_INT64');
  3376. {$endif i8086 or i386 or x86_64 or powerpc64 or aarch64}
  3377. def_system_macro('FPC_HAS_MANAGEMENT_OPERATORS');
  3378. def_system_macro('FPC_HAS_UNICODESTRING');
  3379. def_system_macro('FPC_RTTI_PACKSET1');
  3380. def_system_macro('FPC_HAS_CPSTRING');
  3381. {$ifdef x86_64}
  3382. def_system_macro('FPC_HAS_RIP_RELATIVE');
  3383. {$endif x86_64}
  3384. def_system_macro('FPC_HAS_CEXTENDED');
  3385. def_system_macro('FPC_HAS_RESSTRINITS');
  3386. { these cpus have an inline rol/ror implementaion }
  3387. {$ifdef cpurox}
  3388. {$ifdef m68k}
  3389. if CPUM68K_HAS_ROLROR in cpu_capabilities[init_settings.cputype] then
  3390. def_system_macro('FPC_HAS_INTERNAL_ROX');
  3391. {$else}
  3392. def_system_macro('FPC_HAS_INTERNAL_ROX');
  3393. {$endif}
  3394. {$endif}
  3395. {$ifdef powerpc64}
  3396. def_system_macro('FPC_HAS_LWSYNC');
  3397. {$endif}
  3398. { currently, all supported CPUs have an internal sar implementation }
  3399. def_system_macro('FPC_HAS_INTERNAL_SAR');
  3400. {$ifdef SUPPORT_GET_FRAME}
  3401. def_system_macro('INTERNAL_BACKTRACE');
  3402. {$endif SUPPORT_GET_FRAME}
  3403. def_system_macro('STR_CONCAT_PROCS');
  3404. {$warnings off}
  3405. if pocall_default = pocall_register then
  3406. def_system_macro('REGCALL');
  3407. {$warnings on}
  3408. end;
  3409. var
  3410. env: ansistring;
  3411. i : tfeature;
  3412. j : longint;
  3413. abi : tabi;
  3414. {$if defined(cpucapabilities)}
  3415. cpuflag : tcpuflags;
  3416. hs : string;
  3417. {$endif defined(cpucapabilities)}
  3418. begin
  3419. option:=coption.create;
  3420. disable_configfile:=false;
  3421. { Non-core target defines }
  3422. Option.TargetOptions(true);
  3423. { get default messagefile }
  3424. msgfilename:=GetEnvironmentVariable('PPC_ERROR_FILE');
  3425. { default configfile can be specified on the commandline,
  3426. remove it first }
  3427. if (cmd<>'') and (cmd[1]='[') then
  3428. begin
  3429. ppccfg:=Copy(cmd,2,pos(']',cmd)-2);
  3430. Delete(cmd,1,pos(']',cmd));
  3431. end
  3432. else
  3433. ppccfg:='fpc.cfg';
  3434. { first pass reading of parameters, only -i -v -T etc.}
  3435. option.firstpass:=true;
  3436. if cmd<>'' then
  3437. option.parsecmd(cmd)
  3438. else
  3439. begin
  3440. option.read_parameters;
  3441. { Write only quickinfo }
  3442. if option.quickinfo<>'' then
  3443. option.writequickinfo;
  3444. end;
  3445. option.firstpass:=false;
  3446. { redefine target options so all defines are written even if no -Txxx is passed on the command line }
  3447. Option.TargetOptions(true);
  3448. { target is set here, for wince the default app type is gui }
  3449. if target_info.system in systems_wince then
  3450. SetApptype(app_gui)
  3451. else
  3452. SetApptype(apptype);
  3453. { default defines }
  3454. def_system_macro(target_info.shortname);
  3455. def_system_macro('FPC');
  3456. def_system_macro('VER'+version_nr);
  3457. def_system_macro('VER'+version_nr+'_'+release_nr);
  3458. def_system_macro('VER'+version_nr+'_'+release_nr+'_'+patch_nr);
  3459. { Temporary defines, until things settle down }
  3460. def_system_macro('FPC_HAS_OPERATOR_ENUMERATOR');
  3461. def_system_macro('FPC_HAS_CONSTREF');
  3462. def_system_macro('FPC_STATICRIPFIXED');
  3463. def_system_macro('FPC_VARIANTCOPY_FIXED');
  3464. def_system_macro('FPC_DYNARRAYCOPY_FIXED');
  3465. def_system_macro('FPC_HAS_MEMBAR');
  3466. def_system_macro('FPC_SETBASE_USED');
  3467. { don't remove this, it's also for fpdoc necessary (FK) }
  3468. def_system_macro('FPC_HAS_FEATURE_SUPPORT');
  3469. { make cpu makros available when reading the config files the second time }
  3470. def_cpu_macros;
  3471. if tf_cld in target_info.flags then
  3472. if not UpdateTargetSwitchStr('CLD', init_settings.targetswitches, true) then
  3473. InternalError(2013092801);
  3474. if tf_x86_far_procs_push_odd_bp in target_info.flags then
  3475. if not UpdateTargetSwitchStr('FARPROCSPUSHODDBP', init_settings.targetswitches, true) then
  3476. InternalError(2013092801);
  3477. { Set up a default prefix for binutils when cross-compiling }
  3478. if source_info.system<>target_info.system then
  3479. case target_info.system of
  3480. { Use standard Android NDK prefixes }
  3481. system_arm_android:
  3482. utilsprefix:='arm-linux-androideabi-';
  3483. system_i386_android:
  3484. utilsprefix:='i686-linux-android-';
  3485. system_mipsel_android:
  3486. utilsprefix:='mipsel-linux-android-';
  3487. end;
  3488. { Set up default value for the heap }
  3489. if target_info.system in systems_embedded then
  3490. begin
  3491. case target_info.system of
  3492. {$ifdef AVR}
  3493. system_avr_embedded:
  3494. if init_settings.controllertype=ct_avrsim then
  3495. heapsize:=8192
  3496. else
  3497. heapsize:=128;
  3498. {$endif AVR}
  3499. system_arm_embedded:
  3500. heapsize:=256;
  3501. system_mipsel_embedded:
  3502. heapsize:=256;
  3503. else
  3504. heapsize:=256;
  3505. end;
  3506. end;
  3507. { read configuration file }
  3508. if (not disable_configfile) and
  3509. (ppccfg<>'') then
  3510. read_configfile:=check_configfile(ppccfg,ppccfg)
  3511. else
  3512. read_configfile := false;
  3513. { Read commandline and configfile }
  3514. param_file:='';
  3515. { read configfile }
  3516. if read_configfile then
  3517. option.interpret_file(ppccfg);
  3518. { read parameters again to override config file }
  3519. if cmd<>'' then
  3520. option.parsecmd(cmd)
  3521. else
  3522. begin
  3523. { Write help pages if no parameters are passed }
  3524. if (paramcount=0) then
  3525. Option.WriteHelpPages;
  3526. option.read_parameters;
  3527. { Write only quickinfo }
  3528. if option.quickinfo<>'' then
  3529. option.writequickinfo;
  3530. end;
  3531. { check the compatibility of different options and adjust them if necessary
  3532. (and print possible errors)
  3533. }
  3534. option.checkoptionscompatibility;
  3535. { uses the CPUXXX-defines and target_info to determine whether the selected
  3536. target processor, if any, is supported }
  3537. Option.VerifyTargetProcessor;
  3538. { Stop if errors in options }
  3539. if ErrorCount>0 then
  3540. StopOptions(1);
  3541. { endian define }
  3542. case target_info.endian of
  3543. endian_little :
  3544. begin
  3545. def_system_macro('ENDIAN_LITTLE');
  3546. def_system_macro('FPC_LITTLE_ENDIAN');
  3547. end;
  3548. endian_big :
  3549. begin
  3550. def_system_macro('ENDIAN_BIG');
  3551. def_system_macro('FPC_BIG_ENDIAN');
  3552. end;
  3553. end;
  3554. { Write logo }
  3555. if option.ParaLogo then
  3556. option.writelogo;
  3557. { Check file to compile }
  3558. if param_file='' then
  3559. begin
  3560. Message(option_no_source_found);
  3561. StopOptions(1);
  3562. end;
  3563. {$ifndef Unix}
  3564. param_file:=FixFileName(param_file);
  3565. {$endif not unix}
  3566. inputfilepath:=ExtractFilePath(param_file);
  3567. inputfilename:=ExtractFileName(param_file);
  3568. if ExtractFileExt(inputfilename)='' then
  3569. begin
  3570. if FileExists(inputfilepath+ChangeFileExt(inputfilename,sourceext)) then
  3571. inputfilename:=ChangeFileExt(inputfilename,sourceext)
  3572. else if FileExists(inputfilepath+ChangeFileExt(inputfilename,pasext)) then
  3573. inputfilename:=ChangeFileExt(inputfilename,pasext)
  3574. else if ((m_mac in current_settings.modeswitches) or
  3575. (tf_p_ext_support in target_info.flags))
  3576. and FileExists(inputfilepath+ChangeFileExt(inputfilename,pext)) then
  3577. inputfilename:=ChangeFileExt(inputfilename,pext);
  3578. end;
  3579. { Check output dir }
  3580. if (OutputExeDir<>'') and
  3581. not PathExists(OutputExeDir,false) then
  3582. begin
  3583. Message1(general_e_path_does_not_exist,OutputExeDir);
  3584. StopOptions(1);
  3585. end;
  3586. { Add paths specified with parameters to the searchpaths }
  3587. UnitSearchPath.AddList(option.ParaUnitPath,true);
  3588. ObjectSearchPath.AddList(option.ParaObjectPath,true);
  3589. IncludeSearchPath.AddList(option.ParaIncludePath,true);
  3590. LibrarySearchPath.AddList(option.ParaLibraryPath,true);
  3591. FrameworkSearchPath.AddList(option.ParaFrameworkPath,true);
  3592. packagesearchpath.addlist(option.parapackagepath,true);
  3593. for j:=0 to option.parapackages.count-1 do
  3594. add_package(option.parapackages.NameOfIndex(j),true,true);
  3595. { add unit environment and exepath to the unit search path }
  3596. if inputfilepath<>'' then
  3597. Unitsearchpath.AddPath(inputfilepath,true);
  3598. if not disable_configfile then
  3599. begin
  3600. env:=GetEnvironmentVariable(target_info.unit_env);
  3601. if env<>'' then
  3602. UnitSearchPath.AddPath(GetEnvironmentVariable(target_info.unit_env),false);
  3603. end;
  3604. {$ifdef Unix}
  3605. fpcdir:=FixPath(GetEnvironmentVariable('FPCDIR'),false);
  3606. if fpcdir='' then
  3607. begin
  3608. if PathExists('/usr/local/lib/fpc/'+version_string,true) then
  3609. fpcdir:='/usr/local/lib/fpc/'+version_string+'/'
  3610. else
  3611. fpcdir:='/usr/lib/fpc/'+version_string+'/';
  3612. end;
  3613. {$else unix}
  3614. fpcdir:=FixPath(GetEnvironmentVariable('FPCDIR'),false);
  3615. if fpcdir='' then
  3616. begin
  3617. fpcdir:=ExePath+'../';
  3618. if not(PathExists(fpcdir+'units',true)) and
  3619. not(PathExists(fpcdir+'rtl',true)) then
  3620. fpcdir:=fpcdir+'../';
  3621. end;
  3622. {$endif unix}
  3623. { first try development RTL, else use the default installation path }
  3624. if not disable_configfile then
  3625. begin
  3626. if PathExists(FpcDir+'rtl',true) then
  3627. if (tf_use_8_3 in Source_Info.Flags) or
  3628. (tf_use_8_3 in Target_Info.Flags) then
  3629. UnitSearchPath.AddPath(FpcDir+'rtl/'+target_os_string,false)
  3630. else
  3631. UnitSearchPath.AddPath(FpcDir+'rtl/'+target_full_string,false)
  3632. else
  3633. if (tf_use_8_3 in Source_Info.Flags) or
  3634. (tf_use_8_3 in Target_Info.Flags) then
  3635. UnitSearchPath.AddPath(FpcDir+'units/'+target_os_string+'/rtl',false)
  3636. else
  3637. UnitSearchPath.AddPath(FpcDir+'units/'+target_full_string+'/rtl',false);
  3638. end;
  3639. { Add exepath if the exe is not in the current dir, because that is always searched already.
  3640. Do not add it when linking on the target because then we can maybe already find
  3641. .o files that are not for the target }
  3642. if (ExePath<>cfileutl.GetCurrentDir) and
  3643. not(cs_link_on_target in init_settings.globalswitches) then
  3644. UnitSearchPath.AddPath(ExePath,false);
  3645. { Add unit dir to the object and library path }
  3646. objectsearchpath.AddList(unitsearchpath,false);
  3647. librarysearchpath.AddList(unitsearchpath,false);
  3648. {$ifdef llvm}
  3649. { force llvm assembler writer }
  3650. option.paratargetasm:=as_llvm;
  3651. {$endif llvm}
  3652. { maybe override assembler }
  3653. if (option.paratargetasm<>as_none) then
  3654. begin
  3655. if not set_target_asm(option.paratargetasm) then
  3656. begin
  3657. Message2(option_incompatible_asm,asminfos[option.paratargetasm]^.idtxt,target_info.name);
  3658. set_target_asm(target_info.assemextern);
  3659. Message1(option_asm_forced,target_asm.idtxt);
  3660. end;
  3661. if (af_no_debug in asminfos[option.paratargetasm]^.flags) and
  3662. (option.paratargetdbg<>dbg_none) then
  3663. begin
  3664. Message1(option_confict_asm_debug,
  3665. asminfos[option.paratargetasm]^.idtxt);
  3666. option.paratargetdbg:=dbg_none;
  3667. exclude(init_settings.moduleswitches,cs_debuginfo);
  3668. end;
  3669. end;
  3670. {TOptionheck a second time as we might have changed assembler just above }
  3671. option.checkoptionscompatibility;
  3672. { maybe override debug info format }
  3673. if (option.paratargetdbg<>dbg_none) then
  3674. if not set_target_dbg(option.paratargetdbg) then
  3675. Message(option_w_unsupported_debug_format);
  3676. { switch assembler if it's binary and we got -a on the cmdline }
  3677. if (cs_asm_leave in init_settings.globalswitches) and
  3678. (af_outputbinary in target_asm.flags) then
  3679. begin
  3680. Message(option_switch_bin_to_src_assembler);
  3681. set_target_asm(target_info.assemextern);
  3682. { At least i8086 needs that for nasm and -CX
  3683. which is incompatible with internal linker }
  3684. option.checkoptionscompatibility;
  3685. end;
  3686. { Force use of external linker if there is no
  3687. internal linker or the linking is skipped }
  3688. if not(cs_link_extern in init_settings.globalswitches) and
  3689. ((target_info.link=ld_none) or
  3690. (cs_link_nolink in init_settings.globalswitches)) then
  3691. begin
  3692. include(init_settings.globalswitches,cs_link_extern);
  3693. end;
  3694. { turn off stripping if compiling with debuginfo or profile }
  3695. if (
  3696. (cs_debuginfo in init_settings.moduleswitches) or
  3697. (cs_profile in init_settings.moduleswitches)
  3698. ) and
  3699. not(cs_link_separate_dbg_file in init_settings.globalswitches) then
  3700. exclude(init_settings.globalswitches,cs_link_strip);
  3701. { set Mac OS X version default macros if not specified explicitly }
  3702. option.MaybeSetDefaultMacVersionMacro;
  3703. { force fpu emulation on arm/wince, arm/gba, arm/embedded and arm/nds
  3704. if fpu type not explicitly set }
  3705. if not(option.FPUSetExplicitly) and
  3706. ((target_info.system in [system_arm_wince,system_arm_gba,
  3707. system_m68k_amiga,system_m68k_atari,
  3708. system_arm_nds,system_arm_embedded])
  3709. {$ifdef arm}
  3710. or (target_info.abi=abi_eabi)
  3711. {$endif arm}
  3712. )
  3713. {$if defined(arm) or defined (m68k)}
  3714. or (init_settings.fputype=fpu_soft)
  3715. {$endif arm or m68k}
  3716. then
  3717. begin
  3718. {$ifdef cpufpemu}
  3719. include(init_settings.moduleswitches,cs_fp_emulation);
  3720. { cs_fp_emulation and fpu_soft are equal on arm and m68k }
  3721. init_settings.fputype:=fpu_soft;
  3722. {$endif cpufpemu}
  3723. end;
  3724. {$ifdef i386}
  3725. case target_info.system of
  3726. system_i386_android:
  3727. begin
  3728. { set default cpu type to PentiumM for Android unless specified otherwise }
  3729. if not option.CPUSetExplicitly then
  3730. init_settings.cputype:=cpu_PentiumM;
  3731. if not option.OptCPUSetExplicitly then
  3732. init_settings.optimizecputype:=cpu_PentiumM;
  3733. { set default fpu type to SSSE3 for Android unless specified otherwise }
  3734. if not option.FPUSetExplicitly then
  3735. init_settings.fputype:=fpu_ssse3;
  3736. end;
  3737. end;
  3738. {$endif i386}
  3739. {$ifdef arm}
  3740. case target_info.system of
  3741. system_arm_darwin:
  3742. begin
  3743. { set default cpu type to ARMv7 for Darwin unless specified otherwise, and fpu
  3744. to VFPv3 (that's what all 32 bit ARM iOS devices use nowadays)
  3745. }
  3746. if not option.CPUSetExplicitly then
  3747. init_settings.cputype:=cpu_armv7;
  3748. if not option.OptCPUSetExplicitly then
  3749. init_settings.optimizecputype:=cpu_armv7;
  3750. if not option.FPUSetExplicitly then
  3751. init_settings.fputype:=fpu_vfpv3;
  3752. end;
  3753. system_arm_android:
  3754. begin
  3755. { set default cpu type to ARMv5T for Android unless specified otherwise }
  3756. if not option.CPUSetExplicitly then
  3757. init_settings.cputype:=cpu_armv5t;
  3758. if not option.OptCPUSetExplicitly then
  3759. init_settings.optimizecputype:=cpu_armv5t;
  3760. end;
  3761. end;
  3762. { ARMHF defaults }
  3763. if (target_info.abi = abi_eabihf) then
  3764. { set default cpu type to ARMv7a for ARMHF unless specified otherwise }
  3765. begin
  3766. {$ifdef CPUARMV6}
  3767. { if the compiler is built for armv6, then
  3768. inherit this setting, e.g. Raspian is armhf but
  3769. only armv6, this makes rebuilds of the compiler
  3770. easier }
  3771. if not option.CPUSetExplicitly then
  3772. init_settings.cputype:=cpu_armv6;
  3773. if not option.OptCPUSetExplicitly then
  3774. init_settings.optimizecputype:=cpu_armv6;
  3775. {$else CPUARMV6}
  3776. if not option.CPUSetExplicitly then
  3777. init_settings.cputype:=cpu_armv7a;
  3778. if not option.OptCPUSetExplicitly then
  3779. init_settings.optimizecputype:=cpu_armv7a;
  3780. {$endif CPUARMV6}
  3781. { Set FPU type }
  3782. if not(option.FPUSetExplicitly) then
  3783. begin
  3784. init_settings.fputype:=fpu_vfpv3_d16
  3785. end
  3786. else
  3787. begin
  3788. if not (init_settings.fputype in [fpu_vfpv2,fpu_vfpv3,fpu_vfpv3_d16,fpu_vfpv4]) then
  3789. begin
  3790. Message(option_illegal_fpu_eabihf);
  3791. StopOptions(1);
  3792. end;
  3793. end;
  3794. end;
  3795. if (init_settings.instructionset=is_thumb) and not(CPUARM_HAS_THUMB2 in cpu_capabilities[init_settings.cputype]) then
  3796. begin
  3797. def_system_macro('CPUTHUMB');
  3798. if not option.FPUSetExplicitly then
  3799. init_settings.fputype:=fpu_soft;
  3800. {$if defined(FPC_ARMEL) or defined(FPC_ARMHF)}
  3801. 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';
  3802. {$else FPC_ARMAL or FPC_ARMHF}
  3803. if target_info.endian=endian_little then
  3804. 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';
  3805. {$endif FPC_ARMAL or FPC_ARMHF}
  3806. end;
  3807. if (init_settings.instructionset=is_thumb) and (CPUARM_HAS_THUMB2 in cpu_capabilities[init_settings.cputype]) then
  3808. def_system_macro('CPUTHUMB2');
  3809. {$endif arm}
  3810. {$ifdef jvm}
  3811. { set default CPU type to Dalvik when targeting Android }
  3812. if target_info.system=system_jvm_android32 then
  3813. begin
  3814. if not option.CPUSetExplicitly then
  3815. init_settings.cputype:=cpu_dalvik;
  3816. end;
  3817. {$endif jvm}
  3818. {$ifdef llvm}
  3819. { standard extension for llvm bitcode files }
  3820. target_info.asmext:='.ll';
  3821. { don't generate dwarf cfi, llvm will do that }
  3822. exclude(target_info.flags,tf_needs_dwarf_cfi);
  3823. {$endif llvm}
  3824. {$ifdef mipsel}
  3825. case target_info.system of
  3826. system_mipsel_android:
  3827. begin
  3828. { set default cpu type to MIPS32 rev. 1 and hard float for MIPS-Android unless specified otherwise }
  3829. if not option.CPUSetExplicitly then
  3830. init_settings.cputype:=cpu_mips32;
  3831. if not option.OptCPUSetExplicitly then
  3832. init_settings.optimizecputype:=cpu_mips32;
  3833. if not option.FPUSetExplicitly then
  3834. init_settings.fputype:=fpu_mips2;
  3835. end;
  3836. system_mipsel_embedded:
  3837. begin
  3838. { set default cpu type to PIC32MX and softfloat for MIPSEL-EMBEDDED target unless specified otherwise }
  3839. if not option.CPUSetExplicitly then
  3840. init_settings.cputype:=cpu_pic32mx;
  3841. if not option.OptCPUSetExplicitly then
  3842. init_settings.optimizecputype:=cpu_pic32mx;
  3843. if not option.FPUSetExplicitly then
  3844. init_settings.fputype:=fpu_soft;
  3845. end;
  3846. end;
  3847. {$endif mipsel}
  3848. {$ifdef m68k}
  3849. if init_settings.cputype in cpu_coldfire then
  3850. def_system_macro('CPUCOLDFIRE')
  3851. else
  3852. if (target_info.system in [system_m68k_linux,system_m68k_netbsd]) and
  3853. not (option.FPUSetExplicitly) then
  3854. begin
  3855. { enable HW FPU for UNIX by default, but only for
  3856. original 68k, not Coldfire }
  3857. exclude(init_settings.moduleswitches,cs_fp_emulation);
  3858. init_settings.fputype:=fpu_68881;
  3859. end;
  3860. {$endif m68k}
  3861. { now we can define cpu and fpu type }
  3862. def_cpu_macros;
  3863. { Use init_settings cpu type for asm cpu type,
  3864. if asmcputype is cpu_none,
  3865. at least as long as there is no explicit
  3866. option to set it on command line PM }
  3867. if init_settings.asmcputype = cpu_none then
  3868. init_settings.asmcputype:=init_settings.cputype;
  3869. {$ifdef llvm}
  3870. def_system_macro('CPULLVM');
  3871. {$endif llvm}
  3872. {$if defined(cpucapabilities)}
  3873. for cpuflag:=low(cpuflag) to high(cpuflag) do
  3874. begin
  3875. str(cpuflag,hs);
  3876. if cpuflag in cpu_capabilities[init_settings.cputype] then
  3877. def_system_macro(hs)
  3878. else
  3879. undef_system_macro(hs);
  3880. end;
  3881. {$endif defined(cpucapabilities)}
  3882. if init_settings.fputype<>fpu_none then
  3883. begin
  3884. {$if defined(i386) or defined(i8086)}
  3885. def_system_macro('FPC_HAS_TYPE_EXTENDED');
  3886. {$endif}
  3887. def_system_macro('FPC_HAS_TYPE_SINGLE');
  3888. def_system_macro('FPC_HAS_TYPE_DOUBLE');
  3889. {$if not defined(i386) and not defined(x86_64) and not defined(i8086) and not defined(aarch64)}
  3890. def_system_macro('FPC_INCLUDE_SOFTWARE_INT64_TO_DOUBLE');
  3891. {$endif}
  3892. {$if defined(m68k)}
  3893. def_system_macro('FPC_INCLUDE_SOFTWARE_LONGWORD_TO_DOUBLE');
  3894. {$endif}
  3895. {$ifdef x86_64}
  3896. {$ifndef FPC_SUPPORT_X87_TYPES_ON_WIN64}
  3897. { normally, win64 doesn't support the legacy fpu }
  3898. if target_info.system=system_x86_64_win64 then
  3899. undef_system_macro('FPC_HAS_TYPE_EXTENDED')
  3900. else
  3901. {$endif FPC_SUPPORT_X87_TYPES_ON_WIN64}
  3902. def_system_macro('FPC_HAS_TYPE_EXTENDED');
  3903. {$endif}
  3904. end;
  3905. { Enable now for testing }
  3906. {$ifndef DISABLE_TLS_DIRECTORY}
  3907. if target_info.system in systems_windows then
  3908. def_system_macro('FPC_USE_TLS_DIRECTORY');
  3909. {$endif not DISABLE_TLS_DIRECTORY}
  3910. {$ifndef DISABLE_WIN64_SEH}
  3911. if target_info.system=system_x86_64_win64 then
  3912. def_system_macro('FPC_USE_WIN64_SEH');
  3913. {$endif DISABLE_WIN64_SEH}
  3914. {$ifdef TEST_WIN32_SEH}
  3915. if target_info.system=system_i386_win32 then
  3916. def_system_macro('FPC_USE_WIN32_SEH');
  3917. {$endif TEST_WIN32_SEH}
  3918. {$ifdef ARM}
  3919. { define FPC_DOUBLE_HILO_SWAPPED if needed to properly handle doubles in RTL }
  3920. if (init_settings.fputype in [fpu_fpa,fpu_fpa10,fpu_fpa11]) and
  3921. not(cs_fp_emulation in init_settings.moduleswitches) then
  3922. def_system_macro('FPC_DOUBLE_HILO_SWAPPED');
  3923. {$endif ARM}
  3924. { inline bsf/bsr implementation }
  3925. {$if not defined(llvm) and (defined(i386) or defined(x86_64) or defined(aarch64) or defined(powerpc) or defined(powerpc64))}
  3926. def_system_macro('FPC_HAS_INTERNAL_BSF');
  3927. def_system_macro('FPC_HAS_INTERNAL_BSR');
  3928. {$endif}
  3929. { hardware FMA support }
  3930. {$if defined(i386) or defined(x86_64)}
  3931. if (cpu_capabilities[current_settings.cputype]*[CPUX86_HAS_FMA,CPUX86_HAS_FMA4])<>[] then
  3932. begin
  3933. def_system_macro('FPC_HAS_FAST_FMA_SINGLE');
  3934. def_system_macro('FPC_HAS_FAST_FMA_DOUBLE');
  3935. end;
  3936. {$endif defined(i386) or defined(x86_64)}
  3937. {$if defined(arm)}
  3938. { it is determined during system unit compilation if clz is used for bsf or not,
  3939. this is not perfect but the current implementation bsf/bsr does not allow another
  3940. solution }
  3941. if (CPUARM_HAS_CLZ in cpu_capabilities[init_settings.cputype]) and
  3942. ((init_settings.instructionset=is_arm) or
  3943. (CPUARM_HAS_THUMB2 in cpu_capabilities[init_settings.cputype])) then
  3944. begin
  3945. def_system_macro('FPC_HAS_INTERNAL_BSR');
  3946. if CPUARM_HAS_RBIT in cpu_capabilities[init_settings.cputype] then
  3947. def_system_macro('FPC_HAS_INTERNAL_BSF');
  3948. end;
  3949. {$endif}
  3950. {$if defined(powerpc64)}
  3951. { on sysv targets, default to elfv2 for little endian and to elfv1 for
  3952. big endian (unless specified otherwise). As the gcc man page says:
  3953. "Overriding the default ABI requires special system support and is
  3954. likely to fail in spectacular ways" }
  3955. if not option.ABISetExplicitly then
  3956. begin
  3957. if (target_info.abi=abi_powerpc_sysv) and
  3958. (target_info.endian=endian_little) then
  3959. target_info.abi:=abi_powerpc_elfv2
  3960. else
  3961. if (target_info.abi=abi_powerpc_elfv2) and
  3962. (target_info.endian=endian_big) then
  3963. target_info.abi:=abi_powerpc_sysv
  3964. end;
  3965. {$endif}
  3966. {$if defined(powerpc) or defined(powerpc64)}
  3967. { define _CALL_ELF symbol like gcc }
  3968. case target_info.abi of
  3969. abi_powerpc_sysv:
  3970. set_system_compvar('_CALL_ELF','1');
  3971. abi_powerpc_elfv2:
  3972. set_system_compvar('_CALL_ELF','2');
  3973. end;
  3974. {$endif}
  3975. { Section smartlinking conflicts with import sections on Windows }
  3976. if GenerateImportSection and
  3977. (target_info.system in [system_i386_win32,system_x86_64_win64]) then
  3978. exclude(target_info.flags,tf_smartlink_sections);
  3979. if not option.LinkTypeSetExplicitly then
  3980. set_default_link_type;
  3981. { Default alignment settings,
  3982. 1. load the defaults for the target
  3983. 2. override with generic optimizer setting (little size)
  3984. 3. override with the user specified -Oa }
  3985. UpdateAlignment(init_settings.alignment,target_info.alignment);
  3986. if (cs_opt_size in init_settings.optimizerswitches) then
  3987. begin
  3988. init_settings.alignment.procalign:=1;
  3989. init_settings.alignment.jumpalign:=1;
  3990. init_settings.alignment.loopalign:=1;
  3991. {$ifdef x86}
  3992. { constalignmax=1 keeps the executable and thus the memory foot print small but
  3993. all processors except x86 are really hurt by this or might even crash }
  3994. init_settings.alignment.constalignmax:=1;
  3995. {$endif x86}
  3996. end;
  3997. UpdateAlignment(init_settings.alignment,option.paraalignment);
  3998. set_system_macro('FPC_VERSION',version_nr);
  3999. set_system_macro('FPC_RELEASE',release_nr);
  4000. set_system_macro('FPC_PATCH',patch_nr);
  4001. set_system_macro('FPC_FULLVERSION',Format('%d%.02d%.02d',[StrToInt(version_nr),StrToInt(release_nr),StrToInt(patch_nr)]));
  4002. if target_info.system in systems_indirect_entry_information then
  4003. def_system_macro('FPC_HAS_INDIRECT_ENTRY_INFORMATION');
  4004. if not (tf_winlikewidestring in target_info.flags) then
  4005. def_system_macro('FPC_WIDESTRING_EQUAL_UNICODESTRING');
  4006. if tf_supports_packages in target_info.flags then
  4007. def_system_macro('FPC_HAS_DYNAMIC_PACKAGES');
  4008. if target_info.system in systems_indirect_var_imports then
  4009. def_system_macro('FPC_HAS_INDIRECT_VAR_ACCESS');
  4010. if cs_compilesystem in init_settings.moduleswitches then
  4011. for i:=low(tfeature) to high(tfeature) do
  4012. if i in features then
  4013. def_system_macro('FPC_HAS_FEATURE_'+featurestr[i]);
  4014. {$push}
  4015. {$warn 6018 off} { Unreachable code due to compile time evaluation }
  4016. if ControllerSupport and (target_info.system in systems_embedded) and
  4017. (init_settings.controllertype<>ct_none) then
  4018. begin
  4019. with embedded_controllers[init_settings.controllertype] do
  4020. begin
  4021. set_system_macro('FPC_FLASHBASE',tostr(flashbase));
  4022. set_system_macro('FPC_FLASHSIZE',tostr(flashsize));
  4023. set_system_macro('FPC_SRAMBASE',tostr(srambase));
  4024. set_system_macro('FPC_SRAMSIZE',tostr(sramsize));
  4025. set_system_macro('FPC_EEPROMBASE',tostr(eeprombase));
  4026. set_system_macro('FPC_EEPROMSIZE',tostr(eepromsize));
  4027. set_system_macro('FPC_BOOTBASE',tostr(bootbase));
  4028. set_system_macro('FPC_BOOTSIZE',tostr(bootsize));
  4029. end;
  4030. end;
  4031. {$pop}
  4032. option.free;
  4033. Option:=nil;
  4034. clearstack_pocalls := [pocall_cdecl,pocall_cppdecl,pocall_syscall,pocall_mwpascal,pocall_sysv_abi_cdecl,pocall_ms_abi_cdecl];
  4035. cdecl_pocalls := [pocall_cdecl, pocall_cppdecl, pocall_mwpascal, pocall_sysv_abi_cdecl, pocall_ms_abi_cdecl];
  4036. if (tf_safecall_clearstack in target_info.flags) then
  4037. begin
  4038. include (cdecl_pocalls, pocall_safecall);
  4039. include (clearstack_pocalls, pocall_safecall)
  4040. end;
  4041. end;
  4042. initialization
  4043. coption:=toption;
  4044. finalization
  4045. if assigned(option) then
  4046. option.free;
  4047. end.