CCompiler=gcc


OBJS=common.o socket.o rle.o lz.o compress_decompress_engine.o \
	stats.o message.o ingress_thread.o egress_thread.o   \
	cli_parser.o file_parser.o bucket.o qos.o web.o 

HEADERS=common.h socket.h rle.h lz.h compress_decompress_engine.h \
        stats.h message.h ingress_thread.h egress_thread.h   \
        cli_parser.h file_parser.h bucket.h qos.h web.h



all: swill trafficsqueezer


common.o:
	$(CCompiler) -Wall -c common.c

socket.o:
	$(CCompiler) -Wall -c socket.c

rle.o:
	$(CCompiler) -Wall -c rle.c

lz.o:
	$(CCompiler) -Wall -c lz.c

compress_decompress_engine.o:
	$(CCompiler) -Wall -c compress_decompress_engine.c

stats.o:
	$(CCompiler) -Wall -c stats.c

message.o:
	$(CCompiler) -Wall -c message.c

ingress_thread.o: bucket.o
	$(CCompiler) -Wall -c ingress_thread.c

egress_thread.o:
	$(CCompiler) -Wall -c egress_thread.c

cli_parser.o:
	$(CCompiler) -Wall -c cli_parser.c

file_parser.o:
	$(CCompiler) -Wall -c file_parser.c

bucket.o:
	$(CCompiler) -Wall -c bucket.c

qos.o:
	$(CCompiler) -Wall -c qos.c

web.o:
	$(CCompiler) -Wall -c web.c



trafficsqueezer.o: $(HEADERS) trafficsqueezer.c
	$(CCompiler) -Wall -c trafficsqueezer.c
	


trafficsqueezer: $(OBJS) trafficsqueezer.o
	rm -rf ./trafficsqueezer
	cp ./trafficsqueezer-swill-1.0/libswill.* /lib/.
	$(CCompiler) -Wall -o ./bin/trafficsqueezer $(OBJS) trafficsqueezer.o -lpthread -lswill
	ln -s ./bin/trafficsqueezer trafficsqueezer


swill:
	cd ./trafficsqueezer-swill-1.0; $(MAKE) all
	cd ./trafficsqueezer-swill-1.0; $(MAKE) install

install:
	cp ./trafficsqueezer-swill-1.0/libswill.* /lib/.
	cp ./bin/trafficsqueezer /sbin/.
	rm -rf /etc/trafficsqueezer
	mkdir /etc/trafficsqueezer
	cp ./config/trafficsqueezer.cfg /etc/trafficsqueezer/.
	rm -rf /usr/share/trafficsqueezer
	mkdir /usr/share/trafficsqueezer
	cp -r ./web /usr/share/trafficsqueezer/web
	rm -rf /var/log/trafficsqueezer
	mkdir /var/log/trafficsqueezer
	touch /var/log/trafficsqueezer/clf.log


clean:
	rm -f /lib/libswill.*
	rm -f  ./*.o ./bin/trafficsqueezer ./trafficsqueezer
	rm -rf /etc/trafficsqueezer
	rm -f /sbin/trafficsqueezer
	cd ./trafficsqueezer-swill-1.0; $(MAKE) clean
	rm -rf /usr/share/trafficsqueezer/web
	rm -rf /var/log/trafficsqueezer


uninstall:
	rm -f /lib/libswill.*
	rm -rf /etc/trafficsqueezer
	rm -f /sbin/trafficsqueezer
	rm -rf /usr/share/trafficsqueezer/web
	rm -rf /var/log/trafficsqueezer



