Added include dir to allow compilation with GCC 3 again.
[cake.git] / tools / MetaMake / mmake.c
blob896f1167aae8214e09e36516d4d24a6ec1addf6a
1 /* MetaMake - A Make extension
2 Copyright © 1995-2008, The AROS Development Team. All rights reserved.
4 This file is part of MetaMake.
6 MetaMake is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
11 MetaMake is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU CC; see the file COPYING. If not, write to
18 the Free Software Foundation, 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
20 /* Includes */
22 //#define DEBUG_MMAKE
24 #include "config.h"
26 #ifdef PROTOTYPES
27 # define PARAMS(x) x
28 #else
29 # define PARAMS(x) ()
30 #endif /* PROTOTYPES */
32 #if defined(HAVE_STDARG_H) && defined(__STDC__) && __STDC__
33 # include <stdarg.h>
34 # define VA_START(args, lastarg) va_start(args, lastarg)
35 #else
36 # include <varargs.h>
37 # define VA_START(args, lastarg) va_start(args)
38 #endif
40 #ifndef __DATE__
41 # define __DATE__ "No __DATE__"
42 #endif
44 #include <stdio.h>
45 #include <assert.h>
46 #include <errno.h>
47 #include <ctype.h>
48 #include <stdlib.h>
49 #include <time.h>
50 #ifdef HAVE_STRING_H
51 # include <string.h>
52 #else
53 # include <strings.h>
54 #endif
55 #ifdef HAVE_SYS_STAT_H
56 # include <sys/stat.h>
57 #endif
58 #ifdef HAVE_SYS_TYPES_H
59 # include <sys/types.h>
60 #endif
62 #include "list.h"
63 #include "mem.h"
64 #include "var.h"
65 #include "dep.h"
66 #include "project.h"
68 #if defined(DEBUG_MMAKE)
69 #define debug(a) a
70 #else
71 #define debug(v)
72 #endif
74 /* globals */
75 char * mflags[64];
76 int mflagc;
77 int verbose = 0;
78 int debug = 0;
80 char *mm_srcdir; /* Location to scan for cfg files */
81 char *mm_builddir; /* Location to generate files/build in */
83 /* Functions */
84 void
85 error (char * fmt, ...)
87 va_list args;
88 VA_START (args, fmt);
89 fprintf (stderr, "Error: ");
90 vfprintf (stderr, fmt, args);
91 if (errno != 0)
92 fprintf (stderr, ": %s", strerror (errno));
93 fprintf (stderr, "\n");
94 va_end (args);
98 int
99 main (int argc, char ** argv)
101 char * currdir;
102 int t;
103 char * targets[64];
104 int targetc;
106 currdir = getcwd (NULL, 1024);
108 mm_srcdir = currdir;
109 mm_builddir = currdir;
111 mflagc = targetc = 0;
113 for (t=1; t<argc; t++)
115 if (argv[t][0] == '-')
117 if (!strcmp (argv[t], "--version"))
119 printf ("MetaMake %s (%s)\n", PACKAGE_VERSION, __DATE__);
120 if (argc == 2)
121 exit (0);
123 else if (!strncmp (argv[t], "--srcdir", 8) || !strcmp (argv[t], "-s"))
125 mm_srcdir = (char *)&argv[t][9];
127 else if (!strncmp (argv[t], "--builddir", 10) || !strcmp (argv[t], "-b"))
129 mm_builddir = (char *)&argv[t][11];
131 else if (!strcmp (argv[t], "--verbose") || !strcmp (argv[t], "-v"))
133 verbose = 1;
135 else if (!strcmp (argv[t], "--debug"))
137 debug = 1;
139 else if (!strcmp (argv[t], "--help"))
141 printf ("%s [--srcdir=<directory>] [--builddir=<directory>] [--version] [-v,--verbose] [--debug] [--help]\n", argv[0]);
142 return 0;
144 else
146 mflags[mflagc++] = argv[t];
149 else
151 targets[targetc++] = argv[t];
155 if (verbose)
157 printf ("SRCDIR '%s'\n", mm_srcdir);
158 printf ("BUILDDIR '%s'\n", mm_builddir);
161 debug(printf("MMAKE:mmake.c->main: parsed command line options\n"));
163 initprojects ();
165 debug(printf("MMAKE:mmake.c->main: projects initialised\n"));
167 if (!targetc)
169 Project * firstprj = getfirstproject ();
171 assert (firstprj);
173 targets[targetc++] = firstprj->node.name;
174 debug(printf("MMAKE:mmake.c->main: targetc not set, using default'%s'\n", firstprj->node.name));
177 for (t=0; t<targetc; t++)
179 char * pname, * tname, * ptr;
180 Project * prj;
182 pname = ptr = targets[t];
183 while (*ptr && *ptr != '.')
184 ptr ++;
185 if (*ptr)
186 *ptr ++ = 0;
187 tname = ptr;
189 prj = findproject (pname);
191 if (!prj)
193 printf ("Nothing known about project %s\n", pname);
194 return 20;
197 debug(printf("MMAKE:mmake.c->main: calling maketarget '%s'\n", tname));
198 maketarget (prj, tname);
201 expungeprojects ();
203 chdir (currdir);
205 free (currdir);
207 return 0;