all:	cavacheck sync_master .make_last_install

# Make sure that the CAVA environment is set up.

cavacheck:
	@rc=0 ;                                          \
	if [ "x${CAVA}" = "x" ] ; then                   \
	    echo CAVA not set ;                          \
	    rc=$$(( $$rc + 1 )) ;                        \
	fi ;                                             \
	if ( echo ${PATH} | grep -vq ${CAVA}/bin) ; then    \
	    echo ${CAVA}/bin is not in the PATH ;           \
	    rc=$$(( $$rc + 2 )) ;                        \
	fi ;                                             \
	if ( echo ${PATH} | grep -vq ${CAVA}/tools ) ; then \
	    echo ${CAVA}/tools is not in the PATH ;         \
	    rc=$$(( $$rc + 4 )) ;                        \
	fi ; exit $$rc

# If CAVABUILD has a value, use the new scheme for build directories.
# Otherwise, use the old scheme.
#
ifeq ($(CAVABUILD),)
  BUILD_DIR = ../../glibc/make
else
  BUILD_DIR = ${CAVABUILD}/glibc
endif

$(BUILD_DIR):
	mkdir -p $(BUILD_DIR)

.make_last_install:	.diffcp_last_updated $(BUILD_DIR) $(BUILD_DIR)/Makefile
	make -C $(BUILD_DIR)/
#	make      -C $(BUILD_DIR)/
#	make -C $(BUILD_DIR)/ install
	touch .make_last_install

sync_master:
	diffcp sysdeps	$(CAVA)/glibc-2.9/src/sysdeps/cava
	diffcp linux	$(CAVA)/glibc-2.9/src/sysdeps/unix/sysv/linux/cava

$(BUILD_DIR)/Makefile:
	mkdir -p $(BUILD_DIR)/linuxthreads
	touch $(BUILD_DIR)/linuxthreads/stamp.o
	cd  $(BUILD_DIR);						\
	CC=cava-linux-gcc CFLAGS='-O -g' ${CAVA}/glibc-2.9/src/configure	\
		--build=i386-gnu-linux					\
		--target=cava-linux					\
		--host=cava-linux					\
		--prefix=${CAVA}					\
		--with-binutils=${CAVA}/cava-linux/bin			\
		--with-headers=/usr/include				\
		--disable-shared					\
		--disable-profile					\
		--disable-sanity-checks                                 \
		--disable-threads                                       \
		--disable-tls						\
		--disable-bootstrap					\
		--disable-multilib					\
		--disable-libssp					\
		--disable-libgomp					\
		--disable-decimal-float					\
		--disable-fixed-point					\
		--disable-nls						\
		--enable-languages=c					\


.diffcp_last_updated:
	touch .diffcp_last_updated

rebuild:
	rm -rf $(BUILD_DIR)


#	CC=cava-linux-gcc CFLAGS='-O0 -g -fno-inline' ${CAVA}/glibc/src/configure \

$(BUILD_DIR):
	mkdir -p $(BUILD_DIR)
