SOURCE=rp-pppoe-3.8/src

.PHONY: all clean distclean openSource install
all: openSource
clean:
	make -C $(SOURCE) clean

distclean:
	make -C $(SOURCE) distclean
	rm -f $(SOURCE)/.configured
	rm -f $(SOURCE)/Makefile

openSource: $(SOURCE)/.configured
	make -C $(SOURCE)

$(SOURCE)/.configured:
	[ "$$PJ_PREFIX" != "" ]
	[ "$$PJ_TARGET" != "" ]
	[ "$$PJ_HOST" != "" ]
	cd $(SOURCE) \
		 && LDFLAGS='-s' CFLAGS='-Os' ./configure \
			--disable-nls \
		 && sed -re 's/gcc/arm-linux-gcc/' -i Makefile \
		 && sed -re 's/TARGETS=pppoe pppoe-server pppoe-sniff pppoe-relay/TARGETS=pppoe/' -i Makefile
	touch $(SOURCE)/.configured

USR_SBIN := $(PJ_PREFIX)/usr/sbin
install: openSource
	install -d -m 0755 $(USR_SBIN)/
	cp $(SOURCE)/pppoe $(USR_SBIN)/
