Linux Audio

Check our new training course

Linux kernel drivers training

May 6-19, 2025
Register
Loading...
v3.15
 
  1# file format version
  2FILE_VERSION = 1
  3
  4LIBLOCKDEP_VERSION=$(shell make --no-print-directory -sC ../../.. kernelversion)
  5
  6# Makefiles suck: This macro sets a default value of $(2) for the
  7# variable named by $(1), unless the variable has been set by
  8# environment or command line. This is necessary for CC and AR
  9# because make sets default values, so the simpler ?= approach
 10# won't work as expected.
 11define allow-override
 12  $(if $(or $(findstring environment,$(origin $(1))),\
 13            $(findstring command line,$(origin $(1)))),,\
 14    $(eval $(1) = $(2)))
 15endef
 16
 17# Allow setting CC and AR, or setting CROSS_COMPILE as a prefix.
 18$(call allow-override,CC,$(CROSS_COMPILE)gcc)
 19$(call allow-override,AR,$(CROSS_COMPILE)ar)
 
 20
 21INSTALL = install
 22
 23# Use DESTDIR for installing into a different root directory.
 24# This is useful for building a package. The program will be
 25# installed in this directory as if it was the root directory.
 26# Then the build tool can move it later.
 27DESTDIR ?=
 28DESTDIR_SQ = '$(subst ','\'',$(DESTDIR))'
 29
 30prefix ?= /usr/local
 31libdir_relative = lib
 32libdir = $(prefix)/$(libdir_relative)
 33bindir_relative = bin
 34bindir = $(prefix)/$(bindir_relative)
 35
 36export DESTDIR DESTDIR_SQ INSTALL
 37
 
 
 
 
 38# copy a bit from Linux kbuild
 39
 40ifeq ("$(origin V)", "command line")
 41  VERBOSE = $(V)
 42endif
 43ifndef VERBOSE
 44  VERBOSE = 0
 45endif
 46
 47ifeq ("$(origin O)", "command line")
 48  BUILD_OUTPUT := $(O)
 
 
 
 49endif
 50
 51ifeq ($(BUILD_SRC),)
 52ifneq ($(BUILD_OUTPUT),)
 53
 54define build_output
 55	$(if $(VERBOSE:1=),@)$(MAKE) -C $(BUILD_OUTPUT)	\
 56	BUILD_SRC=$(CURDIR) -f $(CURDIR)/Makefile $1
 57endef
 58
 59saved-output := $(BUILD_OUTPUT)
 60BUILD_OUTPUT := $(shell cd $(BUILD_OUTPUT) && /bin/pwd)
 61$(if $(BUILD_OUTPUT),, \
 62     $(error output directory "$(saved-output)" does not exist))
 63
 64all: sub-make
 65
 66gui: force
 67	$(call build_output, all_cmd)
 68
 69$(filter-out gui,$(MAKECMDGOALS)): sub-make
 70
 71sub-make: force
 72	$(call build_output, $(MAKECMDGOALS))
 73
 74
 75# Leave processing to above invocation of make
 76skip-makefile := 1
 77
 78endif # BUILD_OUTPUT
 79endif # BUILD_SRC
 80
 81# We process the rest of the Makefile if this is the final invocation of make
 82ifeq ($(skip-makefile),)
 83
 84srctree		:= $(realpath $(if $(BUILD_SRC),$(BUILD_SRC),$(CURDIR)))
 85objtree		:= $(realpath $(CURDIR))
 86src		:= $(srctree)
 87obj		:= $(objtree)
 88
 89export prefix libdir bindir src obj
 90
 91# Shell quotes
 92libdir_SQ = $(subst ','\'',$(libdir))
 93bindir_SQ = $(subst ','\'',$(bindir))
 94
 95LIB_FILE = liblockdep.a liblockdep.so.$(LIBLOCKDEP_VERSION)
 
 96BIN_FILE = lockdep
 
 97
 98CONFIG_INCLUDES =
 99CONFIG_LIBS	=
