/* well, we have no subdirs ...
#define PassCDebugFlags 'CDEBUGFLAGS=$(CDEBUGFLAGS)'
*/

#ifdef DEBUG
CDEBUGFLAGS := $(CDEBUGFLAGS) -g
#endif

#ifndef BuildBoth
#define BuildBoth (defined(LinuxArchitecture) && !UseElfFormat)
#endif

#ifndef LinuxShadowSuite
#define LinuxShadowSuite NO
#endif

#if FSUseSyslog
LOG_DEFINES = -DUSE_SYSLOG
#endif

#ifdef NoXDMCP
XDMCPLIB =
#else
XDMCP_DEFINES = -DXDMCP
#endif

#if HasXdmAuth
XDMAUTH_DEFINES = -DHASXDMAUTH
XDMAUTHOBJS = xdmauth.o
XDMAUTHSRCS = xdmauth.c
#endif

#if HasSecureRPC
RPC_DEFINES = -DSECURE_RPC
RPCOBJS = rpcauth.o
RPCSRCS = rpcauth.c
RPCLIB = -lrpcsvc
#endif

#if HasKrbIV
#if NOAFS
KRBIV_DEFINES = KrbIVDefines -DNO_AFS
#else
KRBIV_DEFINES = KrbIVDefines
#endif
KRBIV_INCLUDES = KrbIVIncludes
KRBIVLIB = KrbIVLibraries
#endif

#if HasKrb5
KRB5_DEFINES = Krb5Defines
KRB5_INCLUDE = Krb5Includes
KRB5OBJS = krb5auth.o
KRB5SRCS = krb5auth.c
#endif

/* This is correct for Linux and FreeBSD */
#if HasPam
PAM_LIBRARIES = PamLibraries
PAM_DEFINES = -DUSE_PAM
#endif

#if HasPam
#undef HasShadowPasswd
#define HasShadowPasswd NO
#undef HasLibCrypt
#define HasLibCrypt NO
#endif

/*
#if HasBSDAuth
BSDAUTH_DEFINES = -DUSE_BSDAUTH
#endif
*/

#if SystemV4 || HasShadowPasswd

#if !LinuxShadowSuite
PWD_DEFINES = -DUSESHADOW
#else
PWD_DEFINES = -DUSESHADOW -DSHADOWSUITE
#endif

#if !defined(i386IscArchitecture) && !defined(i386ScoArchitecture) && !defined(LinuxArchitecture) && !defined(NTOArchitecture) && !defined(SGIArchitecture)
SYS_LIBRARIES3 = -lresolv
#endif
#if SystemV || defined(SequentArchitecture)
SYS_LIBRARIES1 = -lsec
#endif
#if defined(LinuxArchitecture) && (!UseElfFormat || LinuxShadowSuite)
SYS_LIBRARIES1 = -lshadow
#endif

#endif

#if defined(UltrixArchitecture)
SYS_LIBRARIES1 = -lauth
#endif

#if (defined(AIXArchitecture) && (OSMajorVersion >= 3))
SYS_LIBRARIES1 = -ls
#endif

#if HasLibCrypt
#ifdef SpecialLibCrypt
CRYPT_LIBRARIES = SpecialLibCrypt
#else
CRYPT_LIBRARIES = -lcrypt
#if defined(LynxOSArchitecture)
CRYPT_DEFINES = -DHAS_CRYPT
#endif
#endif
#endif

#if HasBSD44Sockets
SOCK_DEFINES = -DBSD44SOCKETS
#endif

#if defined(i386Architecture) || defined(AmigaArchitecture)
FRAGILE_DEFINES = -DFRAGILE_DEV_MEM
#endif

#ifdef RandomDefines
RANDOM_DEFINES = RandomDefines
#elif defined(OpenBSDArchitecture)
RANDOM_DEFINES = -DARC4_RANDOM
#elif defined(LinuxArchitecture)
RANDOM_DEFINES = -DDEV_RANDOM=\"/dev/urandom\"
#elif defined(NetBSDArchitecture) && \
  ((OSMajorVersion > 1) || \
   (OSMajorVersion == 1 && OSMinorVersion > 3))
