Improve linker check for Winsock library name.
[ffmpeg.git] / subdir.mak
index f78d3cb..65d9c6f 100644 (file)
@@ -18,7 +18,32 @@ endif
 
 INCINSTDIR := $(INCDIR)/lib$(NAME)
 
+THIS_LIB := $(SUBDIR)$($(BUILD_SHARED:yes=S)LIBNAME)
+
 define RULES
+$(SUBDIR)%$(EXESUF): $(SUBDIR)%.o
+       $(LD) $(FFLDFLAGS) -o $$@ $$^ -l$(FULLNAME) $(FFEXTRALIBS) $$(ELIBS)
+
+$(SUBDIR)%-test.o: $(SUBDIR)%.c
+       $(CC) $(CFLAGS) -DTEST -c -o $$@ $$^
+
+$(SUBDIR)%-test.o: $(SUBDIR)%-test.c
+       $(CC) $(CFLAGS) -DTEST -c -o $$@ $$^
+
+$(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::
+       rm -f $(addprefix $(SUBDIR),*-example$(EXESUF) *-test$(EXESUF) $(CLEANFILES) $(CLEANSUFFIXES) $(LIBSUFFIXES)) \
+           $(addprefix $(SUBDIR), $(foreach suffix,$(CLEANSUFFIXES),$(addsuffix /$(suffix),$(DIRS))))
+
+distclean:: clean
+       rm -f  $(addprefix $(SUBDIR),$(DISTCLEANSUFFIXES)) \
+            $(addprefix $(SUBDIR), $(foreach suffix,$(DISTCLEANSUFFIXES),$(addsuffix /$(suffix),$(DIRS))))
+
 ifdef BUILD_SHARED
 all: $(SUBDIR)$(SLIBNAME)
 
@@ -29,18 +54,17 @@ $(SUBDIR)$(SLIBNAME): $(SUBDIR)$(SLIBNAME_WITH_MAJOR)
 
 $(SUBDIR)$(SLIBNAME_WITH_MAJOR): $(OBJS)
        $(SLIB_CREATE_DEF_CMD)
-       $(CC) $(SHFLAGS) $(FFLDFLAGS) -o $$@ $$^ $(FFEXTRALIBS) $(EXTRAOBJS)
+       $(LD) $(SHFLAGS) $(FFLDFLAGS) -o $$@ $$(filter %.o,$$^) $(FFEXTRALIBS) $(EXTRAOBJS)
        $(SLIB_EXTRA_CMD)
 
 ifdef SUBDIR
-$(SUBDIR)$(SLIBNAME_WITH_MAJOR): \
-    $(foreach NAME,$(FFLIBS),lib$(NAME)/$(SLIBNAME))
+$(SUBDIR)$(SLIBNAME_WITH_MAJOR): $(DEP_LIBS)
 endif
 endif
 
 install-lib$(NAME)-shared: $(SUBDIR)$(SLIBNAME)
        install -d "$(SHLIBDIR)"
-       install -m 755 $(SUBDIR)$(SLIBNAME) "$(SHLIBDIR)/$(SLIBNAME_WITH_VERSION)"
+       install -m 755 $$< "$(SHLIBDIR)/$(SLIBNAME_WITH_VERSION)"
        $(STRIP) "$(SHLIBDIR)/$(SLIBNAME_WITH_VERSION)"
        cd "$(SHLIBDIR)" && \
                $(LN_S) $(SLIBNAME_WITH_VERSION) $(SLIBNAME_WITH_MAJOR)
@@ -50,14 +74,14 @@ install-lib$(NAME)-shared: $(SUBDIR)$(SLIBNAME)
 
 install-lib$(NAME)-static: $(SUBDIR)$(LIBNAME)
        install -d "$(LIBDIR)"
-       install -m 644 $(SUBDIR)$(LIBNAME) "$(LIBDIR)"
+       install -m 644 $$< "$(LIBDIR)"
        $(LIB_INSTALL_EXTRA_CMD)
 
 install-headers::
        install -d "$(INCINSTDIR)"
        install -d "$(LIBDIR)/pkgconfig"
        install -m 644 $(addprefix "$(SRC_DIR)"/,$(HEADERS)) "$(INCINSTDIR)"
-       install -m 644 $(BUILD_ROOT)/lib$(NAME).pc "$(LIBDIR)/pkgconfig"
+       install -m 644 $(BUILD_ROOT)/lib$(NAME)/lib$(NAME).pc "$(LIBDIR)/pkgconfig"
 
 uninstall-libs::
        -rm -f "$(SHLIBDIR)/$(SLIBNAME_WITH_MAJOR)" \
@@ -73,3 +97,8 @@ uninstall-headers::
 endef
 
 $(eval $(RULES))
+
+$(EXAMPLES) $(TESTPROGS): $(THIS_LIB) $(DEP_LIBS)
+
+examples: $(EXAMPLES)
+testprogs: $(TESTPROGS)