# -*- makefile -*-
# This is the developer's makefile, not the user's makefile.
# Don't use it unless you know exactly what you do!

SHELL = /bin/sh
MAKE = make
AUTOCONF = autoconf-2.57
AUTOHEADER = autoheader-2.57
AUTOMAKE = automake-1.7
GPERF = gperf
CC = gcc
CFLAGS = -O
MAN2HTML = groff -mandoc -Thtml
CP = cp
RM = rm -f


all : configures config.h.in srclib/Makefile.in config.h_vms config.h.msvc lib/config.h_vms lib/config.h.msvc include/iconv.h_vms include/iconv.h.msvc-static include/iconv.h.msvc-shared lib/aliases.h lib/aliases_aix.h lib/aliases_osf1.h lib/aliases_dos.h lib/aliases_extra.h lib/flags.h lib/translit.h man/iconv.1.html man/iconv.3.html man/iconv_close.3.html man/iconv_open.3.html po/Makefile.msvc force
	cd libcharset && $(MAKE) -f Makefile.devel all


# Before making a new release:
# - check that the encoding lists in README and man/iconv_open.3 are up to date,
# - increment the version number in
#     include/iconv.h.in
#     README
#     windows/iconv.rc
#     djgpp/README
#     djgpp/fnchange.lst
#     libcharset/djgpp/README
#     libcharset/djgpp/fnchange.lst
# - update the version info in lib/Makefile.in,
# - do "make -f Makefile.devel".


CONFIGURES = configure
CONFIGURES_IN = configure.in

#CLISP_DIR = ..
#m4/general.m4 : $(CLISP_DIR)/src/m4/general.m4 ; cp -p $< $@-t && mv $@-t $@
#m4/proto.m4 : $(CLISP_DIR)/src/m4/proto.m4 ; cp -p $< $@-t && mv $@-t $@
#m4/cp.m4 : $(CLISP_DIR)/src/m4/cp.m4 ; cp -p $< $@-t && mv $@-t $@
#m4/ln.m4 : $(CLISP_DIR)/src/m4/ln.m4 ; cp -p $< $@-t && mv $@-t $@
#m4/endian.m4 : $(CLISP_DIR)/src/m4/endian.m4 ; cp -p $< $@-t && mv $@-t $@
#m4/libtool.m4 : $(CLISP_DIR)/src/m4/libtool.m4 ; cp -p $< $@-t && mv $@-t $@

aclocal.m4 : m4/general.m4 m4/proto.m4 m4/cp.m4 m4/ln.m4 m4/codeset.m4 m4/eilseq.m4 m4/endian.m4 m4/glibc21.m4 m4/isc-posix.m4 m4/lcmessage.m4 m4/alloca.m4 m4/canonicalize.m4 m4/error.m4 m4/mbstate_t.m4 m4/onceonly.m4 m4/pathmax.m4 m4/relocatable.m4 m4/setenv.m4 m4/stdbool.m4 m4/strerror.m4 m4/strerror_r.m4 m4/unlocked-io.m4 m4/xreadlink.m4  m4/libtool.m4  m4/gettext.m4 m4/iconv.m4 m4/lib-ld.m4 m4/lib-link.m4 m4/lib-prefix.m4 m4/nls.m4 m4/po.m4 m4/progtest.m4
	aclocal -I m4 --output=$@

configures : $(CONFIGURES)

AUTOCONF_FILES = aclocal.m4

configure : configure.in $(AUTOCONF_FILES)
	$(AUTOCONF)

check-configures : $(CONFIGURES)
	set -e; for f in $(CONFIGURES); do bash -x -n $$f; done

config.h.in : configure.in $(AUTOCONF_FILES)
	$(AUTOHEADER)
	touch $@


srclib/Makefile.in : srclib/Makefile.am
	$(AUTOMAKE) --gnits srclib/Makefile


