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