# 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
GPERF = gperf
CC = gcc
CFLAGS = -O
CP = cp
RM = rm -f


all : configures src/config.h.msvc include/iconv.h.msvc src/aliases.h src/flags.h src/translit.h


# 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 and README,
# - update the version info in src/Makefile.in,
# - do "make -f Makefile.devel".


CONFIGURES = configure
CONFIGURES_IN = configure.in

CLISP_DIR = ..
ACLOCAL = $(CLISP_DIR)/src/autoconf/aclocal.m4
ACSELECT = $(CLISP_DIR)/src/autoconf/acselect
OTHERMACROS = $(CLISP_DIR)/src/autoconf/libtool.m4

autoconf/aclocal.m4 : $(ACLOCAL)
	($(ACSELECT) `cat $(CONFIGURES_IN) | grep '^[A-Z][A-Z]_' | sed 's,[^A-Z_].*$$,,g' | sort | uniq` < $(ACLOCAL) ; cat $(OTHERMACROS) | sed -e 's,AC_CANONICAL_HOST,CL_CANONICAL_HOST,g' -e 's,AC_PROG_RANLIB,CL_PROG_RANLIB,g') > autoconf/aclocal.m4

configures : $(CONFIGURES)

AUTOCONF_FILES = autoconf/aclocal.m4 autoconf/acgeneral.m4 autoconf/acspecific.m4

configure : configure.in $(AUTOCONF_FILES)
	autoconf/autoconf -m autoconf

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


src/config.h.msvc : src/config.h.in
	sed -e 's/#undef WORDS_LITTLEENDIAN$$/#define WORDS_LITTLEENDIAN 1/' < $< > $@

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


# We use "-7" to make a smaller table, but use "unsigned char" array indices
# to avoid gcc warning.
src/aliases.h : src/aliases.gperf
	$(GPERF) -t -L ANSI-C -H aliases_hash -N aliases_lookup -7 -C -k '1,3-11,$$' src/aliases.gperf | sed -e 's/\[str/\[(unsigned char) str/' > tmp.h
	$(CP) tmp.h src/aliases.h
	$(RM) tmp.h

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


src/flags.h : src/encodings.def src/converters.h src/genflags.c
	$(CC) $(CFLAGS) src/genflags.c -o genflags
	./genflags > src/flags.h
	$(RM) genflags


src/translit.h : src/translit.def src/gentranslit.c
	$(CC) $(CFLAGS) src/gentranslit.c -o gentranslit
	./gentranslit < src/translit.def > src/translit.h
	$(RM) gentranslit


force :
