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