Subversion Repositories Programming Utils

Compare Revisions

Ignore whitespace Rev 44 → Rev 45

/trunk/C-CPP-utils/supermakemake/MakefileObject.cpp
0,0 → 1,108
#include <fstream>
#include <iostream>
#include <cstring>
#include <cstdlib>
 
#include "MakefileObject.h"
#include "dirlist.h"
 
using std::ifstream;
using std::cerr;
using std::endl;
using std::string;
using std::set;
using std::cout;
 
static string parseList( char* buffer ){
string finalString;
char* equalsLocation = strchr( buffer, '=' );
if( equalsLocation == NULL ){
cerr << "ERROR: Couldn't parse list" << endl;
return finalString;
}
 
//pointer arithmetic to get rid of the equals sign
char* file = strtok( buffer + ( equalsLocation - buffer ) + 1, " \t" );
while( file != NULL ){
finalString.append( file );
file = strtok( NULL, " " );
}
 
return finalString;
}
 
static void parseFileList( char* buffer, set<string>* putInto ){
char* equalsLocation = strchr( buffer, '=' );
if( equalsLocation == NULL ){
cerr << "ERROR: Couldn't parse files" << endl;
return;
}
//We've found our files
//pointer arithmetic to get rid of the equals sign
char* file = strtok( buffer + ( equalsLocation - buffer ) + 1, " \t" );
while( file != NULL ){
putInto->insert( string( file ) );
file = strtok( NULL, " " );
}
 
}
 
Makefile::Makefile( const char* makefile ){
ifstream theFile( makefile );
char* buffer;
 
buffer = (char*)malloc( 300 );
 
if( theFile.fail() ){
cerr << "ERROR: Couldn't open file " << makefile << endl;
}
 
while( theFile.good() ){
theFile.getline( buffer, 300 );
if( memcmp( buffer, "CPP_FILES", 9 ) == 0 ){
parseFileList( buffer, &cpp_files );
}
 
if( memcmp( buffer, "H_FILES", 7 ) == 0 ){
parseFileList( buffer, &h_files );
}
 
if( memcmp( buffer, "C_FILES", 7 ) == 0 ){
parseFileList( buffer, &c_files );
}
 
if( memcmp( buffer, "PS_FILES", 8 ) == 0 ){
parseFileList( buffer, &ps_files );
}
 
if( memcmp( buffer, "S_FILES", 7 ) == 0 ){
parseFileList( buffer, &s_files );
}
 
if( memcmp( buffer, "CPPFLAGS", 8 ) == 0 ){
cpp_flags = parseList( buffer );
}
 
if( memcmp( buffer, "CFLAGS", 6 ) == 0 ){
c_flags = parseList( buffer );
}
 
if( memcmp( buffer, "CXXFLAGS", 8 ) == 0 ){
cxx_flags = parseList( buffer );
}
 
if( memcmp( buffer, "CLIBFLAGS", 9 ) == 0 ){
clib_flags = parseList( buffer );
}
if( memcmp( buffer, "CCLIBFLAGS", 10 ) == 0 ){
cxxlib_flags = parseList( buffer );
}
}
 
free( buffer );
}
 
void Makefile::writeMakefile(){
// cout << FileListInserter( cpp_files );
}
/trunk/C-CPP-utils/supermakemake/MakefileObject.h
0,0 → 1,44
#ifndef MAKEFILE_H
#define MAKEFILE_H
 
#include <set>
#include <string>
 
/**
* Represents a makefile
*/
class Makefile{
 
public:
/**
* Parse an already existing makefile
*/
Makefile( const char* filename );
 
/**
* Create a new Makefile with no settings
*/
Makefile();
 
/**
* Output a Makefile
*/
void writeMakefile();
 
private:
 
//Lists of files
std::set<std::string> cpp_files;
std::set<std::string> h_files;
std::set<std::string> c_files;
std::set<std::string> ps_files; //preprocessed assembly
std::set<std::string> s_files; //assembly
 
std::string cpp_flags; //preprocessor flags
std::string c_flags; // c flags
std::string cxx_flags; // c++ flags
std::string clib_flags; //c library flags
std::string cxxlib_flags; //c++ library flags
};
 
#endif
/trunk/C-CPP-utils/supermakemake/makemake.cpp
55,7 → 55,11
 
}
 
