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