#  This file is a component of the SurfAgent Proxy, based on original code from
#  the Internet Junkbuster Proxy.
# 
#  Copyright (C) 2000 Gabriel L. Somlo
#  Copyright (C) 1997 Anonymous Coders and Junkbusters Corporation
# 
#  This program is free software; you can redistribute it and/or
#  modify it under the terms of the GNU General Public License
#  as published by the Free Software Foundation; either version 2
#  of the License, or (at your option) any later version.
# 
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
# 
#  You should have received a copy of the GNU General Public License
#  along with this program (see ../GPL.txt); if not, write to the Free Software
#  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.


# Debugging vs. Optimization flags
#PERFORMANCE_CFLAGS = -g
PERFORMANCE_CFLAGS = -O3


# Miscellaneous flags for testing and generally messing around


################################################################################
#                                                                              #
#  You shouldn't have to worry about anything past this mark...                #
#                                                                              #
################################################################################

# Figure out which OS we're making for:
OSNAME = $(shell uname)

# Set OS-dependent cflags:
#  SOL_SETCONC=4     - the concurrency level on Solaris
#  SOLARIS_GETHOST   - gethostbyname_r() is Solaris version
#  LINUX_GETHOST     - gethostbyname_r() is Linux version
#  _BSD_SOURCE       - turns on gethostbyname_r() on Linux
#  _XOPEN_SOURCE=500 - turns on pthread_rwlock_* on Linux
ifeq ($(OSNAME),SunOS)
  EXTRA_CFLAGS = -DSOL_SETCONC=4 -DSOLARIS_GETHOST
  EXTRA_LIBS = -lnsl -lsocket
else
ifeq ($(OSNAME),Linux)
  EXTRA_CFLAGS = -D_BSD_SOURCE -DLINUX_GETHOST -D_XOPEN_SOURCE=500
else
  # error "This currently works on Solaris and Linux only..."
endif
endif

DEFAULT_CFLAGS = -D_REENTRANT -Wall

REGEX_CFLAGS = -DSTDC_HEADERS -DHAVE_STRING

DEFAULT_LIBS = -lpthread -lm

CFLAGS = $(DEFAULT_CFLAGS) $(REGEX_CFLAGS) \
	$(PERFORMANCE_CFLAGS) $(EXTRA_CFLAGS) $(MISC_CFLAGS)

LIBS = $(DEFAULT_LIBS) $(EXTRA_LIBS)

CC = gcc

RM = rm -f

INSTALL = cp -f

# the following doesn't take into account the dependencies of .c files on .h !!!
OBJS =	chat.o filters.o parsers.o filegard.o blckstat.o \
	bindconn.o socks4.o csp.o sed.o \
	urlcodec.o miscstr.o urlstr.o trie.o hash.o errlog.o gnu_regex.o \
	smrtcook.o strlist.o tfidf.o htmparse.o stopword.o linkvec.o profile.o \
        wordvec.o

# Rules start here...

all:	surfagent
	$(INSTALL) surfagent ..

surfagent: $(OBJS)
	$(CC) -o $@ $(OBJS) $(LIBS)

#rules for individual objects based on dependencies on .h files go here...

clean:
	$(RM) *.o *% *~ *.bck

clobber: clean
	$(RM) surfagent
