# Copyright 2000, International Business Machines Corporation and others.
# All Rights Reserved.
# 
# This software has been released under the terms of the IBM Public
# License.  For details, see the LICENSE file in the top-level source
# directory or online at http://www.openafs.org/dl/license10.html

include ../../config/Makefile.config
#${SYS_NAME}

DEST=@DEST@
TOP_SRCDIR=@TOP_SRCDIR@
TOP_INCDIR=@TOP_INCDIR@
TOP_LIBDIR=@TOP_LIBDIR@
TOP_JLIBDIR=@TOP_SRCDIR@/JAVA/libjafs
JNI_INC=-I ${JAVA_HOME}/include -I `dirname ${JAVA_HOME}/include/*/jni_md.h`
prefix=@prefix@
exec_prefix=@exec_prefix@
datarootdir=@datarootdir@
bindir=@bindir@
sbindir=@sbindir@
libexecdir=@libexecdir@
libdir=@libdir@
includedir=@includedir@
mandir=@mandir@
afssrvbindir=@afssrvbindir@
afssrvsbindir=@afssrvsbindir@
afssrvlibexecdir=@afssrvlibexecdir@
COMPILE_ET=${TOP_SRCDIR}/comerr/compile_et
RXGEN=${TOP_SRCDIR}/rxgen/rxgen
SYS_NAME=@AFS_SYSNAME@


CC = ${MT_CC}
SHARED_FLAGS = -shared -Xlinker -Bsymbolic
OBJECT_FLAGS = -fPIC -c

ifeq "$(BUILD_TYPE)" "admin"
	INC := -I${TOP_SRCDIR}/config -I${TOP_INCDIR} -I${TOP_INCDIR}/afs/ ${JNI_INC}
	CFLAGS := ${INC} ${DBG} ${OPTMZ} -I${TOP_SRCDIR}/config ${MT_CFLAGS}
else
	INC := -I${TOP_SRCDIR}/config -I${TOP_SRCDIR}/libuafs -I${TOP_INCDIR} ${JNI_INC}
	CFLAGS := ${INC} ${DBG} ${OPTMZ} ${FSINCLUDES} -D_REENTRANT -DLIBJUAFS ${MT_CFLAGS}
endif


LIBJAFSADMDIR = ./
ROOTPACKAGEDIR = ../classes
RELPACKAGEDIR = org/openafs/jafs/
PACKAGEDIR = ${ROOTPACKAGEDIR}/${RELPACKAGEDIR}
JAVADOCSDIR = javadocs/

JAVAH = ${JAVA_HOME}/bin/javah -classpath ${ROOTPACKAGEDIR} -jni -d ${LIBJAFSADMDIR}
JAVAC = ${JAVA_HOME}/bin/javac -source 1.4 -classpath ${ROOTPACKAGEDIR}

J_NATIVE_PREFIX = org.openafs.jafs.
C_NATIVE_PREFIX = org_openafs_jafs_

PACKAGE =\
	${PACKAGEDIR}ACL.class \
	${PACKAGEDIR}AFSException.class \
	${PACKAGEDIR}AFSFileException.class \
	${PACKAGEDIR}AFSSecurityException.class \
	${PACKAGEDIR}Cell.class \
	${PACKAGEDIR}File.class \
	${PACKAGEDIR}FileInputStream.class \
	${PACKAGEDIR}FileOutputStream.class \
	${PACKAGEDIR}Group.class \
	${PACKAGEDIR}Key.class \
	${PACKAGEDIR}Partition.class \
	${PACKAGEDIR}Process.class \
	${PACKAGEDIR}Server.class \
	${PACKAGEDIR}Token.class \
	${PACKAGEDIR}User.class \
	${PACKAGEDIR}Volume.class \
	${PACKAGEDIR}VersionInfo.class

ifeq (${SYS_NAME}, ppc64_linux26)
LIBJAFS_OBJS =
else
ifeq (${SYS_NAME}, s390x_linux26)
LIBJAFS_OBJS =
else
LIBJAFS_OBJS =\
        ${LIBJAFSADMDIR}GetNativeString.o \
        ${LIBJAFSADMDIR}ACL.o
endif
endif

