include $(MAKETOP)/usr/src/GNUtoolchain

SUBDIRS = expat-2.1.0
CONFIGURE_SUBDIRS = $(patsubst %,configure-%,$(SUBDIRS))
INST_SUBDIRS = $(patsubst %,install-%,$(SUBDIRS))
CLEAN_SUBDIRS = $(patsubst %,clean-%,$(SUBDIRS))

ifeq (arm,$(GNUCC_ARCH))
SYSROOT="--sysroot=$(MAKETOP)"
CFLAGS="--sysroot=$(MAKETOP) -g -O2 $(GNUCC_ARCH_CFLAGS_EXTRA)"
CPPFLAGS=$(CFLAGS)
LDFLAGS="$(SYSROOT) -Wl,-rpath,/usr/pana/lib:/lib:/usr/lib:/usr/local/lib:/usr/pana/lib"
endif

all: $(SUBDIRS)

$(SUBDIRS): configure
	$(MAKE) -C $@ all

configure: $(CONFIGURE_SUBDIRS)

$(CONFIGURE_SUBDIRS):
	dir=`echo $@ |sed -e 's/configure-//'`;			\
	if test ! -f $$dir/Makefile; then			\
		touch-autotools.scm $${dir};			\
		(cd $${dir}; makeconf; CFLAGS=$(CFLAGS) CPPFLAGS=$(CPPFLAGS) LDFLAGS=$(LDFLAGS) ./configure --host=$(GNUCC_HOST)	\
		 --build=`./config.guess`			\
		 --prefix=$(CROSS_C_ROOT_PATH)/usr		\
		 --with-pic					\
		 ;						\
		 sed -i 's|^hardcode_libdir_flag_spec=.*|hardcode_libdir_flag_spec=""|g' libtool; \
		 sed -i 's|^runpath_var=LD_RUN_PATH|runpath_var=DIE_RPATH_DIE|g' libtool; \
		)						\
	fi;

install: $(INST_SUBDIRS)

$(INST_SUBDIRS): configure
	dir=`echo $@ |sed -e 's/install-//'`;			\
	$(MAKE) -C $${dir} install
	$(RM) -f $(CROSS_C_ROOT_PATH)/usr/lib/libexpat.la

clean: $(CLEAN_SUBDIRS)

$(CLEAN_SUBDIRS): configure
	dir=`echo $@ |sed -e 's/clean-//'`;			\
	$(MAKE) -C $${dir} clean;				\
	$(RM) -f $${dir}/Makefile


.PHONY:	all configure install clean $(SUBDIRS) $(CONFIGURE_SUBDIRS) $(INST_SUBDIRS) $(CLEAN_SUBDIRS)
