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