Makefile 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. # SPDX-License-Identifier: GPL-2.0
  2. include ../../scripts/Makefile.include
  3. include ../../scripts/utilities.mak # QUIET_CLEAN
  4. ifeq ($(srctree),)
  5. srctree := $(patsubst %/,%,$(dir $(CURDIR)))
  6. srctree := $(patsubst %/,%,$(dir $(srctree)))
  7. srctree := $(patsubst %/,%,$(dir $(srctree)))
  8. #$(info Determined 'srctree' to be $(srctree))
  9. endif
  10. CC ?= $(CROSS_COMPILE)gcc
  11. LD ?= $(CROSS_COMPILE)ld
  12. AR ?= $(CROSS_COMPILE)ar
  13. RM = rm -f
  14. MAKEFLAGS += --no-print-directory
  15. INSTALL = install
  16. # Use DESTDIR for installing into a different root directory.
  17. # This is useful for building a package. The program will be
  18. # installed in this directory as if it was the root directory.
  19. # Then the build tool can move it later.
  20. DESTDIR ?=
  21. DESTDIR_SQ = '$(subst ','\'',$(DESTDIR))'
  22. LIBFILE = $(OUTPUT)libsubcmd.a
  23. CFLAGS := -ggdb3 -Wall -Wextra -std=gnu99 -fPIC
  24. ifeq ($(DEBUG),0)
  25. ifeq ($(feature-fortify-source), 1)
  26. CFLAGS += -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2
  27. endif
  28. endif
  29. ifeq ($(DEBUG),1)
  30. CFLAGS += -O0
  31. else ifeq ($(CC_NO_CLANG), 0)
  32. CFLAGS += -O3
  33. else
  34. CFLAGS += -O6
  35. endif
  36. # Treat warnings as errors unless directed not to
  37. ifneq ($(WERROR),0)
  38. CFLAGS += -Werror
  39. endif
  40. CFLAGS += -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE
  41. CFLAGS += -I$(srctree)/tools/include/
  42. CFLAGS += $(EXTRA_WARNINGS) $(EXTRA_CFLAGS)
  43. SUBCMD_IN := $(OUTPUT)libsubcmd-in.o
  44. ifeq ($(LP64), 1)
  45. libdir_relative = lib64
  46. else
  47. libdir_relative = lib
  48. endif
  49. prefix ?=
  50. libdir = $(prefix)/$(libdir_relative)
  51. # Shell quotes
  52. libdir_SQ = $(subst ','\'',$(libdir))
  53. all:
  54. export srctree OUTPUT CC LD CFLAGS V
  55. include $(srctree)/tools/build/Makefile.include
  56. all: fixdep $(LIBFILE)
  57. $(SUBCMD_IN): FORCE
  58. @$(MAKE) $(build)=libsubcmd
  59. $(LIBFILE): $(SUBCMD_IN)
  60. $(QUIET_AR)$(RM) $@ && $(AR) rcs $@ $(SUBCMD_IN)
  61. define do_install_mkdir
  62. if [ ! -d '$(DESTDIR_SQ)$1' ]; then \
  63. $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$1'; \
  64. fi
  65. endef
  66. define do_install
  67. if [ ! -d '$2' ]; then \
  68. $(INSTALL) -d -m 755 '$2'; \
  69. fi; \
  70. $(INSTALL) $1 $(if $3,-m $3,) '$2'
  71. endef
  72. install_lib: $(LIBFILE)
  73. $(call QUIET_INSTALL, $(LIBFILE)) \
  74. $(call do_install_mkdir,$(libdir_SQ)); \
  75. cp -fpR $(LIBFILE) $(DESTDIR)$(libdir_SQ)
  76. HDRS := exec-cmd.h help.h pager.h parse-options.h run-command.h
  77. INSTALL_HDRS_PFX := $(DESTDIR)$(prefix)/include/subcmd
  78. INSTALL_HDRS := $(addprefix $(INSTALL_HDRS_PFX)/, $(HDRS))
  79. $(INSTALL_HDRS): $(INSTALL_HDRS_PFX)/%.h: %.h
  80. $(call QUIET_INSTALL, $@) \
  81. $(call do_install,$<,$(INSTALL_HDRS_PFX)/,644)
  82. install_headers: $(INSTALL_HDRS)
  83. $(call QUIET_INSTALL, libsubcmd_headers)
  84. install: install_lib install_headers
  85. clean:
  86. $(call QUIET_CLEAN, libsubcmd) $(RM) $(LIBFILE); \
  87. find $(or $(OUTPUT),.) -name \*.o -or -name \*.o.cmd -or -name \*.o.d | xargs $(RM)
  88. FORCE:
  89. .PHONY: clean FORCE