###########################################################################
# Makefile for Samba SMB client/server for unix
# Copyright Andrew Tridgell 1992,1993,1994
###########################################################################

# The base manpages directory to put the man pages in
# Note: $(MANDIR)/man1, $(MANDIR)/man5 and $(MANDIR)/man8 must exist.
MANDIR = /usr/local/man

# The directories to put things in. If you use multiple
# architectures or share the samba binaries across NFS then
# you will probably want to change this layout.
BASEDIR = /usr/local/samba
BINDIR = $(BASEDIR)/bin
LIBDIR = $(BASEDIR)/lib
VARDIR = $(BASEDIR)/var

# WARNING: If you are upgrading, make sure you put all the files
# in the right spot! The default positions have changed!


# The permissions to give the executables
INSTALLPERMS = 0755

# Add any optimisation or debugging flags here
FLAGS1 = -O
LIBS1 = 

# You will need to use a ANSI C compiler. This means under SunOS 4 you can't 
# use cc, instead you will have to use gcc. 
# CC = gcc

# This may help with some versions of make
SHELL = /bin/sh


# 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))
LOGFILE = $(VARDIR)/log
CONFIGFILE = $(LIBDIR)/smb.conf
LMHOSTSFILE = $(LIBDIR)/lmhosts

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

# set this to the default group you want your machine to appear in
# for browsing. This can also be set in nmbd (see nmbd(8))
# Note that this workgroup must exist!
WORKGROUP = LANGROUP

# set this to the name of the default account, which is the one
# to use when no username or password is specified.  This can be overridden
# in the runtime configuration file (see smb.conf(5))
# NOTE: The account "nobody" may not be a good one as
# on many unixes it may not be able to print. Thus you
# might have to create a separate guest account that can print.
GUESTACCOUNT = nobody

# 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!
SMBRUN = $(BINDIR)/smbrun

# This is for AFS authentication.  If you use AFS then set AFS_BASE 
# according to your system layout, and uncomment the other lines as well.
# AFS_BASE = /usr/afsws
# AFS_FLAGS = -DAFS_AUTH -I$(AFS_BASE)/include
# AFS_LIBDIR = $(AFS_BASE)/lib
# AFS_LIBS = -L$(AFS_LIBDIR) -L$(AFS_LIBDIR)/afs -lkauth -lprot -lubik \
#                -lauth -lrxkad -lsys -ldes -lrx -llwp -lcom_err -laudit \
#                $(AFS_LIBDIR)/afs/util.a


#####################################
# WHICH OPERATING SYSTEM?
# UNCOMMENT ONE OF THE SECTIONS BELOW
# MAKE SURE ONLY *ONE* IS UNCOMMENTED
#
# The following are additional flags that may apply
#   -DNETGROUP if your machine supports yp netgroups
#   -DSHADOW_PWD if you are using shadow passwords
#   -DGETPWANAM if you wish to use getpwanam() call
#   -DPWDAUTH if you have and want to use the pwdauth() call
#   -DUFC_CRYPT if you want the fast crypt routine
#   -DALLOW_CHANGE_PASSWORD if you want users to be able to set their password
#                           remotely (only works on some systems)
#   -DQUOTAS for quota support in disk_free(). This probably only works 
#            on some systems.
#                            
#    NOTE: GETPWANAM & PWDAUTH are mutually exclusive, if you
#          Define one, you should NOT define the other.
#####################################


# This is for SUNOS 4. Use the SOLARIS entry for SunOS 5.
# Note that you cannot use Suns "cc" compiler
# as it's not an Ansi-C compiler. Get gcc or acc. 
# Note that if you have adjunct passwords you may need the GETPWANAM 
# or PWDAUTH option. There have been reports that using PWDAUTH may crash
# your pwdauthd server so GETPWANAM is preferable (and probably faster)
# contributed by Andrew.Tridgell@anu.edu.au
# FLAGSM = -DSUN
# LIBSM =   


# Use this for Linux with shadow passwords
# contributed by Andrew.Tridgell@anu.edu.au
# FLAGSM = -DLINUX -DSHADOW_PWD
# LIBSM = -lshadow

# Use this for Linux without shadow passwords
# contributed by Andrew.Tridgell@anu.edu.au
# FLAGSM = -DLINUX
# LIBSM = 


