backport from HEAD
[freeradius.git] / src / modules / rlm_sql / drivers / 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 all: dynamic
24
25 #######################################################################
26 #
27 #  definitions for new dependencies on suffixes
28 #
29 #######################################################################
30 .SUFFIXES: .lo .o .la .a
31
32 #######################################################################
33 #
34 # define static and dynamic objects for the libraries,
35 # along with a number of other useful definitions.
36 #
37 #######################################################################
38 STATIC_OBJS     = $(SRCS:.c=.o)
39 DYNAMIC_OBJS    = $(SRCS:.c=.lo)
40 CFLAGS          += -I../.. -I../../../../include
41
42 #######################################################################
43 #
44 # Ensure that the modules get re-built if the server header files
45 # change.
46 #
47 #######################################################################
48 SERVER_HEADERS  = ../../rlm_sql.h
49 $(STATIC_OBJS):  $(SERVER_HEADERS)
50 $(DYNAMIC_OBJS): $(SERVER_HEADERS)
51
52 #######################################################################
53 #
54 # define new rules
55 #
56 #######################################################################
57 %.o : %.c
58         $(CC) $(CFLAGS) $(RLM_SQL_CFLAGS) -c $< -o $@
59
60 %.lo : %.c
61         $(LIBTOOL) --mode=compile $(CC) $(CFLAGS) $(RLM_SQL_CFLAGS) -c $<
62
63 ifneq ($(TARGET),)
64 #######################################################################
65 #
66 # Define a number of new targets
67 #
68 #######################################################################
69 $(TARGET).a: $(STATIC_OBJS)
70         $(LIBTOOL) --mode=link $(LD) -module -static $(CFLAGS) $(RLM_SQL_CFLAGS) $^ -o $@ 
71
72 #
73 #  If the module is in the list of static modules, then the "dynamic"
74 #  library is built statically, so that the '.la' file contains the
75 #  libraries that the module depends on.
76 #
77 #  Yes, this is a horrible hack.
78 #
79 ifeq ($(findstring $(TARGET),$(STATIC_MODULES)),)
80 LINK_MODE=-export-dynamic
81 else
82 LINK_MODE=-static
83 endif
84
85 #
86 #  Also, if we're NOT using shared libraries, then force the
87 #  link mode to static.
88 #
89 ifneq ($(USE_SHARED_LIBS),yes)
90 LINK_MODE=-static
91 endif
92
93 $(TARGET).la: $(DYNAMIC_OBJS)
94         $(LIBTOOL) --mode=link $(CC) -release $(RADIUSD_VERSION) \
95         -module $(LINK_MODE) $(CFLAGS) \
96         $(RLM_SQL_CFLAGS) -o $@ -rpath $(libdir) $^ $(RLM_SQL_LIBS)
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 static: $(TARGET).a
108         @cp $< ../lib
109
110 dynamic: $(TARGET).la
111         @cp $< ../lib
112
113 #######################################################################
114 #
115 #  It's a dummy target: don't build it
116 #
117 #######################################################################
118 else
119 static:
120
121 dynamic:
122
123 # if $(TARGET) == ""
124 endif
125
126 #######################################################################
127 #
128 #  clean and install rules
129 #
130 #######################################################################
131 clean:
132         @rm -f *.a *.o *.lo *.la *~
133         @rm -rf .libs _libs
134         @rm -f config.log config.status config.cache
135
136 distclean: clean
137         @rm -f config.h config.mak
138
139 reconfig:
140         @[ "x$(AUTOCONF)" != "x" ] && [ -f ./configure.in ] && $(AUTOCONF) -l $(RLM_DIR)../../..
141
142 #
143 #  Do any module-specific installation.
144 #
145 #  If there isn't a TARGET defined, then don't do anything.
146 #  Otherwise, install the libraries into $(libdir)
147 #
148 install:
149         [ "x$(TARGET)" = "x" ] || $(LIBTOOL) --mode=install $(INSTALL) -c $(TARGET).la $(R)$(libdir)/$(TARGET).la