
# Setting the DEBRAM_LOCAL environment variable causes this makefile
# correctly to build `debram' locally in the present directory, such
# that the `debram' executable seeks its library data file locally.
# To build `debram' locally, enter
#
#   $ DEBRAM_LOCAL=1 make
#
# Otherwise, this makefile builds `debram' for Debian packaging and
# distribution, such that the `debram' executable seeks its library data
# file in `/usr/lib/debram/':
#
#   $ make
#
# To prepare for an all-new build, enter one of
#
#   $ make clean
#   $ DEBRAM_LOCAL=1 make clean
#
# (The only difference between the two is that the latter cleans
# a few extra scratchpad files up, if they exist, as specified
# by $(clean_local) below.)
#
# To view the manpage locally, enter
#
#   $ man ./debram.1
#

prog     := debram

DEBRAM_OPTIM_LVL ?= -O2
ifdef DEBRAM_LOCAL
  ccdef       := -DDEBRAM_LOCAL
  warn        := -Wall
  clean_local := a.out out err
else
  optim       := $(DEBRAM_OPTIM_LVL) -g -fomit-frame-pointer
endif

CFLAGS   += $(warn) $(ccdef) $(optim)
LDFLAGS  += $(warn)

LDLIBS   += -lz

def_h     =                      def.h
gen_h     = $(def_h)             gen.h
alloc_h   =                      alloc.h
strx_h    = $(def_h)             strx.h
conv_h    = $(def_h)             conv.h
argp_h    = $(def_h)             argp.h
sel_h     = $(def_h)             sel.h
color_h   = $(def_h) $(argp_h)   color.h
utf8_h    = $(def_h) $(argp_h)   \
                     $(color_h)  utf8.h
ldf_h     = $(def_h)             ldf.h
datum_h   = $(def_h)             datum.h
xref_h    = $(def_h)             xref.h
plan_h    = $(def_h)             plan.h
prdeb_h   = $(def_h) $(datum_h)  prdeb.h
prram_h   = $(def_h) $(xref_h)   prram.h
find_h    = $(def_h)             find.h
main_h    = $(def_h)             main.h

obj      := strx.o   \
            conv.o   \
            argp.o   \
            sel.o    \
            color.o  \
            utf8.o   \
            ldf.o    \
            datum.o  \
            xref.o   \
            plan.o   \
            prdeb.o  \
            prram.o  \
            find.o   \
            main.o

all       : $(prog)
.PHONY: all

$(prog)   : $(obj)
	$(CC) $(LDFLAGS) -o $@ $^ $(LDLIBS)

$(obj)    : $(gen_h)
strx.o    : $(strx_h)
conv.o    : $(conv_h)
argp.o    : $(argp_h)   $(alloc_h)
sel.o     : $(sel_h)    $(alloc_h)
color.o   : $(color_h)  $(argp_h)
utf8.o    : $(utf8_h)   $(alloc_h)
ldf.o     : $(ldf_h)    $(argp_h)
datum.o   : $(datum_h)  $(conv_h)   \
                        $(argp_h)   \
                        $(ldf_h)
xref.o    : $(xref_h)   $(strx_h)   \
                        $(argp_h)   \
                        $(datum_h)  \
                        $(alloc_h)
plan.o    : $(plan_h)   $(argp_h)   \
                        $(color_h)  \
                        $(utf8_h)   \
                        $(xref_h)
prdeb.o   : $(prdeb_h)  $(strx_h)   \
                        $(argp_h)   \
                        $(sel_h)    \
                        $(color_h)  \
                        $(utf8_h)   \
                        $(datum_h)
prram.o   : $(prram_h)  $(conv_h)   \
                        $(argp_h)   \
                        $(color_h)  \
                        $(utf8_h)   \
                        $(datum_h)  \
                        $(prdeb_h)
find.o    : $(find_h)   $(strx_h)   \
                        $(argp_h)   \
                        $(datum_h)  \
                        $(xref_h)   \
                        $(prdeb_h)
main.o    : $(main_h)   $(argp_h)   \
                        $(sel_h)    \
                        $(utf8_h)   \
                        $(xref_h)   \
                        $(plan_h)   \
                        $(prram_h)  \
                        $(find_h)

.PHONY    : clean
clean     :
	rm -f $(prog) $(obj) $(clean_local)