# This is for SOLARIS 2.2 and above (aka SunOS 5)
# contributed by Andrew.Tridgell@anu.edu.au
# FLAGSM = -DSOLARIS -DSHADOW_PWD -DNETGROUP -DBSD_COMP
# LIBSM = -lsocket -lnsl


# This is for SVR4
# Contributed by mark@scot1.ucsalf.ac.uk
# FLAGSM = -DSVR4 -DSHADOW_PWD
# LIBSM = -lsocket -lnsl -lc -L/usr/ucblib -lucb


# This is for ULTRIX. Add -DULTRIX_AUTH for Ultrix enhanced security.
# contributed by iversen@dsfys1.fi.uib.no
# FLAGSM = -DULTRIX -DUSE_DIRECT
# LIBSM =   


# This is for OSF1 (Alpha)
# contributed by errath@balu.kfunigraz.ac.at
# FLAGSM = -DOSF1
# LIBSM =

# This is for OSF1 (Alpha) with NIS and Fast Crypt
# contributed by David Gardiner <dgardine@cssip.edu.au>
# FLAGSM = -DOSF1 -DNETGROUP -DUFC_CRYPT
# LIBSM =


# This is for OSF1 (Alpha) V2.0 Enhanced Security 
# contributed by Udo Linauer <ul@eacpc4.tuwien.ac.at>
# FLAGSM = -DOSF1 -DOSF1_ENH_SEC
# LIBSM = -lsecurity


# This is for AIX
# contributed by tomc@osi.curtin.edu.au
# FLAGSM = -DAIX
# LIBSM =   


# This is for BSDI 
# contributed by tomh@metrics.com
# FLAGSM = -DBSDI -DUSE_DIRECT
# LIBSM =   


# This is for NetBSD. Add -DNETBSD_1_0 if you are using 1.0
# contributed by noses@oink.rhein.de
# FLAGSM = -DNETBSD -DUSE_DIRECT -DSHADOW_PWD
# LIBSM = -lcrypt 


# This is for SEQUENT. 
# Contributed by fwk@ix.netcom.com (Frank Keeney) and 
# rpwillia@Pentagon-EMH6.army.mil (Ray Williams)
# tested on DYNIX/ptx(R) V2.1.0
# FLAGSM = -DSEQUENT -DUSE_DIRECT -DSHADOW_PWD -DHAVE_TIMEZONE
# LIBSM = -lrpc -lsocket -lPW -leli -linet -lnsl -lseq -lsec


# This is for HP-UX. Note that some systems don't like the -Aa switch.
# contributed by Pasi.Kaara@atk.tpo.fi
# FLAGSM = -DHPUX -Aa -D_HPUX_SOURCE -D_POSIX_SOURCE
# LIBSM = 


# This is for SGI.
# contributed by lpc@solomon.technet.sg (Michael Chua)
# FOR SGI IRIX 4.x.x, use the following line
# FLAGSM = -DSGI -DUSE_DIRECT -DHAVE_TIMEZONE
# LIBSM =

# FOR SGI IRIX 5.x.x, use this line instead
# FLAGSM = -DSGI -DSHADOW_PWD -DUSE_DIRECT -DHAVE_TIMEZONE
# LIBSM =


# This is for FreeBSD
# contributed by kuku@acds.physik.rwth-aachen.de
# FLAGSM = -DFreeBSD -DUSE_DIRECT
# LIBSM = -lcrypt 


# This is for NeXT. Note that versions of NeXT less than 3.2 
# don't properly support posix, so they may present problems
# contributed by lendecke@namu01.gwdg.de
# FLAGSM = -DNEXT -posix
# LIBSM = 

# This is for NeXT OS 2.x
# No Posix, use 'cc' for C compiler (CC above).
# contributed by brad@cac.washington.edu (Brad Greer)
# FLAGSM = -DNEXT2 
# LIBSM = 

# This is for NeXT OS 3.0
# No Posix, use 'cc' for C compiler (CC above).
# contributed by brad@cac.washington.edu (Brad Greer)
# FLAGSM = -DNEXT3_0
# LIBSM = 


