xref: /linux/usr/include/Makefile (revision 0fc8f6200d2313278fbf4539bbab74677c685531)
1d6fc9fcbSMasahiro Yamada# SPDX-License-Identifier: GPL-2.0-only
2d6fc9fcbSMasahiro Yamada
3d6fc9fcbSMasahiro Yamada# Unlike the kernel space, exported headers are written in standard C.
4d6fc9fcbSMasahiro Yamada#  - Forbid C++ style comments
5d6fc9fcbSMasahiro Yamada#  - Use '__inline__', '__asm__' instead of 'inline', 'asm'
6d6fc9fcbSMasahiro Yamada#
7d6fc9fcbSMasahiro Yamada# -std=c90 (equivalent to -ansi) catches the violation of those.
8d6fc9fcbSMasahiro Yamada# We cannot go as far as adding -Wpedantic since it emits too many warnings.
9c4cb34aeSThomas WeißschuhUAPI_CFLAGS := -std=c90 -Werror=implicit-function-declaration
10b4ec38cbSThomas WeißschuhUAPI_ARCH := $(or $(HEADER_ARCH),$(SRCARCH))
11d6fc9fcbSMasahiro Yamada
12cf822413SThomas Weißschuhoverride c_flags = $(KBUILD_USERCFLAGS) $(UAPI_CFLAGS) -Wp,-MMD,$(depfile)
13*dcc99abeSThomas Weißschuhcxx_flags = $(filter-out -Wmissing-prototypes -Wstrict-prototypes -std=%, $(KBUILD_USERCFLAGS)) -std=c++98
14d6fc9fcbSMasahiro Yamada
15d6fc9fcbSMasahiro Yamada# The following are excluded for now because they fail to build.
16d6fc9fcbSMasahiro Yamada#
17d6fc9fcbSMasahiro Yamada# Do not add a new header to the blacklist without legitimate reason.
18d6fc9fcbSMasahiro Yamada# Please consider to fix the header first.
19d6fc9fcbSMasahiro Yamada#
20d6fc9fcbSMasahiro Yamada# Sorted alphabetically.
210186b126SMasahiro Yamadano-header-test += asm/ucontext.h
220186b126SMasahiro Yamadano-header-test += drm/vmwgfx_drm.h
230186b126SMasahiro Yamadano-header-test += linux/am437x-vpfe.h
240186b126SMasahiro Yamadano-header-test += linux/coda.h
25d1ad2721SGreg Kroah-Hartmanno-header-test += linux/cyclades.h
260186b126SMasahiro Yamadano-header-test += linux/errqueue.h
270186b126SMasahiro Yamadano-header-test += linux/hdlc/ioctl.h
280186b126SMasahiro Yamadano-header-test += linux/ivtv.h
290186b126SMasahiro Yamadano-header-test += linux/matroxfb.h
300186b126SMasahiro Yamadano-header-test += linux/omap3isp.h
310186b126SMasahiro Yamadano-header-test += linux/omapfb.h
320186b126SMasahiro Yamadano-header-test += linux/patchkey.h
330186b126SMasahiro Yamadano-header-test += linux/phonet.h
340186b126SMasahiro Yamadano-header-test += linux/sctp.h
350186b126SMasahiro Yamadano-header-test += linux/sysctl.h
360186b126SMasahiro Yamadano-header-test += linux/usb/audio.h
370186b126SMasahiro Yamadano-header-test += linux/v4l2-mediabus.h
380186b126SMasahiro Yamadano-header-test += linux/v4l2-subdev.h
390186b126SMasahiro Yamadano-header-test += linux/videodev2.h
400186b126SMasahiro Yamadano-header-test += linux/vm_sockets.h
410186b126SMasahiro Yamadano-header-test += sound/asequencer.h
420186b126SMasahiro Yamadano-header-test += sound/asoc.h
430186b126SMasahiro Yamadano-header-test += sound/asound.h
440186b126SMasahiro Yamadano-header-test += sound/compress_offload.h
450186b126SMasahiro Yamadano-header-test += sound/emu10k1.h
460186b126SMasahiro Yamadano-header-test += sound/sfnt_info.h
470186b126SMasahiro Yamadano-header-test += xen/evtchn.h
480186b126SMasahiro Yamadano-header-test += xen/gntdev.h
490186b126SMasahiro Yamadano-header-test += xen/privcmd.h
50d6fc9fcbSMasahiro Yamada
51d6fc9fcbSMasahiro Yamada# More headers are broken in some architectures
52d6fc9fcbSMasahiro Yamada
53b4ec38cbSThomas Weißschuhifneq ($(filter arc openrisc xtensa nios2, $(UAPI_ARCH)),)
5456045757SRandy Dunlapno-header-test += linux/bpf_perf_event.h
5556045757SRandy Dunlapendif
5656045757SRandy Dunlap
57b4ec38cbSThomas Weißschuhifeq ($(UAPI_ARCH),sparc)
580186b126SMasahiro Yamadano-header-test += asm/uctx.h
590186b126SMasahiro Yamadano-header-test += asm/fbio.h
60d6fc9fcbSMasahiro Yamadaendif
61d6fc9fcbSMasahiro Yamada
62d6fc9fcbSMasahiro Yamada# asm-generic/*.h is used by asm/*.h, and should not be included directly
630186b126SMasahiro Yamadano-header-test += asm-generic/%
64d6fc9fcbSMasahiro Yamada
65*dcc99abeSThomas Weißschuh# The following are not compatible with C++.
66*dcc99abeSThomas Weißschuh#
67*dcc99abeSThomas Weißschuh# Do not add a new header to the list without legitimate reason.
68*dcc99abeSThomas Weißschuh# Please consider to fix the header first.
69*dcc99abeSThomas Weißschuh#
70*dcc99abeSThomas Weißschuh# Sorted alphabetically.
71*dcc99abeSThomas Weißschuhno-header-test-cxx += linux/auto_dev-ioctl.h
72*dcc99abeSThomas Weißschuhno-header-test-cxx += linux/map_to_14segment.h
73*dcc99abeSThomas Weißschuhno-header-test-cxx += linux/map_to_7segment.h
74*dcc99abeSThomas Weißschuhno-header-test-cxx += linux/netfilter/xt_sctp.h
75*dcc99abeSThomas Weißschuhno-header-test-cxx += linux/target_core_user.h
76*dcc99abeSThomas Weißschuhno-header-test-cxx += linux/vhost.h
77*dcc99abeSThomas Weißschuhno-header-test-cxx += linux/vhost_types.h
78*dcc99abeSThomas Weißschuhno-header-test-cxx += linux/virtio_net.h
79*dcc99abeSThomas Weißschuhno-header-test-cxx += linux/virtio_ring.h
80*dcc99abeSThomas Weißschuhno-header-test-cxx += scsi/fc/fc_els.h
81*dcc99abeSThomas Weißschuh
82*dcc99abeSThomas Weißschuhifeq ($(UAPI_ARCH),x86)
83*dcc99abeSThomas Weißschuhno-header-test-cxx += asm/elf.h
84*dcc99abeSThomas Weißschuhendif
85*dcc99abeSThomas Weißschuh
866059b880SThomas Weißschuh# The following are using libc header and types.
876059b880SThomas Weißschuh#
886059b880SThomas Weißschuh# Do not add a new header to the list without legitimate reason.
896059b880SThomas Weißschuh# Please consider to fix the header first.
906059b880SThomas Weißschuh#
916059b880SThomas Weißschuh# Sorted alphabetically.
926059b880SThomas Weißschuhuses-libc += linux/a.out.h
936059b880SThomas Weißschuhuses-libc += linux/atmbr2684.h
946059b880SThomas Weißschuhuses-libc += linux/auto_dev-ioctl.h
956059b880SThomas Weißschuhuses-libc += linux/auto_fs.h
966059b880SThomas Weißschuhuses-libc += linux/auto_fs4.h
976059b880SThomas Weißschuhuses-libc += linux/btrfs_tree.h
986059b880SThomas Weißschuhuses-libc += linux/cec-funcs.h
996059b880SThomas Weißschuhuses-libc += linux/cec.h
1006059b880SThomas Weißschuhuses-libc += linux/dvb/dmx.h
1016059b880SThomas Weißschuhuses-libc += linux/dvb/video.h
1026059b880SThomas Weißschuhuses-libc += linux/ethtool.h
1036059b880SThomas Weißschuhuses-libc += linux/ethtool_netlink.h
1046059b880SThomas Weißschuhuses-libc += linux/fuse.h
1056059b880SThomas Weißschuhuses-libc += linux/gsmmux.h
1066059b880SThomas Weißschuhuses-libc += linux/icmp.h
1076059b880SThomas Weißschuhuses-libc += linux/idxd.h
1086059b880SThomas Weißschuhuses-libc += linux/if.h
1096059b880SThomas Weißschuhuses-libc += linux/if_arp.h
1106059b880SThomas Weißschuhuses-libc += linux/if_bonding.h
1116059b880SThomas Weißschuhuses-libc += linux/if_pppox.h
1126059b880SThomas Weißschuhuses-libc += linux/if_tunnel.h
1136059b880SThomas Weißschuhuses-libc += linux/input.h
1146059b880SThomas Weißschuhuses-libc += linux/ip6_tunnel.h
1156059b880SThomas Weißschuhuses-libc += linux/joystick.h
1166059b880SThomas Weißschuhuses-libc += linux/llc.h
1176059b880SThomas Weißschuhuses-libc += linux/mctp.h
1186059b880SThomas Weißschuhuses-libc += linux/mdio.h
1196059b880SThomas Weißschuhuses-libc += linux/mii.h
1206059b880SThomas Weißschuhuses-libc += linux/mptcp.h
1216059b880SThomas Weißschuhuses-libc += linux/netdevice.h
1226059b880SThomas Weißschuhuses-libc += linux/netfilter/xt_RATEEST.h
1236059b880SThomas Weißschuhuses-libc += linux/netfilter/xt_hashlimit.h
1246059b880SThomas Weißschuhuses-libc += linux/netfilter/xt_physdev.h
1256059b880SThomas Weißschuhuses-libc += linux/netfilter/xt_rateest.h
1266059b880SThomas Weißschuhuses-libc += linux/netfilter_arp/arp_tables.h
1276059b880SThomas Weißschuhuses-libc += linux/netfilter_arp/arpt_mangle.h
1286059b880SThomas Weißschuhuses-libc += linux/netfilter_bridge.h
1296059b880SThomas Weißschuhuses-libc += linux/netfilter_bridge/ebtables.h
1306059b880SThomas Weißschuhuses-libc += linux/netfilter_ipv4.h
1316059b880SThomas Weißschuhuses-libc += linux/netfilter_ipv4/ip_tables.h
1326059b880SThomas Weißschuhuses-libc += linux/netfilter_ipv6.h
1336059b880SThomas Weißschuhuses-libc += linux/netfilter_ipv6/ip6_tables.h
1346059b880SThomas Weißschuhuses-libc += linux/route.h
1356059b880SThomas Weißschuhuses-libc += linux/shm.h
1366059b880SThomas Weißschuhuses-libc += linux/soundcard.h
1376059b880SThomas Weißschuhuses-libc += linux/string.h
1386059b880SThomas Weißschuhuses-libc += linux/tipc_config.h
1396059b880SThomas Weißschuhuses-libc += linux/uhid.h
1406059b880SThomas Weißschuhuses-libc += linux/uinput.h
1416059b880SThomas Weißschuhuses-libc += linux/vhost.h
1426059b880SThomas Weißschuhuses-libc += linux/vhost_types.h
1436059b880SThomas Weißschuhuses-libc += linux/virtio_ring.h
1446059b880SThomas Weißschuhuses-libc += linux/wireless.h
1456059b880SThomas Weißschuhuses-libc += regulator/regulator.h
1466059b880SThomas Weißschuhuses-libc += scsi/fc/fc_els.h
1476059b880SThomas Weißschuh
148b4ec38cbSThomas Weißschuhifeq ($(UAPI_ARCH),hexagon)
1496059b880SThomas Weißschuhuses-libc += asm/sigcontext.h
1506059b880SThomas Weißschuhendif
1516059b880SThomas Weißschuh
152b4ec38cbSThomas Weißschuhifeq ($(UAPI_ARCH),nios2)
1536059b880SThomas Weißschuhuses-libc += asm/ptrace.h
1546059b880SThomas Weißschuhendif
1556059b880SThomas Weißschuh
156b4ec38cbSThomas Weißschuhifeq ($(UAPI_ARCH),s390)
1576059b880SThomas Weißschuhuses-libc += asm/chpid.h
1586059b880SThomas Weißschuhuses-libc += asm/chsc.h
1596059b880SThomas Weißschuhendif
1606059b880SThomas Weißschuh
161c1ea04d8SMasahiro Yamadaalways-y := $(patsubst $(obj)/%.h,%.hdrtest, $(shell find $(obj) -name '*.h' 2>/dev/null))
162fcbb8461SMasahiro Yamada
163*dcc99abeSThomas Weißschuh# $(cc-option) forces '-x c' which breaks '-x c++' detection.
164*dcc99abeSThomas Weißschuhcc-can-compile-cxx := $(call try-run,$(CC) $(CLANG_FLAGS) -c -x c++ /dev/null -o "$$TMP", 1)
165*dcc99abeSThomas Weißschuh
166510c7a57SThomas Weißschuhtarget-libc = $(filter $(uses-libc), $*.h)
167579f103fSThomas Weißschuhtarget-can-compile = $(filter-out $(no-header-test), $*.h)
168*dcc99abeSThomas Weißschuhtarget-can-compile-cxx = $(and $(cc-can-compile-cxx), $(target-can-compile), $(filter-out $(no-header-test-cxx), $*.h))
1694ac85d9bSThomas Weißschuh
17055d68ec5SThomas Weißschuhhdrtest-flags = -fsyntax-only -Werror \
171cf822413SThomas Weißschuh		-nostdinc -I $(obj) $(if $(target-libc), -I $(srctree)/usr/dummy-include)
17255d68ec5SThomas Weißschuh
17300d76a0cSMasahiro Yamada# Include the header twice to detect missing include guard.
174fcbb8461SMasahiro Yamadaquiet_cmd_hdrtest = HDRTEST $<
1757ecaf069SMasahiro Yamada      cmd_hdrtest = \
17655d68ec5SThomas Weißschuh		$(CC) $(c_flags) $(hdrtest-flags) -x c /dev/null \
1774ac85d9bSThomas Weißschuh			$(if $(target-can-compile), -include $< -include $<); \
178*dcc99abeSThomas Weißschuh		$(if $(target-can-compile-cxx), \
179*dcc99abeSThomas Weißschuh			$(CC) $(cxx_flags) $(hdrtest-flags) -x c++ /dev/null -include $<;) \
180d67393f4SGeert Uytterhoeven		$(PERL) $(src)/headers_check.pl $(obj) $<; \
1817ecaf069SMasahiro Yamada		touch $@
182fcbb8461SMasahiro Yamada
183d4b7080bSThomas Weißschuh$(obj)/%.hdrtest: $(obj)/%.h $(src)/headers_check.pl FORCE
184fcbb8461SMasahiro Yamada	$(call if_changed_dep,hdrtest)
185d6fc9fcbSMasahiro Yamada
18650a48340SMasahiro Yamada# Since GNU Make 4.3, $(patsubst $(obj)/%/,%,$(wildcard $(obj)/*/)) works.
18750a48340SMasahiro Yamada# To support older Make versions, use a somewhat tedious way.
18850a48340SMasahiro Yamadaclean-files += $(filter-out Makefile headers_check.pl, $(notdir $(wildcard $(obj)/*)))
189