libxfs: restructure to match kernel layout

The kernel now has a libxfs directory, so we need to restructure the
userspace libxfs source tree to match the kernel layout. This
involves changing the location of libxfs include files and how they
are linked into include/xfs for all the subdirectories to see them.

This is a bit convoluted as an initial conversion step - we move all
the libxfs headers files from include/ to libxfs/ and then add build
rules to symlink the files directly to include/xfs so everything
still "sees" the same header files. This changes the build
dependencies slightly, as libxfs now must be built after include
(unchanged) but before anything else (new) so that we have a
complete include/xfs directory. This also affects install and
packaging rules, as header install rules are now split across
include and libxfs Makefiles.

Signed-off-by: Dave Chinner <dchinner@redhat.com>
diff --git a/Makefile b/Makefile
index f56aebd..d04f853 100644
--- a/Makefile
+++ b/Makefile
@@ -40,7 +40,9 @@
 LDIRT += $(SRCTAR)
 endif
 
-LIB_SUBDIRS = libxfs libxlog libxcmd libhandle libdisk
+
+DLIB_SUBDIRS = libxlog libxcmd libhandle libdisk
+LIB_SUBDIRS = libxfs $(DLIB_SUBDIRS)
 TOOL_SUBDIRS = copy db estimate fsck fsr growfs io logprint mkfs quota \
 		mdrestore repair rtcp m4 man doc po debian
 
@@ -54,15 +56,16 @@
 endif
 
 # tool/lib dependencies
+# note: include/xfs is set up by libxfs, too, so everything is dependent on it.
 $(LIB_SUBDIRS) $(TOOL_SUBDIRS): include
-copy mdrestore: libxfs
-db logprint: libxfs libxlog
+$(DLIB_SUBDIRS) $(TOOL_SUBDIRS): libxfs
+db logprint: libxlog
 fsr: libhandle
-growfs: libxfs libxcmd
+growfs: libxcmd
 io: libxcmd libhandle
-mkfs: libxfs
 quota: libxcmd
-repair: libxfs libxlog
+repair: libxlog
+
 
 ifneq ($(ENABLE_BLKID), yes)
 mkfs: libdisk
diff --git a/include/Makefile b/include/Makefile
index a867516..7976bf5 100644
--- a/include/Makefile
+++ b/include/Makefile
@@ -21,46 +21,39 @@
 QAHFILES = libxfs.h libxlog.h \
 	atomic.h bitops.h cache.h kmem.h list.h hlist.h parent.h radix-tree.h \
 	swab.h \
-	xfs_ag.h xfs_alloc.h xfs_alloc_btree.h xfs_arch.h xfs_attr_leaf.h \
-	xfs_attr_sf.h xfs_bit.h xfs_bmap.h xfs_bmap_btree.h xfs_btree.h \
-	xfs_attr_remote.h \
+	xfs_arch.h \
 	xfs_btree_trace.h \
-	xfs_cksum.h \
-	xfs_da_btree.h \
-	xfs_da_format.h \
-	xfs_dinode.h \
-	xfs_dir2.h \
-	xfs_format.h \
-	xfs_ialloc.h \
-	xfs_ialloc_btree.h \
-	xfs_inode_buf.h \
-	xfs_inode_fork.h \
-	xfs_inum.h \
-	xfs_log_format.h \
 	xfs_log_recover.h \
 	xfs_metadump.h \
-	xfs_quota_defs.h \
-	xfs_sb.h \
-	xfs_shared.h \
-	xfs_trace.h \
-	xfs_trans_resv.h \
-	xfs_trans_space.h
+	xfs_trace.h
 
-HFILES = handle.h jdm.h xqm.h xfs.h xfs_fs.h xfs_types.h
+HFILES = handle.h jdm.h xqm.h xfs.h
 HFILES += $(PKG_PLATFORM).h
 PHFILES = darwin.h freebsd.h irix.h linux.h gnukfreebsd.h
 DKHFILES = volume.h fstyp.h dvh.h
+LIBHFILES = command.h input.h path.h project.h
 LSRCFILES = $(shell echo $(PHFILES) | sed -e "s/$(PKG_PLATFORM).h//g")
 LSRCFILES += platform_defs.h.in builddefs.in buildmacros buildrules install-sh
-LSRCFILES += $(DKHFILES) command.h input.h path.h project.h
-LDIRT = xfs disk
+LSRCFILES += $(DKHFILES) $(LIBHFILES)
+LDIRT = disk
+LDIRDIRT = xfs
 
-default install: xfs disk
+default install: .xfs disk
 
-xfs disk:
+disk:
 	@echo "    [LN]     $@"
 	$(Q)$(LN_S) . $@
 
+# set up include/xfs header directory
+.xfs: $(addsuffix -hdrs, $(HFILES) $(QAHFILES) $(PHFILES) $(DKHFILES) $(LIBHFILES))
+
+%-hdrs: xfs
+	$(Q)$(LN_S) -f $(PWD)/include/$* xfs/$*
+
+xfs:
+	@mkdir -p xfs
+
+
 include $(BUILDRULES)
 
 install-dev: default
