mirror of
https://github.com/Kiritow/MiniEngine.git
synced 2024-03-22 13:11:22 +08:00
Update C4droid makefile generator. Remove linux makefile generator.(Recommand Codeblocks on Linux)
This commit is contained in:
parent
a19874c6da
commit
813fdfc985
|
@ -1,70 +1,70 @@
|
||||||
/// makefile_c4gen.cpp
|
/// makefile_c4gen.cpp
|
||||||
/// Under MIT License. Part of MiniEngine Project.
|
/// 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 <cstdio>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <algorithm>
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
char buff[1024];
|
char buff[1024];
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
printf("#Detecting source files...#\n");
|
printf("Generator: Detecting source files...\n");
|
||||||
// Set up environment
|
/// Find files
|
||||||
sprintf(buff,"PATH=%s:/data/data/com.n0n3m4.droidc/bzbox/",getenv("PATH"));
|
vector<string> objvec;
|
||||||
putenv(buff);
|
const string toFindCpp=".cpp";
|
||||||
fflush(stdout);
|
const string toFindC=".c";
|
||||||
system("find . -name \"*.cpp\" > cpplist.txt ");
|
const string toAppendObj=".o";
|
||||||
system("find . -name \"*.c\" > clist.txt ");
|
auto replaceEnd=[](const string& source,const string& replaceFrom,const string& replaceTo)->string
|
||||||
vector<string> dvec;
|
|
||||||
FILE* fp=fopen("cpplist.txt","r");
|
|
||||||
memset(buff,0,1024);
|
|
||||||
while(fgets(buff,1024,fp)!=nullptr)
|
|
||||||
{
|
{
|
||||||
int len=strlen(buff);
|
return source.substr(0,source.size()-replaceFrom.size()).append(replaceTo);
|
||||||
if(buff[len-1]=='\n') buff[len-1]=0;
|
};
|
||||||
char* p=strstr(buff,".cpp");
|
auto endWith=[](const string& text,const string& testEndWith)->bool
|
||||||
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);
|
return (text.substr(text.size()-testEndWith.size())==testEndWith);
|
||||||
if(buff[len-1]=='\n') buff[len-1]=0;
|
};
|
||||||
char* p=strstr(buff,".c");
|
FindFileRev(".",[&](const std::string& name)
|
||||||
sprintf(p,".o");
|
{
|
||||||
string d(buff);
|
if(endWith(name,toFindCpp))
|
||||||
dvec.push_back(d);
|
{
|
||||||
memset(buff,0,1024);
|
objvec.push_back(replaceEnd(name,toFindCpp,toAppendObj));
|
||||||
}
|
}
|
||||||
fclose(fp);
|
else if(endWith(name,toFindC))
|
||||||
|
{
|
||||||
printf("#Excluding files...#\n");
|
objvec.push_back(replaceEnd(name,toFindC,toAppendObj));
|
||||||
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("Generator: Excluding files...\n");
|
||||||
printf("#Generating makefile...#\n");
|
objvec.erase(remove_if(objvec.begin(),objvec.end(),[](const string& objname)->bool
|
||||||
fp=fopen("makefile","w");
|
{
|
||||||
|
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,
|
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"
|
"LDFLAGS =\n"
|
||||||
"LDLIBS = -lSDL2_image -lSDL2_net -ltiff -ljpeg -lpng -lz -lSDL2_ttf -lfreetype -lSDL2_mixer "
|
"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 "
|
"-lSDL2_test -lsmpeg2 -lvorbisfile -lvorbis -logg -lstdc++ -lSDL2 -lEGL -lGLESv1_CM -lGLESv2 "
|
||||||
"-landroid -Wl,--no-undefined -shared\n"
|
"-landroid -Wl,--no-undefined -shared\n"
|
||||||
"PROG = program_name\n"
|
"PROG = program_name\n"
|
||||||
"OBJS = ");
|
"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,"\n");
|
||||||
fprintf(fp,
|
fprintf(fp,
|
||||||
|
@ -74,9 +74,87 @@ int main()
|
||||||
"\t$(CXX) $(CXXFLAGS) $(LDFLAGS) $(LDLIBS) -o $@ $(OBJS) `sdl2-config --cflags --libs`\n"
|
"\t$(CXX) $(CXXFLAGS) $(LDFLAGS) $(LDLIBS) -o $@ $(OBJS) `sdl2-config --cflags --libs`\n"
|
||||||
"\n"
|
"\n"
|
||||||
"clean:\n"
|
"clean:\n"
|
||||||
"\trm -f $(PROG) $(OBJS))\n");
|
"\trm -f $(PROG) $(OBJS)\n");
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
|
|
||||||
printf("#End of Generation#\n");
|
printf("Generator: Generation Finished.\n");
|
||||||
return 0;
|
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
|
||||||
|
|
|
@ -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;
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user