Update C4droid makefile generator. Remove linux makefile generator.(Recommand Codeblocks on Linux)

This commit is contained in:
Kirigaya Kazuto 2017-07-07 11:28:56 +08:00
parent a19874c6da
commit 813fdfc985
2 changed files with 124 additions and 120 deletions

View File

@ -1,70 +1,70 @@
/// makefile_c4gen.cpp
/// Under MIT License. Part of MiniEngine Project.
/// You can run this code to generate a makefile for c4droid.
/// You can run this code to generate a makefile for C4droid.
#include <string>
#include <functional>
/// Declaration
void FindFileRev(const std::string& dirname,const std::function<void(const std::string&)>& func);
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
char buff[1024];
int main()
{
printf("#Detecting source files...#\n");
// Set up environment
sprintf(buff,"PATH=%s:/data/data/com.n0n3m4.droidc/bzbox/",getenv("PATH"));
putenv(buff);
fflush(stdout);
system("find . -name \"*.cpp\" > cpplist.txt ");
system("find . -name \"*.c\" > clist.txt ");
vector<string> dvec;
FILE* fp=fopen("cpplist.txt","r");
memset(buff,0,1024);
while(fgets(buff,1024,fp)!=nullptr)
printf("Generator: Detecting source files...\n");
/// Find files
vector<string> objvec;
const string toFindCpp=".cpp";
const string toFindC=".c";
const string toAppendObj=".o";
auto replaceEnd=[](const string& source,const string& replaceFrom,const string& replaceTo)->string
{
int len=strlen(buff);
if(buff[len-1]=='\n') buff[len-1]=0;
char* p=strstr(buff,".cpp");
sprintf(p,".o");
string d(buff);
dvec.push_back(d);
memset(buff,0,1024);
}
fclose(fp);
vector<string> ccd;
fp=fopen("clist.txt","r");
memset(buff,0,1024);
while(fgets(buff,1024,fp)!=nullptr)
return source.substr(0,source.size()-replaceFrom.size()).append(replaceTo);
};
auto endWith=[](const string& text,const string& testEndWith)->bool
{
int len=strlen(buff);
if(buff[len-1]=='\n') buff[len-1]=0;
char* p=strstr(buff,".c");
sprintf(p,".o");
string d(buff);
dvec.push_back(d);
memset(buff,0,1024);
}
fclose(fp);
printf("#Excluding files...#\n");
auto iter=find_if(dvec.begin(),dvec.end(),[](const string& str){ return (str.find("makefile_c4gen")!=string::npos);});
if(iter!=dvec.end()) dvec.erase(iter);
printf("#Generating makefile...#\n");
fp=fopen("makefile","w");
return (text.substr(text.size()-testEndWith.size())==testEndWith);
};
FindFileRev(".",[&](const std::string& name)
{
if(endWith(name,toFindCpp))
{
objvec.push_back(replaceEnd(name,toFindCpp,toAppendObj));
}
else if(endWith(name,toFindC))
{
objvec.push_back(replaceEnd(name,toFindC,toAppendObj));
}
});
printf("Generator: Excluding files...\n");
objvec.erase(remove_if(objvec.begin(),objvec.end(),[](const string& objname)->bool
{
return ( /// Beginning of excluding list
(objname.find("makefile_")!=string::npos && objname.find("gen.")!=string::npos) ||
(objname.find("_Windows.")!=string::npos)
);
}),objvec.end());
printf("Generator: Generating makefile...\n");
FILE* fp=fopen("makefile","w");
fprintf(fp,
"CXXFLAGS = -std=c++14 -Wall -O2 -D__C4DROID__ -Iinclude\n"
"CFLAGS = -Wall -s -O2 -D__LINUX__ -Iinclude -fPIC\n"
"CXXFLAGS = -std=c++14 -Wall -s -O2 -D__C4DROID__ -Iinclude\n"
"LDFLAGS =\n"
"LDLIBS = -lSDL2_image -lSDL2_net -ltiff -ljpeg -lpng -lz -lSDL2_ttf -lfreetype -lSDL2_mixer "
"-lSDL2_test -lsmpeg2 -lvorbisfile -lvorbis -logg -lstdc++ -lSDL2 -lEGL -lGLESv1_CM -lGLESv2 "
"-landroid -Wl,--no-undefined -shared\n"
"PROG = program_name\n"
"OBJS = ");
for(auto& d:dvec)
for(auto& obj:objvec)
{
fprintf(fp,"%s ",d.c_str());
fprintf(fp,"%s ",obj.c_str());
}
fprintf(fp,"\n");
fprintf(fp,
@ -74,9 +74,87 @@ int main()
"\t$(CXX) $(CXXFLAGS) $(LDFLAGS) $(LDLIBS) -o $@ $(OBJS) `sdl2-config --cflags --libs`\n"
"\n"
"clean:\n"
"\trm -f $(PROG) $(OBJS))\n");
"\trm -f $(PROG) $(OBJS)\n");
fclose(fp);
printf("#End of Generation#\n");
printf("Generator: Generation Finished.\n");
return 0;
}
/// Implement
#if defined(_MSC_VER) || defined(_WIN32) /// VS or Windows
#include <windows.h>
#include <cstdio>
#include <cstdlib>
#include <cstring>
void FindFileRev(const std::string& dirname,const std::function<void(const std::string&)>& func)
{
std::string patternString;
if(dirname[dirname.size()-1]!='\\')
{
patternString=dirname+"\\*";
}
else
{
patternString=dirname+"*";
}
WIN32_FIND_DATA fnd;
HANDLE hand=FindFirstFile(patternString.c_str(),&fnd);
if(hand!=INVALID_HANDLE_VALUE)
{
do
{
std::string fullname=dirname+fnd.cFileName;
if(fnd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
{
fullname.append("\\");
FindFileRev(fullname,func);
}
else
{
func(fullname);
}
}
while(FindNextFile(hand,&fnd));
FindClose(hand);
}
}
#else /// Linux-like
#include <dirent.h>
#include <cstdio>
#include <cstdlib>
#include <cstring>
void FindFileRev(const std::string& dirname,const std::function<void(const std::string&)>& func)
{
DIR* Dir = NULL;
struct dirent* file = NULL;
std::string curDir;
if (dirname[dirname.size()-1] != '/')
{
curDir=dirname+"/";
}
else
{
curDir=dirname;
}
if ((Dir = opendir(curDir.c_str())) == NULL)
{
return ;
}
while ((file = readdir(Dir)) != nullptr)
{
if (file->d_type == DT_REG)
{
func(curDir + file->d_name);
}
else if (file->d_type == DT_DIR && strcmp(file->d_name, ".") != 0 && strcmp(file->d_name, "..") != 0)
{
FindFileRev(curDir + file->d_name,func);
}
}
closedir(Dir);
}
#endif

View File

@ -1,74 +0,0 @@
/// makefile_linuxgen.cpp
/// Under MIT License. Part of MiniEngine Project.
/// You can run this code to generate a makefile for linux.
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <vector>
using namespace std;
char buff[1024];
int main()
{
printf("#Detecting source files...#\n");
/// Find files
system("find . -name \"*.cpp\" > cpplist.txt ");
system("find . -name \"*.c\" > clist.txt ");
vector<string> dvec;
FILE* fp=fopen("cpplist.txt","r");
memset(buff,0,1024);
while(fgets(buff,1024,fp)!=nullptr)
{
int len=strlen(buff);
if(buff[len-1]=='\n') buff[len-1]=0;
char* p=strstr(buff,".cpp");
sprintf(p,".o");
string d(buff);
dvec.push_back(d);
memset(buff,0,1024);
}
fclose(fp);
vector<string> ccd;
fp=fopen("clist.txt","r");
memset(buff,0,1024);
while(fgets(buff,1024,fp)!=nullptr)
{
int len=strlen(buff);
if(buff[len-1]=='\n') buff[len-1]=0;
char* p=strstr(buff,".c");
sprintf(p,".o");
string d(buff);
dvec.push_back(d);
memset(buff,0,1024);
}
fclose(fp);
printf("#Generating makefile...#\n");
fp=fopen("makefile","w");
fprintf(fp,
"CXXFLAGS = -std=c++14 -Wall -O2 -D__LINUX__ -Iinclude\n"
"LDFLAGS = \n"
"LDLIBS = -lstdc++ -lSDL2_image -lSDL2_net -lSDL2_ttf -lSDL2_mixer -lSDL2_test -lSDL2 -shared\n"
"\n"
"PROG = your_project\n"
"OBJS = ");
for(auto& d:dvec)
{
fprintf(fp,"%s ",d.c_str());
}
fprintf(fp,"\n");
fprintf(fp,
"all: $(PROG)\n"
"\n"
"$(PROG): $(OBJS)\n"
"\t$(CXX) $(CXXFLAGS) $(LDFLAGS) $(LDLIBS) -o $@ $(OBJS) `sdl2-config --cflags --libs`\n"
"\n"
"clean:\n"
"\trm -f $(PROG) $(OBJS))\n");
fclose(fp);
printf("#End of Generation#\n");
return 0;
}