include $(MAKETOP)/usr/src/GNUtoolchain

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

ifeq (arm,$(GNUCC_ARCH))
SYSROOT="--sysroot=$(MAKETOP)"
CFLAGS="$(SYSROOT) -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};					\
		 makedonf;					\
		 rm -f arm-linux.cache;				\
		 cp ../arm-linux.cache .;			\
		 chmod a-w arm-linux.cache;			\
		 CFLAGS=$(CFLAGS) CPPFLAGS=$(CPPFLAGS) LDFLAGS=$(LDFLAGS)	\
		 ./configure --host=$(GNUCC_PREFIX)		\
		 --build=`./config.guess`			\
		 --prefix=$(CROSS_C_ROOT_PATH)/usr		\
		 --disable-silent-rules				\
		 --enable-static				\
		 --enable-shared				\
		 --disable-fam					\
		 --cache-file=arm-linux.cache			\
		 ;						\
		 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

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)