config.h_vms : config.h.in
	sed -e 's/#undef ENABLE_NLS$$/#define ENABLE_NLS 1/' \
	    -e 's/#undef ENABLE_RELOCATABLE$$/#define ENABLE_RELOCATABLE 1/' \
	    -e 's/#undef HAVE_ALLOCA$$/#define HAVE_ALLOCA 1/' \
	    -e 's/#undef HAVE_DECL_STRERROR$$/#define HAVE_DECL_STRERROR 1/' \
	    -e 's/#undef HAVE_DLFCN_H$$/#define HAVE_DLFCN_H 1/' \
	    -e 's/#undef HAVE_ERRNO_DECL$$/#define HAVE_ERRNO_DECL 1/' \
	    -e 's/#undef HAVE_GETCWD$$/#define HAVE_GETCWD 1/' \
	    -e 's/#undef HAVE_ICONV$$/#define HAVE_ICONV 1/' \
	    -e 's/#undef HAVE_INTTYPES_H$$/#define HAVE_INTTYPES_H 1/' \
	    -e 's/#undef HAVE_LANGINFO_CODESET$$/#define HAVE_LANGINFO_CODESET 1/' \
	    -e 's/#undef HAVE_LIMITS_H$$/#define HAVE_LIMITS_H 1/' \
	    -e 's/#undef HAVE_LOCALE_H$$/#define HAVE_LOCALE_H 1/' \
	    -e 's/#undef HAVE_MBRTOWC$$/#define HAVE_MBRTOWC 1/' \
	    -e 's/#undef HAVE_MBSINIT$$/#define HAVE_MBSINIT 1/' \
	    -e 's/#undef HAVE_MEMMOVE$$/#define HAVE_MEMMOVE 1/' \
	    -e 's/#undef HAVE_MEMORY_H$$/#define HAVE_MEMORY_H 1/' \
	    -e 's/#undef HAVE_SETENV$$/#define HAVE_SETENV 1/' \
	    -e 's/#undef HAVE_SETLOCALE$$/#define HAVE_SETLOCALE 1/' \
	    -e 's/#undef HAVE_STDBOOL_H$$/#define HAVE_STDBOOL_H 1/' \
	    -e 's/#undef HAVE_STDDEF_H$$/#define HAVE_STDDEF_H 1/' \
	    -e 's/#undef HAVE_STDLIB_H$$/#define HAVE_STDLIB_H 1/' \
	    -e 's/#undef HAVE_STRERROR$$/#define HAVE_STRERROR 1/' \
	    -e 's/#undef HAVE_STRINGS_H$$/#define HAVE_STRINGS_H 1/' \
	    -e 's/#undef HAVE_STRING_H$$/#define HAVE_STRING_H 1/' \
	    -e 's/#undef HAVE_SYS_PARAM_H$$/#define HAVE_SYS_PARAM_H 1/' \
	    -e 's/#undef HAVE_SYS_STAT_H$$/#define HAVE_SYS_STAT_H 1/' \
	    -e 's/#undef HAVE_SYS_TYPES_H$$/#define HAVE_SYS_TYPES_H 1/' \
	    -e 's/#undef HAVE_UNISTD_H$$/#define HAVE_UNISTD_H 1/' \
	    -e 's/#undef HAVE_UNSETENV$$/#define HAVE_UNSETENV 1/' \
	    -e 's/#undef HAVE_VPRINTF$$/#define HAVE_VPRINTF 1/' \
	    -e 's/#undef HAVE_WCHAR_H$$/#define HAVE_WCHAR_H 1/' \
	    -e 's/#undef HAVE_WCRTOMB$$/#define HAVE_WCRTOMB 1/' \
	    -e 's/#undef ICONV_CONST$$/#define ICONV_CONST/' \
	    -e 's/#undef STDC_HEADERS$$/#define STDC_HEADERS 1/' \
	    -e 's/#undef WORDS_LITTLEENDIAN$$/#define WORDS_LITTLEENDIAN 1/' \
	    -e 's/#undef realpath$$/#define realpath rpl_realpath/' \
	    -e '/#undef INSTALLPREFIX$$/d' \
	  < $< > $@

