#
# Makefile for the OS/2 Quoteriser
#
#       Created: 18th January, 1997
# Last modified: 10th April, 1997
#
# (C) 1997 Nicholas Paul Sheppard
#
# This file is distributed under the GNU General Public License. See the
# file COPYING for details.
#

#
# Compiler and linker names and options. Mine are for EMX/GCC and LINK386.
#
# CC      - name of the compiler (also used for linking)
# CFLAGS  - flags to pass to the compiler for the normal executables
# CDFLAGS - flags to pass to the compiler for the debug-enabled executables
# RC      - resource compiler
# RFLAGS  - options to pass to the resource compiler
# LIBS    - C libraries to be linked
#

CC      = gcc
CFLAGS  = -I include -Zomf -Zsys -Zmt -m486 -O2 -s -Wall
CDFLAGS = -I include -Zmt -g
RC      = rc
RFLAGS  = -I \emx\include -I include
LIBS    = -lgdbm


#
# Directories. Mine are for placing the binaries in sub-directories of the
# current directory.
#
# BIN   - directory for normal executables
# DEBUG - directory for debug-enabled executables
#

BIN   = bin
DEBUG = debug

#
# Programs to make. To make parts of the Quoteriser, use the appropriate target:
#
# all    - make the whole lot (default target)
# quoter - make the Quoteriser main program, both normal and debug versions
# qotd   - make the Quote-of-the-Day utility, both normal and debug version
# bin    - make the normal executables for both programs
# debug  - make the debug executables for both programs
#
# Of course, you make only one executable by using the name of that executable.
#

all: quoter qotd

quoter: $(BIN)/quoter.exe $(DEBUG)/quoter.exe
qotd: $(BIN)/qotd.exe $(DEBUG)/qotd.exe
bin: $(BIN)/quoter.exe $(BIN)/qotd.exe
debug: $(DEBUG)/quoter.exe $(DEBUG)/qotd.exe

#
# Rules for linking.
#

QUOTER_OBJS = \
$(BIN)/quoter.obj $(BIN)/general.obj $(BIN)/paint1.obj $(BIN)/html.obj $(BIN)/quoter.res \
$(BIN)/qdb.obj $(BIN)/quotes.obj $(BIN)/qsearch.obj $(BIN)/qthreads.obj \
$(BIN)/adb.obj $(BIN)/authors.obj $(BIN)/asearch.obj $(BIN)/athreads.obj

QUOTER_DOBJS = \
$(DEBUG)/quoter.o $(DEBUG)/general.o $(DEBUG)/paint1.o $(DEBUG)/html.o $(DEBUG)/quoter.res \
$(DEBUG)/qdb.o $(DEBUG)/quotes.o $(DEBUG)/qsearch.o $(DEBUG)/qthreads.o \
$(DEBUG)/adb.o $(DEBUG)/authors.o $(DEBUG)/asearch.o $(DEBUG)/athreads.o

QOTD_OBJS = \
$(BIN)/qotd.obj $(BIN)/general.obj $(BIN)/paint2.obj $(BIN)/html.obj $(BIN)/qotd.res \
$(BIN)/qdb.obj $(BIN)/quotes.obj $(BIN)/qsearch.obj $(BIN)/qthreads.obj \
$(BIN)/adb.obj $(BIN)/authors.obj

QOTD_DOBJS = \
$(DEBUG)/qotd.o $(DEBUG)/general.o $(DEBUG)/paint1.o $(DEBUG)/html.o $(DEBUG)/qotd.res \
$(DEBUG)/qdb.o $(DEBUG)/quotes.o $(DEBUG)/qsearch.o $(DEBUG)/qthreads.o \
$(DEBUG)/adb.o $(DEBUG)/authors.o


$(BIN)/quoter.exe: $(QUOTER_OBJS) source/quoter.def
	$(CC) $(CFLAGS) -o $@ $(QUOTER_OBJS) source/quoter.def $(LIBS)

$(DEBUG)/quoter.exe: $(QUOTER_DOBJS) source/quoter.def
	$(CC) $(CDFLAGS) -o $@ $(QUOTER_DOBJS) source/quoter.def $(LIBS)

$(BIN)/qotd.exe: $(QOTD_OBJS) source/qotd.def
	$(CC) $(CFLAGS) -o $@ $(QOTD_OBJS) source/qotd.def $(LIBS)

