###########################################################################
# Makefile.in for Samba - rewritten for autoconf support
# Copyright Andrew Tridgell 1992-1998
###########################################################################

prefix=@prefix@
exec_prefix=@exec_prefix@
mandir=@mandir@
INSTALL_BIN=$(exec_prefix)/bin
INSTALL_MAN=$(prefix)/man

LIBS=@LIBS@
CC=@CC@
CFLAGS=@CFLAGS@
AWK=@AWK@

INSTALLCMD=@INSTALL@

VPATH=@srcdir@
srcdir=@srcdir@
SHELL=/bin/sh

.SUFFIXES:
.SUFFIXES: .c .o

BASEDIR=$(prefix)/samba
BINDIR = $(BASEDIR)/bin
SBINDIR = $(BASEDIR)/bin
LIBDIR = $(BASEDIR)/lib
VARDIR = $(BASEDIR)/var
MANDIR = $(BASEDIR)/man

# The permissions to give the executables
INSTALLPERMS = 0755

# set these to where to find various files
# These can be overridden by command line switches (see smbd(8))
# or in smb.conf (see smb.conf(5))
SMBLOGFILE = $(VARDIR)/log.smb
NMBLOGFILE = $(VARDIR)/log.nmb
CONFIGFILE = $(LIBDIR)/smb.conf
LMHOSTSFILE = $(LIBDIR)/lmhosts
DRIVERFILE = $(LIBDIR)/printers.def
SMB_PASSWD = $(BINDIR)/smbpasswd
SMB_PASSWD_FILE = $(BASEDIR)/private/smbpasswd

# This is where SWAT images and help files go
SWATDIR = $(BASEDIR)/swat

# the directory where lock files go
LOCKDIR = $(VARDIR)/locks

# The directory where code page definition files go
CODEPAGEDIR = $(LIBDIR)/codepages

# The current codepage definition list.
CODEPAGELIST= 437 737 850 852 861 932 866 949 950 936

# where you are going to have the smbrun binary. This defaults to the 
# install directory. This binary is needed for correct printing
# and magic script execution. This should be an absolute path!
# Also not that this should include the name "smbrun" on the end (the
# name of the executable)
SMBRUN = $(BINDIR)/smbrun


PASSWD_FLAGS = -DSMB_PASSWD=\"$(SMB_PASSWD)\" -DSMB_PASSWD_FILE=\"$(SMB_PASSWD_FILE)\"
FLAGS1 = $(CFLAGS) -I$(srcdir)/include -I$(srcdir)/ubiqx -DSMBLOGFILE=\"$(SMBLOGFILE)\" -DNMBLOGFILE=\"$(NMBLOGFILE)\"
FLAGS2 = -DCONFIGFILE=\"$(CONFIGFILE)\" -DLMHOSTSFILE=\"$(LMHOSTSFILE)\"  
FLAGS3 = -DSWATDIR=\"$(SWATDIR)\" -DSBINDIR=\"$(SBINDIR)\" -DLOCKDIR=\"$(LOCKDIR)\" -DSMBRUN=\"$(SMBRUN)\" -DCODEPAGEDIR=\"$(CODEPAGEDIR)\"
FLAGS4 = -DDRIVERFILE=\"$(DRIVERFILE)\"
FLAGS5 = $(FLAGS1) $(FLAGS2) $(FLAGS3) $(FLAGS4) -DHAVE_INCLUDES_H
FLAGS  = $(FLAGS5) $(PASSWD_FLAGS)

SPROGS = bin/smbd bin/nmbd bin/swat
PROGS1 = bin/smbclient bin/testparm bin/testprns bin/smbrun bin/smbstatus 
PROGS2 = bin/smbpasswd bin/make_smbcodepage
PROGS = $(PROGS1) $(PROGS2) bin/nmblookup bin/make_printerdef 

SCRIPTS = script/smbtar script/addtosmbpass


######################################################################
# object file lists
######################################################################

LIB_OBJ = lib/charcnv.o lib/charset.o lib/debug.o lib/fault.o \
          lib/getsmbpass.o lib/interface.o lib/kanji.o lib/md4.o \
          lib/membuffer.o lib/netmask.o lib/pidfile.o lib/replace.o \
          lib/signal.o lib/slprintf.o lib/system.o lib/time.o lib/ufc.o \
          lib/util.o lib/genrand.o lib/username.o lib/access.o lib/smbrun.o \
	  lib/bitmap.o

