瀏覽代碼

Made it possible to include multiple folders in a library.

David Piuva 5 年之前
父節點
當前提交
fc7efd5934
共有 3 個文件被更改,包括 30 次插入11 次删除
  1. 3 3
      Source/tools/build.sh
  2. 1 1
      Source/tools/buildAndRun.sh
  3. 26 7
      Source/tools/buildLibrary.sh

+ 3 - 3
Source/tools/build.sh

@@ -1,7 +1,7 @@
 #!/bin/bash
 
 # Load arguments into named variables in order
-PROJECT_FOLDER=$1 # Where your code is
+PROJECT_FOLDERS=$1 # Where your code is as a space separated list of folders in a quote
 TARGET_FILE=$2 # Your executable to build
 ROOT_PATH=$3 # The parent folder of DFPSR, SDK and tools
 TEMP_ROOT=$4 # Where your temporary objects should be
@@ -30,13 +30,13 @@ then
 fi
 
 # Abort if the project folder is replaced with the NONE keyword
-if [ ${PROJECT_FOLDER} = "NONE" ]
+if [ "${PROJECT_FOLDERS}" = "NONE" ]
 then
 	exit 0
 fi
 
 echo "Compiling application."
-${ROOT_PATH}/tools/buildLibrary.sh g++ ${PROJECT_FOLDER} ${TEMP_DIR} "application" "${COMPILER_FLAGS}" CLEAN
+${ROOT_PATH}/tools/buildLibrary.sh g++ "${PROJECT_FOLDERS}" ${TEMP_DIR} "application" "${COMPILER_FLAGS}" CLEAN
 if [ $? -ne 0 ]
 then
 	exit 1

+ 1 - 1
Source/tools/buildAndRun.sh

@@ -1,7 +1,7 @@
 #!/bin/bash
 
 # Load arguments into named variables in order
-PROJECT_FOLDER=$1 # Where your code is
+PROJECT_FOLDERS=$1 # Where your code is as a space separated list of folders in a quote
 TARGET_FILE=$2 # Your executable to build
 ROOT_PATH=$3 # The parent folder of DFPSR, SDK and tools
 TEMP_ROOT=$4 # Where your temporary objects should be

+ 26 - 7
Source/tools/buildLibrary.sh

@@ -4,8 +4,8 @@
 
 # The global command for running the compiler (tested with g++ and clang++)
 COMPILER=$1
-# The root of the source files
-SOURCE_FOLDER=$2
+# The root of each folder containing source files
+SOURCE_FOLDERS=$2
 # The target folder where the library will be created
 TARGET=$3
 # The name of your library without any path nor extension
@@ -34,7 +34,7 @@ then
 	# Cat takes a filename and returns the content
 	OLD_SUM="$(cat ${SUM_FILENAME})"
 	# Use tar to create an archive and apply md5sum on the archive
-	NEW_SUM="$(tar cf - ${SOURCE_FOLDER} | md5sum)"
+	NEW_SUM="$(tar cf - ${SOURCE_FOLDERS} | md5sum)"
 	# Remove extra characters from the result
 	NEW_SUM=$(echo $NEW_SUM | tr -d " \t\n\r-")
 	echo "  Old md5 checksum: ${OLD_SUM}"
@@ -51,9 +51,14 @@ then
 fi
 
 # Check if the target library already exists
-if [ ! -f ${LIBRARY_FILENAME} ]; then
+if [ ! -f ${LIBRARY_FILENAME} ]
+then
 	# Argument: $1 as the folder to compile recursively
 	compileFolder() {
+		if [ ! -d "$1" ]; then
+			echo "Failed to compile files in $1 because the folder does not exist!"
+			exit 1
+		fi
 		# Compile files in the folder
 		for file in "$1"/*.cpp
 		do
@@ -79,12 +84,26 @@ if [ ! -f ${LIBRARY_FILENAME} ]; then
 			fi
 		done
 	}
-	# Compiling temporary objects
-	echo "Compiling cpp files into object files in $TARGET using $MODE mode."
-	compileFolder ${SOURCE_FOLDER}
+
+	# Split the space separated folders into an array
+	OLD_IFS="${IFS}"
+	IFS=" "
+	read -ra FOLDER_ARRAY <<< "$SOURCE_FOLDERS"
+	IFS="${OLD_IFS}" # IFS must be brought back to avoid crashing the compiler
+	#Compile each of the project folders (Only one of them may contain main, so the rest must be libraries)
+	for FOLDER in "${FOLDER_ARRAY[@]}"; do
+		echo "Compiling ${FOLDER} using ${COMPILER_FLAGS}."
+		compileFolder "${FOLDER}"
+		if [ $? -ne 0 ]
+		then
+			exit 1
+		fi
+	done
+
 	# Assembling static library
 	echo "Assembling object files into ${LIBRARY_NAME}.a."
 	ar rcs ${LIBRARY_FILENAME} ${TARGET}/*${OBJECT_POSTFIX}
+
 	# Cleaning up temporary objects
 	echo "Cleaning up temporary ${LIBRARY_NAME} object files."
 	rm -f ${TARGET}/*${OBJECT_POSTFIX}