# Makefile                bmon Makefile
#
# Copyright (c) 2001-2005 Thomas Graf <tgraf@suug.ch>
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"),
# to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.
#
ifeq ($(shell [ ! -r ../Makefile.opts ] && echo 1),)
    include ../Makefile.opts
endif

# Core
CORE := utils.c input.c output.c conf.c node.c item.c graph.c
CORE += signal.c bindings.c itemtab.c attr.c unit.c group.c
CORE += pipe.c

CIN := bmon.c $(CORE)

# Primary input modules
CIN  += in_null.c in_dummy.c in_netlink.c in_proc.c in_sysfs.c in_netstat.c
#CIN  += in_sysctl.c in_distribution.c in_kstat.c

# Primary output modules
CIN  += out_null.c out_ascii.c out_format.c

# Secondary output module
#CIN  += out_distribution.c
CIN  += out_html.c out_xml_event.c out_xml_state.c

ifeq ($(CURSES),Yes)
CIN  += out_curses.c
endif

#ifeq ($(RRD),Yes)
#CIN  += out_rrd.c
#endif

ifeq ($(ASOUND),Yes)
CIN  += out_audio.c
endif

#ifeq ($(PQ),Yes)
#CIN  += db.c out_db.c in_db.c
#YACCIN := db_filter.y
#LEXIN := db_filter.l
#endif

YACCOUT := $(YACCIN:%.y=%.yacc.c)
LEXOUT := $(LEXIN:%.l=%.lex.c)
CFYIN := $(YACCOUT) $(LEXOUT) $(CIN)
OBJ  := $(CFYIN:%.c=%.o)
OUT  := bmon

ifeq ($(PQ),Yes)
BMONDB_CIN := $(CORE) bmondb.c db.c $(YACCOUT) $(LEXOUT)
BMONDB_OBJ := $(BMONDB_CIN:%.c=%.o)
endif
BMONDB_OUT := bmondb

DEPS := $(CFYIN:%.c=.deps/%.d) $(BMONDB_CIN:%.c=.deps/%.d)

export

.PHONY: all clean install $(OUT)

#all: $(OUT) $(BMONDB_OUT)
all: $(OUT)

$(OUT): ../Makefile.opts $(OBJ)
	@echo "  LD $(OUT)"; \
	$(CC) $(CFLAGS) $(CPPFLAGS) -o $(OUT) $(OBJ) $(LDFLAGS) $(BMON_LIB)

ifeq ($(PQ),Yes)
$(BMONDB_OUT): ../Makefile.opts $(BMONDB_OBJ)
	@echo "  LD $(BMONDB_OUT)"; \
	$(CC) $(CFLAGS) $(CPPFLAGS) -o $(BMONDB_OUT) $(BMONDB_OBJ) $(BMONDB_LIB) -lpq -lm
else
$(BMONDB_OUT):
endif

clean:
	@echo "  CLEAN src"; \
	$(RM) -f $(OBJ) $(OUT) $(YACCOUT) $(LEXOUT) db_filter.yacc.h db_filter.yacc.output

distclean:
	@echo "  DISTCLEAN src"; \
	$(RM) -f .deps/*

$(DEPS): ../Makefile.opts $(YACCOUT) $(LEXOUT)

include ../Makefile.rules

