an update containing libatomic changes.
[AROS.git] / tools / MetaMake / mmake.c
blobc069fa46e655259f6dbfb2082cc0667ec3a1d912
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;
80 int logfailed = 0;
81 FILE *mm_faillogfh = NULL;
83 char *mm_srcdir; /* Location to scan for cfg files */
84 char *mm_builddir; /* Location to generate files/build in */
85 char *mm_envtarget;
87 /* Functions */
88 void
89 error (char * fmt, ...)
91 va_list args;
92 VA_START (args, fmt);
93 fprintf (stderr, "[MMAKE] Error: ");
94 vfprintf (stderr, fmt, args);
95 if (errno != 0)
96 fprintf (stderr, ": %s", strerror (errno));
97 fprintf (stderr, "\n");
98 va_end (args);
103 main (int argc, char ** argv)
105 char * currdir;
106 int t;
107 char * targets[64];
108 int targetc;
109 int doenv = 0;
111 currdir = getcwd (NULL, 1024);
113 mm_srcdir = currdir;
114 mm_builddir = currdir;
116 mflagc = targetc = 0;
118 for (t=1; t<argc; t++)
120 if (argv[t][0] == '-')
122 if (!strcmp (argv[t], "--version"))
124 printf ("MetaMake %s (%s)\n", PACKAGE_VERSION, __DATE__);
125 if (argc == 2)
126 exit (0);
128 else if (!strncmp (argv[t], "--srcdir", 8) || !strcmp (argv[t], "-s"))
130 mm_srcdir = (char *)&argv[t][9];
132 else if (!strncmp (argv[t], "--builddir", 10) || !strcmp (argv[t], "-b"))
134 mm_builddir = (char *)&argv[t][11];
136 else if (!strcmp (argv[t], "--verbose") || !strcmp (argv[t], "-v"))
138 verbose = 1;
140 else if (!strcmp (argv[t], "--quiet") || !strcmp (argv[t], "-q"))
142 quiet = 1;
144 else if (!strcmp (argv[t], "--debug"))
146 debug = 1;
148 else if (!strcmp (argv[t], "--logfailed"))
150 logfailed = 1;
152 else if (!strcmp (argv[t], "--help"))
154 printf ("%s [--srcdir=<directory>] [--builddir=<directory>] [--version] [-v,--verbose] [-q,--quiet] [--debug] [--help]\n", argv[0]);
155 return 0;
157 else
159 mflags[mflagc++] = argv[t];
162 else
164 targets[targetc++] = argv[t];
168 if (verbose)
170 quiet = 0;
171 printf ("SRCDIR '%s'\n", mm_srcdir);
172 printf ("BUILDDIR '%s'\n", mm_builddir);
175 if (debug)
177 quiet = 0;
180 debug(printf("MMAKE:mmake.c->main: parsed command line options\n"));
182 initprojects ();
184 debug(printf("MMAKE:mmake.c->main: projects initialised\n"));
186 if (!targetc)
188 struct Project * firstprj = getfirstproject ();
190 assert (firstprj);
192 targets[targetc++] = firstprj->node.name;
193 debug(printf("MMAKE:mmake.c->main: targetc not set, using default'%s'\n", firstprj->node.name));
196 mm_envtarget = getenv("_MMAKE_TARGETS");
197 if (!mm_envtarget)
198 doenv = 1;
200 if (logfailed)
201 mm_faillogfh = fopen ("mmake.failed", "w");
203 for (t=0; t<targetc; t++)
205 char * pname, * tname, * ptr;
206 struct Project * prj;
208 pname = ptr = targets[t];
209 while (*ptr && *ptr != '.')
210 ptr ++;
211 if (*ptr)
212 *ptr ++ = 0;
213 tname = ptr;
215 prj = findproject (pname);
217 if (!prj)
219 printf ("[MMAKE] Nothing known about project %s\n", pname);
220 return 20;
223 if (doenv)
225 setenv("_MMAKE_TARGET", tname, 1);
226 mm_envtarget = tname;
229 debug(printf("MMAKE:mmake.c->main: calling maketarget '%s'\n", tname));
230 maketarget (prj, tname);
232 if (doenv)
233 unsetenv("_MMAKE_TARGET");
236 if (mm_faillogfh)
237 fclose (mm_faillogfh);
239 expungeprojects ();
241 ASSERT(chdir (currdir) == 0);
243 free (currdir);
245 return 0;