今天学习了一下Boost的文件遍历功能,同时发现GNU编译器有-MM选项,可以自动生成依赖关系,于是利用以上两点写了一个Makefile生成器。可以生成一般的单个可执行文件的Makefile,使用的是Windows+Mingw+boost环境。如果使用Linux,只需在程序中的两个System系统调用处和clean标签生成处将del 改成rm相关操作就好了。
现在更改成了Linux版本。下载的版本是Windows的。
下面是源代码:
makemake.cpp:
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <vector>
#include <string>
#include <exception>
#include <boost/filesystem/operations.hpp>
#include <boost/filesystem/path.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/program_options.hpp>
using namespace std;
namespace po = boost::program_options;
using namespace boost::filesystem;
using namespace boost;
void getFiles(vector<string>& src);
const string head = string(
"#########################################