]> git.stg.codes - stg.git/blob - projects/stargazer/Makefile
Implemented daily fee charge with backward compatibility.
[stg.git] / projects / stargazer / Makefile
1 ###############################################################################
2 # $Id: Makefile,v 1.50 2010/10/07 18:27:27 faust Exp $
3 ###############################################################################
4
5 include ../../Makefile.conf
6
7 PROG = stargazer
8
9 SRCS = ./admin_impl.cpp \
10        ./admins_impl.cpp \
11        ./corps_impl.cpp \
12        ./eventloop.cpp \
13        ./main.cpp \
14        ./pidfile.cpp \
15        ./plugin_runner.cpp \
16        ./settings_impl.cpp \
17        ./services_impl.cpp \
18        ./stg_timer.cpp \
19        ./store_loader.cpp \
20        ./tariff_impl.cpp \
21        ./tariffs_impl.cpp \
22        ./traffcounter_impl.cpp \
23        ./user_impl.cpp \
24        ./user_property.cpp \
25        ./users_impl.cpp
26
27 STGLIBS = scriptexecuter \
28           dotconfpp \
29           locker \
30           logger \
31           common
32
33 STGLIBS_INCS = $(addprefix -I ../../stglibs/,$(addsuffix .lib/include,$(STGLIBS)))
34 STGLIBS_LIBS = $(addprefix -L ../../stglibs/,$(addsuffix .lib,$(STGLIBS)))
35
36 LIBS += $(addprefix -lstg,$(STGLIBS)) $(LIB_THREAD)
37
38 ifeq ($(OS),linux)
39 LIBS += -ldl
40 else
41 LIBS += -lc -liconv
42 endif
43
44 SEARCH_DIRS = -I ../../include
45
46 OBJS = $(notdir $(patsubst %.cpp, %.o, $(patsubst %.c, %.o, $(SRCS))))
47
48 CXXFLAGS += $(DEFS) $(STGLIBS_INCS) $(SEARCH_DIRS)
49 CFLAGS += $(DEFS) $(STGLIBS_INCS) $(SEARCH_DIRS)
50 LDFLAGS += -Wl,-E $(STGLIBS_LIBS)
51
52 .PHONY: all clean distclean libs plugins install uninstall install-bin install-data
53 all: libs plugins $(PROG)
54
55 libs:
56         $(MAKE) -C $(DIR_LIBSRC)
57
58 plugins: libs 
59         $(MAKE) -C $(DIR_PLUGINS)
60
61 $(PROG): $(OBJS)
62         $(CXX) $^ $(LDFLAGS) $(LIBS) -o $(PROG)
63
64 clean:
65         rm -f deps $(PROG) *.o tags *.*~ .OS
66         rm -f .OS
67         rm -f .store
68         rm -f .db.sql
69         rm -f core*
70         $(MAKE) -C $(DIR_LIBSRC) clean
71         $(MAKE) -C $(DIR_PLUGINS) clean
72
73 distclean: clean
74         rm -f $(DIR_MOD)/*
75         rm -f ../../Makefile.conf
76
77 install: install-bin install-data
78
79 install-bin: $(PROG)
80         install -m $(BIN_MODE) -o $(OWNER) -s $(PROG) $(PREFIX)/usr/sbin/$(PROG)
81         $(MAKE) -C $(DIR_INCLUDE) install
82         $(MAKE) -C $(DIR_LIBSRC) install
83         $(MAKE) -C $(DIR_PLUGINS) install
84
85 install-data:
86         # Install etc
87         mkdir -m $(DIR_MODE) -p $(PREFIX)/etc/stargazer
88         mkdir -m $(DIR_MODE) -p $(PREFIX)/etc/stargazer/conf-available.d
89         mkdir -m $(DIR_MODE) -p $(PREFIX)/etc/stargazer/conf-enabled.d
90         install -m $(DATA_MODE) -o $(OWNER) $(ETC_DIR)/stargazer.conf $(PREFIX)/etc/stargazer/stargazer.conf
91         install -m $(DATA_MODE) -o $(OWNER) $(ETC_DIR)/conf-available.d/*.conf $(PREFIX)/etc/stargazer/conf-available.d
92         ln -sf ../conf-available.d/mod_ao.conf $(PREFIX)/etc/stargazer/conf-enabled.d/mod_ao.conf
93         ln -sf ../conf-available.d/mod_ia.conf $(PREFIX)/etc/stargazer/conf-enabled.d/mod_ia.conf
94         ln -sf ../conf-available.d/mod_ping.conf $(PREFIX)/etc/stargazer/conf-enabled.d/mod_ping.conf
95         ln -sf ../conf-available.d/mod_sg.conf $(PREFIX)/etc/stargazer/conf-enabled.d/mod_sg.conf
96         ln -sf ../conf-available.d/store_files.conf $(PREFIX)/etc/stargazer/conf-enabled.d/store_files.conf
97
98 ifeq ($(OS),linux)
99         ln -sf ../conf-available.d/mod_cap_ether.conf $(PREFIX)/etc/stargazer/conf-enabled.d/mod_cap_ether.conf
100 else
101         ln -sf ../conf-available.d/mod_cap_bpf.conf $(PREFIX)/etc/stargazer/conf-enabled.d/mod_cap_bpf.conf
102 endif
103
104         install -m $(DATA_MODE) -o $(OWNER) $(ETC_DIR)/rules $(PREFIX)/etc/stargazer/rules
105         install -m $(BIN_MODE) -o $(OWNER) $(ETC_DIR)/On* $(PREFIX)/etc/stargazer/
106         
107         # Install file db
108         mkdir -m $(DIR_MODE) -p $(PREFIX)/var/stargazer/admins
109         mkdir -m $(DIR_MODE) -p $(PREFIX)/var/stargazer/tariffs
110         mkdir -m $(DIR_MODE) -p $(PREFIX)/var/stargazer/users/test
111         install -m $(DATA_MODE) -o $(OWNER) $(VAR_DIR)/admins/admin.adm $(PREFIX)/var/stargazer/admins/admin.adm
112         install -m $(DATA_MODE) -o $(OWNER) $(VAR_DIR)/tariffs/tariff.tf $(PREFIX)/var/stargazer/tariffs/tariff.tf
113         install -m $(DATA_MODE) -o $(OWNER) $(VAR_DIR)/users/test/conf $(PREFIX)/var/stargazer/users/test/conf
114         install -m $(DATA_MODE) -o $(OWNER) $(VAR_DIR)/users/test/stat $(PREFIX)/var/stargazer/users/test/stat
115
116 uninstall: uninstall-bin uninstall-data
117
118 uninstall-bin:
119         rm -f $(PREFIX)/usr/sbin/$(PROG)
120         $(MAKE) -C $(DIR_LIBSRC) uninstall
121         $(MAKE) -C $(DIR_PLUGINS) uninstall
122         rm -rf $(PREFIX)/usr/lib/stg
123
124 uninstall-data:
125         # Uninstall etc
126         rm -rf $(PREFIX)/etc/stargazer
127         rm -rf $(PREFIX)/var/stargazer
128
129
130 ifneq ($(MAKECMDGOALS),distclean)
131 ifneq ($(MAKECMDGOALS),clean)
132 ifneq ($(MAKECMDGOALS),uninstall)
133 -include deps
134 endif
135 endif
136 endif
137
138 deps: $(SRCS) ../../Makefile.conf
139         $(MAKE) -C $(DIR_LIBSRC)
140         @>deps ;\
141         for file in $(SRCS); do\
142           echo "$$file" | grep ".c$$" > /dev/null;\
143           if [ $$? -eq 0 ];\
144           then\
145             echo "`$(CC) $(CFLAGS) -MM $$file` Makefile" >> deps ;\
146             printf '%b\n' '\t$$(CC) $(CFLAGS) -c $$<' >> deps ;\
147           else\
148             echo "`$(CXX) $(CXXFLAGS) -MM $$file` Makefile" >> deps ;\
149             printf '%b\n' '\t$$(CXX) $(CXXFLAGS) -c $$<' >> deps ;\
150           fi;\
151         done