# POS

CXX = @g++
ifndef NDEBUG
CXXFLAGS = -g -O0 -Wall -I/users/m4burns/thrift/include -I. -Igen-cpp
else
CXXFLAGS = -O3 -fexpensive-optimizations -ffast-math -fno-math-errno -Wall -I/users/m4burns/thrift/include -I. -Igen-cpp
endif
LDFLAGS = /users/m4burns/thrift/lib/libthriftnb.a /users/m4burns/thrift/lib/libthrift.a -levent

SOURCES = ConfigFile.cpp posdb.cpp db_if.cpp linus_sha1.c log.cpp nameserver.cpp sha1.cpp gen-cpp/pos_constants.cpp gen-cpp/Pos.cpp gen-cpp/pos_types.cpp salt_store.cpp gen-cpp/PosBookie.cpp

CPPOBJECTS = $(patsubst %.cpp,%.o,$(SOURCES))
OBJECTS = $(patsubst %.c,%.o,$(CPPOBJECTS))
CPPDEPS = $(patsubst %.cpp,%.d,$(SOURCES))
DEPS = $(patsubst %.c,%.d,$(CPPDEPS))

SERVER = server
CLIENT = client
DUMP = dump
BOOKIE = bookie
##################################################################

.PHONY : all clean

all : $(SERVER) $(CLIENT) $(DUMP) $(BOOKIE)

%.d : %.cpp
	$(CXX) -MM $(CXXFLAGS) $^ > $@

%.d : %.c
	$(CXX) -MM $(CXXFLAGS) $^ > $@

ifneq ($(MAKECMDGOALS),clean)
-include $(DEPS)
endif

%.o : %.cpp
	$(CXX) $(CXXFLAGS) -c -o $@ $<

%.o : %.c
	$(CXX) $(CXXFLAGS) -c -o $@ $<

$(SERVER) : $(OBJECTS) gen-cpp/Pos_server.skeleton.o
	$(CXX) $(CXXFLAGS) $(OBJECTS) gen-cpp/Pos_server.skeleton.o -o $@ $(LDFLAGS)

$(CLIENT) : $(OBJECTS) client.o
	$(CXX) $(CXXFLAGS) $(OBJECTS) client.o -o $@ $(LDFLAGS)

$(DUMP) : $(OBJECTS) dump.o
	$(CXX) $(CXXFLAGS) $(OBJECTS) dump.o -o $@ $(LDFLAGS)

$(BOOKIE) : $(OBJECTS) gen-cpp/PosBookie_server.skeleton.o
	$(CXX) $(CXXFLAGS) $(OBJECTS) gen-cpp/PosBookie_server.skeleton.o -o $@ $(LDFLAGS)

#################################################################

clean :
	rm -f *.o gen-cpp/*.o $(SERVER) $(CLIENT) $(DUMP) *.d gen-cpp/*.d

