add c++ compiler detection

Sat, 03 Aug 2019 17:45:03 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Sat, 03 Aug 2019 17:45:03 +0200
changeset 8
82cd9f1d94cb
parent 7
686991ae6e2f
child 9
ebdecbbb2f79

add c++ compiler detection

dist/bin/uwproj file | annotate | diff | comparison | revisions
src/main/java/de/unixwork/uwproj/Dependency.java file | annotate | diff | comparison | revisions
src/main/java/de/unixwork/uwproj/Project.java file | annotate | diff | comparison | revisions
test/config.mk file | annotate | diff | comparison | revisions
test/configure file | annotate | diff | comparison | revisions
test/make/project.xml file | annotate | diff | comparison | revisions
test/make/toolchain.sh file | annotate | diff | comparison | revisions
--- a/dist/bin/uwproj	Sat Aug 03 13:46:43 2019 +0200
+++ b/dist/bin/uwproj	Sat Aug 03 17:45:03 2019 +0200
@@ -3,3 +3,6 @@
 PREFIX=/usr
 
 java -jar $PREFIX/lib/uwproj/uwproj-0.1.jar "$@"
+if [ $? -eq 0 ]; then
+	chmod +x configure
+fi
--- a/src/main/java/de/unixwork/uwproj/Dependency.java	Sat Aug 03 13:46:43 2019 +0200
+++ b/src/main/java/de/unixwork/uwproj/Dependency.java	Sat Aug 03 17:45:03 2019 +0200
@@ -25,6 +25,8 @@
     private List<String> tests = new LinkedList<>();
     private StringBuilder make = new StringBuilder();
     
+    private List<String> lang = new LinkedList<>();
+    
     private boolean abortOnError = false;
     
     private int num = 0;
@@ -62,6 +64,8 @@
                 } else if(n.equals("make")) {
                     String m = Xml.getContent(elm);
                     d.addMake(m);
+                } else if(n.equals("lang")) {
+                    d.lang.add(n.trim().toLowerCase());
                 }
             }
         }
@@ -152,4 +156,8 @@
     public String getMake() {
         return make.toString();
     }
+    
+    public List<String> getLang() {
+        return lang;
+    }
 }
--- a/src/main/java/de/unixwork/uwproj/Project.java	Sat Aug 03 13:46:43 2019 +0200
+++ b/src/main/java/de/unixwork/uwproj/Project.java	Sat Aug 03 17:45:03 2019 +0200
@@ -39,7 +39,7 @@
     
     private HashMap<String,ConfigVar> configVars = new HashMap<>();
     private List<ConfigVar> configVarsList = new LinkedList<>();
