4 * Handle recursive makes
6 * © 1998 Straylight/Edgeware
9 /*----- Licensing note ----------------------------------------------------*
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2, or (at your option)
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program. If not, write to the Free Software Foundation,
23 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
26 /*----- Header files ------------------------------------------------------*/
39 /*----- Main code ---------------------------------------------------------*/
41 typedef struct submk_ctx {
47 static void submk_add(const char *p, void *ctx)
49 int len = _swi(OS_FSControl, _inr(0, 5) | _return(5), 37, p, 0, 0, 0, 0);
50 char *q = xmalloc(1 - len);
53 _swi(OS_FSControl, _inr(0, 5), 37, p, q, 0, 0, 1 - len);
54 if (sx->i == sx->sz) {
56 sx->p = xrealloc(sx->p, sx->sz * sizeof(sx->p[0]));
61 static char *nstrcpy(char *d, const char *s)
63 while ((*d++ = *s++) != 0)
68 int main(int argc, char *argv[])
75 /* --- Remember the original DDEUtils prefix --- */
79 if (_swix(OS_ReadVarVal, _inr(0, 4) | _out(2),
80 "Prefix$Dir", prefix, sizeof(prefix), 0, 0,
87 /* --- Initialise the context --- */
90 sx.p = xmalloc(sx.sz * sizeof(sx.p[0]));
93 /* --- Mangle the command line arguments --- */
98 /* --- Expand wildcarded makefile names --- */
100 for (i = 1; i < argc && strcmp(argv[i], "--"); i++) {
101 if (glob(argv[i], submk_add, &sx) == 0)
102 submk_add(argv[i], &sx);
105 /* --- Take the rest of the arguments --- *
107 * This is one of those times that C shows its Unix roots most
108 * irritatingly. I've got to grab all the carefully separated
109 * arguments, and stick them all back together.
120 for (j = i; j < argc; j++)
121 sz += strlen(argv[j]) + 1;
122 tail = xmalloc(sz + 1);
125 p = nstrcpy(p, argv[i++]);
126 for (j = i; j < argc; j++) {
128 p = nstrcpy(p, argv[j]);
134 /* --- Now start work on making things --- */
141 _swi(XDDEUtils_Prefix, _in(0), 0);
142 for (i = 0; i < sx.i; i++) {
143 sprintf(cmdbuf, "amu -desktop -f %s%s", sx.p[i], tail);
144 printf("submake: Making%s with `%s'\n", tail, sx.p[i]);
145 if ((e = system(cmdbuf)) != 0) {
146 printf("submake: Failed%s with `%s' [%i]\n", tail, sx.p[i], e);
149 printf("submake: Successfully made%s with `%s'\n", tail, sx.p[i]);
153 /* --- Restore the original prefix --- */
156 _swi(XDDEUtils_Prefix, _in(0), prefix);
158 /* --- That's it: return --- */