build: Skip generating .version files when cleaning
[ffmpeg.git] / ffbuild / library.mak
1 include $(SRC_PATH)/ffbuild/common.mak
2
3 ifeq (,$(filter %clean,$(MAKECMDGOALS)))
4 -include $(SUBDIR)lib$(NAME).version
5 endif
6
7 LIBVERSION := $(lib$(NAME)_VERSION)
8 LIBMAJOR   := $(lib$(NAME)_VERSION_MAJOR)
9 LIBMINOR   := $(lib$(NAME)_VERSION_MINOR)
10 INCINSTDIR := $(INCDIR)/lib$(NAME)
11
12 INSTHEADERS := $(INSTHEADERS) $(HEADERS:%=$(SUBDIR)%)
13
14 all-$(CONFIG_STATIC): $(SUBDIR)$(LIBNAME)  $(SUBDIR)lib$(FULLNAME).pc
15 all-$(CONFIG_SHARED): $(SUBDIR)$(SLIBNAME) $(SUBDIR)lib$(FULLNAME).pc
16
17 LIBOBJS := $(OBJS) $(SUBDIR)%.h.o $(TESTOBJS)
18 $(LIBOBJS) $(LIBOBJS:.o=.s) $(LIBOBJS:.o=.i):   CPPFLAGS += -DHAVE_AV_CONFIG_H
19 $(TESTOBJS) $(TESTOBJS:.o=.i): CFLAGS += -Umain
20
21 $(SUBDIR)$(LIBNAME): $(OBJS)
22         $(RM) $@
23         $(AR) $(ARFLAGS) $(AR_O) $^
24         $(RANLIB) $@
25
26 install-headers: install-lib$(NAME)-headers install-lib$(NAME)-pkgconfig
27
28 install-libs-$(CONFIG_STATIC): install-lib$(NAME)-static
29 install-libs-$(CONFIG_SHARED): install-lib$(NAME)-shared
30
31 define RULES
32 $(TOOLS):     THISLIB = $(FULLNAME:%=$(LD_LIB))
33 $(TESTPROGS): THISLIB = $(SUBDIR)$(LIBNAME)
34
35 $(TESTPROGS) $(TOOLS): %$(EXESUF): %.o
36         $$(LD) $(LDFLAGS) $(LDEXEFLAGS) $$(LD_O) $$(filter %.o,$$^) $$(THISLIB) $(FFEXTRALIBS) $$(ELIBS)
37
38 $(SUBDIR)lib$(NAME).version: $(SUBDIR)version.h | $(SUBDIR)
39         $$(M) $$(SRC_PATH)/ffbuild/libversion.sh $(NAME) $$< > $$@
40
41 $(SUBDIR)lib$(FULLNAME).pc: $(SUBDIR)version.h | $(SUBDIR)
42         $$(M) $$(SRC_PATH)/ffbuild/pkgconfig_generate.sh $(NAME) "$(DESC)"
43
44 $(SUBDIR)lib$(NAME).ver: $(SUBDIR)lib$(NAME).v $(OBJS)
45         $$(M)sed 's/MAJOR/$(lib$(NAME)_VERSION_MAJOR)/' $$< | $(VERSION_SCRIPT_POSTPROCESS_CMD) > $$@
46
47 $(SUBDIR)$(SLIBNAME): $(SUBDIR)$(SLIBNAME_WITH_MAJOR)
48         $(Q)cd ./$(SUBDIR) && $(LN_S) $(SLIBNAME_WITH_MAJOR) $(SLIBNAME)
49
50 $(SUBDIR)$(SLIBNAME_WITH_MAJOR): $(OBJS) $(SLIBOBJS) $(SUBDIR)lib$(NAME).ver
51         $(SLIB_CREATE_DEF_CMD)
52         $$(LD) $(SHFLAGS) $(LDFLAGS) $(LDLIBFLAGS) $$(LD_O) $$(filter %.o,$$^) $(FFEXTRALIBS)
53         $(SLIB_EXTRA_CMD)
54
55 ifdef SUBDIR
56 $(SUBDIR)$(SLIBNAME_WITH_MAJOR): $(DEP_LIBS)
57 endif
58
59 clean::
60         $(RM) $(addprefix $(SUBDIR),$(CLEANFILES) $(CLEANSUFFIXES) $(LIBSUFFIXES)) \
61             $(CLEANSUFFIXES:%=$(SUBDIR)$(ARCH)/%) $(CLEANSUFFIXES:%=$(SUBDIR)tests/%)
62
63 distclean:: clean
64         $(RM) $(DISTCLEANSUFFIXES:%=$(SUBDIR)%) $(DISTCLEANSUFFIXES:%=$(SUBDIR)$(ARCH)/%) \
65             $(DISTCLEANSUFFIXES:%=$(SUBDIR)tests/%)
66
67 install-lib$(NAME)-shared: $(SUBDIR)$(SLIBNAME)
68         $(Q)mkdir -p "$(SHLIBDIR)"
69         $$(INSTALL) -m 755 $$< "$(SHLIBDIR)/$(SLIB_INSTALL_NAME)"
70         $$(STRIP) "$(SHLIBDIR)/$(SLIB_INSTALL_NAME)"
71         $(Q)$(foreach F,$(SLIB_INSTALL_LINKS),(cd "$(SHLIBDIR)" && $(LN_S) $(SLIB_INSTALL_NAME) $(F));)
72         $(if $(SLIB_INSTALL_EXTRA_SHLIB),$$(INSTALL) -m 644 $(SLIB_INSTALL_EXTRA_SHLIB:%=$(SUBDIR)%) "$(SHLIBDIR)")
73         $(if $(SLIB_INSTALL_EXTRA_LIB),$(Q)mkdir -p "$(LIBDIR)")
74         $(if $(SLIB_INSTALL_EXTRA_LIB),$$(INSTALL) -m 644 $(SLIB_INSTALL_EXTRA_LIB:%=$(SUBDIR)%) "$(LIBDIR)")
75
76 install-lib$(NAME)-static: $(SUBDIR)$(LIBNAME)
77         $(Q)mkdir -p "$(LIBDIR)"
78         $$(INSTALL) -m 644 $$< "$(LIBDIR)"
79         $(LIB_INSTALL_EXTRA_CMD)
80
81 install-lib$(NAME)-headers: $(addprefix $(SUBDIR),$(HEADERS) $(BUILT_HEADERS))
82         $(Q)mkdir -p "$(INCINSTDIR)"
83         $$(INSTALL) -m 644 $$^ "$(INCINSTDIR)"
84
85 install-lib$(NAME)-pkgconfig: $(SUBDIR)lib$(FULLNAME).pc
86         $(Q)mkdir -p "$(PKGCONFIGDIR)"
87         $$(INSTALL) -m 644 $$^ "$(PKGCONFIGDIR)"
88
89 uninstall-libs::
90         -$(RM) "$(SHLIBDIR)/$(SLIBNAME_WITH_MAJOR)" \
91                "$(SHLIBDIR)/$(SLIBNAME)"            \
92                "$(SHLIBDIR)/$(SLIBNAME_WITH_VERSION)"
93         -$(RM)  $(SLIB_INSTALL_EXTRA_SHLIB:%="$(SHLIBDIR)/%")
94         -$(RM)  $(SLIB_INSTALL_EXTRA_LIB:%="$(LIBDIR)/%")
95         -$(RM) "$(LIBDIR)/$(LIBNAME)"
96
97 uninstall-headers::
98         $(RM) $(addprefix "$(INCINSTDIR)/",$(HEADERS) $(BUILT_HEADERS))
99         $(RM) "$(PKGCONFIGDIR)/lib$(FULLNAME).pc"
100         -rmdir "$(INCINSTDIR)"
101 endef
102
103 $(eval $(RULES))
104
105 $(TOOLS):     $(DEP_LIBS) $(SUBDIR)$($(CONFIG_SHARED:yes=S)LIBNAME)
106 $(TESTPROGS): $(DEP_LIBS) $(SUBDIR)$(LIBNAME)
107
108 testprogs: $(TESTPROGS)