# 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

# MakefileProto for Linux i386 systems
#
DEST=@DEST@
TOP_INCDIR=@TOP_INCDIR@
TOP_LIBDIR=@TOP_LIBDIR@
TOP_SRCDIR=@TOP_SRCDIR@
prefix=@prefix@
exec_prefix=@exec_prefix@
bindir=@bindir@
sbindir=@sbindir@
libexecdir=@libexecdir@
libdir=@libdir@
includedir=@includedir@
mandir=@mandir@
afssrvbindir=@afssrvbindir@
afssrvsbindir=@afssrvsbindir@
afssrvlibexecdir=@afssrvlibexecdir@
afskerneldir=@afskerneldir@
SYS_NAME=@AFS_SYSNAME@
KDEBUG=@KERN_DEBUG_OPT@
FOMIT=@OMIT_FRAME_POINTER@

include config/Makefile.${SYS_NAME}

# OS specific object files:
AFS_OS_OBJS = \
	osi_alloc.o \
	osi_cred.o \
	osi_groups.o \
	osi_inode.o \
	osi_file.o \
	osi_misc.o \
	osi_module.o \
	osi_sleep.o \
	osi_sysctl.o \
	osi_vfsops.o \
	osi_vm.o \
	osi_vnodeops.o

AFS_OS_NFSOBJS =

AFS_OS_NONFSOBJS =


# System specific build commands and flags
CC = gcc
LD = ld
# -Wall
<i386_linux22 i386_linux24>
CCFLAGS =  $(KDEBUG) -O2 $(FOMIT) \
	-fno-strength-reduce -pipe -march=i486 -malign-loops=2 -malign-jumps=2 \
	-malign-functions=2
DEFINES = -D__KERNEL__  -DCPU=586 -DKERNEL -D_KERNEL -DMODULE ${SMP_DEF} ${KDEFINES}
<alpha_linux_22 alpha_linux_24>
CCFLAGS = $(KDEBUG) -O2 $(FOMIT) -fno-strength-reduce -pipe -mno-fp-regs -ffixed-8
DEFINES = -D__KERNEL__ -DKERNEL -D_KERNEL -DMODULE ${SMP_DEF}
<s390_linux22 s390_linux24>
CCFLAGS =   -O $(FOMIT) -fno-strength-reduce \
	-fno-strict-aliasing -fsigned-char 
DEFINES = -D__KERNEL__  -D__s390__ -DKERNEL -D_KERNEL -DMODULE ${SMP_DEF}
<sparc_linux22 sparc_linux24>
LD = ld -m elf32_sparc
CCFLAGS =   $(KDEBUG) -O2 $(FOMIT) \
	-fno-strength-reduce -pipe -mcpu=v8 -mno-fpu -fcall-used-g5 -fcall-used-g7
DEFINES = -D__KERNEL__  -DCPU=sparc -DKERNEL -D_KERNEL -DMODULE ${SMP_DEF}
<sparc64_linux22 sparc64_linux24>
CC = sparc64-linux-gcc
LD = ld -m elf64_sparc
CCFLAGS =   $(KDEBUG) -O2 $(FOMIT) \
	-fno-strength-reduce -pipe -mcpu=ultrasparc -m64 -mno-fpu -mcmodel=medlow -ffixed-g4 -fcall-used-g5 -fcall-used-g7 -Wno-sign-compare
DEFINES = -D__KERNEL__  -DCPU=sparc64 -DKERNEL -D_KERNEL -DMODULE ${SMP_DEF}
<ppc_linux22 ppc_linux24>
CCFLAGS =   $(KDEBUG) -O2 $(FOMIT) -fno-strength-reduce \
	-fno-strict-aliasing -fsigned-char -msoft-float -pipe \
	-fno-builtin -ffixed-r2
DEFINES = -D__KERNEL__  -D__powerpc__ -DKERNEL -D_KERNEL -DMODULE ${SMP_DEF}
<parisc_linux24>
CCFLAGS =   $(KDEBUG) -O2 $(FOMIT) \
	-fno-strict-aliasing -fno-common -fno-strength-reduce \
        -fno-strict-aliasing -fsigned-char -mno-space-regs -mfast-indirect-calls \
        -mdisable-fpregs -ffunction-sections -march=1.1 -mschedule=7100
DEFINES = -D__KERNEL__  -D__linux__ -DKERNEL -D_KERNEL -DMODULE ${SMP_DEF}
<ia64_linux24>
CCFLAGS =   $(KDEBUG) -O2 $(FOMIT) -fno-strict-aliasing -fno-common -pipe \
	-ffixed-r13 -mfixed-range=f10-f15,f32-f127 -falign-functions=32 -mb-step
DEFINES = -D__KERNEL__ -DKERNEL -D_KERNEL ${SMP_DEF} -DMODULE
<all>
INCLUDES = -I. -I../ -I${TOP_SRCDIR}/config

