rjw | 1f88458 | 2022-01-06 17:20:42 +0800 | [diff] [blame^] | 1 | # SPDX-License-Identifier: GPL-2.0 |
| 2 | include ../../scripts/Makefile.include |
| 3 | include ../../scripts/utilities.mak # QUIET_CLEAN |
| 4 | |
| 5 | ifeq ($(srctree),) |
| 6 | srctree := $(patsubst %/,%,$(dir $(CURDIR))) |
| 7 | srctree := $(patsubst %/,%,$(dir $(srctree))) |
| 8 | srctree := $(patsubst %/,%,$(dir $(srctree))) |
| 9 | #$(info Determined 'srctree' to be $(srctree)) |
| 10 | endif |
| 11 | |
| 12 | CC ?= $(CROSS_COMPILE)gcc |
| 13 | LD ?= $(CROSS_COMPILE)ld |
| 14 | AR ?= $(CROSS_COMPILE)ar |
| 15 | |
| 16 | RM = rm -f |
| 17 | |
| 18 | MAKEFLAGS += --no-print-directory |
| 19 | |
| 20 | LIBFILE = $(OUTPUT)libsubcmd.a |
| 21 | |
| 22 | CFLAGS := $(EXTRA_WARNINGS) $(EXTRA_CFLAGS) |
| 23 | CFLAGS += -ggdb3 -Wall -Wextra -std=gnu99 -fPIC |
| 24 | |
| 25 | ifeq ($(DEBUG),0) |
| 26 | ifeq ($(feature-fortify-source), 1) |
| 27 | CFLAGS += -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 |
| 28 | endif |
| 29 | endif |
| 30 | |
| 31 | ifeq ($(DEBUG),1) |
| 32 | CFLAGS += -O0 |
| 33 | else ifeq ($(CC_NO_CLANG), 0) |
| 34 | CFLAGS += -O3 |
| 35 | else |
| 36 | CFLAGS += -O6 |
| 37 | endif |
| 38 | |
| 39 | # Treat warnings as errors unless directed not to |
| 40 | ifneq ($(WERROR),0) |
| 41 | CFLAGS += -Werror |
| 42 | endif |
| 43 | |
| 44 | CFLAGS += -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE |
| 45 | |
| 46 | CFLAGS += -I$(srctree)/tools/include/ |
| 47 | |
| 48 | SUBCMD_IN := $(OUTPUT)libsubcmd-in.o |
| 49 | |
| 50 | all: |
| 51 | |
| 52 | export srctree OUTPUT CC LD CFLAGS V |
| 53 | include $(srctree)/tools/build/Makefile.include |
| 54 | |
| 55 | all: fixdep $(LIBFILE) |
| 56 | |
| 57 | $(SUBCMD_IN): FORCE |
| 58 | @$(MAKE) $(build)=libsubcmd |
| 59 | |
| 60 | $(LIBFILE): $(SUBCMD_IN) |
| 61 | $(QUIET_AR)$(RM) $@ && $(AR) rcs $@ $(SUBCMD_IN) |
| 62 | |
| 63 | clean: |
| 64 | $(call QUIET_CLEAN, libsubcmd) $(RM) $(LIBFILE); \ |
| 65 | find $(if $(OUTPUT),$(OUTPUT),.) -name \*.o -or -name \*.o.cmd -or -name \*.o.d | xargs $(RM) |
| 66 | |
| 67 | FORCE: |
| 68 | |
| 69 | .PHONY: clean FORCE |