# src/Makefile
# This file is part of SlugTerm; see http://chezphil.org/slugterm
# (C) 2005 Philip Endecott
# Modifications for 4D Systems Display Graphics Modules (C) 2018 Sven Killig <sven@killig.de>

# This is version $Name:  $
#   (if there is no version (e.g. V0-1) mentioned in the previous line,
#    this is probably a snapshot from between "official" releases.)

# This program 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 2 of the License, or
# any later version.
#
# 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, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.


default_target: compile

EXECUTABLE=slugterm

compile: $(EXECUTABLE)


PKG_CONFIG=pkg-config

ROTE_CONFIG=rote-config
ROTE_CFLAGS=$(shell $(ROTE_CONFIG) --cflags)
ROTE_LIBS=$(shell $(ROTE_CONFIG) --libs)
BOOST_LIBS=$(shell $(PKG_CONFIG) --libs libboost)

CPP_FLAGS=$(ROTE_CFLAGS) $(FTDI_CFLAGS)

GCC_FLAGS=-D_REENTRANT

NO_OPT_COMPILE_FLAGS=$(CPP_FLAGS) $(GCC_FLAGS) -Wall
COMPILE_FLAGS=$(NO_OPT_COMPILE_FLAGS) -O


C_COMPILE_FLAGS=$(COMPILE_FLAGS) -std=gnu99


C_SRCS=$(wildcard *.c)
CC_SRCS=$(wildcard *.cc)
CPP_SRCS=$(wildcard *.cpp)

OBJS=$(addsuffix .o,$(basename $(C_SRCS) $(CC_SRCS) $(CPP_SRCS)))

UkKeyboardLayout.o:
	$(CXX) $(NO_OPT_COMPILE_FLAGS) -o $@ -c $<

%.o: %.cc
	$(CXX) $(COMPILE_FLAGS) -o $@ -c $<

%.o: %.cpp
	$(CXX) $(COMPILE_FLAGS) -o $@ -c $<

%.o: %.c
	$(CC) $(C_COMPILE_FLAGS) -o $@ -c $<


$(EXECUTABLE): $(OBJS)
	$(CXX) -o $(EXECUTABLE) $(OBJS) $(LINK_FLAGS) -lpthread -lboost_thread -lboost_program_options -lboost_system -lrote -lncurses

%.d: %.cc
	$(CXX) -MM -MG -MT $@ -MT $(<:%.cc=%.o) $(CPP_FLAGS) $(GCC_FLAGS) -o $@ $<

%.d: %.cpp
	$(CXX) -MM -MG -MT $@ -MT $(<:%.cc=%.o) $(CPP_FLAGS) $(GCC_FLAGS) -o $@ $<

%.d: %.c
	$(CC) -MM -MG -MT $@ -MT $(<:%.c=%.o) $(CPP_FLAGS) $(GCC_FLAGS) -o $@ $<

DEPENDS=$(addsuffix .d,$(basename $(OBJS)))

-include $(DEPENDS)

clean: FORCE
	$(RM) -f *.o

veryclean: clean
	$(RM) -f *.d


.PHONY: default_target compile install FORCE
