Better ANSI C compatibility and portability:
+ Addition of function prototypes and include files. + Change function definitions to ANSI C style. + Initial support for CMake
This commit is contained in:
parent
10717cc791
commit
910643ccbb
23
util/make/CMakeLists.txt
Normal file
23
util/make/CMakeLists.txt
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
cmake_minimum_required (VERSION 2.6)
|
||||||
|
project (ack-make)
|
||||||
|
|
||||||
|
set(SRC
|
||||||
|
check.c
|
||||||
|
input.c
|
||||||
|
macro.c
|
||||||
|
make.c
|
||||||
|
main.c
|
||||||
|
reader.c
|
||||||
|
rules.c
|
||||||
|
h.h
|
||||||
|
)
|
||||||
|
|
||||||
|
# The following should be added if utime.h and unistd.h are
|
||||||
|
# available.
|
||||||
|
|
||||||
|
# add_definitions(-Dunix)
|
||||||
|
|
||||||
|
add_executable(${PROJECT_NAME} ${SRC})
|
||||||
|
|
||||||
|
install(TARGETS ${PROJECT_NAME} DESTINATION bin)
|
||||||
|
|
|
@ -40,3 +40,6 @@ xi) $? added. (see UNIX manual)
|
||||||
Hacked further by Ceriel Jacobs to make it work better. Use this "make" to
|
Hacked further by Ceriel Jacobs to make it work better. Use this "make" to
|
||||||
install ACK under Microsoft Xenix V3.2. Some of the makefiles are just too
|
install ACK under Microsoft Xenix V3.2. Some of the makefiles are just too
|
||||||
big for the Xenix "make". Strange, they work on a PDP-11 ...
|
big for the Xenix "make". Strange, they work on a PDP-11 ...
|
||||||
|
|
||||||
|
Made it almost ISO C90 and POSIX portable by Carl Eric Codere, and
|
||||||
|
also made it safer by using correct datatypes on some library calls.
|
||||||
|
|
|
@ -7,13 +7,32 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include "h.h"
|
#include "h.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Recursive routine that does the actual checking.
|
||||||
|
*/
|
||||||
|
static void check(struct name *np)
|
||||||
|
{
|
||||||
|
register struct depend * dp;
|
||||||
|
register struct line * lp;
|
||||||
|
|
||||||
|
if (np->n_flag & N_MARK)
|
||||||
|
fatal("Circular dependency from %s", np->n_name);
|
||||||
|
|
||||||
|
np->n_flag |= N_MARK;
|
||||||
|
|
||||||
|
for (lp = np->n_line; lp; lp = lp->l_next)
|
||||||
|
for (dp = lp->l_dep; dp; dp = dp->d_next)
|
||||||
|
check(dp->d_name);
|
||||||
|
|
||||||
|
np->n_flag &= (uchar)~N_MARK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Prints out the structures as defined in memory. Good for check
|
* Prints out the structures as defined in memory. Good for check
|
||||||
* that you make file does what you want (and for debugging make).
|
* that you make file does what you want (and for debugging make).
|
||||||
*/
|
*/
|
||||||
void
|
void prt(void)
|
||||||
prt()
|
|
||||||
{
|
{
|
||||||
register struct name * np;
|
register struct name * np;
|
||||||
register struct depend * dp;
|
register struct depend * dp;
|
||||||
|
@ -21,7 +40,6 @@ prt()
|
||||||
register struct cmd * cp;
|
register struct cmd * cp;
|
||||||
register struct macro * mp;
|
register struct macro * mp;
|
||||||
|
|
||||||
|
|
||||||
for (mp = macrohead; mp; mp = mp->m_next)
|
for (mp = macrohead; mp; mp = mp->m_next)
|
||||||
fprintf(stderr, "%s = %s\n", mp->m_name, mp->m_val);
|
fprintf(stderr, "%s = %s\n", mp->m_name, mp->m_val);
|
||||||
|
|
||||||
|
@ -43,11 +61,7 @@ prt()
|
||||||
fputc('\n', stderr);
|
fputc('\n', stderr);
|
||||||
|
|
||||||
for (cp = lp->l_cmd; cp; cp = cp->c_next)
|
for (cp = lp->l_cmd; cp; cp = cp->c_next)
|
||||||
#ifdef os9
|
|
||||||
fprintf(stderr, "- %s\n", cp->c_cmd);
|
|
||||||
#else
|
|
||||||
fprintf(stderr, "-\t%s\n", cp->c_cmd);
|
fprintf(stderr, "-\t%s\n", cp->c_cmd);
|
||||||
#endif
|
|
||||||
fputc('\n', stderr);
|
fputc('\n', stderr);
|
||||||
}
|
}
|
||||||
fputc('\n', stderr);
|
fputc('\n', stderr);
|
||||||
|
@ -55,30 +69,6 @@ prt()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Recursive routine that does the actual checking.
|
|
||||||
*/
|
|
||||||
void
|
|
||||||
check(np)
|
|
||||||
struct name * np;
|
|
||||||
{
|
|
||||||
register struct depend * dp;
|
|
||||||
register struct line * lp;
|
|
||||||
|
|
||||||
|
|
||||||
if (np->n_flag & N_MARK)
|
|
||||||
fatal("Circular dependency from %s", np->n_name);
|
|
||||||
|
|
||||||
np->n_flag |= N_MARK;
|
|
||||||
|
|
||||||
for (lp = np->n_line; lp; lp = lp->l_next)
|
|
||||||
for (dp = lp->l_dep; dp; dp = dp->d_next)
|
|
||||||
check(dp->d_name);
|
|
||||||
|
|
||||||
np->n_flag &= ~N_MARK;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Look for circular dependancies.
|
* Look for circular dependancies.
|
||||||
* ie.
|
* ie.
|
||||||
|
@ -86,28 +76,23 @@ struct name * np;
|
||||||
* b: a
|
* b: a
|
||||||
* is a circular dep
|
* is a circular dep
|
||||||
*/
|
*/
|
||||||
void
|
void circh(void)
|
||||||
circh()
|
|
||||||
{
|
{
|
||||||
register struct name * np;
|
register struct name * np;
|
||||||
|
|
||||||
|
|
||||||
for (np = namehead.n_next; np; np = np->n_next)
|
for (np = namehead.n_next; np; np = np->n_next)
|
||||||
check(np);
|
check(np);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Check the target .PRECIOUS, and mark its dependentd as precious
|
* Check the target .PRECIOUS, and mark its dependentd as precious
|
||||||
*/
|
*/
|
||||||
void
|
void precious(void)
|
||||||
precious()
|
|
||||||
{
|
{
|
||||||
register struct depend * dp;
|
register struct depend * dp;
|
||||||
register struct line * lp;
|
register struct line * lp;
|
||||||
register struct name * np;
|
register struct name * np;
|
||||||
|
|
||||||
|
|
||||||
if (!((np = newname(".PRECIOUS"))->n_flag & N_TARG))
|
if (!((np = newname(".PRECIOUS"))->n_flag & N_TARG))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|
|
@ -6,29 +6,17 @@
|
||||||
|
|
||||||
|
|
||||||
#ifndef uchar
|
#ifndef uchar
|
||||||
#ifdef os9
|
|
||||||
#define uchar char
|
|
||||||
#define void int
|
|
||||||
#define fputc putc
|
|
||||||
#else
|
|
||||||
#define uchar unsigned char
|
#define uchar unsigned char
|
||||||
#endif
|
#endif
|
||||||
#endif
|
|
||||||
|
#include <time.h>
|
||||||
|
|
||||||
#define bool int
|
#define bool int
|
||||||
#define time_t long
|
|
||||||
#define TRUE (1)
|
#define TRUE (1)
|
||||||
#define FALSE (0)
|
#define FALSE (0)
|
||||||
#define max(a,b) ((a)>(b)?(a):(b))
|
|
||||||
|
|
||||||
#define DEFN1 "makefile" /* Default names */
|
#define DEFN1 "makefile" /* Default names */
|
||||||
#ifdef unix
|
|
||||||
#define DEFN2 "Makefile"
|
#define DEFN2 "Makefile"
|
||||||
#endif
|
|
||||||
#ifdef eon
|
|
||||||
#define DEFN2 "Makefile"
|
|
||||||
#endif
|
|
||||||
/* os9 is case insensitive */
|
|
||||||
|
|
||||||
#define LZ (2048) /* Line size */
|
#define LZ (2048) /* Line size */
|
||||||
|
|
||||||
|
@ -116,30 +104,24 @@ extern char str1[];
|
||||||
extern char str2[];
|
extern char str2[];
|
||||||
extern int lineno;
|
extern int lineno;
|
||||||
|
|
||||||
char * fgets();
|
void circh(void);
|
||||||
char * index();
|
char * getmacro(char* name);
|
||||||
char * rindex();
|
struct macro * setmacro(char* name, char* val, int prio);
|
||||||
char * malloc();
|
void input(FILE *fd);
|
||||||
char * strcpy();
|
void error(char *msg, char* a1);
|
||||||
char * strcat();
|
void expand(char *str);
|
||||||
extern int errno;
|
void fatal(char* msg, char* value);
|
||||||
|
bool dyndep(struct name *np);
|
||||||
void circh();
|
int make(struct name *np, int level);
|
||||||
char * getmacro();
|
void modtime(struct name *np);
|
||||||
struct macro * setmacro();
|
struct name *newname(char *name);
|
||||||
void input();
|
struct depend *newdep(struct name *np, struct depend *dp);
|
||||||
void error();
|
struct cmd *newcmd(char *str, struct cmd *cp);
|
||||||
void expand();
|
void newline(struct name *np, struct depend *dp, struct cmd *cp, int flag);
|
||||||
void fatal();
|
void prt(void);
|
||||||
int make();
|
char *suffix(char *name);
|
||||||
void modtime();
|
void touch(struct name *np);
|
||||||
struct name * newname();
|
void makerules(void);
|
||||||
struct depend * newdep();
|
char *gettok(char **ptr);
|
||||||
struct cmd * newcmd();
|
void precious(void);
|
||||||
void newline();
|
bool mgetline(char* str, FILE* fd);
|
||||||
void prt();
|
|
||||||
char * suffix();
|
|
||||||
void touch();
|
|
||||||
void makerules();
|
|
||||||
char * gettok();
|
|
||||||
void precious();
|
|
||||||
|
|
|
@ -4,47 +4,39 @@
|
||||||
* $Header$
|
* $Header$
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <stdlib.h>
|
||||||
#include "h.h"
|
#include "h.h"
|
||||||
|
|
||||||
|
|
||||||
struct name namehead;
|
struct name namehead;
|
||||||
struct name * firstname;
|
struct name * firstname;
|
||||||
|
|
||||||
char str1[LZ]; /* General store */
|
char str1[LZ]; /* General store */
|
||||||
char str2[LZ];
|
char str2[LZ];
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Intern a name. Return a pointer to the name struct
|
* Intern a name. Return a pointer to the name struct
|
||||||
*/
|
*/
|
||||||
struct name *
|
struct name *newname(char *name)
|
||||||
newname(name)
|
|
||||||
char * name;
|
|
||||||
{
|
{
|
||||||
|
|
||||||
register struct name * rp;
|
register struct name * rp;
|
||||||
register struct name * rrp;
|
register struct name * rrp;
|
||||||
register char * cp;
|
register char * cp;
|
||||||
|
|
||||||
|
for (rp = namehead.n_next, rrp = &namehead; rp;
|
||||||
for
|
rp = rp->n_next, rrp = rrp->n_next)
|
||||||
(
|
|
||||||
rp = namehead.n_next, rrp = &namehead;
|
|
||||||
rp;
|
|
||||||
rp = rp->n_next, rrp = rrp->n_next
|
|
||||||
)
|
|
||||||
if (strcmp(name, rp->n_name) == 0)
|
if (strcmp(name, rp->n_name) == 0)
|
||||||
return rp;
|
return rp;
|
||||||
|
|
||||||
if ((rp = (struct name *)malloc(sizeof (struct name)))
|
if ((rp = (struct name *) malloc(sizeof(struct name))) == (struct name *) 0)
|
||||||
== (struct name *)0)
|
fatal("No memory for name",NULL);
|
||||||
fatal("No memory for name");
|
|
||||||
rrp->n_next = rp;
|
rrp->n_next = rp;
|
||||||
rp->n_next = (struct name *) 0;
|
rp->n_next = (struct name *) 0;
|
||||||
if ((cp = malloc((unsigned) (strlen(name) + 1))) == (char *) 0)
|
if ((cp = malloc((unsigned) (strlen(name) + 1))) == (char *) 0)
|
||||||
fatal("No memory for name");
|
fatal("No memory for name",NULL);
|
||||||
strcpy(cp, name);
|
strcpy(cp, name);
|
||||||
rp->n_name = cp;
|
rp->n_name = cp;
|
||||||
rp->n_line = (struct line *) 0;
|
rp->n_line = (struct line *) 0;
|
||||||
|
@ -54,23 +46,18 @@ char * name;
|
||||||
return rp;
|
return rp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Add a dependant to the end of the supplied list of dependants.
|
* Add a dependant to the end of the supplied list of dependants.
|
||||||
* Return the new head pointer for that list.
|
* Return the new head pointer for that list.
|
||||||
*/
|
*/
|
||||||
struct depend *
|
struct depend *newdep(struct name *np, struct depend *dp)
|
||||||
newdep(np, dp)
|
|
||||||
struct name * np;
|
|
||||||
struct depend * dp;
|
|
||||||
{
|
{
|
||||||
register struct depend * rp;
|
register struct depend * rp;
|
||||||
register struct depend * rrp;
|
register struct depend * rrp;
|
||||||
|
|
||||||
|
|
||||||
if ((rp = (struct depend *) malloc(sizeof(struct depend)))
|
if ((rp = (struct depend *) malloc(sizeof(struct depend)))
|
||||||
== (struct depend *) 0)
|
== (struct depend *) 0)
|
||||||
fatal("No memory for dependant");
|
fatal("No memory for dependant",NULL);
|
||||||
rp->d_next = (struct depend *) 0;
|
rp->d_next = (struct depend *) 0;
|
||||||
rp->d_name = np;
|
rp->d_name = np;
|
||||||
|
|
||||||
|
@ -85,22 +72,17 @@ struct depend * dp;
|
||||||
return dp;
|
return dp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Add a command to the end of the supplied list of commands.
|
* Add a command to the end of the supplied list of commands.
|
||||||
* Return the new head pointer for that list.
|
* Return the new head pointer for that list.
|
||||||
*/
|
*/
|
||||||
struct cmd *
|
struct cmd *newcmd(char *str, struct cmd *cp)
|
||||||
newcmd(str, cp)
|
|
||||||
char * str;
|
|
||||||
struct cmd * cp;
|
|
||||||
{
|
{
|
||||||
register struct cmd * rp;
|
register struct cmd * rp;
|
||||||
register struct cmd * rrp;
|
register struct cmd * rrp;
|
||||||
register char * rcp;
|
register char * rcp;
|
||||||
|
|
||||||
|
if ((rcp = strrchr(str, '\n')))
|
||||||
if (rcp = rindex(str, '\n'))
|
|
||||||
*rcp = '\0'; /* Loose newline */
|
*rcp = '\0'; /* Loose newline */
|
||||||
|
|
||||||
while (isspace(*str))
|
while (isspace(*str))
|
||||||
|
@ -109,12 +91,11 @@ struct cmd * cp;
|
||||||
if (*str == '\0') /* If nothing left, the exit */
|
if (*str == '\0') /* If nothing left, the exit */
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if ((rp = (struct cmd *)malloc(sizeof (struct cmd)))
|
if ((rp = (struct cmd *) malloc(sizeof(struct cmd))) == (struct cmd *) 0)
|
||||||
== (struct cmd *)0)
|
fatal("No memory for command",NULL);
|
||||||
fatal("No memory for command");
|
|
||||||
rp->c_next = (struct cmd *) 0;
|
rp->c_next = (struct cmd *) 0;
|
||||||
if ((rcp = malloc((unsigned) (strlen(str) + 1))) == (char *) 0)
|
if ((rcp = malloc((unsigned) (strlen(str) + 1))) == (char *) 0)
|
||||||
fatal("No memory for command");
|
fatal("No memory for command",NULL);
|
||||||
strcpy(rcp, str);
|
strcpy(rcp, str);
|
||||||
rp->c_cmd = rcp;
|
rp->c_cmd = rcp;
|
||||||
|
|
||||||
|
@ -129,7 +110,6 @@ struct cmd * cp;
|
||||||
return cp;
|
return cp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Add a new 'line' of stuff to a target. This check to see
|
* Add a new 'line' of stuff to a target. This check to see
|
||||||
* if commands already exist for the target. If flag is set,
|
* if commands already exist for the target. If flag is set,
|
||||||
|
@ -144,17 +124,12 @@ struct cmd * cp;
|
||||||
* Neither of these free the space used by dependents or commands,
|
* Neither of these free the space used by dependents or commands,
|
||||||
* since they could be used by another target.
|
* since they could be used by another target.
|
||||||
*/
|
*/
|
||||||
void
|
void newline(struct name *np, struct depend *dp, struct cmd *cp, int flag)
|
||||||
newline(np, dp, cp, flag)
|
|
||||||
struct name * np;
|
|
||||||
struct depend * dp;
|
|
||||||
struct cmd * cp;
|
|
||||||
{
|
{
|
||||||
bool hascmds = FALSE; /* Target has commands */
|
bool hascmds = FALSE; /* Target has commands */
|
||||||
register struct line * rp;
|
register struct line * rp;
|
||||||
register struct line * rrp;
|
register struct line * rrp;
|
||||||
|
|
||||||
|
|
||||||
/* Handle the .SUFFIXES case */
|
/* Handle the .SUFFIXES case */
|
||||||
if (!strcmp(np->n_name, ".SUFFIXES") && !dp && !cp)
|
if (!strcmp(np->n_name, ".SUFFIXES") && !dp && !cp)
|
||||||
{
|
{
|
||||||
|
@ -164,17 +139,13 @@ struct cmd * cp;
|
||||||
free((char *) rp);
|
free((char *) rp);
|
||||||
}
|
}
|
||||||
np->n_line = (struct line *) 0;
|
np->n_line = (struct line *) 0;
|
||||||
np->n_flag &= ~N_TARG;
|
np->n_flag &= (uchar)~N_TARG;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* This loop must happen since rrp is used later. */
|
/* This loop must happen since rrp is used later. */
|
||||||
for
|
for (rp = np->n_line, rrp = (struct line *) 0; rp;
|
||||||
(
|
rrp = rp, rp = rp->l_next)
|
||||||
rp = np->n_line, rrp = (struct line *)0;
|
|
||||||
rp;
|
|
||||||
rrp = rp, rp = rp->l_next
|
|
||||||
)
|
|
||||||
if (rp->l_cmd)
|
if (rp->l_cmd)
|
||||||
hascmds = TRUE;
|
hascmds = TRUE;
|
||||||
|
|
||||||
|
@ -191,9 +162,8 @@ struct cmd * cp;
|
||||||
if (!(np->n_flag & N_DOUBLE) != !flag) /* like xor */
|
if (!(np->n_flag & N_DOUBLE) != !flag) /* like xor */
|
||||||
error("Inconsistent rules for target %s", np->n_name);
|
error("Inconsistent rules for target %s", np->n_name);
|
||||||
|
|
||||||
if ((rp = (struct line *)malloc(sizeof (struct line)))
|
if ((rp = (struct line *) malloc(sizeof(struct line))) == (struct line *) 0)
|
||||||
== (struct line *)0)
|
fatal("No memory for line",NULL);
|
||||||
fatal("No memory for line");
|
|
||||||
rp->l_next = (struct line *) 0;
|
rp->l_next = (struct line *) 0;
|
||||||
rp->l_dep = dp;
|
rp->l_dep = dp;
|
||||||
rp->l_cmd = cp;
|
rp->l_cmd = cp;
|
||||||
|
@ -208,14 +178,11 @@ struct cmd * cp;
|
||||||
np->n_flag |= N_DOUBLE;
|
np->n_flag |= N_DOUBLE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Parse input from the makefile, and construct a tree structure
|
* Parse input from the makefile, and construct a tree structure
|
||||||
* of it.
|
* of it.
|
||||||
*/
|
*/
|
||||||
void
|
void input(FILE *fd)
|
||||||
input(fd)
|
|
||||||
FILE * fd;
|
|
||||||
{
|
{
|
||||||
char * p; /* General */
|
char * p; /* General */
|
||||||
char * q;
|
char * q;
|
||||||
|
@ -224,32 +191,27 @@ FILE * fd;
|
||||||
struct cmd * cp;
|
struct cmd * cp;
|
||||||
bool dbl;
|
bool dbl;
|
||||||
|
|
||||||
|
if (mgetline(str1, fd)) /* Read the first line */
|
||||||
if (getline(str1, fd)) /* Read the first line */
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
for (;;)
|
for (;;)
|
||||||
{
|
{
|
||||||
#ifdef os9
|
|
||||||
if (*str1 == ' ') /* Rules without targets */
|
|
||||||
#else
|
|
||||||
if (*str1 == '\t') /* Rules without targets */
|
if (*str1 == '\t') /* Rules without targets */
|
||||||
#endif
|
error("Rules not allowed here", NULL );
|
||||||
error("Rules not allowed here");
|
|
||||||
|
|
||||||
p = str1;
|
p = str1;
|
||||||
|
|
||||||
while (isspace(*p)) /* Find first target */
|
while (isspace(*p)) /* Find first target */
|
||||||
p++;
|
p++;
|
||||||
|
|
||||||
while (((q = index(p, '=')) != (char *)0) &&
|
while (((q = strchr(p, '=')) != (char *) 0) && (p != q)
|
||||||
(p != q) && (q[-1] == '\\')) /* Find value */
|
&& (q[-1] == '\\')) /* Find value */
|
||||||
{
|
{
|
||||||
register char * a;
|
register char * a;
|
||||||
|
|
||||||
a = q - 1; /* Del \ chr; move rest back */
|
a = q - 1; /* Del \ chr; move rest back */
|
||||||
p = q;
|
p = q;
|
||||||
while(*a++ = *q++)
|
while ((*a++ = *q++))
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -260,16 +222,16 @@ FILE * fd;
|
||||||
*q++ = '\0'; /* Separate name and val */
|
*q++ = '\0'; /* Separate name and val */
|
||||||
while (isspace(*q))
|
while (isspace(*q))
|
||||||
q++;
|
q++;
|
||||||
if (p = rindex(q, '\n'))
|
if ((p = strrchr(q, '\n')))
|
||||||
*p = '\0';
|
*p = '\0';
|
||||||
|
|
||||||
p = str1;
|
p = str1;
|
||||||
if ((a = gettok(&p)) == (char *) 0)
|
if ((a = gettok(&p)) == (char *) 0)
|
||||||
error("No macro name");
|
error("No macro name", NULL );
|
||||||
|
|
||||||
setmacro(a, q, 2);
|
setmacro(a, q, 2);
|
||||||
|
|
||||||
if (getline(str1, fd))
|
if (mgetline(str1, fd))
|
||||||
return;
|
return;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -277,19 +239,19 @@ FILE * fd;
|
||||||
expand(str1);
|
expand(str1);
|
||||||
p = str1;
|
p = str1;
|
||||||
|
|
||||||
while (((q = index(p, ':')) != (char *)0) &&
|
while (((q = strchr(p, ':')) != (char *) 0) && (p != q)
|
||||||
(p != q) && (q[-1] == '\\')) /* Find dependents */
|
&& (q[-1] == '\\')) /* Find dependents */
|
||||||
{
|
{
|
||||||
register char * a;
|
register char * a;
|
||||||
|
|
||||||
a = q - 1; /* Del \ chr; move rest back */
|
a = q - 1; /* Del \ chr; move rest back */
|
||||||
p = q;
|
p = q;
|
||||||
while(*a++ = *q++)
|
while ((*a++ = *q++))
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (q == (char *) 0)
|
if (q == (char *) 0)
|
||||||
error("No targets provided");
|
error("No targets provided", NULL );
|
||||||
|
|
||||||
*q++ = '\0'; /* Separate targets and dependents */
|
*q++ = '\0'; /* Separate targets and dependents */
|
||||||
|
|
||||||
|
@ -312,16 +274,12 @@ FILE * fd;
|
||||||
/* Need two nulls for gettok (Remember separation) */
|
/* Need two nulls for gettok (Remember separation) */
|
||||||
|
|
||||||
cp = (struct cmd *) 0;
|
cp = (struct cmd *) 0;
|
||||||
if (getline(str2, fd) == FALSE) /* Get commands */
|
if (mgetline(str2, fd) == FALSE) /* Get commands */
|
||||||
{
|
{
|
||||||
#ifdef os9
|
|
||||||
while (*str2 == ' ')
|
|
||||||
#else
|
|
||||||
while (*str2 == '\t')
|
while (*str2 == '\t')
|
||||||
#endif
|
|
||||||
{
|
{
|
||||||
cp = newcmd(&str2[0], cp);
|
cp = newcmd(&str2[0], cp);
|
||||||
if (getline(str2, fd))
|
if (mgetline(str2, fd))
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,15 +5,16 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
#include "h.h"
|
#include "h.h"
|
||||||
|
|
||||||
|
|
||||||
struct macro * macrohead;
|
struct macro * macrohead;
|
||||||
|
|
||||||
|
|
||||||
struct macro *
|
static struct macro *getmp(char *name)
|
||||||
getmp(name)
|
|
||||||
char * name;
|
|
||||||
{
|
{
|
||||||
register struct macro * rp;
|
register struct macro * rp;
|
||||||
|
|
||||||
|
@ -24,23 +25,18 @@ char * name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
char *
|
char * getmacro(char* name)
|
||||||
getmacro(name)
|
|
||||||
char * name;
|
|
||||||
{
|
{
|
||||||
struct macro * mp;
|
struct macro * mp;
|
||||||
|
|
||||||
if (mp = getmp(name))
|
if ((mp = getmp(name)))
|
||||||
return mp->m_val;
|
return mp->m_val;
|
||||||
else
|
else
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
struct macro *
|
struct macro * setmacro(char* name, char* val, int prio)
|
||||||
setmacro(name, val, prio)
|
|
||||||
char * name;
|
|
||||||
char * val;
|
|
||||||
{
|
{
|
||||||
register struct macro * rp;
|
register struct macro * rp;
|
||||||
register char * cp;
|
register char * cp;
|
||||||
|
@ -60,23 +56,23 @@ char * val;
|
||||||
{
|
{
|
||||||
if ((rp = (struct macro *)malloc(sizeof (struct macro)))
|
if ((rp = (struct macro *)malloc(sizeof (struct macro)))
|
||||||
== (struct macro *)0)
|
== (struct macro *)0)
|
||||||
fatal("No memory for macro");
|
fatal("No memory for macro",NULL);
|
||||||
|
|
||||||
rp->m_next = macrohead;
|
rp->m_next = macrohead;
|
||||||
macrohead = rp;
|
macrohead = rp;
|
||||||
rp->m_flag = FALSE;
|
rp->m_flag = FALSE;
|
||||||
|
|
||||||
if ((cp = malloc((unsigned)(strlen(name)+1))) == (char *)0)
|
if ((cp = malloc((unsigned)(strlen(name)+1))) == (char *)0)
|
||||||
fatal("No memory for macro");
|
fatal("No memory for macro",NULL);
|
||||||
strcpy(cp, name);
|
strcpy(cp, name);
|
||||||
rp->m_name = cp;
|
rp->m_name = cp;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((cp = malloc((unsigned)(strlen(val)+1))) == (char *)0)
|
if ((cp = malloc((unsigned)(strlen(val)+1))) == (char *)0)
|
||||||
fatal("No memory for macro");
|
fatal("No memory for macro",NULL);
|
||||||
strcpy(cp, val); /* Copy in new value */
|
strcpy(cp, val); /* Copy in new value */
|
||||||
rp->m_val = cp;
|
rp->m_val = cp;
|
||||||
rp->m_prio = prio;
|
rp->m_prio = (uchar)prio;
|
||||||
|
|
||||||
return rp;
|
return rp;
|
||||||
}
|
}
|
||||||
|
@ -86,12 +82,7 @@ char * val;
|
||||||
/*
|
/*
|
||||||
* Do the dirty work for expand
|
* Do the dirty work for expand
|
||||||
*/
|
*/
|
||||||
void
|
static void doexp(char **to, char* from, int* len, char* buf)
|
||||||
doexp(to, from, len, buf)
|
|
||||||
char ** to;
|
|
||||||
char * from;
|
|
||||||
int * len;
|
|
||||||
char * buf;
|
|
||||||
{
|
{
|
||||||
register char * rp;
|
register char * rp;
|
||||||
register char * p;
|
register char * p;
|
||||||
|
@ -140,7 +131,7 @@ char * buf;
|
||||||
mp->m_flag = FALSE;
|
mp->m_flag = FALSE;
|
||||||
}
|
}
|
||||||
if (*len <= 0)
|
if (*len <= 0)
|
||||||
error("Expanded line too line");
|
error("Expanded line too line", NULL);
|
||||||
}
|
}
|
||||||
*p = '\0';
|
*p = '\0';
|
||||||
*to = p;
|
*to = p;
|
||||||
|
@ -150,9 +141,7 @@ char * buf;
|
||||||
/*
|
/*
|
||||||
* Expand any macros in str.
|
* Expand any macros in str.
|
||||||
*/
|
*/
|
||||||
void
|
void expand(char *str)
|
||||||
expand(str)
|
|
||||||
char * str;
|
|
||||||
{
|
{
|
||||||
char *a;
|
char *a;
|
||||||
static char b[MBUFSIZ]; /* temp storage for macroname */
|
static char b[MBUFSIZ]; /* temp storage for macroname */
|
||||||
|
@ -160,7 +149,7 @@ char * str;
|
||||||
int len = LZ-1;
|
int len = LZ-1;
|
||||||
|
|
||||||
a = malloc((unsigned)(strlen(str)+1));
|
a = malloc((unsigned)(strlen(str)+1));
|
||||||
if (!a) fatal("No memory for expand");
|
if (!a) fatal("No memory for expand",NULL);
|
||||||
strcpy(a, str);
|
strcpy(a, str);
|
||||||
doexp(&p, a, &len, b);
|
doexp(&p, a, &len, b);
|
||||||
free(a);
|
free(a);
|
||||||
|
|
101
util/make/main.c
101
util/make/main.c
|
@ -18,24 +18,10 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
#include "h.h"
|
#include "h.h"
|
||||||
|
|
||||||
#ifdef unix
|
|
||||||
#include <errno.h>
|
|
||||||
#endif
|
|
||||||
#ifdef eon
|
|
||||||
#include <sys/err.h>
|
|
||||||
#endif
|
|
||||||
#ifdef os9
|
|
||||||
#include <errno.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef eon
|
|
||||||
#define MEMSPACE (16384)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
char * myname;
|
char * myname;
|
||||||
char * makefile; /* The make file */
|
char * makefile; /* The make file */
|
||||||
#ifdef eon
|
#ifdef eon
|
||||||
|
@ -51,11 +37,10 @@ bool rules = TRUE; /* Use inbuilt rules */
|
||||||
bool dotouch = FALSE;/* Touch files instead of making */
|
bool dotouch = FALSE;/* Touch files instead of making */
|
||||||
bool quest = FALSE; /* Question up-to-dateness of file */
|
bool quest = FALSE; /* Question up-to-dateness of file */
|
||||||
|
|
||||||
|
static void usage(void);
|
||||||
|
|
||||||
void
|
|
||||||
main(argc, argv)
|
int main(int argc, char** argv)
|
||||||
int argc;
|
|
||||||
char ** argv;
|
|
||||||
{
|
{
|
||||||
register char * p; /* For argument processing */
|
register char * p; /* For argument processing */
|
||||||
int estat = 0; /* For question */
|
int estat = 0; /* For question */
|
||||||
|
@ -80,17 +65,6 @@ char ** argv;
|
||||||
case 'f': /* Alternate file name */
|
case 'f': /* Alternate file name */
|
||||||
fflag = 1;
|
fflag = 1;
|
||||||
break;
|
break;
|
||||||
#ifdef eon
|
|
||||||
case 'm': /* Change space requirements */
|
|
||||||
if (*++p == '\0')
|
|
||||||
{
|
|
||||||
if (argc-- <= 0)
|
|
||||||
usage();
|
|
||||||
p = *argv++;
|
|
||||||
}
|
|
||||||
memspace = atoi(p);
|
|
||||||
goto end_of_args;
|
|
||||||
#endif
|
|
||||||
case 'n': /* Pretend mode */
|
case 'n': /* Pretend mode */
|
||||||
domake = FALSE;
|
domake = FALSE;
|
||||||
break;
|
break;
|
||||||
|
@ -134,42 +108,26 @@ char ** argv;
|
||||||
argv = nargv - nargc;
|
argv = nargv - nargc;
|
||||||
argc = nargc;
|
argc = nargc;
|
||||||
|
|
||||||
#ifdef eon
|
|
||||||
if (initalloc(memspace) == 0xffff) /* Must get memory for alloc */
|
|
||||||
fatal("Cannot initalloc memory");
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (makefile && strcmp(makefile, "-") == 0) /* Can use stdin as makefile */
|
if (makefile && strcmp(makefile, "-") == 0) /* Can use stdin as makefile */
|
||||||
ifd = stdin;
|
ifd = stdin;
|
||||||
else
|
else
|
||||||
if (!makefile) /* If no file, then use default */
|
if (!makefile) /* If no file, then use default */
|
||||||
{
|
{
|
||||||
if ((ifd = fopen(DEFN1, "r")) == (FILE *)0)
|
if ((ifd = fopen(DEFN1, "r")) == NULL)
|
||||||
#ifdef eon
|
if ((ifd == NULL)
|
||||||
if (errno != ER_NOTF)
|
&& ((ifd = fopen(DEFN2, "r")) == NULL))
|
||||||
fatal("Can't open %s; error %02x", DEFN1, errno);
|
|
||||||
#endif
|
|
||||||
#ifdef unix
|
|
||||||
if (errno != ENOENT)
|
|
||||||
fatal("Can't open %s; error %02x", DEFN1, errno);
|
|
||||||
#endif
|
|
||||||
#ifndef os9
|
|
||||||
if ((ifd == (FILE *)0)
|
|
||||||
&& ((ifd = fopen(DEFN2, "r")) == (FILE *)0))
|
|
||||||
fatal("Can't open %s", DEFN2);
|
fatal("Can't open %s", DEFN2);
|
||||||
#else
|
|
||||||
fatal("Can't open %s", DEFN1);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
if ((ifd = fopen(makefile, "r")) == (FILE *)0)
|
if ((ifd = fopen(makefile, "r")) == NULL)
|
||||||
fatal("Can't open %s", makefile);
|
fatal("Can't open %s", makefile);
|
||||||
|
|
||||||
makerules();
|
makerules();
|
||||||
|
|
||||||
setmacro("$", "$", 4);
|
setmacro("$", "$", 4);
|
||||||
|
|
||||||
while (argc && (p = index(*argv, '=')))
|
while (argc && (p = strchr(*argv, '=')))
|
||||||
{
|
{
|
||||||
char c;
|
char c;
|
||||||
|
|
||||||
|
@ -200,7 +158,7 @@ char ** argv;
|
||||||
precious();
|
precious();
|
||||||
|
|
||||||
if (!firstname)
|
if (!firstname)
|
||||||
fatal("No targets defined");
|
fatal("No targets defined",NULL);
|
||||||
|
|
||||||
circh(); /* Check circles in target definitions */
|
circh(); /* Check circles in target definitions */
|
||||||
|
|
||||||
|
@ -217,10 +175,11 @@ char ** argv;
|
||||||
exit(estat);
|
exit(estat);
|
||||||
else
|
else
|
||||||
exit(0);
|
exit(0);
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
usage()
|
static void usage(void)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "Usage: %s [-f makefile] [-inpqrst] [macro=val ...] [target(s) ...]\n", myname);
|
fprintf(stderr, "Usage: %s [-f makefile] [-inpqrst] [macro=val ...] [target(s) ...]\n", myname);
|
||||||
exit(1);
|
exit(1);
|
||||||
|
@ -228,34 +187,18 @@ usage()
|
||||||
|
|
||||||
|
|
||||||
/*VARARGS1*/
|
/*VARARGS1*/
|
||||||
void
|
void fatal(char *msg, char* value)
|
||||||
fatal(msg, a1, a2, a3, a4, a5, a6)
|
{
|
||||||
char *msg;
|
if (value != NULL)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "%s: ", myname);
|
fprintf(stderr, "%s: ", myname);
|
||||||
fprintf(stderr, msg, a1, a2, a3, a4, a5, a6);
|
fprintf(stderr, msg, value);
|
||||||
|
} else
|
||||||
|
{
|
||||||
|
fprintf(stderr, "%s: ", myname);
|
||||||
|
fprintf(stderr, msg);
|
||||||
|
}
|
||||||
fputc('\n', stderr);
|
fputc('\n', stderr);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
char *
|
|
||||||
index(s, c)
|
|
||||||
register char *s, c;
|
|
||||||
{
|
|
||||||
while (*s)
|
|
||||||
if (*s++ == c)
|
|
||||||
return --s;
|
|
||||||
return (char *)0;
|
|
||||||
}
|
|
||||||
|
|
||||||
char *
|
|
||||||
rindex(str, chr)
|
|
||||||
register char *str, chr;
|
|
||||||
{
|
|
||||||
register char *retptr = 0;
|
|
||||||
|
|
||||||
while (*str)
|
|
||||||
if (*str++ == chr)
|
|
||||||
retptr = &str[-1];
|
|
||||||
return retptr;
|
|
||||||
}
|
|
||||||
|
|
306
util/make/make.c
306
util/make/make.c
|
@ -5,24 +5,38 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#ifdef unix
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <time.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
/* UNIX specific */
|
||||||
|
#if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__)))
|
||||||
|
#ifndef unix
|
||||||
|
#define unix
|
||||||
#endif
|
#endif
|
||||||
#ifdef eon
|
|
||||||
#include <sys/stat.h>
|
|
||||||
#include <sys/err.h>
|
|
||||||
#endif
|
#endif
|
||||||
#ifdef os9
|
|
||||||
#include <time.h>
|
#if defined(__MINGW32__) || defined(__MINGW64__)
|
||||||
#include <os9.h>
|
#ifndef unix
|
||||||
#include <modes.h>
|
#define unix
|
||||||
#include <direct.h>
|
#endif
|
||||||
#include <errno.h>
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef unix
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <utime.h>
|
||||||
#endif
|
#endif
|
||||||
#include "h.h"
|
#include "h.h"
|
||||||
|
|
||||||
|
void docmds(struct name *np);
|
||||||
|
|
||||||
|
#ifndef max
|
||||||
|
#define max(a,b) ((a)>(b)?(a):(b))
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -31,45 +45,16 @@
|
||||||
* async command, used by the debugger (ugg).
|
* async command, used by the debugger (ugg).
|
||||||
* [exec on eon is like a fork+exec on unix]
|
* [exec on eon is like a fork+exec on unix]
|
||||||
*/
|
*/
|
||||||
int
|
static int dosh(char *string, char *shell)
|
||||||
dosh(string, shell)
|
|
||||||
char * string;
|
|
||||||
char * shell;
|
|
||||||
{
|
{
|
||||||
int number;
|
|
||||||
|
|
||||||
#ifdef unix
|
|
||||||
return system(string);
|
return system(string);
|
||||||
#endif
|
|
||||||
#ifdef eon
|
|
||||||
return ((number = execl(shell, shell,"-c", string, 0)) == -1) ?
|
|
||||||
-1: /* couldn't start the shell */
|
|
||||||
wait(number); /* return its exit status */
|
|
||||||
#endif
|
|
||||||
#ifdef os9
|
|
||||||
int status, pid;
|
|
||||||
|
|
||||||
strcat(string, "\n");
|
|
||||||
if ((number = os9fork(shell, strlen(string), string, 0, 0, 0)) == -1)
|
|
||||||
return -1; /* Couldn't start a shell */
|
|
||||||
do
|
|
||||||
{
|
|
||||||
if ((pid = wait(&status)) == -1)
|
|
||||||
return -1; /* child already died!?!? */
|
|
||||||
} while (pid != number);
|
|
||||||
|
|
||||||
return status;
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Do commands to make a target
|
* Do commands to make a target
|
||||||
*/
|
*/
|
||||||
void
|
static void docmds1(struct name *np, struct line *lp)
|
||||||
docmds1(np, lp)
|
|
||||||
struct name * np;
|
|
||||||
struct line * lp;
|
|
||||||
{
|
{
|
||||||
bool ssilent;
|
bool ssilent;
|
||||||
bool signore;
|
bool signore;
|
||||||
|
@ -81,16 +66,9 @@ struct line * lp;
|
||||||
|
|
||||||
|
|
||||||
if (*(shell = getmacro("SHELL")) == '\0')
|
if (*(shell = getmacro("SHELL")) == '\0')
|
||||||
#ifdef eon
|
|
||||||
shell = ":bin/esh";
|
|
||||||
#endif
|
|
||||||
#ifdef unix
|
#ifdef unix
|
||||||
shell = "/bin/sh";
|
shell = "/bin/sh";
|
||||||
#endif
|
#endif
|
||||||
#ifdef os9
|
|
||||||
shell = "shell";
|
|
||||||
#endif
|
|
||||||
|
|
||||||
for (cp = lp->l_cmd; cp; cp = cp->c_next)
|
for (cp = lp->l_cmd; cp; cp = cp->c_next)
|
||||||
{
|
{
|
||||||
strcpy(str1, cp->c_cmd);
|
strcpy(str1, cp->c_cmd);
|
||||||
|
@ -144,7 +122,7 @@ struct line * lp;
|
||||||
{
|
{
|
||||||
putchar('\n');
|
putchar('\n');
|
||||||
if (!(np->n_flag & N_PREC))
|
if (!(np->n_flag & N_PREC))
|
||||||
if (unlink(np->n_name) == 0)
|
if (remove(np->n_name) == 0)
|
||||||
printf("%s: '%s' removed.\n", myname, np->n_name);
|
printf("%s: '%s' removed.\n", myname, np->n_name);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
@ -156,8 +134,7 @@ struct line * lp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
docmds(np)
|
void docmds(struct name *np)
|
||||||
struct name * np;
|
|
||||||
{
|
{
|
||||||
register struct line * lp;
|
register struct line * lp;
|
||||||
|
|
||||||
|
@ -167,189 +144,76 @@ struct name * np;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#ifdef os9
|
|
||||||
/*
|
|
||||||
* Some stuffing around to get the modified time of a file
|
|
||||||
* in an os9 file system
|
|
||||||
*/
|
|
||||||
getmdate(fd, tbp)
|
|
||||||
struct sgtbuf * tbp;
|
|
||||||
{
|
|
||||||
struct registers regs;
|
|
||||||
static struct fildes fdbuf;
|
|
||||||
|
|
||||||
|
|
||||||
regs.rg_a = fd;
|
|
||||||
regs.rg_b = SS_FD;
|
|
||||||
regs.rg_x = &fdbuf;
|
|
||||||
regs.rg_y = sizeof (fdbuf);
|
|
||||||
|
|
||||||
if (_os9(I_GETSTT, ®s) == -1)
|
|
||||||
{
|
|
||||||
errno = regs.rg_b & 0xff;
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
if (tbp)
|
|
||||||
{
|
|
||||||
_strass(tbp, fdbuf.fd_date, sizeof (fdbuf.fd_date));
|
|
||||||
tbp->t_second = 0; /* Files are only acurate to mins */
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Kludge routine to return an aproximation of how many
|
|
||||||
* seconds since 1980. Dates will be in order, but will not
|
|
||||||
* be lineer
|
|
||||||
*/
|
|
||||||
time_t
|
|
||||||
cnvtime(tbp)
|
|
||||||
struct sgtbuf *tbp;
|
|
||||||
{
|
|
||||||
long acc;
|
|
||||||
|
|
||||||
|
|
||||||
acc = tbp->t_year - 80; /* Baseyear is 1980 */
|
|
||||||
acc = acc * 12 + tbp->t_month;
|
|
||||||
acc = acc * 31 + tbp->t_day;
|
|
||||||
acc = acc * 24 + tbp->t_hour;
|
|
||||||
acc = acc * 60 + tbp->t_minute;
|
|
||||||
acc = acc * 60 + tbp->t_second;
|
|
||||||
|
|
||||||
return acc;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Get the current time in the internal format
|
|
||||||
*/
|
|
||||||
time(tp)
|
|
||||||
time_t * tp;
|
|
||||||
{
|
|
||||||
struct sgtbuf tbuf;
|
|
||||||
|
|
||||||
|
|
||||||
if (getime(&tbuf) < 0)
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
if (tp)
|
|
||||||
*tp = cnvtime(&tbuf);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Get the modification time of a file. If the first
|
* Get the modification time of a file. If the first
|
||||||
* doesn't exist, it's modtime is set to 0.
|
* doesn't exist, it's modtime is set to 0.
|
||||||
*/
|
*/
|
||||||
void
|
void modtime(struct name *np)
|
||||||
modtime(np)
|
|
||||||
struct name * np;
|
|
||||||
{
|
{
|
||||||
#ifdef unix
|
|
||||||
struct stat info;
|
struct stat info;
|
||||||
|
|
||||||
|
|
||||||
if (stat(np->n_name, &info) < 0)
|
if (stat(np->n_name, &info) < 0)
|
||||||
{
|
{
|
||||||
if (errno != ENOENT)
|
if (errno != ENOENT)
|
||||||
fatal("Can't open %s; error %d", np->n_name, errno);
|
fatal("Can't open %s", np->n_name);
|
||||||
|
|
||||||
np->n_time = 0L;
|
np->n_time = 0L;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
np->n_time = info.st_mtime;
|
np->n_time = info.st_mtime;
|
||||||
#endif
|
|
||||||
#ifdef eon
|
|
||||||
struct stat info;
|
|
||||||
int fd;
|
|
||||||
|
|
||||||
|
|
||||||
if ((fd = open(np->n_name, 0)) < 0)
|
|
||||||
{
|
|
||||||
if (errno != ER_NOTF)
|
|
||||||
fatal("Can't open %s; error %02x", np->n_name, errno);
|
|
||||||
|
|
||||||
np->n_time = 0L;
|
|
||||||
}
|
|
||||||
else if (getstat(fd, &info) < 0)
|
|
||||||
fatal("Can't getstat %s; error %02x", np->n_name, errno);
|
|
||||||
else
|
|
||||||
np->n_time = info.st_mod;
|
|
||||||
|
|
||||||
close(fd);
|
|
||||||
#endif
|
|
||||||
#ifdef os9
|
|
||||||
struct sgtbuf info;
|
|
||||||
int fd;
|
|
||||||
|
|
||||||
|
|
||||||
if ((fd = open(np->n_name, 0)) < 0)
|
|
||||||
{
|
|
||||||
if (errno != E_PNNF)
|
|
||||||
fatal("Can't open %s; error %02x", np->n_name, errno);
|
|
||||||
|
|
||||||
np->n_time = 0L;
|
|
||||||
}
|
|
||||||
else if (getmdate(fd, &info) < 0)
|
|
||||||
fatal("Can't getstat %s; error %02x", np->n_name, errno);
|
|
||||||
else
|
|
||||||
np->n_time = cnvtime(&info);
|
|
||||||
|
|
||||||
close(fd);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Update the mod time of a file to now.
|
* Update the mod time of a file to now.
|
||||||
*/
|
*/
|
||||||
void
|
void touch(struct name *np)
|
||||||
touch(np)
|
|
||||||
struct name * np;
|
|
||||||
{
|
{
|
||||||
char c;
|
#ifdef unix
|
||||||
int fd;
|
|
||||||
|
|
||||||
|
|
||||||
if (!domake || !silent)
|
if (!domake || !silent)
|
||||||
printf(" touch(%s)\n", np->n_name);
|
printf(" touch(%s)\n", np->n_name);
|
||||||
|
|
||||||
if (domake)
|
if (domake)
|
||||||
{
|
{
|
||||||
#ifdef unix
|
struct utimbuf a;
|
||||||
long a[2];
|
time_t timeval;
|
||||||
long time();
|
|
||||||
|
|
||||||
a[0] = a[1] = time((long *)0);
|
a.actime = a.modtime = time(&timeval);
|
||||||
if (utime(np->n_name, &a[0]) < 0)
|
if (utime(np->n_name, &a) < 0)
|
||||||
printf("%s: '%s' not touched - non-existant\n",
|
printf("%s: '%s' not touched - non-existant\n",
|
||||||
myname, np->n_name);
|
myname, np->n_name);
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
#ifdef eon
|
}
|
||||||
if ((fd = open(np->n_name, 0)) < 0)
|
|
||||||
printf("%s: '%s' not touched - non-existant\n",
|
static void make1(struct name *np, struct line *lp, struct depend *qdp)
|
||||||
myname, np->n_name);
|
{
|
||||||
|
register struct depend * dp;
|
||||||
|
register char *p;
|
||||||
|
|
||||||
|
if (dotouch)
|
||||||
|
touch(np);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
uread(fd, &c, 1, 0);
|
strcpy(str1, "");
|
||||||
uwrite(fd, &c, 1);
|
for (dp = qdp; dp; dp = qdp)
|
||||||
|
{
|
||||||
|
if (strlen(str1))
|
||||||
|
strcat(str1, " ");
|
||||||
|
strcat(str1, dp->d_name->n_name);
|
||||||
|
qdp = dp->d_next;
|
||||||
|
free((char *)dp);
|
||||||
}
|
}
|
||||||
close(fd);
|
setmacro("?", str1, 4);
|
||||||
#endif
|
setmacro("@", np->n_name, 4);
|
||||||
#ifdef os9
|
p = strrchr(np->n_name, '.');
|
||||||
/*
|
if (p) *p = 0;
|
||||||
* Strange that something almost as totally useless
|
setmacro("*", np->n_name, 4);
|
||||||
* as this is easy to do in os9!
|
if (p) *p = '.';
|
||||||
*/
|
if (lp) /* lp set if doing a :: rule */
|
||||||
if ((fd = open(np->n_name, S_IWRITE)) < 0)
|
docmds1(np, lp);
|
||||||
printf("%s: '%s' not touched - non-existant\n",
|
else
|
||||||
myname, np->n_name);
|
docmds(np);
|
||||||
close(fd);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -357,10 +221,7 @@ struct name * np;
|
||||||
/*
|
/*
|
||||||
* Recursive routine to make a target.
|
* Recursive routine to make a target.
|
||||||
*/
|
*/
|
||||||
int
|
int make(struct name *np, int level)
|
||||||
make(np, level)
|
|
||||||
struct name * np;
|
|
||||||
int level;
|
|
||||||
{
|
{
|
||||||
register struct depend * dp;
|
register struct depend * dp;
|
||||||
register struct line * lp;
|
register struct line * lp;
|
||||||
|
@ -401,7 +262,7 @@ int level;
|
||||||
if (s) {
|
if (s) {
|
||||||
sv = malloc((unsigned)(strlen(s)+1));
|
sv = malloc((unsigned)(strlen(s)+1));
|
||||||
if (!sv) {
|
if (!sv) {
|
||||||
fatal("no space for saved $<");
|
fatal("no space for saved $<",NULL);
|
||||||
}
|
}
|
||||||
strcpy(sv, s);
|
strcpy(sv, s);
|
||||||
}
|
}
|
||||||
|
@ -445,38 +306,3 @@ int level;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
make1(np, lp, qdp)
|
|
||||||
register struct depend * qdp;
|
|
||||||
struct line * lp;
|
|
||||||
struct name * np;
|
|
||||||
{
|
|
||||||
register struct depend * dp;
|
|
||||||
register char *p;
|
|
||||||
char *rindex();
|
|
||||||
|
|
||||||
|
|
||||||
if (dotouch)
|
|
||||||
touch(np);
|
|
||||||
else
|
|
||||||
{
|
|
||||||
strcpy(str1, "");
|
|
||||||
for (dp = qdp; dp; dp = qdp)
|
|
||||||
{
|
|
||||||
if (strlen(str1))
|
|
||||||
strcat(str1, " ");
|
|
||||||
strcat(str1, dp->d_name->n_name);
|
|
||||||
qdp = dp->d_next;
|
|
||||||
free((char *)dp);
|
|
||||||
}
|
|
||||||
setmacro("?", str1, 4);
|
|
||||||
setmacro("@", np->n_name, 4);
|
|
||||||
p = rindex(np->n_name, '.');
|
|
||||||
if (p) *p = 0;
|
|
||||||
setmacro("*", np->n_name, 4);
|
|
||||||
if (p) *p = '.';
|
|
||||||
if (lp) /* lp set if doing a :: rule */
|
|
||||||
docmds1(np, lp);
|
|
||||||
else
|
|
||||||
docmds(np);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -5,6 +5,8 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include "h.h"
|
#include "h.h"
|
||||||
|
@ -17,12 +19,17 @@ int lineno;
|
||||||
* Syntax error handler. Print message, with line number, and exits.
|
* Syntax error handler. Print message, with line number, and exits.
|
||||||
*/
|
*/
|
||||||
/*VARARGS1*/
|
/*VARARGS1*/
|
||||||
void
|
void error(char *msg, char* a1)
|
||||||
error(msg, a1, a2, a3)
|
|
||||||
char * msg;
|
|
||||||
{
|
{
|
||||||
fprintf(stderr, "%s: ", myname);
|
fprintf(stderr, "%s: ", myname);
|
||||||
fprintf(stderr, msg, a1, a2, a3);
|
if (a1 != NULL)
|
||||||
|
{
|
||||||
|
fprintf(stderr, msg, a1);
|
||||||
|
} else
|
||||||
|
{
|
||||||
|
fprintf(stderr, "%s",msg);
|
||||||
|
}
|
||||||
|
|
||||||
if (lineno)
|
if (lineno)
|
||||||
fprintf(stderr, " near line %d", lineno);
|
fprintf(stderr, " near line %d", lineno);
|
||||||
fputc('\n', stderr);
|
fputc('\n', stderr);
|
||||||
|
@ -35,10 +42,7 @@ char * msg;
|
||||||
* comments, ignore blank lines. Deal with quoted (\) #, and
|
* comments, ignore blank lines. Deal with quoted (\) #, and
|
||||||
* quoted newlines. If EOF return TRUE.
|
* quoted newlines. If EOF return TRUE.
|
||||||
*/
|
*/
|
||||||
bool
|
bool mgetline(char* str, FILE* fd)
|
||||||
getline(str, fd)
|
|
||||||
char * str;
|
|
||||||
FILE * fd;
|
|
||||||
{
|
{
|
||||||
register char * p;
|
register char * p;
|
||||||
char * q;
|
char * q;
|
||||||
|
@ -52,8 +56,8 @@ FILE * fd;
|
||||||
|
|
||||||
lineno++;
|
lineno++;
|
||||||
|
|
||||||
if ((p = index(str+pos, '\n')) == (char *)0)
|
if ((p = strchr(str+pos, '\n')) == (char *)0)
|
||||||
error("Line too long");
|
error("Line too long", NULL);
|
||||||
|
|
||||||
if (p[-1] == '\\')
|
if (p[-1] == '\\')
|
||||||
{
|
{
|
||||||
|
@ -63,14 +67,14 @@ FILE * fd;
|
||||||
}
|
}
|
||||||
|
|
||||||
p = str;
|
p = str;
|
||||||
while (((q = index(p, '#')) != (char *)0) &&
|
while (((q = strchr(p, '#')) != (char *)0) &&
|
||||||
(p != q) && (q[-1] == '\\'))
|
(p != q) && (q[-1] == '\\'))
|
||||||
{
|
{
|
||||||
char *a;
|
char *a;
|
||||||
|
|
||||||
a = q - 1; /* Del \ chr; move rest back */
|
a = q - 1; /* Del \ chr; move rest back */
|
||||||
p = q;
|
p = q;
|
||||||
while (*a++ = *q++)
|
while ((*a++ = *q++))
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
if (q != (char *)0)
|
if (q != (char *)0)
|
||||||
|
@ -95,9 +99,7 @@ FILE * fd;
|
||||||
* return a pointer to it. String returned has no white spaces
|
* return a pointer to it. String returned has no white spaces
|
||||||
* in it.
|
* in it.
|
||||||
*/
|
*/
|
||||||
char *
|
char *gettok(char **ptr)
|
||||||
gettok(ptr)
|
|
||||||
char **ptr;
|
|
||||||
{
|
{
|
||||||
register char * p;
|
register char * p;
|
||||||
|
|
||||||
|
|
|
@ -4,18 +4,17 @@
|
||||||
* $Header$
|
* $Header$
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
#include <stdio.h>
|
||||||
#include "h.h"
|
#include "h.h"
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Return a pointer to the suffix of a name
|
* Return a pointer to the suffix of a name
|
||||||
*/
|
*/
|
||||||
char *
|
char *suffix(char *name)
|
||||||
suffix(name)
|
|
||||||
char * name;
|
|
||||||
{
|
{
|
||||||
return rindex(name, '.');
|
return strrchr(name, '.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -26,9 +25,7 @@ char * name;
|
||||||
* source name, and rules. Returns TRUE if np was made into
|
* source name, and rules. Returns TRUE if np was made into
|
||||||
* a target.
|
* a target.
|
||||||
*/
|
*/
|
||||||
bool
|
bool dyndep(struct name *np)
|
||||||
dyndep(np)
|
|
||||||
struct name * np;
|
|
||||||
{
|
{
|
||||||
register char * p;
|
register char * p;
|
||||||
register char * q;
|
register char * q;
|
||||||
|
@ -58,14 +55,14 @@ struct name * np;
|
||||||
{
|
{
|
||||||
newsuff = dp->d_name->n_name;
|
newsuff = dp->d_name->n_name;
|
||||||
if (strlen(suff)+strlen(newsuff)+1 >= LZ)
|
if (strlen(suff)+strlen(newsuff)+1 >= LZ)
|
||||||
fatal("Suffix rule too long");
|
fatal("Suffix rule too long",NULL);
|
||||||
p = str1;
|
p = str1;
|
||||||
q = newsuff;
|
q = newsuff;
|
||||||
while (*p++ = *q++)
|
while ((*p++ = *q++))
|
||||||
;
|
;
|
||||||
p--;
|
p--;
|
||||||
q = suff;
|
q = suff;
|
||||||
while (*p++ = *q++)
|
while ((*p++ = *q++))
|
||||||
;
|
;
|
||||||
sp = newname(str1);
|
sp = newname(str1);
|
||||||
if (sp->n_flag & N_TARG)
|
if (sp->n_flag & N_TARG)
|
||||||
|
@ -73,12 +70,12 @@ struct name * np;
|
||||||
p = str1;
|
p = str1;
|
||||||
q = basename;
|
q = basename;
|
||||||
if (strlen(basename) + strlen(newsuff)+1 >= LZ)
|
if (strlen(basename) + strlen(newsuff)+1 >= LZ)
|
||||||
fatal("Implicit name too long");
|
fatal("Implicit name too long",NULL);
|
||||||
while (*p++ = *q++)
|
while ((*p++ = *q++))
|
||||||
;
|
;
|
||||||
p--;
|
p--;
|
||||||
q = newsuff;
|
q = newsuff;
|
||||||
while (*p++ = *q++)
|
while ((*p++ = *q++))
|
||||||
;
|
;
|
||||||
op = newname(str1);
|
op = newname(str1);
|
||||||
if (!op->n_time)
|
if (!op->n_time)
|
||||||
|
@ -99,8 +96,7 @@ struct name * np;
|
||||||
/*
|
/*
|
||||||
* Make the default rules
|
* Make the default rules
|
||||||
*/
|
*/
|
||||||
void
|
void makerules(void)
|
||||||
makerules()
|
|
||||||
{
|
{
|
||||||
struct cmd * cp;
|
struct cmd * cp;
|
||||||
struct name * np;
|
struct name * np;
|
||||||
|
@ -158,7 +154,7 @@ makerules()
|
||||||
#else
|
#else
|
||||||
cp = newcmd("$(CC) $(CFLAGS) -c $<", (struct cmd *)0);
|
cp = newcmd("$(CC) $(CFLAGS) -c $<", (struct cmd *)0);
|
||||||
np = newname(".c.o");
|
np = newname(".c.o");
|
||||||
#endif MINIX
|
#endif /* MINIX */
|
||||||
newline(np, (struct depend *)0, cp, 0);
|
newline(np, (struct depend *)0, cp, 0);
|
||||||
|
|
||||||
setmacro("AS", "as", 0);
|
setmacro("AS", "as", 0);
|
||||||
|
|
Loading…
Reference in a new issue