Merge branch 'sam'
[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 $(INCLTDL)
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         @echo CC $<
67         @echo CC $<
68         @$(LIBTOOL) --quiet --mode=compile $(CC) $(CFLAGS) $(RLM_CFLAGS) -c $<
69
70 %.lo: %.cpp
71         @echo CXX $<
72         @$(LIBTOOL) --quiet --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 #######################################################################
103 #
104 #  Generic targets so we can sweep through all modules
105 # without knowing what their names are.
106 #
107 #  These rules also allow us to copy the '.a' or '.la' up
108 # a level, to the 'src/modules' directory, for general consumption.
109 #
110 #######################################################################
111
112 #
113 #  We can't use $(PWD), because that's apparently where the "make"
114 #  started.  Any child builds (make -C foo) don't change PWD.
115 #
116 WHERE=$(shell pwd)
117
118 build-module: $(TARGET).la $(RLM_UTILS)
119         @[ -d $(top_builddir)/src/modules/lib/.libs ] || mkdir $(top_builddir)/src/modules/lib/.libs
120         @for x in .libs/* $^; do \
121                 rm -rf $(top_builddir)/src/modules/lib/$$x; \
122                 ln -s $(WHERE)/$$x $(top_builddir)/src/modules/lib/$$x; \
123         done
124
125 $(TARGET).la: $(RLM_SUBDIRS) $(LT_OBJS)
126         @echo LINK $@ $^
127         @$(LIBTOOL) --quiet --mode=link $(CC) -release $(RADIUSD_VERSION) \
128             -module $(LINK_MODE) $(LDFLAGS) $(RLM_LDFLAGS) -o $@     \
129             -rpath $(libdir) $^ $(LIBRADIUS) $(RLM_LIBS) $(LIBS)
130
131 #######################################################################
132 #
133 #  It's a dummy target: don't build it
134 #
135 #######################################################################
136 else
137 build-module:
138
139 # if $(TARGET) == ""
140 endif
141
142 #######################################################################
143 #
144 #  clean and install rules
145 #
146 #######################################################################
147 clean:
148         @rm -f *.a *.o *.lo *.la *~
149         @rm -rf .libs _libs
150         @rm -f config.cache config.log config.status $(RLM_UTILS)
151         @[ "x$(RLM_SUBDIRS)" = "x" ] || $(MAKE) $(MFLAGS) WHAT_TO_MAKE=clean common
152
153 distclean: clean
154         @rm -f config.h config.mak
155         @test -f Makefile.in && rm -f Makefile
156
157 reconfig:
158         @if [ -f configure.in ]; then \
159                 [ "x$(AUTOCONF)" != "x" ] && $(AUTOCONF) -I $(top_builddir); \
160         fi
161         @[ "x$(AUTOHEADER)" != "x" ] && [ -f ./configure.in ] && \
162         if grep AC_CONFIG_HEADERS configure.in >/dev/null; then\
163                 $(AUTOHEADER);\
164         fi
165
166 #
167 #  Do any module-specific installation.
168 #
169 #  If there isn't a TARGET defined, then don't do anything.
170 #  Otherwise, install the libraries into $(libdir)
171 #
172 install:
173         @[ "x$(RLM_INSTALL)" = "x" ] || $(MAKE) $(MFLAGS) $(RLM_INSTALL)
174         if [ "x$(TARGET)" != "x" ]; then \
175             $(LIBTOOL) --mode=install $(INSTALL) -c \
176                 $(TARGET).la $(R)$(libdir)/$(TARGET).la || exit $$?; \
177             rm -f $(R)$(libdir)/$(TARGET)-$(RADIUSD_VERSION).la; \
178             ln -s $(TARGET).la $(R)$(libdir)/$(TARGET)-$(RADIUSD_VERSION).la || exit $$?; \
179         fi
180 ifneq ($(RLM_UTILS),)
181         $(INSTALL) -d -m 755 $(R)$(bindir)
182         for x in $(RLM_UTILS); do \
183                 $(LIBTOOL) --mode=install $(INSTALL) -m 755 $(INSTALLSTRIP) $$x$(EXEEXT) $(R)$(bindir); \
184         done
185 endif