#  This file is a component of the JunkBusterMT 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
OPT_CFLAGS = -O3
#OPT_CFLAGS = -g


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

# Set OS-dependent cflags:

#  SOL_SETCONC=4             - the concurrency level on Solaris
#  _BSD_SOURCE               - turns on gethostbyname_r() on Linux
#  _XOPEN_SOURCE=500         - turns on pthread_rwlock_* on Linux
#  STDC_HEADERS, HAVE_STRING - needed by gnu_regex.*

# Default C-flags and libraries:
DEF_CFLAGS = $(OPT_CFLAGS) $(MISC_CFLAGS) -Wall -DSTDC_HEADERS -DHAVE_STRING
DEF_LIBS = 

# Linux-specific C-flags and libraries:
LIN_GCC_CFLAGS = $(DEF_CFLAGS) -DLIN_GCC -D_REENTRANT -D_BSD_SOURCE -D_XOPEN_SOURCE=500
LIN_GCC_LIBS = $(DEF_LIBS) -lpthread

# Solaris-specific C-flags and libraries:
SOL_GCC_CFLAGS = $(DEF_CFLAGS) -DSOL_GCC -D_REENTRANT -DSOL_SETCONC=4
SOL_GCC_LIBS = $(DEF_LIBS) -lpthread -lnsl -lsocket

# Windows(mingw32)-specific C-flags and libraries:
WIN_GCC_CFLAGS = $(DEF_CFLAGS) -DWIN_GCC -mthreads -UNDEBUG
WIN_GCC_LIBS = $(DEF_LIBS) -lpthreadw32 -lwsock32

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

ifeq ($(OSNAME),SunOS)
  CFLAGS = $(SOL_GCC_CFLAGS)
  LIBS = $(SOL_GCC_LIBS)
  RM = rm -f
  JBMT = jbmt
else
ifeq ($(OSNAME),Linux)
  CFLAGS = $(LIN_GCC_CFLAGS)
  LIBS = $(LIN_GCC_LIBS)
  RM = rm -f
  JBMT = jbmt
else #assume windows-migw32
  CFLAGS = $(WIN_GCC_CFLAGS)
  LIBS = $(WIN_GCC_LIBS)
  RM = del /q
  JBMT = jbmt.exe
endif
endif

CC = gcc

# 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 errlog.o gnu_regex.o smrtcook.o

# Rules start here...

all:	$(JBMT)

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

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

clean:
	$(RM) *.o

clobber: clean
	$(RM) $(JBMT)
