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