INSTALL = @INSTALL@
INSTALL_PROGRAM = @INSTALL_PROGRAM@
INSTALL_DATA = @INSTALL_DATA@

prefix = @prefix@
exec_prefix = @exec_prefix@

SHAREDOPT = -shared -fPIC,-Wl,-soname,libcgi.so.0
LIBDIR = $(prefix)/lib
INCDIR = $(prefix)/include/libcgi/
MANDIR	= $(prefix)/man/man3
SHELL = /bin/sh
EXTRA_LIBS = 

INCS =  -Isrc
FLAGS = -Wall -D_REENTRANT

OBJS = src/error.o src/cgi.o src/session.o src/base64.o src/md5.o \
	src/string.o src/general.o src/list.o src/cookie.o
SHOBJS=$(OBJS:.o=.sh.o)

%.o: %.c
	$(CC) $(FLAGS) -c $*.c -o $@

%.sh.o: %.c
	$(CC) $(FLAGS) -fPIC -c $*.c -o $@

all: src/libcgi.so src/libcgi.a

	@echo ""
	@echo ""
	@echo ""
	@echo "+---------------------------------------+"
	@echo "|       Thanks for using LibCGI         |"
	@echo "+---------------------------------------+"
	@echo "| LibCGI is getting better because      |"
	@echo "| people like you are using it. So, if  |"
	@echo "| LibCGI is helping you in some way,    |"
	@echo "| please help us to improve it, sending |"
	@echo "| suggestions, bug reports, bug fixes,  |"
	@echo "| and specially improvment code.        |"
	@echo "| You can subscribe to the mailing list |"
	@echo "| or send a mail to the author.         |"
	@echo "+---------------------------------------+---------------------------+"
	@echo "| List: http://lists.sourceforge.net/lists/listinfo/libcgi-general  |"
	@echo "+-------------------------------------------------------------------+"
	@echo ""


shared: src/libcgi.so
	cp src/libcgi.so $(LIBDIR)

src/libcgi.a: $(OBJS)
	$(AR) rc src/libcgi.a $(OBJS)

src/libcgi.so: $(SHOBJS)
	$(CC) $(SHAREDOPT) -o src/libcgi.so $(SHOBJS) $(EXTRA_LIBS)

install:
	cp src/libcgi.a $(DESTDIR)/$(LIBDIR)
	cp src/libcgi.so $(DESTDIR)/$(LIBDIR)
	[ -d $(DESTDIR)/$(INCDIR) ] || mkdir $(DESTDIR)/$(INCDIR)
	cp src/cgi.h $(DESTDIR)/$(INCDIR)
	cp src/session.h $(DESTDIR)/$(INCDIR)


src/error.o: src/error.c src/error.h
src/cgi.o: src/cgi.c src/cgi.h
src/session.o: src/session.c src/session.h
src/base64.o: src/base64.c
src/md5.o: src/md5.c
src/string.o: src/string.c
src/cookie.o: src/cookie.c
src/general.o: src/general.c
src/list.o: src/list.c

clean:
	find src/ -name *.o -exec rm -f {} \;
	find src/ -name *.a -exec rm -f {} \;
	find src/ -name *.so -exec rm -f {} \;

uninstall: clean
	rm -f $(LIBDIR)/libcgi.*
	rm -f $(INCDIR)/cgi.h
	rm -f $(INCDIR)/session.h
	rm -f $(MANDIR)/libcgi*

#install_man:
#	cp doc/man/man3/libcgi_base64.3 $(MANDIR)
#	cp doc/man/man3/libcgi_cgi.3 $(MANDIR)
#	cp doc/man/man3/libcgi_general.3 $(MANDIR)
#	cp doc/man/man3/libcgi_string.3 $(MANDIR)
#	cp doc/man/man3/libcgi_session.3 $(MANDIR)
#	cp doc/man/man3/libcgi_cookie.3 $(MANDIR)

