Pull fix from branch_1_1
[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
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
57 $(LT_OBJS): $(SERVER_HEADERS)
58
59 #######################################################################
60 #
61 # define new rules
62 #
63 #######################################################################
64 %.lo: %.c
65         $(LIBTOOL) --mode=compile $(CC) $(CFLAGS) $(RLM_CFLAGS) -c $<
66
67 %.lo: %.cpp
68         $(LIBTOOL) --mode=compile $(CXX) $(CFLAGS) $(RLM_CFLAGS) -c $<
69
70 ifneq ($(TARGET),)
71 #######################################################################
72 #
73 # Define a number of new targets
74 #
75 #######################################################################
76
77 #
78 #  If the module is in the list of static modules, then the "dynamic"
79 #  library is built statically, so that the '.la' file contains the
80 #  libraries that the module depends on.
81 #
82 #  Yes, this is a horrible hack.
83 #
84 ifeq ($(findstring $(TARGET),$(STATIC_MODULES)),)
85 LINK_MODE = -export-dynamic
86 else
87 LINK_MODE = -static
88 endif
89
90 #
91 #  Also, if we're NOT using shared libraries, then force the
92 #  link mode to static.
93 #
94 ifneq ($(USE_SHARED_LIBS),yes)
95 LINK_MODE = -static
96 endif
97
98 #######################################################################
99 #
100 #  Generic targets so we can sweep through all modules
101 # without knowing what their names are.
102 #
103 #  These rules also allow us to copy the '.a' or '.la' up
104 # a level, to the 'src/modules' directory, for general consumption.
105 #
106 #######################################################################
107
108 build-module: $(TARGET).la $(RLM_UTILS)
109         @[ "x$(RLM_SUBDIRS)" = "x" ] || $(MAKE) $(MFLAGS) WHAT_TO_MAKE=all common
110         @[ -d .libs ] && cp .libs/* $(top_builddir)/src/modules/lib
111         @cp $< $(top_builddir)/src/modules/lib
112
113 $(TARGET).la: $(LT_OBJS)
114         $(LIBTOOL) --mode=link $(CC) -release $(RADIUSD_VERSION) \
115         -module $(LINK_MODE) $(LDFLAGS) $(RLM_LDFLAGS) -o $@     \
116         -rpath $(libdir) $^ $(top_builddir)/src/lib/libradius.la \
117         $(RLM_LIBS) $(LIBS)
118
119 #######################################################################
120 #
121 #  It's a dummy target: don't build it
122 #
123 #######################################################################
124 else
125 build-module:
126
127 # if $(TARGET) == ""
128 endif
129
130 #######################################################################
131 #
132 #  clean and install rules
133 #
134 #######################################################################
135 clean:
136         @rm -f *.a *.o *.lo *.la *~
137         @rm -rf .libs _libs
138         @rm -f config.cache config.log config.status $(RLM_UTILS)
139         @[ "x$(RLM_SUBDIRS)" = "x" ] || $(MAKE) $(MFLAGS) WHAT_TO_MAKE=clean common
140
141 distclean: clean
142         @rm -f config.h config.mak
143         @test -f Makefile.in && rm -f Makefile
144
145 reconfig:
146         @if [ -f configure.in ]; then \
147                 [ "x$(AUTOCONF)" != "x" ] && $(AUTOCONF) -I $(top_builddir); \
148         fi
149         @[ "x$(AUTOHEADER)" != "x" ] && [ -f ./configure.in ] && \
150         if grep AC_CONFIG_HEADERS configure.in >/dev/null; then\
151                 $(AUTOHEADER);\
152         fi
153
154 #
155 #  Do any module-specific installation.
156 #
157 #  If there isn't a TARGET defined, then don't do anything.
158 #  Otherwise, install the libraries into $(libdir)
159 #
160 install:
161         @[ "x$(RLM_INSTALL)" = "x" ] || $(MAKE) $(MFLAGS) $(RLM_INSTALL)
162         if [ "x$(TARGET)" != "x" ]; then \
163             $(LIBTOOL) --mode=install $(INSTALL) -c \
164                 $(TARGET).la $(R)$(libdir)/$(TARGET).la || exit $$?; \
165             rm -f $(R)$(libdir)/$(TARGET)-$(RADIUSD_VERSION).la; \
166             ln -s $(TARGET).la $(R)$(libdir)/$(TARGET)-$(RADIUSD_VERSION).la || exit $$?; \
167         fi