-
Notifications
You must be signed in to change notification settings - Fork 31
/
Makefile
110 lines (91 loc) · 2.51 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#
# Makefile
#
# Copyright (C) 2010 Creytiv.com
#
# Input variables:
#
# USE_MYSQL If non-empty, build mysql_ser client module
#
VER_MAJOR := 0
VER_MINOR := 4
VER_PATCH := 2
PROJECT := restund
VERSION := $(VER_MAJOR).$(VER_MINOR).$(VER_PATCH)
MODULES := binding auth turn stat status influxdb cpuusage
MODULES += $(EXTRA_MODULES)
LIBRE_MK := $(shell [ -f ../re/mk/re.mk ] && \
echo "../re/mk/re.mk")
ifeq ($(LIBRE_MK),)
LIBRE_MK := $(shell [ -f /usr/share/re/re.mk ] && \
echo "/usr/share/re/re.mk")
endif
ifeq ($(LIBRE_MK),)
LIBRE_MK := $(shell [ -f /usr/local/share/re/re.mk ] && \
echo "/usr/local/share/re/re.mk")
endif
include $(LIBRE_MK)
# Optional syslog module
ifneq ($(OS),win32)
USE_SYSLOG := 1
endif
ifneq ($(USE_SYSLOG),)
MODULES += syslog
endif
# Optional MySQL client module
USE_MYSQL := $(shell [ -f $(SYSROOT)/include/mysql/mysql.h ] || \
[ -f $(SYSROOT)/local/include/mysql/mysql.h ] || \
[ -f $(SYSROOT_ALT)/include/mysql/mysql.h ] || \
[ -f $(SYSROOT_ALT)/include/mysql5/mysql/mysql.h ] && echo "1")
ifneq ($(USE_MYSQL),)
MODULES += mysql_ser
endif
INSTALL := install
ifeq ($(DESTDIR),)
PREFIX := /usr/local
else
PREFIX := /usr
endif
SBINDIR := $(PREFIX)/sbin
DATADIR := $(PREFIX)/share
ifeq ($(LIBDIR),)
LIBDIR := $(PREFIX)/lib
endif
MOD_PATH:= $(LIBDIR)/$(PROJECT)/modules
CFLAGS += -I$(LIBRE_INC) -Iinclude -std=gnu99
BIN := $(PROJECT)$(BIN_SUFFIX)
MOD_BINS:= $(patsubst %,%.so,$(MODULES))
APP_MK := src/srcs.mk
MOD_MK := $(patsubst %,modules/%/module.mk,$(MODULES))
MOD_BLD := $(patsubst %,$(BUILD)/modules/%,$(MODULES))
include $(APP_MK)
include $(MOD_MK)
OBJS ?= $(patsubst %.c,$(BUILD)/src/%.o,$(SRCS))
all: $(MOD_BINS) $(BIN)
-include $(OBJS:.o=.d)
# GPROF requires static linking
$(BIN): $(OBJS)
@echo " LD $@"
ifneq ($(GPROF),)
@$(LD) $(LFLAGS) $(APP_LFLAGS) $^ ../re/libre.a $(LIBS) -o $@
else
@$(LD) $(LFLAGS) $(APP_LFLAGS) $^ -L$(LIBRE_SO) -lre $(LIBS) -o $@
endif
$(BUILD)/%.o: %.c $(BUILD) Makefile $(APP_MK)
@echo " CC $@"
@$(CC) $(CFLAGS) -o $@ -c $< $(DFLAGS)
$(BUILD): Makefile
@mkdir -p $(BUILD)/src $(MOD_BLD)
@touch $@
clean:
@rm -rf $(BIN) $(MOD_BINS) $(BUILD)/
install: $(BIN) $(MOD_BINS)
@mkdir -p $(DESTDIR)$(SBINDIR)
$(INSTALL) -m 0755 $(BIN) $(DESTDIR)$(SBINDIR)
@mkdir -p $(DESTDIR)$(MOD_PATH)
$(INSTALL) -m 0644 $(MOD_BINS) $(DESTDIR)$(MOD_PATH)
@mkdir -p $(DESTDIR)$(DATADIR)/munin/plugins
$(INSTALL) -m 0755 etc/munin/* $(DESTDIR)$(DATADIR)/munin/plugins
config:
@mkdir -p $(DESTDIR)/etc
$(INSTALL) -m 0644 etc/restund.conf $(DESTDIR)/etc/.