aboutsummaryrefslogtreecommitdiffstats
path: root/src/so.mk
blob: 63a0da7ce3fb41d4eeb93de50678e5ec26b7e559 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# Common definitions for making shared objects.
#
# Note: $(ROOT)/config.mk must be included before this file.
#
# The includer should probably define SO and TARGET and may also want to define
# EXTRA_OBJS and extend CLEANFILES.

CC ?= cc
RM ?= rm -f

HDRS :=
SRCS := $(sort $(wildcard $(MOD_DIR)/*.c))
OBJS := $(SRCS:.c=.o)
DEPS := $(sort $(wildcard $(OBJS:.o=.d)))

ifeq ($(DEPS),)
HDRS := $(sort $(wildcard $(MOD_DIR)/*.h $(ROOT)/src/include/*.h))
endif

.PHONY: all
all: $(TARGET)
-include $(DEPS)

%.o : %.c $(HDRS) $(ROOT)/config.mk
	$(CC) $(SO_CFLAGS) $(CFLAGS) $(CPPFLAGS) -c $< -o $@

$(SO): $(OBJS) $(EXTRA_OBJS) $(ROOT)/config.mk
	$(CC) $(SO_LDFLAGS) -shared $(LDFLAGS) -o $@ $(OBJS) $(EXTRA_OBJS) -ldl

.PHONY: clean
clean:; $(RM) -r $(SO) $(CLEANFILES)