9302722eaebc3e18c80513d5c8b35333ad6f21d6
[ffmpeg.git] / subdir.mak
1 SRC_DIR := $(SRC_PATH_BARE)/lib$(NAME)
2
3 include $(SUBDIR)../common.mak
4
5 LIBVERSION := $(lib$(NAME)_VERSION)
6 LIBMAJOR   := $(lib$(NAME)_VERSION_MAJOR)
7
8 ifdef CONFIG_STATIC
9 all: $(SUBDIR)$(LIBNAME)
10
11 install-libs: install-lib$(NAME)-static
12 install-headers: install-lib$(NAME)-headers install-lib$(NAME)-pkgconfig
13
14 $(SUBDIR)$(LIBNAME): $(OBJS)
15         $(RM) $@
16         $(AR) rc $@ $^ $(EXTRAOBJS)
17         $(RANLIB) $@
18 endif
19
20 INCINSTDIR := $(INCDIR)/lib$(NAME)
21
22 THIS_LIB := $(SUBDIR)$($(CONFIG_SHARED:yes=S)LIBNAME)
23
24 define RULES
25 $(SUBDIR)%$(EXESUF): $(SUBDIR)%.o
26         $(LD) $(FFLDFLAGS) -o $$@ $$^ -l$(FULLNAME) $(FFEXTRALIBS) $$(ELIBS)
27
28 $(SUBDIR)%-test.o: $(SUBDIR)%.c
29         $(CC) $(CPPFLAGS) $(CFLAGS) -DTEST -c $$(CC_O) $$^
30
31 $(SUBDIR)%-test.o: $(SUBDIR)%-test.c
32         $(CC) $(CPPFLAGS) $(CFLAGS) -DTEST -c $$(CC_O) $$^
33
34 $(SUBDIR)x86/%.o: $(SUBDIR)x86/%.asm
35         $(YASMDEP) $(YASMFLAGS) -I $$(<D)/ -M -o $$@ $$< > $$(@:.o=.d)
36         $(YASM) $(YASMFLAGS) -I $$(<D)/ -o $$@ $$<
37
38 clean::
39         $(RM) $(addprefix $(SUBDIR),*-example$(EXESUF) *-test$(EXESUF) $(CLEANFILES) $(CLEANSUFFIXES) $(LIBSUFFIXES)) \
40             $(addprefix $(SUBDIR), $(foreach suffix,$(CLEANSUFFIXES),$(addsuffix /$(suffix),$(DIRS)))) \
41             $(HOSTOBJS) $(HOSTPROGS)
42
43 distclean:: clean
44         $(RM)  $(addprefix $(SUBDIR),$(DISTCLEANSUFFIXES)) \
45             $(addprefix $(SUBDIR), $(foreach suffix,$(DISTCLEANSUFFIXES),$(addsuffix /$(suffix),$(DIRS))))
46
47 ifdef CONFIG_SHARED
48 all: $(SUBDIR)$(SLIBNAME)
49
50 install-libs: install-lib$(NAME)-shared
51
52 $(SUBDIR)$(SLIBNAME): $(SUBDIR)$(SLIBNAME_WITH_MAJOR)
53         cd ./$(SUBDIR) && $(LN_S) $(SLIBNAME_WITH_MAJOR) $(SLIBNAME)
54
55 $(SUBDIR)$(SLIBNAME_WITH_MAJOR): $(OBJS) $(SUBDIR)lib$(NAME).ver
56         $(SLIB_CREATE_DEF_CMD)
57         $(LD) $(SHFLAGS) $(FFLDFLAGS) -o $$@ $$(filter %.o,$$^) $(FFEXTRALIBS) $(EXTRAOBJS)
58         $(SLIB_EXTRA_CMD)
59
60 ifdef SUBDIR
61 $(SUBDIR)$(SLIBNAME_WITH_MAJOR): $(DEP_LIBS)
62 endif
63 endif
64
65 install-lib$(NAME)-shared: $(SUBDIR)$(SLIBNAME)
66         mkdir -p "$(SHLIBDIR)"
67         $$(INSTALL) -m 755 $$< "$(SHLIBDIR)/$(SLIBNAME_WITH_VERSION)"
68         $(STRIP) "$(SHLIBDIR)/$(SLIBNAME_WITH_VERSION)"
69         cd "$(SHLIBDIR)" && \
70                 $(LN_S) $(SLIBNAME_WITH_VERSION) $(SLIBNAME_WITH_MAJOR)
71         cd "$(SHLIBDIR)" && \
72                 $(LN_S) $(SLIBNAME_WITH_VERSION) $(SLIBNAME)
73         $(SLIB_INSTALL_EXTRA_CMD)
74
75 install-lib$(NAME)-static: $(SUBDIR)$(LIBNAME)
76         mkdir -p "$(LIBDIR)"
77         $$(INSTALL) -m 644 $$< "$(LIBDIR)"
78         $(LIB_INSTALL_EXTRA_CMD)
79
80 install-lib$(NAME)-headers: $(addprefix $(SUBDIR),$(HEADERS) $(BUILT_HEADERS))
81         mkdir -p "$(INCINSTDIR)"
82         $$(INSTALL) -m 644 $$^ "$(INCINSTDIR)"
83
84 install-lib$(NAME)-pkgconfig: $(SUBDIR)lib$(NAME).pc
85         mkdir -p "$(LIBDIR)/pkgconfig"
86         $$(INSTALL) -m 644 $$^ "$(LIBDIR)/pkgconfig"
87
88 uninstall-libs::
89         -$(RM) "$(SHLIBDIR)/$(SLIBNAME_WITH_MAJOR)" \
90                "$(SHLIBDIR)/$(SLIBNAME)"            \
91                "$(SHLIBDIR)/$(SLIBNAME_WITH_VERSION)"
92         -$(SLIB_UNINSTALL_EXTRA_CMD)
93         -$(RM) "$(LIBDIR)/$(LIBNAME)"
94
95 uninstall-headers::
96         $(RM) $(addprefix "$(INCINSTDIR)/",$(HEADERS))
97         $(RM) "$(LIBDIR)/pkgconfig/lib$(NAME).pc"
98         -rmdir "$(INCDIR)"
99 endef
100
101 $(eval $(RULES))
102
103 $(EXAMPLES) $(TESTPROGS): $(THIS_LIB) $(DEP_LIBS)
104
105 examples: $(EXAMPLES)
106 testprogs: $(TESTPROGS)