Fix issues found by LLVM checker.
[freeradius.git] / src / modules / rules.mak
1 #######################################################################
2 #
3 # $Id$
4 #
5 #  Each module should have a few common defines at the TOP of the
6 # Makefile, and the 'include ../rules.mak'
7 #
8 # e.g.
9 #
10 ############################
11 # TARGET = rlm_foo
12 # SRCS   = rlm_foo.c other.c
13 #
14 # include ../rules.mak
15 #
16 # RLM_CFLAGS = my_cflags
17 # RLM_LDLAGS = my_ldflags
18 ############################
19 #
20 # and everything will be automagically built
21 #
22 #######################################################################
23
24 include $(RLM_DIR)../../../Make.inc
25
26 .PHONY: all build-module clean distclean install reconfig
27
28 all: build-module
29
30 #######################################################################
31 #
32 #  definitions for new dependencies on suffixes
33 #
34 #######################################################################
35 .SUFFIXES: .lo .o .la .a
36
37 #######################################################################
38 #
39 # define libtool objects for the libraries,
40 # along with a number of other useful definitions.
41 #
42 #######################################################################
43 LT_OBJS         += $(SRCS:.c=.lo)
44 LT_OBJS         += $(SRCS:.cpp=.lo)
45 CFLAGS          += -I$(top_builddir)/src -I$(top_builddir)/libltdl
46
47 #######################################################################
48 #
49 # Ensure that the modules get re-built if the server header files
50 # change.
51 #
52 #######################################################################
53 SERVER_HEADERS  = $(top_builddir)/src/include/radius.h  \
54                   $(top_builddir)/src/include/radiusd.h \
55                   $(top_builddir)/src/include/modules.h \
56                   $(top_builddir)/src/include/libradius.h
57
58 $(LT_OBJS): $(SERVER_HEADERS)
59
60 #######################################################################
61 #
62 # define new rules
63 #
64 #######################################################################
65 %.lo: %.c
66         $(LIBTOOL) --mode=compile $(CC) $(CFLAGS) $(RLM_CFLAGS) -c $<
67
68 %.lo: %.cpp
69         $(LIBTOOL) --mode=compile $(CXX) $(CFLAGS) $(RLM_CFLAGS) -c $<
70
71 ifneq ($(TARGET),)
72 #######################################################################
73 #
74 # Define a number of new targets
75 #
76 #######################################################################
77
78 #
79 #  If the module is in the list of static modules, then the "dynamic"
80 #  library is built statically, so that the '.la' file contains the
81 #  libraries that the module depends on.
82 #
83 #  Yes, this is a horrible hack.
84 #
85 ifeq ($(findstring $(TARGET),$(STATIC_MODULES)),)
86 LINK_MODE = -export-dynamic
87 else
88 LINK_MODE = -static
89 endif
90
91 #
92 #  Also, if we're NOT using shared libraries, then force the
93 #  link mode to static.
94 #
95 ifneq ($(USE_SHARED_LIBS),yes)
96 LINK_MODE = -static
97 endif
98
99 #######################################################################
100 #
101 #  Generic targets so we can sweep through all modules
102 # without knowing what their names are.
103 #
104 #  These rules also allow us to copy the '.a' or '.la' up
105 # a level, to the 'src/modules' directory, for general consumption.
106 #
107 #######################################################################
108
109 #
110 #  We can't use $(PWD), because that's apparently where the "make"
111 #  started.  Any child builds (make -C foo) don't change PWD.
112 #
113 WHERE=$(shell pwd)
114
115 build-module: $(TARGET).la $(RLM_UTILS)
116         @[ "x$(RLM_SUBDIRS)" = "x" ] || $(MAKE) $(MFLAGS) WHAT_TO_MAKE=all common
117         @[ -d $(top_builddir)/src/modules/lib/.libs ] || mkdir $(top_builddir)/src/modules/lib/.libs
118         for x in .libs/* $^; do \
119                 rm -rf $(top_builddir)/src/modules/lib/$$x; \
120                 ln -s $(WHERE)/$$x $(top_builddir)/src/modules/lib/$$x; \
121         done
122
123 $(TARGET).la: $(LT_OBJS)
124         $(LIBTOOL) --mode=link $(CC) -release $(RADIUSD_VERSION) \
125         -module $(LINK_MODE) $(LDFLAGS) $(RLM_LDFLAGS) -o $@     \
126         -rpath $(libdir) $^ $(LIBRADIUS) $(RLM_LIBS) $(LIBS)
127
128 #######################################################################
129 #
130 #  It's a dummy target: don't build it
131 #
132 #######################################################################
133 else
134 build-module:
135
136 # if $(TARGET) == ""
137 endif
138
139 #######################################################################
140 #
141 #  clean and install rules
142 #
143 #######################################################################
144 clean:
145         @rm -f *.a *.o *.lo *.la *~
146         @rm -rf .libs _libs
147         @rm -f config.cache config.log config.status $(RLM_UTILS)
148         @[ "x$(RLM_SUBDIRS)" = "x" ] || $(MAKE) $(MFLAGS) WHAT_TO_MAKE=clean common
149
150 distclean: clean
151         @rm -f config.h config.mak
152         @test -f Makefile.in && rm -f Makefile
153
154 reconfig:
155         @if [ -f configure.in ]; then \
156                 [ "x$(AUTOCONF)" != "x" ] && $(AUTOCONF) -I $(top_builddir); \
157         fi
158         @[ "x$(AUTOHEADER)" != "x" ] && [ -f ./configure.in ] && \
159         if grep AC_CONFIG_HEADERS configure.in >/dev/null; then\
160                 $(AUTOHEADER);\
161         fi
162
163 #
164 #  Do any module-specific installation.
165 #
166 #  If there isn't a TARGET defined, then don't do anything.
167 #  Otherwise, install the libraries into $(libdir)
168 #
169 install:
170         @[ "x$(RLM_INSTALL)" = "x" ] || $(MAKE) $(MFLAGS) $(RLM_INSTALL)
171         if [ "x$(TARGET)" != "x" ]; then \
172             $(LIBTOOL) --mode=install $(INSTALL) -c \
173                 $(TARGET).la $(R)$(libdir)/$(TARGET).la || exit $$?; \
174             rm -f $(R)$(libdir)/$(TARGET)-$(RADIUSD_VERSION).la; \
175             ln -s $(TARGET).la $(R)$(libdir)/$(TARGET)-$(RADIUSD_VERSION).la || exit $$?; \
176         fi
177
178 .PHONY: scan
179 scan:
180         @[ "$(SCAN_BUILD)" == "" ] || ($(MAKE) SCAN=yes LIBTOOL= 2>&1) | grep 'scan-view' || true