#
# logresolve 2.0 - http://www.net/~tomr/progs/logresolve/
#
# Tom Rathborne - tomr@uunet.ca - http://www.net/~tomr/
#

#
# Please use GNU Make! I've had trouble with others.
#

###### Available commands:

# 'make'            compiles everything (currently just logresolve)
# 'make logresolve' builds the program (same as just 'make' right now)
#
# 'make sweep'      cleans up (removes pieces)
# 'make clean'      cleans up (removes objects AND executables)
#
# 'make distdir'    puts distribution files into a 'dist' directory
# 'make indent'     runs my preferred indent command on all files

###### Compiler and flags 

# I prefer gcc, that's why it's the default.
COMPILER = gcc

# Add -DLR_NEED_OWN_FLOCK to CFLAGS if flock() is unavailable on your system.

# For best speed/compactness, use:
CFLAGS = -O2

# To really check out the code, I use: (it passes with flying colours, too!)
#CFLAGS = -O2 -Wall -pedantic -ansi

# For some Solaris systems, or where UCB stuff is needed: (from Bob Ramstad)
#CFLAGS = -O2 -L/usr/ucblib -I/usr/ucbinclude

# For some Solaris systems, or where UCB stuff is missing: (from UUNET Canada)
#CFLAGS = -O2 -L/usr/lib -I/usr/include

# Use this for nit-picky optimization on an Intel box: (at least 486)
#CFLAGS = -O9 -m486 -fexpensive-optimizations -finline-functions

###### Linker flags and Required libraries - varies by OS

# (The -s gives about the same results as stripping your executable)
LFLAGS = -s

# Pick your favourite ndbm-compatible library: (choose at most one :) )
DBMLIB = -lgdbm
# DBMLIB = -lndbm
# DBMLIB = -ldb
# DBMLIB = -ldbm
# DBMLIB = -lc

# Some Solaris systems apparently need socket, nameservice, and UCB libraries.
#   "Note that this also may require /usr/ucblib to be in LD_LIBRARY_PATH
#    in order for the executable to run properly." - Bob Ramstad
#LIBS = -lsocket -lnsl -lucb

# Most Solaris systems that don't have ucb libraries still need these:
#LIBS = -lsocket -lnsl

# Linux, Irix and SunOS don't seem to need much else.

######## You shouldn't have to fiddle with anything below here! ########

TARGETS = logresolve
SOURCES = logresolve.c lr-dbm.c lr-hash.c lr-ip.c lr-nsrec.c lr-stats.c
OBJECTS = $(SOURCES:.c=.o)
DOCS = logresolve.txt

### Note that everything is said to depend on the Makefile so that changes
  # in the Makefile are guaranteed to cause a full rebuild, just to be safe.

ALLDEPS = logresolve.h Makefile
INCLUDES = logresolve.h lr-dbm.h lr-dbm-flock.h lr-hash.h lr-ip.h lr-nsrec.h lr-stats.h

.SUFFIXES: .c .o

.c.o: $(COMPILER) $(CFLAGS) -c $<

logresolve: $(OBJECTS)
	$(COMPILER) $(LFLAGS) $(DBMLIB) $(LIBS) $(OBJECTS) -o logresolve

$(OBJECTS) : $(ALLDEPS)
	$(COMPILER) $(CFLAGS) -c $*.c

sweep:
	rm -f $(OBJECTS)

clean:
	rm -f $(TARGETS) $(OBJECTS)

distdir:
	rm -rf dist
	mkdir dist
	cp Makefile $(DOCS) $(SOURCES) $(INCLUDES) dist

indent:
	indent -fc1 -bad -bap -sob -ncdb -sc -br -ce -cli4 -nss -npcs -cs -lp -ci4 -ip4 -i4 -l79 $(SOURCES) $(INCLUDES)
	rm $(SOURCES:=~)
	rm $(INCLUDES:=~)

### additional dependencies - anyone know a cleaner way to do this?

logresolve.o: logresolve.c logresolve.h
lr-nsrec.o: lr-nsrec.c lr-nsrec.h
lr-stats.o: lr-stats.c lr-stats.h
lr-ip.o: lr-ip.c lr-ip.h lr-nsrec.h
lr-hash.o: lr-hash.c lr-hash.h lr-dbm.h lr-nsrec.h
lr-dbm.o: lr-dbm.c lr-dbm.h lr-dbm-flock.h lr-nsrec.h

