/ Makefile
Makefile
  1  ## SPDX-License-Identifier: BSD-3-Clause
  2  
  3  ifneq ($(words $(CURDIR)),1)
  4      $(error Error: Path to the main directory cannot contain spaces)
  5  endif
  6  top := $(CURDIR)
  7  src := src
  8  srck := $(top)/util/kconfig
  9  obj ?= build
 10  override obj := $(subst $(top)/,,$(abspath $(obj)))
 11  xcompile ?= $(obj)/xcompile
 12  objutil ?= $(obj)/util
 13  objk := $(objutil)/kconfig
 14  absobj := $(abspath $(obj))
 15  
 16  additional-dirs :=
 17  
 18  VBOOT_HOST_BUILD ?= $(abspath $(objutil)/vboot_lib)
 19  
 20  COREBOOT_EXPORTS := COREBOOT_EXPORTS
 21  COREBOOT_EXPORTS += top src srck obj objutil objk
 22  
 23  DOTCONFIG ?= $(top)/.config
 24  KCONFIG_CONFIG = $(DOTCONFIG)
 25  KCONFIG_AUTOADS := $(obj)/cb-config.ads
 26  KCONFIG_RUSTCCFG := $(obj)/cb-config.rustcfg
 27  KCONFIG_AUTOHEADER := $(obj)/config.h
 28  KCONFIG_AUTOCONFIG := $(obj)/auto.conf
 29  KCONFIG_DEPENDENCIES := $(obj)/auto.conf.cmd
 30  KCONFIG_SPLITCONFIG := $(obj)/config/
 31  KCONFIG_TRISTATE := $(obj)/tristate.conf
 32  KCONFIG_NEGATIVES := 1
 33  KCONFIG_WERROR := 1
 34  KCONFIG_WARN_UNKNOWN_SYMBOLS := 1
 35  KCONFIG_PACKAGE := CB.Config
 36  KCONFIG_MAKEFILE_REAL ?= $(objk)/Makefile.real
 37  
 38  COREBOOT_EXPORTS += KCONFIG_CONFIG KCONFIG_AUTOHEADER KCONFIG_AUTOCONFIG
 39  COREBOOT_EXPORTS += KCONFIG_DEPENDENCIES KCONFIG_SPLITCONFIG KCONFIG_TRISTATE
 40  COREBOOT_EXPORTS += KCONFIG_NEGATIVES
 41  ifeq ($(filter %config,$(MAKECMDGOALS)),)
 42  COREBOOT_EXPORTS += KCONFIG_WERROR
 43  endif
 44  COREBOOT_EXPORTS += KCONFIG_WARN_UNKNOWN_SYMBOLS
 45  COREBOOT_EXPORTS += KCONFIG_AUTOADS KCONFIG_PACKAGE
 46  COREBOOT_EXPORTS += KCONFIG_RUSTCCFG
 47  
 48  # Make does not offer a recursive wildcard function, so here's one:
 49  rwildcard=$(wildcard $1$2) $(foreach d,$(wildcard $1*),$(call rwildcard,$d/,$2))
 50  SYMLINK_LIST = $(call rwildcard,site-local/,symlink.txt)
 51  
 52  
 53  # Directory containing the toplevel Makefile.mk
 54  TOPLEVEL := .
 55  
 56  CONFIG_SHELL := sh
 57  KBUILD_DEFCONFIG := configs/defconfig
 58  UNAME_RELEASE := $(shell uname -r)
 59  HAVE_DOTCONFIG := $(wildcard $(DOTCONFIG))
 60  HAVE_KCONFIG_MAKEFILE_REAL := $(wildcard $(KCONFIG_MAKEFILE_REAL))
 61  MAKEFLAGS += -rR --no-print-directory
 62  
 63  # Make is silent per default, but 'make V=1' will show all compiler calls.
 64  Q:=@
 65  ifneq ($(V),1)
 66  ifneq ($(Q),)
 67  .SILENT:
 68  MAKEFLAGS += -s
 69  quiet_errors := 2>/dev/null
 70  endif
 71  endif
 72  
 73  # Disable implicit/built-in rules to make Makefile errors fail fast.
 74  .SUFFIXES:
 75  
 76  HOSTCFLAGS := -g
 77  HOSTCXXFLAGS := -g
 78  
 79  HOSTPKG_CONFIG ?= pkg-config
 80  COREBOOT_EXPORTS += HOSTPKG_CONFIG
 81  
 82  PREPROCESS_ONLY := -E -P -x assembler-with-cpp -undef -I .
 83  
 84  export $(COREBOOT_EXPORTS)
 85  
 86  all: real-all
 87  
 88  help_coreboot help::
 89  	@echo  '*** coreboot platform targets ***'
 90  	@echo  '  Use "make [target] V=1" for extra build debug information'
 91  	@echo  '  all                     - Build coreboot'
 92  	@echo  '  clean                   - Remove coreboot build artifacts'
 93  	@echo  '  distclean               - Remove build artifacts and config files'
 94  	@echo  '  sphinx                  - Build sphinx documentation for coreboot'
 95  	@echo  '  sphinx-lint             - Build sphinx documentation for coreboot with warnings as errors'
 96  	@echo  '  filelist                - Show files used in current build'
 97  	@echo  '  printall                - Print makefile info for debugging'
 98  	@echo  '  gitconfig               - Set up git to submit patches to coreboot'
 99  	@echo  '  ctags / ctags-project   - Make ctags file for all of coreboot or current board'
