# Semurg C++ SDK. Requires a C++17 compiler and libcurl (libcurl4-openssl-dev).
CXX      ?= g++
CXXFLAGS ?= -std=c++17 -O2 -Wall -Wextra -Iinclude
LDLIBS   ?= -lcurl

BUILD := build
LIB   := $(BUILD)/libsemurg.a
OBJS  := $(BUILD)/http.o $(BUILD)/client.o $(BUILD)/ws.o

.PHONY: all lib example test smoke clean
all: lib example $(BUILD)/frame_test

lib: $(LIB)

$(BUILD):
	mkdir -p $(BUILD)

$(BUILD)/%.o: src/%.cpp | $(BUILD)
	$(CXX) $(CXXFLAGS) -c $< -o $@

$(LIB): $(OBJS)
	ar rcs $@ $(OBJS)

# The example and live smoke test link the library + libcurl.
example: $(BUILD)/health
$(BUILD)/health: examples/health.cpp $(LIB) | $(BUILD)
	$(CXX) $(CXXFLAGS) $< $(LIB) $(LDLIBS) -o $@

smoke: $(BUILD)/smoke_test
$(BUILD)/smoke_test: tests/smoke_test.cpp $(LIB) | $(BUILD)
	$(CXX) $(CXXFLAGS) $< $(LIB) $(LDLIBS) -o $@

# The frame test is header-only (no libcurl).
$(BUILD)/frame_test: tests/frame_test.cpp | $(BUILD)
	$(CXX) $(CXXFLAGS) $< -o $@

# Build and run the offline byte-exactness tests.
test: $(BUILD)/frame_test
	./$(BUILD)/frame_test

clean:
	rm -rf $(BUILD)
