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