subdir.mak 2.86 KB
Newer Older
Måns Rullgård's avatar
Måns Rullgård committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
SRC_DIR := $(SRC_PATH_BARE)/lib$(NAME)

include $(SUBDIR)../common.mak

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

ifeq ($(BUILD_STATIC),yes)
all: $(SUBDIR)$(LIBNAME)

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

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

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

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

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 34 35 36 37 38 39

$(SUBDIR)x86/%.o: $(SUBDIR)x86/%.asm
	$(YASM) $(YASMFLAGS) -I $$(<D)/ -o $$@ $$<

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

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

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

47
ifdef BUILD_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)
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 66
endif
endif

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

install-headers::
	install -d "$(INCINSTDIR)"
	install -d "$(LIBDIR)/pkgconfig"
	install -m 644 $(addprefix "$(SRC_DIR)"/,$(HEADERS)) "$(INCINSTDIR)"
84
	install -m 644 $(BUILD_ROOT)/lib$(NAME)/lib$(NAME).pc "$(LIBDIR)/pkgconfig"
Måns Rullgård's avatar
Måns Rullgård committed
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99

uninstall-libs::
	-rm -f "$(SHLIBDIR)/$(SLIBNAME_WITH_MAJOR)" \
	       "$(SHLIBDIR)/$(SLIBNAME)"            \
	       "$(SHLIBDIR)/$(SLIBNAME_WITH_VERSION)"
	-$(SLIB_UNINSTALL_EXTRA_CMD)
	-rm -f "$(LIBDIR)/$(LIBNAME)"

uninstall-headers::
	rm -f $(addprefix "$(INCINSTDIR)/",$(HEADERS))
	rm -f "$(LIBDIR)/pkgconfig/lib$(NAME).pc"
	-rmdir "$(INCDIR)"
endef

$(eval $(RULES))
100

101 102
$(EXAMPLES) $(TESTPROGS): $(THIS_LIB) $(DEP_LIBS)

103 104
examples: $(EXAMPLES)
testprogs: $(TESTPROGS)