# NOTE: ISC is also known as "INTERACTIVE"
# This is for Sunsoft ISC SVR3V4 running in POSIX mode
# contributed by pim@cti-software.nl (Pim Zandbergen)
# FLAGSM = -posix -D_SYSV3 -DISC -DSHADOW_PWD
# LIBSM = -lsec -lcrypt -linet

# This is for Sunsoft ISC SVR3V4 running in iBCS2 mode
# contributed by pim@cti-software.nl (Pim Zandbergen)
# FLAGSM = -D_POSIX_SOURCE -D_XOPEN_SOURCE -D_SYSV3\
#          -DISC -DSHADOW_PWD -DREPLACE_GETWD -DREPLACE_RENAME
# LIBSM = -lsec -lcrypt -linet -lcposix


# This is for A/UX 3.0
# Contributed by root@dolphin.csudh.edu (Jon S. Stevens)
# FLAGSM = -DAUX
# LIBSM =


#Note: The SCO entries require the libcrypt library. You can get it via
#anonymous ftp from ftp.sco.com:/SLS/lng225b.* or ftp.uu.net:/vendors/sco
#
# Use this for SCO with shadow passwords. Tested on "Open enterprise 3.0"
# SCO changes from Heinz Mauelshagen (mauelsha@ez.da.telekom.de)
# FLAGSM = -DSCO -DSHADOW_PWD -DNETGROUP
# LIBSM = -lyp -lrpc -lyp -lsec -lsocket -lcrypt_i -lintl

# Use this for SCO with shadow passwords, without YP.
# Tested on "Open Enterprise Server 3.0" (John Owens john@micros.com)
# Also, use "CC = cc" above.
# FLAGSM = -DSCO -DSHADOW_PWD
# LIBSM = -lsec -lsocket -lcrypt_i

# Use this for SCO with TCB passwords (default).
# Tested on "Open enterprise 3.0". Contributed by lance@fox.com.
# CC     = cc
# FLAGSM = -DSCO -DSecureWare
# LIBSM  = -lprot_s -lcrypt -lsocket -lm -lc_s

# Use this for SCO Unix 3.2v2 (ODT 1.1) with TCB passwords (default).
# Contributed by Stephen.Rothwell@pd.necisa.oz.au
# N.B. this needs gcc
# FLAGSM = -DSCO -DSecureWare -DSCO3_2_2
# LIBSM  = -lprot -lcrypt_i -lsocket -lm -lintl

# This is for intergraph. 
# contributed by cjkiick@flinx.b11.ingr.com
# FLAGSM = -DCLIX
# LIBSM = -lbsd

# This is for DGUX. 
# Contributed by ross@augie.insci.com (Ross Andrus)
# FLAGSM = -DDGUX 
# LIBSM  = 

# This is for Apollo Domain/OS sr10.3 (systype = BSD4.3)
# Added 1994-07-08 Stephen C. Steel <steve@qv3donald.LeidenUniv.nl>
# additional patches by jmi@csd.cri.dk (John Mills)
# you may need the "-A ansi" switch to cc
# FLAGSM = -DAPOLLO -D_INCLUDE_BSD_SOURCE -D_INCLUDE_XOPEN_SOURCE
# LIBSM =


######################################################################
# DON'T EDIT BELOW THIS LINE
######################################################################

CFLAGS = $(FLAGS1) -DLOGFILE=\"$(LOGFILE)\" -DCONFIGFILE=\"$(CONFIGFILE)\" -DLMHOSTSFILE=\"$(LMHOSTSFILE)\" -DLOCKDIR=\"$(LOCKDIR)\" -DSMBRUN=\"$(SMBRUN)\" -DWORKGROUP=\"$(WORKGROUP)\" -DGUEST_ACCOUNT=\"$(GUESTACCOUNT)\" $(FLAGSM) $(AFS_FLAGS)
LIBS = $(LIBS1) $(LIBSM)

PROGS = smbd smbclient nmbd testparm testprns smbrun smbstatus

all : CHECK $(PROGS)

CHECK :
	@if [ "$(FLAGSM)" = "" ];  then \
		echo "You forgot to uncomment an OS type in the Makefile"; \
		exit 1; \
	fi; exit 0;

INCLUDES1 = version.h local.h includes.h smb.h loadparm.h params.h 
INCLUDES2 = pcap.h trans2.h reply.h
INCLUDES = $(INCLUDES1) $(INCLUDES2)

