(* we put all this in the System context *)
   Begin["System`"]

(* set up the first possible message *)
   General::noopen = "Can't open `1`."

(* this message is here because we want to use Off[General::writewarn] *)
   General::writewarn = "Defining rule for `1`."

   Off[General::newsym]

(* install SetAttributes and ClearAttributes commands.  Some of the
	packages below use SetAttributes[ ] so keep this up here. *)
   <<Attributes.m

(* external packages communication (to be moved into the kernel) *)
   << Install.m

(* install ExpandAll,ExpandDenominator,ExpandNumerator,PowerExpand *)
   <<Expand.m

(* install ValueQ function *)
   <<ValueQ.m

(* install basic Mathematica code for Integrate[ ] *)
   <<Integrate.m

(* install SinIntegral, CosIntegral *)
   <<SinIntegral.m

(* install inverse functions *)
   <<InverseFunctions.m

(* install formats for Infinity *)
   <<FormatInfinity.m

(* install multidimensional Fourier Transforms *)
   <<Fourier.m

(* install RunThrough command *)
   <<RunThrough.m

(* install Edit command *)
   <<Edit.m

(* install the correct conversion utilities for Plots *)
  <<GraphicsCoercion.m

(* install Digits.m (obsolete) *)
   << Digits.m

(* warning messages for obsolete options and functions *)
  << Obsolete.m

(* Now carry out Thin system generation *)

$DumpedPackages = 
  { "Install.m", "Expand.m", "ValueQ.m", "Integrate.m", "SinIntegral.m",
    "InverseFunctions.m", "FormatInfinity.m", "Fourier.m", "RunThrough.m",
    "Edit.m", "Attributes.m", "GraphicsCoercion.m", "Digits.m", "Obsolete.m"}

$DumpedPackages::usage = "$DumpedPackages gives a list of the packages which
	have been dumped into the system."

System`Private`FatStuff := 
(
Get["msg.m"];		 	(* read in messages file *)
Get["info.m"];		 	(* read in file of information about functions *)
Get["Integrate/table.m"]; 	(* install code for indefinite integration  *)
Get["Integrate/main.m"]; 	(* install code for definite integration  *)
Get["Elliptic.m"];	 	(* install elliptic functions *)
Get["HypergeometricPFQ.m"]; 	(* install generalized hypergeometric functions *)
Get["Series.m"];	 	(* install additional Series definitions *)
Get["ClebschGordan.m"]; 	(* install symbolic Clebsch-Gordan coefficients *)
Get["LinearProgramming.m"]; 	(* install linear programming *)
Get["PrimePi.m"];	 	(* install PrimePi *)
Get["GroebnerBasis.m"]; 	(* install GroebnerBasis command *)
Get["ComplexExpand.m"];		(* install ComplexExpand code *)
Get["NSolve.m"];	 	(* install NSolve *)
$DumpedPackages = Join[ $DumpedPackages,
  {"msg.m", "info.m", "Integrate/table.m",
   "Integrate/main.m", "Elliptic.m", "HypergeometricPFQ.m", "Series.m", 
   "ClebschGordan.m", "LinearProgramming.m", "PrimePi.m", "GroebnerBasis.m",
   "NSolve.m", "ComplexExpand.m"}]
)

(* Thin system stuff  *)


Unprotect[ $NewMessage]

Unprotect[ SystemStub]

Unprotect[AutoLoad]

Begin["`Private`"] 

$NewMessage :=
        Function[ {Symb, Tag},
                Module[ {Res, Mname},
                        Mname = ToString[ MessageName[Symb, Tag]] ;
                        Res = If[ Tag =!= "usage",
                                FindList[ "msgthin.m",{ Mname,
                                        ToString[MessageName[General, Tag]]}],
                                FindList[ "infothin.m", Mname]] ;
			If[ ListQ[Res] && Apply[ And, Map[ StringQ, Res]],
					  ToExpression[ Res]] ;
                        ],
                {HoldAll}]

Attributes[ $NewMessage] = {Protected}

SystemStub[ Fn_, File_] :=
        Block[{Args},
                Unprotect[ Fn] ;
                (Fn[Args___]:= AutoLoad[Fn,File,{Args}]);
                SetAttributes[Fn, {Protected, ReadProtected}];
        ]

Attributes[ SystemStub] = {Protected}

AutoLoad[Fn_,File_,Args_]:=
        Block[{},
                Get[File];
                Apply[Fn,Args]
        ];

