# -*- makefile -*-

# Adjust these to reflect where you've installed gnulib.
GNULIB = ../gnulib
GNULIB_TOOL = $(GNULIB)/gnulib-tool

GNULIB_MODULES = \
	assert \
	byteswap \
	c-strcase \
	c-strcasestr \
	c-ctype \
	c-strtod \
	clean-temp \
	close \
	configmake \
	count-one-bits \
	crc \
	crypto/md4 \
	crypto/md5 \
	dirname \
	dtoastr \
	environ \
	fatal-signal \
	fcntl \
	fpieee \
	fprintf-posix \
	full-read \
	full-write \
        fseeko \
        ftello \
	fwriteerror \
	getline \
	gettext \
	gettimeofday \
        getopt-gnu \
	gitlog-to-changelog \
	include_next \
	isfinite \
	isinf \
	isnan \
	intprops \
	inttostr \
	localcharset \
        mbchar \
        mbiter \
	memcasecmp \
	memchr \
	mempcpy \
	memrchr \
	minmax \
	mkdtemp \
	mkstemp \
	printf-posix \
	printf-safe \
	progname \
	rawmemchr \
	read-file \
	regex \
	relocatable-prog \
	rename \
	round \
	snprintf \
	snprintf-posix \
	sprintf-posix \
	stdarg \
	stdbool \
	stdint \
	stpcpy \
	strerror \
	strftime \
	strtod \
	strtok_r \
	sys_stat \
	tempname \
	trunc \
	unictype/ctype-print \
	unictype/property-id-continue \
	unictype/property-id-start \
	unigbrk/uc-is-grapheme-break \
	unilbrk/u8-possible-linebreaks \
	unistd \
	unistr/u8-check \
	unistr/u8-cpy \
	unistr/u8-mblen \
	unistr/u8-mbtouc \
	unistr/u8-mbtoucr \
	unistr/u8-strlen \
	unistr/u8-strmbtouc \
	unistr/u8-strncat \
	unistr/u8-uctomb \
	uniwidth/u8-strwidth \
	unitypes \
	unlocked-io \
	vasprintf-posix \
	version-etc \
	version-etc-fsf \
	vfprintf-posix \
	vprintf-posix \
	vsnprintf \
	vsnprintf-posix \
	vsprintf-posix \
	xalloc \
	xalloc-die \
	xmalloca \
	xmemdup0 \
	xsize \
	xstrndup \
	xvasprintf

all: prep_ph
	$(MAKE) -f Smake Makefile.in configure

.PHONY: prep_ph
prep_ph: 
	test -e ChangeLog || touch ChangeLog
	test -d m4 || mkdir m4
	touch m4/Makefile.am
	$(GNULIB_TOOL) --add-import --no-changelog --m4-base=gl/m4 \
		--source-base=gl --lib=libgl --tests-base=tests \
		--doc-base=gl/doc --aux-dir=build-aux  \
		--libtool $(GNULIB_MODULES)
	libtoolize --force --automake

aclocal.m4:
	aclocal -I m4 -I gl/m4

configure: configure.ac aclocal.m4
	autoconf

config.h.in: configure.ac
	autoheader

Makefile.in: Makefile.am config.h.in aclocal.m4
	automake --add-missing --copy --no-force --include-deps


gettextize:
	test -d m4 || mkdir m4
	touch m4/Makefile.am
	gettextize --force --no-changelog

check: all
	rm -rf _check
	mkdir _check
	cd _check && ../configure $(CONFIGUREFLAGS)
	cd _check && make distcheck
	rm -rf _check

_build: all
	test -d _build || mkdir _build
	cd _build && ../configure $(CONFIGUREFLAGS)

_debug: all
	test -d _debug || mkdir _debug
	cd _debug && ../configure $(CONFIGUREFLAGS) --enable-debug

PO_FILES = po/ChangeLog \
po/Rules-quot po/boldquot.sed		\
po/cat-id-tbl.c po/en@boldquot.header po/en@quot.header			\
po/insert-header.sin po/quot.sed po/remove-potcdate.sin po/stamp-po	\
po/Makevars.template po/pspp.pot

clean:
	rm -f config.sub config.guess config.rpath
	rm -fr autom4te.cache
	rm -f aclocal.m4
	rm -f missing mkinstalldirs
	rm -f install-sh
	rm -f configure Makefile 
	rm -f depcomp
	rm -rf intl gl
	rm -f m4/*.m4
	rm -f $(PO_FILES) po/*.gmo 
	rm -f mdate-sh texinfo.tex
	rm -f doc/stamp-vti
	rm -f config.h.in~
	rm -f config.h.in
	find . -name Makefile.in -exec rm -f {} \; 
	rm -f compile
	rm -f ltmain.sh
	rm -f reloc-ldflags install-reloc

.PHONY: all gettextize clean
