xref: /linux/tools/testing/shared/shared.mk (revision d794cd23dc81f4e61eb166a214ea22a5b6a09d02)
1# SPDX-License-Identifier: GPL-2.0
2include ../../scripts/Makefile.arch
3
4CFLAGS += -I../shared -I. -I../../include -I../../arch/$(SRCARCH)/include \
5	  -I../../../lib -g -Og -Wall \
6	  -D_LGPL_SOURCE -fsanitize=address -fsanitize=undefined
7LDFLAGS += -fsanitize=address -fsanitize=undefined
8LDLIBS += -lpthread -lurcu
9LIBS := slab.o find_bit.o bitmap.o hweight.o vsprintf.o
10SHARED_OFILES = xarray-shared.o radix-tree.o idr.o linux.o $(LIBS)
11
12SHARED_DEPS = Makefile ../shared/shared.mk ../shared/*.h generated/map-shift.h \
13	generated/bit-length.h generated/autoconf.h \
14	../../include/linux/*.h \
15	../../include/asm/*.h \
16	../../arch/$(SRCARCH)/include/asm/*.h \
17	../../../include/linux/xarray.h \
18	../../../include/linux/maple_tree.h \
19	../../../include/linux/radix-tree.h \
20	../../../lib/radix-tree.h \
21	../../../include/linux/idr.h \
22	../../../lib/maple_tree.c \
23	../../../lib/test_maple_tree.c
24
25ifndef SHIFT
26	SHIFT=3
27endif
28
29ifeq ($(BUILD), 32)
30	CFLAGS += -m32
31	LDFLAGS += -m32
32LONG_BIT := 32
33endif
34
35ifndef LONG_BIT
36LONG_BIT := $(shell getconf LONG_BIT)
37endif
38
39%.o: ../shared/%.c
40	$(CC) -c $(CFLAGS) $< -o $@
41
42vpath %.c ../../lib
43
44$(SHARED_OFILES): $(SHARED_DEPS)
45
46radix-tree.c: ../../../lib/radix-tree.c
47	sed -e 's/^static //' -e 's/__always_inline //' -e 's/inline //' < $< > $@
48
49idr.c: ../../../lib/idr.c
50	sed -e 's/^static //' -e 's/__always_inline //' -e 's/inline //' < $< > $@
51
52xarray-shared.o: ../shared/xarray-shared.c ../../../lib/xarray.c \
53	../../../lib/test_xarray.c
54
55maple-shared.o: ../shared/maple-shared.c ../../../lib/maple_tree.c \
56	../../../lib/test_maple_tree.c
57
58generated/autoconf.h:
59	@mkdir -p generated
60	cp ../shared/autoconf.h generated/autoconf.h
61
62generated/map-shift.h:
63	@mkdir -p generated
64	@if ! grep -qws $(SHIFT) generated/map-shift.h; then            \
65		echo "Generating $@";                                   \
66		echo "#define XA_CHUNK_SHIFT $(SHIFT)" >                \
67				generated/map-shift.h;                  \
68	fi
69
70generated/bit-length.h: FORCE
71	@mkdir -p generated
72	@if ! grep -qws CONFIG_$(LONG_BIT)BIT generated/bit-length.h; then   \
73		echo "Generating $@";                                        \
74		echo "#define CONFIG_$(LONG_BIT)BIT 1" > $@;                 \
75		echo "#define CONFIG_PHYS_ADDR_T_$(LONG_BIT)BIT 1" >> $@;    \
76	fi
77
78FORCE: ;
79