xref: /linux/tools/lib/api/Makefile (revision 3a39d672e7f48b8d6b91a09afa4b55352773b4b5)
1b2441318SGreg Kroah-Hartman# SPDX-License-Identifier: GPL-2.0
2553873e1SBorislav Petkovinclude ../../scripts/Makefile.include
3ca70c24fSArnaldo Carvalho de Meloinclude ../../scripts/utilities.mak		# QUIET_CLEAN
4553873e1SBorislav Petkov
5b4f91668SJiri Olsaifeq ($(srctree),)
6e19b7ceeSUwe Kleine-Königsrctree := $(patsubst %/,%,$(dir $(CURDIR)))
7b4f91668SJiri Olsasrctree := $(patsubst %/,%,$(dir $(srctree)))
8b4f91668SJiri Olsasrctree := $(patsubst %/,%,$(dir $(srctree)))
9b4f91668SJiri Olsa#$(info Determined 'srctree' to be $(srctree))
10b4f91668SJiri Olsaendif
11b4f91668SJiri Olsa
1212024aacSDavid Carrillo-CisnerosCC ?= $(CROSS_COMPILE)gcc
1312024aacSDavid Carrillo-CisnerosAR ?= $(CROSS_COMPILE)ar
1412024aacSDavid Carrillo-CisnerosLD ?= $(CROSS_COMPILE)ld
15553873e1SBorislav Petkov
16b4f91668SJiri OlsaMAKEFLAGS += --no-print-directory
17553873e1SBorislav Petkov
18a6efaa2cSIan RogersINSTALL = install
19a6efaa2cSIan Rogers
20a6efaa2cSIan Rogers
21a6efaa2cSIan Rogers# Use DESTDIR for installing into a different root directory.
22a6efaa2cSIan Rogers# This is useful for building a package. The program will be
23a6efaa2cSIan Rogers# installed in this directory as if it was the root directory.
24a6efaa2cSIan Rogers# Then the build tool can move it later.
25a6efaa2cSIan RogersDESTDIR ?=
26a6efaa2cSIan RogersDESTDIR_SQ = '$(subst ','\'',$(DESTDIR))'
27a6efaa2cSIan Rogers
28285a8f24SJiri OlsaLIBFILE = $(OUTPUT)libapi.a
29553873e1SBorislav Petkov
30b4f91668SJiri OlsaCFLAGS := $(EXTRA_WARNINGS) $(EXTRA_CFLAGS)
3158b79186SJiri OlsaCFLAGS += -ggdb3 -Wall -Wextra -std=gnu99 -U_FORTIFY_SOURCE -fPIC
3249b3cd30SArnaldo Carvalho de Melo
3358b79186SJiri Olsaifeq ($(DEBUG),0)
3449b3cd30SArnaldo Carvalho de Melo  CFLAGS += -O3
3558b79186SJiri Olsaendif
3658b79186SJiri Olsa
3758b79186SJiri Olsaifeq ($(DEBUG),0)
3858b79186SJiri Olsa  CFLAGS += -D_FORTIFY_SOURCE
3958b79186SJiri Olsaendif
40b983d544SChris Phlipot
41b983d544SChris Phlipot# Treat warnings as errors unless directed not to
42b983d544SChris Phlipotifneq ($(WERROR),0)
43b983d544SChris Phlipot  CFLAGS += -Werror
44b983d544SChris Phlipotendif
45b983d544SChris Phlipot
46b4f91668SJiri OlsaCFLAGS += -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64
47975f14faSJiri OlsaCFLAGS += -I$(srctree)/tools/lib/api
48b31e3e33SArnaldo Carvalho de MeloCFLAGS += -I$(srctree)/tools/include
49553873e1SBorislav Petkov
50553873e1SBorislav PetkovRM = rm -f
51553873e1SBorislav Petkov
52285a8f24SJiri OlsaAPI_IN := $(OUTPUT)libapi-in.o
53553873e1SBorislav Petkov
54a6efaa2cSIan Rogersifeq ($(LP64), 1)
55a6efaa2cSIan Rogers  libdir_relative = lib64
56a6efaa2cSIan Rogerselse
57a6efaa2cSIan Rogers  libdir_relative = lib
58a6efaa2cSIan Rogersendif
59a6efaa2cSIan Rogers
60a6efaa2cSIan Rogersprefix ?=
61a6efaa2cSIan Rogerslibdir = $(prefix)/$(libdir_relative)
62a6efaa2cSIan Rogers
63a6efaa2cSIan Rogers# Shell quotes
64a6efaa2cSIan Rogerslibdir_SQ = $(subst ','\'',$(libdir))
65a6efaa2cSIan Rogers
667c422f55SJiri Olsaall:
677c422f55SJiri Olsa
68b4f91668SJiri Olsaexport srctree OUTPUT CC LD CFLAGS V
69ab6201d0SJiri Olsainclude $(srctree)/tools/build/Makefile.include
70a6efaa2cSIan Rogersinclude $(srctree)/tools/scripts/Makefile.include
71553873e1SBorislav Petkov
727c422f55SJiri Olsaall: fixdep $(LIBFILE)
73553873e1SBorislav Petkov
74b4f91668SJiri Olsa$(API_IN): FORCE
75285a8f24SJiri Olsa	@$(MAKE) $(build)=libapi
76b4f91668SJiri Olsa
77b4f91668SJiri Olsa$(LIBFILE): $(API_IN)
78b4f91668SJiri Olsa	$(QUIET_AR)$(RM) $@ && $(AR) rcs $@ $(API_IN)
79553873e1SBorislav Petkov
80a6efaa2cSIan Rogersdefine do_install_mkdir
81a6efaa2cSIan Rogers	if [ ! -d '$(DESTDIR_SQ)$1' ]; then             \
82a6efaa2cSIan Rogers		$(INSTALL) -d -m 755 '$(DESTDIR_SQ)$1'; \
83a6efaa2cSIan Rogers	fi
84a6efaa2cSIan Rogersendef
85a6efaa2cSIan Rogers
86a6efaa2cSIan Rogersdefine do_install
87*1849f9f0SIan Rogers	if [ ! -d '$2' ]; then             \
88*1849f9f0SIan Rogers		$(INSTALL) -d -m 755 '$2'; \
89a6efaa2cSIan Rogers	fi;                                \
90*1849f9f0SIan Rogers	$(INSTALL) $1 $(if $3,-m $3,) '$2'
91a6efaa2cSIan Rogersendef
92a6efaa2cSIan Rogers
93a6efaa2cSIan Rogersinstall_lib: $(LIBFILE)
94a6efaa2cSIan Rogers	$(call QUIET_INSTALL, $(LIBFILE)) \
95a6efaa2cSIan Rogers		$(call do_install_mkdir,$(libdir_SQ)); \
96a6efaa2cSIan Rogers		cp -fpR $(LIBFILE) $(DESTDIR)$(libdir_SQ)
97a6efaa2cSIan Rogers
98*1849f9f0SIan RogersHDRS := cpu.h debug.h io.h
99*1849f9f0SIan RogersFD_HDRS := fd/array.h
100*1849f9f0SIan RogersFS_HDRS := fs/fs.h fs/tracing_path.h
101*1849f9f0SIan RogersINSTALL_HDRS_PFX := $(DESTDIR)$(prefix)/include/api
102*1849f9f0SIan RogersINSTALL_HDRS := $(addprefix $(INSTALL_HDRS_PFX)/, $(HDRS))
103*1849f9f0SIan RogersINSTALL_FD_HDRS := $(addprefix $(INSTALL_HDRS_PFX)/, $(FD_HDRS))
104*1849f9f0SIan RogersINSTALL_FS_HDRS := $(addprefix $(INSTALL_HDRS_PFX)/, $(FS_HDRS))
105*1849f9f0SIan Rogers
106*1849f9f0SIan Rogers$(INSTALL_HDRS): $(INSTALL_HDRS_PFX)/%.h: %.h
107*1849f9f0SIan Rogers	$(call QUIET_INSTALL, $@) \
108*1849f9f0SIan Rogers		$(call do_install,$<,$(INSTALL_HDRS_PFX)/,644)
109*1849f9f0SIan Rogers
110*1849f9f0SIan Rogers$(INSTALL_FD_HDRS): $(INSTALL_HDRS_PFX)/fd/%.h: fd/%.h
111*1849f9f0SIan Rogers	$(call QUIET_INSTALL, $@) \
112*1849f9f0SIan Rogers		$(call do_install,$<,$(INSTALL_HDRS_PFX)/fd/,644)
113*1849f9f0SIan Rogers
114*1849f9f0SIan Rogers$(INSTALL_FS_HDRS): $(INSTALL_HDRS_PFX)/fs/%.h: fs/%.h
115*1849f9f0SIan Rogers	$(call QUIET_INSTALL, $@) \
116*1849f9f0SIan Rogers		$(call do_install,$<,$(INSTALL_HDRS_PFX)/fs/,644)
117*1849f9f0SIan Rogers
118*1849f9f0SIan Rogersinstall_headers: $(INSTALL_HDRS) $(INSTALL_FD_HDRS) $(INSTALL_FS_HDRS)
119*1849f9f0SIan Rogers	$(call QUIET_INSTALL, libapi_headers)
120a6efaa2cSIan Rogers
121a6efaa2cSIan Rogersinstall: install_lib install_headers
122a6efaa2cSIan Rogers
123553873e1SBorislav Petkovclean:
124285a8f24SJiri Olsa	$(call QUIET_CLEAN, libapi) $(RM) $(LIBFILE); \
1255c816641SMasahiro Yamada	find $(or $(OUTPUT),.) -name \*.o -or -name \*.o.cmd -or -name \*.o.d | xargs $(RM)
126553873e1SBorislav Petkov
127b4f91668SJiri OlsaFORCE:
128b4f91668SJiri Olsa
129b4f91668SJiri Olsa.PHONY: clean FORCE
130