f2fs: Update make rules for CM compatibility

* Make sure fsck.f2fs and mkfs.f2fs are built for CM12.1/13.0
* Add CM13.0 rule for relinking mkfs.f2fs
* Minor cleanup of nested if/else in prebuilts

Note on CM SDKs: 3=cm-12.1, 4=cm-13.0
I'm not yet sure whether it is possible that the CMSDK increments
within the same branch of CM.

Change-Id: I7b521159a8b5d0e0ea639f5e0fdd885100612df0
diff --git a/Android.mk b/Android.mk
index 61435c3..6d9959c 100644
--- a/Android.mk
+++ b/Android.mk
@@ -415,6 +415,13 @@
         ntfsfix \
         mkntfs
 endif
+ifeq ($(TARGET_USERIMAGES_USE_F2FS), true)
+ifeq ($(shell test $(CM_PLATFORM_SDK_VERSION) -ge 3; echo $$?),0)
+    LOCAL_ADDITIONAL_DEPENDENCIES += \
+        fsck.f2fs \
+        mkfs.f2fs
+endif
+endif
 
 include $(BUILD_EXECUTABLE)
 
diff --git a/prebuilt/Android.mk b/prebuilt/Android.mk
index 036d602..2160573 100644
--- a/prebuilt/Android.mk
+++ b/prebuilt/Android.mk
@@ -163,14 +163,15 @@
     RELINK_SOURCE_FILES += $(TARGET_OUT_SHARED_LIBRARIES)/libopenaes.so
 endif
 ifeq ($(TARGET_USERIMAGES_USE_F2FS), true)
-    ifneq (,$(filter $(PLATFORM_SDK_VERSION), 23))
+    ifeq ($(shell test $(CM_PLATFORM_SDK_VERSION) -ge 4; echo $$?),0)
+        RELINK_SOURCE_FILES += $(TARGET_OUT_EXECUTABLES)/mkfs.f2fs
+        RELINK_SOURCE_FILES += $(TARGET_OUT_SHARED_LIBRARIES)/libf2fs.so
+    else ifneq (,$(filter $(PLATFORM_SDK_VERSION), 23))
         RELINK_SOURCE_FILES += $(TARGET_RECOVERY_ROOT_OUT)/sbin/mkfs.f2fs
+    else ifneq (,$(filter $(PLATFORM_SDK_VERSION), 21 22))
+        RELINK_SOURCE_FILES += $(TARGET_ROOT_OUT_SBIN)/mkfs.f2fs
     else
-        ifneq (,$(filter $(PLATFORM_SDK_VERSION), 21 22))
-            RELINK_SOURCE_FILES += $(TARGET_ROOT_OUT_SBIN)/mkfs.f2fs
-        else
-            RELINK_SOURCE_FILES += $(TARGET_OUT_EXECUTABLES)/mkfs.f2fs
-        endif
+        RELINK_SOURCE_FILES += $(TARGET_OUT_EXECUTABLES)/mkfs.f2fs
     endif
     RELINK_SOURCE_FILES += $(TARGET_OUT_EXECUTABLES)/fsck.f2fs
 endif