##########################################################################
#   Copyright (C) International Business Machines  Corp., 2004
#
#   This program is free software;  you can redistribute it and/or modify
#   it under the terms of the GNU General Public License as published by
#   the Free Software Foundation; either version 2 of the License, or
#   (at your option) any later version.
#
#   This program is distributed in the hope that it will be useful,
#   but WITHOUT ANY WARRANTY;  without even the implied warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
#   the GNU General Public License for more details.
#
#   You should have received a copy of the GNU General Public License
#   along with this program;  if not, write to the Free Software
#   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
#
#
#  FILE   : Makefile
#
#  PURPOSE: The default "all" target uses the gcc compiler to compile all
#           test files in the current directory.
#
#           The "clean" target removes all files the end in ".o" (object
#           files).
#
#
#  HISTORY:
#    10/04 originated by Dan Jones (danjones@us.ibm.com)
#
##########################################################################
TOPDIR= ../..
LOG=log
CC=gcc 
EXE=testfileperms
DIRS= proc \
	sys

all:: $(EXE)

run:: all
	-grep "^fpermu" /etc/passwd | awk -F: '{print $$1}' | xargs -i userdel -r {}
	-grep "^fpermg" /etc/group | awk -F: '{print $$1}' | xargs -i groupdel {}
	useradd fpermu &>/dev/null
	groupadd fpermg &>/dev/null
	-for i in $(DIRS); do ./$(EXE) /$$i fpermu fpermg &>$(EXE).$$i.$(LOG); done
	-for i in $(DIRS); do grep "FAIL" $(EXE).$$i.$(LOG) > $(EXE).$$i.FAIL; done
	-for i in $(DIRS); do grep "SKIP" $(EXE).$$i.$(LOG) > $(EXE).$$i.SKIP; done

	groupdel fpermg &>/dev/null
	userdel -fr fpermu &>/dev/null

rmlogs::
	rm -f *log &>/dev/null
	rm -f *FAIL &>/dev/null
	rm -f *SKIP &>/dev/null

clean::
	rm -f $(EXE)

include $(TOPDIR)/rules.mk
