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