wip
[AROS.git] / tools / MetaMake / mmake.c
blob5c6b57c9d0442fef1c86ead982da8a6bb80ed0c8
1 /* MetaMake - A Make extension
2 Copyright © 1995-2011, 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 quiet = 0;
79 int debug = 0;
81 char *mm_srcdir; /* Location to scan for cfg files */
82 char *mm_builddir; /* Location to generate files/build in */
84 /* Functions */
85 void
86 error (char * fmt, ...)
88 va_list args;
89 VA_START (args, fmt);
90 fprintf (stderr, "[MMAKE] Error: ");
91 vfprintf (stderr, fmt, args);
92 if (errno != 0)
93 fprintf (stderr, ": %s", strerror (errno));
94 fprintf (stderr, "\n");
95 va_end (args);
99 int
100 main (int argc, char ** argv)
102 char * currdir;
103 int t;
104 char * targets[64];
105 int targetc;
107 currdir = getcwd (NULL, 1024);
109 mm_srcdir = currdir;
110 mm_builddir = currdir;
112 mflagc = targetc = 0;
114 for (t=1; t<argc; t++)
116 if (argv[t][0] == '-')
118 if (!strcmp (argv[t], "--version"))
120 printf ("MetaMake %s (%s)\n", PACKAGE_VERSION, __DATE__);
121 if (argc == 2)
122 exit (0);
124 else if (!strncmp (argv[t], "--srcdir", 8) || !strcmp (argv[t], "-s"))
126 mm_srcdir = (char *)&argv[t][9];
128 else if (!strncmp (argv[t], "--builddir", 10) || !strcmp (argv[t], "-b"))
130 mm_builddir = (char *)&argv[t][11];
132 else if (!strcmp (argv[t], "--verbose") || !strcmp (argv[t], "-v"))
134 verbose = 1;
136 else if (!strcmp (argv[t], "--quiet") || !strcmp (argv[t], "-q"))
138 quiet = 1;
140 else if (!strcmp (argv[t], "--debug"))
142 debug = 1;
144 else if (!strcmp (argv[t], "--help"))
146 printf ("%s [--srcdir=<directory>] [--builddir=<directory>] [--version] [-v,--verbose] [-q,--quiet] [--debug] [--help]\n", argv[0]);
147 return 0;
149 else
151 mflags[mflagc++] = argv[t];
154 else
156 targets[targetc++] = argv[t];
160 if (verbose)
162 quiet = 0;
163 printf ("SRCDIR '%s'\n", mm_srcdir);
164 printf ("BUILDDIR '%s'\n", mm_builddir);
167 if (debug)
169 quiet = 0;
172 debug(printf("MMAKE:mmake.c->main: parsed command line options\n"));
174 initprojects ();
176 debug(printf("MMAKE:mmake.c->main: projects initialised\n"));
178 if (!targetc)
180 struct Project * firstprj = getfirstproject ();
182 assert (firstprj);
184 targets[targetc++] = firstprj->node.name;
185 debug(printf("MMAKE:mmake.c->main: targetc not set, using default'%s'\n", firstprj->node.name));
188 for (t=0; t<targetc; t++)
190 char * pname, * tname, * ptr;
191 struct Project * prj;
193 pname = ptr = targets[t];
194 while (*ptr && *ptr != '.')
195 ptr ++;
196 if (*ptr)
197 *ptr ++ = 0;
198 tname = ptr;
200 prj = findproject (pname);
202 if (!prj)
204 printf ("[MMAKE] Nothing known about project %s\n", pname);
205 return 20;
208 debug(printf("MMAKE:mmake.c->main: calling maketarget '%s'\n", tname));
209 maketarget (prj, tname);
212 expungeprojects ();
214 ASSERT(chdir (currdir) == 0);
216 free (currdir);
218 return 0;