Subversion Repositories Programming Utils

Rev

Rev 1 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1 rm5248 1
/* makemake.cpp
2
 *
3
 * $Id: makemake.cpp,v 1.2 2009/12/26 01:41:46 sidney Exp $
4
 *
5
 * $Log: makemake.cpp,v $
6
 * Revision 1.2  2009/12/26 01:41:46  sidney
7
 * changed while(c = *exename++) to while((c = *exename++)) for style
8
 *
9
 * Revision 1.1  2006/06/08 02:14:38  swm
10
 * Initial revision
11
 *
12
 */
13
 
14
#include <iostream>
15
#include <cstdlib>
16
#include <cstring>
17
 
18
#include "dirlist.h"
19
#include "write.h"
20
 
21
bool debug( false );
22
 
2 rm5248 23
//Method prototype
24
void printHelp(char*);
25
 
26
void printHelp(char* progName){
27
        cout << "Usage: " << progName << " [-update] [-depends] [-header headerfile | -no-header] [-programs programsfile | -no-programs] ";
28
        cout << "[-no-debug] [-ar name] [-so name] [-install] [-prefix=PREFIX] [-dirs=DIRS] [files] " << endl;
29
 
30
        cout << "Note that " << progName << " outputs the makefile to STDOUT; it is typically invoked as " << progName << " > Makefile" << endl;
31
 
32
        cout << "" << endl;
33
        cout << " -update \t\tLet " << progName << " update the list of files that it compiles.  Any new files will be added to the makefile.  ";
34
        cout << "This will also remove files if " << progName << " cannot find them anymore.  All targets and flags from the old makefile are kept." << endl;
35
        cout << " -depends \t\tUpdate the dependencies that the makefile keeps track of.  All targets and flags from the old makefile are kept." << endl;
36
        cout << " -header HEADER\t\tUse the specified file instead of header.mak(see man makemake for more information)" << endl;
37
        cout << " -no-header \t\tDo not open header.mak even if it exists" << endl;
38
        cout << " -programs PROGRAMS\t\tUse the specified file instead of programs.mak(see man makemake for more information)" << endl;
39
        cout << " -no-programs \t\tDo not open programs.mak even if it exists" << endl;
40
        cout << " -no-debug \t\tDo not output compiler instructions to insert debugging information" << endl;
41
        cout << " -ar NAME \t\tInstead of making an executable program, compile and link into an archive file with name NAME" << endl;
42
        cout << " -so NAME \t\tInstead of making an executable program, compile and link into a shared object file with name NAME" << endl;
43
        cout << " -install \t\tGenerate a 'make install' target to install this program.  By default, it will be installed to /usr/bin" << endl;
44
        cout << " -prefix=PREFIX \t\tGenerate a 'make install' target, but install to PREFIX instead of /usr/bin.  -install does not have to be specified" << endl;
45
        cout << " -dirs-DIRS \t\tLook through the specified colon-separated directories for files to compile" << endl;
46
        cout << " files \t\tThe files to create the makefile from.  If no files are specified, " << progName << " will look through the current directory ";
47
        cout << "for the files to create the makefile from" << endl;
48
        cout << "" << endl;
49
 
50
        cout << "SuperMakemake v1.0" << endl;
51
        cout << "Based off of code by Prof. Sidney Marshall, Rochester Institute of Technology Department of Computer Science" << endl;
52
        cout << "Original source code may be found at http://cs.rit.edu/~swm/makemake" << endl;
53
        cout << "Currently maintained by rm5248 @ www.rm5248.com" << endl;
54
 
55
}
56
 
1 rm5248 57
int main( int argc, char **argv ){
2 rm5248 58
        char* progName;
1 rm5248 59
  string header_file( "header.mak" );
60
  string programs_file( "programs.mak" );
61
 
62
  // Flag indicates whether the CCFLAGS and CFLAGS output should
63
  // have -g debugging option omitted
64
  bool noDebugFlag( false );
65
 
2 rm5248 66
  map<string, string> config;  
67
  config["c_compiler"] = "gcc";
68
  config["cpp_compiler"] = "g++";
69
  config["no_debug"] = "false";
70
  config["header_file"] = "header.mak";
71
  config["program_file"] = "programs.mak";
72
  config["update"] = "false";
73
  config["depends"] = "false";
74
  config["ar"] = "false";
75
  config["so"] = "false";
76
  config["install"] = "false";
77
  config["prefix"] = "/usr/bin";
78
  config["dirs"] = ".";
79
 
1 rm5248 80
  // Flag indicates using gnu compiler
81
  bool useGCC = false;
82
 
83
  // check gnu compiler make or sun compiler make
84
  // if first letter of executable is 'g' then gnu otherwise sun
85
 
86
  char *exename = argv[0];
87
  char c;
88
 
89
  while((c = *exename++)) {
90
    if(c == '/') {
91
      argv[0] = exename;
92
    }
93
  }
94
  if(argv[0][0] == 'g') {
95
    useGCC = true;
96
  }
2 rm5248 97
  progName = argv[0];
98
  config["executable"] = string( progName );
1 rm5248 99
 
100
  //
101
  // Process command line options
102
  //
103
  while( argc--, *++argv != NULL && **argv == '-' ){
104
    if( strcmp( *argv, "-header" ) == 0 && argv[ 1 ] != NULL ){
105
      header_file = *++argv;
106
      argc--;
107
    } else if( strcmp( *argv, "-no-header" ) == 0 ){
108
      header_file = "//";
109
    } else if( strcmp( *argv, "-programs" ) == 0 && argv[ 1 ] != NULL ){
110
      programs_file = *++argv;
111
      argc--;
112
    } else if( strcmp( *argv, "-no-programs" ) == 0 ){
113
      programs_file = "//";
114
    } else if(strcmp("-no-debug",*argv) == 0){
115
      noDebugFlag = true;
2 rm5248 116
    } else if( strcmp("--help", *argv) == 0 ){
117
        printHelp( progName );
118
        return 0;
119
    } else if( strcmp("-update", *argv) == 0 ){
120
        cout << "Update makefile NOT YET IMPLEMENTED" << endl;
121
    } else if( strcmp("-depends", *argv) == 0 ){
122
        cout << "Update depends NOT YET IMPLEMENTED" << endl;
123
    } else if( strcmp("-ar", *argv) == 0 ){
124
        cout << "make archive file NOT YET IMPLEMENTED" << endl;
125
    } else if( strcmp("-so", *argv) == 0 ){
126
        cout << "make shared object file NOT YET IMPLEMENTED" << endl;
127
    } else if( strcmp("-install", *argv) == 0 ){
128
 
129
    } else if( strcmp("-prefix", *argv) == 0 ){
130
 
131
    } else if( strcmp("-dirs", *argv) == 0 ){
132
        cout << "DIRS NOT YET IMPLEMENTED" << endl;
133
    //} else if( strcmp("-update", *argv) == 0 ){
134
    //} else if( strcmp("-update", *argv) == 0 ){
135
    }else {
1 rm5248 136
      switch( *++*argv ){
137
      case 'd':
138
        debug = true;
139
        break;
140
 
141
      default:
142
        cerr << "Invalid option: -" << **argv << endl;
143
        exit( 1 );
144
      }
145
    }
146
  }
147
 
148
  //
149
  // Read the current directory (and cmd line arguments) to find 
150
  // file names.
151
  //
152
  DirList dirlist( argc, argv );
153
 
154
  //
155
  // Now write the makefile
156
  //
2 rm5248 157
  Write write( dirlist, &config );
1 rm5248 158
 
159
  return 0;
160
}