summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/ctor.h2
-rw-r--r--src/tasks.cc23
-rw-r--r--src/util.cc61
-rw-r--r--src/util.h7
4 files changed, 70 insertions, 23 deletions
diff --git a/src/ctor.h b/src/ctor.h
index b8b3ae6..9738949 100644
--- a/src/ctor.h
+++ b/src/ctor.h
@@ -24,6 +24,8 @@ enum class target_type
unit_test,
unit_test_library,
function,
+
+ unknown,
};
enum class language
diff --git a/src/tasks.cc b/src/tasks.cc
index 67bed2b..b44fce8 100644
--- a/src/tasks.cc
+++ b/src/tasks.cc
@@ -18,6 +18,7 @@
#include "task_fn.h"
#include "rebuild.h"
#include "configure.h"
+#include "util.h"
const std::deque<Target>& getTargets(const ctor::settings& settings,
bool resolve_externals)
@@ -92,23 +93,9 @@ std::set<std::shared_ptr<Task>> taskFactory(const ctor::build_configuration& con
{
target_type = ctor::target_type::function;
}
- else if(targetFile.extension() == ".a")
- {
- target_type = ctor::target_type::static_library;
- }
- else if(targetFile.extension() == ".so")
- {
- target_type = ctor::target_type::dynamic_library;
- }
- else if(targetFile.extension() == "")
- {
- target_type = ctor::target_type::executable;
- }
else
{
- std::cerr << "Could not deduce target type from target " <<
- targetFile.string() << " please specify.\n";
- exit(1);
+ target_type = target_type_from_extension(targetFile);
}
}
@@ -140,6 +127,12 @@ std::set<std::shared_ptr<Task>> taskFactory(const ctor::build_configuration& con
// The target_type cannot be Auto
break;
+ case ctor::target_type::unknown:
+ std::cerr << "Could not deduce target type from target " <<
+ targetFile.string() << " please specify.\n";
+ exit(1);
+ break;
+
case ctor::target_type::static_library:
case ctor::target_type::unit_test_library:
tasks.insert(std::make_shared<TaskAR>(config, settings, config.target,
diff --git a/src/util.cc b/src/util.cc
index ee56ede..601fd54 100644
--- a/src/util.cc
+++ b/src/util.cc
@@ -5,6 +5,15 @@
#include <iostream>
#include <fstream>
+#include <algorithm>
+#include <cctype>
+
+std::string to_lower(const std::string& str)
+{
+ std::string out{str};
+ std::transform(out.begin(), out.end(), out.begin(), ::tolower);
+ return out;
+}
std::string readFile(const std::string& fileName)
{
@@ -83,15 +92,23 @@ std::vector<std::string> readDeps(const std::string& depFile)
ctor::language languageFromExtension(const std::filesystem::path& file)
{
auto ext = file.extension().string();
+
+ // First a few case sensitive comparisons
if(ext == ".c")
{
return ctor::language::c;
}
- if(ext == ".C" ||
- ext == ".cc" ||
+ if(ext == ".C")
+ {
+ return ctor::language::cpp;
+ }
+
+ // The rest are compared in lowercase
+ ext = to_lower(ext);
+
+ if(ext == ".cc" ||
ext == ".cpp" ||
- ext == ".CPP" ||
ext == ".c++" ||
ext == ".cp" ||
ext == ".cxx")
@@ -100,7 +117,6 @@ ctor::language languageFromExtension(const std::filesystem::path& file)
}
if(ext == ".s" ||
- ext == ".S" ||
ext == ".asm")
{
return ctor::language::assembler;
@@ -135,3 +151,40 @@ std::string cleanUp(const std::string& path)
}
return cleaned;
}
+
+ctor::target_type target_type_from_extension(const std::filesystem::path& file)
+{
+ auto ext = to_lower(file.extension().string());
+ // Loosely based on:
+ // https://en.wikipedia.org/wiki/List_of_file_formats#Object_code,_executable_files,_shared_and_dynamically_linked_libraries
+ if(ext == ".a" ||
+ ext == ".lib")
+ {
+ return ctor::target_type::static_library;
+ }
+
+ if(ext == ".so" ||
+ ext == ".dll" ||
+ ext == ".dylib")
+ {
+ return ctor::target_type::dynamic_library;
+ }
+
+ if(ext == ".o" ||
+ ext == ".obj")
+ {
+ return ctor::target_type::object;
+ }
+
+ if(ext == "" ||
+ ext == ".exe" ||
+ ext == ".com" ||
+ ext == ".bin" ||
+ ext == ".run" ||
+ ext == ".out")
+ {
+ return ctor::target_type::executable;
+ }
+
+ return ctor::target_type::unknown;
+}
diff --git a/src/util.h b/src/util.h
index c7318aa..45f69d4 100644
--- a/src/util.h
+++ b/src/util.h
@@ -8,6 +8,8 @@
#include <string>
#include <filesystem>
+std::string to_lower(const std::string& str);
+
std::string readFile(const std::string& fileName);
std::vector<std::string> readDeps(const std::string& depFile);
ctor::language languageFromExtension(const std::filesystem::path& file);
@@ -19,7 +21,4 @@ void append(T& a, const T& b)
a.insert(a.end(), b.begin(), b.end());
}
-//using cxx_flags = std::vector<ctor::cxx_flag>;
-//using c_flags = std::vector<std::string>;
-//using ld_flags= std::vector<std::string>;
-//using asm_flags = std::vector<std::string>;
+ctor::target_type target_type_from_extension(const std::filesystem::path& file);