# Copyright (C) 2006-2010,2012-2013 G.P. Halkes
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 3, as
# published by the Free Software Foundation.
#
# This program 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/>.
.POSIX:

# C-compiler flags
CFLAGS=-O2 -Isrc

CONFIGFLAGS=
CONFIGLIBS=
INSTALL=install
SILENTCC=@echo '[CC]' $< ;
SILENTLD=@echo '[LD]' $@ ;
prefix=/usr/local
bindir=$(prefix)/bin
docdir=$(prefix)/share/doc/termdebug
mandir=$(prefix)/share/man

OBJECTS=src/input_lex.o src/common.o src/replay.o src/view.o src/rerecord.o src/compare.o src/record.o src/input.o
OPTOBJECTS=

all: termdebug

.PHONY: all clean install

clean:
	rm -rf src/*.o

dist-clean: clean
	rm -rf tdrecord tdreplay tdrerecord tdview tdcompare config.log Makefile

.c.o:
	$(SILENTCC) $(CC) $(CFLAGS) $(CONFIGFLAGS) -c -o $@ $<

termdebug: $(OBJECTS) $(OPTOBJECTS)
	$(SILENTLD) $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(OBJECTS) $(OPTOBJECTS) $(LDLIBS) $(CONFIGLIBS)

# Macros to make DESTDIR support more readable
_bindir=$(DESTDIR)$(bindir)
_docdir=$(DESTDIR)$(docdir)
_mandir=$(DESTDIR)$(mandir)

install: all
	$(INSTALL) -d "$(_bindir)"
	$(INSTALL) termdebug "$(_bindir)"
	cd "$(_bindir)" && ln -s termdebug tdrecord
	cd "$(_bindir)" && ln -s termdebug tdreplay
	cd "$(_bindir)" && ln -s termdebug tdrerecord
	cd "$(_bindir)" && ln -s termdebug tdview
	cd "$(_bindir)" && ln -s termdebug tdcompare
	$(INSTALL) -d "$(_mandir)/man1"
	$(INSTALL) -m 644 man/*.1 "$(_mandir)/man1"
	$(INSTALL) -d "$(_docdir)"
	$(INSTALL) -m 644 README COPYING Changelog "$(_docdir)"