-    
+       
     public Project(File file) throws ParserConfigurationException, SAXException, IOException, Exception {
         DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
         factory.setNamespaceAware(true);
--- a/test/config.mk	Sat Aug 03 13:46:43 2019 +0200
+++ b/test/config.mk	Sat Aug 03 17:45:03 2019 +0200
@@ -3,41 +3,32 @@
 #
 
 # general vars
-HOST=xxx
-INSTALL_DIR=yyy
-PREFIX=/export/home/olaf/Projekte/uwproj/test
+HOST=x8
+PREFIX=/export/home/olaf/Projekte/uwproj/test/work
+INSTALL_DIR=/export/home/olaf/Projekte/uwproj/test/work
 
-EPREFIX=/export/home/olaf/Projekte/uwproj/test
+EPREFIX=/export/home/olaf/Projekte/uwproj/test/work
 
-BINDIR=/export/home/olaf/Projekte/uwproj/test/bin
-SBINDIR=/export/home/olaf/Projekte/uwproj/test/sbin
-LIBDIR=/export/home/olaf/Projekte/uwproj/test/lib
-LIBEXECDIR=/export/home/olaf/Projekte/uwproj/test/libexec
-DATADIR=/export/home/olaf/Projekte/uwproj/test/share
-SYSCONFDIR=/export/home/olaf/Projekte/uwproj/test/etc
-SHAREDSTATEDIR=/export/home/olaf/Projekte/uwproj/test/com
-LOCALSTATEDIR=/export/home/olaf/Projekte/uwproj/test/var
-INCLUDEDIR=/export/home/olaf/Projekte/uwproj/test/include
-INFODIR=/export/home/olaf/Projekte/uwproj/test/info
-MANDIR=/export/home/olaf/Projekte/uwproj/test/man
+BINDIR=/export/home/olaf/Projekte/uwproj/test/work/bin
+SBINDIR=/export/home/olaf/Projekte/uwproj/test/work/sbin
+LIBDIR=/export/home/olaf/Projekte/uwproj/test/work/lib
+LIBEXECDIR=/export/home/olaf/Projekte/uwproj/test/work/libexec
+DATADIR=/export/home/olaf/Projekte/uwproj/test/work/share
+SYSCONFDIR=/export/home/olaf/Projekte/uwproj/test/work/etc
+SHAREDSTATEDIR=/export/home/olaf/Projekte/uwproj/test/work/com
+LOCALSTATEDIR=/export/home/olaf/Projekte/uwproj/test/work/var
+INCLUDEDIR=/export/home/olaf/Projekte/uwproj/test/work/include
+INFODIR=/export/home/olaf/Projekte/uwproj/test/work/info
+MANDIR=/export/home/olaf/Projekte/uwproj/test/work/man
 
 # toolchain
-CC = cc
-LD = cc
-include $(BUILD_ROOT)make/gcc.mk
+CC = gcc
+CXX = g++
+LD = gcc
+include $(BUILD_ROOT)/make/gcc.mk
 
 
-CFLAGS += -DLINUX
-LDFLAGS += -lpthread -ldl -lm -lldap
 
 CFLAGS  +=  -I/usr/include/libxml2  
 LDFLAGS +=  -lxml2  -lssl -lcrypto 
 
-# platform dependend source files
-PLATFORM_DAEMONOBJ = event_linux.o
-
-# platform dependend vars
-OBJ_EXT = .o
-LIB_EXT = .so
-APP_EXT =
-
--- a/test/configure	Sat Aug 03 13:46:43 2019 +0200
+++ b/test/configure	Sat Aug 03 17:45:03 2019 +0200
@@ -1,8 +1,8 @@
 #!/bin/sh
 
-HOST=xxx
-INSTALL_DIR=yyy
-PREFIX=`pwd`
+HOST=`uname -n`
+PREFIX=`pwd`/work
+INSTALL_DIR=$PREFIX
 
 EPREFIX=$PREFIX
 
@@ -195,8 +195,8 @@
 
 # general vars
 HOST=$HOST
+PREFIX=$PREFIX
 INSTALL_DIR=$INSTALL_DIR
-PREFIX=$PREFIX
 
 EPREFIX=$EPREFIX
 
@@ -311,79 +311,9 @@
 LDFLAGS=
 while true
 do
-    if ! isplatform "linux"; then
-        break
-    fi
-    while true
-    do
-        
-        CFLAGS+="-DLINUX"    
-        LDFLAGS+="-lpthread -ldl -lm -lldap"    
-		cat >> $TEMP_DIR/make.mk << __EOF__
-# platform dependend source files
-PLATFORM_DAEMONOBJ = event_linux.o
-
-# platform dependend vars
-OBJ_EXT = .o
-LIB_EXT = .so
-APP_EXT =
-
-__EOF__
-        
-        break
-    done
-    
-    break
-done
-while true
-do
-    if ! isplatform "bsd"; then
-        break
-    fi
-    if isplatform "macos"; then
-        break
-    fi
     while true
     do
         
-        CFLAGS+="-DBSD"    
-        LDFLAGS+="-lpthread -lm -lldap"    
-		cat >> $TEMP_DIR/make.mk << __EOF__
-# platform dependend source files
-PLATFORM_DAEMONOBJ = event_bsd.o
-
-# platform dependend vars
-OBJ_EXT = .o
-LIB_EXT = .so
-APP_EXT =
-
-__EOF__
-        
-        break
-    done
-    
-    break
-done
-while true
-do
-    if ! isplatform "solaris"; then
-        break
-    fi
-    while true
-    do
-        
-        CFLAGS+="-DSOLARIS -D_REENTRANT -D_POSIX_PTHREAD_SEMANTICS"    
-        LDFLAGS+="-lsocket -lnsl -lsendfile -lposix4 -lpthread -ldl -lm -lmd -lldap"    
-		cat >> $TEMP_DIR/make.mk << __EOF__
-# platform dependend source files
-PLATFORM_DAEMONOBJ = event_solaris.o
-
-# platform dependend vars
-OBJ_EXT = .o
-LIB_EXT = .so
-APP_EXT =
-
-__EOF__
         
         break
     done
--- a/test/make/project.xml	Sat Aug 03 13:46:43 2019 +0200
+++ b/test/make/project.xml	Sat Aug 03 17:45:03 2019 +0200
@@ -2,52 +2,13 @@
 <project>
 	<!-- makefile config -->
 	<config>
-		<var name="HOST">xxx</var>
-		<var name="INSTALL_DIR">yyy</var>
-		<var name="PREFIX" type="exec">pwd</var>
+		<var name="HOST" type="exec">uname -n</var>
+		<var name="PREFIX">`pwd`/work</var>
+		<var name="INSTALL_DIR">$PREFIX</var>
 	</config>
 	
-	<!-- platform specific settings -->
-	<dependency platform="linux">
-		<cflags>-DLINUX</cflags>
-		<ldflags>-lpthread -ldl -lm -lldap</ldflags>
-		<make>
-# platform dependend source files
-PLATFORM_DAEMONOBJ = event_linux.o
-
-# platform dependend vars
-OBJ_EXT = .o
-LIB_EXT = .so
-APP_EXT =
-		</make>
-	</dependency>
-	
-	<dependency platform="bsd" not="macos">
-		<cflags>-DBSD</cflags>
-		<ldflags>-lpthread -lm -lldap</ldflags>
-		<make>
-# platform dependend source files
-PLATFORM_DAEMONOBJ = event_bsd.o
-
-# platform dependend vars
-OBJ_EXT = .o
-LIB_EXT = .so
-APP_EXT =
-		</make>
-	</dependency>
-	
-	<dependency platform="solaris">
-		<cflags>-DSOLARIS -D_REENTRANT -D_POSIX_PTHREAD_SEMANTICS</cflags>
-		<ldflags>-lsocket -lnsl -lsendfile -lposix4 -lpthread -ldl -lm -lmd -lldap</ldflags>
-		<make>
-# platform dependend source files
-PLATFORM_DAEMONOBJ = event_solaris.o
-
-# platform dependend vars
-OBJ_EXT = .o
-LIB_EXT = .so
-APP_EXT =
-		</make>
+	<dependency>
+		<lang>c++</lang>
 	</dependency>
 
 	<!-- library dependencies -->
--- a/test/make/toolchain.sh	Sat Aug 03 13:46:43 2019 +0200
+++ b/test/make/toolchain.sh	Sat Aug 03 17:45:03 2019 +0200
@@ -3,12 +3,13 @@
 # toolchain detection
 #
 
-COMPILERS="cc gcc clang suncc"
+C_COMPILERS="cc gcc clang suncc"
+CPP_COMPILERS="CC g++ clang++ sunCC"
 unset CC_ARG_CHECKED
 unset TOOLCHAIN_DETECTION_ERROR
 unset TOOLCHAIN_NAME
 
-check_compiler()
+check_c_compiler()
 {
     cat > $TEMP_DIR/test.c << __EOF__
 /* test file */
@@ -27,7 +28,34 @@
 }
 __EOF__
     rm -f $TEMP_DIR/checkcc
-    $1 -o $TEMP_DIR/checkcc $CFLAGS $LDFLAGS $TEMP_DIR/test.c
+    $1 -o $TEMP_DIR/checkcc $CFLAGS $LDFLAGS $TEMP_DIR/test.c 2> /dev/null
+    
+    if [ $? -ne 0 ]; then
+        return 1
+    fi
+    return 0
+}
+
+check_cpp_compiler()
+{
+    cat > $TEMP_DIR/test.cpp << __EOF__
+/* test file */
+#include <iostream>
+int main(int argc, char **argv) {
+#if defined(__GNUC__)
+    std::cout << "gcc" << std::endl;
+#elif defined(__clang__)
+    std::cout << "clang" << std::endl;
+#elif defined(__sun)
+	std::cout << "suncc" << std::endl;
+#else
+    std::cout << "unknown" << std::endl;
+#endif
+    return 0;
+}
+__EOF__
+    rm -f $TEMP_DIR/checkcc
+    $1 -o $TEMP_DIR/checkcc $CXXFLAGS $LDFLAGS $TEMP_DIR/test.cpp 2> /dev/null
     
     if [ $? -ne 0 ]; then
         return 1
@@ -37,22 +65,90 @@
 
 printf "detect toolchain... "
 
-for COMP in $COMPILERS
+for COMP in $C_COMPILERS
 do
-    check_compiler $COMP
+    check_c_compiler $COMP
     if [ $? -ne 0 ]; then
-        if [ $COMP = $CC ]; then
-            echo "$CC is not a working C Compiler"
-            TOOLCHAIN_DETECTION_ERROR="error"
-            break
-        fi
+	    if [[ ! -z $CC ]]; then
+        	if [ $COMP = $CC ]; then
+            	echo "$CC is not a working C Compiler"
+            	TOOLCHAIN_DETECTION_ERROR="error"
+            	break
+        	fi
+		fi
     else
         TOOLCHAIN_NAME=`$TEMP_DIR/checkcc`
+		if [ $COMP = "cc" ]; then
+		   # we have found a working compiler, but in case
+		   # the compiler is gcc or clang, we try to use
+		   # these commands and not 'cc'
+		   TOOLCHAIN_NAME=`$TEMP_DIR/checkcc`
+		   if [ $TOOLCHAIN_NAME = "gcc" ]; then
+		       check_c_compiler "gcc"
+			   if [ $? -eq 0 ]; then
+			       COMP=gcc
+			   fi
+		   fi
+		   if [ $TOOLCHAIN_NAME = "clang" ]; then
+		       check_c_compiler "clang"
+			   if [ $? -eq 0 ]; then
+			       COMP=clang
+			   fi
+		   fi
+		fi
+		
+		TOOLCHAIN_NAME=`$TEMP_DIR/checkcc`
         TOOLCHAIN_CC=$COMP
-        echo $TOOLCHAIN_NAME
+        echo $TOOLCHAIN_NAME 
         break
     fi
 done
+if [ -z $TOOLCHAIN_CC ]; then
+    echo "not found"
+fi
+
+printf "detect C++ compiler... "
+
+for COMP in $CPP_COMPILERS
+do
+    check_cpp_compiler $COMP
+    if [ $? -ne 0 ]; then
+		if [[ ! -z $CXX ]]; then
+        	if [ $COMP = $CXX ]; then
+                echo "$CC is not a working C++ Compiler"
+                TOOLCHAIN_DETECTION_ERROR="error"
+                break
+            fi
+		fi
+    else
+        if [ $COMP = "CC" ]; then
+		   # we have found a working compiler, but in case
+		   # the compiler is gcc or clang, we try to use
+		   # these commands and not 'cc'
+		   TOOLCHAIN_NAME=`$TEMP_DIR/checkcc`
+		   if [ $TOOLCHAIN_NAME = "gcc" ]; then
+		       check_c_compiler "gcc"
+			   if [ $? -eq 0 ]; then
+			       COMP=gcc
+			   fi
+		   fi
+		   if [ $TOOLCHAIN_NAME = "clang" ]; then
+		       check_c_compiler "clang"
+			   if [ $? -eq 0 ]; then
+			       COMP=clang
+			   fi
+		   fi
+		fi
+		
+		TOOLCHAIN_NAME=`$TEMP_DIR/checkcc`
+        TOOLCHAIN_CXX=$COMP
+        echo $TOOLCHAIN_NAME 
+        break
+    fi
+done
+if [ -z $TOOLCHAIN_CXX ]; then
+    echo "not found"
+fi
 
 TOOLCHAIN_LD=$TOOLCHAIN_CC
 
@@ -63,9 +159,12 @@
 # toolchain
 __EOF__
 	echo "CC = ${TOOLCHAIN_CC}" >> $TEMP_DIR/config.mk
+	if [[ ! -z $TOOLCHAIN_CXX ]]; then
+		echo "CXX = ${TOOLCHAIN_CXX}" >> $TEMP_DIR/config.mk
+	fi
     echo "LD = ${TOOLCHAIN_LD}" >> $TEMP_DIR/config.mk
     
     if [ -e "make/${TOOLCHAIN_NAME}.mk" ]; then 
-        echo "include \$(BUILD_ROOT)make/${TOOLCHAIN_NAME}.mk" >> $TEMP_DIR/config.mk
+        echo "include \$(BUILD_ROOT)/make/${TOOLCHAIN_NAME}.mk" >> $TEMP_DIR/config.mk
     fi
 fi

mercurial