#       $NetBSD: Makefile.ioctl-c,v 1.40 2024/04/01 18:33:24 riastradh Exp $

# NOTE: <bsd.own.mk> needs to be previously .included for NETBSDSRCDIR

# We are trying to get the list of .h files that define all ioctls
# This version grabs the non-obsolete .h files from the set lists
# and silently ignores any that don't exist in ${DESTDIR}.
# NB: The compiler uses the .h files in ${NETBSDSRCDIR}.

SETBASES=       ${NETBSDSRCDIR}/distrib/sets/lists/comp \
               ${NETBSDSRCDIR}/distrib/sets/lists/xcomp

for sb in ${SETBASES}
if exists(${sb}/mi)
SETFILES:=${SETFILES} ${sb}/mi
endif
for md in md.${MACHINE} /md.${MACHINE}.${MACHINE_ARCH}
if exists(${sb}/${md})
SETFILES:= ${SETFILES} ${sb}/${md}
endif
endfor
endfor
if ${MKDTRACE} != "no"
EXTRAS= ${NETBSDSRCDIR}/external/cddl/osnet/dist/uts/common/sys/dtrace.h
endif

if !make(cleandir) && !make(obj) && !make(includes) && !make(install)
DEPFILEGLOB = ${TOOL_SED} \
   -ne '/\/usr\/.*include\/.*\.h[      ]/{s/[  ,]obsolete//;t' \
   -e "s/xorg_server_ver=${XORG_SERVER_VER}//;t skipserver" \
   -e "s/xorg_server_ver=//;t" \
   -e ":skipserver" \
   -e 's/xenio//;t' \
   -e 's,\.\([^        ]*\).*,${DESTDIR}\1,;p;}' ${SETFILES}
DEPFILES != (${DEPFILEGLOB}; echo ${EXTRAS}) | xargs egrep -l '(_IO\(|_IOR\(|_IOW\(|_IOWR\()' 2>/dev/null || :
endif


SRCS+=          ${PROG}-ioctl.c
CLEANFILES+=    ${PROG}-ioctl.c
DPSRCS+=        ${PROG}-ioctl.c
CPPFLAGS+=      -I${DESTDIR}/usr/X11R7/include/libdrm
CPPFLAGS+=      -I${DESTDIR}/usr/X11R7/include/pixman-1
CPPFLAGS+=      -I${DESTDIR}/usr/X11R7/include
CPPFLAGS+=      -I${NETBSDSRCDIR}/sys/external/bsd/libnv/dist
if ${MKDTRACE} != "no"
CPPFLAGS+=      -I${NETBSDSRCDIR}/external/cddl/osnet/sys
CPPFLAGS+=      -I${NETBSDSRCDIR}/external/cddl/osnet/dist/uts/common
CWARNFLAGS+=    -Wno-unknown-pragmas
endif
CPPFLAGS+=      -D_DEV_IC_BT8XX_H_
CPPFLAGS+=      -D_ALTQ_ALTQ_JOBS_H_    # redefinition of inline
CPPFLAGS+=      -D_I915_DRM_H_          # Dup ioctls
# Once upon a time these only conflicted with themselves, but noe
# the i915 version conflicts with base ioctls, so that one is now
# always must be excluded.
# De-select one, dup ioctls
CPPFLAGS+=      -D_VIA_DRM_H_           # Missing header
CPPFLAGS+=      -DQXL_DRM_H             # Dup ioctls
CPPFLAGS+=      -D__R128_DRM_H__        # Dup ioctls
CPPFLAGS+=      -D__SIS_DRM_H__         # Dup ioctls
CPPFLAGS+=      -D__SAVAGE_DRM_H__      # Dup ioctls
#CPPFLAGS+=     -D__RADEON_DRM_H__      # Dup ioctls
CPPFLAGS+=      -D__MACH64_DRM_H__      # Dup ioctls
CPPFLAGS+=      -D__MGA_DRM_H__         # Dup ioctls
CPPFLAGS+=      -D_SYS_ELFDEFINITIONS_H_        # collides with sys/exec_elf.h

${PROG}-ioctl.c: mkioctls Makefile ${DEPFILES} ${SETFILES}
       ${_MKTARGET_CREATE}
       AWK=${TOOL_AWK:q} CC=${CC:q} DESTDIR=${DESTDIR:q} SED=${TOOL_SED:q} \
           NETBSDSRCDIR=${NETBSDSRCDIR:q} CPPFLAGS=${CPPFLAGS:q} \
           ${HOST_SH} ${NETBSDSRCDIR}/usr.bin/kdump/mkioctls \
           ${DEPFILES} >${.TARGET}

${DEPFILES}: .PRECIOUS