#  
# Makefile for Brutus test/sample code.
# Copyright (C) 2004-2007 OMC Denmark ApS.
# 
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# 
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.


# Directories
IDL_OUTPUT_DIR := $(shell pwd)

# Compilation directives
ifndef TOP_INVOKED
    CC := gcc
    OPT = -Os
    DEBUG := -g -O0
    CFLAGS := -Wall -DORBIT2=1 -D_REENTRANT $(DEBUG) 
    IDL_ROOT := $(shell pwd)/../../..
    INCLUDE := -I$./ -I$(shell pwd)/../idl_output -I$(shell pwd)/.. -I/usr/include/orbit-2.0 -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include 
    ORBIT_IDL := orbit-idl-2
endif
DEPS := deps

ORBIT_IDLFLAGS := --showcpperrors  --onlytop --skeleton-impl --output-dir=$(IDL_OUTPUT_DIR) --headerguardprefix=_BRUTUS_

IDL_FILES := $(IDL_ROOT)/types.idl \
             $(IDL_ROOT)/BrutusCheck.idl \
             $(IDL_ROOT)/IMAPIAdviseSink.idl \
             $(IDL_ROOT)/IMAPIProgress.idl

# Get IDL file names without directory prefix
BARE_NAMES := $(notdir $(IDL_FILES))

# IDL compiler generated header files
IDL_HEADERS :=  $(BARE_NAMES:.idl=.h)

# Get names of *-common.c files
COMMON_SOURCES := $(BARE_NAMES:.idl=-common.c)

# Get names of *-skels.c files
SKEL_SOURCES := $(BARE_NAMES:.idl=-skels.c)

# Get names of *_impl.c files
IMPL_SOURCES := $(BARE_NAMES:.idl=_impl.c)

# Get skeleton objects
COMMON_OBJS := $(COMMON_SOURCES:.c=.o)

# Get skeleton objects
SKEL_OBJS := $(SKEL_SOURCES:.c=.o)

# Get implementation objects
IMPL_OBJS := $(BARE_NAMES:.idl=_impl.o)

# All sources and objects
SOURCES := $(COMMON_SOURCES) $(SKEL_SOURCES) $(IMPL_SOURCES) servant_utils.c
OBJS := $(COMMON_OBJS) $(SKEL_OBJS) $(IMPL_OBJS) servant_utils.o


all: depend $(OBJS)

stubs: very_clean idl

.c.o:
	$(CC) $(CFLAGS) $(INCLUDE) -c $<

idl: $(IDL_FILES)
	@echo
	@for file in $(IDL_FILES); do \
		(echo Compiling $$file ; cd $(IDL_ROOT) && $(ORBIT_IDL) $(ORBIT_IDLFLAGS) $$file); \
	done

depend :
	$(CC) -MM -E $(INCLUDE)  $(SOURCES)> $(DEPS)

clean:
	-rm -f $(OBJS) *~ 

very_clean:
	-rm -f $(OBJS) $(IDL_HEADERS) $(IDL_OUTPUT_DIR)/*-stubs.* $(IDL_OUTPUT_DIR)/*-skels.* $(IDL_OUTPUT_DIR)/*-common.* $(IDL_OUTPUT_DIR)/*-skelimpl.* *~ 


.PHONY: all stubs idl depend clean very_clean

sinclude $(DEPS)


