fix two typos. Duh
[gnulib.git] / lib / Makefile.am
index c568c3f..b4300e0 100644 (file)
@@ -35,7 +35,7 @@ BUILT_SOURCES = getdate.c lstat.c stat.c
 MAINTAINERCLEANFILES = $(BUILT_SOURCES)
 DISTCLEANFILES = lstat.c stat.c
 
-EXTRA_DIST = xstat.in config.charset
+EXTRA_DIST = xstat.in config.charset ref-add.sin ref-del.sin
 lstat.c: xstat.in
        sed \
          -e '/@IGNORE@/d' \
@@ -55,19 +55,43 @@ stat.c: xstat.in
        mv $@-t $@
 
 
-# What a mess needed in order to install a simple file in $(libdir)!
+# The following is needed in order to install a simple file in $(libdir)
+# which is shared with other installed packages. We use a list of referencing
+# packages so that "make uninstall" will remove the file if and only if it
+# is not used by another installed package.
 
-all-local: charset.alias
+all-local: charset.alias ref-add.sed ref-del.sed
 
+charset_alias = $(DESTDIR)$(libdir)/charset.alias
+charset_tmp = $(DESTDIR)$(libdir)/charset.tmp
 install-exec-local: all-local
-       $(INSTALL_DATA) charset.alias $(libdir)/charset.alias
-
-# Probably not a good idea. Other packages need $(libdir)/charset.alias too.
-#uninstall-local:
-#      -rm -f $(libdir)/charset.alias
+       $(mkinstalldirs) $(DESTDIR)$(libdir)
+       test -f $(charset_alias) \
+         && orig=$(charset_alias) \
+         || orig=charset.alias; \
+       sed -f ref-add.sed $$orig > $(charset_tmp)
+       $(INSTALL_DATA) $(charset_tmp) $(charset_alias)
+       rm -f $(charset_tmp)
+
+uninstall-local: all-local
+       if test -f $(charset_alias); then \
+         sed -f ref-del.sed $(charset_alias) > $(charset_tmp); \
+         if grep '^# Packages using this file: $$' $(charset_tmp) \
+             > /dev/null; then \
+           rm -f $(charset_alias); \
+         else \
+           $(INSTALL_DATA) $(charset_tmp) $(charset_alias); \
+         fi; \
+         rm -f $(charset_tmp); \
+       fi
 
 charset.alias: config.charset
        $(SHELL) $(srcdir)/config.charset '@host@' > $@-t
        mv $@-t $@
 
-CLEANFILES = charset.alias
+SUFFIXES = .sed .sin
+.sin.sed:
+       sed -e '/^#/d' -e 's/@''PACKAGE''@/@PACKAGE@/g' $< > $@-t
+       mv $@-t $@
+
+CLEANFILES = charset.alias ref-add.sed ref-del.sed