build: fix CFLAGS order and LIBS order

_BAD_CFLAGS should always come first, then GST_PLUGINS_BASE_CFLAGS,
then GST_BASE_CFLAGS then GST_CFLAGS. Same for libs: first plugins
base libs, then GST_BASE_LIB then GST_LIBS.
diff --git a/ext/cog/Makefile.am b/ext/cog/Makefile.am
index 595dab7..bbed6fe 100644
--- a/ext/cog/Makefile.am
+++ b/ext/cog/Makefile.am
@@ -5,9 +5,9 @@
 
 libgstcog_la_CFLAGS = \
 	-DCOG_ENABLE_UNSTABLE_API \
+	$(GST_PLUGINS_BAD_CFLAGS) \
 	-I$(srcdir)/.. \
 	$(GST_PLUGINS_BASE_CFLAGS) \
-	$(GST_PLUGINS_BAD_CFLAGS) \
 	$(GST_CFLAGS) \
 	$(ORC_CFLAGS) \
 	$(COG_CFLAGS)
diff --git a/ext/curl/Makefile.am b/ext/curl/Makefile.am
index 4fc6868..42fbe31 100644
--- a/ext/curl/Makefile.am
+++ b/ext/curl/Makefile.am
@@ -2,8 +2,8 @@
 
 libgstcurl_la_SOURCES = gstcurl.c gstcurlsink.c
 libgstcurl_la_CFLAGS = \
-	$(GST_BASE_CFLAGS) \
 	$(GST_PLUGINS_BAD_CFLAGS) \
+	$(GST_BASE_CFLAGS) \
 	$(GST_CFLAGS) \
 	$(CURL_CFLAGS)
 libgstcurl_la_LIBADD = \
diff --git a/ext/gsettings/Makefile.am b/ext/gsettings/Makefile.am
index 2c3abb1..6cef006 100644
--- a/ext/gsettings/Makefile.am
+++ b/ext/gsettings/Makefile.am
@@ -18,7 +18,7 @@
         gstswitchsrc.c \
 	plugin.c
 
-libgstgsettingselements_la_CFLAGS = $(GST_CFLAGS) $(GST_PLUGINS_BAD_CFLAGS) $(GSETTINGS_CFLAGS) $(DIR_CFLAGS) \
+libgstgsettingselements_la_CFLAGS = $(GST_PLUGINS_BAD_CFLAGS) $(GST_CFLAGS) $(GSETTINGS_CFLAGS) $(DIR_CFLAGS) \
 	-DGstSwitchSrc=GstGSettingsSwitchSrc \
 	-DGstSwitchSrcClass=GstGSettingsSwitchSrcClass \
 	-DGstSwitchSink=GstGSettingsSwitchSink \
diff --git a/ext/kate/Makefile.am b/ext/kate/Makefile.am
index d732ffa..4e310d9 100644
--- a/ext/kate/Makefile.am
+++ b/ext/kate/Makefile.am
@@ -9,7 +9,7 @@
 endif
 
 # flags used to compile this plugin
-libgstkate_la_CFLAGS = $(GST_CFLAGS) $(GST_PLUGINS_BASE_CFLAGS) $(GST_PLUGINS_BAD_CFLAGS) $(TIGER_CFLAGS) $(KATE_CFLAGS)
+libgstkate_la_CFLAGS = $(GST_PLUGINS_BAD_CFLAGS) $(GST_PLUGINS_BASE_CFLAGS) $(GST_CFLAGS) $(TIGER_CFLAGS) $(KATE_CFLAGS)
 libgstkate_la_LIBADD = $(GST_PLUGINS_BASE_LIBS) -lgstvideo-$(GST_MAJORMINOR) -lgsttag-$(GST_MAJORMINOR) $(GST_LIBS) $(TIGER_LIBS) $(KATE_LIBS)
 libgstkate_la_LDFLAGS = $(GST_PLUGIN_LDFLAGS)
 libgstkate_la_LIBTOOLFLAGS = --tag=disable-static
diff --git a/ext/mpeg2enc/Makefile.am b/ext/mpeg2enc/Makefile.am
index 32e00c8..ae78a55 100644
--- a/ext/mpeg2enc/Makefile.am
+++ b/ext/mpeg2enc/Makefile.am
@@ -8,7 +8,7 @@
 	gstmpeg2encpicturereader.cc
 
 libgstmpeg2enc_la_CXXFLAGS = \
