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

include $(SUBDIR)../common.mak

LIBVERSION := $(lib$(NAME)_VERSION)
LIBMAJOR   := $(lib$(NAME)_VERSION_MAJOR)
7 8
INCINSTDIR := $(INCDIR)/lib$(NAME)
THIS_LIB   := $(SUBDIR)$($(CONFIG_SHARED:yes=S)LIBNAME)
Måns Rullgård's avatar
Måns Rullgård committed
9

10 11 12 13 14 15 16 17 18 19
$(SUBDIR)%-test.o: $(SUBDIR)%.c
	$(CC) $(CPPFLAGS) $(CFLAGS) -DTEST -c $(CC_O) $^

$(SUBDIR)%-test.o: $(SUBDIR)%-test.c
	$(CC) $(CPPFLAGS) $(CFLAGS) -DTEST -c $(CC_O) $^

$(SUBDIR)x86/%.o: $(SUBDIR)x86/%.asm
	$(YASMDEP) $(YASMFLAGS) -I $(<D)/ -M -o $@ $< > $(@:.o=.d)
	$(YASM) $(YASMFLAGS) -I $(<D)/ -o $@ $<

20
$(OBJS) $(SUBDIR)%.ho $(SUBDIR)%-test.o $(TESTOBJS): CPPFLAGS += -DHAVE_AV_CONFIG_H
21

Måns Rullgård's avatar
Måns Rullgård committed
22
ifdef CONFIG_STATIC
Måns Rullgård's avatar
Måns Rullgård committed
23 24 25 26 27
all: $(SUBDIR)$(LIBNAME)

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

$(SUBDIR)$(LIBNAME): $(OBJS)
Måns Rullgård's avatar
Måns Rullgård committed
28
	$(RM) $@
Måns Rullgård's avatar
Måns Rullgård committed
29 30 31 32
	$(AR) rc $@ $^ $(EXTRAOBJS)
	$(RANLIB) $@
endif

33 34
install-headers: install-lib$(NAME)-headers install-lib$(NAME)-pkgconfig

Måns Rullgård's avatar
Måns Rullgård committed
35
define RULES
36
$(SUBDIR)%$(EXESUF): $(SUBDIR)%.o
Måns Rullgård's avatar
Måns Rullgård committed
37
	$$(LD) $(FFLDFLAGS) -o $$@ $$^ -l$(FULLNAME) $(FFEXTRALIBS) $$(ELIBS)
38 39

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

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

48
ifdef CONFIG_SHARED
Måns Rullgård's avatar
Måns Rullgård committed
49 50 51 52 53
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
54
	$(Q)cd ./$(SUBDIR) && $(LN_S) $(SLIBNAME_WITH_MAJOR) $(SLIBNAME)
Måns Rullgård's avatar
Måns Rullgård committed
55

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

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

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

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
78 79

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

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

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

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

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

$(eval $(RULES))
106

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

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