
# You probably only want to edit config.h to install Alex.

# for prof both CF and LDF need "-p"

# CFLAGS= -g -O -p -pg
CFLAGS= -O

# -g -pg
LDFLAGS= 

RPCGEN=	rpcgen
CC= cc

#------------------------------End of configuration section.


NFSOBJS= nfs_prot_svc.o nfs_prot_xdr.o unfsd.o init.o fh.o 

MOUNTOBJS= mount_svc.o mount_xdr.o unfsmntd.o fh.o alexlib.o phonehome.o \
           readinfo.o cmucs.o compat.o

ALEXOBJS= alex.o dirtoinfo.o ftpparent.o ftpchild.o alexlib.o remtimezone.o \
          stringtotime.o readinfo.o cmucs.o compat.o phonehome.o


all: local.h basic alexfsck evictor printinfo 

local.h:
	echo '/* Put local config.h options in here.  Use #undef if needed. */' > local.h

# Basic is what is needed to get started.
basic: alexd alexmountd

alexd:  ${NFSOBJS} ${ALEXOBJS} defs
	${CC} $(LDFLAGS) -o alexd ${NFSOBJS} ${ALEXOBJS} -lm `/bin/csh -f libdefs`

alexmountd: ${MOUNTOBJS}
	${CC} $(LDFLAGS) -o alexmountd ${MOUNTOBJS} `/bin/csh -f libdefs`


# Non basic
#
evictor: evictor.o alexlib.o cmucs.o phonehome.o
	${CC} ${LDFLAGS} -o evictor evictor.o alexlib.o cmucs.o compat.o phonehome.o

alexfsck: readinfo.o alexlib.o alexfsck.o cmucs.o compat.o phonehome.o
	${CC} -o alexfsck alexfsck.o alexlib.o readinfo.o cmucs.o compat.o phonehome.o

printinfo: printinfo.c
	${CC} ${CFLAGS} -o printinfo printinfo.c

defs: defs.o alexlib.o cmucs.o compat.o phonehome.o 
	${CC} ${LDFLAGS} -o defs defs.o alexlib.o cmucs.o compat.o phonehome.o


# -----------------  major items above minor things below --------------------

# if you do not have yacc just say "make noyacc" and then do "make"       
noyacc:
	touch stringtotime.c 

stringtotime.c: stringtotime.y
	/bin/rm -f stringtotime.c
	yacc -v stringtotime.y
	mv y.tab.c stringtotime.c

stringtotime.o: stringtotime.c
	${CC} ${CFLAGS} -c -DYYDEBUG stringtotime.c

stringtotime: stringtotime.o stringtotimemain.o alexlib.o phonehome.o
	cc -o stringtotime stringtotime.o stringtotimemain.o alexlib.o phonehome.o

remtimezone: stringtotime.o remtimezonemain.o alexlib.o phonehome.o remtimezone.o
	cc -o remtimezone stringtotime.o remtimezonemain.o alexlib.o phonehome.o remtimezone.o


#  Installation stuff  -----------------------------------------------------

install: all installbasic defs
	/bin/csh -f install nonbasic

installbasic: basic defs
	/bin/csh -f install basic

#  NFS Stuff ------------------------------------------------------------------

norpcgen:
	touch nfs_prot.h
	touch nfs_prot_svc.c
	touch nfs_prot_xdr.c
	touch mount.h
	touch mount_svc.c
	touch mount_xdr.c

nfs_prot.h: nfs_prot.x config.nfs.h
	${RPCGEN} -h -o $@ nfs_prot.x

nfs_prot_svc.c: nfs_prot.x config.nfs.h
	${RPCGEN} -s udp nfs_prot.x | \
	sed \
		-e 's/main()/main(argc,argv,envp) int argc; char **argv, **envp; /' \
 		-e 's/pmap_unset(/init_Log(); pmap_unset(/' \
		-e 's/RPC_ANYSOCK/makesock(NFS_PORT, NFS_MAXDATA)/' \
		-e 's/svc_run();/unfsd_init(argc,argv,envp); svc_run();/' \
	    > $@

nfs_prot_xdr.c: nfs_prot.x config.nfs.h
	${RPCGEN} -c -o $@ nfs_prot.x



mount.h: mount.x config.nfs.h
	${RPCGEN} -h -o $@ mount.x

mount_svc.c: mount.x config.nfs.h
	${RPCGEN} -s udp mount.x | \
	sed \
		-e 's/main()/main(argc,argv) int argc; char **argv;/' \
 		-e 's/pmap_unset(/init_Log(); pmap_unset(/' \
		-e 's/svc_run();/unfsmntd_init(argc,argv); svc_run();/' \
	    > $@

mount_xdr.c: mount.x config.nfs.h
	${RPCGEN} -c -o $@ mount.x

#  misc    ---------------------------------------------------------------------

