

CXXLINK = $(CXX) $(CXXFLAGS) $(LDFLAGS) -o $@
LDFLAGS = @LDFLAGS@
LDADD = @arch_ld_flags@
LIBS = @LIBS@

PREFIX = /usr
PDLIBDIR = $(PREFIX)/lib/pd
DOCBASE = /share/doc

TARG_DIR=Manips  Particles Base MarkEx Pixes Controls Nongeos  Geos Gige
OBJECTS =../Manips/*.o \
         ../Particles/*.o \
         ../Base/*.o \
         ../MarkEx/*.o \
         ../Pixes/*.o \
         ../Controls/*.o \
         ../Nongeos/*.o \
         ../Geos/*.o \
         ../Gige/*.o


all: subdirs Gem.pd

Gem.pd: $(OBJECTS) $(Gem_pd_DEPENDENCIES)
	@rm -f Gem.pd
	$(CXXLINK) $(LDFLAGS) $(OBJECTS) $(LDADD) $(LIBS)
	cp Gem.pd ../../Gem.pd_linux


subdirs:
	for d in ${TARG_DIR}; do \
	    echo ""\
	    echo "----------$$d----------"; \
	    cd ../$$d && ${MAKE} || exit -1; \
	done


depend:
	@for d in ${TARG_DIR}; do \
	    echo "\n----------$$d----------"; \
	    cd ../$$d ; ${MAKE} depend; cd ../Gnu; \
	done


clean:
	@for d in ${TARG_DIR}; do \
	    echo "\n----------$$d----------"; \
	    cd ../$$d ; ${MAKE} clean;cd ../Gnu; \
	done
	-rm Gem.pd ../../Gem.pd_linux *~


install: installdocs
	install -m644 -D ../../Gem.pd_linux $(DESTDIR)/$(PDLIBDIR)/externs/Gem.pd_linux


installdocs:
	install -d $(DESTDIR)/$(PREFIX)/$(DOCBASE)/gem
	install -m644 ../../doc/* $(DESTDIR)/$(PREFIX)/$(DOCBASE)/gem

	install -d $(DESTDIR)/$(PDLIBDIR)/doc/5.reference
	install -m644 ../../help/* $(DESTDIR)/$(PDLIBDIR)/doc/5.reference

	cp -r ../../examples $(DESTDIR)/$(PREFIX)/$(DOCBASE)/gem
	cp -r ../../manual $(DESTDIR)/$(PREFIX)/$(DOCBASE)/gem

	ln -s ../../../$(DOCBASE)/gem $(DESTDIR)/$(PDLIBDIR)/doc/

distclean: clean
	@for d in ${TARG_DIR}; do \
	    echo "\n----------$$d----------"; \
	    cd ../$$d ; ${MAKE} distclean;cd ../Gnu; \
	done
	-rm config.cache config.log config.status Makefile
	./makeauxlibs clean


