#-----------------------------------------------------
# The locations where this program should be installed
INSTALL_DIR=/usr/local/bin
MAN_DIR=/usr/local/man/man1

# The location and names of the X11 libraries
LDIR = -L/usr/X11R6/lib
LIBS = -lXpm -lX11

# The include path to the X11 files
C_INCLUDE = -I. -I/usr/X11R6/include

#-----------------------------------------------------
CC = gcc
COPTS = -O2 -pipe -Wall -Wshadow
#COMPILE_FLAGS = -DDEBUG -DTEST -g

CFLAGS = $(COPTS) $(COMPILE_FLAGS) $(C_INCLUDE)

OBJ = asapm.o apm_read.o apm_x.o apm_react.o apm_rc.o safecopy.o

all:	asapm
	@echo Ready.

asapm:  $(OBJ)
	$(CC) $(OBJ) $(LDIR) $(LIBS) -o asapm

asapm.o: asapm.c safecopy.h state.h apm_read.h apm_x.h apm_react.h apm_rc.h
	$(CC) -c $< $(CFLAGS) -o $@

safecopy.o: safecopy.c
	$(CC) -c $< $(CFLAGS) -o $@

apm_read.o: apm_read.c state.h
	$(CC) -c $< $(CFLAGS) -o $@

apm_rc.o: apm_rc.c
	$(CC) -c $< $(CFLAGS) -o $@

apm_x.o: apm_x.c state.h background_in.xpm background_out.xpm\
         alphabet_in.xpm alphabet_out.xpm
	$(CC) -c $< $(CFLAGS) -o $@

apm_react.o: apm_react.c state.h
	$(CC) -c $< $(CFLAGS) -o $@

install: 
	@echo Installing asapm in $(INSTALL_DIR) ...
	-@strip asapm
	-@if [ -e $(INSTALL_DIR)/asapm ] ; then rm $(INSTALL_DIR)/asapm; fi
	@cp asapm $(INSTALL_DIR)/asapm
	@chmod 755 $(INSTALL_DIR)/asapm
	@echo Installing the man page in $(MAN_DIR) ...
	@cp asapm.man $(MAN_DIR)/asapm.1x
	@chmod 644 $(MAN_DIR)/asapm.1x
	@echo Done.

uninstall:
	@echo Uninstalling asapm in $(INSTALL_DIR) ...
	-@if [ -e $(INSTALL_DIR)/asapm ] ; then rm $(INSTALL_DIR)/asapm; fi
	@echo Uninstalling the man page in $(MAN_DIR) ...
	-@if [ -e $(MAN_DIR)/asapm.1x ] ; then rm $(MAN_DIR)/asapm.1x; fi
	@echo Done.

clean:
	rm -f $(OBJ) asapm

