From 69ff5d5513fc8b07c3e85b8f8cb15e03e667bb8a Mon Sep 17 00:00:00 2001
From: Heinz Mauelshagen <heinzm@redhat.com>
Date: Mon, 15 Jul 2013 16:48:36 +0200
Subject: [PATCH] autconf: support build of thin_metadata_size.c

---
 Makefile.in                                   | 28 ++++++++++++++++---
 configure.in                                  |  1 +
 thin-provisioning/thin_metadata_size.c        |  1 -
 ...in_metadata_size => thin_metadata_size.rb} |  0
 4 files changed, 25 insertions(+), 5 deletions(-)
 rename thin-provisioning/{thin_metadata_size => thin_metadata_size.rb} (100%)

diff --git a/Makefile.in b/Makefile.in
index 8cda0c3..f5e2d1d 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -24,7 +24,8 @@ PROGRAMS=\
 	thin_dump \
 	thin_restore \
 	thin_repair \
-	thin_rmap
+	thin_rmap \
+	thin_metadata_size
 
 all: $(PROGRAMS)
 
@@ -73,10 +74,15 @@ PROGRAM_SOURCE=\
 	thin-provisioning/thin_repair.cc \
 	thin-provisioning/thin_rmap.cc
 
+C_PROGRAM_SOURCE=\
+	thin-provisioning/thin_metadata_size.c
+
+CC:=@CC@
 CXX:=@CXX@
 OBJECTS:=$(subst .cc,.o,$(SOURCE))
 TOP_DIR:=@top_srcdir@
 TOP_BUILDDIR:=@top_builddir@
+CFLAGS+=-g -Wall -O3
 CXXFLAGS+=-std=c++11 -g -Wall -fno-strict-aliasing
 CXXFLAGS+=@CXXOPTIMISE_FLAG@
 CXXFLAGS+=@CXXDEBUG_FLAG@
@@ -104,6 +110,14 @@ endif
 
 .SUFFIXES: .d
 
+%.o: %.c
+	@echo "    [CC] $<"
+	$(V) $(CC) -c $(INCLUDES) $(CFLAGS) -o $@ $<
+	@echo "    [DEP] $<"
+	$(V) $(CC) -MM -MT $(subst .c,.o,$<) $(INCLUDES) $(CFLAGS) $< > $*.$$$$; \
+	sed 's,\([^ :]*\)\.o[ :]*,\1.o \1.gmo $* : Makefile ,g' < $*.$$$$ > $*.d; \
+	$(RM) $*.$$$$
+
 %.o: %.cc
 	@echo "    [CXX] $<"
 	$(V) $(CXX) -c $(INCLUDES) $(CXXFLAGS) -o $@ $<
@@ -195,6 +209,10 @@ thin_rmap: $(THIN_RMAP_OBJECTS) thin-provisioning/thin_rmap.o
 	@echo "    [LD]  $@"
 	$(V) $(CXX) $(CXXFLAGS) -o $@ $+ $(LIBS)
 
+thin_metadata_size: thin-provisioning/thin_metadata_size.o
+	@echo "    [LD]  $@"
+	$(V) $(CC) $(CFLAGS) -o $@ $+ -lm
+
 #----------------------------------------------------------------
 # Cache tools
 
@@ -221,14 +239,16 @@ cache_check: $(CACHE_CHECK_OBJECTS) cache/check.o
 DEPEND_FILES=\
 	$(subst .cc,.d,$(SOURCE)) \
 	$(subst .cc,.d,$(TEST_SOURCE)) \
-	$(subst .cc,.d,$(PROGRAM_SOURCE))
+	$(subst .cc,.d,$(PROGRAM_SOURCE)) \
+	$(subst .c,.d,$(C_PROGRAM_SOURCE))
 
 .PHONY: clean distclean
 
 clean:
 	find . -name \*.o -delete
 	find . -name \*.gmo -delete
-	$(RM) $(DEPEND_FILES) $(TEST_PROGRAMS) $(PROGRAMS) $(GMOCK_OBJECTS) lib/*.a
+	find . -name \*.d -delete
+	$(RM) $(TEST_PROGRAMS) $(PROGRAMS) $(GMOCK_OBJECTS) lib/*.a
 
 distclean: clean
 	$(RM) config.cache config.log config.status configure.h version.h Makefile unit-tests/Makefile
@@ -240,7 +260,7 @@ install: $(PROGRAMS)
 	$(INSTALL_PROGRAM) -s thin_repair $(BINDIR)
 	$(INSTALL_PROGRAM) -s thin_restore $(BINDIR)
 	$(INSTALL_PROGRAM) -s thin_rmap $(BINDIR)
-	$(INSTALL_PROGRAM) thin-provisioning/thin_metadata_size $(BINDIR)
+	$(INSTALL_PROGRAM) -s thin_metadata_size $(BINDIR)
 	$(INSTALL_DIR) $(MANPATH)/man8
 	$(INSTALL_DATA) man8/thin_check.8 $(MANPATH)/man8
 	$(INSTALL_DATA) man8/thin_dump.8 $(MANPATH)/man8
diff --git a/configure.in b/configure.in
index 78d88c1..8f25002 100644
--- a/configure.in
+++ b/configure.in
@@ -30,6 +30,7 @@ dnl -- Setup the directory where autoconf has auxilary files
 AC_CONFIG_AUX_DIR(autoconf)
 AC_CANONICAL_TARGET([])
 AC_PROG_CXX([g++])
+AC_PROG_CC([gcc])
 AC_LANG(C++)
 
 ################################################################
diff --git a/thin-provisioning/thin_metadata_size.c b/thin-provisioning/thin_metadata_size.c
index e798b0c..e5952fe 100755
--- a/thin-provisioning/thin_metadata_size.c
+++ b/thin-provisioning/thin_metadata_size.c
@@ -190,7 +190,6 @@ static void printf_precision(double r, int full, char *unit_str)
 {
 	double rtrunc = truncl(r);
 
-	/* FIXME: correct output */
 	if (full)
 		printf("%s - estimated metadata area size is ", prg);
 
diff --git a/thin-provisioning/thin_metadata_size b/thin-provisioning/thin_metadata_size.rb
similarity index 100%
rename from thin-provisioning/thin_metadata_size
rename to thin-provisioning/thin_metadata_size.rb