xref: /openbmc/linux/tools/lib/subcmd/Makefile (revision 42466b9f)
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
13LD ?= $(CROSS_COMPILE)ld
14AR ?= $(CROSS_COMPILE)ar
15
16RM = rm -f
17
18MAKEFLAGS += --no-print-directory
19
20LIBFILE = $(OUTPUT)libsubcmd.a
21
22CFLAGS := $(EXTRA_WARNINGS) $(EXTRA_CFLAGS)
23CFLAGS += -ggdb3 -Wall -Wextra -std=gnu99 -fPIC
24
25ifeq ($(DEBUG),0)
26  ifeq ($(feature-fortify-source), 1)
27    CFLAGS += -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2
28  endif
29endif
30
31ifeq ($(CC_NO_CLANG), 0)
32  CFLAGS += -O3
33else
34  CFLAGS += -O6
35endif
36
37# Treat warnings as errors unless directed not to
38ifneq ($(WERROR),0)
39  CFLAGS += -Werror
40endif
41
42CFLAGS += -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE
43
44CFLAGS += -I$(srctree)/tools/include/
45
46SUBCMD_IN := $(OUTPUT)libsubcmd-in.o
47
48all:
49
50export srctree OUTPUT CC LD CFLAGS V
51include $(srctree)/tools/build/Makefile.include
52
53all: fixdep $(LIBFILE)
54
55$(SUBCMD_IN): FORCE
56	@$(MAKE) $(build)=libsubcmd
57
58$(LIBFILE): $(SUBCMD_IN)
59	$(QUIET_AR)$(RM) $@ && $(AR) rcs $@ $(SUBCMD_IN)
60
61clean:
62	$(call QUIET_CLEAN, libsubcmd) $(RM) $(LIBFILE); \
63	find $(if $(OUTPUT),$(OUTPUT),.) -name \*.o -or -name \*.o.cmd -or -name \*.o.d | xargs $(RM)
64
65FORCE:
66
67.PHONY: clean FORCE
68