clean: halfclean
	/bin/rm -f nfs_prot_svc.c nfs_prot_xdr.c nfs_prot.h mount_svc.c mount_xdr.c mount.h  

#  if you want to still be able to do "make norpcgen"
halfclean:
	/bin/rm -f *.o y.tab.h y.output stringtotime.c alexd alexmountd \
	    printinfo defs alexfsck evictor 


# could make and install "UidStr" but not needed 

UidStr:
	cat /etc/passwd /etc/passwds | awk -f UidStrA.awk | sort -nu | awk -f UidStrB.awk > UidStr


#  To get and make a new version of the software ------------------------------
#
#  Different people like "getalex", "patchalex", and "updatealex" so 
#  we actually have all of them though they do similar things.  The
#  "srclinks" gives you symlinks to the latest source.
#
#  Except for "alpha" and "new" you need to run "make install" and
#  then either "grepnkill alexd" to restart or "start.alex" for coldstart.

# Recommended - gets latest stuff, compiles, install, and starts things up
alpha:
	/bin/csh -f getalex alex.alpha.tar.Z

# Latest "stable" code.
new:
	/bin/csh -f getalex alex.tar.Z

# Good for small changes.  If whole new files have been added it will miss them.
# But as new files are not added very often this usually works.
patch:
	/bin/csh -f patchalex

# Copies all release files that have changed since last time.  
update:
	/bin/csh -f updatealex

# Just make symlinks to all of the source files.
srclinks:
	mv -f /usr/alexsrvr/src /usr/alexsrvr/src.old
	sh cp-rs /alex/edu/cmu/cs/sp/alex/src/alexsrvr/src /usr/alexsrvr/src
	echo "You can go back to real files by doing a     make new"
	echo " "
	echo "Your current directory has changed"
	pwd

# Only first timers should do this 
# If there is a running server it will die and this will not finish
alllinks:
	echo "This should only be run to get Alex the first time."
	echo "This should only be run as  alexsrvr."
	echo "If either of these is not true, you have 15 seconds to stop this."
	sleep 15
	(if [ ! -d /usr/alexsrvr/.old ] ; then mkdir /usr/alexsrvr/.old; fi ;\
	 touch /usr/alexsrvr/tmp                                            ;\
	 mv -f /usr/alexsrvr/* /usr/alexsrvr/.old                           ;\
	 sh cp-rs /alex/edu/cmu/cs/sp/alex/src/alexsrvr /usr/alexsrvr       ;\
	 /bin/rm -f /usr/alexsrvr/bin/*                                     ;\
	 cd /usr/alexsrvr/src                                               ;\
	 make install                                                       ;\
	 echo "Run /usr/alexsrvr/bin/start.alex as root"                     )


# Get and compile archie
archie:
	/bin/csh -f /alex/edu/cmu/cs/sp/alex/user/bin/getpackage archie

#  These are sort of development things ----------------------------------------

LINTFLAGS = -abchx -DDEBUG 
alexlint:
	lint -u alexlib.c dirtoinfo.c alex.c ftpparent.c ftpchild.c remtimezone.c stringtotime.c \
		unfsd.c fh.c readinfo.c phonehome.c

mountlint:
	lint -u alexlib.c unfsmntd.c fh.c readinfo.c

rcs:
	rcsci -q -l unfsd.c init.c fh.c alex.c ftpparent.c ftpchild.c dirtoinfo.c \
		alexlib.c phonehome.c remtimezone.c stringtotime.y readinfo.c \
		remtimezone.c mount.x nfs_prot.x alex.h alexincs.h \
               	config.h config.nfs.h Makefile makerelease printinfo.c \
                alexfsck.c evictor.c getalex defs.c install scripts/* \
                updatealex patchalex

backup:
	cp *.x backups
	cp *.c backups
	cp *.h backups
	cp *.y backups
	cp Makefile backups
	cp getalex updatealex patchalex backups
	cp makerelease backups

release:
	makerelease

releaseget:
	cp getalex /../alex/usr/anon/src


# include dependencies    -------------------------------------------------------

nfs_prot_svc.o nfs_prot_xdr.o unfsd.o fh.o init.o: nfs_prot.h config.nfs.h

mount_svc.o mount_xdr.o unfsmntd.o: mount.h config.nfs.h

fh.o unfsd.o init.o: unfsd.h fh.h config.nfs.h

ftpparent.o ftpchild.o: alexftp.h

init.o fh.o unfsd.o dirtoinfo.o ftpparent.o ftpchild.o alexlib.o \
remtimezone.o alexmain.o remtimezonemain.o stringtotimemain.o \
stringtotime.o stringtotime.c alex.o readinfo.o unfsmntd.o evictor.o \
phonehome.o defs.o alexfsck.o: alex.h alexincs.h config.h local.h



 
