# Makefile for VgaGames: extlib/
 
# PREFIX is tempinstall-path

all: prefix_dirs sml3.d iolib.d flac.d mp3.d ogg.d tmidi.d

install:
	mkdir -p "$(DESTDIR)/libexec" || true
	cp -a $(PREFIX)/bin/* $(DESTDIR)/libexec/ 2>/dev/null || true
	rm -f $(DESTDIR)/libexec/*-config
	# don't copy iolib-libraries, just if one was compiled and then name it libIOlib.so
	{ io_lib=`PREFIX=$(PREFIX) ./config.sh install`; \
	  test "$$io_lib" = "" && true || cp $$io_lib $(DESTDIR)/libexec/libIOlib.so; \
	}
	cp iolib-script $(DESTDIR)/libexec/

clean:
	cd tmidi && $(MAKE) clean || true
	cd ogg && MAKE="$(MAKE)" ./make.sh clean || true
	cd mp3 && $(MAKE) clean || true
	cd flac && MAKE="$(MAKE)" ./make.sh clean || true
	{ cd iolib && for vz in `ls`; do (cd $$vz && MAKE="$(MAKE)" ./make.sh clean); done; } || true
	cd sml3 && $(MAKE) clean || true
	test "x$(PREFIX)" = "x" && true || rm -rf "$(PREFIX)"
	rm -f iolib-script disable.* ext.libs


prefix_dirs:
	mkdir -p "$(PREFIX)" || true
	mkdir -p "$(PREFIX)/lib" || true
	mkdir -p "$(PREFIX)/bin" || true

sml3.d:
	cd sml3 && $(MAKE) PREFIX="$(PREFIX)" CC="$(CC)" a install
	echo -n " -lsml3" >>ext.libs

iolib.d:
	MAKE="$(MAKE)" PREFIX="$(PREFIX)" CC="$(CC)" ./config.sh make

flac.d:
	test -f disable.flac && true || { cd flac && MAKE="$(MAKE)" PREFIX="$(PREFIX)" CC="$(CC)" ./make.sh all && echo -n " -lFLAC" >>../ext.libs; }

mp3.d:
	test -f disable.mp3 && true || { cd mp3 && $(MAKE) PREFIX="$(PREFIX)" CC="$(CC)" CFLAGS="$(CFLAGS)" all; }

ogg.d:
	test -f disable.ogg && true || { cd ogg && MAKE="$(MAKE)" PREFIX="$(PREFIX)" CC="$(CC)" ./make.sh all; }

tmidi.d:
	test -f disable.midi && true || { cd tmidi && $(MAKE) PREFIX="$(PREFIX)" CC="$(CC)" CFLAGS="$(CFLAGS)" all; }

