# Make sure we export all our variables, even to the kplot/Makefile,
# which was not generated by autotools.
export

# Trick to run the build rules of current Makefile before the subdir
# ones, so that we can move the files (see below) first.
SUBDIRS = . \
		  kplot

# This is a very ugly trick because kplot tree was just copied as is
# with a raw Makefile. So let's just copy the whole source before
# compiling if the build dir is different to the source dir.
all-local:
	if [ ! -f "$(top_builddir)/subprojects/kplot/Makefile" ]; then \
		cp -fr "$(top_srcdir)/subprojects/kplot" "$(top_builddir)/subprojects/kplot"; \
	fi

if !HAVE_LIBRTPROCESS
# not adding it in subdirs because we don't want to run most targets in it, and specifying
# the rtprocess_static target allows us to build only the static lib we link against
build-librtprocess:
	mkdir -p $(abs_builddir)/librtprocess/build && \
	cd $(abs_builddir)/librtprocess/build && \
	ls $(abs_srcdir)/librtprocess/ && \
	$(CMAKE) $(CMAKE_GENERATOR) -DCMAKE_BUILD_TYPE="Release" -DBUILD_SHARED_LIBS=OFF -DOPTION_OMP=OFF $(abs_srcdir)/librtprocess/ && \
	$(MAKE)

clean-librtprocess:
	rm -f $(abs_builddir)/librtprocess/build/CMakeCache.txt

all: build-librtprocess
clean: clean-librtprocess
endif

if !HAVE_HTMESH
# not adding it in subdirs because we don't want to run most targets in it, and specifying
# the htmesh target allows us to build only the static lib we link against
build-htmesh:
	mkdir -p $(abs_builddir)/htmesh/build && \
	cd $(abs_builddir)/htmesh/build && \
	ls $(abs_srcdir)/htmesh/ && \
	$(CMAKE) $(CMAKE_GENERATOR) -DCMAKE_BUILD_TYPE="Release" -DCMAKE_CXX_FLAGS="-Wno-psabi -I$(abs_srcdir)/htmesh" $(abs_srcdir)/htmesh/ && \
	$(MAKE)

clean-htmesh:
	rm -f $(abs_builddir)/htmesh/build/CMakeCache.txt

all: build-htmesh
clean: clean-htmesh
endif

if !HAVE_HEALPIX_CXX
# not adding it in subdirs because we don't want to run most targets in it, and specifying
# the healpix target allows us to build only the static lib we link against
build-healpix:
	mkdir -p $(abs_builddir)/healpix_cxx/build && \
	cd $(abs_builddir)/healpix_cxx/build && \
	ls $(abs_srcdir)/healpix_cxx/ && \
	$(CMAKE) $(CMAKE_GENERATOR) -DCMAKE_BUILD_TYPE="Release" -DCMAKE_CXX_FLAGS="-Wno-psabi -I$(abs_srcdir)/healpix_cxx" $(abs_srcdir)/healpix_cxx/ && \
	$(MAKE)

clean-healpix:
	rm -f $(abs_builddir)/healpix_cxx/build/CMakeCache.txt

all: build-healpix
clean: clean-healpix
endif
