1ENV ?= env 2M4 ?= m4 3MKDIR ?= mkdir 4EXE ?= libsepol-tests 5 6CFLAGS += -g3 -gdwarf-2 -O0 -Wall -W -Wundef -Wmissing-noreturn -Wmissing-format-attribute -Wno-unused-parameter -Werror 7 8# Statically link libsepol on the assumption that we are going to 9# be testing internal functions. 10LIBSEPOL := ../src/libsepol.a 11 12# In order to load source policies we need to link in the checkpolicy/checkmodule parser and util code. 13# This is less than ideal, but it makes the tests easier to maintain by allowing source policies 14# to be loaded directly. 15CHECKPOLICY := ../../checkpolicy/ 16override CPPFLAGS += -I../include/ -I$(CHECKPOLICY) 17 18# test program object files 19objs := $(patsubst %.c,%.o,$(sort $(wildcard *.c))) 20parserobjs := $(CHECKPOLICY)queue.o $(CHECKPOLICY)y.tab.o \ 21 $(CHECKPOLICY)parse_util.o $(CHECKPOLICY)lex.yy.o \ 22 $(CHECKPOLICY)policy_define.o $(CHECKPOLICY)module_compiler.o 23 24# test policy pieces 25m4support := $(wildcard policies/support/*.spt) 26testsuites := $(wildcard policies/test-*) 27policysrc := $(foreach path,$(testsuites),$(wildcard $(path)/*.conf)) 28stdpol := $(addsuffix .std,$(policysrc)) 29mlspol := $(addsuffix .mls,$(policysrc)) 30policies := $(stdpol) $(mlspol) 31 32all: $(EXE) $(policies) 33policies: $(policies) 34 35$(EXE): $(objs) $(parserobjs) $(LIBSEPOL) 36 $(CC) $(LDFLAGS) $(objs) $(parserobjs) -lcunit $(LIBSEPOL) -o $@ 37 38%.conf.std: $(m4support) %.conf 39 $(M4) $(M4PARAMS) $^ > $@ 40 41%.conf.mls: $(m4support) %.conf 42 $(M4) $(M4PARAMS) -D enable_mls $^ > $@ 43 44clean: 45 rm -f $(objs) $(EXE) 46 rm -f $(policies) 47 rm -f policies/test-downgrade/policy.hi policies/test-downgrade/policy.lo 48 49# mkdir is run in a clean environment created by env -i to avoid failing under ASan with: 50# 51# ASan runtime does not come first in initial library list; 52# you should either link runtime to your application or manually preload it with LD_PRELOAD 53# 54# when the source code is built with ASan 55test: $(EXE) $(policies) 56 $(ENV) -i $(MKDIR) -p policies/test-downgrade 57 ../../checkpolicy/checkpolicy -M policies/test-cond/refpolicy-base.conf -o policies/test-downgrade/policy.hi 58 ./$(EXE) 59 60.PHONY: all policies clean test 61