100CONFIG_FLAGS	=
101
102OBJ		= $@
103N		=
104
105export Q VERBOSE
106
107INCLUDES = -I. -I/usr/local/include -I./uinclude -I./include $(CONFIG_INCLUDES)
108
109# Set compile option CFLAGS if not set elsewhere
110CFLAGS ?= -g -DCONFIG_LOCKDEP -DCONFIG_STACKTRACE -DCONFIG_PROVE_LOCKING -DBITS_PER_LONG=__WORDSIZE -DLIBLOCKDEP_VERSION='"$(LIBLOCKDEP_VERSION)"' -rdynamic -O0 -g
 
 
111
112override CFLAGS += $(CONFIG_FLAGS) $(INCLUDES) $(PLUGIN_DIR_SQ)
113
114ifeq ($(VERBOSE),1)
115  Q =
116  print_compile =
117  print_app_build =
118  print_fpic_compile =
119  print_shared_lib_compile =
120  print_install =
121else
122  Q = @
123  print_compile =		echo '  CC                 '$(OBJ);
124  print_app_build =		echo '  BUILD              '$(OBJ);
125  print_fpic_compile =		echo '  CC FPIC            '$(OBJ);
126  print_shared_lib_compile =	echo '  BUILD SHARED LIB   '$(OBJ);
127  print_static_lib_build =	echo '  BUILD STATIC LIB   '$(OBJ);
128  print_install =		echo '  INSTALL     '$1'	to	$(DESTDIR_SQ)$2';
129endif
130
131do_fpic_compile =					\
132	($(print_fpic_compile)				\
133	$(CC) -c $(CFLAGS) $(EXT) -fPIC $< -o $@)
134
135do_app_build =						\
136	($(print_app_build)				\
137	$(CC) $^ -rdynamic -o $@ $(CONFIG_LIBS) $(LIBS))
138
139do_compile_shared_library =			\
140	($(print_shared_lib_compile)		\
141	$(CC) --shared $^ -o $@ -lpthread -ldl -Wl,-soname='"$@"';$(shell ln -s $@ liblockdep.so))
142
143do_build_static_lib =				\
144	($(print_static_lib_build)		\
145	$(RM) $@;  $(AR) rcs $@ $^)
146
147
148define do_compile
149	$(print_compile)						\
150	$(CC) -c $(CFLAGS) $(EXT) $< -o $(obj)/$@;
151endef
152
153$(obj)/%.o: $(src)/%.c
154	$(Q)$(call do_compile)
155
156%.o: $(src)/%.c
157	$(Q)$(call do_compile)
158
159PEVENT_LIB_OBJS = common.o lockdep.o preload.o rbtree.o
160
161ALL_OBJS = $(PEVENT_LIB_OBJS)
162
163CMD_TARGETS = $(LIB_FILE)
164
165TARGETS = $(CMD_TARGETS)
166
167
168all: all_cmd
169
170all_cmd: $(CMD_TARGETS)
171
172liblockdep.so.$(LIBLOCKDEP_VERSION): $(PEVENT_LIB_OBJS)
 
 
 
