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