subdir.mak 3.15 KB
Newer Older
Måns Rullgård's avatar
Måns Rullgård committed
1 2 3 4 5 6 7
SRC_DIR := $(SRC_PATH_BARE)/lib$(NAME)

include $(SUBDIR)../common.mak

LIBVERSION := $(lib$(NAME)_VERSION)
LIBMAJOR   := $(lib$(NAME)_VERSION_MAJOR)

Måns Rullgård's avatar
Måns Rullgård committed
8
ifdef CONFIG_STATIC
Måns Rullgård's avatar
Måns Rullgård committed
9 10 11
all: $(SUBDIR)$(LIBNAME)

install-libs: install-lib$(NAME)-static
12
install-headers: install-lib$(NAME)-headers install-lib$(NAME)-pkgconfig
Måns Rullgård's avatar
Måns Rullgård committed
13 14

$(SUBDIR)$(LIBNAME): $(OBJS)
Måns Rullgård's avatar
Måns Rullgård committed
15
	$(RM) $@
Måns Rullgård's avatar
Måns Rullgård committed
16 17 18 19 20 21
	$(AR) rc $@ $^ $(EXTRAOBJS)
	$(RANLIB) $@
endif

INCINSTDIR := $(INCDIR)/lib$(NAME)

22
THIS_LIB := $(SUBDIR)$($(CONFIG_SHARED:yes=S)LIBNAME)
23

Måns Rullgård's avatar
Måns Rullgård committed
24
define RULES
25
$(SUBDIR)%$(EXESUF): $(SUBDIR)%.o
Måns Rullgård's avatar
Måns Rullgård committed
26
	$$(LD) $(FFLDFLAGS) -o $$@ $$^ -l$(FULLNAME) $(FFEXTRALIBS) $$(ELIBS)
27 28

$(SUBDIR)%-test.o: $(SUBDIR)%.c
Måns Rullgård's avatar
Måns Rullgård committed
29
	$$(CC) $(CPPFLAGS) $(CFLAGS) -DTEST -c $$(CC_O) $$^
30 31

$(SUBDIR)%-test.o: $(SUBDIR)%-test.c
Måns Rullgård's avatar
Måns Rullgård committed
32
	$$(CC) $(CPPFLAGS) $(CFLAGS) -DTEST -c $$(CC_O) $$^
33 34

$(SUBDIR)x86/%.o: $(SUBDIR)x86/%.asm
Måns Rullgård's avatar
Måns Rullgård committed
35 36
	$$(YASMDEP) $(YASMFLAGS) -I $$(<D)/ -M -o $$@ $$< > $$(@:.o=.d)
	$$(YASM) $(YASMFLAGS) -I $$(<D)/ -o $$@ $$<
37 38

clean::
Måns Rullgård's avatar
Måns Rullgård committed
39
	$(RM) $(addprefix $(SUBDIR),*-example$(EXESUF) *-test$(EXESUF) $(CLEANFILES) $(CLEANSUFFIXES) $(LIBSUFFIXES)) \
40 41
	    $(addprefix $(SUBDIR), $(foreach suffix,$(CLEANSUFFIXES),$(addsuffix /$(suffix),$(DIRS)))) \
	    $(HOSTOBJS) $(HOSTPROGS)
42 43

distclean:: clean
Måns Rullgård's avatar
Måns Rullgård committed
44
	$(RM)  $(addprefix $(SUBDIR),$(DISTCLEANSUFFIXES)) \
45 46
            $(addprefix $(SUBDIR), $(foreach suffix,$(DISTCLEANSUFFIXES),$(addsuffix /$(suffix),$(DIRS))))

47
ifdef CONFIG_SHARED
Måns Rullgård's avatar
Måns Rullgård committed
48 49 50 51 52
all: $(SUBDIR)$(SLIBNAME)

install-libs: install-lib$(NAME)-shared

$(SUBDIR)$(SLIBNAME): $(SUBDIR)$(SLIBNAME_WITH_MAJOR)
Måns Rullgård's avatar
Måns Rullgård committed
53
	$(Q)cd ./$(SUBDIR) && $(LN_S) $(SLIBNAME_WITH_MAJOR) $(SLIBNAME)
Måns Rullgård's avatar
Måns Rullgård committed
54

55
$(SUBDIR)$(SLIBNAME_WITH_MAJOR): $(OBJS) $(SUBDIR)lib$(NAME).ver
Måns Rullgård's avatar
Måns Rullgård committed
56
	$(SLIB_CREATE_DEF_CMD)
Måns Rullgård's avatar
Måns Rullgård committed
57
	$$(LD) $(SHFLAGS) $(FFLDFLAGS) -o $$@ $$(filter %.o,$$^) $(FFEXTRALIBS) $(EXTRAOBJS)
