diff --git a/Makefile b/Makefile
index 7c2cd937f2dfbca4560db59f3ff84ba91c6591dc..19cf90669dd0b44b73b9ccf34d29b985bd06c4da 100644
--- a/Makefile
+++ b/Makefile
@@ -44,13 +44,13 @@ endif
 endif
 
 ifeq ($(CONFIG_LIBOGG),yes)
-EXTRALIBS+= -logg 
 ifeq ($(CONFIG_LIBVORBIS),yes)
-EXTRALIBS+= -lvorbis -lvorbisenc
+EXTRALIBS+= -lvorbisenc -lvorbis
 endif
 ifeq ($(CONFIG_LIBTHEORA),yes)
 EXTRALIBS+= -ltheora
 endif
+EXTRALIBS+= -logg
 endif
 
 ifeq ($(CONFIG_FAAD),yes)
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index c15e2761c41209674ea4ed6343ae65f34a9574c3..8a966706c2b4fa56ace67ce1d6493dc8a75c399e 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -125,15 +125,15 @@ EXTRALIBS += -lmp3lame
 endif
 
 ifeq ($(CONFIG_LIBOGG),yes)
-EXTRALIBS += -logg
 ifeq ($(CONFIG_LIBVORBIS),yes)
 OBJS += oggvorbis.o
-EXTRALIBS += -lvorbis -lvorbisenc
+EXTRALIBS += -lvorbisenc -lvorbis
 endif
 ifeq ($(CONFIG_LIBTHEORA), yes)
 OBJS += oggtheora.o
 EXTRALIBS += -ltheora
 endif
+EXTRALIBS += -logg
 endif
 
 ifeq ($(TARGET_GPROF),yes)