# GNUmakefile
#
# Simple makefile to build .psbb request handler test/demonstration
# program; with no apology, this may gratuitously require GNU make.
#
# Written by Keith Marshall <keith@users.osdn.me>
# Copyright (C) 2017, Free Software Foundation, Inc.
#
# This file is part of groff.
#
# groff is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free
# Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# groff is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
# for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
psbb:

# For convenience, we've placed a necessary subset of libgroff sources
# and headers in our local libgroff subdirectory; ensure that make, and 
# the C/C++ compilers can see them.
#
vpath %.c ./libgroff
vpath %.cpp ./libgroff
vpath %.h ./libgroff

CFLAGS = -g -O2 -I./libgroff
CXXFLAGS = -g -O2 -I./libgroff

# GNU make's default $(YACC) rule doesn't satisfy the dependencies we
# would like, so we specify our own alternative rule.
#
%.tab.c %.tab.h: %.y
	$(YACC) $(YFLAGS) -b $* -d $<

# This is a minimal subset of libgroff.a, (just sufficient to satisfy
# our immediate requirements for our .psbb handler test program).
#
libgroff.a: error.o errarg.o itoa.o fatal.o
	$(AR) rcs $@ $^

# By default, GNU make uses $(CC) for linking, but we need C++ support,
# (which $(CC) doesn't give us automatically); moreover, we do not want
# psbb to incur a default dependency on psbb.o, so link explicitly.
#
psbb: t-psbb.o psbblex.o psbb.tab.o libgroff.a
	$(CXX) $(LDFLAGS) $(TARGET_ARCH) $^ -o $@

# Object file dependencies: GCC could generate these automatically, but
# this is simpler, in this trivial instance.
#
psbblex.o: psbblex.c psbb.tab.h psbb.h
t-psbb.o psbblex.o psbb.tab.o error.o errarg.o: error.h errarg.h
t-psbb.o: psbb.h

# Clean up rules
#
clean:; $(RM) *.o psbb
realclean: clean
	$(RM) `echo *.l | sed 's,\.l,.c,g'` *.tab.* *.a
