^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) # SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) # Unlike the kernel space, exported headers are written in standard C.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) # - Forbid C++ style comments
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) # - Use '__inline__', '__asm__' instead of 'inline', 'asm'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) #
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) # -std=c90 (equivalent to -ansi) catches the violation of those.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) # We cannot go as far as adding -Wpedantic since it emits too many warnings.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) UAPI_CFLAGS := -std=c90 -Wall -Werror=implicit-function-declaration
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) # In theory, we do not care -m32 or -m64 for header compile tests.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) # It is here just because CONFIG_CC_CAN_LINK is tested with -m32 or -m64.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) UAPI_CFLAGS += $(filter -m32 -m64, $(KBUILD_CFLAGS))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) # USERCFLAGS might contain sysroot location for CC.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) UAPI_CFLAGS += $(USERCFLAGS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) override c_flags = $(UAPI_CFLAGS) -Wp,-MMD,$(depfile) -I$(objtree)/usr/include
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) # The following are excluded for now because they fail to build.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) # Do not add a new header to the blacklist without legitimate reason.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) # Please consider to fix the header first.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) # Sorted alphabetically.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) no-header-test += asm/shmbuf.h
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) no-header-test += asm/signal.h
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) no-header-test += asm/ucontext.h
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) no-header-test += drm/vmwgfx_drm.h
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) no-header-test += linux/am437x-vpfe.h
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) no-header-test += linux/android/binder.h
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) no-header-test += linux/android/binderfs.h
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) no-header-test += linux/coda.h
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) no-header-test += linux/errqueue.h
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) no-header-test += linux/fsmap.h
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) no-header-test += linux/hdlc/ioctl.h
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) no-header-test += linux/ivtv.h
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) no-header-test += linux/kexec.h
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) no-header-test += linux/matroxfb.h
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) no-header-test += linux/omap3isp.h
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) no-header-test += linux/omapfb.h
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) no-header-test += linux/patchkey.h
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) no-header-test += linux/phonet.h
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) no-header-test += linux/reiserfs_xattr.h
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) no-header-test += linux/sctp.h
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) no-header-test += linux/signal.h
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) no-header-test += linux/sysctl.h
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) no-header-test += linux/usb/audio.h
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) no-header-test += linux/v4l2-mediabus.h
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) no-header-test += linux/v4l2-subdev.h
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) no-header-test += linux/videodev2.h
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) no-header-test += linux/vm_sockets.h
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) no-header-test += sound/asequencer.h
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) no-header-test += sound/asoc.h
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) no-header-test += sound/asound.h
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) no-header-test += sound/compress_offload.h
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) no-header-test += sound/emu10k1.h
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) no-header-test += sound/sfnt_info.h
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) no-header-test += xen/evtchn.h
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) no-header-test += xen/gntdev.h
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) no-header-test += xen/privcmd.h
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) # More headers are broken in some architectures
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) ifeq ($(SRCARCH),arc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) no-header-test += linux/bpf_perf_event.h
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) ifeq ($(SRCARCH),ia64)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) no-header-test += asm/setup.h
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) no-header-test += asm/sigcontext.h
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) no-header-test += asm/perfmon.h
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) no-header-test += asm/perfmon_default_smpl.h
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) no-header-test += linux/if_bonding.h
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) ifeq ($(SRCARCH),mips)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) no-header-test += asm/stat.h
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) ifeq ($(SRCARCH),powerpc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) no-header-test += asm/stat.h
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) no-header-test += linux/bpf_perf_event.h
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) ifeq ($(SRCARCH),riscv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) no-header-test += linux/bpf_perf_event.h
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) ifeq ($(SRCARCH),sparc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) no-header-test += asm/stat.h
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) no-header-test += asm/uctx.h
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) no-header-test += asm/fbio.h
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) # asm-generic/*.h is used by asm/*.h, and should not be included directly
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) no-header-test += asm-generic/%
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) extra-y := $(patsubst $(obj)/%.h,%.hdrtest, $(shell find $(obj) -name '*.h' 2>/dev/null))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) # Include the header twice to detect missing include guard.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) quiet_cmd_hdrtest = HDRTEST $<
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) cmd_hdrtest = \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) $(CC) $(c_flags) -S -o /dev/null -x c /dev/null \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) $(if $(filter-out $(no-header-test), $*.h), -include $< -include $<); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) $(PERL) $(srctree)/scripts/headers_check.pl $(obj) $(SRCARCH) $<; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) touch $@
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) $(obj)/%.hdrtest: $(obj)/%.h FORCE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) $(call if_changed_dep,hdrtest)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) clean-files += $(filter-out Makefile, $(notdir $(wildcard $(obj)/*)))