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