btrfs-progs-0002-Improve-static-building-and-installation.patch 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. From 6cef3077e0e7073e3449286b3e544ec60e3c5270 Mon Sep 17 00:00:00 2001
  2. From: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
  3. Date: Sat, 30 Aug 2014 14:43:04 +0200
  4. Subject: [PATCH 2/2] Improve static building and installation
  5. This commit improves the static-only building of btrfs-progs, and adds
  6. support for installing the static only tools:
  7. - It now ensures that all programs are built statically, not only a
  8. small subset of them, by defining 'progs_static' from the existing
  9. 'progs' variable.
  10. - It changes the order of libraries in the btrfs-%.static rule so
  11. that -lpthread (part of STATIC_LIBS) appears *after* the '$($(subst
  12. -,_,$(subst .static,,$@)-libs))' logic, which brings in
  13. -lcom_err. This is needed because libcom_err.a uses the semaphore
  14. functions, which are available in the pthread library.
  15. - Adds the necessary rules to generate the btrfsck.static link and
  16. btrfstune.static binary.
  17. - Adds an 'install-static' target to install the static
  18. binaries. Note that they are renamed to not carry a '.static'
  19. suffix.
  20. Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
  21. ---
  22. Makefile | 22 +++++++++++++++++++---
  23. 1 file changed, 19 insertions(+), 3 deletions(-)
  24. diff --git a/Makefile b/Makefile
  25. index 926885f..93e264b 100644
  26. --- a/Makefile
  27. +++ b/Makefile
  28. @@ -50,6 +50,8 @@ progs = mkfs.btrfs btrfs-debug-tree btrfsck \
  29. btrfs btrfs-map-logical btrfs-image btrfs-zero-log btrfs-convert \
  30. btrfs-find-root btrfstune btrfs-show-super
  31. +progs_static = $(foreach p,$(progs),$(p).static)
  32. +
  33. # external libs required by various binaries; for btrfs-foo,
  34. # specify btrfs_foo_libs = <list of libs>; see $($(subst...)) rules below
  35. btrfs_convert_libs = -lext2fs -lcom_err
  36. @@ -141,7 +143,7 @@ test:
  37. # NOTE: For static compiles, you need to have all the required libs
  38. # static equivalent available
  39. #
  40. -static: btrfs.static mkfs.btrfs.static btrfs-find-root.static
  41. +static: $(progs_static)
  42. version.h:
  43. @echo " [SH] $@"
  44. @@ -174,8 +176,8 @@ $(lib_links):
  45. btrfs-%.static: $(static_objects) btrfs-%.static.o $(static_libbtrfs_objects)
  46. @echo " [LD] $@"
  47. $(Q)$(CC) $(STATIC_CFLAGS) -o $@ $@.o $(static_objects) \
  48. - $(static_libbtrfs_objects) $(STATIC_LDFLAGS) $(STATIC_LIBS) \
  49. - $($(subst -,_,$(subst .static,,$@)-libs))
  50. + $(static_libbtrfs_objects) $(STATIC_LDFLAGS) \
  51. + $($(subst -,_,$(subst .static,,$@)-libs)) $(STATIC_LIBS)
  52. btrfs-%: $(objects) $(libs) btrfs-%.o
  53. @echo " [LD] $@"
  54. @@ -196,6 +198,10 @@ btrfsck: btrfs
  55. @echo " [LN] $@"
  56. $(Q)$(LN) -f btrfs btrfsck
  57. +btrfsck.static: btrfs.static
  58. + @echo " [LN] $@"
  59. + $(Q)$(LN) -f $^ $@
  60. +
  61. mkfs.btrfs: $(objects) $(libs) mkfs.o
  62. @echo " [LD] $@"
  63. $(Q)$(CC) $(CFLAGS) -o mkfs.btrfs $(objects) mkfs.o $(LDFLAGS) $(LIBS)
  64. @@ -209,6 +215,11 @@ btrfstune: $(objects) $(libs) btrfstune.o
  65. @echo " [LD] $@"
  66. $(Q)$(CC) $(CFLAGS) -o btrfstune $(objects) btrfstune.o $(LDFLAGS) $(LIBS)
  67. +btrfstune.static: $(static_objects) btrfstune.static.o $(static_libbtrfs_objects)
  68. + @echo " [LD] $@"
  69. + $(Q)$(CC) $(STATIC_CFLAGS) -o $@ btrfstune.static.o $(static_objects) \
  70. + $(static_libbtrfs_objects) $(STATIC_LDFLAGS) $(STATIC_LIBS)
  71. +
  72. dir-test: $(objects) $(libs) dir-test.o
  73. @echo " [LD] $@"
  74. $(Q)$(CC) $(CFLAGS) -o dir-test $(objects) dir-test.o $(LDFLAGS) $(LIBS)
  75. @@ -258,6 +269,11 @@ install: $(libs) $(progs) $(INSTALLDIRS)
  76. $(INSTALL) -m755 -d $(DESTDIR)$(incdir)
  77. $(INSTALL) -m644 $(headers) $(DESTDIR)$(incdir)
  78. +install-static: $(progs_static) $(INSTALLDIRS)
  79. + for p in $(progs_static) ; do \
  80. + $(INSTALL) -D -m755 $$p $(DESTDIR)$(bindir)/`basename $$p .static` ; \
  81. + done
  82. +
  83. $(INSTALLDIRS):
  84. @echo "Making install in $(patsubst install-%,%,$@)"
  85. $(Q)$(MAKE) $(MAKEOPTS) -C $(patsubst install-%,%,$@) install
  86. --
  87. 2.0.0