#include "MakefileObject.h"
int main( int argc, char **argv ){
Makefile m( "Makefile" );
return 1;
 
bool search_dirs = false;
char* progName;
 
/trunk/C-CPP-utils/supermakemake/Makefile
1,5 → 1,5
#
# Created by gmakemake (Sparc Jun 17 2005) on Wed Jun 22 14:01:43 2005
# Created by gmakemake x86 (Jan 28 2013) on Mon Jan 28 13:49:26 2013
#
 
#
7,28 → 7,29
#
 
.SUFFIXES:
.SUFFIXES: .a .o .c .C .cpp
.SUFFIXES: .a .o .c .C .cpp .s .S
.c.o:
$(COMPILE.c) $<
$(COMPILE.c) $< -o $@
.C.o:
$(COMPILE.cc) $<
$(COMPILE.cc) $< -o $@
.cpp.o:
$(COMPILE.cc) $<
$(COMPILE.cc) $< -o $@
.S.s:
$(CPP) -o $*.s $<
.s.o:
$(COMPILE.cc) $< -o $@
.c.a:
$(COMPILE.c) -o $% $<
$(AR) $(ARFLAGS) $@ $%
$(RM) $%
.C.a:
$(COMPILE.cc) -o $% $<
$(AR) $(ARFLAGS) $@ $%
$(RM) $%
.cpp.a:
$(COMPILE.cc) -o $% $<
$(AR) $(ARFLAGS) $@ $%
$(RM) $%
 
CC = gcc
CXX = g++
CC = gcc
CXX = g++
 
RM = rm -f
AR = ar
37,30 → 38,30
COMPILE.c = $(CC) $(CFLAGS) $(CPPFLAGS) -c
COMPILE.cc = $(CXX) $(CXXFLAGS) $(CPPFLAGS) -c
 
########## Flags from header.mak
 
CXXFLAGS = -ggdb -Wall
CFLAGS = -ggdb -Wall
########## Default flags (redefine these with a header.mak file if desired)
CXXFLAGS = -ggdb
CFLAGS = -ggdb
CLIBFLAGS = -lm
CCLIBFLAGS =
########## End of default flags
 
########## End of flags from header.mak
 
 
CPP_FILES = dirlist.cpp makemake.cpp write.cpp
CPP_FILES = MakefileObject.cpp dirlist.cpp makemake.cpp write.cpp
C_FILES =
H_FILES = dirlist.h write.h
SOURCEFILES = $(H_FILES) $(CPP_FILES) $(C_FILES)
PS_FILES =
S_FILES =
H_FILES = MakefileObject.h PlatformSwitcher.h dirlist.h write.h
SOURCEFILES = $(H_FILES) $(CPP_FILES) $(C_FILES) $(S_FILES)
.PRECIOUS: $(SOURCEFILES)
OBJFILES = dirlist.o write.o
OBJFILES = MakefileObject.o dirlist.o write.o
 
#
# Main targets
#
 
all: makemake
all: makemake
 
makemake: makemake.o $(OBJFILES) $(CCLIBFLAGS)
makemake: makemake.o $(OBJFILES)
$(CXX) $(CXXFLAGS) -o makemake makemake.o $(OBJFILES) $(CCLIBFLAGS)
 
#
67,11 → 68,19
# Dependencies
#
 
dirlist.o: dirlist.h
makemake.o: dirlist.h write.h
write.o: dirlist.h write.h
MakefileObject.o: MakefileObject.cpp MakefileObject.h
dirlist.o: dirlist.cpp dirlist.h
makemake.o: makemake.cpp dirlist.h write.h PlatformSwitcher.h
write.o: write.cpp write.h dirlist.h PlatformSwitcher.h
 
#
# Installation Targets
#
 
install: makemake
/usr/bin/install makemake /usr/bin
 
#
# Housekeeping
#
 
81,7 → 90,7
tar cf - $(SOURCEFILES) Makefile | gzip > archive.tgz
 
clean:
-/bin/rm -r $(OBJFILES) makemake.o core 2> /dev/null
-/bin/rm $(OBJFILES) makemake.o core 2> /dev/null
 
realclean: clean
/bin/rm -rf makemake
-/bin/rm -rf makemake