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)
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. */
30 #endif /* PROTOTYPES */
32 #if defined(HAVE_STDARG_H) && defined(__STDC__) && __STDC__
34 # define VA_START(args, lastarg) va_start(args, lastarg)
37 # define VA_START(args, lastarg) va_start(args)
41 # define __DATE__ "No __DATE__"
55 #ifdef HAVE_SYS_STAT_H
56 # include <sys/stat.h>
58 #ifdef HAVE_SYS_TYPES_H
59 # include <sys/types.h>
68 #if defined(DEBUG_MMAKE)
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 */
89 error (char * fmt
, ...)
93 fprintf (stderr
, "[MMAKE] Error: ");
94 vfprintf (stderr
, fmt
, args
);
96 fprintf (stderr
, ": %s", strerror (errno
));
97 fprintf (stderr
, "\n");
103 main (int argc
, char ** argv
)
111 currdir
= getcwd (NULL
, 1024);
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__
);
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"))
140 else if (!strcmp (argv
[t
], "--quiet") || !strcmp (argv
[t
], "-q"))
144 else if (!strcmp (argv
[t
], "--debug"))
148 else if (!strcmp (argv
[t
], "--logfailed"))
152 else if (!strcmp (argv
[t
], "--help"))
154 printf ("%s [--srcdir=<directory>] [--builddir=<directory>] [--version] [-v,--verbose] [-q,--quiet] [--debug] [--help]\n", argv
[0]);
159 mflags
[mflagc
++] = argv
[t
];
164 targets
[targetc
++] = argv
[t
];
171 printf ("SRCDIR '%s'\n", mm_srcdir
);
172 printf ("BUILDDIR '%s'\n", mm_builddir
);
180 debug(printf("MMAKE:mmake.c->main: parsed command line options\n"));
184 debug(printf("MMAKE:mmake.c->main: projects initialised\n"));
188 struct Project
* firstprj
= getfirstproject ();
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");
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
!= '.')
215 prj
= findproject (pname
);
219 printf ("[MMAKE] Nothing known about project %s\n", pname
);
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
);
233 unsetenv("_MMAKE_TARGET");
237 fclose (mm_faillogfh
);
241 ASSERT(chdir (currdir
) == 0);