diff --git a/Makefile b/Makefile
index 2e257a5593e63002213d8548182dbb99ba29f602..a35c32ae0e9c14bd6f33485e07e7cafd455ee2cf 100644
--- a/Makefile
+++ b/Makefile
@@ -20,8 +20,10 @@ endif
 
 ifeq ($(BUILD_SHARED),yes)
 FFMPEG_LIB=-Llibavcodec -lffmpeg
+DEP_FFMPEG_LIB=
 else
 FFMPEG_LIB=libavcodec/libavcodec.a
+DEP_FFMPEG_LIB=libavcodec/libavcodec.a
 endif
 
 all: lib $(PROG)
@@ -30,10 +32,10 @@ lib:
 	$(MAKE) -C libavcodec all
 	$(MAKE) -C libav all
 
-ffmpeg$(EXE): ffmpeg.o libav/libav.a 
+ffmpeg$(EXE): ffmpeg.o libav/libav.a $(DEP_FFMPEG_LIB)
 	$(CC) $(LDFLAGS) -lm -o $@ $^ $(FFMPEG_LIB)
 
-ffserver$(EXE): ffserver.o libav/libav.a 
+ffserver$(EXE): ffserver.o libav/libav.a $(DEP_FFMPEG_LIB)
 	$(CC) $(LDFLAGS) -lm -o $@ $^ $(FFMPEG_LIB)
 
 ffplay: ffmpeg$(EXE)