-	$(GST_PLUGINS_BASE_CFLAGS) $(GST_PLUGINS_BAD_CFLAGS) $(GST_CXXFLAGS) $(MPEG2ENC_CFLAGS)
+	$(GST_PLUGINS_BAD_CFLAGS) $(GST_PLUGINS_BASE_CFLAGS) $(GST_CXXFLAGS) $(MPEG2ENC_CFLAGS)
 libgstmpeg2enc_la_LIBADD = \
 	$(GST_PLUGINS_BASE_LIBS) $(GST_LIBS) $(MPEG2ENC_LIBS)
 libgstmpeg2enc_la_LDFLAGS = $(GST_PLUGIN_LDFLAGS)
diff --git a/ext/mplex/Makefile.am b/ext/mplex/Makefile.am
index 4155d70..741b0d8 100644
--- a/ext/mplex/Makefile.am
+++ b/ext/mplex/Makefile.am
@@ -7,7 +7,7 @@
 	gstmplexoutputstream.cc
 
 libgstmplex_la_CXXFLAGS = \
-	$(GST_PLUGINS_BASE_CFLAGS) $(GST_PLUGINS_BAD_CFLAGS) $(GST_CXXFLAGS) $(MPLEX_CFLAGS)
+	$(GST_PLUGINS_BAD_CFLAGS) $(GST_PLUGINS_BASE_CFLAGS) $(GST_CXXFLAGS) $(MPLEX_CFLAGS)
 libgstmplex_la_LIBADD = \
 	$(GST_PLUGINS_BASE_LIBS) $(GST_BASE_LIBS) $(GST_LIBS) $(MPLEX_LIBS)
 libgstmplex_la_LDFLAGS = $(GST_PLUGIN_LDFLAGS) $(MPLEX_LDFLAGS)
diff --git a/ext/opus/Makefile.am b/ext/opus/Makefile.am
index 1aaed79..48a7ead 100644
--- a/ext/opus/Makefile.am
+++ b/ext/opus/Makefile.am
@@ -3,14 +3,13 @@
 libgstopus_la_SOURCES = gstopus.c gstopusdec.c gstopusenc.c gstopusparse.c gstopusheader.c gstopuscommon.c gstrtpopuspay.c gstrtpopusdepay.c
 libgstopus_la_CFLAGS = \
         -DGST_USE_UNSTABLE_API \
-	$(GST_PLUGINS_BASE_CFLAGS) \
 	$(GST_PLUGINS_BAD_CFLAGS) \
+	$(GST_PLUGINS_BASE_CFLAGS) \
 	$(GST_CFLAGS) \
 	$(OPUS_CFLAGS)
 libgstopus_la_LIBADD = \
-	-lgstaudio-$(GST_MAJORMINOR) \
-	$(GST_PLUGINS_BASE_LIBS) -lgsttag-$(GST_MAJORMINOR) \
-    -lgstrtp-@GST_MAJORMINOR@ \
+	$(GST_PLUGINS_BASE_LIBS) -lgstaudio-$(GST_MAJORMINOR) \
+	-lgsttag-$(GST_MAJORMINOR) -lgstrtp-$(GST_MAJORMINOR) \
 	$(GST_BASE_LIBS) \
 	$(GST_LIBS) \
 	$(OPUS_LIBS)
diff --git a/ext/sdl/Makefile.am b/ext/sdl/Makefile.am
index ce027dd..6bc4264 100644
--- a/ext/sdl/Makefile.am
+++ b/ext/sdl/Makefile.am
@@ -5,7 +5,7 @@
 	sdlvideosink.c \
 	sdlaudiosink.c
 
-libgstsdl_la_CFLAGS =  $(GST_PLUGINS_BASE_CFLAGS) $(GST_PLUGINS_BAD_CFLAGS) $(GST_CFLAGS) $(SDL_CFLAGS)
+libgstsdl_la_CFLAGS =  $(GST_PLUGINS_BAD_CFLAGS) $(GST_PLUGINS_BASE_CFLAGS) $(GST_CFLAGS) $(SDL_CFLAGS)
 libgstsdl_la_LIBADD =  $(GST_PLUGINS_BASE_LIBS) \
 				-lgstvideo-$(GST_MAJORMINOR) \
 				-lgstaudio-$(GST_MAJORMINOR) \
