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