Makefile 4.0 KB

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