TOPDIR=../
include $(TOPDIR)Rules.make
LINK_WARNING_H=../link-warning.h

all: $(ALLOCA_H) $(FNMATCH_H) $(STDBOOL_H) $(WCHAR_H) $(WCTYPE_H) $(ALLOCA) $(gl_LIBOBJS)

# Can be included via ALLOCA
alloca.o: alloca.c
	$(CC) alloca.c -o $@ -c
	ln -sf gnulib/alloca.o ..

# Can be included via gl_LIBOBJS
fnmatch.o: fnmatch.c
	$(CC) fnmatch.c -o $@ -c
	ln -sf gnulib/fnmatch.o ..

alloca.h: alloca.in.h
	{ echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \
	  cat alloca.in.h; \
	} > $@-t
	mv -f $@-t $@

fnmatch.h: fnmatch.in.h
	{ echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \
	  cat fnmatch.in.h; \
	} > $@-t
	mv -f $@-t $@

stdbool.h: stdbool.in.h
	rm -f $@-t $@
	{ echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \
	  sed -e 's/@''HAVE__BOOL''@/$(HAVE__BOOL)/g' < stdbool.in.h; \
	} > $@-t
	mv $@-t $@

wchar.h: wchar.in.h
	rm -f $@-t $@
	{ echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \
	  sed -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \
	      -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \
	      -e 's|@''NEXT_WCHAR_H''@|$(NEXT_WCHAR_H)|g' \
	      -e 's|@''HAVE_WCHAR_H''@|$(HAVE_WCHAR_H)|g' \
	      -e 's|@''GNULIB_WCWIDTH''@|$(GNULIB_WCWIDTH)|g' \
	      -e 's|@''HAVE_WINT_T''@|$(HAVE_WINT_T)|g' \
	      -e 's|@''HAVE_DECL_WCWIDTH''@|$(HAVE_DECL_WCWIDTH)|g' \
	      -e 's|@''REPLACE_WCWIDTH''@|$(REPLACE_WCWIDTH)|g' \
	      -e '/definition of GL_LINK_WARNING/r $(LINK_WARNING_H)' \
	    < wchar.in.h; \
	} > $@-t
	mv $@-t $@

wctype.h: wctype.in.h
	rm -f $@-t $@
	{ echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \
	  sed -e 's/@''HAVE_WCTYPE_H''@/$(HAVE_WCTYPE_H)/g' \
	      -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \
	      -e 's|@''PRAGMA_SYSTEM_HEADER''@|$(PRAGMA_SYSTEM_HEADER)|g' \
	      -e 's|@''NEXT_WCTYPE_H''@|$(NEXT_WCTYPE_H)|g' \
	      -e 's/@''HAVE_ISWCNTRL''@/$(HAVE_ISWCNTRL)/g' \
	      -e 's/@''HAVE_WINT_T''@/$(HAVE_WINT_T)/g' \
	      -e 's/@''REPLACE_ISWCNTRL''@/$(REPLACE_ISWCNTRL)/g' \
	      < wctype.in.h; \
	} > $@-t
	mv $@-t $@

clean:
	rm -f *.o *$(LIB_SUFFIX) alloca.h alloca.h-t fnmatch.h fnmatch.h-t stdbool.h stdbool.h-t wchar.h wchar.h-t wctype.h wctype.h-t