Måns Rullgård's avatar
Måns Rullgård committed
58 59
	$(SLIB_EXTRA_CMD)

60
ifdef SUBDIR
Måns Rullgård's avatar
Måns Rullgård committed
61
$(SUBDIR)$(SLIBNAME_WITH_MAJOR): $(DEP_LIBS)
Måns Rullgård's avatar
Måns Rullgård committed
62 63 64 65
endif
endif

install-lib$(NAME)-shared: $(SUBDIR)$(SLIBNAME)
Måns Rullgård's avatar
Måns Rullgård committed
66
	$(Q)mkdir -p "$(SHLIBDIR)"
67
	$$(INSTALL) -m 755 $$< "$(SHLIBDIR)/$(SLIBNAME_WITH_VERSION)"
Måns Rullgård's avatar
Måns Rullgård committed
68 69
	$$(STRIP) "$(SHLIBDIR)/$(SLIBNAME_WITH_VERSION)"
	$(Q)cd "$(SHLIBDIR)" && \
Måns Rullgård's avatar
Måns Rullgård committed
70
		$(LN_S) $(SLIBNAME_WITH_VERSION) $(SLIBNAME_WITH_MAJOR)
Måns Rullgård's avatar
Måns Rullgård committed
71
	$(Q)cd "$(SHLIBDIR)" && \
Måns Rullgård's avatar
Måns Rullgård committed
72
		$(LN_S) $(SLIBNAME_WITH_VERSION) $(SLIBNAME)
73
	$(SLIB_INSTALL_EXTRA_CMD)
Måns Rullgård's avatar
Måns Rullgård committed
74 75 76

install-lib$(NAME)-static: MSG = $(LIBDIR)/$(LIBNAME)
install-lib$(NAME)-shared: MSG = $(LIBDIR)/$(SLIBNAME)
Måns Rullgård's avatar
Måns Rullgård committed
77 78

install-lib$(NAME)-static: $(SUBDIR)$(LIBNAME)
Måns Rullgård's avatar
Måns Rullgård committed
79
	$(Q)mkdir -p "$(LIBDIR)"
80
	$$(INSTALL) -m 644 $$< "$(LIBDIR)"
Måns Rullgård's avatar
Måns Rullgård committed
81
	$(LIB_INSTALL_EXTRA_CMD)
Måns Rullgård's avatar
Måns Rullgård committed
82

83
install-lib$(NAME)-headers: $(addprefix $(SUBDIR),$(HEADERS) $(BUILT_HEADERS))
Måns Rullgård's avatar
Måns Rullgård committed
84
	$(Q)mkdir -p "$(INCINSTDIR)"
85 86 87
	$$(INSTALL) -m 644 $$^ "$(INCINSTDIR)"

install-lib$(NAME)-pkgconfig: $(SUBDIR)lib$(NAME).pc
Måns Rullgård's avatar
Måns Rullgård committed
88
	$(Q)mkdir -p "$(LIBDIR)/pkgconfig"
89
	$$(INSTALL) -m 644 $$^ "$(LIBDIR)/pkgconfig"
Ramiro Polla's avatar
Ramiro Polla committed
90 91

uninstall-libs::
Måns Rullgård's avatar
Måns Rullgård committed
92
	-$(RM) "$(SHLIBDIR)/$(SLIBNAME_WITH_MAJOR)" \
Ramiro Polla's avatar
Ramiro Polla committed
93 94 95
	       "$(SHLIBDIR)/$(SLIBNAME)"            \
	       "$(SHLIBDIR)/$(SLIBNAME_WITH_VERSION)"
	-$(SLIB_UNINSTALL_EXTRA_CMD)
Måns Rullgård's avatar
Måns Rullgård committed
96
	-$(RM) "$(LIBDIR)/$(LIBNAME)"
Ramiro Polla's avatar
Ramiro Polla committed
97 98

uninstall-headers::
Måns Rullgård's avatar
Måns Rullgård committed
99 100
	$(RM) $(addprefix "$(INCINSTDIR)/",$(HEADERS))
	$(RM) "$(LIBDIR)/pkgconfig/lib$(NAME).pc"
Ramiro Polla's avatar
Ramiro Polla committed
101
	-rmdir "$(INCDIR)"
Måns Rullgård's avatar
Måns Rullgård committed
102 103 104
endef

$(eval $(RULES))
105

106 107
$(EXAMPLES) $(TESTPROGS): $(THIS_LIB) $(DEP_LIBS)

108 109
examples: $(EXAMPLES)
testprogs: $(TESTPROGS)