@@ -70,3 +63,4 @@
 
 install-qa: install-dev
 	$(INSTALL) -m 644 $(QAHFILES) $(PKG_INC_DIR)
+
diff --git a/include/buildrules b/include/buildrules
index 399635e..dbd9e10 100644
--- a/include/buildrules
+++ b/include/buildrules
@@ -94,7 +94,7 @@
 ltdepend: rmltdep .ltdep
 
 rmltdep:
-	@rm -f .ltdep
+	$(Q)rm -f .ltdep
 
 .ltdep: $(CFILES) $(HFILES)
 	$(Q)$(MAKEDEP) $(CFILES) | $(SED) -e 's,^\([^:]*\)\.o,\1.lo,' > .ltdep
@@ -102,7 +102,7 @@
 depend: rmdep .dep
 
 rmdep:
-	@rm -f .dep
+	$(Q)rm -f .dep
 
 .dep: $(CFILES) $(HFILES)
 	$(Q)$(MAKEDEP) $(CFILES) > .dep
diff --git a/libxfs/Makefile b/libxfs/Makefile
index b445998..8012823 100644
--- a/libxfs/Makefile
+++ b/libxfs/Makefile
@@ -10,7 +10,46 @@
 LT_REVISION = 0
 LT_AGE = 0
 
-HFILES = xfs.h init.h xfs_dir2_priv.h crc32defs.h crc32table.h
+# headers to install in include/xfs
+PKGHFILES = xfs_fs.h \
+	xfs_types.h
+
+# headers with build dependencies
+HFILES = xfs.h \
+	init.h \
+	crc32defs.h \
+	crc32table.h \
+	xfs_dir2_priv.h \
+
+# headers installed in QA targets
+QAHFILES = xfs_ag.h \
+	xfs_alloc.h \
+	xfs_alloc_btree.h \
+	xfs_attr_leaf.h \
+	xfs_attr_sf.h \
+	xfs_bit.h \
+	xfs_bmap.h \
+	xfs_bmap_btree.h \
+	xfs_btree.h \
+	xfs_attr_remote.h \
+	xfs_cksum.h \
+	xfs_da_btree.h \
+	xfs_da_format.h \
+	xfs_dinode.h \
+	xfs_dir2.h \
+	xfs_format.h \
+	xfs_ialloc.h \
+	xfs_ialloc_btree.h \
+	xfs_inode_buf.h \
+	xfs_inode_fork.h \
+	xfs_inum.h \
+	xfs_log_format.h \
+	xfs_quota_defs.h \
+	xfs_sb.h \
+	xfs_shared.h \
+	xfs_trans_resv.h \
+	xfs_trans_space.h
+
 CFILES = cache.c \
 	crc32.c \
 	init.c kmem.c logitem.c radix-tree.c rdwr.c trans.c util.c \
@@ -64,7 +103,7 @@
 
 LDIRT = gen_crc32table crc32table.h crc32selftest
 
-default: crc32selftest ltdepend $(LTLIBRARY)
+default: xfs crc32selftest ltdepend $(LTLIBRARY)
 
 crc32table.h: gen_crc32table.c
 	@echo "    [CC]     gen_crc32table"
@@ -82,12 +121,21 @@
 	$(Q) $(CC) $(CFLAGS) -D CRC32_SELFTEST=1 crc32.c -o $@
 	$(Q) ./$@
 
+# set up include/xfs header directory
+xfs: $(addsuffix -hdrs, $(PKGHFILES) $(QAHFILES))
+
+%-hdrs:
+	$(Q)$(LN_S) -f $(PWD)/libxfs/$* $(TOPDIR)/include/xfs/$*
+
 include $(BUILDRULES)
 
 install: default
 
-install-dev: default
+install-dev: install
+	$(INSTALL) -m 644 $(HFILES) $(PKG_INC_DIR)
 
-install-qa: default
+install-qa: install-dev
+	$(INSTALL) -m 644 $(QAHFILES) $(PKG_INC_DIR)
 
 -include .ltdep
