PREFIX = /usr
BIN    = avscan

CFLAGS = -Wall -O2 -g -ffast-math 				\
         -DPREFIX="\"/usr\""					\
         -DNEED_STRCASESTR					\
         -DHAVE_CLAMAV						\
         `clamav-config --cflags`				\
         `gtk-config --cflags`					\
         -DHAVE_EDV2 `endeavour2-config --cflags`

INC_DIRS =

LIBS = `clamav-config --libs` -lclamav				\
       `gtk-config --libs`					\
       `endeavour2-config --libs`
LIB_DIRS =

CC = cc
CPP = c++

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

# Source files list:
include Makefile.srclist

# Compiler set up:
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\
\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."

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