update makefile, add install target

This commit is contained in:
Olaf Rempel 2009-01-11 22:49:02 +01:00
parent c008c25e10
commit b6363621ab
4 changed files with 68 additions and 48 deletions

View File

@ -4,10 +4,20 @@ WITH_RRD=yes
PLUGINS := ctstat diskstat load memory mount netdev random rtstat stat uptime vmstat PLUGINS := ctstat diskstat load memory mount netdev random rtstat stat uptime vmstat
PLUGINS += apache mysql conntrack PLUGINS += apache mysql conntrack
DESTDIR = /tmp
BINARY_DIR = /usr/local/bin
CONFIG_DIR = /usr/local/etc
PLUGIN_DIR = /usr/local/lib/sammler
DATA_DIR = /var/lib/sammler
LOG_DIR = /var/log
WWW_DIR = /var/www
WWW_CONFIG = $(WWW_DIR)/sammler_graph.conf
WWW_OWNER = www-data
# ############################ # ############################
SAMMLER_SRC := sammler.c configfile.c event.c helper.c logging.c network.c plugins.c probe.c SAMMLER_SRC := sammler.c configfile.c event.c helper.c logging.c network.c plugins.c probe.c
CFLAGS := -O2 -Wall -fno-stack-protector -Iinclude CFLAGS := -O2 -Wall -MMD -fno-stack-protector -Iinclude
LDFLAGS := -ldl -rdynamic LDFLAGS := -ldl -rdynamic
# ############################ # ############################
@ -20,20 +30,59 @@ endif
# ############################ # ############################
all: sammler all: sammler plugins
make -C plugins PLUGINS="$(PLUGINS)"
sammler: $(SAMMLER_SRC:%.c=%.o) sammler: $(SAMMLER_SRC:%.c=%.o)
$(CC) $(LDFLAGS) $^ -o $@ @echo " Linking file: $@"
@$(CC) $(LDFLAGS) $^ -o $@
%.d: %.c
$(CC) $(CFLAGS) -MM -c $< -o $@
%.o: %.c %.o: %.c
$(CC) $(CFLAGS) -o $@ -c $< @echo " Building file: $<"
@$(CC) $(CFLAGS) -o $@ -c $<
.PHONY: plugins
plugins: $(PLUGINS:%=plugins/%.o) $(PLUGINS:%=plugins/%.so)
plugins/%.so: plugins/%.o
@echo " Linking file: $@"
@$(CC) $(LDFLAGS) -shared -o $@ $<
plugins/apache.so: plugins/apache.o
@echo " Linking file: $@"
@$(CC) $(LDFLAGS) -shared -o -lcurl -o $@ $<
plugins/conntrack.so: plugins/conntrack.o
@echo " Linking file: $@"
@$(CC) $(LDFLAGS) -shared -o -lnfnetlink -lnetfilter_conntrack -o $@ $<
plugins/mysql.so: plugins/mysql.o plugins/mysql_helper.o
@echo " Linking file: $@"
@$(CC) $(LDFLAGS) -shared -o -lmysqlclient -o $@ $<
install: all
install -D -m 755 -s sammler $(DESTDIR)$(BINARY_DIR)/sammler
install -D -m 644 sammler.conf $(DESTDIR)$(CONFIG_DIR)/sammler.conf
sed -i -e "s:^logfile .*$$:logfile $(LOG_DIR)/sammler.log:" \
-e "s:^rrd_dir .*$$:rrd_dir $(DATA_DIR):" \
-e "s:^plugin_dir .*$$:plugin_dir $(PLUGIN_DIR):" \
$(DESTDIR)$(CONFIG_DIR)/sammler.conf
install -d -m 755 $(DESTDIR)$(PLUGIN_DIR)
install -m 755 -s plugins/*.so $(DESTDIR)$(PLUGIN_DIR)
install -d -m 755 $(DESTDIR)$(DATA_DIR) $(DESTDIR)$(LOG_DIR)
ifeq ("$(WITH_RRD)", "yes")
install -D -m 644 sammler.php $(DESTDIR)$(WWW_DIR)/sammler.php
sed -i -e "s:%%WWW_CONFIG%%:$(WWW_CONFIG):" \
-e "s:%%DATA_DIR%%:$(DATA_DIR):" \
$(DESTDIR)$(WWW_DIR)/sammler.php
-install -D -m 644 -o $(WWW_OWNER) /dev/null $(DESTDIR)$(WWW_CONFIG)
else
sed -i -e "s:^forward_only .*$$:forward_only true:" \
$(DESTDIR)$(CONFIG_DIR)/sammler.conf
endif
clean: clean:
rm -rf *.d *.o sammler rm -rf *.d plugins/*.d *.o plugins/*.o plugins/*.so sammler
make -C plugins clean
-include $(SAMMLER_SRC:%.c=%.d) include $(shell find . -name \*.d 2> /dev/null)

View File

@ -1,29 +0,0 @@
CFLAGS := -O2 -Wall -fno-stack-protector -I../include
LDFLAGS := -ldl -rdynamic
# ############################
all: $(PLUGINS:%=%.so)
%.d: %.c
$(CC) $(CFLAGS) -MM -c $< -o $@
%.o: %.c
$(CC) $(CFLAGS) -fPIC -o $@ -c $<
apache.so: apache.o
$(LD) -shared -lcurl -o $@ $^
conntrack.so: conntrack.o
$(LD) -shared -lnfnetlink -lnetfilter_conntrack -o $@ $^
mysql.so: mysql.o mysql_helper.o
$(LD) -shared -lmysqlclient -o $@ $^
%.so: %.o
$(LD) -shared -o $@ $<
clean:
rm -rf *.d *.o *.so
-include $(PLUGINS:%=%.d)

View File

@ -1,9 +1,9 @@
[global] [global]
hostname localhost hostname localhost
listen 127.0.0.1:5000 #listen 127.0.0.1:5000
forward 127.0.0.1:5000 #forward 127.0.0.1:5000
forward_only true forward_only false
logfile sammler.log logfile sammler.log
@ -21,9 +21,9 @@ plugin diskstat.so
plugin ctstat.so plugin ctstat.so
plugin rtstat.so plugin rtstat.so
plugin random.so plugin random.so
plugin mysql.so #plugin mysql.so
plugin apache.so #plugin apache.so
plugin conntrack.so #plugin conntrack.so
# 1h(10s), 12h(1min), 48h(2min), 14d(15min), 4w(60min), 2y(12h) # 1h(10s), 12h(1min), 48h(2min), 14d(15min), 4w(60min), 2y(12h)
rra RRA:MIN:0.5:1:360 RRA:AVERAGE:0.5:1:360 RRA:MAX:0.5:1:360 rra RRA:MIN:0.5:1:360 RRA:AVERAGE:0.5:1:360 RRA:MAX:0.5:1:360

View File

@ -1,7 +1,7 @@
<?php <?php
define('CONFIG', 'sammler_graph.conf'); define('CONFIG', '%%WWW_CONFIG%%');
define('BASE_DIR', '/var/lib/rrd/'); define('BASE_DIR', '%%DATA_DIR%%');
define('RRDTOOL', '/usr/bin/rrdtool'); define('RRDTOOL', '/usr/bin/rrdtool');
function setup_html($conf) { function setup_html($conf) {