diff --git a/gst/hls/Makefile.am b/gst/hls/Makefile.am
index 19fd621..fec8eeb 100644
--- a/gst/hls/Makefile.am
+++ b/gst/hls/Makefile.am
@@ -6,8 +6,8 @@
 	gsthlsdemux.c				\
 	gstfragmentedplugin.c
 
-libgstfragmented_la_CFLAGS = $(GST_CFLAGS) $(GST_BASE_CFLAGS) $(GST_PLUGINS_BAD_CFLAGS) $(SOUP_CFLAGS)
-libgstfragmented_la_LIBADD = $(GST_LIBS) $(GST_BASE_LIBS) $(SOUP_LIBS)
+libgstfragmented_la_CFLAGS = $(GST_PLUGINS_BAD_CFLAGS) $(GST_BASE_CFLAGS) $(GST_CFLAGS) $(SOUP_CFLAGS)
+libgstfragmented_la_LIBADD = $(GST_BASE_LIBS) $(GST_LIBS) $(SOUP_LIBS)
 libgstfragmented_la_LDFLAGS = $(GST_PLUGIN_LDFLAGS) -no-undefined
 libgstfragmented_la_LIBTOOLFLAGS = --tag=disable-static
 
diff --git a/gst/inter/Makefile.am b/gst/inter/Makefile.am
index d6749a5..e404959 100644
--- a/gst/inter/Makefile.am
+++ b/gst/inter/Makefile.am
@@ -22,15 +22,15 @@
 	gstintersurface.h
 
 libgstinter_la_CFLAGS = \
-	$(GST_CFLAGS) \
-	$(GST_PLUGINS_BASE_CFLAGS) \
 	$(GST_PLUGINS_BAD_CFLAGS) \
-	$(GST_BASE_CFLAGS)
+	$(GST_PLUGINS_BASE_CFLAGS) \
+	$(GST_BASE_CFLAGS) \
+	$(GST_CFLAGS)
 
 libgstinter_la_LIBADD = \
-	$(GST_LIBS) \
-	$(GST_BASE_LIBS) \
 	$(GST_PLUGINS_BASE_LIBS) -lgstvideo-@GST_MAJORMINOR@ -lgstaudio-@GST_MAJORMINOR@ \
+	$(GST_BASE_LIBS) \
+	$(GST_LIBS) \
 	$(LIBM)
 
 libgstinter_la_LDFLAGS = $(GST_PLUGIN_LDFLAGS)
@@ -40,13 +40,13 @@
 	gstintertest.c
 
 gstintertest_CFLAGS = \
-	$(GST_CFLAGS) \
+	$(GST_PLUGINS_BAD_CFLAGS) \
 	$(GST_PLUGINS_BASE_CFLAGS) \
-	$(GST_PLUGINS_BAD_CFLAGS)
+	$(GST_CFLAGS)
 
 gstintertest_LDADD = \
-	$(GST_LIBS) \
 	$(GST_PLUGINS_BASE_LIBS) \
+	$(GST_LIBS) \
 	$(LIBM)
 
 Android.mk: Makefile.am $(BUILT_SOURCES)
diff --git a/gst/liveadder/Makefile.am b/gst/liveadder/Makefile.am
index 14f490d..0bbeff9 100644
--- a/gst/liveadder/Makefile.am
+++ b/gst/liveadder/Makefile.am
@@ -1,7 +1,7 @@
 plugin_LTLIBRARIES = libgstliveadder.la
 
 libgstliveadder_la_SOURCES = liveadder.c
-libgstliveadder_la_CFLAGS = $(GST_PLUGINS_BASE_CFLAGS) $(GST_PLUGINS_BAD_CFLAGS) $(GST_CFLAGS)
+libgstliveadder_la_CFLAGS = $(GST_PLUGINS_BAD_CFLAGS) $(GST_PLUGINS_BASE_CFLAGS) $(GST_CFLAGS)
 libgstliveadder_la_LIBADD = \
 	$(GST_PLUGINS_BASE_LIBS) -lgstaudio-@GST_MAJORMINOR@ \
 	$(GST_BASE_LIBS) $(GST_LIBS)