SMBDOBJ1 = server.o util.o loadparm.o params.o access.o pcap.o trans2.o 
SMBDOBJ2 = password.o ufc.o kanji.o ipc.o reply.o mangle.o chgpasswd.o 
SMBDOBJ3 = message.o
SMBDOBJ = $(SMBDOBJ1) $(SMBDOBJ2) $(SMBDOBJ3) 

smbd: $(SMBDOBJ)
	$(CC) $(CFLAGS) -o smbd $(SMBDOBJ) $(LIBS) $(AFS_LIBS)

smbrun: smbrun.o
	$(CC) $(CFLAGS) -o smbrun smbrun.o $(LIBS)

nmbd: nameserv.o util.o
	$(CC) $(CFLAGS) -o nmbd nameserv.o util.o kanji.o $(LIBS)

smbclient: client.o util.o kanji.o
	$(CC) $(CFLAGS) -o smbclient client.o util.o kanji.o $(LIBS)

smbstatus: status.o util.o kanji.o
	$(CC) $(CFLAGS) -o smbstatus status.o util.o kanji.o $(LIBS)

testparm: testparm.o util.o loadparm.o params.o access.o pcap.o kanji.o
	$(CC) $(CFLAGS) -o testparm testparm.o util.o loadparm.o params.o \
                        access.o pcap.o kanji.o $(LIBS)

testprns: testprns.o loadparm.o params.o util.o pcap.o
	$(CC) $(CFLAGS) -o testprns testprns.o loadparm.o params.o util.o \
                        pcap.o kanji.o $(LIBS)

install: installbin installman

installbin: all
	@echo
	@echo "IGNORE ANY \"File exists\" MESSAGES FROM THIS COMMAND"
	-mkdir $(BINDIR)
	-mkdir $(LIBDIR)
	-mkdir $(VARDIR)
	@echo
	@echo "IGNORE ANY \"No such file\" MESSAGES FROM THESE COMMANDS"
	-for i in $(PROGS); do \
		mv $(BINDIR)/$$i $(BINDIR)/$$i.old ; \
	done
	@echo
	@echo "INSTALLING IN "$(BINDIR)
	for i in $(PROGS); do \
		cp $$i $(BINDIR)/$$i ; \
		chmod $(INSTALLPERMS) $(BINDIR)/$$i ; \
	done
	@echo
	@echo "NOTE: You may still need to install your smb.conf"
	@echo
	@echo "INSTALLATION COMPLETE. TO REVERT TO THE PREVIOUS VERSION"
	@echo "USE \"make revert\""

# revert to the previously installed version
revert:
	@echo 
	@echo "REVERTING TO PREVIOUS VERSION"
	for i in $(PROGS); do \
		mv $(BINDIR)/$$i $(BINDIR)/$$i.new ; \
		mv $(BINDIR)/$$i.old $(BINDIR)/$$i ; \
		rm -f $(BINDIR)/$$i.new ; \
	done


installman:
	@echo
	@echo "INSTALLING MANUAL PAGES"
	cp *.1 $(MANDIR)/man1
	cp *.5 $(MANDIR)/man5
	cp *.8 $(MANDIR)/man8
	chmod u=rw,go=r $(MANDIR)/man1/smbstatus.1
	chmod u=rw,go=r $(MANDIR)/man1/smbclient.1
	chmod u=rw,go=r $(MANDIR)/man1/smbrun.1
	chmod u=rw,go=r $(MANDIR)/man1/testparm.1
	chmod u=rw,go=r $(MANDIR)/man1/testprns.1
	chmod u=rw,go=r $(MANDIR)/man5/smb.conf.5
	chmod u=rw,go=r $(MANDIR)/man8/smbd.8
	chmod u=rw,go=r $(MANDIR)/man8/nmbd.8
	
source:
	tar cfv sources.tar COPYING README THANKS \
                            Makefile announce bugs change-log \
                            history smb.conf.sample \
                            *.txt *.c *.h *.[158]

.c.o: $(INCLUDES)
	$(CC) $(CFLAGS) -c $*.c

clean:
	rm -f core *.o *~ smbd smbrun smbclient nmbd testparm testprns smbstatus