173	$(Q)$(do_compile_shared_library)
174
175liblockdep.a: $(PEVENT_LIB_OBJS)
176	$(Q)$(do_build_static_lib)
177
178$(PEVENT_LIB_OBJS): %.o: $(src)/%.c
179	$(Q)$(do_fpic_compile)
180
181## make deps
182
183all_objs := $(sort $(ALL_OBJS))
184all_deps := $(all_objs:%.o=.%.d)
185
186# let .d file also depends on the source and header files
187define check_deps
188		@set -e; $(RM) $@; \
189		$(CC) -MM $(CFLAGS) $< > $@.$$$$; \
190		sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@; \
191		$(RM) $@.$$$$
192endef
193
194$(all_deps): .%.d: $(src)/%.c
195	$(Q)$(call check_deps)
196
197$(all_objs) : %.o : .%.d
198
199dep_includes := $(wildcard $(all_deps))
200
201ifneq ($(dep_includes),)
202 include $(dep_includes)
203endif
204
205### Detect environment changes
206TRACK_CFLAGS = $(subst ','\'',$(CFLAGS)):$(ARCH):$(CROSS_COMPILE)
207
208tags:	force
209	$(RM) tags
210	find . -name '*.[ch]' | xargs ctags --extra=+f --c-kinds=+px \
211	--regex-c++='/_PE\(([^,)]*).*/PEVENT_ERRNO__\1/'
212
213TAGS:	force
214	$(RM) TAGS
215	find . -name '*.[ch]' | xargs etags \
216	--regex='/_PE(\([^,)]*\).*/PEVENT_ERRNO__\1/'
217
218define do_install
219	$(print_install)				\
220	if [ ! -d '$(DESTDIR_SQ)$2' ]; then		\
221		$(INSTALL) -d -m 755 '$(DESTDIR_SQ)$2';	\
222	fi;						\
223	$(INSTALL) $1 '$(DESTDIR_SQ)$2'
224endef
225
226install_lib: all_cmd
227	$(Q)$(call do_install,$(LIB_FILE),$(libdir_SQ))
228	$(Q)$(call do_install,$(BIN_FILE),$(bindir_SQ))
229
230install: install_lib
231
232clean:
233	$(RM) *.o *~ $(TARGETS) *.a *liblockdep*.so* $(VERSION_FILES) .*.d
234	$(RM) tags TAGS
235
236endif # skip-makefile
237
238PHONY += force
239force:
240
241# Declare the contents of the .PHONY variable as phony.  We keep that
242# information in a variable so we can use it in if_changed and friends.
243.PHONY: $(PHONY)
v5.4
  1# SPDX-License-Identifier: GPL-2.0
  2# file format version
  3FILE_VERSION = 1
  4
  5LIBLOCKDEP_VERSION=$(shell make --no-print-directory -sC ../../.. kernelversion)
  6
  7# Makefiles suck: This macro sets a default value of $(2) for the
  8# variable named by $(1), unless the variable has been set by
  9# environment or command line. This is necessary for CC and AR
 10# because make sets default values, so the simpler ?= approach
 11# won't work as expected.
 12define allow-override
 13  $(if $(or $(findstring environment,$(origin $(1))),\
 14            $(findstring command line,$(origin $(1)))),,\
 15    $(eval $(1) = $(2)))
 16endef
 17
 18# Allow setting CC and AR and LD, or setting CROSS_COMPILE as a prefix.
 19$(call allow-override,CC,$(CROSS_COMPILE)gcc)
 20$(call allow-override,AR,$(CROSS_COMPILE)ar)
 21$(call allow-override,LD,$(CROSS_COMPILE)ld)
 22
 23INSTALL = install
 24
 25# Use DESTDIR for installing into a different root directory.
 26# This is useful for building a package. The program will be
 27# installed in this directory as if it was the root directory.
 28# Then the build tool can move it later.
 29DESTDIR ?=
 30DESTDIR_SQ = '$(subst ','\'',$(DESTDIR))'
 31
 32prefix ?= /usr/local
 33libdir_relative = lib
 34libdir = $(prefix)/$(libdir_relative)
 35bindir_relative = bin
 36bindir = $(prefix)/$(bindir_relative)
 37
 38export DESTDIR DESTDIR_SQ INSTALL
 39
 40MAKEFLAGS += --no-print-directory
 41
 42include ../../scripts/Makefile.include
 43
 44# copy a bit from Linux kbuild
 45
 46ifeq ("$(origin V)", "command line")
 47  VERBOSE = $(V)
 48endif
 49ifndef VERBOSE
 50  VERBOSE = 0
 51endif
 52
 53ifeq ($(srctree),)
 54srctree := $(patsubst %/,%,$(dir $(CURDIR)))
 55srctree := $(patsubst %/,%,$(dir $(srctree)))
 56srctree := $(patsubst %/,%,$(dir $(srctree)))
 57#$(info Determined 'srctree' to be $(srctree))
 58endif
 59
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 60# Shell quotes
 61libdir_SQ = $(subst ','\'',$(libdir))
 62bindir_SQ = $(subst ','\'',$(bindir))
 63
 64LIB_IN := $(OUTPUT)liblockdep-in.o
 65
 66BIN_FILE = lockdep
 67LIB_FILE = $(OUTPUT)liblockdep.a $(OUTPUT)liblockdep.so.$(LIBLOCKDEP_VERSION)
 68
 69CONFIG_INCLUDES =
 70CONFIG_LIBS	=
 71CONFIG_FLAGS	=
 72
 73OBJ		= $@
 74N		=
 75
 76export Q VERBOSE
 77
 78INCLUDES = -I. -I./uinclude -I./include -I../../include $(CONFIG_INCLUDES)
 79
 80# Set compile option CFLAGS if not set elsewhere
 81CFLAGS ?= -g -DCONFIG_LOCKDEP -DCONFIG_STACKTRACE -DCONFIG_PROVE_LOCKING -DBITS_PER_LONG=__WORDSIZE -DLIBLOCKDEP_VERSION='"$(LIBLOCKDEP_VERSION)"' -rdynamic -O0 -g
 82CFLAGS += -fPIC
 83CFLAGS += -Wall
 84
 85override CFLAGS += $(CONFIG_FLAGS) $(INCLUDES) $(PLUGIN_DIR_SQ)
 86
 87ifeq ($(VERBOSE),1)
 88  Q =
 
 
 
 89  print_shared_lib_compile =
 90  print_install =
 91else
 92  Q = @
 93  print_shared_lib_compile =	echo '  LD       '$(OBJ);
 94  print_static_lib_build =	echo '  LD       '$(OBJ);
 95  print_install =		echo '  INSTALL  '$1'	to	$(DESTDIR_SQ)$2';
 
 
 
 96endif
 97
 98all:
 99
