最后写了一个小脚本,尽管这可能不是最简单/最有效的方法,但它仍然达到了预期的效果。只需获取一个包含所有头文件和源文件的字符串就非常有用了,这些头文件和源文件可以与
cp [headers] /path/to/dst
#include <iostream>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <list>
std::list<std::string> source_list = {};
std::list<std::string> header_list = {};
int is_dir(const char *path)
{
struct stat statbuf;
if (stat(path, &statbuf) != 0)
return 0;
return S_ISDIR(statbuf.st_mode);
}
void dirSearch(std::string p)
{
FILE *fp;
char path[100];
std::string cd = "cd ";
std::string ls = " && ls";
std::string cmd = cd + p + ls;
fp = popen(cmd.c_str(), "r");
if (fp == NULL) {
printf("Failed to run command\n");
exit(1);
}
while (fgets(path, sizeof(path)-1, fp) != NULL) {
std::string abs_path = p + "/" + path;
abs_path.pop_back();
if ( is_dir(abs_path.c_str()) ) {
dirSearch(abs_path);
}
else {
std::string SOURCE_FILE_EXT = ".cpp";
if (abs_path.substr(abs_path.size() - SOURCE_FILE_EXT.size(), abs_path.size()) == SOURCE_FILE_EXT) {
source_list.push_back(abs_path);
}
std::string HEADER_FILE_EXT = ".h";
if (abs_path.substr(abs_path.size() - HEADER_FILE_EXT.size(), abs_path.size()) == HEADER_FILE_EXT) {
header_list.push_back(abs_path);
}
}
}
pclose(fp);
}
int main(int argc, char **argv)
{
dirSearch(argv[1]);
std::string headers = "";
std::string fsource = " ";
for (std::string l : header_list) {
all_header_files += " " + l;
}
for (std::string l : source_list) {
all_source_files += " " + l;
}
std::cout << all_header_files << std::endl;
std::cout << all_source_files << std::endl;
}
下面是一个示例用法:
g++ scrape_source.cpp -o scrape_source
./scrape_source PhysX-4.1
... PhysX-4.1/physx/src/fastxml/src/PsFastXml.cpp PhysX-4.1/physx/src/foundation/src/PsAllocator.cpp PhysX-4.1/physx/src/foundation/src/PsAssert.cpp PhysX-4.1/physx/src/foundation/src/PsFoundation.cpp PhysX-4.1/physx/src/foundation/src/PsMathUtils.cpp PhysX-4.1/physx/src/foundation/src/PsString.cpp PhysX-4.1/physx/src/foundation/src/PsTempAllocator.cpp PhysX-4.1/physx/src/foundation/src/PsUtilities.cpp PhysX-4.1/physx/src/foundation/src/unix/PsUnixAtomic.cpp PhysX-4.1/physx/src/foundation/src/unix/PsUnixCpu.cpp PhysX-4.1/physx/src/foundation/src/unix/PsUnixFPU.cpp PhysX-4.1/physx/src/foundation/src/unix/PsUnixMutex.cpp PhysX-4.1/physx/src/foundation/src/unix/PsUnixPrintString.cpp PhysX-4.1/physx/src/foundation/src/unix/PsUnixSList.cpp PhysX-4.1/physx/src/foundation/src/unix/PsUnixSocket.cpp PhysX-4.1/physx/src/foundation/src/unix/PsUnixSync.cpp PhysX-4.1/physx/src/foundation/src/unix/PsUnixThread.cpp PhysX-4.1/physx/src/foundation/src/unix/PsUnixTime.cpp PhysX-4.1/physx/src/foundation/src/windows/PsUWPThread.cpp PhysX-4.1/physx/src/foundation/src/windows/PsWindowsAtomic.cpp PhysX-4.1/physx/src/foundation/src/windows/PsWindowsCpu.cpp ...