# @(#) makefile 1.29@(#) 96/03/11 #
# Makefile for dhdtftp for Solaris 1.

.KEEP_STATE:
SHELL=/bin/sh

# Note the horrible trick of checking for the presence of /vmunix to
# indicate a Solaris-1 (SunOS 4.1) system as apposed to a Solaris-2 one.

bARCH:sh=if [ -f /vmunix ]; then /bin/arch; else /usr/ucb/arch; fi
oARCH:sh=if [ -f /vmunix ]; then echo s1; else echo s2; fi
ARCH=$(oARCH)-$(bARCH)

# Base name of executable(s) and document(s) to be made.
BASENAME=dhdsftpd

OPT_TARGETS=$(BASENAME:%=%.$(ARCH))
DBG_TARGETS=$(BASENAME:%=%.$(ARCH).dbg)
TARGETS=$(DBG_TARGETS) $(OPT_TARGETS)

all: $(TARGETS)
	@echo Made $(TARGETS).

clean: FORCE
	rm -f $(TARGETS) *.o

SRCDIST=LICENCE SOURCE-LICENCE MANUAL COPYRIGHT \
	$(BASENAME:%=%.s1-sun3) $(BASENAME:%=%.s1-sun3.dbg) \
	$(BASENAME:%=%.s1-sun4) $(BASENAME:%=%.s1-sun4.dbg) \
	$(BASENAME:%=%.s2-sun4) $(BASENAME:%=%.s2-sun4.dbg) \
	dhdsftpd.c makefile
dhdsftpd-1.1-sourcedist.tar.Z: $(SRCDIST)
	@rm -rf $@
	tar cvf - $(SRCDIST) | compress -v > $@

debug: $(DBG_TARGETS)
	@echo Made debugging $(DBG_TARGETS).

optimised: $(OPT_TARGETS)
	@echo Made optimised $(OPT_TARGETS).

FORCE:

#----------------------
# CFLAGS are flags for all C compilations.
CFLAGS=
# LINKFLAGS are flags for all links.
LINKFLAGS=-lrpcsvc

#----------------------
# EDIT definition of CC and of CFLAGS_OPT below to suit your compiler.
# For example, on my Solaris-1 systems I use /bin/cc, but on Solaris-2
# I use gcc because Sun's UNIX has no cc (grumble, grumble)!
# The -lsocket flag is passed to gcc for Solaris-2 since some of
# the Solaris-1 socket functionality has moved to libsocket.
CC:sh=if [ -f /vmunix ]; then echo cc; else echo gcc -lsocket; fi
#CC=cc

# CCOPT is the list of flags for extra optimisation for your compiler.
# If in doubt, use -O, but you can safely use -O4 with Sun's /bin/cc
# if you wish.
CCOPT=-O

#----------------------
# Optimising compile and link (in one step).
# CFLAGS_OPT are flags for optimising compile/link.
CFLAGS_OPT=$(CFLAGS) $(CCOPT)

%.$(ARCH): %.c
	@rm -f $@
	$(CC) $(CFLAGS_OPT) -o $@ $(@:%.$(ARCH)=%.c) $(LINKFLAGS)
	strip $@

#----------------------
# Debugging compile and link (in one step).
# CFLAGS_DBG are flags for debugging compile/link.
CFLAGS_DBG=$(CFLAGS) -g -DDEBUGGING_COMPILE

%.$(ARCH).dbg: %.c
	@rm -f $@
	$(CC) $(CFLAGS_DBG) -o $@ $(@:%.$(ARCH).dbg=%.c) $(LINKFLAGS)
