From 11d45b4bfda99e3e2cfb9209b2219157f4a0fa92 Mon Sep 17 00:00:00 2001 From: kiritow <1362050620@qq.com> Date: Sun, 2 Jul 2017 10:01:05 +0800 Subject: [PATCH] Add Makefile Generator for C4droid --- makefile_c4 | 14 -------- makefile_c4gen.cpp | 82 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 82 insertions(+), 14 deletions(-) delete mode 100644 makefile_c4 create mode 100644 makefile_c4gen.cpp diff --git a/makefile_c4 b/makefile_c4 deleted file mode 100644 index 507ec04..0000000 --- a/makefile_c4 +++ /dev/null @@ -1,14 +0,0 @@ -CXXFLAGS = -std=c++14 -Wall -O2 -D__C4DROID__ -Iinclude -LDFLAGS = -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 - -PROG = program_name -OBJS = MiniEngine.o MiniEngine_Android.o MiniEngine_Event.o MiniEngine_Widget.o sqlite/sqlite3.o MiniEngine_SQLite.o - -all: $(PROG) - -$(PROG): $(OBJS) - $(CXX) $(CXXFLAGS) $(LDFLAGS) $(LDLIBS) -o $@ $(OBJS) `sdl2-config --cflags --libs` - -clean: - rm -f $(PROG) $(OBJS) \ No newline at end of file diff --git a/makefile_c4gen.cpp b/makefile_c4gen.cpp new file mode 100644 index 0000000..8daca92 --- /dev/null +++ b/makefile_c4gen.cpp @@ -0,0 +1,82 @@ +/// makefile_c4gen.cpp +/// Under MIT License. Part of MiniEngine Project. +/// You can run this code to generate a makefile for c4droid. + +#include +#include +#include +#include +#include +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 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 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("#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"); + fprintf(fp, +"CXXFLAGS = -std=c++14 -Wall -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) + { + 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; +}