# @(#)Makefile 1.16 95/09/16

# Copyright (c) 1994, 1995 by Wayne C. Gramlich.  All rights reserved.

# Permission to use, copy, modify, distribute, and sell this software
# for any purpose is hereby granted without fee provided that the above
# copyright notice and this permission are retained.  The author makes
# no representations about the suitability of this software for any purpose.
# It is provided "as is" without express or implied warranty.

# This should be a pretty portable Makefile:
# All source files are in ANSI-C; a K&R C compiler will not do.

ROOT = ../..
include $(ROOT)/Makefile_common.mk
include $(ROOT)/Makefile_private.mk

#NOTE: I haven't compiled this stuff on Linux yet. -Wayne

# Flags and libraries:
CC = cc
LINT = lint
CFLAGS = -g
NET_LIBRARIES = -lsocket -lnsl

# Install locations:
CGI_BIN_DIR = /opt/WWW/NCSA/httpd/cgi-bin
BIN_DIR = /opt/WWW/NCSA/httpd
ANNOTE_DOCS_DIR = /var/opt/WWW/NCSA/htdocs/annote_docs


# If you are lucky, you shouldn't need to make any modifcations past here.

C_SOURCES =			\
	chr.c			\
	config.c		\
	error.c			\
	form.c			\
	html.c			\
	http.c			\
	link.c			\
	local.c			\
	main.c			\
	memory.c		\
	post_public.c		\
	post_publish.c		\
	post_solicit.c		\
	post_update.c		\
	post_vote.c		\
	ref.c			\
	remote.c		\
	setup_public_annote.c	\
	str.c			\
	text.c			\
	url.c			\
	util.c			\
	vector.c		\
	vote.c			\
	wayne.c
HEADERS =			\
	chr_extern.h		\
	chr_typedef.h		\
	config.h		\
	config_extern.h		\
	config_typedef.h	\
	copyright.h		\
	error.h			\
	error_extern.h		\
	error_typedef.h		\
	form_extern.h		\
	html.h			\
	html_extern.h		\
	html_typedef.h		\
	http.h			\
	http_extern.h		\
	http_typedef.h		\
	link_extern.h		\
	link_typedef.h		\
	local_extern.h		\
	local_typedef.h		\
	memory.h		\
	memory_extern.h		\
	memory_typedef.h	\
	ref.h			\
	ref_extern.h		\
	ref_typedef.h		\
	remote_extern.h		\
	remote_typedef.h	\
	str.h			\
	str_extern.h		\
	str_typedef.h		\
	text.h			\
	text_extern.h		\
	text_typedef.h		\
	url.h			\
	url_extern.h		\
	url_typedef.h		\
	util_extern.h		\
	util_typedef.h		\
	vector.h		\
	vector_extern.h		\
	vector_typedef.h	\
	vote_extern.h		\
	vote_typedef.h
HTMLS =				\
	index.html
SOURCES =			\
	${C_SOURCES}		\
	${HEADERS}		\
	${HTMLS}		\
	Makefile
COPY_LIST = ${SOURCES}
ALL = ${SOURCES}

.PHONY: all clean copy spell

all: ${ALL}

copy: ${ALL}
	set -e ;							\
	if [ "$(COPY_DIRECTORY)" = "" ] ;				\
	  then								\
	    echo "Please set COPY_DIRECTORY in `pwd`" ;			\
	    exit 1 ;							\
	  fi
	rm -rf $(COPY_DIRECTORY)
	mkdir -p $(COPY_DIRECTORY)
	cp ${COPY_LIST} $(COPY_DIRECTORY)

clean:
	$(CLEAN)

spell:


##############################################################################

# List all targets:
PROGRAMS = post_public post_solicit post_update post_vote setup_public_annote
LINTS = post_public_lint post_solicit_lint post_update_lint post_vote_lint \
	setup_public_annote_lint
TARS = post_public.tar source.tar

# Utility library files:
UTIL_TYPEDEFS = chr_typedef.h config_typedef.h error_typedef.h \
	html_typedef.h http_typedef.h link_typedef.h local_typedef.h \
	memory_typedef.h remote_typedef.h str_typedef.h text_typedef.h \
	url_typedef.h util_typedef.h vector_typedef.h vote_typedef.h
UTIL_EXTERNS = chr_extern.h config_extern.h error_extern.h form_extern.h\
	html_extern.h http_extern.h link_extern.h local_extern.h \
	memory_extern.h remote_extern.h str_extern.h text_extern.h \
	url_extern.h util_extern.h vector_extern.h vote_extern.h
UTIL_HEADERS = ${UTIL_TYPEDEFS} ${UTIL_EXTERNS}
UTIL_SOURCES = chr.c config.c error.c form.c html.c http.c link.c local.c \
	memory.c remote.c str.c text.c url.c util.c vector.c vote.c
UTIL_OBJECTS = chr.o config.o error.o form.o html.o http.o link.o local.o \
	memory.o remote.o str.o text.o url.o util.o vector.o vote.o
UTIL_LINTS = chr.ln config.ln error.ln form.ln html.ln http.ln link.ln \
	local.ln memory.ln remote.ln str.ln text.ln url.ln util.ln vector.ln \
	vote.ln
UTIL_LIBRARIES = ${NET_LIBRARIES}

# post_public command:
PUBLIC_SOURCES = post_public.c ${UTIL_SOURCES}
PUBLIC_OBJECTS = post_public.o ${UTIL_OBJECTS}
PUBLIC_LINTS = post_public.ln ${UTIL_LINTS}
PUBLIC_LIBRARIES = ${UTIL_LIBRARIES}

