ccflags-y += -I$(srctree)/security/selinux -I$(srctree)/security/selinux/include
# In out-of-tree builds (O=...) the generated flask.h/av_permissions.h live in
# $(objtree)/security/selinux, which is not covered by the -I paths above.
ccflags-y += -I$(objtree)/security/selinux
obj-y += selinuxp.o

ifdef CONFIG_IEE_SELINUX_P
# flask.h/av_permissions.h are generated files (scripts/selinux/genheaders),
# normally created when security/selinux is built.  With a parallel build this
# directory can be reached before security/selinux regenerates them (and
# "make clean" removes flask.h while leaving av_permissions.h behind, since
# only flask.h is listed in security/selinux targets), which breaks the build
# with "No rule to make target security/selinux/flask.h".  Generate them here
# as well so this directory is self-sufficient; the output is deterministic,
# so a concurrent regeneration by security/selinux is harmless.  In out-of-tree
# builds (O=...) the output directory may not exist yet, so create it first.
FLASK_HDR := $(objtree)/security/selinux/flask.h
AV_PERM_HDR := $(objtree)/security/selinux/av_permissions.h
GENHDRS_TOOL := $(objtree)/scripts/selinux/genheaders/genheaders

$(obj)/selinuxp.o: $(FLASK_HDR)
$(FLASK_HDR): $(GENHDRS_TOOL) $(srctree)/security/selinux/include/classmap.h
	$(Q)mkdir -p $(@D)
	$(Q)$(GENHDRS_TOOL) $(FLASK_HDR) $(AV_PERM_HDR)
endif
