 # $Id$
 #
 # This file is part of the RHexLib Robot Control Software
 #
 #  The contents of this file are subject to the RHexLib Public
 # License Version 2.0 (the "License"); you may not use this file
 # except in compliance with the License. To obtain a copy of the
 # License, please contact <ulucs+rhexlib@cs.cmu.edu>.
 #
 #  Software distributed under the License is distributed on an "AS
 # IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
 # implied. See the License for the specific language governing
 # rights and limitations under the License.
 #
 #  The Original Code is RHexLib Robot Control Software.
 #
 #  The Initial Developer of the Original Code is
 #    Carnegie Mellon University
 #
 #  Portions created by 
 #    Carnegie Mellon University
 #  are Copyright (C) 2003.  All Rights Reserved.
 #
 #  Contributor(s): Uluc Saranli.
 #
 #  Alternatively, the contents of this file may be used under the
 # terms of the GNU Public license (the "GPL License"), in which
 # case the provisions of the GNU Public License are applicable
 # instead of those above.  If you wish to allow use of your version
 # of this file only under the terms of the GPL License and not to
 # allow others to use your version of this file under the RHexLib
 # Public License, indicate your decision by deleting the provisions
 # above and replace them with the notice and other provisions
 # required by the GPL License.  If you do not delete the provisions
 # above, a recipient may use your version of this file under either
 # the RHexLib Public License or the GPL License."
 #
 # Uluc Saranli <ulucs+rhexlib@cs.cmu.edu>

# First, check whether we can access the RHexLib directory.
ifndef RHEX_DIR
$(error RHEX_DIR environment variable is not defined!)
endif

ifneq ($(MAKECMDGOALS),clean)
ifndef FLTK_DIR
$(error FLTK_DIR environment variable is not defined!)
endif
endif

SIMPLEGUI_FILES = LogIntf
LARGEGUI_FILES = BigIntf
COMMON_FILES = loggui LoggerGUI SessionIntf SessionGUI

DEPLIBS = \
	$(RHEX_DIR)/lib/libclient.a \
	$(RHEX_DIR)/lib/libbase.a \
	$(RHEX_DIR)/lib/libutils.a

TARGETS = loggui loggui_simple

LIBS = $(patsubst lib%.a, -l%, $(notdir $(DEPLIBS))) \
	-lfltk -lXext -lX11 -lpthread

CPPFLAGS = \
	-I$(RHEX_DIR)/include \
	-I$(FLTK_DIR)/include \
	 -D_XOPEN_SOURCE=500 

CXXFLAGS = -c -Wall -g

OBJS = $(foreach file,$(COMMON_FILES), $(file).o) 
SRCS = $(foreach file,$(COMMON_FILES), $(file).cc)
SIMPLEGUI_OBJS = $(foreach file,$(SIMPLEGUI_FILES), $(file).o) 
SIMPLEGUI_SRCS = $(foreach file,$(SIMPLEGUI_FILES), $(file).cc)
LARGEGUI_OBJS = $(foreach file,$(LARGEGUI_FILES), $(file).o) 
LARGEGUI_SRCS = $(foreach file,$(LARGEGUI_FILES), $(file).cc)

LDFLAGS = -L$(RHEX_DIR)/lib -L$(FLTK_DIR)/lib -L/usr/X11R6/lib

all: $(TARGETS)

loggui: $(OBJS) $(LARGEGUI_OBJS) $(DEPLIBS)
	$(CXX) -o $@ $(OBJS) $(LARGEGUI_OBJS) $(LDFLAGS) $(LIBS)

loggui_simple: $(OBJS) $(SIMPLEGUI_OBJS) $(DEPLIBS)
	$(CXX) -o $@ $(OBJS) $(SIMPLEGUI_OBJS) $(LDFLAGS) $(LIBS)

clean:
	@rm -rf $(TARGETS) *.o *.d *~ .deps

### Dependencies
.deps/%.d:: %.cc
	@mkdir -p -m 775 .deps
	@echo Finding dependencies for $<
	@$(SHELL) -ec '$(CXX) -M $(CPPFLAGS) $< \
	              | sed '\''s~\($*\.o\)[ :]*~\1 $@ : ~g'\'' > $@ '

ifneq ($(MAKECMDGOALS),clean)

-include $(patsubst %.cc,.deps/%.d,$(SRCS))

endif