# post_solicit command:
SOLICIT_SOURCES = post_solicit.c ${UTIL_SOURCES}
SOLICIT_OBJECTS = post_solicit.o ${UTIL_OBJECTS}
SOLICIT_LINTS = post_solicit.ln ${UTIL_LINTS}
SOLICIT_LIBRARIES = ${UTIL_LIBRARIES}

# post_update command:
UPDATE_SOURCES = post_update.c ${UTIL_SOURCES}
UPDATE_OBJECTS = post_update.o ${UTIL_OBJECTS}
UPDATE_LINTS = post_update.ln ${UTIL_LINTS}
UPDATE_LIBRARIES = ${UTIL_LIBRARIES}

# post_vote command:
VOTE_SOURCES = post_vote.c ${UTIL_SOURCES}
VOTE_OBJECTS = post_vote.o ${UTIL_OBJECTS}
VOTE_LINTS = post_vote.ln ${UTIL_LINTS}
VOTE_LIBRARIES = ${UTIL_LIBRARIES}

# setup_public_annote command:
SETUP_SOURCES = setup_public_annote.c
SETUP_OBJECTS = setup_public_annote.o
SETUP_LINTS = setup_public_annote.ln
SETUP_LIBRARIES =

# File lists for Make clean, etc.
ALL_HEADERS = copyright.h ${UTIL_HEADERS}
ALL_SOURCES = ${PUBLIC_SOURCES} ${SOLICIT_SOURCES} ${UPDATE_SOURCES} \
	${VOTE_SOURCES} ${SETUP_SOURCES}
ALL_OBJECTS = ${PUBLIC_OBJECTS} ${SOLICIT_OBJECTS} ${UPDATE_OBJECTS} \
	${VOTE_OBJECTS} ${SETUP_OBJECTS}
ALL_LINTS = ${PUBLIC_LINTS} ${SOLICIT_LINTS} ${UPDATE_LINTS} \
	${VOTE_LINTS} ${SETUP_LINTS}
ALL_FILES = Makefile index.html ${ALL_SOURCES} ${ALL_HEADERS}


# Targest that build everything:
#all: ${PROGRAMS}

lint : ${LINTS}

# Commands to link and lint pass 2 everything:
post_public: ${ALL_FILES} ${PUBLIC_OBJECTS}
	$(CC) -o post_public ${PUBLIC_OBJECTS} ${PUBLIC_LIBRARIES}

post_public_lint: ${ALL_FILES} ${PUBLIC_LINTS}
	$(LINT) ${PUBLIC_LINTS}
	touch post_public_lint

post_solicit: ${ALL_FILES} ${SOLICIT_OBJECTS}
	$(CC) -o post_solicit ${SOLICIT_OBJECTS} ${SOLICIT_LIBRARIES}

post_solicit_lint: ${ALL_FILES} ${SOLICIT_LINTS}
	$(LINT) ${SOLICIT_LINTS}
	touch post_solicit_lint

post_update: ${ALL_FILES} ${UPDATE_OBJECTS}
	$(CC) -o post_update ${UPDATE_OBJECTS} ${UPDATE_LIBRARIES}

post_update_lint: ${ALL_FILES} ${UPDATE_LINTS}
	$(LINT) ${UPDATE_LINTS}
	touch post_update_lint

post_vote: ${ALL_FILES} ${VOTE_OBJECTS}
	$(CC) -o post_vote ${VOTE_OBJECTS} ${VOTE_LIBRARIES}

post_vote_lint: ${ALL_FILES} ${VOTE_LINTS}
	$(LINT) ${VOTE_LINTS}
	touch post_vote_lint

setup_public_annote: ${ALL_FILES} ${SETUP_OBJECTS}
	$(CC) -o setup_public_annote ${SETUP_OBJECTS} ${SETUP_LIBRARIES}

setup_public_annote_lint: ${ALL_FILES} ${SETUP_LINTS}
	$(LINT) ${SETUP_LINTS}
	touch setup_public_annote_lint

# Build tar files:
post_public.tar: ${PUBILC_FILES}
	rm -f post_public.tar
	tar cvf post_public.tar post_public

source.tar: ${ALL_FILES}
	rm -f source.tar
	tar cf source.tar ${ALL_FILES}

# Generate install shell script so that installs can occur on machines
# that do not have make installed:
install: install.sh ${PROGRAMS} ${TARS}
	install.sh

install.sh:
	rm -f install.sh
	echo rm -f $(ANNOTE_DOCS_DIR)/post_public.tar >> install.sh
	echo cp post_public.tar $(ANNOTE_DOCS_DIR) >> install.sh
	echo rm -f $(ANNOTE_DOCS_DIR)/source.tar >> install.sh
	echo cp source.tar $(ANNOTE_DOCS_DIR) >> install.sh
	echo rm -f $(CGI_BIN_DIR)/post_solicit >> install.sh
	echo cp post_solicit $(CGI_BIN_DIR)/post_solicit >> install.sh
	echo rm -f $(CGI_BIN_DIR)/post_vote >> install.sh
	echo cp post_vote $(CGI_BIN_DIR)/post_vote >> install.sh
	echo rm -f $(CGI_BIN_DIR)/post_update >> install.sh
	echo cp post_update $(CGI_BIN_DIR)/post_update >> install.sh
	echo rm -f $(BIN_DIR)/setup_public_annote >> install.sh
	echo cp setup_public_annote $(BIN_DIR)/setup_public_annote >> install.sh
	chmod +x install.sh

#clean:
#	rm -f ${ALL_OBJECTS} ${ALL_LINTS} ${PROGRAMS} ${LINTS} ${TARS} \
#		install.sh