CFLAGS = $(CCFLAGS) $(DEFINES) $(INCLUDES)

# Name of directory to hold object files and libraries.
KOBJ = MODLOAD
MPS = @MPS@

# COMPDIRS is called in Makefile.common to do the actual builds.
COMPDIRS=linux_compdirs
INSTDIRS=linux_instdirs
DESTDIRS=linux_destdirs

include Makefile.common

LINUX_VERS=@LINUX_VERSION@
LINUX_KERNEL_PATH=@LINUX_KERNEL_PATH@
LINUX_MODULE_NAME=
LOCAL_SMP_DEF=

setup:
	-$(RM) -f h net netinet sys rpc
	-ln -s rx rpc
	for m in ${MPS} ; do \
		KDIR=$(KOBJ)-${LINUX_VERS}${LINUX_MODULE_NAME}-$$m; \
		mkdir -p $${KDIR}; \
		ln -fs ../Makefile $${KDIR}/Makefile ; \
		ln -fs ../Makefile.common $${KDIR}/Makefile.common; \
		ln -fs ../config $${KDIR}/config; \
	done 
	
# Compile SP and MP clients as requested

${COMPDIRS} ${INSTDIRS} ${DESTDIRS}:
	$(RM) -f h 
	ln -s ${LINUX_KERNEL_PATH}/include/linux h 
	$(RM) -f linux 
	ln -s ${LINUX_KERNEL_PATH}/include/linux linux 
	$(RM) -f net 
	ln -s ${LINUX_KERNEL_PATH}/include/linux net 
	$(RM) -f netinet 
	ln -s ${LINUX_KERNEL_PATH}/include/linux netinet 
	$(RM) -f sys
	ln -s ${LINUX_KERNEL_PATH}/include/linux sys
	$(RM) -f asm-generic
	ln -s ${LINUX_KERNEL_PATH}/include/asm-generic asm-generic
	$(RM) -f asm
<alpha_linux_22 alpha_linux_24>
	ln -s ${LINUX_KERNEL_PATH}/include/asm-alpha asm
<i386_linux22 i386_linux24>
	ln -s ${LINUX_KERNEL_PATH}/include/asm-i386 asm
<s390_linux22 s390_linux24>
	ln -s ${LINUX_KERNEL_PATH}/include/asm-s390 asm
<ppc_linux22 ppc_linux24>
	ln -s ${LINUX_KERNEL_PATH}/include/asm-ppc asm 
<sparc_linux22 sparc_linux24>
	ln -s ${LINUX_KERNEL_PATH}/include/asm-sparc asm
<sparc64_linux22 sparc64_linux24>
	ln -s ${LINUX_KERNEL_PATH}/include/asm-sparc64 asm
<ia64_linux24>
	ln -s ${LINUX_KERNEL_PATH}/include/asm-ia64 asm
<all>
	for m in ${MPS} ; do \
		KDIR=${KOBJ}-${LINUX_VERS}${LINUX_MODULE_NAME}-$$m ; \
		echo Building in directory: $${KDIR} ; \
		if [ "$$m" = "MP" ] ; then \
			SMP_DEF="-DAFS_SMP @RHCONFIG_MP@ ${LOCAL_SMP_DEF}" ; \
			TARG="libafs.mp" ; \
		elif [ "$$m" = "EP" ] ; then \
			SMP_DEF="-DAFS_SMP @RHCONFIG_MP@ ${LOCAL_SMP_DEF}" ; \
			TARG="libafs.ep" ; \
		elif [ "$$m" = "BM" ] ; then \
			SMP_DEF="-DAFS_SMP @RHCONFIG_MP@ ${LOCAL_SMP_DEF}" ; \
			TARG="libafs.bm" ; \
		else  \
			SMP_DEF="@RHCONFIG_SP@ ${LOCAL_SMP_DEF}" ; \
			TARG=libafs ; \
		fi ; \
		cd $${KDIR} ; \
		$(MAKE) SMP_DEF="$${SMP_DEF}" $@_$${TARG} CLIENT=${LINUX_VERS}${LINUX_MODULE_NAME} || exit $$?; \
		cd ../ ; \
	done

linux_compdirs_libafs: libafs
linux_compdirs_libafs.mp: libafs.mp
linux_compdirs_libafs.ep: libafs.ep
linux_compdirs_libafs.bm: libafs.bm
linux_instdirs_libafs: install_libafs
linux_instdirs_libafs.mp: install_libafs.mp
linux_instdirs_libafs.ep: install_libafs.ep
linux_instdirs_libafs.bm: install_libafs.bm
linux_destdirs_libafs: dest_libafs
linux_destdirs_libafs.mp: dest_libafs.mp
linux_destdirs_libafs.ep: dest_libafs.ep
linux_destdirs_libafs.bm: dest_libafs.bm