UBIQX_OBJ = ubiqx/ubi_BinTree.o ubiqx/ubi_Cache.o ubiqx/ubi_SplayTree.o \
            ubiqx/ubi_dLinkList.o ubiqx/ubi_sLinkList.o

PARAM_OBJ = param/loadparm.o param/params.o 

LIBSMB_OBJ = libsmb/clientgen.o libsmb/namequery.o libsmb/nmblib.o \
             libsmb/nterr.o libsmb/smbdes.o libsmb/smbencrypt.o \
             libsmb/smberr.o libsmb/credentials.o 

RPC_SERVER_OBJ = rpc_server/srv_ldap_helpers.o rpc_server/srv_lsa.o \
                 rpc_server/srv_lsa_hnd.o rpc_server/srv_netlog.o \
                 rpc_server/srv_pipe_hnd.o rpc_server/srv_reg.o \
                 rpc_server/srv_samr.o rpc_server/srv_srvsvc.o \
                 rpc_server/srv_util.o rpc_server/srv_wkssvc.o

RPC_PARSE_OBJ = rpc_parse/parse_lsa.o rpc_parse/parse_misc.o \
                rpc_parse/parse_net.o rpc_parse/parse_prs.o \
                rpc_parse/parse_reg.o rpc_parse/parse_rpc.o \
                rpc_parse/parse_samr.o rpc_parse/parse_srv.o \
                rpc_parse/parse_wks.o

RPC_CLIENT_OBJ = rpc_client/cli_login.o rpc_client/cli_netlogon.o \
                 rpc_client/cli_pipe.o 

LOCKING_OBJ = locking/locking.o locking/locking_shm.o locking/locking_slow.o \
              locking/shmem.o locking/shmem_sysv.o

PASSDB_OBJ = passdb/passdb.o passdb/smbpassfile.o passdb/smbpass.o \
             passdb/pass_check.o passdb/ldap.o passdb/nispass.o 

SMBD_OBJ1 = smbd/server.o smbd/files.o smbd/chgpasswd.o smbd/connection.o \
            smbd/dfree.o smbd/dir.o smbd/password.o smbd/conn.o smbd/fileio.o \
            smbd/groupname.o smbd/ipc.o smbd/mangle.o smbd/negprot.o \
            smbd/message.o smbd/nttrans.o smbd/pipes.o smbd/predict.o \
            smbd/quotas.o smbd/reply.o smbd/ssl.o smbd/trans2.o smbd/uid.o \
	    smbd/dosmode.o smbd/filename.o smbd/open.o smbd/close.o \
	    smbd/process.o smbd/oplock.o smbd/service.o smbd/error.o

PRINTING_OBJ = printing/pcap.o printing/print_svid.o printing/printing.o

SMBD_OBJ = $(SMBD_OBJ1) $(PARAM_OBJ) $(LIBSMB_OBJ) $(UBIQX_OBJ) \
           $(RPC_SERVER_OBJ) $(RPC_CLIENT_OBJ) $(RPC_PARSE_OBJ) \
           $(LOCKING_OBJ) $(PASSDB_OBJ) $(PRINTING_OBJ) $(LIB_OBJ)


NMBD_OBJ1 = nmbd/asyncdns.o nmbd/nmbd.o nmbd/nmbd_become_dmb.o \
            nmbd/nmbd_become_lmb.o nmbd/nmbd_browserdb.o \
            nmbd/nmbd_browsesync.o nmbd/nmbd_elections.o \
            nmbd/nmbd_incomingdgrams.o nmbd/nmbd_incomingrequests.o \
            nmbd/nmbd_lmhosts.o nmbd/nmbd_logonnames.o nmbd/nmbd_mynames.o \
            nmbd/nmbd_namelistdb.o nmbd/nmbd_namequery.o \
            nmbd/nmbd_nameregister.o nmbd/nmbd_namerelease.o \
            nmbd/nmbd_nodestatus.o nmbd/nmbd_packets.o \
            nmbd/nmbd_processlogon.o nmbd/nmbd_responserecordsdb.o \
            nmbd/nmbd_sendannounce.o nmbd/nmbd_serverlistdb.o \
            nmbd/nmbd_subnetdb.o nmbd/nmbd_winsproxy.o nmbd/nmbd_winsserver.o \
            nmbd/nmbd_workgroupdb.o

