#
# Makefile (gpm-Linux)
#
# Copyright 1994   rubini@ipvvis.unipv.it
#
####
# This Makefile has been used for both a linux system
# and a SunOS-4.1 (when I lost my hard drive)
#
# The main configuration parameters are in gpmCfg.h

CFLAGS = -O2 -fomit-frame-pointer
#CFLAGS = -g -DDEBUG

INSTALL = install -c
INSTALLBIN = $(INSTALL) -m 755
INSTALLLIB = $(INSTALL) -m 644

ifndef PREFIX
  PREFIX = /usr/local
endif
LIBDIR = $(PREFIX)/lib
BINDIR = $(PREFIX)/bin
INCDIR = $(PREFIX)/include
INFODR = $(PREFIX)/info

############## no more editing...

%.elc: %.el
	emacs -batch -l exec.el -exec '(byte-compile-file "$<")'

CLIENTOBJS = mev.o
CLIENTS = $(CLIENTOBJS:.o=) t-mouse.elc
LDFLAGS = -lcurses -L. -l$(TARGET)

TARGET = gpm
   TOBJS = gpm.o gpn.o mice.o
LIB = lib$(TARGET).a
   LOBJS = liblow.o libhigh.o libcurses.o
INCLUDES = gpm.h
INFO = doc/gpm.info

### Hmm... automatic extraction didn't quite work
#SUPPORT = gpm-xterm.c
#SUPPINI = gpm-xterm.ini
#SUPPSRC = libcurses.c liblow.c
#SUPPSRH = gpm.h


ifeq ($(RANLIB),)
   RANLIB = ranlib
endif

# if not Linux, print a message and die
ifneq ($(shell uname),Linux)
all: check
endif

# force make depend
ifneq (.depend,$(wildcard .depend))
all: depend
endif

all: $(TARGET) $(LIB) $(CLIENTOBJS) $(CLIENTS) $(INFO) $(SUPPORT)

check:
	@if [ `uname` != Linux ]; then \
	  echo "" ;\
	  echo "**** This package can compile only under Linux, by now."; \
	  echo "**** Please read the docs (after \"make -C doc\") "; \
	  echo "****    and compile the portable client " \
	       "under \"sample\", instead"; \
	  echo "" ;\
	  exit 1; fi

$(TARGET): $(TOBJS) $(MORETOBJS)
	$(CC) $(CFLAGS) -o $@ $^

$(LIB): $(LOBJS)
	$(AR) r $(LIB) $(LOBJS)
	$(RANLIB) $(LIB)

# Without this silly rule it won't work :-(
# $(LD) won't work, either.
%: %.o
	$(CC) $*.o -o $@ $(LDFLAGS)

$(CLIENTS): $(LIB)

$(INFO): doc/doc.gpm
	$(MAKE) -C doc info

$(SUPPORT): $(SUPPINI) $(SUPPSRC)
	cp $(SUPPINI) $*.c
	cp $(SUPPINI) $*.h
	awk -f ./selector $(SUPPSRC) >> $*.c
	awk -f ./selector gpm.h >> $*.h

############## misc targets

.PHONY: install clean cleanest check distrib terse tar bin\
             mpage sample sample-dist depend dep DEPEND DEP

install:
	$(INSTALLBIN) $(TARGET) $(CLIENTS) $(BINDIR) 
	@echo ""
	@echo -n "     ==> WARNING:"
	@echo " The emacs-lisp file has been installed in $(BINDIR)"
	@echo ""
	$(INSTALLLIB) $(LIB)               $(LIBDIR)
	$(INSTALLLIB) $(INCLUDES)          $(INCDIR)
	$(INSTALLLIB) $(INFO)              $(INFODR)

quickinst:
	(cd bin; tar cf - *) | (cd $(PREFIX); tar xvf -)

terse:
	rm -f *~ */*~ */*.dvi */*.log

clean: terse
	rm -f .depend TAGS Test.log
	$(MAKE) -C doc clean
	rm -f $(TARGET) $(LIB) $(CLIENTS) *.o

cleanest: clean
	rm -r bin
printv:
	@grep RELEASE *.h doc/* sample/*.c

tar:
	n=`basename \`pwd\``; cd ..; tar cvf - $$n | gzip > $$n.tar.gz

mpage:
	$(MAKE) -C doc mpage

sample-dist:
	$(MAKE) -C sample distrib
test: gpm
	csh -c "(time ./gpm -m ./data -T ) |& tee /dev/tty >> Test.log"

depend dep:
	gcc -MM *.c > .depend

DEPEND DEP:
	gcc -M *.c > .depend

bin: all
	-mkdir bin bin/bin bin/include bin/lib bin/info
	$(MAKE) install PREFIX=./bin

sample:
	$(MAKE) -C sample

distrib: mpage sample-dist bin clean sample tar printv


ifeq (.depend,$(wildcard .depend))
include .depend
endif






