PREFIX = /usr


# All programs
#
ALL_PROGS = devices helloworld history lsmimetypes		\
            mimetypeinstall notify open params properties	\
            purge recover recycle rls

# Include directories
#
INC_DIRS =


# Compiler flags
#
CFLAGS   = -Wall -O2 -g `glib-config --cflags` `endeavour2-config --cflags`
CPPFLAGS = -D__cplusplus -Dc_plusplus


# Libraries
#
LIBS = `glib-config --libs` `endeavour2-config --libs`
LIB_DIRS =


# Compilers
#
CC = cc
CPP = c++


# Programs and their flags
#
MKDIR      = mkdir
MKDIRFLAGS = -p -m 0755

LINK      = ln
LINKFLAGS = -s -f

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

RM      = rm
RMFLAGS = -f

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


# Compile time information export:
#
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"


# Rules:
#
all: config $(ALL_PROGS)

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

# Echo rule note: Do not hide the output of the compiler command and
# arguments because we want the user to see them in order to demosrate
# what the compiler command line should look like for compiling these
# programs.

devices:
	@echo "Compiling devices"
	$(CC) $(CFLAGS) $(INC_DIRS) $(LIBS) $(LIB_DIRS) \
        devices.c -o devices

helloworld:
	@echo "Compiling helloworld"
	$(CC) $(CFLAGS) $(INC_DIRS) $(LIBS) $(LIB_DIRS) \
	helloworld.c -o helloworld

history:
	@echo "Compiling history"
	$(CC) $(CFLAGS) $(INC_DIRS) $(LIBS) $(LIB_DIRS) \
        history.c -o history

lsmimetypes:
	@echo "Compiling lsmimetypes"
	$(CC) $(CFLAGS) $(INC_DIRS) $(LIBS) $(LIB_DIRS) \
	lsmimetypes.c -o lsmimetypes

mimetypeinstall:
	@echo "Compiling mimetypeinstall"
	$(CC) $(CFLAGS) $(INC_DIRS) $(LIBS) $(LIB_DIRS) \
        mimetypeinstall.c -o mimetypeinstall

notify:
	@echo "Compiling notify"
	$(CC) $(CFLAGS) $(INC_DIRS) $(LIBS) $(LIB_DIRS) \
	notify.c -o notify

open:
	@echo "Compiling open"
	$(CC) $(CFLAGS) $(INC_DIRS) $(LIBS) $(LIB_DIRS) \
	open.c -o open

params:
	@echo "Compiling params"
	$(CC) $(CFLAGS) $(INC_DIRS) $(LIBS) $(LIB_DIRS) \
	params.c -o params

properties:
	@echo "Compiling properties"
	$(CC) $(CFLAGS) $(INC_DIRS) $(LIBS) $(LIB_DIRS) \
	properties.c -o properties

purge:
	@echo "Compiling purge"
	$(CC) $(CFLAGS) $(INC_DIRS) $(LIBS) $(LIB_DIRS) \
	purge.c -o purge

recover:
	@echo "Compiling recover"
	$(CC) $(CFLAGS) $(INC_DIRS) $(LIBS) $(LIB_DIRS) \
	recover.c -o recover

recycle:
	@echo "Compiling recycle"
	$(CC) $(CFLAGS) $(INC_DIRS) $(LIBS) $(LIB_DIRS) \
	recycle.c -o recycle

rls:
	@echo "Compiling rls"
	$(CC) $(CFLAGS) $(INC_DIRS) $(LIBS) $(LIB_DIRS) \
	rls.c -o rls

HR = "-------------------------------------------------------------------------"

install: preinstall install_demos postinstall

install_demos:
	@for prog in $(ALL_PROGS); 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 " "

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