# This Makefile is for building the Mod9 ASR C++ Library.
#
# It assumes nlohmann_json can be found in a standard location.
# Otherwise, adjust CPPFLAGS as needed.
#
# This single Makefile can build both the static and shared
# versions of the library by calling either "make static"
# or "make shared". It automatically cleans any previous
# builds to ensure static/shared builds don't get confused.
#
# The Makefile uses many default rules.

# Version of the shared library.
SO_VERSION=1.1.0

CPPFLAGS = -I. -Wall -std=c++11
CC = g++

default : static

shared : clean
shared : CPPFLAGS += -fPIC
shared : libmod9-asr.so.$(SO_VERSION)

static : clean
static : libmod9-asr.a

libmod9-asr.a : mod9-asr.o mod9-io.o
	ar rc $@ $^
	ranlib $@


# The following builds the .so file and makes appropriate symbolic
# links for the versions (e.g. libmod9-asr.so.0 -> libmod9-asr.so.0.1).

libmod9-asr.so.$(SO_VERSION) : mod9-asr.o mod9-io.o
	$(CC) -shared -o $@ $^
	prev=libmod9-asr.so; \
        for v in $(shell echo $(SO_VERSION) | tr . ' '); do \
            ln -sf $$prev.$$v $$prev; \
            prev=$$prev.$$v; \
        done

clean:
	rm -f mod9-asr.o mod9-io.o

distclean: clean
	rm -f libmod9-asr.a libmod9-asr.so libmod9-asr.so.*

# Header dependencies

mod9-asr.o: mod9-asr.h mod9-io.h
mod9-io.o: mod9-io.h
