# Makefile for analog 4.13
# Please read docs/Readme.html, or http://www.analog.cx/
CC = gcc           # which compiler to use: eg cc, acc, gcc. NB Different
#                    compilers need different CFLAGS, e.g., -O instead of -O2.
CEXTRAFLAGS = -O2  # options, e.g. for optimisation or ANSI compilation.
#                    HP/UX cc requires CEXTRAFLAGS = -Aa (HP/UX 9) or ...
#                    -Ae (HP/UX 10);       BS2000/OSD requires -XLLML -XLLMK;
#                    NeXTSTEP apparently needs...
#                    CEXTRAFLAGS = -O2 -pipe -no-precomp 
DEFS =             # any of -DNOPIPES -DNODNS -DNODIRENT -DNOOPEN ...
#                    ... -DEBCDIC -DNOGMTIME -DNEED_STRCMP -DNEED_MEMMOVE ...
#                    ... -DNEED_STRTOUL -DNEED_DIFFTIME -DHAVE_ADDR_T ...
#                    ... -DNEED_FLOATINGPOINT_H
#                    Solaris 2 (SunOS 5) might need DEFS = -DNEED_STRCMP
#                    SunOS 4 usually needs...
#   DEFS = -DNEED_MEMMOVE -DNEED_STRTOUL -DNEED_DIFFTIME -DNEED_FLOATINGPOINT_H
#                    64-bit Solaris needs -DHAVE_ADDR_T
#                    DYNIX/ptx reportedly needs -D_SOCKET_VERSION=11
#                    All the options are explained at the bottom of this file.
OS = UNIX          # Operating system: UNIX, DOS, WIN32, MAC, OS2, VMS
#                    RISCOS, BEOS, NEXTSTEP, BS2000, AS400
LIBS =       # extra libraries needed; Solaris 2 (SunOS 5) needs
#              LIBS = -lnsl and SCO Unix needs LIBS = -lsocket
#              IRIX reportedly needs LIBS = -lc
#              OS/2 with EMX requires LIBS = -lsocket; so does BS2000/OSD
#              SVR4 requires LIBS = -lsocket -lnsl
#              DYNIX/ptx requires LIBS = -L/usr/lib/bsd-socket -lsocket -lnsl

PROGRAM = analog
OBJS = alias.o analog.o cache.o dates.o globals.o hash.o init.o init2.o \
	input.o macinput.o macstuff.o output.o output2.o pcre.o process.o \
	settings.o sort.o tree.o utils.o win32.o
HEADERS = anlghead.h anlghea2.h anlghea3.h anlghea4.h macdir.h pcre.h
CFLAGS = $(CEXTRAFLAGS) $(DEFS) -D$(OS)

$(PROGRAM): $(OBJS) $(HEADERS) Makefile
	$(CC) $(CEXTRAFLAGS) -o $(PROGRAM) $(OBJS) $(LIBS)
	@echo '***'
	@echo '***IMPORTANT: You must read the licence before using analog'
	@echo '***'

# There doesn't seem to be a good way to write all these rules in a generic
# form that works for all "make" programs
alias.o: alias.c $(HEADERS) Makefile
	$(CC) $(CFLAGS) -c alias.c

analog.o: analog.c $(HEADERS) Makefile
	$(CC) $(CFLAGS) -c analog.c

cache.o: cache.c $(HEADERS) Makefile
	$(CC) $(CFLAGS) -c cache.c

dates.o: dates.c $(HEADERS) Makefile
	$(CC) $(CFLAGS) -c dates.c

globals.o: globals.c $(HEADERS) Makefile
	$(CC) $(CFLAGS) -c globals.c

hash.o: hash.c $(HEADERS) Makefile
	$(CC) $(CFLAGS) -c hash.c

init.o: init.c $(HEADERS) Makefile
	$(CC) $(CFLAGS) -c init.c

init2.o: init2.c $(HEADERS) Makefile
	$(CC) $(CFLAGS) -c init2.c

input.o: input.c $(HEADERS) Makefile
	$(CC) $(CFLAGS) -c input.c

macinput.o: macinput.c $(HEADERS) Makefile
	$(CC) $(CFLAGS) -c macinput.c

macstuff.o: macstuff.c $(HEADERS) Makefile
	$(CC) $(CFLAGS) -c macstuff.c

output.o: output.c $(HEADERS) Makefile
	$(CC) $(CFLAGS) -c output.c

output2.o: output2.c $(HEADERS) Makefile
	$(CC) $(CFLAGS) -c output2.c

pcre.o: pcre.c pcre.h pcrechar.h pcreintl.h Makefile
	$(CC) $(CFLAGS) -c pcre.c

process.o: process.c $(HEADERS) Makefile
	$(CC) $(CFLAGS) -c process.c

settings.o: settings.c $(HEADERS) Makefile
	$(CC) $(CFLAGS) -c settings.c

sort.o: sort.c $(HEADERS) Makefile
	$(CC) $(CFLAGS) -c sort.c

tree.o: tree.c $(HEADERS) Makefile
	$(CC) $(CFLAGS) -c tree.c

utils.o: utils.c $(HEADERS) Makefile
	$(CC) $(CFLAGS) -c utils.c

win32.o: win32.c $(HEADERS) Makefile
	$(CC) $(CFLAGS) -c win32.c

force:
	rm -f $(OBJS)
	make $(PROGRAM) 'CEXTRAFLAGS=$(CEXTRAFLAGS)' 'LIBS=$(LIBS)' \
	'DEFS=$(DEFS)' CC=$(CC)

clean:
	rm -f *.o analog *~ */*~

# OK, here's the details on all the DEFS options, in case anyone needs to know.
# NOPIPES excludes non-ANSI functions popen() and pclose(). You will lose the
#   UNCOMPRESS command.
# NODNS excludes all the DNS lookup code. This is platform-dependent, but
#   typically involves header files <net*.h> and functions like inet_addr()
#   and gethostbyaddr().
# NODIRENT stops you using wildcards in logfile names. Again, the code is
#   platform-dependent, but usually the header file <dirent.h> and functions
#   opendir(), readdir() and closedir() are involved.
# NOOPEN excludes non-ANSI functions open() and fdopen(). This results in an
#   alternative, less safe locking mechanism for DNS files and cache files.
#
# ** If all of the above are defined only features defined in ANSI C are used.
#
# EBCDIC is needed if your server uses the EBCDIC character set, not ASCII.
# NEED_STRCMP, NEED_MEMMOVE, NEED_STRTOUL and NEED_DIFFTIME provide
#   replacements for standard functions missing on some systems.
# NOGMTIME doesn't use the gmtime() function.
# NEED_FLOATINGPOINT_H includes a header file called <floatingpoint.h>.
# HAVE_ADDR_T is needed if inet_addr() returns in_addr_t which is not the
#   same as unsigned long.
