OPENCORE_AMR_VERSION=0.1.6

build/inst/%/lib/pkgconfig/opencore-amrnb.pc: build/opencore-amr-$(OPENCORE_AMR_VERSION)/build-%/config.h
	cd build/opencore-amr-$(OPENCORE_AMR_VERSION)/build-$* && \
		$(MAKE) install

build/opencore-amr-$(OPENCORE_AMR_VERSION)/build-%/config.h: build/opencore-amr-$(OPENCORE_AMR_VERSION)/configure | build/inst/%/cflags.txt
	mkdir -p build/opencore-amr-$(OPENCORE_AMR_VERSION)/build-$*
	cd build/opencore-amr-$(OPENCORE_AMR_VERSION)/build-$* && \
		emconfigure ../../opencore-amr-$(OPENCORE_AMR_VERSION)/configure \
			--prefix="$(PWD)/build/inst/$*" --host=mipsel-sysv \
			--disable-shared \
			CFLAGS="$(OPTFLAGS) `cat $(PWD)/build/inst/$*/cflags.txt`" \
			CXXFLAGS="$(OPTFLAGS) `cat $(PWD)/build/inst/$*/cflags.txt`"
	touch $@

extract: build/opencore-amr-$(OPENCORE_AMR_VERSION)/configure

build/opencore-amr-$(OPENCORE_AMR_VERSION)/configure: build/opencore-amr-$(OPENCORE_AMR_VERSION).tar.gz
	cd build && tar zxf opencore-amr-$(OPENCORE_AMR_VERSION).tar.gz
	touch $@

build/opencore-amr-$(OPENCORE_AMR_VERSION).tar.gz:
	mkdir -p build
	curl https://downloads.sourceforge.net/project/opencore-amr/opencore-amr/opencore-amr-$(OPENCORE_AMR_VERSION).tar.gz -L -o $@

.PRECIOUS: \
	build/inst/%/lib/pkgconfig/opencore-amrnb.pc \
	build/opencore-amr-$(OPENCORE_AMR_VERSION)/build-%/config.h \
	build/opencore-amr-$(OPENCORE_AMR_VERSION)/configure
