# The top directory of X stuff on your system
X_TOP_DIR=/tools/X11R5

X_INCLUDE_DIR=$(X_TOP_DIR)/include
# Ultrix should use:
#X_INCLUDE_DIR=/usr/include/mit

X_LIB_DIR=$(X_TOP_DIR)/lib

# Direcoty for X application resource defaults
X_APP_DEFAULTS_DIR=$(X_TOP_DIR)/lib/X11/app-defaults

X_LIBS=-lXaw -lXmu -lXt -lXext -lX11
# If compiling with Sun OpenWindows 3, replace the line above by the line below.
#X_LIBS= -lXaw -lm -Bstatic -lXmu -Bdynamic -lXt -lXext -lX11  -lresolv -lm 

HELP_DEST_DIR=$(X_LIB_DIR)/xgopher
HELP_FILE=$(HELP_DEST_DIR)/xgopher.help

# Directory into which rxgopher program will be installed:
BIN_DEST_DIR=$(X_TOP_DIR)/bin

MAN_SUFFIX=n
# Directory into which rxgopher's man page file will be installed:
MAN_DEST_DIR=$(X_TOP_DIR)/man/man$(MAN_SUFFIX)

# Define RESOLV_LIB if your system (e.g., SunOS before 4.1.1)
# doesn't search resolver library automatically.
# Leave it undefined otherwise.
#RESOLV_LIB=-lresolv
# If your compiler or loader complains about _res_init being
# an undefined symbol, then you must define RESOLV_LIB.
#
# IRIX should use the next two lines:
#RESOLV_LIB=-lsun
#CCKR=-cckr

CFLAGS=-I$(X_INCLUDE_DIR) -DAPP_DEFAULTS_DIR=\"$(X_APP_DEFAULTS_DIR)\" -DHELP_FILE=\"$(HELP_FILE)\" $(CCKR)

SOCKS_LIB=../lib/libsocks.a

# The 'install' command is assumed to be the BSD variety (using -m to
# set the file mode). If the default 'install' on your system doesn't
# do that, you have to either specify an alternative one in the line below
# (e.g., /usr/ucb/install) or modify the install instructions.
INSTALL= install

#==============================================================================

SRCS = xgopher.c item.c itemList.c dir.c dirList.c markList.c \
       util.c misc.c net.c ioutil.c \
       gui.c resources.c help.c \
       panel.c save.c text.c error.c cso.c index.c \
       bkmkfile.c options.c version.c single.c itemInfo.c\
       KeyWSink.c

OBJS = xgopher.o item.o itemList.o dir.o dirList.o markList.o \
       util.o misc.o net.o ioutil.o \
       gui.o resources.o help.o \
       panel.o save.o text.o error.o cso.o index.o \
       bkmkfile.o options.o version.o single.o itemInfo.o\
       KeyWSink.o

PROGRAM = rxgopher

all: echocwd rxgopher

rxgopher: $(OBJS) $(SOCKS_LIB)
	$(CC) -o $@ $(OBJS) $(SOCKS_LIB) $(RESOLV_LIB) -L$(X_LIB_DIR) $(X_LIBS)

install: echocwd rxgopher xgopher.help RXgopher.ad RXgopher-color.ad
	@if [ -d $(BIN_DEST_DIR) ]; then set +x; \
	else (set -x; mkdir -p $(BIN_DEST_DIR)); fi
	$(INSTALL) -c rxgopher $(BIN_DEST_DIR)
	@if [ -d $(HELP_DEST_DIR) ]; then set +x; \
	else (set -x; mkdir -p $(HELP_DEST_DIR)); fi
	$(INSTALL) -c -m 0444 xgopher.help $(HELP_DEST_DIR)
	@if [ -d $(X_APP_DEFAULTS_DIR) ]; then set +x; \
	else (set -x; mkdir -p $(X_APP_DEFAULTS_DIR)); fi
	$(INSTALL) -c -m 0444 RXgopher.ad $(X_APP_DEFAULTS_DIR)/RXgopher
	@if [ -d $(X_APP_DEFAULTS_DIR) ]; then set +x; \
	else (set -x; mkdir -p $(X_APP_DEFAULTS_DIR)); fi
	$(INSTALL) -c -m 0444 RXgopher-color.ad $(X_APP_DEFAULTS_DIR)/RXgopher-color

install.man: echocwd xgopher.man rxgopher.n
	@if [ -d $(MAN_DEST_DIR) ]; then set +x; \
	else (set -x; mkdir -p $(MAN_DEST_DIR)); fi
	$(INSTALL) -c -m 0444 xgopher.man $(MAN_DEST_DIR)/xgopher.$(MAN_SUFFIX)
	$(INSTALL) -c -m 0444 rxgopher.n $(MAN_DEST_DIR)


clean: echocwd
	rm -f $(PROGRAM) $(OBJS)

echocwd:
	@pwd
