Makefile 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. # SPDX-License-Identifier: GPL-2.0
  2. # file format version
  3. FILE_VERSION = 1
  4. LIBLOCKDEP_VERSION=$(shell make --no-print-directory -sC ../../.. kernelversion)
  5. # Makefiles suck: This macro sets a default value of $(2) for the
  6. # variable named by $(1), unless the variable has been set by
  7. # environment or command line. This is necessary for CC and AR
  8. # because make sets default values, so the simpler ?= approach
  9. # won't work as expected.
  10. define allow-override
  11. $(if $(or $(findstring environment,$(origin $(1))),\
  12. $(findstring command line,$(origin $(1)))),,\
  13. $(eval $(1) = $(2)))
  14. endef
  15. # Allow setting CC and AR and LD, or setting CROSS_COMPILE as a prefix.
  16. $(call allow-override,CC,$(CROSS_COMPILE)gcc)
  17. $(call allow-override,AR,$(CROSS_COMPILE)ar)
  18. $(call allow-override,LD,$(CROSS_COMPILE)ld)
  19. INSTALL = install
  20. # Use DESTDIR for installing into a different root directory.
  21. # This is useful for building a package. The program will be
  22. # installed in this directory as if it was the root directory.
  23. # Then the build tool can move it later.
  24. DESTDIR ?=
  25. DESTDIR_SQ = '$(subst ','\'',$(DESTDIR))'
  26. prefix ?= /usr/local
  27. libdir_relative = lib
  28. libdir = $(prefix)/$(libdir_relative)
  29. bindir_relative = bin
  30. bindir = $(prefix)/$(bindir_relative)
  31. export DESTDIR DESTDIR_SQ INSTALL
  32. MAKEFLAGS += --no-print-directory
  33. include ../../scripts/Makefile.include
  34. # copy a bit from Linux kbuild
  35. ifeq ("$(origin V)", "command line")
  36. VERBOSE = $(V)
  37. endif
  38. ifndef VERBOSE
  39. VERBOSE = 0
  40. endif
  41. ifeq ($(srctree),)
  42. srctree := $(patsubst %/,%,$(dir $(CURDIR)))
  43. srctree := $(patsubst %/,%,$(dir $(srctree)))
  44. srctree := $(patsubst %/,%,$(dir $(srctree)))
  45. #$(info Determined 'srctree' to be $(srctree))
  46. endif
  47. # Shell quotes
  48. libdir_SQ = $(subst ','\'',$(libdir))
  49. bindir_SQ = $(subst ','\'',$(bindir))
  50. LIB_IN := $(OUTPUT)liblockdep-in.o
  51. BIN_FILE = lockdep
  52. LIB_FILE = $(OUTPUT)liblockdep.a $(OUTPUT)liblockdep.so.$(LIBLOCKDEP_VERSION)
  53. CONFIG_INCLUDES =
  54. CONFIG_LIBS =
  55. CONFIG_FLAGS =
  56. OBJ = $@
  57. N =
  58. export Q VERBOSE
  59. INCLUDES = -I. -I./uinclude -I./include -I../../include $(CONFIG_INCLUDES)
  60. # Set compile option CFLAGS if not set elsewhere
  61. CFLAGS ?= -g -DCONFIG_LOCKDEP -DCONFIG_STACKTRACE -DCONFIG_PROVE_LOCKING -DBITS_PER_LONG=__WORDSIZE -DLIBLOCKDEP_VERSION='"$(LIBLOCKDEP_VERSION)"' -rdynamic -O0 -g
  62. CFLAGS += -fPIC
  63. CFLAGS += -Wall
  64. override CFLAGS += $(CONFIG_FLAGS) $(INCLUDES) $(PLUGIN_DIR_SQ)
  65. ifeq ($(VERBOSE),1)
  66. Q =
  67. print_shared_lib_compile =
  68. print_install =
  69. else
  70. Q = @
  71. print_shared_lib_compile = echo ' LD '$(OBJ);
  72. print_static_lib_build = echo ' LD '$(OBJ);
  73. print_install = echo ' INSTALL '$1' to $(DESTDIR_SQ)$2';
  74. endif
  75. all:
  76. export srctree OUTPUT CC LD CFLAGS V
  77. include $(srctree)/tools/build/Makefile.include
  78. do_compile_shared_library = \
  79. ($(print_shared_lib_compile) \
  80. $(CC) $(LDFLAGS) --shared $^ -o $@ -lpthread -ldl -Wl,-soname='$(@F)';$(shell ln -sf $(@F) $(@D)/liblockdep.so))
  81. do_build_static_lib = \
  82. ($(print_static_lib_build) \
  83. $(RM) $@; $(AR) rcs $@ $^)
  84. CMD_TARGETS = $(LIB_FILE)
  85. TARGETS = $(CMD_TARGETS)
  86. all: fixdep all_cmd
  87. all_cmd: $(CMD_TARGETS)
  88. $(LIB_IN): force
  89. $(Q)$(MAKE) $(build)=liblockdep
  90. $(OUTPUT)liblockdep.so.$(LIBLOCKDEP_VERSION): $(LIB_IN)
  91. $(Q)$(do_compile_shared_library)
  92. $(OUTPUT)liblockdep.a: $(LIB_IN)
  93. $(Q)$(do_build_static_lib)
  94. tags: force
  95. $(RM) tags
  96. find . -name '*.[ch]' | xargs ctags --extra=+f --c-kinds=+px \
  97. --regex-c++='/_PE\(([^,)]*).*/TEP_ERRNO__\1/'
  98. TAGS: force
  99. $(RM) TAGS
  100. find . -name '*.[ch]' | xargs etags \
  101. --regex='/_PE(\([^,)]*\).*/TEP_ERRNO__\1/'
  102. define do_install
  103. $(print_install) \
  104. if [ ! -d '$(DESTDIR_SQ)$2' ]; then \
  105. $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$2'; \
  106. fi; \
  107. $(INSTALL) $1 '$(DESTDIR_SQ)$2'
  108. endef
  109. install_lib: all_cmd
  110. $(Q)$(call do_install,$(LIB_FILE),$(libdir_SQ))
  111. $(Q)$(call do_install,$(BIN_FILE),$(bindir_SQ))
  112. install: install_lib
  113. clean:
  114. $(RM) $(OUTPUT)*.o *~ $(TARGETS) $(OUTPUT)*.a $(OUTPUT)*liblockdep*.so* $(VERSION_FILES) $(OUTPUT).*.d $(OUTPUT).*.cmd
  115. $(RM) tags TAGS
  116. PHONY += force
  117. force:
  118. # Declare the contents of the .PHONY variable as phony. We keep that
  119. # information in a variable so we can use it in if_changed and friends.
  120. .PHONY: $(PHONY)