$(DEBUG)/qotd.exe: $(QOTD_DOBJS) source/qotd.def
	$(CC) $(CDFLAGS) -o $@ $(QOTD_DOBJS) source/qotd.def $(LIBS)

#
# Rules for resource files
#

$(BIN)/%.res: source/%.rc
	$(RC) $(RFLAGS) -r $< $@

$(DEBUG)/%.res: source/%.rc
	$(RC) $(RFLAGS) -r $< $@

#
# Rules for C source files
#

$(BIN)/%.obj: source/%.c
	$(CC) $(CFLAGS) -o $@ -c $<

$(DEBUG)/%.o: source/%.c
	$(CC) $(CDFLAGS) -o $@ -c $<

#
# Special rules for the painting code. This is necessary because paint.c #includes quoterpm.h
# when being compiled for the Quoteriser main program, and #includes qotdpm.h when being
# compiled for the Quote-of-the-Day program (i.e. if QOTD is #defined).
#
# "paint1" belongs to the Quoteriser main program
# "paint2" belongs to the Quote-of-the-Day program
#

$(BIN)/paint1.obj: source/paint.c include/threads.h include/quoterpm.h include/types.h include/html.h
	$(CC) $(CFLAGS) -o $@ -c $<

$(DEBUG)/paint1.o: source/paint.c include/threads.h include/quoterpm.h include/types.h include/html.h
	$(CC) $(CDFLAGS) -o $@ -c $<

$(BIN)/paint2.obj: source/paint.c include/threads.h include/qotdpm.h include/types.h include/html.h
	$(CC) $(CFLAGS) -o $@ -c $< -DQOTD

$(DEBUG)/paint2.o: source/paint.c include/threads.h include/qotdpm.h include/types.h include/html.h
	$(CC) $(CDFLAGS) -o $@ -c $< -DQOTD

#
# Dependencies
#

$(BIN)/quoter.res: source/quoter.rc include/quoterpm.h
$(BIN)/qotd.res: source/qotd.rc include/qotdpm.h
$(BIN)/quoter.obj: source/quoter.c include/quoterpm.h include/general.h include/authors.h include/quotes.h include/types.h include/threads.h
$(BIN)/qotd.obj: source/qotd.c include/qotdpm.h include/general.h include/authors.h include/quotes.h include/types.h include/threads.h
$(BIN)/general.obj: source/general.c include/general.h
$(BIN)/html.obj: source/html.c include/html.h
$(BIN)/adb.obj: source/adb.c include/authors.h
$(BIN)/authors.obj: source/authors.c include/authors.h
$(BIN)/asearch.obj: source/asearch.c include/authors.h
$(BIN)/athreads.obj: source/athreads.c include/authors.h include/threads.h
$(BIN)/qdb.obj: source/qdb.c include/quotes.h
$(BIN)/quotes.obj: source/quotes.c include/quotes.h
$(BIN)/qsearch.obj: source/qsearch.c include/quotes.h
$(BIN)/qthreads.obj: source/qthreads.c include/quotes.h include/threads.h

$(DEBUG)/quoter.res: source/quoter.rc include/quoterpm.h
$(DEBUG)/qotd.res: source/qotd.rc include/qotdpm.h
$(DEBUG)/quoter.o: source/quoter.c include/quoterpm.h include/general.h include/authors.h include/quotes.h include/types.h include/threads.h
$(DEBUG)/qotd.o: source/qotd.c include/qotdpm.h include/general.h include/authors.h include/quotes.h include/types.h include/threads.h
$(DEBUG)/general.o: source/general.c include/general.h
$(DEBUG)/html.o: source/html.c include/html.h
$(DEBUG)/adb.o: source/adb.c include/authors.h
$(DEBUG)/authors.o: source/authors.c include/authors.h
$(DEBUG)/asearch.o: source/asearch.c include/authors.h
$(DEBUG)/athreads.o: source/athreads.c include/authors.h include/threads.h
$(DEBUG)/qdb.o: source/qdb.c include/quotes.h
$(DEBUG)/quotes.o: source/quotes.c include/quotes.h
$(DEBUG)/qsearch.o: source/qsearch.c include/quotes.h
$(DEBUG)/qthreads.o: source/qthreads.c include/quotes.h include/threads.h

