#*
#*  sudo version 1.1 allows users to execute commands as root
#*  Copyright (C) 1991  The Root Group, Inc.
#*
#*  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 1, 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., 675 Mass Ave, Cambridge, MA 02139, USA.
#*
#*  If you make modifications to the source, we would be happy to have
#*  them to include in future releases.  Feel free to send them to:
#*      Jeff Nieusma                       nieusma@rootgroup.com
#*      3959 Arbol CT                      (303) 447-8093
#*      Boulder, CO 80301-1752             
#*
#
#   This is the Makefile for the main level of sudo
#
#
#          The following macros can be defined when compiling
#
#          FQDN                   - if you have fully qualified hostnames
#                                   in your SUDOERS files
#
#          SYSLOG                 - if you want to use syslog instead
#                                   of a log file
#                                   ( This is a nice feature.  You can
#                                     collect all your sudo logs at a
#                                     single host)
#
#          NO_ROOT_SUDO           - sudo will exit if called by root
# 
#          MULTIMAX               - define if installing on Encore Multimax
#                                   Also change the LIBS macro to "LIBS=-ll"
#
#          SEND_MAIL_WHEN_NOT_OK  - if you want a message sent to ALERTMAIL
#                                   when the user is in the SUDOERS but
#                                   does not have permission to execute
#                                   the command entered
#                                   ( This can be used at paranoid sites )
#
#          SEND_MAIL_WHEN_NO_USER - if you want a message sent to ALERTMAIL
#                                   when the user is not in the SUDOERS file
#                                   ( This is generally the case )
#
#          TIMEDIR                  the directory where the timestamp 
#                                   files are kept.
#
#          TIMEOUT                  the number of minutes that can elapse
#                                   before sudo will ask for a passwd again
#
#          TRIES_FOR_PASSWORD       the number of times sudo will let you
#                                   guess are you password before screaming
#
#          INCORRECT_PASSWORD       the message that is displayed if you 
#                                   incorrectly enter your password
#
#          MAILSUBJECT              the subject of the mail sent to ALERTMAIL
#
#          ALERTMAIL                the recipient of mail from sudo
#
#          SUDOERS                  the location of the sudoers file
#
#          TMPSUDOERS               the location of the lock file for visudo
#
#          EDITOR                   the location of the editor
#
#          LOGFILE                  log file location IF NOT USING SYSLOG
#
#          SYSLOG                   if this variable is defined, sudo will log
#                                   using the 4.3 BSD style syslog facility
#
#       Macro:                   Default:
#          Syslog_ident             "sudo"
#          Syslog_options           LOG_PID
#          Syslog_facility          LOG_LOCAL2
#          Syslog_priority_OK       LOG_NOTICE
#          Syslog_priority_NO       LOG_ALERT
#

# define this for shadow passwords
    SHADOW =
        CC = gcc
       LEX = flex
      YACC = bison -y
   CCFLAGS = -O2 -DHAVE_STRDUP -DLINUX $(SHADOW) -m486 -fomit-frame-pointer
   LDFLAGS = -s
# use this for debugging
#   CCFLAGS = -g -DHAVE_STRDUP -DLINUX $(SHADOW)
   LDFLAGS = 
   DEFINES = -LOGFILE=/var/adm/sudo
      OBJS = find_path.o logging.o sudo.o check.o parse.o lex.yy.o y.tab.o
      SRCS = find_path.c logging.c sudo.c check.c parse.c
  INCLUDES = sudo.h
   SUDOBIN = sudo.bin
   SUDODIR = /usr/bin
 VISUDODIR = /usr/sbin
SUDOERSDIR = /etc
MANSECTION = 8
    MANDIR = /usr/man/man${MANSECTION}
      PROG = sudo.bin
      LIBS = -lfl
    SUNOS4 = -Bstatic
     LINUX = 


.SUFFIXES:	.o .c

.c.o:	${SRCS}
	${CC} ${CCFLAGS} -c ${DEFINES} $<

all		:	${PROG} visudo

all-sunos4	:	sudo-sunos4 visudo

${PROG}		:	${OBJS} 
	${CC} -o $@ *.o ${LIBS}

sudo-sunos4	:	${OBJS}
	${CC} -o sudo *.o ${SUNOS4} ${LIBS}

y.tab.o	y.tab.h	:	parse.yacc ${INCLUDES}
	${YACC} -d parse.yacc
	${CC} $(CCFLAGS) -c y.tab.c

lex.yy.o	:	parse.lex y.tab.h ${INCLUDES}
	${LEX} parse.lex
	${CC} $(CCFLAGS) -c lex.yy.c

logging.o sudo.o check.o parse.o : ${INCLUDES}

visudo		:
	(cd visudoers && make ${MFLAGS} $@)

install : install-all

install-all	: install-binaries install-sudoers install-man

install-all-sunos4: install-binaries-sunos4 install-sudoers

install-sudoers:
	install -o root -g root -m 0600 -c sudoers ${SUDOERSDIR}/sudoers

install-binaries:	all
	install -o root -g bin -m 4711 -s -c ${PROG} ${SUDODIR}/${SUDOBIN}
	install -o root -g bin -m 0755 -c sudo.sh ${SUDODIR}/sudo
	install -o root -g bin -m 0755 -s -c visudoers/visudo ${VISUDODIR}/visudo

install-binaries-sunos4:	sudo-sunos4 visudo
	install -o root -g wheel -m 4111 -s -c sudo ${SUDODIR}/sudo
	install -o root -g wheel -m 0111 -s -c visudoers/visudo ${VISUDODIR}/visudo

install-man:
	install -o root -g man -m 0444 -c sudo.8 ${MANDIR}/sudo.${MANSECTION}
	( cd /usr/man/man8 ; \
	  ln -fs sudo.8 visudo.8 ; chown root.man visudo.8 )

tags		:
	ctags ${SRCS} ${INCLUDES}

clean		:
	-rm -f lex.yy.* y.tab.* *.o ${PROG}
	(cd visudoers && make ${MFLAGS} $@);
