Merge commit 'remotes/korg/cupcake'
diff --git a/config/en.us/Android.mk b/config/en.us/Android.mk
index 931b431..8f6d80c 100644
--- a/config/en.us/Android.mk
+++ b/config/en.us/Android.mk
@@ -32,6 +32,9 @@
 DEFAULT_PAR=$(ASR_ROOT_DIR)/config/en.us/baseline11k.par
 G2G_INSTALL_PATH=$(TARGET_OUT)/usr/srec/config/en.us/grammars
 
+# XXX: to use grxmlcompile and make_g2g we need either exec ldconfig or
+#    use LD_LIBRARY_PATH variable
+
 srec_grammars : \
 	$(G2G_INSTALL_PATH)/enroll.g2g \
 	$(G2G_INSTALL_PATH)/bothtags5.g2g \
@@ -55,8 +58,10 @@
 # This needs an explicit rule to specify the vocabulary (dictionary)
 $(G2G_INSTALL_PATH)/enroll.g2g: $(LOCAL_PATH)/grammars/enroll.grxml $(GRXML) $(MAKE_G2G) $(DEFAULT_PAR) $(LOCAL_PATH)/dictionary/enroll.ok
 	mkdir -p $(G2G_INSTALL_PATH)
-	$(GRXML) -par $(DEFAULT_PAR) -grxml $< -vocab dictionary/enroll.ok -outdir $(G2G_INSTALL_PATH)
-	$(MAKE_G2G) -base $(G2G_INSTALL_PATH)/enroll,addWords=0 -out $@
+	$(hide) ( \
+	export LD_LIBRARY_PATH=$(HOST_OUT_SHARED_LIBRARIES) \
+	&& $(GRXML) -par $(DEFAULT_PAR) -grxml $< -vocab dictionary/enroll.ok -outdir $(G2G_INSTALL_PATH) \
+	&& $(MAKE_G2G) -base $(G2G_INSTALL_PATH)/enroll,addWords=0 -out $@ )
 	(cd $(G2G_INSTALL_PATH); rm -f $*.Grev2.det.txt $*.map $*.omap $*.P.txt $*.params $*.PCLG.txt $*.script)
 
 
@@ -66,8 +71,10 @@
 
 $(G2G_INSTALL_PATH)/%.g2g: $(LOCAL_PATH)/grammars/%.grxml $(GRXML) $(MAKE_G2G) $(DEFAULT_PAR) $(LOCAL_PATH)/dictionary/cmu6plus.ok.zip
 	mkdir -p $(G2G_INSTALL_PATH)
-	$(GRXML) -par $(DEFAULT_PAR) -grxml $< -outdir $(G2G_INSTALL_PATH)
-	$(MAKE_G2G) -base $(G2G_INSTALL_PATH)/$*,addWords=0 -out $@
+	$(hide) ( \
+	export LD_LIBRARY_PATH=$(HOST_OUT_SHARED_LIBRARIES) \
+	&& $(GRXML) -par $(DEFAULT_PAR) -grxml $< -outdir $(G2G_INSTALL_PATH) \
+	&& $(MAKE_G2G) -base $(G2G_INSTALL_PATH)/$*,addWords=0 -out $@ )
 	(cd $(G2G_INSTALL_PATH); rm -f $*.Grev2.det.txt $*.map $*.omap $*.P.txt $*.params $*.PCLG.txt $*.script)
 
 
diff --git a/tools/grxmlcompile/Android.mk b/tools/grxmlcompile/Android.mk
index 4661b43..7b00cee 100644
--- a/tools/grxmlcompile/Android.mk
+++ b/tools/grxmlcompile/Android.mk
@@ -68,8 +68,12 @@
 
 LOCAL_LDLIBS := \
 	-lm \
-	-lpthread \
-	-ldl \
+	-lpthread
+
+ifeq ($(HOST_OS),freebsd)
+else
+	LOCAL_LDLIBS += -ldl
+endif
 
 LOCAL_MODULE:= grxmlcompile
 
diff --git a/tools/thirdparty/OpenFst/fst/lib/compat.h b/tools/thirdparty/OpenFst/fst/lib/compat.h
index 4c27ee3..8b3ee0a 100644
--- a/tools/thirdparty/OpenFst/fst/lib/compat.h
+++ b/tools/thirdparty/OpenFst/fst/lib/compat.h
@@ -33,6 +33,7 @@
 #include <sys/stat.h>
 #include <sys/types.h>
 #include <unistd.h>
+#include <string.h>
 
 // exact size types
 typedef short int16;