[PATCH 02/37] libxfs: compile with a C++ compiler

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Darrick J. Wong <djwong@xxxxxxxxxx>

Apparently C++ compilers don't like the implicit void* casts that go on
in the system headers.  Compile a dummy program with the C++ compiler to
make sure this works.

Signed-off-by: Darrick J. Wong <djwong@xxxxxxxxxx>
Tested-by: Sam James <sam@xxxxxxxxxx>
Reviewed-by: Sam James <sam@xxxxxxxxxx>
---
 configure.ac               |    6 ++++++
 include/builddefs.in       |    8 ++++++++
 libxfs/Makefile            |   31 ++++++++++++++++++++++++++++++-
 libxfs/ioctl_c_dummy.c     |   11 +++++++++++
 libxfs/ioctl_cxx_dummy.cpp |   13 +++++++++++++
 m4/package_utilies.m4      |    5 +++++
 6 files changed, 73 insertions(+), 1 deletion(-)
 create mode 100644 libxfs/ioctl_c_dummy.c
 create mode 100644 libxfs/ioctl_cxx_dummy.cpp


diff --git a/configure.ac b/configure.ac
index b75f7d9e7563b2..dc587f39b80533 100644
--- a/configure.ac
+++ b/configure.ac
@@ -9,6 +9,9 @@ AC_PREFIX_DEFAULT(/usr)
 if test "${CFLAGS+set}" != "set"; then
 	CFLAGS="-g -O2 -std=gnu11"
 fi
+if test "${CXXFLAGS+set}" != "set"; then
+	CXXFLAGS="-g -O2 -std=gnu++11"
+fi
 
 AC_PROG_INSTALL
 LT_INIT
@@ -31,6 +34,9 @@ if test "${BUILD_CFLAGS+set}" != "set"; then
   fi
 fi
 
+AC_PROG_CXX
+# no C++ build tools yet
+
 AC_ARG_ENABLE(shared,
 [  --enable-shared=[yes/no]  Enable use of shared libraries [default=yes]],,
 	enable_shared=yes)
diff --git a/include/builddefs.in b/include/builddefs.in
index c8c7de7fd2fd38..1cbace071108dd 100644
--- a/include/builddefs.in
+++ b/include/builddefs.in
@@ -14,6 +14,7 @@ MALLOCLIB = @malloc_lib@
 LOADERFLAGS = @LDFLAGS@
 LTLDFLAGS = @LDFLAGS@
 CFLAGS = @CFLAGS@ -D_FILE_OFFSET_BITS=64 -D_TIME_BITS=64 -Wno-address-of-packed-member
+CXXFLAGS = @CXXFLAGS@ -D_FILE_OFFSET_BITS=64 -D_TIME_BITS=64 -Wno-address-of-packed-member
 BUILD_CFLAGS = @BUILD_CFLAGS@ -D_FILE_OFFSET_BITS=64 -D_TIME_BITS=64
 
 # make sure we don't pick up whacky LDFLAGS from the make environment and
@@ -63,6 +64,7 @@ XFS_SCRUB_ALL_AUTO_MEDIA_SCAN_STAMP=$(PKG_STATE_DIR)/xfs_scrub_all_media.stamp
 
 CC		= @cc@
 BUILD_CC	= @BUILD_CC@
+CXX		= @cxx@
 AWK		= @awk@
 SED		= @sed@
 TAR		= @tar@
@@ -161,9 +163,15 @@ ifeq ($(ENABLE_GETTEXT),yes)
 GCFLAGS += -DENABLE_GETTEXT
 endif
 
+# Override these if C++ needs other options
+SANITIZER_CXXFLAGS = $(SANITIZER_CFLAGS)
+GCXXFLAGS = $(GCFLAGS)
+PCXXFLAGS = $(PCFLAGS)
+
 BUILD_CFLAGS += $(GCFLAGS) $(PCFLAGS)
 # First, Sanitizer, Global, Platform, Local CFLAGS
 CFLAGS += $(FCFLAGS) $(SANITIZER_CFLAGS) $(OPTIMIZER) $(GCFLAGS) $(PCFLAGS) $(LCFLAGS)
+CXXFLAGS += $(FCXXFLAGS) $(SANITIZER_CXXFLAGS) $(OPTIMIZER) $(GCXXFLAGS) $(PCXXFLAGS) $(LCXXFLAGS)
 
 include $(TOPDIR)/include/buildmacros
 
