# Programs List:
#
# Space-separated list of all the demo program names.
#
PROGRAMS_LIST = devices edv_date edv_dir helloworld history	\
                message mls mime_type_install notify open	\
                params properties purge recover recycle rls uls	\
                window

# Locations:
#
PREFIX		= /usr
EDV_BIN_DIR	= $(PREFIX)/lib/endeavour2/bin


# Compiler Flags:
#
CFLAGS	= -Wall -O2 -g
CFLAGS	+= `glib-config --cflags`
CFLAGS	+= `endeavour2-base-config --cflags`

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


# Include Directories:
#
INC_DIRS	=


# Libraries & Library Directories:
#
LIBS		= `glib-config --libs`
LIBS		+= `endeavour2-base-config --libs`
LIB_DIRS	=


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


# Programs:
#
LS		= ls
LSFLAGS		= -s -h -c --color=auto

MKDIR		= mkdir
MKDIRFLAGS	= -p -m 0755

LINK		= ln
LINKFLAGS	= -s -f

INSTALL		= install
INSTBINFLAGS	= -m 0755 -s
INSTINCFLAGS	= -m 0644

RM		= rm
RMFLAGS		= -f


# 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\
\#endif\t/* COMPILETIMEINFO_H */\n"


# Build Rules:
#
.c:
	@echo "Compiling $*"
	$(CC) $*.c $(CFLAGS) $(INC_DIRS) $(LIBS) $(LIB_DIRS) -o $*

all: config $(PROGRAMS_LIST) object_info_gtk

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

object_info_gtk:
	@echo "Compiling $(@)"
	$(CC) $(@).c $(CFLAGS) $(INC_DIRS) $(LIBS) $(LIB_DIRS) \
        `gtk-config --cflags --libs` -o $(@)


# Install Rules:
#
HR = "-------------------------------------------------------------------------"

install: preinstall install_demos postinstall

install_demos:
	@for prog in $(PROGRAMS_LIST); do \
            echo "Installing $$prog -> $(EDV_BIN_DIR)"; \
	    $(INSTALL) $(INSTBINFLAGS) $$prog $(EDV_BIN_DIR); \
	done

preinstall:
	@echo "Installing demos -> $(EDV_BIN_DIR)"

postinstall:
	@echo "Install done."
	@echo $(HR)
	@echo "Demo programs installed in:"
	@echo " "
	@echo "        $(EDV_BIN_DIR)"
	@echo " "
	@echo $(HR)
	@echo " "


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