Btrfs-progs: Add Makefile infrastructure for subdirs

Preparatory patch to move cmd & test files into their
own subdirs.

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
This commit is contained in:
Eric Sandeen 2013-06-11 18:15:17 -05:00 committed by David Sterba
parent d608d404c3
commit dd4d4260d1
2 changed files with 30 additions and 8 deletions

View File

@ -1,3 +1,6 @@
# Export all variables to sub-makes by default
export
CC = gcc CC = gcc
LN = ln LN = ln
AR = ar AR = ar
@ -50,6 +53,18 @@ btrfs_convert_libs = -lext2fs -lcom_err
btrfs_image_libs = -lpthread btrfs_image_libs = -lpthread
btrfs_fragment_libs = -lgd -lpng -ljpeg -lfreetype btrfs_fragment_libs = -lgd -lpng -ljpeg -lfreetype
SUBDIRS = man
BUILDDIRS = $(patsubst %,build-%,$(SUBDIRS))
INSTALLDIRS = $(patsubst %,install-%,$(SUBDIRS))
CLEANDIRS = $(patsubst %,clean-%,$(SUBDIRS))
.PHONY: $(SUBDIRS)
.PHONY: $(BUILDDIRS)
.PHONY: $(INSTALLDIRS)
.PHONY: $(TESTDIRS)
.PHONY: $(CLEANDIRS)
.PHONY: all install clean
# Create all the static targets # Create all the static targets
static_objects = $(patsubst %.o, %.static.o, $(objects)) static_objects = $(patsubst %.o, %.static.o, $(objects))
static_cmds_objects = $(patsubst %.o, %.static.o, $(cmds_objects)) static_cmds_objects = $(patsubst %.o, %.static.o, $(cmds_objects))
@ -102,7 +117,11 @@ endif
@echo " [CC] $@" @echo " [CC] $@"
$(Q)$(CC) $(AM_CFLAGS) $(STATIC_CFLAGS) -c $< -o $@ $(Q)$(CC) $(AM_CFLAGS) $(STATIC_CFLAGS) -c $< -o $@
all: $(progs) manpages all: $(progs) manpages $(BUILDDIRS)
$(SUBDIRS): $(BUILDDIRS)
$(BUILDDIRS):
@echo "Making all in $(patsubst build-%,%,$@)"
$(Q)$(MAKE) $(MAKEOPTS) -C $(patsubst build-%,%,$@)
# #
# NOTE: For static compiles, you need to have all the required libs # NOTE: For static compiles, you need to have all the required libs
@ -195,19 +214,19 @@ send-test: $(objects) $(libs) send-test.o
manpages: manpages:
$(Q)$(MAKE) $(MAKEOPTS) -C man $(Q)$(MAKE) $(MAKEOPTS) -C man
install-man: clean: $(CLEANDIRS)
cd man; $(MAKE) install
clean :
@echo "Cleaning" @echo "Cleaning"
$(Q)rm -f $(progs) cscope.out *.o *.o.d btrfs-convert btrfs-image btrfs-select-super \ $(Q)rm -f $(progs) cscope.out *.o *.o.d btrfs-convert btrfs-image btrfs-select-super \
btrfs-zero-log btrfstune dir-test ioctl-test quick-test send-test btrfsck \ btrfs-zero-log btrfstune dir-test ioctl-test quick-test send-test btrfsck \
btrfs.static mkfs.btrfs.static btrfs-calc-size \ btrfs.static mkfs.btrfs.static btrfs-calc-size \
version.h $(check_defs) \ version.h $(check_defs) \
$(libs) $(lib_links) $(libs) $(lib_links)
$(Q)$(MAKE) $(MAKEOPTS) -C man $@
install: $(libs) $(progs) install-man $(CLEANDIRS):
@echo "Cleaning $(patsubst clean-%,%,$@)"
$(Q)$(MAKE) $(MAKEOPTS) -C $(patsubst clean-%,%,$@) clean
install: $(libs) $(progs) $(INSTALLDIRS)
$(INSTALL) -m755 -d $(DESTDIR)$(bindir) $(INSTALL) -m755 -d $(DESTDIR)$(bindir)
$(INSTALL) $(progs) $(DESTDIR)$(bindir) $(INSTALL) $(progs) $(DESTDIR)$(bindir)
# btrfsck is a link to btrfs in the src tree, make it so for installed file as well # btrfsck is a link to btrfs in the src tree, make it so for installed file as well
@ -218,6 +237,10 @@ install: $(libs) $(progs) install-man
$(INSTALL) -m755 -d $(DESTDIR)$(incdir) $(INSTALL) -m755 -d $(DESTDIR)$(incdir)
$(INSTALL) -m644 $(headers) $(DESTDIR)$(incdir) $(INSTALL) -m644 $(headers) $(DESTDIR)$(incdir)
$(INSTALLDIRS):
@echo "Making install in $(patsubst install-%,%,$@)"
$(Q)$(MAKE) $(MAKEOPTS) -C $(patsubst install-%,%,$@) install
ifneq ($(MAKECMDGOALS),clean) ifneq ($(MAKECMDGOALS),clean)
-include $(objects:.o=.o.d) $(cmd-objects:.o=.o.d) $(subst .btrfs,, $(filter-out btrfsck.o.d, $(progs:=.o.d))) -include $(objects:.o=.o.d) $(cmd-objects:.o=.o.d) $(subst .btrfs,, $(filter-out btrfsck.o.d, $(progs:=.o.d)))
endif endif

View File

@ -23,7 +23,6 @@ all: $(MANPAGES)
$(Q)$(GZIPCMD) -n -c $< > $@ $(Q)$(GZIPCMD) -n -c $< > $@
clean : clean :
@echo "Cleaning manpages"
$(Q)rm -f $(MANPAGES) $(Q)rm -f $(MANPAGES)
install: $(MANPAGES) install: $(MANPAGES)