100  	@echo  '  cscope / cscope-project - Make cscope.out file for coreboot or current board'
101  	@echo
102  	@echo  '*** site-local related targets ***'
103  	@echo  '  symlink                 - Create symbolic links from site-local into coreboot tree'
104  	@echo  '  clean-symlink           - Remove symbolic links created by "make symlink"'
105  	@echo  '  cleanall-symlink        - Remove all symbolic links in the coreboot tree'
106  	@echo
107  
108  # This include must come _before_ the pattern rules below!
109  # Order _does_ matter for pattern rules.
110  include $(srck)/Makefile.mk
111  
112  # The cases where we don't need fully populated $(obj) lists:
113  # 1. when no .config exists
114  # 2. When no $(obj)/util/kconfig/Makefile.real exists and we're building tools
115  # 3. when make config (in any flavour) is run
116  # 4. when make distclean is run
117  # Don't waste time on reading all Makefile.incs in these cases
118  ifeq ($(strip $(HAVE_DOTCONFIG)),)
119  NOCOMPILE:=1
120  endif
121  ifeq ($(strip $(HAVE_KCONFIG_MAKEFILE_REAL)),)
122  ifneq ($(MAKECMDGOALS),tools)
123  NOCOMPILE:=1
124  endif
125  endif
126  ifneq ($(MAKECMDGOALS),)
127  ifneq ($(filter %config %clean cross% clang iasl lint% help% what-jenkins-does,$(MAKECMDGOALS)),)
128  NOCOMPILE:=1
129  endif
130  ifneq ($(filter %clean lint% help% what-jenkins-does,$(MAKECMDGOALS)),)
131  NOMKDIR:=1
132  UNIT_TEST:=1
133  endif
134  endif
135  
136  ifneq ($(filter help%, $(MAKECMDGOALS)), )
137  NOCOMPILE:=1
138  UNIT_TEST:=1
139  else
140  ifneq ($(filter %-test %-tests %coverage-report, $(MAKECMDGOALS)),)
141  ifneq ($(filter-out %-test %-tests %coverage-report, $(MAKECMDGOALS)),)
142  $(error Cannot mix unit-tests targets with other targets)
143  endif
144  UNIT_TEST:=1
145  NOCOMPILE:=
146  endif
147  endif
148  
149  # When building the "tools" target, the BUILD_ALL_TOOLS variable needs
150  # to be set before reading the tools' Makefiles
151  ifneq ($(filter tools, $(MAKECMDGOALS)), )
152  BUILD_ALL_TOOLS:=1
153  endif
154  
155  $(xcompile): util/xcompile/xcompile
156  	rm -f $@
157  	$< $(XGCCPATH) > $@.tmp
158  	\mv -f $@.tmp $@ 2> /dev/null
159  	rm -f $@.tmp
160  
161  ifeq ($(NOCOMPILE),1)
162  # We also don't use .xcompile in the no-compile situations, so
163  # provide some reasonable defaults.
164  HOSTCC ?= $(if $(shell type gcc 2>/dev/null),gcc,cc)
165  HOSTCXX ?= g++
166  
167  include $(TOPLEVEL)/Makefile.mk
168  include $(TOPLEVEL)/payloads/Makefile.mk
169  include $(TOPLEVEL)/util/testing/Makefile.mk
170  -include $(TOPLEVEL)/site-local/Makefile.mk
171  -include $(TOPLEVEL)/site-local/Makefile.inc
172  include $(TOPLEVEL)/tests/Makefile.mk
173  printall real-all:
174  	@echo "Error: Trying to build, but NOCOMPILE is set." >&2
175  	@echo "  Please file a bug with the following information:"
176  	@echo "- MAKECMDGOALS: $(MAKECMDGOALS)" >&2
177  	@echo "- HAVE_DOTCONFIG: $(HAVE_DOTCONFIG)" >&2
178  	@echo "- HAVE_KCONFIG_MAKEFILE_REAL: $(HAVE_KCONFIG_MAKEFILE_REAL)" >&2
179  	@exit 1
180  
181  else
182  
183  ifneq ($(UNIT_TEST),1)
184  include $(DOTCONFIG)
185  endif
186  
187  # The toolchain requires xcompile to determine the ARCH_SUPPORTED, so we can't
188  # wait for make to generate the file.
189  $(if $(wildcard $(xcompile)),, $(shell \
190  	mkdir -p $(dir $(xcompile)) && \
191  	util/xcompile/xcompile $(XGCCPATH) > $(xcompile) || rm -f $(xcompile)))
192  
193  include $(xcompile)
194  
195  ifneq ($(XCOMPILE_COMPLETE),1)
196  $(shell rm -f $(xcompile))
197  $(error $(xcompile) deleted because it's invalid. \
198  	Restarting the build should fix that, or explain the problem)
199  endif
200  
201  # reproducible builds
202  LANG:=C
203  LC_ALL:=C
204  TZ:=UTC0
205  ifneq ($(NOCOMPILE),1)
206  SOURCE_DATE_EPOCH := $(shell $(top)/util/genbuild_h/genbuild_h.sh . | sed -n 's/^.define COREBOOT_BUILD_EPOCH\>.*"\(.*\)".*/\1/p')
207  endif
208  # don't use COREBOOT_EXPORTS to ensure build steps outside the coreboot build system
209  # are reproducible
210  export LANG LC_ALL TZ SOURCE_DATE_EPOCH
211  
212  ifneq ($(UNIT_TEST),1)
213  include toolchain.mk
214  endif
215  
216  strip_quotes = $(strip $(subst ",,$(subst \",,$(1))))
217  # fix makefile syntax highlighting after strip macro \" "))
218  
219  ifneq ($(NOCOMPILE),1)
220  $(shell rm -f $(CCACHE_STATSLOG))
221  endif
222  
223  # The primary target needs to be here before we include the
224  # other files
225  real-all: site-local-target real-target
226  
227  # must come rather early
228  .SECONDARY:
229  .SECONDEXPANSION:
230  .DELETE_ON_ERROR:
231  
232  # conf is treated as an intermediate target and may be built after config.h
233  # during a clean build due to the way GNU Make handles intermediates when the
234  # .SECONDARY target is present, forcing config.h and thus every object out of
235  # date on a subsequent no-op build. Mark it as not intermediate to prevent this
236  .NOTINTERMEDIATE: $(objutil)/kconfig/conf
237  
238  $(KCONFIG_AUTOHEADER): $(KCONFIG_CONFIG) $(objutil)/kconfig/conf
239  	$(MAKE) olddefconfig
240  	$(MAKE) syncconfig
241  
242  $(KCONFIG_AUTOCONFIG): $(KCONFIG_AUTOHEADER)
243  	true
244  
245  $(KCONFIG_AUTOADS): $(KCONFIG_CONFIG) $(KCONFIG_AUTOHEADER) $(objutil)/kconfig/toada
246  	$(objutil)/kconfig/toada CB.Config <$< >$@
247  
248  $(obj)/%/$(notdir $(KCONFIG_AUTOADS)): $(KCONFIG_AUTOADS)
249  	cp $< $@
250  
251  # Add a new class of source/object files to the build system
252  add-class= \
253  	$(eval $(1)-srcs:=) \
254  	$(eval $(1)-objs:=) \
255  	$(eval classes+=$(1))
256  
257  # Special classes are managed types with special behaviour
258  # On parse time, for each entry in variable $(1)-y
259  # a handler $(1)-handler is executed with the arguments:
260  # * $(1): directory the parser is in
261  # * $(2): current entry
262  add-special-class= \
263  	$(eval $(1):=) \
264  	$(eval special-classes+=$(1))
265  
266  # Converts one or more source file paths to their corresponding build/ paths.
267  # Only .ads, adb, .c and .S get converted to .o, other files (like .ld) keep
268  # their name.
269  # $1 stage name
270  # $2 file path (list)
271  src-to-obj=\
272  	$(patsubst $(obj)/%,$(obj)/$(1)/%,\
273  	$(patsubst $(obj)/$(1)/%,$(obj)/%,\
274  	$(patsubst 3rdparty/%,$(obj)/%,\
275  	$(patsubst src/%,$(obj)/%,\
276  	$(patsubst %.ads,%.o,\
277  	$(patsubst %.adb,%.o,\
278  	$(patsubst %.c,%.o,\
279  	$(patsubst %.S,%.o,\
280  	$(subst .$(1),,$(2))))))))))
281  
282  # Converts one or more source file paths to the corresponding build/ paths
283  # of their Ada library information (.ali) files.
284  # $1 stage name
285  # $2 file path (list)
286  src-to-ali=\
287  	$(patsubst $(obj)/%,$(obj)/$(1)/%,\
288  	$(patsubst $(obj)/$(1)/%,$(obj)/%,\
289  	$(patsubst 3rdparty/%,$(obj)/%,\
290  	$(patsubst src/%,$(obj)/%,\
291  	$(patsubst %.ads,%.ali,\
292  	$(patsubst %.adb,%.ali,\
293  	$(subst .$(1),,\
294  	$(filter %.ads %.adb,$(2)))))))))
295  
296  # Clean -y variables, include Makefile.mk & Makefile.inc
297  # Add paths to files in X-y to X-srcs
298  # Add subdirs-y to subdirs
299  includemakefiles= \
300  	$(if $(wildcard $(1)), \
301  		$(foreach class,classes subdirs $(classes) $(special-classes), $(eval $(class)-y:=)) \
302  		$(eval -include $(1)) \
303  		$(foreach class,$(classes-y), $(call add-class,$(class))) \
304  		$(foreach special,$(special-classes), \
305  			$(foreach item,$($(special)-y), $(call $(special)-handler,$(dir $(1)),$(item)))) \
306  		$(foreach class,$(classes), \
307  			$(eval $(class)-srcs+= \
308  				$$(subst $(absobj)/,$(obj)/, \
309  				$$(subst $(top)/,, \
310  				$$(abspath $$(subst $(dir $(1))/,/,$$(addprefix $(dir $(1)),$$($(class)-y)))))))) \
311  		$(eval subdirs+=$$(subst $(CURDIR)/,,$$(wildcard $$(abspath $$(addprefix $(dir $(1)),$$(subdirs-y)))))))
312  
313  # For each path in $(subdirs) call includemakefiles
314  # Repeat until subdirs is empty
315  # TODO: Remove Makefile.inc support
316  evaluate_subdirs= \
317  	$(eval cursubdirs:=$(subdirs)) \
318  	$(eval subdirs:=) \
319  	$(foreach dir,$(cursubdirs), \
320  		$(eval $(call includemakefiles,$(dir)/Makefile.mk))) \
321  	$(foreach dir,$(cursubdirs), \
322  		$(eval $(call includemakefiles,$(dir)/Makefile.inc))) \
323  	$(if $(subdirs),$(eval $(call evaluate_subdirs)))
324  
325  # collect all object files eligible for building
326  subdirs:=$(TOPLEVEL)
327  postinclude-hooks :=
328  
329  # Don't iterate through Makefiles under src/ when building tests
330  ifneq ($(UNIT_TEST),1)
331  $(eval $(call evaluate_subdirs))
332  else
333  include $(TOPLEVEL)/tests/Makefile.mk
334  endif
335  
336  ifeq ($(FAILBUILD),1)
337  $(error cannot continue build)
338  endif
339  
340  # Run hooks registered by subdirectories that need to be evaluated after all files have been parsed
341  $(eval $(postinclude-hooks))
342  
343  # Eliminate duplicate mentions of source files in a class
344  $(foreach class,$(classes),$(eval $(class)-srcs:=$(sort $($(class)-srcs))))
345  
346  ifeq ($(CONFIG_IWYU),y)
347  MAKEFLAGS += -k
348  SAVE_IWYU_OUTPUT := 2>&1 | grep "should\|\#include\|---\|include-list\|^[[:blank:]]\?\'" | tee -a $$(obj)/iwyu.txt
349  endif
350  
351  # Build Kconfig .ads if necessary
352  ifeq ($(CONFIG_ROMSTAGE_ADA),y)
353  romstage-srcs += $(obj)/romstage/$(notdir $(KCONFIG_AUTOADS))
354  endif
355  ifeq ($(CONFIG_RAMSTAGE_ADA),y)
356  ramstage-srcs += $(obj)/ramstage/$(notdir $(KCONFIG_AUTOADS))
357  endif
358  
359  # To track dependencies, we need all Ada specification (.ads) files in
360  # *-srcs. Extract / filter all specification files that have a matching
361  # body (.adb) file here (specifications without a body are valid sources
362  # in Ada).
363  $(foreach class,$(classes),$(eval $(class)-extra-specs := \
364  	$(filter \
365  		$(addprefix %/,$(patsubst %.adb,%.ads,$(notdir $(filter %.adb,$($(class)-srcs))))), \
366  		$(filter %.ads,$($(class)-srcs)))))
367  $(foreach class,$(classes),$(eval $(class)-srcs := \
368  	$(filter-out $($(class)-extra-specs),$($(class)-srcs))))
369  
370  $(foreach class,$(classes),$(eval $(class)-objs:=$(call src-to-obj,$(class),$($(class)-srcs))))
371  $(foreach class,$(classes),$(eval $(class)-alis:=$(call src-to-ali,$(class),$($(class)-srcs))))
372  
373  # For Ada includes
374  $(foreach class,$(classes),$(eval $(class)-ada-dirs:=$(sort $(dir $(filter %.ads %.adb,$($(class)-srcs)) $($(class)-extra-specs)))))
375  
376  # Call post-processors if they're defined
377  $(foreach class,$(classes),\
378  	$(if $(value $(class)-postprocess),$(eval $(call $(class)-postprocess,$($(class)-objs)))))
379  
380  allsrcs:=$(foreach var, $(addsuffix -srcs,$(classes)), $($(var)))
381  allobjs:=$(foreach var, $(addsuffix -objs,$(classes)), $($(var)))
382  alldirs:=$(sort $(abspath $(dir $(allobjs))))
383  
384  # Reads dependencies from an Ada library information (.ali) file
385  # Only basenames (with suffix) are preserved so we have to look the
386  # paths up in $($(stage)-srcs).
387  # $1 stage name
388  # $2 ali file
389  create_ada_deps=$$(if $(2),\
390  	gnat.adc \
391  	$$(filter \
392  		$$(addprefix %/,$$(shell sed -ne's/^D \([^\t]\+\).*$$$$/\1/p' $(2) 2>/dev/null)), \
393  		$$($(1)-srcs) $$($(1)-extra-specs)))
394  
395  # macro to define template macros that are used by use_template macro
396  define create_cc_template
397  # $1 obj class
398  # $2 source suffix (c, S, ld, ...)
399  # $3 additional compiler flags
400  # $4 additional dependencies
401  # $5 generated header dependencies
402  ifn$(EMPTY)def $(1)-objs_$(2)_template
403  de$(EMPTY)fine $(1)-objs_$(2)_template
404  ifn$(EMPTY)eq ($(filter ads adb,$(2)),)
405  $$(call src-to-obj,$1,$$(1).$2): $$(1).$2 $$(call create_ada_deps,$1,$$(call src-to-ali,$1,$$(1).$2)) $(4) | $(5)
406  	@printf "    GCC        $$$$(subst $$$$(obj)/,,$$$$(@))\n"
407  	$(GCC_$(1)) \
408  		$$$$(ADAFLAGS_$(1)) $$$$(addprefix -I,$$$$($(1)-ada-dirs)) \
409  		$(3) -c -o $$$$@ $$$$<
410  el$(EMPTY)se
411  $$(call src-to-obj,$1,$$(1).$2): $$(1).$2 $(KCONFIG_AUTOHEADER) $(4) | $(5)
412  	@printf "    CC         $$$$(subst $$$$(obj)/,,$$$$(@))\n"
413  	$(CC_$(1)) \
414  		-MMD $$$$(CPPFLAGS_$(1)) $$$$(CFLAGS_$(1)) -MT $$$$(@) \
415  		$(3) -c -o $$$$@ $$$$< $(SAVE_IWYU_OUTPUT)
416  end$(EMPTY)if
417  en$(EMPTY)def
418  end$(EMPTY)if
419  endef
420  
421  filetypes-of-class=$(subst .,,$(sort $(suffix $($(1)-srcs))))
422  $(foreach class,$(classes), \
423  	$(foreach type,$(call filetypes-of-class,$(class)), \
424  		$(eval $(class)-$(type)-ccopts += $(generic-$(type)-ccopts) $($(class)-generic-ccopts)) \
425  		$(if $(generic-objs_$(type)_template_gen),$(eval $(call generic-objs_$(type)_template_gen,$(class))),\
426  		$(eval $(call create_cc_template,$(class),$(type),$($(class)-$(type)-ccopts),$($(class)-$(type)-deps),$($(class)-$(type)-gen-deps))))))
427  
428  foreach-src=$(foreach file,$($(1)-srcs),$(eval $(call $(1)-objs_$(subst .,,$(suffix $(file)))_template,$(basename $(file)))))
429  $(eval $(foreach class,$(classes),$(call foreach-src,$(class))))
430  
431  # To supported complex package initializations, we need to call the
432  # emitted code explicitly. gnatbind gathers all the calls for us
433  # and exports them as a procedure $(stage)_adainit(). Every stage that
434  # uses Ada code has to call it!
435  define gnatbind_template
436  # $1 class
437  $$(obj)/$(1)/b__$(1).adb: $$$$(filter-out $$(obj)/$(1)/b__$(1).ali,$$$$($(1)-alis))
438  	@printf "    BIND       $$(subst $$(obj)/,,$$@)\n"
439  	# We have to give gnatbind a simple filename (without leading
440  	# path components) so just cd there.
441  	cd $$(dir $$@) && \
442  		$$(GNATBIND_$(1)) -a -n \
443  			--RTS=$$(absobj)/libgnat-$$(ARCH-$(1)-y)/ \
444  			-L$(1)_ada -o $$(notdir $$@) \
445  			$$(subst $$(dir $$@),,$$^)
446  $$(obj)/$(1)/b__$(1).o: $$(obj)/$(1)/b__$(1).adb
447  	@printf "    GCC        $$(subst $$(obj)/,,$$@)\n"
448  	$(GCC_$(1)) $$(ADAFLAGS_$(1)) -c -o $$@ $$<
449  $(1)-objs += $$(obj)/$(1)/b__$(1).o
450  $($(1)-alis): %.ali: %.o ;
451  endef
452  
453  $(eval $(foreach class,$(filter-out libgnat-%,$(classes)), \
454  	$(if $($(class)-alis),$(call gnatbind_template,$(class)))))
455  
456  DEPENDENCIES += $(addsuffix .d,$(basename $(allobjs)))
457  -include $(DEPENDENCIES)
458  
459  printall:
460  	@$(foreach class,$(classes), echo $(class)-objs: $($(class)-objs) | tr ' ' '\n'; echo; )
461  	@echo alldirs: $(alldirs) | tr ' ' '\n'; echo
462  	@echo allsrcs: $(allsrcs) | tr ' ' '\n'; echo
463  	@echo DEPENDENCIES: $(DEPENDENCIES) | tr ' ' '\n'; echo
464  	@$(foreach class,$(special-classes),echo $(class):'$($(class))' | tr ' ' '\n'; echo; )
465  endif
466  
467  ifndef NOMKDIR
468  $(shell mkdir -p $(KCONFIG_SPLITCONFIG) $(objk)/lxdialog $(additional-dirs) $(alldirs))
469  endif
470  
471  $(obj)/project_filelist.txt:
472  	if [ -z "$(wildcard $(obj)/coreboot.rom)" ]; then \
473  		echo "*** Error: Project must be built before generating file list ***"; \
474  		exit 1; \
475  	fi
476  	find $(obj) -path "$(obj)/util" -prune -o -path "$(obj)/external" -prune -o -name "*.d" -exec cat {} \; | \
477  	  sed "s|$(top)/||" | sed 's/[:\\]/ /g' | sed 's/ /\n/g' | sort | uniq | \
478  	  grep -v '\.o$$' > $(obj)/project_filelist.txt
479  
480  filelist: $(obj)/project_filelist.txt
481  	printf "\nFiles used in build:\n"
482  	cat $(obj)/project_filelist.txt
483  
484  #works with either exuberant ctags or ctags.emacs
485  ctags-project: clean-ctags $(obj)/project_filelist.txt
486  	cat $(obj)/project_filelist.txt | \
487  	  xargs ctags -o tags
488  
489  cscope-project: clean-cscope $(obj)/project_filelist.txt
490  	cat $(obj)/project_filelist.txt | xargs cscope -b
491  
492  cscope:
493  	cscope -bR
494  
495  sphinx:
496  	$(MAKE) -C Documentation sphinx
497  
498  sphinx-lint:
499  	$(MAKE) SPHINXOPTS=-W -C Documentation sphinx
500  
501  # Look at all of the files in the SYMLINK_LIST and create the symbolic links
502  # into the coreboot tree. Each symlink.txt file in site-local should be in the
503  # directory linked from and have a single line with the path to the location to
504  # link to. The path must be relative to the top of the coreboot directory.
505  symlink:
506  	if [ -z "$(SYMLINK_LIST)" ]; then \
507  		echo "No site-local symbolic links to create."; \
508  		exit 0; \
509  	fi; \
510  	echo "Creating symbolic links.."; \
511  	for link in $(SYMLINK_LIST); do \
512  		LINKTO="$(top)/$$(head -n 1 "$${link}")"; \
513  		LINKFROM=$$(dirname "$$(realpath "$${link}")"); \
514  		if [ -L "$${LINKTO}" ]; then \
515  			echo "  $${LINKTO} exists - skipping"; \
516  			continue; \
517  		fi; \
518  		LINKTO="$$(realpath -m "$${LINKTO}")" 2>/dev/null; \
519  		if [ "$${LINKTO}" = "$$(echo "$${LINKTO}" | sed "s|^$(top)||" )" ]; then \
520  			echo "  FAILED: $${LINKTO} is outside of current directory." >&2; \
521  			continue; \
522  		fi; \
523  		if [ ! -e "$${LINKTO}" ]; then \
524  			echo "  LINK $${LINKTO} -> $${LINKFROM}"; \
525  			ln -s "$${LINKFROM}" "$${LINKTO}" || \
526  				echo "FAILED: Could not create link." >&2; \
527  		else \
528  			echo  "  FAILED: $${LINKTO} exists as a file or directory." >&2; \
529  		fi; \
530  	done
531  
532  clean-symlink:
533  	if [ -z "$(SYMLINK_LIST)" ]; then \
534  		echo "No site-local symbolic links to clean."; \
535  		exit 0; \
536  	fi; \
537  	echo "Removing site-local symbolic links from tree.."; \
538  	for link in $(SYMLINK_LIST); do \
539  		SYMLINK="$(top)/$$(head -n 1 "$${link}")"; \
540  		if [ "$${SYMLINK}" = "$$(echo "$${SYMLINK}" | sed "s|^$(top)||")" ]; then \
541  			echo "  FAILED: $${SYMLINK} is outside of current directory." >&2; \
542  			continue; \
543  		elif [ ! -L "$${SYMLINK}" ]; then \
544  			echo "  $${SYMLINK} does not exist - skipping"; \
545  			continue; \
546  		fi; \
547  		if [ -L "$${SYMLINK}" ]; then \
548  			REALDIR="$$(realpath "$${link}")"; \
549  			echo "  UNLINK $${link} (linked from $${REALDIR})"; \
550  			rm "$${SYMLINK}"; \
551  		fi; \
552  	done; \
553  	EXISTING_SYMLINKS="$$(find $(top) -type l | grep -v "3rdparty\|crossgcc" )"; \
554  	if [ -z "$${EXISTING_SYMLINKS}" ]; then \
555  		echo "  No remaining symbolic links found in tree."; \
556  	else \
557  		echo "  Remaining symbolic links found:"; \
558  		for link in $${EXISTING_SYMLINKS}; do \
559  			echo "    $${link}"; \
560  		done; \
561  	fi
562  
563  cleanall-symlink:
564  	echo "Deleting all symbolic links in the coreboot tree (excluding 3rdparty & crossgcc)"; \
565  	EXISTING_SYMLINKS="$$(find $(top) -type l | grep -v "3rdparty\|crossgcc" )"; \
566  	for link in $${EXISTING_SYMLINKS}; do \
567  		if [ -L "$${link}" ]; then \
568  			REALDIR="$$(realpath "$${link}")"; \
569  			echo "  UNLINK $${link} (linked from $${REALDIR})"; \
570  			rm "$${link}"; \
571  		fi; \
572  	done
573  
574  clean-for-update:
575  	rm -rf $(obj) .xcompile
576  
577  clean: clean-for-update clean-utils clean-payloads
578  	rm -f .ccwrap
579  
580  clean-cscope:
581  	rm -f cscope.out
582  
583  clean-ctags:
584  	rm -f tags
585  
586  clean-utils:
587  	$(foreach tool, $(TOOLLIST), \
588  		$(MAKE) -C util/$(tool) clean MFLAGS= MAKEFLAGS= ;)
589  
590  distclean-utils:
591  	$(foreach tool, $(TOOLLIST), \
592  		$(MAKE) -C util/$(tool) distclean MFLAGS= MAKEFLAGS= ; \
593  		rm -f /util/$(tool)/junit.xml;)
594  
595  distclean: clean clean-ctags clean-cscope distclean-payloads distclean-utils
596  	rm -f .config .config.old ..config.tmp* .kconfig.d .tmpconfig* .ccwrap .xcompile
597  	rm -rf coreboot-builds coreboot-builds-chromeos
598  	rm -f abuild*.xml junit.xml* util/lint/junit.xml
599  
600  .PHONY: $(PHONY) clean clean-for-update clean-cscope cscope distclean sphinx sphinx-lint
601  .PHONY: ctags-project cscope-project clean-ctags
602  .PHONY: symlink clean-symlink cleanall-symlink