]> git.stg.codes - stg.git/blob - projects/sgconf/Makefile
Merge branch 'master' of gitorious.org:stg/stg
[stg.git] / projects / sgconf / Makefile
1 ###############################################################################
2 # $Id: Makefile,v 1.21 2010/02/11 12:34:14 faust Exp $
3 ###############################################################################
4
5 include ../../Makefile.conf
6
7 PROG = sgconf
8
9 SRCS = ./main.cpp \
10        ./common_sg.cpp \
11        ./options.cpp \
12        ./actions.cpp
13
14 STGLIBS = conffiles \
15           srvconf \
16           crypto \
17           common
18
19 STGLIBS_INCS = $(addprefix -I ../../stglibs/,$(addsuffix .lib/include,$(STGLIBS)))
20 STGLIBS_LIBS = $(addprefix -L ../../stglibs/,$(addsuffix .lib,$(STGLIBS)))
21
22 LIBS += $(addprefix -lstg,$(STGLIBS)) -lexpat $(LIB_THREAD)
23
24 ifeq ($(OS),linux)
25 else
26 LIBS += -lc \
27         -liconv
28 endif
29
30 SEARCH_DIRS = -I ../../include
31
32 ifeq ($(OS),bsd)
33 SEARCH_DIRS += -I/usr/local/include
34 CXXFLAGS += -DHAVE_DECL_GETOPT=1
35 endif
36
37 ifeq ($(OS),bsd5)
38 SEARCH_DIRS += -I/usr/local/include
39 CXXFLAGS += -DHAVE_DECL_GETOPT=1
40 endif
41
42 OBJS = $(notdir $(patsubst %.cpp, %.o, $(patsubst %.c, %.o, $(SRCS))))
43
44 CXXFLAGS += $(DEFS) $(STGLIBS_INCS) $(SEARCH_DIRS)
45 CFLAGS += $(DEFS) $(STGLIBS_INCS) $(SEARCH_DIRS)
46 LDFLAGS += $(STGLIBS_LIBS)
47
48 ifneq ($(OS),darwin)
49 LDFLAGS += -Wl,-E
50 endif
51
52 .PHONY: all clean distclean libs install uninstall install-bin install-data uninstall-bin uninstall-data
53 all: libs $(PROG) ../../Makefile.conf
54
55 libs:
56         $(MAKE) -C $(DIR_LIBSRC)
57
58 $(PROG): $(OBJS)
59         $(CXX) $^ $(LDFLAGS) $(LIBS) -o $(PROG)
60
61 clean:
62         rm -f deps $(PROG) *.o tags *.*~ .OS
63         rm -f .OS
64         rm -f .store
65         rm -f .db.sql
66         rm -f core*
67         $(MAKE) -C $(DIR_LIBSRC) clean
68
69 distclean: clean
70         rm -f ../../Makefile.conf
71
72 install: install-bin
73
74 install-bin:
75 ifeq ($(DEBUG), yes)
76         install -D -m $(BIN_MODE) -o $(OWNER) $(PROG) $(PREFIX)/usr/bin/$(PROG)
77 else
78         install -D -m $(BIN_MODE) -o $(OWNER) -s $(PROG) $(PREFIX)/usr/bin/$(PROG)
79 endif
80         $(MAKE) -C $(DIR_LIBSRC) install
81
82 uninstall: uninstall-bin
83
84 uninstall-bin:
85         rm -f $(PREFIX)/usr/sbin/$(PROG)
86
87
88 ifneq ($(MAKECMDGOALS),distclean)
89 ifneq ($(MAKECMDGOALS),clean)
90 ifneq ($(MAKECMDGOALS),uninstall)
91 -include deps
92 endif
93 endif
94 endif
95
96 deps:   $(SRCS) ../../Makefile.conf
97         $(MAKE) -C $(DIR_LIBSRC)
98         @>deps ;\
99         for file in $(SRCS); do\
100           echo "$$file" | grep ".c$$" > /dev/null;\
101           if [ $$? -eq 0 ];\
102           then\
103             echo "`$(CC) $(CFLAGS) -MM $$file` Makefile" >> deps ;\
104             printf '%b\n' '\t$$(CC) $(CFLAGS) -c $$<' >> deps ;\
105           else\
106             echo "`$(CXX) $(CXXFLAGS) -MM $$file` Makefile" >> deps ;\
107             printf '%b\n' '\t$$(CXX) $(CXXFLAGS) -c $$<' >> deps ;\
108           fi;\
109         done