NMBD_OBJ = $(NMBD_OBJ1) $(PARAM_OBJ) $(LIBSMB_OBJ) $(UBIQX_OBJ) \
           $(PASSDB_OBJ) $(LIB_OBJ)

SWAT_OBJ = web/cgi.o web/diagnose.o web/startstop.o web/statuspage.o \
           web/swat.o $(LIBSMB_OBJ) $(LOCKING_OBJ) \
           $(PARAM_OBJ) $(PASSDB_OBJ) $(RPC_CLIENT_OBJ) $(RPC_PARSE_OBJ) \
           $(UBIQX_OBJ) $(LIB_OBJ)

SMBRUN_OBJ = utils/smbrun.o

MAKE_SMBCODEPAGE_OBJ = utils/make_smbcodepage.o $(PARAM_OBJ) \
                       $(UBIQX_OBJ) $(LIB_OBJ)

MAKE_PRINTERDEF_OBJ = utils/make_printerdef.o $(PARAM_OBJ) \
                      $(UBIQX_OBJ) $(LIB_OBJ)

STATUS_OBJ = utils/status.o $(LOCKING_OBJ) $(PARAM_OBJ) \
             $(UBIQX_OBJ) $(LIB_OBJ)

TESTPARM_OBJ = utils/testparm.o \
               $(PARAM_OBJ) $(UBIQX_OBJ) $(LIB_OBJ)

TESTPRNS_OBJ = utils/testprns.o $(PARAM_OBJ) $(PRINTING_OBJ) $(UBIQX_OBJ) \
               $(LIB_OBJ)

SMBPASSWD_OBJ = utils/smbpasswd.o $(PARAM_OBJ) $(LIBSMB_OBJ) $(PASSDB_OBJ) \
                $(UBIQX_OBJ) $(RPC_CLIENT_OBJ) $(RPC_PARSE_OBJ) $(LIB_OBJ)

CLIENT_OBJ = client/client.o client/clientutil.o client/clitar.o \
             $(PARAM_OBJ) $(LIBSMB_OBJ) $(UBIQX_OBJ) $(LIB_OBJ)

NMBLOOKUP_OBJ = utils/nmblookup.o $(PARAM_OBJ) $(UBIQX_OBJ) \
                $(LIBSMB_OBJ) $(LIB_OBJ)

SMBTORTURE_OBJ = utils/torture.o $(LIBSMB_OBJ) $(PARAM_OBJ) \
                 $(UBIQX_OBJ) $(LIB_OBJ)

PROTO_OBJ = $(SMBD_OBJ) $(NMBD_OBJ) $(SWAT_OBJ) $(CLIENT_OBJ)

######################################################################
# now the rules...
######################################################################

all : CHECK $(SPROGS) $(PROGS) 

.SUFFIXES:
.SUFFIXES: .c .o .h

CHECK:
	@echo "Using FLAGS = $(FLAGS)"
	@echo "Using LIBS = $(LIBS)"

.c.o: $(INCLUDES)
	@echo Compiling $*.c
	@$(CC) -I. -I$(srcdir) $(FLAGS) -c $< -o $@

bin/smbd: $(SMBD_OBJ) 
	@echo Linking $@
	@$(CC) $(FLAGS) -o $@ $(SMBD_OBJ) $(LIBS) 

bin/nmbd: $(NMBD_OBJ)
	@echo Linking $@
	@$(CC) $(FLAGS) -o $@ $(NMBD_OBJ) $(LIBS)

bin/swat: $(SWAT_OBJ)
	@echo Linking $@
	@$(CC) $(FLAGS) -o $@ $(SWAT_OBJ) $(LIBS) 

bin/smbrun: $(SMBRUN_OBJ)
	@echo Linking $@
	@$(CC) $(FLAGS) -o $@ $(SMBRUN_OBJ) $(LIBS)

bin/smbclient: $(CLIENT_OBJ) 
	@echo Linking $@
	@$(CC) $(FLAGS) -o $@ $(CLIENT_OBJ) $(LIBS)

bin/testparm: $(TESTPARM_OBJ)
	@echo Linking $@
	@$(CC) $(FLAGS) -o $@ $(TESTPARM_OBJ) $(LIBS)

