
ifeq "${MP_CONFIG}" ""
MP_CONFIG := $(shell if test -x ../../metaproxy/metaproxy-config; then echo ../../metaproxy/metaproxy-config; else echo metaproxy-config; fi)
endif

#MP_INTERNAL_INCLUDES = -I ../../metaproxy/src
# ### This isn't right, but we need access to some filters for creating a 
# proper filter chain for testing!

MP_CFLAGS := $(shell $(MP_CONFIG) --cflags) -fPIC  -g 
# $(MP_INTERNAL_INCLUDES)
MP_LIBS := $(shell $(MP_CONFIG) --libs)

MP_SO = metaproxy_filter_cproxy.so

$(MP_SO): filter_cproxy.cpp
	$(CXX) -shared $(CXXFLAGS) $(MP_CFLAGS) $< -o $(MP_SO) $(MP_LIBS)

TEST1 = test_filter_cproxy
$(TEST1): $(TEST1).cpp $(MP_SO)
	$(CXX)  $(CXXFLAGS) $(MP_CFLAGS) $< -o $(TEST1) $(MP_LIBS) ./$(MP_SO)


clean:
	rm -f $(MP_SO) $(TEST1) *~ core ../test/*~ ../test/debug*.log ../test/core ../test/integrationtest/core ../test/integrationtest/debug*log ../test/integrationtest/*~
	rm -rf cf.???.dump cf.???.p cf.???

check: unittest

unittest: $(TEST1)
	rm -rf cf.???.dump cf.???.p cf.???
	./$(TEST1) --test-verbose 2 --test-stop

install: $(MP_SO)
	mkdir -p $(DESTDIR)/etc/cf-proxy
	cd ../etc/; cp cproxy.cfg cproxyrewrite.xml cf-proxy.route.xml cf-proxy.port.xml $(DESTDIR)/etc/cf-proxy/
	mkdir -p $(DESTDIR)$(libdir)/cf-proxy
	cp $(MP_SO) $(DESTDIR)$(libdir)/cf-proxy
	rm -rf /tmp/cf.[0-9][0-9]*   # Old session files, wrong owners