# Below this line are targets when in the COMMON directory:
# For Linux there is no kernel NFS server.
LIBAFS = libafs-${CLIENT}.o
LIBAFS_MP = libafs-${CLIENT}.mp.o
LIBAFS_EP = libafs-${CLIENT}.ep.o
LIBAFS_BM = libafs-${CLIENT}.bm.o

INST_LIBAFS = ${DESTDIR}${afskerneldir}/${LIBAFS}
INST_LIBAFS_MP = ${DESTDIR}${afskerneldir}/${LIBAFS_MP}
INST_LIBAFS_EP = ${DESTDIR}${afskerneldir}/${LIBAFS_EP}
INST_LIBAFS_BM = ${DESTDIR}${afskerneldir}/${LIBAFS_BM}

DEST_LIBAFS = ${DEST}/root.client/usr/vice/etc/modload/${LIBAFS}
DEST_LIBAFS_MP = ${DEST}/root.client/usr/vice/etc/modload/${LIBAFS_MP}
DEST_LIBAFS_EP = ${DEST}/root.client/usr/vice/etc/modload/${LIBAFS_EP}
DEST_LIBAFS_BM = ${DEST}/root.client/usr/vice/etc/modload/${LIBAFS_BM}


libafs:	$(LIBAFS) 
	echo SP Build Complete

libafs.mp: $(LIBAFS_MP)
	echo MP Build Complete

libafs.ep: $(LIBAFS_EP)
	echo EP Build Complete

libafs.bm: $(LIBAFS_BM)
	echo BM Build Complete

${LIBAFS}: $(AFSAOBJS) $(AFSNONFSOBJS)
	$(RM) -f $@
	$(LD) -r -o $@ $(AFSAOBJS) $(AFSNONFSOBJS)

${LIBAFS_MP}: $(AFSAOBJS) $(AFSNONFSOBJS)
	$(RM) -f $@
	$(LD) -r -o $@ $(AFSAOBJS) $(AFSNONFSOBJS)

${LIBAFS_EP}: $(AFSAOBJS) $(AFSNONFSOBJS)
	$(RM) -f $@
	$(LD) -r -o $@ $(AFSAOBJS) $(AFSNONFSOBJS)

${LIBAFS_BM}: $(AFSAOBJS) $(AFSNONFSOBJS)
	$(RM) -f $@
	$(LD) -r -o $@ $(AFSAOBJS) $(AFSNONFSOBJS)

install_libafs:	$(INST_LIBAFS) 
	echo SP Install Complete

install_libafs.mp: $(INST_LIBAFS_MP)
	echo MP Install Complete

install_libafs.ep: $(INST_LIBAFS_EP)
	echo EP Install Complete

install_libafs.bm: $(INST_LIBAFS_BM)
	echo BM Install Complete

dest_libafs:	$(DEST_LIBAFS) 
	echo SP Install Complete

dest_libafs.mp: $(DEST_LIBAFS_MP)
	echo MP Install Complete

dest_libafs.ep: $(DEST_LIBAFS_EP)
	echo EP Install Complete

dest_libafs.bm: $(DEST_LIBAFS_BM)
	echo BM Install Complete

$(INST_LIBAFS): $(LIBAFS)
	${INSTALL} -f $? $@

$(INST_LIBAFS_MP): $(LIBAFS_MP)
	${INSTALL} -f $? $@

$(INST_LIBAFS_EP): $(LIBAFS_EP)
	${INSTALL} -f $? $@

$(INST_LIBAFS_BM): $(LIBAFS_BM)
	${INSTALL} -f $? $@

$(DEST_LIBAFS): $(LIBAFS)
	${INSTALL} -f $? $@

$(DEST_LIBAFS_MP): $(LIBAFS_MP)
	${INSTALL} -f $? $@

$(DEST_LIBAFS_EP): $(LIBAFS_EP)
	${INSTALL} -f $? $@

$(DEST_LIBAFS_BM): $(LIBAFS_BM)
	${INSTALL} -f $? $@


# Linux specific objects
osi_alloc.o: $(AFS)/osi_alloc.c
	$(CRULE1)
osi_cred.o: $(AFS)/osi_cred.c
	$(CRULE1)
osi_groups.o: $(AFS)/osi_groups.c
	$(CRULE1)
osi_file.o: $(AFS)/osi_file.c
	$(CRULE1)
osi_inode.o: $(AFS)/osi_inode.c
	$(CRULE1)
osi_misc.o: $(AFS)/osi_misc.c
	$(CRULE1)
osi_module.o: $(AFS)/osi_module.c
	$(CRULE1)
osi_sleep.o: $(AFS)/osi_sleep.c
	$(CRULE1)
osi_sysctl.o: $(AFS)/osi_sysctl.c
	$(CRULE1)
osi_vfsops.o: $(AFS)/osi_vfsops.c
	$(CRULE1)
osi_vm.o: $(AFS)/osi_vm.c
	$(CRULE1)
osi_vnodeops.o: $(AFS)/osi_vnodeops.c
	$(CRULE1)
