19176f97a71cbf584924e914654c22767b0572f0
[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 include ../../../../../Make.inc
24
25 all: 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../.. -I../../../../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_sql.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_SQL_CFLAGS) -c $< -o $@
61
62 %.lo : %.c
63         $(LIBTOOL) --mode=compile $(CC) $(CFLAGS) $(RLM_SQL_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) -module -static $(CFLAGS) $(RLM_SQL_CFLAGS) $^ -o $@ 
73
74 #
75 #  If the module is in the list of static modules, then the "dynamic"
76 #  library is built statically, so that the '.la' file contains the
77 #  libraries that the module depends on.
78 #
79 #  Yes, this is a horrible hack.
80 #
81 ifeq ($(findstring $(TARGET),$(STATIC_MODULES)),)
82 LINK_MODE=-export-dynamic
83 else
84 LINK_MODE=-static
85 endif
86
87 #
88 #  Also, if we're NOT using shared libraries, then force the
89 #  link mode to static.
90 #
91 ifneq ($(USE_SHARED_LIBS),yes)
92 LINK_MODE=-static
93 endif
94
95 $(TARGET).la: $(DYNAMIC_OBJS)
96         $(LIBTOOL) --mode=link $(CC) -module $(LINK_MODE) $(CFLAGS) \
97         $(RLM_SQL_CFLAGS) -o $@ -rpath $(libdir) $^ $(RLM_SQL_LIBS)
98
99 #######################################################################
100 #
101 #  Generic targets so we can sweep through all modules
102 # without knowing what their names are.
103 #
104 #  These rules also allow us to copy the '.a' or '.la' up
105 # a level, to the 'src/modules' directory, for general consumption.
106 #
107 #######################################################################
108 static: $(TARGET).a
109         @cp $< ../lib
110
111 dynamic: $(TARGET).la
112         @cp $< ../lib
113
114 #######################################################################
115 #
116 #  It's a dummy target: don't build it
117 #
118 #######################################################################
119 else
120 static:
121
122 dynamic:
123
124 # if $(TARGET) == ""
125 endif
126
127 #######################################################################
128 #
129 #  clean and install rules
130 #
131 #######################################################################
132 clean:
133         @rm -f *.a *.o *.lo *.la *~
134         @rm -rf .libs _libs
135
136 distclean:
137         @rm -f config.h config.mak
138
139 #
140 #  Do any module-specific installation.
141 #
142 #  If there isn't a TARGET defined, then don't do anything.
143 #  Otherwise, install the libraries into $(libdir)
144 #
145 install:
146         [ "x$(TARGET)" = "x" ] || $(LIBTOOL) --mode=install $(INSTALL) -c $(TARGET).la $(R)$(libdir)/$(TARGET).la