LIBJAFS_OBJS +=\
	${LIBJAFSADMDIR}File.o \
	${LIBJAFSADMDIR}FileInputStream.o \
	${LIBJAFSADMDIR}FileOutputStream.o \
	${LIBJAFSADMDIR}Internal.o \
	${LIBJAFSADMDIR}UserToken.o \
	${LIBJAFSADMDIR}VersionInfo.o \
	${TOP_SRCDIR}/libuafs/UAFS/xdr_int32.o

ifeq (${SYS_NAME}, ppc64_linux26)
LIBJAFSADM_OBJS =\
        ${LIBJAFSADMDIR}GetNativeString.o \
        ${LIBJAFSADMDIR}ACL.o
else
ifeq (${SYS_NAME}, s390x_linux26)
LIBJAFSADM_OBJS =\
        ${LIBJAFSADMDIR}GetNativeString.o \
        ${LIBJAFSADMDIR}ACL.o
else
LIBJAFSADM_OBJS =
endif
endif

LIBJAFSADM_OBJS +=\
	${LIBJAFSADMDIR}AdminToken.o \
	${LIBJAFSADMDIR}Cell.o \
	${LIBJAFSADMDIR}Group.o \
	${LIBJAFSADMDIR}Internal.o \
	${LIBJAFSADMDIR}Key.o \
	${LIBJAFSADMDIR}Partition.o \
	${LIBJAFSADMDIR}Process.o \
	${LIBJAFSADMDIR}Server.o \
	${LIBJAFSADMDIR}User.o \
	${LIBJAFSADMDIR}Version2.o \
	${LIBJAFSADMDIR}Volume.o

CORRELATING_SOURCE_FILES =\
	${LIBJAFSADMDIR}ACL.c \
	${LIBJAFSADMDIR}Cell.c \
	${LIBJAFSADMDIR}File.c \
	${LIBJAFSADMDIR}FileInputStream.c \
	${LIBJAFSADMDIR}FileOutputStream.c \
	${LIBJAFSADMDIR}Group.c \
	${LIBJAFSADMDIR}Key.c \
	${LIBJAFSADMDIR}Partition.c \
	${LIBJAFSADMDIR}Process.c \
	${LIBJAFSADMDIR}Server.c \
	${LIBJAFSADMDIR}User.c \
	${LIBJAFSADMDIR}Volume.c \
	${LIBJAFSADMDIR}VersionInfo.c


JAVA_HEADERS = ${PACKAGE:${PACKAGEDIR}%.class=${C_NATIVE_PREFIX}%.h}

BOSADMINLIB = ${TOP_LIBDIR}/libbosadmin.a
VOSADMINLIB = ${TOP_LIBDIR}/libvosadmin.a
PTSADMINLIB = ${TOP_LIBDIR}/libptsadmin.a
KASADMINLIB = ${TOP_LIBDIR}/libkasadmin.a
CFGADMINLIB = ${TOP_LIBDIR}/libcfgadmin.a
UTILADMINLIB = ${TOP_LIBDIR}/libafsadminutil.a
CLIENTADMINLIB = ${TOP_LIBDIR}/libclientadmin.a

LIBJAFS_LIBS =\
	${TOP_LIBDIR}/libuafs.a \
	${TOP_LIBDIR}/libafsutil.a \
	-lresolv \
	-lpthread

LIBJAFSADM_LIBS =\
	${CLIENTADMINLIB} \
	${VOSADMINLIB} \
	${BOSADMINLIB} \
	${PTSADMINLIB} \
	${KASADMINLIB} \
	${CFGADMINLIB} \
	${UTILADMINLIB} \
	${TOP_LIBDIR}/libafsauthent.a \
	${TOP_LIBDIR}/libafsrpc.a \
	${TOP_LIBDIR}/libcmd.a \
	${TOP_LIBDIR}/util.a \
	-lresolv \
	-lpthread


JARFILE = jafs.jar

all:  ${TOP_JLIBDIR} libjafs libjafsadm ${PACKAGE} all_jar

install:  all ${DESTDIR}${libdir}/libjafs.so ${DESTDIR}${libdir}/libjafsadm.so ${PACKAGE} install_jar
	if [ ! -e /usr/afswsp ]; then \
	  mkdir -p /usr/afswsp/; \
	fi; \
	if [ ! -e /usr/afswsp/etc ]; then \
	  mkdir -p /usr/afswsp/etc/; \
	  cp ./etc/CacheConfig /usr/afswsp/etc/; \
	fi; \
	if [ ! -e /usr/afswsp/log ]; then \
	  mkdir -p /usr/afswsp/log/; \
	fi; \
	if [ ! -e /usr/afswsp/cache ]; then \
	  mkdir -p /usr/afswsp/cache/; \
	fi; \
	if [ ! -L /usr/vice/etc/CellServDB ]; then \
	  ln -s /usr/vice/etc/CellServDB /usr/afswsp/etc/; \
	fi; \
	if [ ! -L /usr/vice/etc/ThisCell ]; then \
	  ln -s /usr/vice/etc/ThisCell /usr/afswsp/etc/; \
	fi