100export srctree OUTPUT CC LD CFLAGS V
101include $(srctree)/tools/build/Makefile.include
 
 
 
102
103do_compile_shared_library =			\
104	($(print_shared_lib_compile)		\
105	$(CC) $(LDFLAGS) --shared $^ -o $@ -lpthread -ldl -Wl,-soname='$(@F)';$(shell ln -sf $(@F) $(@D)/liblockdep.so))
106
107do_build_static_lib =				\
108	($(print_static_lib_build)		\
109	$(RM) $@;  $(AR) rcs $@ $^)
110
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
111CMD_TARGETS = $(LIB_FILE)
112
113TARGETS = $(CMD_TARGETS)
114
115
116all: fixdep all_cmd
117
118all_cmd: $(CMD_TARGETS)
119
120$(LIB_IN): force
121	$(Q)$(MAKE) $(build)=liblockdep
122
123$(OUTPUT)liblockdep.so.$(LIBLOCKDEP_VERSION): $(LIB_IN)
124	$(Q)$(do_compile_shared_library)
125
126$(OUTPUT)liblockdep.a: $(LIB_IN)
127	$(Q)$(do_build_static_lib)
128
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
129tags:	force
130	$(RM) tags
131	find . -name '*.[ch]' | xargs ctags --extra=+f --c-kinds=+px \
132	--regex-c++='/_PE\(([^,)]*).*/TEP_ERRNO__\1/'
133
134TAGS:	force
135	$(RM) TAGS
136	find . -name '*.[ch]' | xargs etags \
137	--regex='/_PE(\([^,)]*\).*/TEP_ERRNO__\1/'
138
139define do_install
140	$(print_install)				\
141	if [ ! -d '$(DESTDIR_SQ)$2' ]; then		\
142		$(INSTALL) -d -m 755 '$(DESTDIR_SQ)$2';	\
143	fi;						\
144	$(INSTALL) $1 '$(DESTDIR_SQ)$2'
145endef
146
147install_lib: all_cmd
148	$(Q)$(call do_install,$(LIB_FILE),$(libdir_SQ))
149	$(Q)$(call do_install,$(BIN_FILE),$(bindir_SQ))
150
151install: install_lib
152
153clean:
154	$(RM) $(OUTPUT)*.o *~ $(TARGETS) $(OUTPUT)*.a $(OUTPUT)*liblockdep*.so* $(VERSION_FILES) $(OUTPUT).*.d $(OUTPUT).*.cmd
155	$(RM) tags TAGS
 
 
156
157PHONY += force
158force:
159
160# Declare the contents of the .PHONY variable as phony.  We keep that
161# information in a variable so we can use it in if_changed and friends.
162.PHONY: $(PHONY)