# All Rights Reserved, Copyright (C) 2003, Hitachi Software Engineering Co., Ltd.
# Yuichi Nakamura: Fixed for FC4 
CC		= gcc
LEX		= lex
YACC		= yacc
CFLAGS		= -Wall -O2 -g -DDEBUG=1
LD		= -ll -lselinux
INCLUDE		= -I/usr/include/selinux
LDPATH		= -L/usr/lib
OBJS		= y.tab.o action.o hashtab.o file_label.o convert.o security_class.o common.o  initial_policy.o debug.o out_file_acl.o

prefix = /usr/local
INSTALL_PATH	= $(prefix)
#for developper's test purpose
TESTDIR	= ./test_data
CONFDIR = $(TESTDIR)/middle_policy
BASEPOLICYDIR = $(TESTDIR)/base_policy
MACRODIR = $(TESTDIR)/macros
OUTDIR = $(TESTDIR)/sepolicy


all: converter

converter: $(OBJS)
	$(CC) -o $@ $(OBJS) $(LD) $(LDPATH)

.c.o:
	$(CC) -c $(CFLAGS) $(INCLUDE) $<

y.tab.o: lex.yy.c y.tab.c
	$(CC) -c $(CFLAGS) y.tab.c

lex.yy.c: middle_lang.l 
	$(LEX) middle_lang.l

y.tab.c: middle_lang.y middle_lang.h lex.yy.c action.h initial_policy.h  security_class.h
	$(YACC) middle_lang.y

action.o: middle_lang.h action.h hashtab.h file_label.h global.h common.h debug.h

hashtab.o: hashtab.h

file_label.o: hashtab.h file_label.h global.h

convert.o: file_label.h action.h hashtab.h convert.h global.h debug.h out_file_acl.h initial_policy.h common.h security_class.h

out_file_acl.o: global.h debug.h hashtab.h action.h

initial_policy.o: initial_policy.h security_class.h  file_label.h common.h global.h

security_class.o: common.h security_class.h initial_policy.h

common.o: common.h

debug.o: debug.h

install: converter
	mkdir -p $(INSTALL_PATH)
	mkdir -p $(INSTALL_PATH)/bin
	cp converter $(INSTALL_PATH)/bin

clean:
	rm -f *.o converter lex.yy.c y.tab.c a.out policy.conf test.conf file_context

#for developper's test
devtest: converter
	cat $(CONFDIR)/global $(CONFDIR)/*.a >$(CONFDIR)/all;
	./converter -i $(CONFDIR)/all -o $(OUTDIR)/test.conf -f $(OUTDIR)/file_contexts -b $(BASEPOLICYDIR);
	m4 -Imacros -s $(MACRODIR)/*.te $(OUTDIR)/test.conf > $(OUTDIR)/policy.conf;
	checkpolicy -o $(OUTDIR)/policy.`cat /selinux/policyvers` $(OUTDIR)/policy.conf;
