#                   Endeavour Mark II - Makefile
#

# Include the Platform Configurator (pconf) Makefile to get
# platform-specific values; PREFIX, CFLAGS, INC_DIGS, LIBS, and
# LIBDIRS:
#
include Makefile.pconf


# C++ flags:
#
CPPFLAGS        = -D__cplusplus -Dc_plusplus


# Compilers:
#
CC	= cc
CPP	= c++


# Programs:
#
LS	= ls
LSFLAGS	= -s -h -c --color=auto
RM	= rm
RMFLAGS	= -f


# Source Files List:
#
include Makefile.srclist


# Compile Time Information Output:
#
EXPORT_COMPILETIMEINFO_H = /bin/echo -n -e "\
\#ifndef COMPILETIMEINFO_H\n\
\#define COMPILETIMEINFO_H\n\
\#define COMPILE_COMPILER\t\"`$(CPP) --version | tr '\n' ' '`\"\n\
\#define COMPILE_USER\t\t\"$(USER)\"\n\
\#define COMPILE_LOCATION\t\"`uname -n`\"\n\
\#define COMPILE_DATE\t\t`date +\"%s\"`\n\
\n\
\#ifndef IMLIB_VERSION\n\
\# define IMLIB_VERSION\t\t\"`imlib-config --version`\"\n\
\#endif\n\
\n\
\#endif\t/* COMPILETIMEINFO_H */\n"


# Build Rules:
#
BIN	= endeavour2
OBJ_C	= $(SRC_C:.c=.o)
OBJ_CPP	= $(SRC_CPP:.cpp=.o)
.c.o:
	@echo "Compiling module $*.o"
	@+$(CC) -c $*.c $(INC_DIRS) $(CFLAGS)
.cpp.o:
	@echo "Compiling module $*.o"
	@+$(CPP) -c $*.cpp $(INC_DIRS) $(CFLAGS) $(CPPFLAGS)


$(BIN): prebuild config modules postbuild

config:
	@echo "Compiling resources"
	@$(EXPORT_COMPILETIMEINFO_H) > compiletimeinfo.h

modules: $(OBJ_C) $(OBJ_CPP)
	@echo -n "Linking modules..."
	@$(CPP) $(OBJ_C) $(OBJ_CPP) -o $(BIN) $(LIB_DIRS) $(LIBS)
	@echo -n "   "
	@-$(LS) $(LSFLAGS) $(BIN)

prebuild:
	@echo "Building program \"$(BIN)\"..."

postbuild:
	@echo "Build done."

all: $(BIN)


# Install Rules:
#
include Makefile.install.UNIX


# Clean Rule:
#
clean:
	@echo "Cleaning program \"$(BIN)\"..."
	@echo "Deleting all intermediate files..."
	@$(RM) $(RMFLAGS) a.out core *.o compiletimeinfo.h $(BIN)
	@echo "Clean done."
