lots more changes to dynamic library stuff. This time, I've
[freeradius.git] / src / modules / rules.mak
1 #######################################################################
2 #
3 #  Each module should have a few common defines at the TOP of the
4 # Makefile, and the 'include ../rules.mak'
5 #
6 # e.g.
7 #
8 ##########################
9 # TARGET = rlm_foo
10 # SRCS   = rlm_foo.c other.c
11 #
12 # include ../rules.mak
13 #
14 # CFLAGS += my_c_flags
15 ##########################
16 #
17 # and everything will be automagically built
18 #
19 #######################################################################
20
21 include ../../../Make.inc
22
23 all: static dynamic
24
25 #######################################################################
26 #
27 #  definitions for new dependencies on suffixes
28 #
29 #######################################################################
30 .SUFFIXES: .lo .o .so .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../../include
41
42 #######################################################################
43 #
44 # define new rules
45 #
46 #######################################################################
47 %.o : %.c
48         $(CC) $(CFLAGS) $(RLM_CFLAGS) -c $< -o $@
49
50 %.lo : %.c
51         $(CC) $(CFLAGS) $(RLM_CFLAGS) -fPIC -c $< -o $@
52
53 ifneq ($(TARGET),)
54 #######################################################################
55 #
56 # Define a number of new targets
57 #
58 #######################################################################
59 $(TARGET).a: $(STATIC_OBJS)
60         $(AR) crv $@ $^
61
62 $(TARGET).so: $(DYNAMIC_OBJS)
63         $(LD) $(MODULE_LDFLAGS) $(LIBS) $^ -o $@
64
65 #######################################################################
66 #
67 #  Generic targets so we can sweep through all modules
68 # without knowing what their names are.
69 #
70 #  These rules also allow us to copy the '.a' or '.so' up
71 # a level, to the 'src/modules' directory, for general consumption.
72 #
73 #######################################################################
74 static: $(TARGET).a
75         @cp $< ../lib
76
77 dynamic: $(TARGET).so
78         @cp $< ../lib
79
80 #######################################################################
81 #
82 #  It's a dummy target: don't build it
83 #
84 #######################################################################
85 else
86 static:
87
88 dynamic:
89
90 # if $(TARGET) == ""
91 endif
92
93 #######################################################################
94 #
95 #  clean and install rules
96 #
97 #######################################################################
98 clean:
99         @rm -f *.a *.o *.lo *.so *~
100
101 reallyclean: clean
102         @rm -f config.h config.mak