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

include $(SUBDIR)../common.mak

LIBVERSION := $(lib$(NAME)_VERSION)
LIBMAJOR   := $(lib$(NAME)_VERSION_MAJOR)

Måns Rullgård's avatar
Måns Rullgård committed
8
ifdef CONFIG_STATIC
Måns Rullgård's avatar
Måns Rullgård committed
9 10 11
all: $(SUBDIR)$(LIBNAME)

install-libs: install-lib$(NAME)-static
12
install-headers: install-lib$(NAME)-headers install-lib$(NAME)-pkgconfig
Måns Rullgård's avatar
Måns Rullgård committed
13 14

$(SUBDIR)$(LIBNAME): $(OBJS)
Måns Rullgård's avatar
Måns Rullgård committed
15
	$(RM) $@
Måns Rullgård's avatar
Måns Rullgård committed
16 17 18 19 20 21
	$(AR) rc $@ $^ $(EXTRAOBJS)
	$(RANLIB) $@
endif

INCINSTDIR := $(INCDIR)/lib$(NAME)

22
THIS_LIB := $(SUBDIR)$($(CONFIG_SHARED:yes=S)LIBNAME)
23

Måns Rullgård's avatar
Måns Rullgård committed
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 37 38
	$(YASM) $(YASMFLAGS) -I $$(<D)/ -o $$@ $$<

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

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

47
ifdef CONFIG_SHARED
Måns Rullgård's avatar
Måns Rullgård committed
48 49 50 51 52 53 54
all: $(SUBDIR)$(SLIBNAME)

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

$(SUBDIR)$(SLIBNAME): $(SUBDIR)$(SLIBNAME_WITH_MAJOR)
	cd ./$(SUBDIR) && $(LN_S) $(SLIBNAME_WITH_MAJOR) $(SLIBNAME)

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

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

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

install-lib$(NAME)-static: $(SUBDIR)$(LIBNAME)
76
	mkdir -p "$(LIBDIR)"
77
	$$(INSTALL) -m 644 $$< "$(LIBDIR)"
Måns Rullgård's avatar
Måns Rullgård committed
78 79
	$(LIB_INSTALL_EXTRA_CMD)

80
install-lib$(NAME)-headers: $(addprefix $(SUBDIR),$(HEADERS) $(BUILT_HEADERS))
81
	mkdir -p "$(INCINSTDIR)"
82 83 84
	$$(INSTALL) -m 644 $$^ "$(INCINSTDIR)"

install-lib$(NAME)-pkgconfig: $(SUBDIR)lib$(NAME).pc
85
	mkdir -p "$(LIBDIR)/pkgconfig"
86
	$$(INSTALL) -m 644 $$^ "$(LIBDIR)/pkgconfig"
Ramiro Polla's avatar
Ramiro Polla committed
87 88

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

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

$(eval $(RULES))
102

103 104
$(EXAMPLES) $(TESTPROGS): $(THIS_LIB) $(DEP_LIBS)

105 106
examples: $(EXAMPLES)
testprogs: $(TESTPROGS)