xref: /linux/tools/lib/api/Makefile (revision 3a39d672e7f48b8d6b91a09afa4b55352773b4b5)
1# SPDX-License-Identifier: GPL-2.0
2include ../../scripts/Makefile.include
3include ../../scripts/utilities.mak		# QUIET_CLEAN
4
5ifeq ($(srctree),)
6srctree := $(patsubst %/,%,$(dir $(CURDIR)))
7srctree := $(patsubst %/,%,$(dir $(srctree)))
8srctree := $(patsubst %/,%,$(dir $(srctree)))
9#$(info Determined 'srctree' to be $(srctree))
10endif
11
12CC ?= $(CROSS_COMPILE)gcc
13AR ?= $(CROSS_COMPILE)ar
14LD ?= $(CROSS_COMPILE)ld
15
16MAKEFLAGS += --no-print-directory
17
18INSTALL = install
19
20
21# Use DESTDIR for installing into a different root directory.
22# This is useful for building a package. The program will be
23# installed in this directory as if it was the root directory.
24# Then the build tool can move it later.
25DESTDIR ?=
26DESTDIR_SQ = '$(subst ','\'',$(DESTDIR))'
27
28LIBFILE = $(OUTPUT)libapi.a
29
30CFLAGS := $(EXTRA_WARNINGS) $(EXTRA_CFLAGS)
31CFLAGS += -ggdb3 -Wall -Wextra -std=gnu99 -U_FORTIFY_SOURCE -fPIC
32
33ifeq ($(DEBUG),0)
34  CFLAGS += -O3
35endif
36
37ifeq ($(DEBUG),0)
38  CFLAGS += -D_FORTIFY_SOURCE
39endif
40
41# Treat warnings as errors unless directed not to
42ifneq ($(WERROR),0)
43  CFLAGS += -Werror
44endif
45
46CFLAGS += -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64
47CFLAGS += -I$(srctree)/tools/lib/api
48CFLAGS += -I$(srctree)/tools/include
49
50RM = rm -f
51
52API_IN := $(OUTPUT)libapi-in.o
53
54ifeq ($(LP64), 1)
55  libdir_relative = lib64
56else
57  libdir_relative = lib
58endif
59
60prefix ?=
61libdir = $(prefix)/$(libdir_relative)
62
63# Shell quotes
64libdir_SQ = $(subst ','\'',$(libdir))
65
66all:
67
68export srctree OUTPUT CC LD CFLAGS V
69include $(srctree)/tools/build/Makefile.include
70include $(srctree)/tools/scripts/Makefile.include
71
72all: fixdep $(LIBFILE)
73
74$(API_IN): FORCE
75	@$(MAKE) $(build)=libapi
76
77$(LIBFILE): $(API_IN)
78	$(QUIET_AR)$(RM) $@ && $(AR) rcs $@ $(API_IN)
79
80define do_install_mkdir
81	if [ ! -d '$(DESTDIR_SQ)$1' ]; then             \
82		$(INSTALL) -d -m 755 '$(DESTDIR_SQ)$1'; \
83	fi
84endef
85
86define do_install
87	if [ ! -d '$2' ]; then             \
88		$(INSTALL) -d -m 755 '$2'; \
89	fi;                                \
90	$(INSTALL) $1 $(if $3,-m $3,) '$2'
91endef
92
93install_lib: $(LIBFILE)
94	$(call QUIET_INSTALL, $(LIBFILE)) \
95		$(call do_install_mkdir,$(libdir_SQ)); \
96		cp -fpR $(LIBFILE) $(DESTDIR)$(libdir_SQ)
97
98HDRS := cpu.h debug.h io.h
99FD_HDRS := fd/array.h
100FS_HDRS := fs/fs.h fs/tracing_path.h
101INSTALL_HDRS_PFX := $(DESTDIR)$(prefix)/include/api
102INSTALL_HDRS := $(addprefix $(INSTALL_HDRS_PFX)/, $(HDRS))
103INSTALL_FD_HDRS := $(addprefix $(INSTALL_HDRS_PFX)/, $(FD_HDRS))
104INSTALL_FS_HDRS := $(addprefix $(INSTALL_HDRS_PFX)/, $(FS_HDRS))
105
106$(INSTALL_HDRS): $(INSTALL_HDRS_PFX)/%.h: %.h
107	$(call QUIET_INSTALL, $@) \
108		$(call do_install,$<,$(INSTALL_HDRS_PFX)/,644)
109
110$(INSTALL_FD_HDRS): $(INSTALL_HDRS_PFX)/fd/%.h: fd/%.h
111	$(call QUIET_INSTALL, $@) \
112		$(call do_install,$<,$(INSTALL_HDRS_PFX)/fd/,644)
113
114$(INSTALL_FS_HDRS): $(INSTALL_HDRS_PFX)/fs/%.h: fs/%.h
115	$(call QUIET_INSTALL, $@) \
116		$(call do_install,$<,$(INSTALL_HDRS_PFX)/fs/,644)
117
118install_headers: $(INSTALL_HDRS) $(INSTALL_FD_HDRS) $(INSTALL_FS_HDRS)
119	$(call QUIET_INSTALL, libapi_headers)
120
121install: install_lib install_headers
122
123clean:
124	$(call QUIET_CLEAN, libapi) $(RM) $(LIBFILE); \
125	find $(or $(OUTPUT),.) -name \*.o -or -name \*.o.cmd -or -name \*.o.d | xargs $(RM)
126
127FORCE:
128
129.PHONY: clean FORCE
130