subdir.mak 2.51 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 12 13 14 15 16 17 18 19 20
all: $(SUBDIR)$(LIBNAME)

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

$(SUBDIR)$(LIBNAME): $(OBJS)
	rm -f $@
	$(AR) rc $@ $^ $(EXTRAOBJS)
	$(RANLIB) $@
endif

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

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

Måns Rullgård's avatar
Måns Rullgård committed
23
define RULES
24
$(SUBDIR)%$(EXESUF): $(SUBDIR)%.o
25
	$(LD) $(FFLDFLAGS) -o $$@ $$^ -l$(FULLNAME) $(FFEXTRALIBS) $$(ELIBS)
26 27

$(SUBDIR)%-test.o: $(SUBDIR)%.c
28
	$(CC) $(CPPFLAGS) $(CFLAGS) -DTEST -c -o $$@ $$^
29 30

$(SUBDIR)%-test.o: $(SUBDIR)%-test.c
31
	$(CC) $(CPPFLAGS) $(CFLAGS) -DTEST -c -o $$@ $$^
32 33

$(SUBDIR)x86/%.o: $(SUBDIR)x86/%.asm
34
	$(YASM) $(YASMFLAGS) -I $$(<D)/ -M -o $$@ $$< > $$(@:.o=.d)
35 36 37
	$(YASM) $(YASMFLAGS) -I $$(<D)/ -o $$@ $$<

clean::
38
	rm -f $(addprefix $(SUBDIR),*-example$(EXESUF) *-test$(EXESUF) $(CLEANFILES) $(CLEANSUFFIXES) $(LIBSUFFIXES)) \
39 40
	    $(addprefix $(SUBDIR), $(foreach suffix,$(CLEANSUFFIXES),$(addsuffix /$(suffix),$(DIRS)))) \
	    $(HOSTOBJS) $(HOSTPROGS)
41 42 43 44 45

distclean:: clean
	rm -f  $(addprefix $(SUBDIR),$(DISTCLEANSUFFIXES)) \
            $(addprefix $(SUBDIR), $(foreach suffix,$(DISTCLEANSUFFIXES),$(addsuffix /$(suffix),$(DIRS))))

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

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

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

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

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

install-lib$(NAME)-shared: $(SUBDIR)$(SLIBNAME)
	install -d "$(SHLIBDIR)"
66
	install -m 755 $$< "$(SHLIBDIR)/$(SLIBNAME_WITH_VERSION)"
Måns Rullgård's avatar
Måns Rullgård committed
67 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)
	install -d "$(LIBDIR)"
76
	install -m 644 $$< "$(LIBDIR)"
Måns Rullgård's avatar
Måns Rullgård committed
77 78 79 80 81 82
	$(LIB_INSTALL_EXTRA_CMD)

install-headers::
	install -d "$(INCINSTDIR)"
	install -d "$(LIBDIR)/pkgconfig"
	install -m 644 $(addprefix "$(SRC_DIR)"/,$(HEADERS)) "$(INCINSTDIR)"
83
	install -m 644 $(BUILD_ROOT)/lib$(NAME)/lib$(NAME).pc "$(LIBDIR)/pkgconfig"
Måns Rullgård's avatar
Måns Rullgård committed
84 85 86
endef

$(eval $(RULES))
87

88 89
$(EXAMPLES) $(TESTPROGS): $(THIS_LIB) $(DEP_LIBS)

90 91
examples: $(EXAMPLES)
testprogs: $(TESTPROGS)