LOCAL=$(PWD)/local
ENV=LD_RUN_PATH=$(LOCAL)/lib LD_LIBRARY_PATH=$(LOCAL)/lib CPATH=$(LOCAL)/include

all: libdwarf libcxxfileno libsrk31cxx libdwarfpp

.PHONY: local
local:
	mkdir -p $(LOCAL)/include $(LOCAL)/lib/pkgconfig

.PHONY: libdwarf libcxxfileno libsrk31cxx libdwarfpp

libdwarf: local
	cd $@ && $(ENV) ./configure --prefix=$(LOCAL) --enable-shared
	$(ENV) $(MAKE) -C $@
	cp $@/libdwarf/libdwarf.a $@/libdwarf/libdwarf.so $(LOCAL)/lib
	cp $@/libdwarf/libdwarf.h $@/libdwarf/dwarf.h $(LOCAL)/include

libcxxfileno: local
	cd $@ && libtoolize && autoreconf -i && $(ENV) ./configure --prefix=$(LOCAL)
	$(ENV) $(MAKE) -C $@
	$(ENV) $(MAKE) -C $@ install

libsrk31cxx: local libcxxfileno
	cd $@ && libtoolize && autoreconf -i && ./configure --prefix=$(LOCAL)
	$(ENV) $(MAKE) -C $@
	$(ENV) $(MAKE) -C $@ install

libdwarfpp: local libdwarf libsrk31cxx libcxxfileno
	cd $@ && autoreconf -i
	cd $@ && \
		LIBCXXFILENO_CXXFLAGS=" " \
		LIBSRK31CXX_CXXFLAGS=" " \
		LIBCXXFILENO_LIBS="-lc++fileno" \
		LIBSRK31CXX_LIBS="-lsrk31c++" \
		$(ENV) \
		./configure --prefix=$(LOCAL) \
			--with-libdwarf-includes="$(LOCAL)/include" \
			--with-libdwarf-libs="$(LOCAL)/lib"
	$(ENV) $(MAKE) -C $@
	$(ENV) $(MAKE) -C $@ install
