#-----------------------------------------------------
# The locations where this program should be installed
INSTALL_X_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 -lm

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

#-----------------------------------------------------
CC = gcc
COPTS = -O3 -std=c99 -pipe -Wall -DNDEBUG -D_BSD_SOURCE -D_XOPEN_SOURCE=600 -Werror -pedantic-errors
#COMPILE_FLAGS = -DDEBUG -DTEST -g

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

OBJ = astime.o astime_x.o safecopy.o x_color.o sunriset.o

all:	astime
	@echo Ready.

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

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

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

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

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

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

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

clean:
	rm -f $(OBJ) astime