clean:
	${RM} -f ${PACKAGEDIR}*.class ${LIBJAFSADMDIR}*.o ${LIBJAFSADMDIR}${C_NATIVE_PREFIX}*.h

setup:	FORCE
	if [ ! -e ./h ]; then \
	  ln -s /usr/include/sys h; \
	fi;

${TOP_JLIBDIR}:
	mkdir -p $@

FORCE: ;

############# Shared library ###############################

libjafs: setup
	${RM} -f ${LIBJAFSADMDIR}Internal.o; \
	export BUILD_TYPE=user; \
	${MAKE} ${TOP_LIBDIR}/libjafs.so

libjafsadm:
	${RM} -f ${LIBJAFSADMDIR}Internal.o; \
	export BUILD_TYPE=admin; \
	${MAKE} ${TOP_LIBDIR}/libjafsadm.so

${TOP_LIBDIR}/libjafs.so: ${LIBJAFS_OBJS}
	${CC} ${CFLAGS} ${SHARED_FLAGS} -o $@ $^ ${LIBJAFS_LIBS}

${DESTDIR}${libdir}/libjafs.so: ${LIBJAFS_OBJS}192.168.13.10
	${CC} ${CFLAGS} ${SHARED_FLAGS} -o $@ $^ ${LIBJAFS_LIBS}

${TOP_LIBDIR}/libjafsadm.so: ${LIBJAFSADM_OBJS}
	${CC} ${CFLAGS} ${SHARED_FLAGS} -o $@ $^ ${LIBJAFSADM_LIBS}

${DESTDIR}${libdir}/libjafsadm.so: ${LIBJAFSADM_OBJS}
	${CC} ${CFLAGS} ${SHARED_FLAGS} -o $@ $^ ${LIBJAFSADM_LIBS}

############## Object files ################################

${LIBJAFSADM_OBJS}: %.o: %.c
	${CC} ${CFLAGS} ${OBJECT_FLAGS} -o $@ $<

############## C files #####################################

${CORRELATING_SOURCE_FILES}: ${LIBJAFSADMDIR}%.c: ${LIBJAFSADMDIR}${C_NATIVE_PREFIX}%.h ${LIBJAFSADMDIR}Internal.h

${LIBJAFSADMDIR}AdminToken.c: ${LIBJAFSADMDIR}${C_NATIVE_PREFIX}Token.h ${LIBJAFSADMDIR}${C_NATIVE_PREFIX}Cell.h

${LIBJAFSADMDIR}Internal.c: ${LIBJAFSADMDIR}Internal.h

${LIBJAFSADMDIR}Version2.c: ${LIBJAFSADMDIR}${C_NATIVE_PREFIX}VersionInfo.h ${LIBJAFSADMDIR}JAFS_Version.h

${LIBJAFSADMDIR}UserToken.c: ${LIBJAFSADMDIR}${C_NATIVE_PREFIX}Token.h

############## Package javac section #########################

${PACKAGEDIR}%.class: ${PACKAGEDIR}%.java
	${JAVAC} $<

############## Javah section ###############################

${JAVA_HEADERS}: ${C_NATIVE_PREFIX}%.h: ${PACKAGEDIR}%.class
	${JAVAH} ${J_NATIVE_PREFIX}$*

############# JAR file #####################################

all_jar: clean_jar
	cd ${ROOTPACKAGEDIR}; ${JAVA_HOME}/bin/jar -cMf ${TOP_JLIBDIR}/${JARFILE} *.properties ${RELPACKAGEDIR}*.class

install_jar: clean_jar
	cd ${ROOTPACKAGEDIR}; ${JAVA_HOME}/bin/jar -cMf ${JAVA_HOME}/lib/${JARFILE} *.properties ${RELPACKAGEDIR}*.class

clean_jar:
	${RM} -f ${TOP_JLIBDIR}/${JARFILE}