config.h.msvc : config.h.in
	sed -e 's/#undef ENABLE_RELOCATABLE$$/#define ENABLE_RELOCATABLE 1/' \
	    -e 's/#undef HAVE_ALLOCA$$/#define HAVE_ALLOCA 1/' \
	    -e 's/#undef HAVE_DECL_STRERROR$$/#define HAVE_DECL_STRERROR 1/' \
	    -e 's/#undef HAVE_ENVIRON_DECL$$/#define HAVE_ENVIRON_DECL 1/' \
	    -e 's/#undef HAVE_ERRNO_DECL$$/#define HAVE_ERRNO_DECL 1/' \
	    -e 's/#undef HAVE_GETCWD$$/#define HAVE_GETCWD 1/' \
	    -e 's/#undef HAVE_LIMITS_H$$/#define HAVE_LIMITS_H 1/' \
	    -e 's/#undef HAVE_LOCALE_H$$/#define HAVE_LOCALE_H 1/' \
	    -e 's/#undef HAVE_MEMMOVE$$/#define HAVE_MEMMOVE 1/' \
	    -e 's/#undef HAVE_MEMORY_H$$/#define HAVE_MEMORY_H 1/' \
	    -e 's/#undef HAVE_SEARCH_H$$/#define HAVE_SEARCH_H 1/' \
	    -e 's/#undef HAVE_SETLOCALE$$/#define HAVE_SETLOCALE 1/' \
	    -e 's/#undef HAVE_STDDEF_H$$/#define HAVE_STDDEF_H 1/' \
	    -e 's/#undef HAVE_STDLIB_H$$/#define HAVE_STDLIB_H 1/' \
	    -e 's/#undef HAVE_STRERROR$$/#define HAVE_STRERROR 1/' \
	    -e 's/#undef HAVE_STRING_H$$/#define HAVE_STRING_H 1/' \
	    -e 's/#undef HAVE_SYS_STAT_H$$/#define HAVE_SYS_STAT_H 1/' \
	    -e 's/#undef HAVE_SYS_TYPES_H$$/#define HAVE_SYS_TYPES_H 1/' \
	    -e 's/#undef HAVE_VPRINTF$$/#define HAVE_VPRINTF 1/' \
	    -e 's/#undef STACK_DIRECTION$$/#define STACK_DIRECTION -1/' \
	    -e 's/#undef STDC_HEADERS$$/#define STDC_HEADERS 1/' \
	    -e 's/#undef WORDS_LITTLEENDIAN$$/#define WORDS_LITTLEENDIAN 1/' \
	    -e '/#undef ENABLE_NLS$$/d' \
	    -e '/#undef INSTALLPREFIX$$/d' \
	  < $< > $@

lib/config.h_vms : lib/config.h.in
	sed -e 's/#undef ENABLE_RELOCATABLE$$/#define ENABLE_RELOCATABLE 1/' \
	    -e 's/#undef HAVE_ICONV$$/#define HAVE_ICONV 1/' \
	    -e 's/#define ICONV_CONST const$$/#define ICONV_CONST/' \
	    -e 's/#undef HAVE_LANGINFO_CODESET$$/#define HAVE_LANGINFO_CODESET 1/' \
	    -e 's/#undef HAVE_MBRTOWC$$/#define HAVE_MBRTOWC 1/' \
	    -e 's/#undef HAVE_SETLOCALE$$/#define HAVE_SETLOCALE 1/' \
	    -e 's/#undef HAVE_STDDEF_H$$/#define HAVE_STDDEF_H 1/' \
	    -e 's/#undef HAVE_STDLIB_H$$/#define HAVE_STDLIB_H 1/' \
	    -e 's/#undef HAVE_STRING_H$$/#define HAVE_STRING_H 1/' \
	    -e 's/#undef HAVE_WCRTOMB$$/#define HAVE_WCRTOMB 1/' \
	    -e 's/#undef WORDS_LITTLEENDIAN$$/#define WORDS_LITTLEENDIAN 1/' \
	    -e '/#undef INSTALLPREFIX$$/d' \
	  < $< > $@