Attributes[ AutoLoad] = {Protected}

End[]

SystemStub[ Integrate`Definite, "Integrate`main`"];
SystemStub[ Integrate`TableLookUp, "Integrate`table`"];
SystemStub[ JacobiSN, "Elliptic.m"];
SystemStub[ JacobiSD, "Elliptic.m"];
SystemStub[ JacobiSC, "Elliptic.m"];
SystemStub[ JacobiCS, "Elliptic.m"];
SystemStub[ JacobiCN, "Elliptic.m"];
SystemStub[ JacobiCD, "Elliptic.m"];
SystemStub[ JacobiNC, "Elliptic.m"];
SystemStub[ JacobiND, "Elliptic.m"];
SystemStub[ JacobiDN, "Elliptic.m"];
SystemStub[ JacobiDS, "Elliptic.m"];
SystemStub[ JacobiDC, "Elliptic.m"];
SystemStub[ JacobiAmplitude, "Elliptic.m"];
SystemStub[ InverseJacobiSN, "Elliptic.m"];
SystemStub[ InverseJacobiSD, "Elliptic.m"];
SystemStub[ InverseJacobiSC, "Elliptic.m"];
SystemStub[ InverseJacobiCS, "Elliptic.m"];
SystemStub[ InverseJacobiCN, "Elliptic.m"];
SystemStub[ InverseJacobiCD, "Elliptic.m"];
SystemStub[ InverseJacobiNS, "Elliptic.m"];
SystemStub[ InverseJacobiNC, "Elliptic.m"];
SystemStub[ InverseJacobiDS, "Elliptic.m"];
SystemStub[ InverseJacobiDC, "Elliptic.m"];
SystemStub[ InverseJacobiDN, "Elliptic.m"];
SystemStub[ InverseJacobiND, "Elliptic.m"];
SystemStub[ EllipticNomeQ, "Elliptic.m"];
SystemStub[ EllipticThetaS, "Elliptic.m"];
SystemStub[ EllipticThetaC, "Elliptic.m"];
SystemStub[ EllipticThetaN, "Elliptic.m"];
SystemStub[ EllipticThetaD, "Elliptic.m"];
SystemStub[ WeierstrassP, "Elliptic.m"];
SystemStub[ WeierstrassPPrime, "Elliptic.m"];
SystemStub[ InverseWeierstrassP, "Elliptic.m"];
SystemStub[ EllipticExp, "Elliptic.m"];
SystemStub[ EllipticLog, "Elliptic.m"];
SystemStub[ HypergeometricPFQ, "HypergeometricPFQ.m"];
SystemStub[ HypergeometricPFQRegularized, "HypergeometricPFQ.m"];
SystemStub[ Hypergeometric1F1, "HypergeometricPFQ.m"];
SystemStub[ Hypergeometric2F1, "HypergeometricPFQ.m"];
SystemStub[InverseSeries, "Series.m"];
SystemStub[Series, "Series.m"];
SystemStub[SeriesData, "Series.m"];
SystemStub[ ClebschGordan, "ClebschGordan.m"];
SystemStub[ ThreeJSymbol, "ClebschGordan.m"];
SystemStub[ SixJSymbol, "ClebschGordan.m"];
SystemStub[ LinearProgramming, "LinearProgramming.m"];
SystemStub[ PrimePi, "PrimePi.m"];
SystemStub[ NSolve, "NSolve.m"];
SystemStub[ GroebnerBasis, "GroebnerBasis.m"];
SystemStub[ ComplexExpand, "ComplexExpand.m"];
SystemStub[ TargetFunctions, "ComplexExpand.m"];
Begin[ "System`ComplexExpand`"];
SystemStub[ AbsExpr, "ComplexExpand.m"];
SystemStub[ ArgExpr, "ComplexExpand.m"];
SystemStub[ ConjugateExpr, "ComplexExpand.m"];
SystemStub[ ReImExpr, "ComplexExpand.m"];
SystemStub[ SignExpr, "ComplexExpand.m"];
End[];

(* End Thin system stuff *)


(* NProtect functions READ this is LAST to prevent wrong symbols
	being generated *)
(*
   <<NProt.m
*)

(* this symbol will be evaluated when Mathematica ends *)
   $Epilog := << end.m

(* restore previous context *)
   End[]

(* standard return value for the Get which got this file *)
   Null
