xref: /openbmc/linux/tools/lib/api/Makefile (revision 8d1f68bd)
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)
34ifeq ($(CC_NO_CLANG), 0)
35  CFLAGS += -O3
36else
37  CFLAGS += -O6
38endif
39endif
40
41ifeq ($(DEBUG),0)
42  CFLAGS += -D_FORTIFY_SOURCE
43endif
44
45# Treat warnings as errors unless directed not to
46ifneq ($(WERROR),0)
47  CFLAGS += -Werror
48endif
49
50CFLAGS += -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64
51CFLAGS += -I$(srctree)/tools/lib/api
52CFLAGS += -I$(srctree)/tools/include
53
54RM = rm -f
55
56API_IN := $(OUTPUT)libapi-in.o
57
58ifeq ($(LP64), 1)
59  libdir_relative = lib64
60else
61  libdir_relative = lib
62endif
63
64prefix ?=
65libdir = $(prefix)/$(libdir_relative)
66
67# Shell quotes
68libdir_SQ = $(subst ','\'',$(libdir))
69
70all:
71
72export srctree OUTPUT CC LD CFLAGS V
73include $(srctree)/tools/build/Makefile.include
74include $(srctree)/tools/scripts/Makefile.include
75
76all: fixdep $(LIBFILE)
77
78$(API_IN): FORCE
79	@$(MAKE) $(build)=libapi
80
81$(LIBFILE): $(API_IN)
82	$(QUIET_AR)$(RM) $@ && $(AR) rcs $@ $(API_IN)
83
84define do_install_mkdir
85	if [ ! -d '$(DESTDIR_SQ)$1' ]; then             \
86		$(INSTALL) -d -m 755 '$(DESTDIR_SQ)$1'; \
87	fi
88endef
89
90define do_install
91	if [ ! -d '$(DESTDIR_SQ)$2' ]; then             \
92		$(INSTALL) -d -m 755 '$(DESTDIR_SQ)$2'; \
93	fi;                                             \
94	$(INSTALL) $1 $(if $3,-m $3,) '$(DESTDIR_SQ)$2'
95endef
96
97install_lib: $(LIBFILE)
98	$(call QUIET_INSTALL, $(LIBFILE)) \
99		$(call do_install_mkdir,$(libdir_SQ)); \
100		cp -fpR $(LIBFILE) $(DESTDIR)$(libdir_SQ)
101
102install_headers:
103	$(call QUIET_INSTALL, headers) \
104		$(call do_install,cpu.h,$(prefix)/include/api,644); \
105		$(call do_install,debug.h,$(prefix)/include/api,644); \
106		$(call do_install,io.h,$(prefix)/include/api,644); \
107		$(call do_install,fd/array.h,$(prefix)/include/api/fd,644); \
108		$(call do_install,fs/fs.h,$(prefix)/include/api/fs,644);
109		$(call do_install,fs/tracing_path.h,$(prefix)/include/api/fs,644);
110
111install: install_lib install_headers
112
113clean:
114	$(call QUIET_CLEAN, libapi) $(RM) $(LIBFILE); \
115	find $(or $(OUTPUT),.) -name \*.o -or -name \*.o.cmd -or -name \*.o.d | xargs $(RM)
116
117FORCE:
118
119.PHONY: clean FORCE
120