lib/config.h.msvc : lib/config.h.in
	sed -e 's/#undef ENABLE_RELOCATABLE$$/#define ENABLE_RELOCATABLE 1/' \
	    -e 's/#undef HAVE_SETLOCALE$$/#define HAVE_SETLOCALE 1/' \
	    -e 's/#undef HAVE_STDDEF_H$$/#define HAVE_STDDEF_H 1/' \
	    -e 's/#undef HAVE_STDLIB_H$$/#define HAVE_STDLIB_H 1/' \
	    -e 's/#undef HAVE_STRING_H$$/#define HAVE_STRING_H 1/' \
	    -e 's/#undef WORDS_LITTLEENDIAN$$/#define WORDS_LITTLEENDIAN 1/' \
	    -e '/#undef INSTALLPREFIX$$/d' \
	  < $< > $@

include/iconv.h_vms : include/iconv.h.in
	sed -e 's/@ICONV_CONST@//g' < $< > $@

include/iconv.h.msvc-static : include/iconv.h.in
	sed -e 's/@ICONV_CONST@/const/g' < $< > $@

include/iconv.h.msvc-shared : include/iconv.h.in windows/dllexport.h
	sed -e 's/@ICONV_CONST@/const/g' -e 's/extern \([^"]\)/extern LIBICONV_DLL_EXPORTED \1/' -e '/_LIBICONV_VERSION/r windows/dllexport.h' < $< > $@


lib/aliases.h : lib/aliases.gperf
	$(GPERF) -m 10 lib/aliases.gperf > tmp.h
	$(CP) tmp.h lib/aliases.h
	$(RM) tmp.h

lib/aliases.gperf : lib/encodings.def lib/encodings_local.def lib/genaliases.c
	$(CC) $(CFLAGS) lib/genaliases.c -o genaliases
	./genaliases > lib/aliases.gperf
	$(RM) genaliases

lib/aliases_aix.h : lib/encodings_aix.def lib/genaliases2.c
	$(CC) $(CFLAGS) -DUSE_AIX lib/genaliases2.c -o genaliases
	./genaliases aix > lib/aliases_aix.h
	$(RM) genaliases

lib/aliases_osf1.h : lib/encodings_osf1.def lib/genaliases2.c
	$(CC) $(CFLAGS) -DUSE_OSF1 lib/genaliases2.c -o genaliases
	./genaliases osf1 > lib/aliases_osf1.h
	$(RM) genaliases

lib/aliases_dos.h : lib/encodings_dos.def lib/genaliases2.c
	$(CC) $(CFLAGS) -DUSE_DOS lib/genaliases2.c -o genaliases
	./genaliases dos > lib/aliases_dos.h
	$(RM) genaliases

lib/aliases_extra.h : lib/encodings_extra.def lib/genaliases2.c
	$(CC) $(CFLAGS) -DUSE_EXTRA lib/genaliases2.c -o genaliases
	./genaliases extra > lib/aliases_extra.h
	$(RM) genaliases


lib/flags.h : lib/encodings.def lib/encodings_aix.def lib/encodings_osf1.def lib/encodings_dos.def lib/encodings_extra.def lib/converters.h lib/genflags.c
	$(CC) $(CFLAGS) lib/genflags.c -o genflags
	./genflags > lib/flags.h
	$(RM) genflags


lib/translit.h : lib/translit.def lib/gentranslit.c
	$(CC) $(CFLAGS) lib/gentranslit.c -o gentranslit
	ulimit -s unlimited; ./gentranslit < lib/translit.def > lib/translit.h
	$(RM) gentranslit


man/%.html : man/%
	$(MAN2HTML) $< > $@


po/Makefile.msvc : po/LINGUAS
	ALL_LINGUAS=`sed -e '/^#/d' po/LINGUAS`; \
	GMOFILES=; for lang in $$ALL_LINGUAS; do GMOFILES="$$GMOFILES $$lang.gmo"; done; \
	$(SHELL) po/Makefile.msvc.sh libiconv "$$GMOFILES" > po/Makefile.msvc


force :
