pciexp_device: Fix a bug in pciexp_enable_ltr()
[coreboot.git] / payloads / libpayload / Makefile.payload
blobfa98d8a4de94f157a994f8493b5193ffa67711d7
1 # SPDX-License-Identifier: BSD-3-Clause
4 # This file is meant to be included by in-tree payloads
5 # to provide default targets for incremental builds.
7 # Variables with file names and directory overrides have
8 # to be defined in advance for proper dependency tracking.
9 # Then, include this file. e.g
11 #     obj := output
12 #     OBJS := $(obj)/payload.o
13 #     TARGET := $(obj)/payload.elf
14 #     include ../path/to/libpayload/Makefile.payload
17 # Find relative path to libpayload (where this Makefile resides).
18 LIBPAYLOAD_SRC := $(dir $(lastword $(MAKEFILE_LIST)))
19 LIBPAYLOAD_SRC := $(patsubst %/,%,$(LIBPAYLOAD_SRC))
21 # Build dir and config for libpayload. Need absolute
22 # paths to pass to libpayload's sub-make.
23 LIBPAYLOAD_OBJ  ?= $(CURDIR)/libpayload
24 LIBPAYLOAD      := $(LIBPAYLOAD_OBJ)/libpayload.a
25 LIBPAYLOAD_CONFIG_H := $(LIBPAYLOAD_OBJ)/libpayload-config.h
26 LIBPAYLOAD_DOTCONFIG ?= $(CURDIR)/.lp.config
27 LIBPAYLOAD_DEFCONFIG ?= $(CURDIR)/$(LIBPAYLOAD_SRC)/configs/defconfig
29 # Some default dependencies for all targets:
30 DEFAULT_DEPS := Makefile $(lastword $(MAKEFILE_LIST))
31 DEFAULT_DEPS += $(PAYLOAD_DEPS)
33 obj ?= build
35 ARCH ?=
36 OBJS ?=
37 CCACHE ?=
39 CFLAGS  = $(CFLAGS_$(ARCH))
40 CFLAGS += -Os -ffreestanding
41 CFLAGS += -Wall -Wextra -Wmissing-prototypes -Wvla -Werror
43 STRIP ?= debug
45 $(TARGET):
47 # Make is silent per default, but `make V=1` will show all calls.
48 Q:=@
49 ifneq ($(V),1)
50 ifneq ($(Q),)
51 .SILENT:
52 MAKEFLAGS += -s
53 endif
54 endif
55 export V
57 ifeq ($(filter %clean,$(MAKECMDGOALS)),)
59 -include $(LIBPAYLOAD_DOTCONFIG)
61 xcompile        := $(obj)/xcompile
62 xcompile_script := $(LIBPAYLOAD_SRC)/../../util/xcompile/xcompile
64 # In addition to the dependency below, create the file if it doesn't exist
65 # to silence warnings about a file that would be generated anyway.
66 $(if $(wildcard $(xcompile)),,$(shell   \
67         mkdir -p $(dir $(xcompile)) &&  \
68         $(xcompile_script) $(XGCCPATH) > $(xcompile) || rm -f $(xcompile)))
70 $(xcompile): $(xcompile_script)
71         $< $(XGCCPATH) > $@
73 include $(xcompile)
75 ifneq ($(XCOMPILE_COMPLETE),1)
76 $(shell rm -f $(XCOMPILE_COMPLETE))
77 $(error $(xcompile) deleted because it's invalid. \
78         Restarting the build should fix that, or explain the problem.)
79 endif
81 # `lpgcc` in in-tree mode:
82 LPGCC  = CC="$(CCACHE) $(GCC_CC_$(ARCH))"
83 LPGCC += _OBJ="$(LIBPAYLOAD_OBJ)"
84 LPGCC += $(LIBPAYLOAD_SRC)/bin/lpgcc
86 LPAS  = AS="$(AS_$(ARCH))"
87 LPAS += $(LIBPAYLOAD_SRC)/bin/lpas
89 OBJCOPY = $(OBJCOPY_$(ARCH))
91 $(obj)/%.bin: $(OBJS) $(LIBPAYLOAD) $(DEFAULT_DEPS)
92         @printf "    LPGCC      $(subst $(obj)/,,$@)\n"
93         $(LPGCC) $(CFLAGS) -o $@ $(OBJS)
95 $(obj)/%.map: $(obj)/%.bin
96         @printf "    SYMS       $(subst $(obj)/,,$@)\n"
97         $(NM_$(ARCH)) -n $< > $@
99 $(obj)/%.debug: $(obj)/%.bin
100         @printf "    DEBUG      $(subst $(obj)/,,$@)\n"
101         $(OBJCOPY) --only-keep-debug $< $@
103 .PRECIOUS: $(obj)/%.debug
105 $(obj)/%.elf: $(obj)/%.bin $(obj)/%.debug
106         @printf "    STRIP      $(subst $(obj)/,,$@)\n"
107         $(OBJCOPY) --strip-$(STRIP) $< $@
108         $(OBJCOPY) --add-gnu-debuglink=$(obj)/$*.debug $@
110 $(obj)/%.o: %.c $(LIBPAYLOAD_CONFIG_H) $(DEFAULT_DEPS)
111         @printf "    LPGCC      $(subst $(obj)/,,$@)\n"
112         $(LPGCC) -MMD $(CFLAGS) -c $< -o $@
114 $(obj)/%.S.o: %.S $(LIBPAYLOAD_CONFIG_H) $(DEFAULT_DEPS)
115         @printf "    LPAS       $(subst $(obj)/,,$@)\n"
116         $(LPAS) $< -o $@
118 -include $(OBJS:.o=.d)
120 .PRECIOUS: $(OBJS)
122 LIBPAYLOAD_OPTS := obj="$(LIBPAYLOAD_OBJ)"
123 LIBPAYLOAD_OPTS += DOTCONFIG="$(LIBPAYLOAD_DOTCONFIG)"
124 LIBPAYLOAD_OPTS += CONFIG_=CONFIG_LP_
125 LIBPAYLOAD_OPTS += $(if $(CCACHE),CONFIG_LP_CCACHE=y)
127 ifneq ($(LIBPAYLOAD_DEFCONFIG),)
128 $(LIBPAYLOAD_DOTCONFIG): $(LIBPAYLOAD_DEFCONFIG)
129         $(MAKE) -C $(LIBPAYLOAD_SRC) $(LIBPAYLOAD_OPTS) \
130                 KBUILD_DEFCONFIG=$(LIBPAYLOAD_DEFCONFIG) defconfig
131 endif
133 $(LIBPAYLOAD_CONFIG_H): $(LIBPAYLOAD_DOTCONFIG)
134         $(MAKE) -C $(LIBPAYLOAD_SRC) $(LIBPAYLOAD_OPTS) $(LIBPAYLOAD_CONFIG_H)
136 force-relay:
138 lp-%: force-relay
139         $(MAKE) -C $(LIBPAYLOAD_SRC) $(LIBPAYLOAD_OPTS) $*
141 $(LIBPAYLOAD): force-relay | $(LIBPAYLOAD_CONFIG_H)
142         $(MAKE) -C $(LIBPAYLOAD_SRC) $(LIBPAYLOAD_OPTS)
144 $(shell mkdir -p $(sort $(dir $(OBJS))))
146 .PHONY: force-relay
148 else # %clean,$(MAKECMDGOALS)
150 default-payload-clean:
151         rm -rf $(obj) $(LIBPAYLOAD_OBJ)
152 clean: default-payload-clean
154 default-payload-distclean: clean
155         rm -f $(LIBPAYLOAD_DOTCONFIG) $(LIBPAYLOAD_DOTCONFIG).old
156 distclean: default-payload-distclean
158 .PHONY: default-payload-clean clean default-payload-distclean distclean
160 endif