###
### Makefile
###
### Author:  Kazu Yamamoto <Kazu@Mew.org>
### Created: Jul 7, 2000
### Revised: 

###
### make
### make install
###

srcdir = @srcdir@
VPATH = @srcdir@

prefix = @prefix@
exec_prefix = @exec_prefix@
bindir = @bindir@
mandir = @mandir@/man1

CC = @CC@
CFLAGS = @CFLAGS@
CPPFLAGS = @CPPFLAGS@
LDFLAGS = @LDFLAGS@
COFLAG = -o $@ 
LIBS = @LIBS@

INSTALL = @INSTALL@
LN = ln
RM = rm -f
MKDIR = mkdir -p

#INSTALL = copy
#LN = copy
#RM = del
#MKDIR = md

EXEEXT=@EXEEXT@
OBJEXT=.@OBJEXT@

SRC1 = mewencode.c utils.c
OBJ1 = mewencode$(OBJEXT) utils$(OBJEXT)
PRG1 = mewencode$(EXEEXT)
ALT  = mewdecode$(EXEEXT) mewcat$(EXEEXT)
SRC2 = mewl.c utils.c pattern.c
OBJ2 = mewl$(OBJEXT) utils$(OBJEXT) pattern$(OBJEXT)
PRG2 = mewl$(EXEEXT)
SRC3 = incm.c
OBJ3 = incm$(OBJEXT) utils$(OBJEXT)
PRG3 = incm$(EXEEXT)
PRG4 = mewest
PRG5 = mew-pinentry
PRG6 = cmew
PRG7 = smew

DO1 = utils$(OBJEXT)
SR2 = pattern.c
DO2 = pat$(OBJEXT)
DBG = pattern

MAN1 = mewencode.1
MALT = mewdecode.1 mewcat.1
MAN2 = mewl.1
MAN3 = incm.1
MAN4 = mewest.1
MAN5 = mew-pinentry.1
MAN6 = cmew.1
MAN7 = smew.1

CNF = config.h config.status config.cache config.log configure.lineno
MK  = Makefile

DESTDIR =

.c$(OBJEXT):
	$(CC) -c $(DEFS) $(CFLAGS) $(CPPFLAGS) $<

all: $(PRG1) $(PRG2) $(PRG3)

$(PRG1) : $(OBJ1)
	$(CC) $(COFLAG) $(LDFLAGS) $(OBJ1) $(LIBS)
	$(RM) $(ALT)
	for f in $(ALT); do \
	  $(LN) $(PRG1) $${f}; done

$(PRG2): $(OBJ2)
	$(CC) $(COFLAG) $(LDFLAGS) $(OBJ2)

$(PRG3): $(OBJ3)
	$(CC) $(COFLAG) $(LDFLAGS) $(OBJ3)

$(DO2): $(SR2)
	$(CC) -DDEBUG -c $(CFLAG) -o $(DO2) $(SR2)

$(DBG): $(DO1) $(DO2)
	$(CC) $(CFLAGS) $(COFLAG) $(DO1) $(DO2)

clean:
	$(RM) $(OBJ1) $(PRG1) $(ALT) $(OBJ2) $(PRG2) $(OBJ3) $(PRG3) $(DBG) $(DO2)

distclean: clean
	$(RM) $(CNF) $(MK) $(PRG5)

install: all
	-@if [ ! -d $(DESTDIR)$(bindir) ]; then \
		$(MKDIR) $(DESTDIR)$(bindir); \
	fi
	$(INSTALL) -m 555 $(PRG1) $(DESTDIR)$(bindir)
	for f in $(ALT); do \
		$(RM) $(DESTDIR)$(bindir)/$${f}; \
		$(LN) $(DESTDIR)$(bindir)/$(PRG1) $(DESTDIR)$(bindir)/$${f}; \
	done
	$(INSTALL) -m 555 $(PRG2) $(DESTDIR)$(bindir)
	$(INSTALL) -m 555 $(PRG3) $(DESTDIR)$(bindir)
	$(INSTALL) -m 555 $(PRG4) $(DESTDIR)$(bindir)
	$(INSTALL) -m 555 $(PRG5) $(DESTDIR)$(bindir)
	$(INSTALL) -m 555 $(PRG6) $(DESTDIR)$(bindir)
	$(INSTALL) -m 555 $(PRG7) $(DESTDIR)$(bindir)
	-@if [ ! -d $(DESTDIR)$(mandir) ]; then \
		$(MKDIR) $(DESTDIR)$(mandir); \
	fi
	$(INSTALL) -m 444 $(MAN1) $(DESTDIR)$(mandir)
	for f in $(MALT); do \
		$(RM) $(DESTDIR)$(mandir)/$${f}; \
		$(LN) $(DESTDIR)$(mandir)/$(MAN1) $(DESTDIR)$(mandir)/$${f}; \
	done
	$(INSTALL) -m 444 $(MAN2) $(DESTDIR)$(mandir)
	$(INSTALL) -m 444 $(MAN3) $(DESTDIR)$(mandir)
	$(INSTALL) -m 444 $(MAN4) $(DESTDIR)$(mandir)
	$(INSTALL) -m 444 $(MAN5) $(DESTDIR)$(mandir)
	$(INSTALL) -m 444 $(MAN6) $(DESTDIR)$(mandir)
	$(INSTALL) -m 444 $(MAN7) $(DESTDIR)$(mandir)

##
## End of Makefile
##
