162306a36Sopenharmony_ci# SPDX-License-Identifier: GPL-2.0-only
262306a36Sopenharmony_ci
362306a36Sopenharmony_ci# Unlike the kernel space, exported headers are written in standard C.
462306a36Sopenharmony_ci#  - Forbid C++ style comments
562306a36Sopenharmony_ci#  - Use '__inline__', '__asm__' instead of 'inline', 'asm'
662306a36Sopenharmony_ci#
762306a36Sopenharmony_ci# -std=c90 (equivalent to -ansi) catches the violation of those.
862306a36Sopenharmony_ci# We cannot go as far as adding -Wpedantic since it emits too many warnings.
962306a36Sopenharmony_ciUAPI_CFLAGS := -std=c90 -Wall -Werror=implicit-function-declaration
1062306a36Sopenharmony_ci
1162306a36Sopenharmony_ci# In theory, we do not care -m32 or -m64 for header compile tests.
1262306a36Sopenharmony_ci# It is here just because CONFIG_CC_CAN_LINK is tested with -m32 or -m64.
1362306a36Sopenharmony_ciUAPI_CFLAGS += $(filter -m32 -m64 --target=%, $(KBUILD_CFLAGS))
1462306a36Sopenharmony_ci
1562306a36Sopenharmony_ci# USERCFLAGS might contain sysroot location for CC.
1662306a36Sopenharmony_ciUAPI_CFLAGS += $(USERCFLAGS)
1762306a36Sopenharmony_ci
1862306a36Sopenharmony_cioverride c_flags = $(UAPI_CFLAGS) -Wp,-MMD,$(depfile) -I $(obj) -I $(srctree)/usr/dummy-include
1962306a36Sopenharmony_ci
2062306a36Sopenharmony_ci# The following are excluded for now because they fail to build.
2162306a36Sopenharmony_ci#
2262306a36Sopenharmony_ci# Do not add a new header to the blacklist without legitimate reason.
2362306a36Sopenharmony_ci# Please consider to fix the header first.
2462306a36Sopenharmony_ci#
2562306a36Sopenharmony_ci# Sorted alphabetically.
2662306a36Sopenharmony_cino-header-test += asm/ucontext.h
2762306a36Sopenharmony_cino-header-test += drm/vmwgfx_drm.h
2862306a36Sopenharmony_cino-header-test += linux/am437x-vpfe.h
2962306a36Sopenharmony_cino-header-test += linux/coda.h
3062306a36Sopenharmony_cino-header-test += linux/cyclades.h
3162306a36Sopenharmony_cino-header-test += linux/errqueue.h
3262306a36Sopenharmony_cino-header-test += linux/hdlc/ioctl.h
3362306a36Sopenharmony_cino-header-test += linux/ivtv.h
3462306a36Sopenharmony_cino-header-test += linux/matroxfb.h
3562306a36Sopenharmony_cino-header-test += linux/omap3isp.h
3662306a36Sopenharmony_cino-header-test += linux/omapfb.h
3762306a36Sopenharmony_cino-header-test += linux/patchkey.h
3862306a36Sopenharmony_cino-header-test += linux/phonet.h
3962306a36Sopenharmony_cino-header-test += linux/sctp.h
4062306a36Sopenharmony_cino-header-test += linux/sysctl.h
4162306a36Sopenharmony_cino-header-test += linux/usb/audio.h
4262306a36Sopenharmony_cino-header-test += linux/v4l2-mediabus.h
4362306a36Sopenharmony_cino-header-test += linux/v4l2-subdev.h
4462306a36Sopenharmony_cino-header-test += linux/videodev2.h
4562306a36Sopenharmony_cino-header-test += linux/vm_sockets.h
4662306a36Sopenharmony_cino-header-test += sound/asequencer.h
4762306a36Sopenharmony_cino-header-test += sound/asoc.h
4862306a36Sopenharmony_cino-header-test += sound/asound.h
4962306a36Sopenharmony_cino-header-test += sound/compress_offload.h
5062306a36Sopenharmony_cino-header-test += sound/emu10k1.h
5162306a36Sopenharmony_cino-header-test += sound/sfnt_info.h
5262306a36Sopenharmony_cino-header-test += xen/evtchn.h
5362306a36Sopenharmony_cino-header-test += xen/gntdev.h
5462306a36Sopenharmony_cino-header-test += xen/privcmd.h
5562306a36Sopenharmony_ci
5662306a36Sopenharmony_ci# More headers are broken in some architectures
5762306a36Sopenharmony_ci
5862306a36Sopenharmony_ciifeq ($(SRCARCH),arc)
5962306a36Sopenharmony_cino-header-test += linux/bpf_perf_event.h
6062306a36Sopenharmony_ciendif
6162306a36Sopenharmony_ci
6262306a36Sopenharmony_ciifeq ($(SRCARCH),ia64)
6362306a36Sopenharmony_cino-header-test += asm/setup.h
6462306a36Sopenharmony_cino-header-test += asm/sigcontext.h
6562306a36Sopenharmony_cino-header-test += linux/if_bonding.h
6662306a36Sopenharmony_ciendif
6762306a36Sopenharmony_ci
6862306a36Sopenharmony_ciifeq ($(SRCARCH),powerpc)
6962306a36Sopenharmony_cino-header-test += linux/bpf_perf_event.h
7062306a36Sopenharmony_ciendif
7162306a36Sopenharmony_ci
7262306a36Sopenharmony_ciifeq ($(SRCARCH),sparc)
7362306a36Sopenharmony_cino-header-test += asm/uctx.h
7462306a36Sopenharmony_cino-header-test += asm/fbio.h
7562306a36Sopenharmony_ciendif
7662306a36Sopenharmony_ci
7762306a36Sopenharmony_ci# asm-generic/*.h is used by asm/*.h, and should not be included directly
7862306a36Sopenharmony_cino-header-test += asm-generic/%
7962306a36Sopenharmony_ci
8062306a36Sopenharmony_cialways-y := $(patsubst $(obj)/%.h,%.hdrtest, $(shell find $(obj) -name '*.h' 2>/dev/null))
8162306a36Sopenharmony_ci
8262306a36Sopenharmony_ci# Include the header twice to detect missing include guard.
8362306a36Sopenharmony_ciquiet_cmd_hdrtest = HDRTEST $<
8462306a36Sopenharmony_ci      cmd_hdrtest = \
8562306a36Sopenharmony_ci		$(CC) $(c_flags) -fsyntax-only -x c /dev/null \
8662306a36Sopenharmony_ci			$(if $(filter-out $(no-header-test), $*.h), -include $< -include $<); \
8762306a36Sopenharmony_ci		$(PERL) $(srctree)/$(src)/headers_check.pl $(obj) $(SRCARCH) $<; \
8862306a36Sopenharmony_ci		touch $@
8962306a36Sopenharmony_ci
9062306a36Sopenharmony_ci$(obj)/%.hdrtest: $(obj)/%.h FORCE
9162306a36Sopenharmony_ci	$(call if_changed_dep,hdrtest)
9262306a36Sopenharmony_ci
9362306a36Sopenharmony_ci# Since GNU Make 4.3, $(patsubst $(obj)/%/,%,$(wildcard $(obj)/*/)) works.
9462306a36Sopenharmony_ci# To support older Make versions, use a somewhat tedious way.
9562306a36Sopenharmony_ciclean-files += $(filter-out Makefile headers_check.pl, $(notdir $(wildcard $(obj)/*)))
96