bin/testprns: $(TESTPRNS_OBJ)
	@echo Linking $@
	@$(CC) $(FLAGS) -o $@ $(TESTPRNS_OBJ) $(LIBS)

bin/smbstatus: $(STATUS_OBJ)
	@echo Linking $@
	@$(CC) $(FLAGS) -o $@ $(STATUS_OBJ) $(LIBS)

bin/smbpasswd: $(SMBPASSWD_OBJ)
	@echo Linking $@
	@$(CC) $(FLAGS) -o $@ $(SMBPASSWD_OBJ) $(LIBS)

bin/make_smbcodepage: $(MAKE_SMBCODEPAGE_OBJ) 
	@echo Linking $@
	@$(CC) $(FLAGS) -o $@ $(MAKE_SMBCODEPAGE_OBJ) $(LIBS)

bin/nmblookup: $(NMBLOOKUP_OBJ)
	@echo Linking $@
	@$(CC) $(FLAGS) -o $@ $(NMBLOOKUP_OBJ) $(LIBS)

bin/make_printerdef: $(MAKE_PRINTERDEF_OBJ) 
	@echo Linking $@
	@$(CC) $(FLAGS) -o $@ $(MAKE_PRINTERDEF_OBJ) $(LIBS)

bin/smbtorture: $(SMBTORTURE_OBJ) 
	@echo Linking $@
	@$(CC) $(FLAGS) -o $@ $(SMBTORTURE_OBJ) $(LIBS)


install: installbin installman installscripts installcp installswat

installbin: all
	@$(SHELL) $(srcdir)/script/installbin.sh $(INSTALLPERMS) $(BASEDIR) $(SBINDIR) $(LIBDIR) $(VARDIR) $(SPROGS)
	@$(SHELL) $(srcdir)/script/installbin.sh $(INSTALLPERMS) $(BASEDIR) $(BINDIR) $(LIBDIR) $(VARDIR) $(PROGS)

installscripts:
	@$(SHELL) $(srcdir)/script/installscripts.sh $(INSTALLPERMS) $(BINDIR) $(SCRIPTS)

installcp:
	@$(SHELL) $(srcdir)/script/installcp.sh $(LIBDIR) $(CODEPAGEDIR) $(BINDIR) $(CODEPAGELIST)

installswat:
	@$(SHELL) $(srcdir)/script/installswat.sh $(SWATDIR) $(srcdir)

# revert to the previously installed version
revert:
	@$(SHELL) $(srcdir)/script/revert.sh $(SBINDIR) $(SPROGS) 
	@$(SHELL) $(srcdir)/script/revert.sh $(BINDIR) $(PROGS) $(SCRIPTS)

installman:
	@$(SHELL) $(srcdir)/script/installman.sh $(MANDIR) $(srcdir)

uninstall: uninstallman uninstallbin uninstallscripts uninstallcp

uninstallman:
	@$(SHELL) $(srcdir)/script/uninstallman.sh $(MANDIR) $(srcdir)

uninstallbin:
	@$(SHELL) $(srcdir)/script/uninstallbin.sh $(INSTALLPERMS) $(BASEDIR) $(SBINDIR) $(LIBDIR) $(VARDIR) $(SPROGS)
	@$(SHELL) $(srcdir)/script/uninstallbin.sh $(INSTALLPERMS) $(BASEDIR) $(BINDIR) $(LIBDIR) $(VARDIR) $(PROGS)

uninstallscripts:
	@$(SHELL) $(srcdir)/script/uninstallscripts.sh $(INSTALLPERMS) $(BINDIR) $(SCRIPTS)

uninstallcp:
	@$(SHELL) $(srcdir)/script/uninstallcp.sh $(CODEPAGEDIR) $(CODEPAGELIST)

clean: 
	rm -f core */*.o */*~ *~ config.cache $(PROGS)

proto:
	@echo rebuilding include/proto.h
	@$(AWK) -f script/mkproto.awk `echo $(PROTO_OBJ) | tr ' ' '\n' | sed -e 's/\.o/\.c/g' | sort -u | grep -v "ubiqx/"` > include/proto.h

etags:
	etags `find . -name "*.[ch]"`

ctags:
	ctags `find . -name "*.[ch]"`

realclean: clean