diff --git a/libxfs/Makefile b/libxfs/Makefile
index 72e287b8b7957a..aca28440adac08 100644
--- a/libxfs/Makefile
+++ b/libxfs/Makefile
@@ -125,6 +125,18 @@ CFILES = buf_mem.c \
 	xfs_trans_space.c \
 	xfs_types.c
 
+EXTRA_CFILES=\
+	ioctl_c_dummy.c
+
+EXTRA_CXXFILES=\
+	ioctl_cxx_dummy.cpp
+
+EXTRA_OBJECTS=\
+	$(patsubst %.c,%.o,$(EXTRA_CFILES)) \
+	$(patsubst %.cpp,%.o,$(EXTRA_CXXFILES))
+
+LDIRT += $(EXTRA_OBJECTS)
+
 #
 # Tracing flags:
 # -DMEM_DEBUG		all zone memory use
@@ -148,7 +160,23 @@ LTLIBS = $(LIBPTHREAD) $(LIBRT)
 # don't try linking xfs_repair with a debug libxfs.
 DEBUG = -DNDEBUG
 
-default: ltdepend $(LTLIBRARY)
+default: ltdepend $(LTLIBRARY) $(EXTRA_OBJECTS)
+
+%dummy.o: %dummy.cpp
+	@echo "    [CXXD]   $@"
+	$(Q)$(CXX) $(CXXFLAGS) -c $<
+
+%dummy.o: %dummy.c
+	@echo "    [CCD]    $@"
+	$(Q)$(CC) $(CFLAGS) -c $<
+
+MAKECXXDEP := $(MAKEDEPEND) $(CXXFLAGS)
+
+.PHONY: .extradep
+
+.extradep: $(EXTRA_CFILES) $(EXTRA_CXXFILES) $(HFILES)
+	$(Q)$(MAKEDEP) $(EXTRA_CFILES) > .extradep
+	$(Q)$(MAKECXXDEP) $(EXTRA_CXXFILES) >> .extradep
 
 # set up include/xfs header directory
 include $(BUILDRULES)
@@ -172,4 +200,5 @@ install-dev: install
 # running the install-headers target.
 ifndef NODEP
 -include .ltdep
+-include .extradep
 endif
diff --git a/libxfs/ioctl_c_dummy.c b/libxfs/ioctl_c_dummy.c
new file mode 100644
index 00000000000000..e417332c3cf9f6
--- /dev/null
+++ b/libxfs/ioctl_c_dummy.c
@@ -0,0 +1,11 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (c) 2024 Oracle.  All Rights Reserved.
+ * Author: Darrick J. Wong <djwong@xxxxxxxxxx>
+ */
+
+/* Dummy program to test C compilation of user-exported xfs headers */
+
+#include "include/xfs.h"
+#include "include/handle.h"
+#include "include/jdm.h"
diff --git a/libxfs/ioctl_cxx_dummy.cpp b/libxfs/ioctl_cxx_dummy.cpp
new file mode 100644
index 00000000000000..b95babff0b0aee
--- /dev/null
+++ b/libxfs/ioctl_cxx_dummy.cpp
@@ -0,0 +1,13 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (c) 2024 Oracle.  All Rights Reserved.
+ * Author: Darrick J. Wong <djwong@xxxxxxxxxx>
+ */
+
+/* Dummy program to test C++ compilation of user-exported xfs headers */
+
+extern "C" {
+#include "include/xfs.h"
+#include "include/handle.h"
+#include "include/jdm.h"
+};
diff --git a/m4/package_utilies.m4 b/m4/package_utilies.m4
index 49f4dfbbd2d168..56ee0b266130bf 100644
--- a/m4/package_utilies.m4
+++ b/m4/package_utilies.m4
@@ -42,6 +42,11 @@ AC_DEFUN([AC_PACKAGE_UTILITIES],
     AC_SUBST(cc)
     AC_PACKAGE_NEED_UTILITY($1, "$cc", cc, [C compiler])
 
+    AC_PROG_CXX
+    cxx="$CXX"
+    AC_SUBST(cxx)
+    AC_PACKAGE_NEED_UTILITY($1, "$cxx", cxx, [C++ compiler])
+
     if test -z "$MAKE"; then
         AC_PATH_PROG(MAKE, gmake,, $PATH)
     fi





[Index of Archives]     [XFS Filesystem Development (older mail)]     [Linux Filesystem Development]     [Linux Audio Users]     [Yosemite Trails]     [Linux Kernel]     [Linux RAID]     [Linux SCSI]


  Powered by Linux