diff --git a/gst/mve/Makefile.am b/gst/mve/Makefile.am
index 2c3104f..8be4517 100644
--- a/gst/mve/Makefile.am
+++ b/gst/mve/Makefile.am
@@ -1,6 +1,6 @@
 plugin_LTLIBRARIES = libgstmve.la
 
-libgstmve_la_CFLAGS = $(GST_BASE_CFLAGS) $(GST_PLUGINS_BAD_CFLAGS) $(GST_CFLAGS)
+libgstmve_la_CFLAGS = $(GST_PLUGINS_BAD_CFLAGS) $(GST_BASE_CFLAGS) $(GST_CFLAGS)
 libgstmve_la_LIBADD = $(GST_BASE_LIBS) $(GST_LIBS) $(LIBM)
 libgstmve_la_LDFLAGS = $(GST_PLUGIN_LDFLAGS)
 libgstmve_la_LIBTOOLFLAGS = --tag=disable-static
diff --git a/sys/decklink/Makefile.am b/sys/decklink/Makefile.am
index 94dbb09..22863ed 100644
--- a/sys/decklink/Makefile.am
+++ b/sys/decklink/Makefile.am
@@ -1,8 +1,8 @@
 plugin_LTLIBRARIES = libgstdecklink.la
 
 libgstdecklink_la_CPPFLAGS = \
-	$(GST_BASE_CFLAGS) \
 	$(GST_PLUGINS_BAD_CFLAGS) \
+	$(GST_BASE_CFLAGS) \
 	$(GST_CXXFLAGS) \
 	$(DECKLINK_CXXFLAGS)
 libgstdecklink_la_LIBADD = \
diff --git a/sys/shm/Makefile.am b/sys/shm/Makefile.am
index 59a1e3b..f62e20e 100644
--- a/sys/shm/Makefile.am
+++ b/sys/shm/Makefile.am
@@ -5,9 +5,9 @@
 plugin_LTLIBRARIES = libgstshm.la
 
 libgstshm_la_SOURCES = shmpipe.c shmalloc.c gstshm.c gstshmsrc.c gstshmsink.c
-libgstshm_la_CFLAGS = $(GST_CFLAGS) $(GST_PLUGINS_BAD_CFLAGS) -DSHM_PIPE_USE_GLIB
+libgstshm_la_CFLAGS = $(GST_PLUGINS_BAD_CFLAGS) $(GST_CFLAGS) -DSHM_PIPE_USE_GLIB
 libgstshm_la_LIBADD = -lrt
-libgstshm_la_LDFLAGS = $(GST_PLUGIN_LDFLAGS) $(GST_BASE_LIBS) $(GST_PLUGINS_BASE_LIBS)
+libgstshm_la_LDFLAGS = $(GST_PLUGIN_LDFLAGS) $(GST_BASE_LIBS)
 libgstshm_la_LIBTOOLFLAGS = --tag=disable-static
 
 noinst_HEADERS = gstshmsrc.h gstshmsink.h shmpipe.h  shmalloc.h
diff --git a/tests/examples/scaletempo/Makefile.am b/tests/examples/scaletempo/Makefile.am
index 500e511..aec2f29 100644
--- a/tests/examples/scaletempo/Makefile.am
+++ b/tests/examples/scaletempo/Makefile.am
@@ -1,8 +1,8 @@
 noinst_PROGRAMS = scaletempo-demo
 
 scaletempo_demo_SOURCES = demo-main.c demo-player.c demo-gui.c
-scaletempo_demo_CFLAGS = $(GST_CFLAGS) $(GST_PLUGINS_BASE_CFLAGS) $(GST_PLUGINS_BAD_CFLAGS) $(GTK_CFLAGS) 
-scaletempo_demo_LDFLAGS = $(GST_LIBS) $(GST_PLUGINS_BASE_LIBS) $(GTK_LIBS) -lgstinterfaces-@GST_MAJORMINOR@
+scaletempo_demo_CFLAGS = $(GST_PLUGINS_BAD_CFLAGS) $(GST_PLUGINS_BASE_CFLAGS) $(GST_CFLAGS) $(GTK_CFLAGS)
+scaletempo_demo_LDFLAGS = $(GST_PLUGINS_BASE_LIBS) -lgstinterfaces-@GST_MAJORMINOR@ $(GST_LIBS) $(GTK_LIBS)
 
 noinst_HEADERS = demo-player.h demo-gui.h