builddir_inc=@OMBUILDDIR@/include
buildbin=@OMBUILDDIR@/bin
buildlib=@OMBUILDDIR@/lib/@host_short@/omc

prefix = @prefix@
exec_prefix = @exec_prefix@
bindir = @bindir@
bindir = @includedir@
libdir = @libdir@/@host_short@/omc

omplot: mkbuilddirs qwt
	$(MAKE) -C OMPlot/OMPlotGUI -f Makefile.unix
	cp -a OMPlot/OMPlotGUI/*.h @OMBUILDDIR@/include/omplot

.PHONY: install

$(buildlib)/libomqwt.so: mkbuilddirs qwt-build
	cp -a qwt/lib/libomqwt.so* $(buildlib)/
$(buildlib)/libomqwt.dylib: mkbuilddirs qwt-build
	cp -a qwt/lib/libomqwt*dylib $(buildlib)/
	install_name_tool -id @rpath/libomqwt.6.1.5.dylib $(buildlib)/libomqwt.6.1.5.dylib

install:
ifeq (@APP@,)
	mkdir -p ${DESTDIR}/@bindir@
	cp -a @OMBUILDDIR@/bin/OMPlot@EXE@ ${DESTDIR}/@bindir@
else
	mkdir -p ${DESTDIR}/Applications/
	cp -a @OMBUILDDIR@/bin/OMPlot@APP@ ${DESTDIR}/Applications/
endif
	mkdir -p ${DESTDIR}/$(libdir) ${DESTDIR}/$(includedir)/omplot/qwt
	cp -a $(buildlib)/* ${DESTDIR}/$(libdir)
	cp -a $(builddir_inc)/omplot/qwt ${DESTDIR}/$(includedir)/omplot
	cp -a OMPlot/OMPlotGUI/*.h ${DESTDIR}/$(includedir)/omplot

qwt: $(buildlib)/libomqwt@SHREXT@

qwt-build: mkbuilddirs
	$(MAKE) -C qwt -f Makefile.unix
	test -f $(builddir_inc)/omplot/qwt/qwt_global.h || ($(MAKE) -C qwt install && chmod 644 qwt/build/include/*.h && cp -a qwt/build/include/*.h $(builddir_inc)/omplot/qwt)

mkbuilddirs:
	mkdir -p $(builddir_inc)/omplot/qwt
	mkdir -p $(buildlib)
	mkdir -p $(buildbin)

clean:
	$(MAKE) -C qwt -f Makefile.unix clean
	$(MAKE) -C OMPlot/OMPlotGUI -f Makefile.unix clean
Makefile: Makefile.in config.status
	./config.status

config.status: configure
	./config.status --recheck

configure: configure.ac common/m4/*.m4
	autoconf