RANDOM_DEFINES = -DDEV_RANDOM=\"/dev/urandom\"
#endif


#if HasSetUserContext
USER_CONTEXT_DEFINES = -DHAS_SETUSERCONTEXT
# XXX - only FreeBSD has this in libutil
SYS_LIBRARIES1 = -lutil
#endif

#if HasSetProcTitle
PROCTITLE_DEFINES = -DHAS_SETPROCTITLE
#endif

  SYS_LIBRARIES = $(SYS_LIBRARIES1) $(SYS_LIBRARIES2) $(SYS_LIBRARIES3)

  INCLUDES = $(KRB5_INCLUDE)
   DEPLIBS = $(DEPXLIB) $(DEPXAUTHLIB) $(DEPXDMCPLIB)
   LOCAL_LIBRARIES = $(XLIB) $(XAUTHLIB) \
 $(XDMCPLIB) $(RPCLIB) $(PAM_LIBRARIES) \
 $(CRYPT_LIBRARIES) $(KRBIVLIB)

      COMMSRCS = auth.c daemon.c server.c dpylist.c dm.c error.c \
		 netaddr.c reset.c resource.c protodpy.c policy.c \
		 session.c socket.c streams.c util.c xdmcp.c \
		 process.c mitauth.c \
		 genauth.c access.c choose.c \
		 $(XDMAUTHSRCS) $(RPCSRCS) $(KRB5SRCS)
      COMMOBJS = auth.o daemon.o server.o dpylist.o dm.o error.o \
		 netaddr.o reset.o resource.o protodpy.o policy.o \
		 session.o socket.o streams.o util.o xdmcp.o \
		 process.o mitauth.o \
		 genauth.o access.o choose.o \
		 $(XDMAUTHOBJS) $(RPCOBJS) $(KRB5OBJS)

         SRCS1 = $(COMMSRCS) client.c
         OBJS1 = $(COMMOBJS) client.o

#if BuildBoth
         SRCS2 = $(COMMSRCS) clientsh.c
         OBJS2 = $(COMMOBJS) clientsh.o

    XDM_SHADOW = xdm-shadow
#endif

       PROGRAMS = xdm $(XDM_SHADOW)


 OSMAJORVERSION = OSMajorVersion
 OSMINORVERSION = OSMinorVersion
   CONN_DEFINES = $(CONNECTION_FLAGS)
        DEFINES = $(SIGNAL_DEFINES) $(LOG_DEFINES) \
  $(CRYPT_DEFINES)$(PWD_DEFINES)  \
  $(BSDAUTH_DEFINES) $(PAM_DEFINES) $(USER_CONTEXT_DEFINES) \
  $(XDMAUTH_DEFINES) $(RPC_DEFINES) $(KRB5_DEFINES) \
  $(XDMCP_DEFINES) $(SOCK_DEFINES) $(CONN_DEFINES) \
  $(FRAGILE_DEFINES) $(RANDOM_DEFINES) $(PROCTITLE_DEFINES) \
  -DOSMAJORVERSION=$(OSMAJORVERSION) -DOSMINORVERSION=$(OSMINORVERSION) \
  -Dconst=

ComplexProgramTarget_1(xdm,$(LOCAL_LIBRARIES),NullParameter)
#if BuildBoth
NormalProgramTarget(xdm-shadow,$(OBJS2),$(DEPLIBS),$(LOCAL_LIBRARIES),-lshadow)
InstallProgram(xdm-shadow,$(BINDIR))
ObjectFromSpecialSource(clientsh,client,-DUSESHADOW)
#endif

#if defined(FreeBSDArchitecture) && (OSMajorVersion < 2)
XCOMM only for daemon.c? it's used in some other places, too.
SpecialCObjectRule(daemon,$(ICONFIGFILES),-UCSRG_BASED)
#endif

