PREFIX = /usr

# Uncomment only one of the following CFLAGS lines.
# You can remove -DINCLUDE_IV_TITLE_IMAGE if you do not want to compile
# in the title image (about + 150 kb in size).

# Optimized with Imlib
CFLAGS = -Wall -O6 -fomit-frame-pointer -funroll-loops		\
         -finline-functions -ffast-math				\
         -DHAVE_LIBPNG						\
         -DHAVE_IMLIB `imlib-config --cflags`			\
         `gtk-config --cflags`					\
         -DINCLUDE_IV_TITLE_IMAGE

# For debugging
#CFLAGS = -Wall -O -g \
#         -DHAVE_LIBPNG -DHAVE_IMLIB `gtk-config --cflags` \
#         -DINCLUDE_IV_TITLE_IMAGE


INC_DIRS =

LIBS = -lpng `imlib-config --libs` `gtk-config --libs`

LIB_DIRS =  -L/usr/X11R6/lib/

# Compiler:
CC = cc
CPP = c++

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

# Source files list:
include Makefile.srclist

# Compiler set up:
BIN     = iv
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 | 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\
\#endif\t/* COMPILETIMEINFO_H */\n"

$(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) $(LIBS) $(LIB_DIRS)
	@echo -n "   "
	@-$(LS) $(LSFLAGS) $(BIN)

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

postbuild:
	@echo "Build done."
	@echo "To install, type \"su\" (to gain root privileges) and then type \"make install\"."

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."
