[OpenWrt-Devel,8/8] tools/mtd-utils: add cygwin compatibility
diff mbox series

Message ID 20191008010225.8822-8-rosenp@gmail.com
State Rejected
Delegated to: Petr Štetiar
Headers show
Series
  • [OpenWrt-Devel,1/8] ncurses: add cygwin compatibility
Related show

Commit Message

Rosen Penev Oct. 8, 2019, 1:02 a.m. UTC
From: Alexey Loukianov <lx2@lexa2.ru>

* Add blkpg.h linux header (not available under cygwin) and
  patch types.h to reflect cygwin specifics.
* Define __USE_LINUX_IOCTL_DEFS under cygwin.
* Properly handle ".exe" suffix in package makefile.

Signed-off-by: Alexey Loukianov <lx2@lexa2.ru>
Signed-off-by: Rosen Penev <rosenp@gmail.com>
---
 tools/mtd-utils/Makefile              | 17 ++++++++++++-
 tools/mtd-utils/include/linux/blkpg.h | 35 +++++++++++++++++++++++++++
 tools/mtd-utils/include/linux/types.h |  6 +++++
 3 files changed, 57 insertions(+), 1 deletion(-)
 create mode 100644 tools/mtd-utils/include/linux/blkpg.h

Patch
diff mbox series

diff --git a/tools/mtd-utils/Makefile b/tools/mtd-utils/Makefile
index e0e083d2b6..8a7ee06b62 100644
--- a/tools/mtd-utils/Makefile
+++ b/tools/mtd-utils/Makefile
@@ -18,6 +18,7 @@  PKG_FIXUP:=autoreconf
 include $(INCLUDE_DIR)/host-build.mk
 
 ifneq ($(HOST_OS),Linux)
+ifneq (CYGWIN,$(findstring CYGWIN,$(HOST_OS)))
   HOST_CFLAGS += \
 	-I$(CURDIR)/include \
 	-Dloff_t=off_t \
@@ -25,6 +26,14 @@  ifneq ($(HOST_OS),Linux)
 	-include endian.h \
 	-DNO_NATIVE_SUPPORT \
 	-include fls.h
+else
+  HOST_CFLAGS += \
+	-I$(CURDIR)/include \
+	-include endian.h \
+	-DNO_NATIVE_SUPPORT \
+	-include fls.h \
+	-D__USE_LINUX_IOCTL_DEFS
+endif
 endif
 
 HOST_CONFIGURE_VARS+= \
@@ -37,8 +46,14 @@  HOST_CONFIGURE_ARGS+= \
 	--without-zstd \
 	--without-lzo
 
+ifeq (CYGWIN,$(findstring CYGWIN,$(HOST_OS)))
+EXEC_SUFFIX:=.exe
+else
+EXEC_SUFFIX:=
+endif
+
 HOST_MAKE_FLAGS += \
-	PROGRAMS="mkfs.jffs2 ubinize mkfs.ubifs"
+	PROGRAMS="mkfs.jffs2$(EXEC_SUFFIX) ubinize$(EXEC_SUFFIX) mkfs.ubifs$(EXEC_SUFFIX)"
 
 define Host/Install
 	$(CP) \
diff --git a/tools/mtd-utils/include/linux/blkpg.h b/tools/mtd-utils/include/linux/blkpg.h
new file mode 100644
index 0000000000..7d90fa5d86
--- /dev/null
+++ b/tools/mtd-utils/include/linux/blkpg.h
@@ -0,0 +1,35 @@ 
+#ifndef __LINUX_BLKPG_H
+#define __LINUX_BLKPG_H
+
+/*#include <linux/ioctl.h> */
+
+#define BLKPG      _IO(0x12,105)
+
+/* The argument structure */
+struct blkpg_ioctl_arg {
+        int op;
+        int flags;
+        int datalen;
+        void *data;
+};
+
+/* The subfunctions (for the op field) */
+#define BLKPG_ADD_PARTITION     1
+#define BLKPG_DEL_PARTITION     2
+#define BLKPG_RESIZE_PARTITION  3
+
+/* Sizes of name fields. Unused at present. */
+#define BLKPG_DEVNAMELTH        64
+#define BLKPG_VOLNAMELTH        64
+
+/* The data structure for ADD_PARTITION and DEL_PARTITION */
+struct blkpg_partition {
+        long long start;                /* starting offset in bytes */
+        long long length;               /* length in bytes */
+        int pno;                        /* partition number */
+        char devname[BLKPG_DEVNAMELTH]; /* partition name, like sda5 or c0d1p2,
+                                           to be used in kernel messages */
+        char volname[BLKPG_VOLNAMELTH]; /* volume label */
+};
+
+#endif /* __LINUX_BLKPG_H */
diff --git a/tools/mtd-utils/include/linux/types.h b/tools/mtd-utils/include/linux/types.h
index 559fac7a2c..0b28190fb1 100644
--- a/tools/mtd-utils/include/linux/types.h
+++ b/tools/mtd-utils/include/linux/types.h
@@ -5,7 +5,13 @@ 
 
 typedef uint16_t __u16;
 typedef uint32_t __u32;
+
+#if defined(__CYGWIN__)
+typedef __signed__ long long __s64;
+typedef unsigned long long __u64;
+#else
 typedef uint64_t __u64;
+#endif
 
 typedef __u16 __le16;
 typedef __u32 __le32;