PREFIX = /usr

CFLAGS = -Wall -g -O2

INC_DIRS =

LIBS = -lm `glib-config --libs`
LIB_DIRS =

CC = cc
CPP = c++

CPPFLAGS = -D__cplusplus -Dc_plusplus

OBJ_C   = $(SRC_C:.c=.o)
OBJ_CPP = $(SRC_CPP:.cpp=.o)

# Programs
#
LS           = ls
LSFLAGS      = -a -l
COPY         = cp
COPYFLAGS    = -R -f
MOVE         = mv
MOVEFLAGS    = -R -f
MKDIR        = mkdir
MKDIRFLAGS   = -p -m 0755
RM           = rm
RMFLAGS      = -f
INSTALL      = install
INSTBINFLAGS = -m 0755 -s


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


# Build List
#
BUILD_LIST = confirmation_dialog style_editor


# Compile Time Info
#
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"


# Build Rules
#
all: pre_build config $(BUILD_LIST) post_build

pre_build:
	@echo "Building utilities..."

post_build:
	@echo "Build done."

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

confirmation_dialog:
	@echo "Compiling confirmation_dialog"
	@$(CC) -c $(CFLAGS) `gtk-config --cflags` \
        confirmation_dialog.c
	@$(CPP) `gtk-config --libs` \
        confirmation_dialog.o \
	../guiutils.o ../cdialog.o ../string.o ../fio.o \
        -o confirmation_dialog

style_editor:
	@echo "Compiling style_editor"
	@$(CC) -c $(CFLAGS) `gtk-config --cflags` \
        style_editor.c
	@$(CPP) `gtk-config --libs` \
        style_editor.o \
        ../guiutils.o ../cdialog.o ../fprompt.o ../pulist.o \
        ../fb.o ../csd.o ../fsd.o ../styleedit.o \
        ../string.o ../strexp.o ../fio.o ../disk.o \
        -o style_editor


# Install
#
INSTALL      = install
INSTBINFLAGS = -m 0755 -s
INSTUIDFLAGS = -m 4755
INSTLIBFLAGS = -m 0755 -s
INSTINCFLAGS = -m 0644
INSTMANFLAGS = -m 0644
INSTCFGFLAGS = -m 0644
INSTDATFLAGS = -m 0644

install: pre_install install_bin install_data post_install

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

pre_install:

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

install_data:

post_install:
	@echo "Install done."
	@echo $(HR)
	@echo "Utilities installed in:"
	@echo " "
	@echo "        $(EDV_BIN_DIR)"
	@echo " "
	@echo $(HR)
	@echo " "


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