# Prefix:
PREFIX = /usr

# Compiler flags:
CFLAGS = -Wall -O2 -g				\
         -DNEED_STRCASESTR			\
         `gtk-config --cflags`

# Include directory:
INC_DIRS =

# Libraries:
LIBS = -lm `gtk-config --libs`
LIB_DIRS =

# Compiler:
CC = cc
CPP = c++

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

# Source files list:
include Makefile.srclist

# Compiler set up:
BIN     = tedit
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)

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

# Build rules:
EXPORT_COMPILETIMEINFO_H = echo -n -e "\
\#ifndef COMPILETIMEINFO_H\n\
\#define COMPILETIMEINFO_H\n\
\#define COMPILE_COMPILER\t\"`$(CPP) --version`\"\n\
\#define COMPILE_USER\t\t\"$(USER)\"\n\
\#define COMPILE_LOCATION\t\"`uname -n`\"\n\
\#define COMPILE_DATE\t\t`date +\"%s\"`\n\
\#endif\t/* COMPILETIMEINFO_H */\n"

$(BIN): config prebuild modules postbuild

config:
	@$(EXPORT_COMPILETIMEINFO_H) > compiletimeinfo.h

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

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

postbuild:
	@echo "Build done."

all: $(BIN)


# Install Rules:
include Makefile.install.UNIX


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