# 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

# For best speed/compactness, use:
# (The -s gives about the same results as stripping your executable)
CFLAGS = -O2 -s

# In case that gives you trouble, and if you're debugging:
# CFLAGS = -O1

# Use this for Solaris, or wherever UCB stuff is needed: (from Bob Ramstad)
# CFLAGS = -O2 -s -L/usr/ucblib -I/usr/ucbinclude

###### Required libraries - varies by OS

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

# Solaris apparently needs 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

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

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

OBJECTS = logresolve
SOURCES = logresolve.c lr-nsrec.c lr-stats.c lr-ip.c lr-hash.c lr-dbm.c
PIECES = $(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-hash.h lr-ip.h lr-nsrec.h lr-stats.h

.SUFFIXES: .c .o

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

logresolve: $(PIECES)
	$(COMPILER) $(CFLAGS) $(LIBS) $(DBMLIB) -o logresolve $(PIECES)

$(PIECES) : $(ALLDEPS)
	$(COMPILER) $(CFLAGS) -c $*.c
sweep:
	rm -f $(PIECES)

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

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

indent:
	indent -bad -bap -sob -cdb -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-nsrec.h

