#
# This makefile contains the make stuff for pam_smb v1.0
# Run configure to produce a Makefile
#
#

INCLUDES = -I./lib/include -I./lib/rpc/include -I./rpc_validate
EXTRALIBS = @LIBS@

LD_FLAGS = @LDFLAGS@
CC = @CC@
AWK = @AWK@

SHELL=/bin/sh

INSTALL= @INSTALL@
SCONFIGED = @SCONFIGED@

SHLIB_LD = @SHLIB_LD@

@SET_MAKE@

CFLAGS = @CFLAGS@ @DEFS@ @SHLIB_CFLAGS@ -DSCONFIGED=\"$(SCONFIGED)\" -DDEBUG_PASSWORD

CMD_OBJ = \
		rpc_validate/cmd_lsarpc.o 

CLI_OBJ = \
		lib/smb/clientgen.o

# client specific object code in the rpc directory
# don't include this one, yet: lib/rpc/ntclienttrust.o
RPC_CLI_OBJ  = \
		lib/rpc/client/cli_pipe.o \
		lib/rpc/client/cli_lsarpc.o \
		lib/rpc/client/cli_netlogon.o \
		lib/rpc/client/cli_login.o 


# shared client/server object files (parsing) in the rpc subdirectory
RPC_LIB_OBJ  = \
		lib/rpc/parse/parse_rpc.o  \
		lib/rpc/parse/parse_net.o  \
		lib/rpc/parse/parse_misc.o  \
		lib/rpc/parse/parse_lsa.o  \
		lib/rpc/parse/parse_prs.o 

# miscellaneous utility object files
UTIL_OBJ = \
		lib/util/membuffer.o \
		lib/util/smberr.o    \
		lib/util/genrand.o    \
		lib/util/util.o    \
		lib/util/smbpassfile.o    \
		lib/util/slprintf.o    \
		lib/util/system.o    \
		lib/util/debug.o    \
		lib/util/nmblib.o    \
		lib/util/util_pwdb.o    \
		lib/util/util_unistr.o    \
		lib/util/util_file.o    \
		lib/util/util_sock.o    \
		lib/util/util_sid.o    \
		lib/util/util_array.o    \
		lib/util/util_str.o    \
		lib/util/time.o    \
		lib/util/signal.o    \
		lib/util/ufc.o    \
		lib/util/credentials.o    \
		lib/util/md4.o    \
		lib/util/md5.o    \
		lib/util/hmacmd5.o    \
		lib/util/kanji.o    \
		lib/util/charcnv.o    \
		lib/util/crc32.o    \
		lib/util/arcfour.o    \
		lib/util/smbdes.o    \
		lib/util/smbencrypt.o    \
		lib/util/pwd_cache.o    \
		lib/util/nterr.o

OBJS = $(CMD_OBJ) $(UTIL_OBJ) $(CLI_OBJ) $(RPC_LIB_OBJ) $(RPC_CLI_OBJ) 

LIBAUTHSH = pam_ntdom_auth.so

LIBAUTHOBJ = rpc_validate.o pam_ntdom_auth.o pam_read_conf.o support.o
LIBAUTHSRC = rpc_validate.c pam_ntdom_auth.c pam_read_conf.c support.c

LIBOBJ = $(LIBAUTHOBJ) 
LIBSRC = $(LIBAUTHSRC)

LIBSHARED = $(LIBAUTHSH) 

LIBOBJD = $(addprefix dynamic/,$(LIBOBJ))
LIBOBJS = $(addprefix static/,$(LIBOBJ))

export CFLAGS CC

dynamic/%.o : %.c
	$(CC) $(CFLAGS) $(DYNAMIC) $(CPPFLAGS) $(INCLUDES) -c $< -o $@


########################### don't edit below #######################

dummy: all
info:
	@echo
	@echo "*** Building pam-ntdom(alpha) module of the framework..."
	@echo "Contact: lkcl@samba.org"
	@echo

all: dirs info $(LIBSHARED) 

dirs:
	mkdir -p ./dynamic

$(LIBOBJD): $(LIBSRC)

$(LIBAUTHSH):	$(LIBAUTHSRC) $(LIBOBJD) $(OBJS)
		$(SHLIB_LD) $(LD_FLAGS) -o $@ $(addprefix dynamic/,$(LIBAUTHOBJ)) $(OBJS) $(EXTRALIBS) $(INCLUDES)

smbcliproto:
	@echo rebuilding lib/include/smb_cli_proto.h
	@$(AWK) -f mkproto.awk `echo $(CLI_OBJ) | tr ' ' '\n' | sed -e 's/\.o/\.c/g' | sort -u ` > lib/include/smb_cli_proto.h

smbutiproto:
	@echo rebuilding lib/include/smb_uti_proto.h
	@$(AWK) -f mkproto.awk `echo $(UTIL_OBJ) | tr ' ' '\n' | sed -e 's/\.o/\.c/g' | sort -u ` > lib/include/smb_uti_proto.h

rpccliproto:
	@echo rebuilding lib/include/rpc_cli_proto.h
	@$(AWK) -f mkproto.awk `echo $(RPC_CLI_OBJ) | tr ' ' '\n' | sed -e 's/\.o/\.c/g' | sort -u ` > lib/include/rpc_cli_proto.h

ntdomproto:
	@echo rebuilding rpc_validate/ntdom_proto.h
	@$(AWK) -f mkproto.awk `echo $(CMD_OBJ) rpc_validate.o pam_read_conf.o | tr ' ' '\n' | sed -e 's/\.o/\.c/g' | sort -u ` > rpc_validate/ntdom_proto.h

rpclibproto:
	@echo rebuilding lib/include/rpc_lib_proto.h
	@$(AWK) -f mkproto.awk `echo $(RPC_LIB_OBJ) | tr ' ' '\n' | sed -e 's/\.o/\.c/g' | sort -u ` > lib/include/rpc_lib_proto.h

proto: smbcliproto smbutiproto rpccliproto rpclibproto ntdomproto

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

clean:
	set -e ; $(MAKE) -C lib clean
	set -e ; $(MAKE) -C rpc_validate clean
	rm -f $(LIBAUTHSH) $(LIBOBJD) $(LIBOBJS) a.out core *~

extraclean: clean
	rm -f *.a *.out *.o *.so *.bak config.log config.cache config.status config.h Makefile

.c.o:	
	$(CC) -c $(CFLAGS) $(INCLUDES) -o $@ $<
