# SE Tools Main makefile

MAKEFILE =  Makefile
MAKE = make

TCL_INCLUDE	= -I/usr/include
TCL_LIBINC	= -L/usr/lib 
TCL_LIBS	= -ltk8.3 -ltcl8.3 -lfl -lm 
LINKFLAGS	= 
CC		= gcc 
YACC		= bison -y 
LEX		= flex -olex.yy.c


# Compile options
#
# -DOBJ_CLASSES_PERMS	classes and permissions (must use) 
# -DUSE_SORTING		sorted arrays using AVL trees within arrays (must use, alternative
#			code is deprecated and no longer supported and probably won't work!)
# -DAPOL_PERFORM_TEST	simple performance measure tests (shouldn't normally use)
# -DCONFIG_SECURITY_SELINUX_MLS 
#			compiles library to be compatible with MLS 
#			in the policy (experimental, see Readme)
#
CC_DEFINES	= -DOBJ_CLASSES_PERMS -DUSE_SORTING 

CFLAGS		= -Wall -O2 $(TCL_INCLUDE) $(CC_DEFINES)
#CFLAGS		= -Wall -g $(TCL_INCLUDE) $(CC_DEFINES)

# Install directories
# Binaries go here
BINDIR		= /usr/local/selinux/bin


# NOTE: DON'T CHANGE INSTALL_LIBDIR.  The code expects below INSTALL_LIBDIR 
# to point here.  We will eventually fix this so that the code
# uses the path below, rather than having a hard-coded path.  If you really want
# to change this, then change it here, and change the #define for APOL_INSTALL_DIR
# in ./setools/libapol/apol_tcl.h and change the value of the "help_file"
# variable in ./setools/sepct/top.tcl .  Also make sure to change 
# ./setools/policy/seuser.fc to reflect the change.
#
INSTALL_LIBDIR	= /usr/local/lib/apol
#
# END NOTE

# Assumed policy source directory
POLICY_SRC_DIR	= /etc/security/selinux/src

# This should be imported from tools/Makefile
SRC_POLICY_DIR = ../../

# all apps that have a te/fc file need to be listed here
POLICYINSTALLDIRS = seuser

# exports
export CFLAGS CC YACC LEX LINKFLAGS BINDIR INSTALL_LIBDIR TCL_LIBINC TCL_LIBS MAKE POLICY_SRC_DIR SRC_POLICY_DIR

default:
	@echo "Make targets: (setools version 0.6)"
	@echo "   install:       build and install everything (selinux required)"
	@echo "   install-apol   build and install apol (selinux not required)"
	@echo "   install-sepcut build and install sepct (selinux not required)"
	@echo "   install-seuser build and install seuser (selinux required)"
	@echo " "
	@echo "   The following 3 targets are for use in the selinux build process only"
	@echo "   insert-policy  insert policy files into pre-selinux policy"
	@echo "   sys-install    build and install everything pre-selinux"
	@echo "   sys-make	 build everthing pre-selinux (no install)"
	@echo " "
	@echo "   all:           build everything, but don't install"
	@echo "   apol:          build policy analysis tool"
	@echo "   seuser:        build SE Linux add user tool"
	@echo "   sepcut         build policy customization/browsing tool"
	@echo "   awish:         build TCL/TK wish interpreter with SE Linux tools extensions"
	@echo " "
	@echo "   clean:         clean up interim files"
	@echo "   bare:          more extensive clean up"


apol: selinux_tool
	cd apol; $(MAKE) apol 

awish: selinux_tool
	cd awish; $(MAKE) awish

seuser: selinux_tool
	cd seuser; $(MAKE) seuser

sepcut: selinux_tool
	cd sepct; $(MAKE) sepcut

libapol: selinux_tool
	cd libapol; $(MAKE) 

libseuser: selinux_tool
	cd libseuser; $(MAKE)

all: libapol libseuser apol awish seuser sepcut

$(INSTALL_LIBDIR):
	install -m 755 -d $(INSTALL_LIBDIR)

install-apol: $(INSTALL_LIBDIR)
	cd apol; $(MAKE) install
	cd awish; $(MAKE) install	

install-seuser: $(INSTALL_LIBDIR)
	cd seuser; $(MAKE) install

install-sepcut: $(INSTALL_LIBDIR)
	cd sepct; $(MAKE) install

install: install-apol install-seuser install-sepcut

# Next four targets are to support installation as part of a system
# install.
#
# copy all policy files to the uninstalled selinux policy build directory
insert-policy: 
	cd seuser ; $(MAKE) $@ 
	
sysinstall-seuser: $(INSTALL_LIBDIR)
	cd seuser; $(MAKE) sys-install "CFLAGS+=$(SYS_OPTIONS)"

sysall-seuser: 
	cd seuser; $(MAKE) sys-all "CFLAGS+=$(SYS_OPTIONS)"
	
sys-install: install-apol sysinstall-seuser install-sepcut

sys-all: apol sysall-seuser sepcut

clean:
	cd apol; $(MAKE) clean
	cd awish; $(MAKE) clean
	cd libapol; $(MAKE) clean
	cd sepct; $(MAKE) clean
	cd seuser; $(MAKE) clean
	cd libseuser; $(MAKE) clean
	rm -f *~

bare:
	cd apol; $(MAKE) bare
	cd awish; $(MAKE) bare
	cd libapol; $(MAKE) bare
	cd seuser; $(MAKE) bare
	cd sepct; $(MAKE) bare
	cd libseuser; $(MAKE) bare
	rm -f *~
	rm -rf ./lib


# Leave this empty target here!
selinux_tool:
# empty!