+
diff --git a/include/xfs_ag.h b/libxfs/xfs_ag.h
similarity index 100%
rename from include/xfs_ag.h
rename to libxfs/xfs_ag.h
diff --git a/include/xfs_alloc.h b/libxfs/xfs_alloc.h
similarity index 100%
rename from include/xfs_alloc.h
rename to libxfs/xfs_alloc.h
diff --git a/include/xfs_alloc_btree.h b/libxfs/xfs_alloc_btree.h
similarity index 100%
rename from include/xfs_alloc_btree.h
rename to libxfs/xfs_alloc_btree.h
diff --git a/include/xfs_attr_leaf.h b/libxfs/xfs_attr_leaf.h
similarity index 100%
rename from include/xfs_attr_leaf.h
rename to libxfs/xfs_attr_leaf.h
diff --git a/include/xfs_attr_remote.h b/libxfs/xfs_attr_remote.h
similarity index 100%
rename from include/xfs_attr_remote.h
rename to libxfs/xfs_attr_remote.h
diff --git a/include/xfs_attr_sf.h b/libxfs/xfs_attr_sf.h
similarity index 100%
rename from include/xfs_attr_sf.h
rename to libxfs/xfs_attr_sf.h
diff --git a/include/xfs_bit.h b/libxfs/xfs_bit.h
similarity index 100%
rename from include/xfs_bit.h
rename to libxfs/xfs_bit.h
diff --git a/include/xfs_bmap.h b/libxfs/xfs_bmap.h
similarity index 100%
rename from include/xfs_bmap.h
rename to libxfs/xfs_bmap.h
diff --git a/include/xfs_bmap_btree.h b/libxfs/xfs_bmap_btree.h
similarity index 100%
rename from include/xfs_bmap_btree.h
rename to libxfs/xfs_bmap_btree.h
diff --git a/include/xfs_btree.h b/libxfs/xfs_btree.h
similarity index 100%
rename from include/xfs_btree.h
rename to libxfs/xfs_btree.h
diff --git a/include/xfs_cksum.h b/libxfs/xfs_cksum.h
similarity index 100%
rename from include/xfs_cksum.h
rename to libxfs/xfs_cksum.h
diff --git a/include/xfs_da_btree.h b/libxfs/xfs_da_btree.h
similarity index 100%
rename from include/xfs_da_btree.h
rename to libxfs/xfs_da_btree.h
diff --git a/include/xfs_da_format.h b/libxfs/xfs_da_format.h
similarity index 100%
rename from include/xfs_da_format.h
rename to libxfs/xfs_da_format.h
diff --git a/include/xfs_dinode.h b/libxfs/xfs_dinode.h
similarity index 100%
rename from include/xfs_dinode.h
rename to libxfs/xfs_dinode.h
diff --git a/include/xfs_dir2.h b/libxfs/xfs_dir2.h
similarity index 100%
rename from include/xfs_dir2.h
rename to libxfs/xfs_dir2.h
diff --git a/include/xfs_format.h b/libxfs/xfs_format.h
similarity index 100%
rename from include/xfs_format.h
rename to libxfs/xfs_format.h
diff --git a/include/xfs_fs.h b/libxfs/xfs_fs.h
similarity index 100%
rename from include/xfs_fs.h
rename to libxfs/xfs_fs.h
diff --git a/include/xfs_ialloc.h b/libxfs/xfs_ialloc.h
similarity index 100%
rename from include/xfs_ialloc.h
rename to libxfs/xfs_ialloc.h
diff --git a/include/xfs_ialloc_btree.h b/libxfs/xfs_ialloc_btree.h
similarity index 100%
rename from include/xfs_ialloc_btree.h
rename to libxfs/xfs_ialloc_btree.h
diff --git a/include/xfs_inode_buf.h b/libxfs/xfs_inode_buf.h
similarity index 100%
rename from include/xfs_inode_buf.h
rename to libxfs/xfs_inode_buf.h
diff --git a/include/xfs_inode_fork.h b/libxfs/xfs_inode_fork.h
similarity index 100%
rename from include/xfs_inode_fork.h
rename to libxfs/xfs_inode_fork.h
diff --git a/include/xfs_inum.h b/libxfs/xfs_inum.h
similarity index 100%
rename from include/xfs_inum.h
rename to libxfs/xfs_inum.h
diff --git a/include/xfs_log_format.h b/libxfs/xfs_log_format.h
similarity index 100%
rename from include/xfs_log_format.h
rename to libxfs/xfs_log_format.h
diff --git a/include/xfs_quota_defs.h b/libxfs/xfs_quota_defs.h
similarity index 100%
rename from include/xfs_quota_defs.h
rename to libxfs/xfs_quota_defs.h
diff --git a/include/xfs_sb.h b/libxfs/xfs_sb.h
similarity index 100%
rename from include/xfs_sb.h
rename to libxfs/xfs_sb.h
diff --git a/include/xfs_shared.h b/libxfs/xfs_shared.h
similarity index 100%
rename from include/xfs_shared.h
rename to libxfs/xfs_shared.h
diff --git a/include/xfs_trans_resv.h b/libxfs/xfs_trans_resv.h
similarity index 100%
rename from include/xfs_trans_resv.h
rename to libxfs/xfs_trans_resv.h
diff --git a/include/xfs_trans_space.h b/libxfs/xfs_trans_space.h
similarity index 100%
rename from include/xfs_trans_space.h
rename to libxfs/xfs_trans_space.h
diff --git a/include/xfs_types.h b/libxfs/xfs_types.h
similarity index 100%
rename from include/xfs_types.h
rename to libxfs/xfs_types.h