Simplify static/shared build rules
[libav.git] / subdir.mak
CommitLineData
71c61f62
MR
1SRC_DIR := $(SRC_PATH_BARE)/lib$(NAME)
2
3include $(SUBDIR)../common.mak
4
5LIBVERSION := $(lib$(NAME)_VERSION)
6LIBMAJOR := $(lib$(NAME)_VERSION_MAJOR)
477b3382
MR
7INCINSTDIR := $(INCDIR)/lib$(NAME)
8THIS_LIB := $(SUBDIR)$($(CONFIG_SHARED:yes=S)LIBNAME)
71c61f62 9
451db983
MR
10all-$(CONFIG_STATIC): $(SUBDIR)$(LIBNAME)
11all-$(CONFIG_SHARED): $(SUBDIR)$(SLIBNAME)
12
8c5239b3
MR
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
2a5500b1 23$(OBJS) $(SUBDIR)%.ho $(SUBDIR)%-test.o $(TESTOBJS): CPPFLAGS += -DHAVE_AV_CONFIG_H
72c2bdeb 24
e273b038 25ifdef CONFIG_STATIC
71c61f62 26$(SUBDIR)$(LIBNAME): $(OBJS)
50e10cbd 27 $(RM) $@
71c61f62
MR
28 $(AR) rc $@ $^ $(EXTRAOBJS)
29 $(RANLIB) $@
30endif
31
56540673
MR
32install-headers: install-lib$(NAME)-headers install-lib$(NAME)-pkgconfig
33
451db983
MR
34install-libs-$(CONFIG_STATIC): install-lib$(NAME)-static
35install-libs-$(CONFIG_SHARED): install-lib$(NAME)-shared
36
71c61f62 37define RULES
3fd422ff 38$(SUBDIR)%$(EXESUF): $(SUBDIR)%.o
63611f31 39 $$(LD) $(FFLDFLAGS) -o $$@ $$^ -l$(FULLNAME) $(FFEXTRALIBS) $$(ELIBS)
3fd422ff 40
3fd422ff 41clean::
50e10cbd 42 $(RM) $(addprefix $(SUBDIR),*-example$(EXESUF) *-test$(EXESUF) $(CLEANFILES) $(CLEANSUFFIXES) $(LIBSUFFIXES)) \
de4070b5
MR
43 $(addprefix $(SUBDIR), $(foreach suffix,$(CLEANSUFFIXES),$(addsuffix /$(suffix),$(DIRS)))) \
44 $(HOSTOBJS) $(HOSTPROGS)
3fd422ff
MR
45
46distclean:: clean
50e10cbd 47 $(RM) $(addprefix $(SUBDIR),$(DISTCLEANSUFFIXES)) \
3fd422ff
MR
48 $(addprefix $(SUBDIR), $(foreach suffix,$(DISTCLEANSUFFIXES),$(addsuffix /$(suffix),$(DIRS))))
49
bea81a52 50ifdef CONFIG_SHARED
71c61f62 51$(SUBDIR)$(SLIBNAME): $(SUBDIR)$(SLIBNAME_WITH_MAJOR)
63611f31 52 $(Q)cd ./$(SUBDIR) && $(LN_S) $(SLIBNAME_WITH_MAJOR) $(SLIBNAME)
71c61f62 53
a482e61b 54$(SUBDIR)$(SLIBNAME_WITH_MAJOR): $(OBJS) $(SUBDIR)lib$(NAME).ver
71c61f62 55 $(SLIB_CREATE_DEF_CMD)
63611f31 56 $$(LD) $(SHFLAGS) $(FFLDFLAGS) -o $$@ $$(filter %.o,$$^) $(FFEXTRALIBS) $(EXTRAOBJS)
71c61f62
MR
57 $(SLIB_EXTRA_CMD)
58
8e255b8b 59ifdef SUBDIR
76ca42a8 60$(SUBDIR)$(SLIBNAME_WITH_MAJOR): $(DEP_LIBS)
71c61f62
MR
61endif
62endif
63
64install-lib$(NAME)-shared: $(SUBDIR)$(SLIBNAME)
63611f31 65 $(Q)mkdir -p "$(SHLIBDIR)"
fd676deb 66 $$(INSTALL) -m 755 $$< "$(SHLIBDIR)/$(SLIBNAME_WITH_VERSION)"
63611f31
MR
67 $$(STRIP) "$(SHLIBDIR)/$(SLIBNAME_WITH_VERSION)"
68 $(Q)cd "$(SHLIBDIR)" && \
71c61f62 69 $(LN_S) $(SLIBNAME_WITH_VERSION) $(SLIBNAME_WITH_MAJOR)
63611f31 70 $(Q)cd "$(SHLIBDIR)" && \
71c61f62 71 $(LN_S) $(SLIBNAME_WITH_VERSION) $(SLIBNAME)
bfca7777 72 $(SLIB_INSTALL_EXTRA_CMD)
63611f31
MR
73
74install-lib$(NAME)-static: MSG = $(LIBDIR)/$(LIBNAME)
75install-lib$(NAME)-shared: MSG = $(LIBDIR)/$(SLIBNAME)
71c61f62
MR
76
77install-lib$(NAME)-static: $(SUBDIR)$(LIBNAME)
63611f31 78 $(Q)mkdir -p "$(LIBDIR)"
fd676deb 79 $$(INSTALL) -m 644 $$< "$(LIBDIR)"
6cfac0e9 80 $(LIB_INSTALL_EXTRA_CMD)
71c61f62 81
34512bca 82install-lib$(NAME)-headers: $(addprefix $(SUBDIR),$(HEADERS) $(BUILT_HEADERS))
63611f31 83 $(Q)mkdir -p "$(INCINSTDIR)"
34512bca
MR
84 $$(INSTALL) -m 644 $$^ "$(INCINSTDIR)"
85
86install-lib$(NAME)-pkgconfig: $(SUBDIR)lib$(NAME).pc
63611f31 87 $(Q)mkdir -p "$(LIBDIR)/pkgconfig"
34512bca 88 $$(INSTALL) -m 644 $$^ "$(LIBDIR)/pkgconfig"
d3cb93b3
RP
89
90uninstall-libs::
50e10cbd 91 -$(RM) "$(SHLIBDIR)/$(SLIBNAME_WITH_MAJOR)" \
d3cb93b3
RP
92 "$(SHLIBDIR)/$(SLIBNAME)" \
93 "$(SHLIBDIR)/$(SLIBNAME_WITH_VERSION)"
94 -$(SLIB_UNINSTALL_EXTRA_CMD)
50e10cbd 95 -$(RM) "$(LIBDIR)/$(LIBNAME)"
d3cb93b3
RP
96
97uninstall-headers::
50e10cbd
MR
98 $(RM) $(addprefix "$(INCINSTDIR)/",$(HEADERS))
99 $(RM) "$(LIBDIR)/pkgconfig/lib$(NAME).pc"
d3cb93b3 100 -rmdir "$(INCDIR)"
71c61f62
MR
101endef
102
103$(eval $(RULES))
3fd422ff 104
bbba084b
MR
105$(EXAMPLES) $(TESTPROGS): $(THIS_LIB) $(DEP_LIBS)
106
3fd422ff
MR
107examples: $(EXAMPLES)
108testprogs: $(TESTPROGS)