Incorporate bsdmake into buildsystem and reorganize libs

This commit is contained in:
Arun Thomas 2010-02-16 14:41:33 +00:00
parent 6686e9ae9f
commit b706112487
1513 changed files with 8094 additions and 26613 deletions

View file

@ -1,6 +1,6 @@
# Master Makefile to compile everything in /usr/src except the system. # Master Makefile to compile everything in /usr/src except the system.
MAKE = exec make -$(MAKEFLAGS) MAKE=make
usage: usage:
@echo "" @echo ""
@ -11,7 +11,7 @@ usage:
@echo " make world # Compile everything (libraries & commands)" @echo " make world # Compile everything (libraries & commands)"
@echo " make includes # Install include files from src/" @echo " make includes # Install include files from src/"
@echo " make libraries # Compile and install libraries" @echo " make libraries # Compile and install libraries"
@echo " make cmds # Compile all, commands, but don't install" @echo " make commands # Compile all, commands, but don't install"
@echo " make install # Compile and install commands" @echo " make install # Compile and install commands"
@echo " make depend # Generate required .depend files" @echo " make depend # Generate required .depend files"
@echo " make clean # Remove all compiler results" @echo " make clean # Remove all compiler results"
@ -27,19 +27,19 @@ usage:
# 'make install' target. # 'make install' target.
# #
# etcfiles has to be done first. # etcfiles has to be done first.
world: includes depend libraries cmds install postinstall world: includes depend libraries install postinstall
includes: includes:
cd include && $(MAKE) install gcc cd include && $(MAKE) install gcc
libraries: libraries:
cd lib && $(MAKE) all install cd lib && sh ack_build.sh obj depend all install
cmds: gnu-libraries:
if [ -f commands/Makefile ] ; then cd commands && $(MAKE) all; fi cd lib && sh gnu_build.sh obj depend all install
install:: commands:
if [ -f commands/Makefile ] ; then cd commands && $(MAKE) install; fi cd commands && $(MAKE) all
depend:: depend::
mkdep kernel mkdep kernel
@ -49,23 +49,33 @@ depend::
cd servers && $(MAKE) $@ cd servers && $(MAKE) $@
cd drivers && $(MAKE) $@ cd drivers && $(MAKE) $@
clean::
cd lib && $(MAKE) $@
test ! -f commands/Makefile || { cd commands && $(MAKE) $@; }
etcfiles:: etcfiles::
cd etc && $(MAKE) install cd etc && $(MAKE) install
clean:: all::
cd test && $(MAKE) $@ cd boot && $(MAKE) all
cd man && $(MAKE) all
cd commands && $(MAKE) all
cd tools && $(MAKE) all
cd servers && $(MAKE) all
all install clean:: install::
cd boot && $(MAKE) $@ cd boot && $(MAKE) all install
cd man && $(MAKE) $@ # First manpages, then commands cd man && $(MAKE) all install
test ! -f commands/Makefile || { cd commands && $(MAKE) $@; } cd commands && $(MAKE) all install
cd tools && $(MAKE) $@ cd tools && $(MAKE) all install
cd servers && $(MAKE) $@ cd servers && $(MAKE) all install
clean::
cd boot && $(MAKE) clean
cd man && $(MAKE) clean
cd commands && $(MAKE) clean
cd tools && $(MAKE) clean
cd servers && $(MAKE) clean
cd lib && sh ack_build.sh clean
cd lib && sh gnu_build.sh clean
cd commands && $(MAKE) clean
cd test && $(MAKE) clean
postinstall: postinstall:
cd etc && $(MAKE) $@ cd etc && $(MAKE) $@

View file

@ -55,16 +55,16 @@ sh: $(OBJS)
install: /usr/bin/ash /usr/bin/sh /bin/sh /bin/bigsh install: /usr/bin/ash /usr/bin/sh /bin/sh /bin/bigsh
/usr/bin/ash: sh /usr/bin/ash: sh
install -cs -o bin $< $@ install -cs -o bin $> $@
/usr/bin/sh: /usr/bin/ash /usr/bin/sh: /usr/bin/ash
install -l $< $@ install -l $> $@
/bin/sh: /usr/bin/ash /bin/sh: /usr/bin/ash
install -lcs $< $@ install -lcs $> $@
/bin/bigsh: /usr/bin/ash /bin/bigsh: /usr/bin/ash
install -S 6600k -lcs $< $@ install -S 6600k -lcs $> $@
clean: clean:
rm -f $(CLEANFILES) sh core rm -f $(CLEANFILES) sh core
@ -111,6 +111,9 @@ mksyntax: mksyntax.c parser.h
bltin/operators.h: bltin/mkexpr bltin/unary_op bltin/binary_op bltin/operators.h: bltin/mkexpr bltin/unary_op bltin/binary_op
cd bltin && sh mkexpr unary_op binary_op cd bltin && sh mkexpr unary_op binary_op
bltin/operators.c: bltin/mkexpr bltin/unary_op bltin/binary_op
cd bltin && sh mkexpr unary_op binary_op
# Dependencies you say? This will have to do. # Dependencies you say? This will have to do.
$(OBJS): error.h eval.h exec.h expand.h init.h input.h \ $(OBJS): error.h eval.h exec.h expand.h init.h input.h \
jobs.h machdep.h mail.h main.h memalloc.h mystring.h options.h \ jobs.h machdep.h mail.h main.h memalloc.h mystring.h options.h \

View file

@ -1,6 +0,0 @@
#!/bin/sh
export PATH=$PATH:/usr/gnu/bin
make -f Makefile.boot clean
make -f Makefile.boot CFLAGS="-g -Wall -DHAVE_SETENV -DHAVE_STRERROR -DHAVE_STRDUP -DHAVE_STRFTIME -DHAVE_VSNPRINTF -D_GNU_SOURCE -DUSE_SELECT -DSYSV -D_POSIX_SOURCE"
#make -f Makefile.boot

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -74,18 +74,6 @@ if $PROGRAM = cc
RTSO = -.c RTSO = -.c
LIBS = $LIBS + -.c LIBS = $LIBS + -.c
arg -.mod
if $PROGRAM = m2
ifndef RTSO
RTSO = -.mod
LIBS = $LIBS + -.mod
arg -.p
if $PROGRAM = pc
ifndef RTSO
RTSO = -.p
LIBS = $LIBS + -.p
# Omit the runtime startoff, but keep the libraries. # Omit the runtime startoff, but keep the libraries.
arg -.o arg -.o
RTSO = RTSO =
@ -315,24 +303,6 @@ transform .i .k
RTSO = -.c RTSO = -.c
LIBS = $LIBS + -.c LIBS = $LIBS + -.c
# Compile Modula-2 source to EM-code.
transform .mod .k
ifhash $*
apply .c .i
$ACK_M2 $* $>
ifndef RTSO
RTSO = -.mod
LIBS = $LIBS + -.mod
# Compile Pascal source to EM-code.
transform .p .k
ifhash $*
apply .c .i
$ACK_PC $* $>
ifndef RTSO
RTSO = -.p
LIBS = $LIBS + -.p
# Compact EM to readable EM. # Compact EM to readable EM.
transform .k .e transform .k .e
transform .m .e transform .m .e
@ -393,23 +363,13 @@ combine (.o .a) .out
rtso = rtso =
if $RTSO = -.c if $RTSO = -.c
rtso = $A/$ARCH/crtso.o rtso = $A/$ARCH/crtso.o
if $RTSO = -.mod libd = ; libc = ; libfp =
rtso = $A/$ARCH/m2rtso.o
if $RTSO = -.p
rtso = $A/$ARCH/prtso.o
libm2 = ; libp = ; libd = ; libc = ; libfp =
if (-.mod - $LIBS) = ()
libm2 = $A/$ARCH/libm2.a
libc = $A/$ARCH/libc.a
if (-.p - $LIBS) = ()
libp = $A/$ARCH/libp.a
libc = $A/$ARCH/libc.a
if (-.c - $LIBS) = () if (-.c - $LIBS) = ()
libd = $A/$ARCH/libd.a libd = $A/$ARCH/libd.a
libc = $A/$ARCH/libc.a libc = $A/$ARCH/libc.a
if (-fsoft - $LIBS) = () if (-fsoft - $LIBS) = ()
libfp = $A/$ARCH/libfp.a libfp = $A/$ARCH/libfp.a
libs = $libm2 $libp $libd $libc $libfp $A/$ARCH/libe.a libs = $libd $libc $libfp $A/$ARCH/libe.a
ifndef OUT ifndef OUT
OUT = a.out OUT = a.out
if (-r - $MODEL) = () if (-r - $MODEL) = ()
@ -418,7 +378,7 @@ combine (.o .a) .out
else else
# Combine to an executable. # Combine to an executable.
mktemp EXE mktemp EXE
$ACK_LED $model -o $EXE $rtso $* $libs $A/$ARCH/end.a $ACK_LED $model -o $EXE $rtso $* $libs $A/$ARCH/libend.a
$ACK_CV -x -m$ARCH $EXE $OUT $ACK_CV -x -m$ARCH $EXE $OUT
# Add object files to a library. # Add object files to a library.

View file

@ -11,13 +11,10 @@ cc: cc.c
$(CCLD) -o $@ $? $(CCLD) -o $@ $?
install -S 6kb $@ install -S 6kb $@
install: /usr/bin/cc /usr/bin/m2 /usr/bin/pc install: /usr/bin/cc
/usr/bin/cc: cc /usr/bin/cc: cc
install -cs -o bin $? $@ install -cs -o bin $? $@
/usr/bin/m2 /usr/bin/pc: /usr/bin/cc
install -l $? $@
clean: clean:
rm -rf a.out core cc rm -rf a.out core cc

View file

@ -1,22 +1,54 @@
# Makefile for make (!) # $NetBSD: Makefile.boot,v 1.19 2009/01/24 11:59:39 dsl Exp $
#
# a very simple makefile...
#
# You only want to use this if you aren't running NetBSD.
#
# modify MACHINE and MACHINE_ARCH as appropriate for your target architecture
#
#CC=gcc -O -g
CC=cc
CFLAGS=-g -Wall -DHAVE_SETENV -DHAVE_STRERROR -DHAVE_STRDUP -DHAVE_STRFTIME -DHAVE_VSNPRINTF -DUSE_SELECT -D_POSIX_SOURCE -D_MINIX
CFLAGS = -O -Dunix -D_MINIX -D_POSIX_SOURCE .c.o:
CC = exec cc ${CC} ${CFLAGS} -c $< -o $@
OBJ = check.o input.o macro.o main.o make.o reader.o rules.o archive.o MACHINE=i386
MACHINE_ARCH=i386
# tested on HP-UX 10.20
#MAKE_MACHINE=hp700
#MAKE_MACHINE_ARCH=hppa
CFLAGS+= -DTARGET_MACHINE=\"${MACHINE}\" \
-DTARGET_MACHINE_ARCH=\"${MACHINE_ARCH}\" \
-DMAKE_MACHINE=\"${MACHINE}\"
LIBS=
OBJ=arch.o buf.o compat.o cond.o dir.o for.o hash.o job.o main.o make.o \
make_malloc.o parse.o str.o strlist.o suff.o targ.o trace.o var.o util.o
LIBOBJ= lst.lib/lstAppend.o lst.lib/lstAtEnd.o lst.lib/lstAtFront.o \
lst.lib/lstClose.o lst.lib/lstConcat.o lst.lib/lstDatum.o \
lst.lib/lstDeQueue.o lst.lib/lstDestroy.o lst.lib/lstDupl.o \
lst.lib/lstEnQueue.o lst.lib/lstFind.o lst.lib/lstFindFrom.o \
lst.lib/lstFirst.o lst.lib/lstForEach.o lst.lib/lstForEachFrom.o \
lst.lib/lstInit.o lst.lib/lstInsert.o lst.lib/lstIsAtEnd.o \
lst.lib/lstIsEmpty.o lst.lib/lstLast.o lst.lib/lstMember.o \
lst.lib/lstNext.o lst.lib/lstOpen.o lst.lib/lstRemove.o \
lst.lib/lstReplace.o lst.lib/lstSucc.o lst.lib/lstPrev.o
all: make all: make
make : $(OBJ) make: ${OBJ} ${LIBOBJ}
$(CC) -i -o make $(OBJ) # @echo 'make of make and make.0 started.'
install -S 330k make ${CC} ${CFLAGS} ${OBJ} ${LIBOBJ} -o make ${LIBS}
@ls -l $@
# nroff -h -man make.1 > make.0
# @echo 'make of make and make.0 completed.'
install: /usr/bin/make install: /usr/bin/make
/usr/bin/make: make /usr/bin/make: make
install -c -o bin make $@ install -c -o bin make $@
$(OBJ): h.h
clean: clean:
rm -f *.o *.bak core make rm -f ${OBJ} ${LIBOBJ} ${PORTOBJ} make

View file

@ -1,309 +0,0 @@
/* archive.c - archive support Author: Kees J. Bot
* 13 Nov 1993
*/
#include "h.h"
#ifdef unix
#include <unistd.h>
#include <fcntl.h>
#define arraysize(a) (sizeof(a) / sizeof((a)[0]))
#define arraylimit(a) ((a) + arraysize(a))
/* ASCII ar header. */
#define ASCII_ARMAG "!<arch>\n"
#define ASCII_SARMAG 8
#define ASCII_ARFMAG "`\n"
struct ascii_ar_hdr {
char ar_name[16];
char ar_date[12];
char ar_uid[6];
char ar_gid[6];
char ar_mode[8];
char ar_size[10];
char ar_fmag[2];
};
/* ACK ar header. */
#define ACK_ARMAG 0177545
#define ACK_AALMAG 0177454
struct ack_ar_hdr {
char ar_name[14];
unsigned long ar_date;
unsigned char ar_uid;
unsigned char ar_gid;
unsigned short ar_mode;
unsigned long ar_size;
};
typedef struct archname {
struct archname *next; /* Next on the hash chain. */
char name[16]; /* One archive entry. */
time_t date; /* The timestamp. */
/* (no need for other attibutes) */
} archname_t;
static size_t namelen; /* Max name length, 14 or 16. */
#define HASHSIZE (64 << sizeof(int))
static archname_t *nametab[HASHSIZE];
_PROTOTYPE( static int hash, (char *name) );
_PROTOTYPE( static int searchtab, (char *name, time_t *date, int scan) );
_PROTOTYPE( static void deltab, (void) );
_PROTOTYPE( static long ar_atol, (char *s, size_t n) );
_PROTOTYPE( static int read_ascii_archive, (int afd) );
_PROTOTYPE( static int read_ack_archive, (int afd) );
static char *lpar, *rpar; /* Leave these at '(' and ')'. */
int is_archive_ref(name) char *name;
/* True if name is of the form "archive(file)". */
{
char *p = name;
while (*p != 0 && *p != '(' && *p != ')') p++;
lpar = p;
if (*p++ != '(') return 0;
while (*p != 0 && *p != '(' && *p != ')') p++;
rpar = p;
if (*p++ != ')') return 0;
return *p == 0;
}
static int hash(name) char *name;
/* Compute a hash value out of a name. */
{
unsigned h = 0;
unsigned char *p = (unsigned char *) name;
int n = namelen;
while (*p != 0) {
h = h * 0x1111 + *p++;
if (--n == 0) break;
}
return h % arraysize(nametab);
}
static int searchtab(name, date, scan) char *name; time_t *date; int scan;
/* Enter a name to the table, or return the date of one already there. */
{
archname_t **pnp, *np;
int cmp = 1;
pnp = &nametab[hash(name)];
while ((np = *pnp) != NULL
&& (cmp = strncmp(name, np->name, namelen)) > 0) {
pnp= &np->next;
}
if (cmp != 0) {
if (scan) {
errno = ENOENT;
return -1;
}
if ((np = (archname_t *) malloc(sizeof(*np))) == NULL)
fatal("No memory for archive name cache",(char *)0,0);
strncpy(np->name, name, namelen);
np->date = *date;
np->next = *pnp;
*pnp = np;
}
if (scan) *date = np->date;
return 0;
}
static void deltab()
/* Delete the name cache, a different library is to be read. */
{
archname_t **pnp, *np, *junk;
for (pnp = nametab; pnp < arraylimit(nametab); pnp++) {
for (np = *pnp; np != NULL; ) {
junk = np;
np = np->next;
free(junk);
}
*pnp = NULL;
}
}
static long ar_atol(s, n) char *s; size_t n;
/* Transform a string into a number. Ignore the space padding. */
{
long l= 0;
while (n > 0) {
if (*s != ' ') l= l * 10 + (*s - '0');
s++;
n--;
}
return l;
}
static int read_ascii_archive(afd)
int afd;
/* Read a modern ASCII type archive. */
{
struct ascii_ar_hdr hdr;
off_t pos= 8;
char *p;
time_t date;
namelen = 16;
for (;;) {
if (lseek(afd, pos, SEEK_SET) == -1) return -1;
switch (read(afd, &hdr, sizeof(hdr))) {
case sizeof(hdr):
break;
case -1:
return -1;
default:
return 0;
}
if (strncmp(hdr.ar_fmag, ASCII_ARFMAG, sizeof(hdr.ar_fmag)) != 0) {
errno= EINVAL;
return -1;
}
/* Strings are space padded! */
for (p= hdr.ar_name; p < hdr.ar_name + sizeof(hdr.ar_name); p++) {
if (*p == ' ') {
*p= 0;
break;
}
}
/* Add a file to the cache. */
date = ar_atol(hdr.ar_date, sizeof(hdr.ar_date));
searchtab(hdr.ar_name, &date, 0);
pos+= sizeof(hdr) + ar_atol(hdr.ar_size, sizeof(hdr.ar_size));
pos= (pos + 1) & (~ (off_t) 1);
}
}
static int read_ack_archive(afd)
int afd;
/* Read an ACK type archive. */
{
unsigned char raw_hdr[14 + 4 + 1 + 1 + 2 + 4];
struct ack_ar_hdr hdr;
off_t pos= 2;
time_t date;
namelen = 14;
for (;;) {
if (lseek(afd, pos, SEEK_SET) == -1) return -1;
switch (read(afd, raw_hdr, sizeof(raw_hdr))) {
case sizeof(raw_hdr):
break;
case -1:
return -1;
default:
return 0;
}
/* Copy the useful fields from the raw bytes transforming PDP-11
* style numbers to native format.
*/
memcpy(hdr.ar_name, raw_hdr + 0, 14);
hdr.ar_date= (long) raw_hdr[14 + 1] << 24
| (long) raw_hdr[14 + 0] << 16
| (long) raw_hdr[14 + 3] << 8
| (long) raw_hdr[14 + 2] << 0;
hdr.ar_size= (long) raw_hdr[22 + 1] << 24
| (long) raw_hdr[22 + 0] << 16
| (long) raw_hdr[22 + 3] << 8
| (long) raw_hdr[22 + 2] << 0;
/* Add a file to the cache. */
date = hdr.ar_date;
searchtab(hdr.ar_name, &date, 0);
pos= (pos + 26 + hdr.ar_size + 1) & (~ (off_t) 1);
}
}
int archive_stat(name, stp) char *name; struct stat *stp;
/* Search an archive for a file and return that file's stat info. */
{
int afd;
int r= -1;
char magic[8];
char *file;
static dev_t ardev;
static ino_t arino = 0;
static time_t armtime;
if (!is_archive_ref(name)) { errno = EINVAL; return -1; }
*lpar= 0;
*rpar= 0;
file= lpar + 1;
if (stat(name, stp) < 0) goto bail_out;
if (stp->st_ino != arino || stp->st_dev != ardev) {
/* Either the first (and probably only) library, or a different
* library.
*/
arino = stp->st_ino;
ardev = stp->st_dev;
armtime = stp->st_mtime;
deltab();
if ((afd= open(name, O_RDONLY)) < 0) goto bail_out;
switch (read(afd, magic, sizeof(magic))) {
case 8:
if (strncmp(magic, ASCII_ARMAG, 8) == 0) {
r= read_ascii_archive(afd);
break;
}
if ((magic[0] & 0xFF) == ((ACK_AALMAG >> 0) & 0xFF)
&& (magic[1] & 0xFF) == ((ACK_AALMAG >> 8) & 0xFF)
) {
r= read_ack_archive(afd);
break;
}
/*FALL THROUGH*/
default:
errno = EINVAL;
/*FALL THROUGH*/
case -1:
/* r= -1 */;
}
{ int e= errno; close(afd); errno= e; }
} else {
/* Library is cached. */
r = 0;
}
if (r == 0) {
/* Search the cache. */
r = searchtab(file, &stp->st_mtime, 1);
if (stp->st_mtime > armtime) stp->st_mtime = armtime;
}
bail_out:
/* Repair the name(file) thing. */
*lpar= '(';
*rpar= ')';
return r;
}
#endif

View file

@ -1,3 +0,0 @@
#!/bin/sh
make clean
make && make install

View file

@ -1,128 +0,0 @@
/*************************************************************************
*
* m a k e : c h e c k . c
*
* debugging stuff: Check structures for make.
*========================================================================
* Edition history
*
* # Date Comments By
* --- -------- ---------------------------------------------------- ---
* 1 ?? ??
* 2 23.08.89 adapted to new name tree structure RAL
* 3 30.08.89 indention changed PSH,RAL
* 4 06.09.89 prt output redirected to stdout RAL
* ------------ Version 2.0 released ------------------------------- RAL
*
*************************************************************************/
#include "h.h"
/*
* Prints out the structures as defined in memory. Good for check
* that you make file does what you want (and for debugging make).
*/
void prt()
{
register struct name *np;
register struct depend *dp;
register struct line *lp;
register struct cmd *cp;
register struct macro *mp;
register int i;
for (mp = macrohead; mp; mp = mp->m_next)
printf("%s = %s\n", mp->m_name, mp->m_val);
putchar('\n');
for (i = 0; i <= maxsuffarray ; i++)
for (np = suffparray[i]->n_next; np; np = np->n_next)
{
if (np->n_flag & N_DOUBLE)
printf("%s::\n", np->n_name);
else
printf("%s:\n", np->n_name);
if (np == firstname)
printf("(MAIN NAME)\n");
for (lp = np->n_line; lp; lp = lp->l_next)
{
putchar(':');
for (dp = lp->l_dep; dp; dp = dp->d_next)
printf(" %s", dp->d_name->n_name);
putchar('\n');
for (cp = lp->l_cmd; cp; cp = cp->c_next)
#ifdef os9
printf("- %s\n", cp->c_cmd);
#else
printf("-\t%s\n", cp->c_cmd);
#endif
putchar('\n');
}
putchar('\n');
}
}
/*
* 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,0);
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.
* ie.
* a: b
* b: a
* is a circular dep
*/
void circh()
{
register struct name *np;
register int i;
for (i = 0; i <= maxsuffarray ; i++)
for (np = suffparray[i]->n_next; np; np = np->n_next)
check(np);
}
/*
* Check the target .PRECIOUS, and mark its dependentd as precious
*/
void precious()
{
register struct depend *dp;
register struct line *lp;
register struct name *np;
if (!((np = newname(".PRECIOUS"))->n_flag & N_TARG))
return;
for (lp = np->n_line; lp; lp = lp->l_next)
for (dp = lp->l_dep; dp; dp = dp->d_next)
dp->d_name->n_flag |= N_PREC;
}

View file

@ -1,320 +0,0 @@
/*************************************************************************
*
* m a k e : h . h
*
* include file for make
*========================================================================
* Edition history
*
* # Date Comments By
* --- -------- ---------------------------------------------------- ---
* 1 ?? ??
* 2 23.08.89 LZ increased,N_EXISTS added,suffix as macro added RAL
* 3 30.08.89 macro flags added, indention changed PSH,RAL
* 4 03.09.89 fixed LZ eliminated, struct str added,... RAL
* 5 06.09.89 TABCHAR,M_MAKE added RAL
* 6 09.09.89 tos support added, EXTERN,INIT,PARMS added PHH,RAL
* 7 17.09.89 __STDC__ added, make1 decl. fixed , N_EXEC added RAL
* ------------ Version 2.0 released ------------------------------- RAL
*
*************************************************************************/
#ifdef unix
#include <sys/types.h>
#include <sys/stat.h>
#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <utime.h>
#include <stdio.h>
#include <limits.h>
#endif
#ifdef eon
#include <sys/stat.h>
#include <sys/err.h>
#endif
#ifdef os9
#include <time.h>
#include <os9.h>
#include <modes.h>
#include <direct.h>
#include <errno.h>
#endif
#ifdef tos
struct DOSTIME {short time,date; }; /* time structure of TOS */
#ifdef LATTICE
#include <error.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <osbind.h>
#endif /* LATTICE */
#ifdef TURBO
#include <tos.h>
#include <errno.h>
#include <string.h>
#endif /* TURBO */
#endif /* tos */
#include <ctype.h>
#include <stdio.h>
#include <assert.h>
#ifdef eon
#define MNOENT ER_NOTF
#else
#define MNOENT ENOENT
#endif
#ifndef uchar
#ifdef os9
#define uchar char
#define void int
#define fputc putc
#else
#define uchar unsigned char
#endif
#endif
#define bool uchar
#ifndef time_t
#define time_t long
#endif
#define TRUE (1)
#define FALSE (0)
#define max(a,b) ((a)>(b)?(a):(b))
#ifdef unix
#define DEFN1 "makefile"
#define DEFN2 "Makefile"
#endif
#ifdef eon
#define DEFN1 "makefile"
#define DEFN2 "Makefile"
#endif
#ifdef tos
#define DEFN1 "makefile."
#define DEFN2 (char *)0
#endif
#ifdef os9
#define DEFN1 "makefile"
#define DEFN2 (char *)0
#endif
#ifdef os9
#define TABCHAR ' '
#else
#define TABCHAR '\t'
#endif
#define LZ1 (2048) /* Initial input/expand string size */
#define LZ2 (256) /* Initial input/expand string size */
/*
* A name. This represents a file, either to be made, or existant
*/
struct name
{
struct name *n_next; /* Next in the list of names */
char *n_name; /* Called */
struct line *n_line; /* Dependencies */
time_t n_time; /* Modify time of this name */
uchar n_flag; /* Info about the name */
};
#define N_MARK 0x01 /* For cycle check */
#define N_DONE 0x02 /* Name looked at */
#define N_TARG 0x04 /* Name is a target */
#define N_PREC 0x08 /* Target is precious */
#define N_DOUBLE 0x10 /* Double colon target */
#define N_EXISTS 0x20 /* File exists */
#define N_ERROR 0x40 /* Error occured */
#define N_EXEC 0x80 /* Commands executed */
/*
* Definition of a target line.
*/
struct line
{
struct line *l_next; /* Next line (for ::) */
struct depend *l_dep; /* Dependents for this line */
struct cmd *l_cmd; /* Commands for this line */
};
/*
* List of dependents for a line
*/
struct depend
{
struct depend *d_next; /* Next dependent */
struct name *d_name; /* Name of dependent */
};
/*
* Commands for a line
*/
struct cmd
{
struct cmd *c_next; /* Next command line */
char *c_cmd; /* Command line */
};
/*
* Macro storage
*/
struct macro
{
struct macro *m_next; /* Next variable */
char *m_name; /* Called ... */
char *m_val; /* Its value */
uchar m_flag; /* Infinite loop check */
};
#define M_MARK 0x01 /* for infinite loop check */
#define M_OVERRIDE 0x02 /* command-line override */
#define M_MAKE 0x04 /* for MAKE macro */
/*
* String
*/
struct str
{
char **ptr; /* ptr to real ptr. to string */
int len; /* length of string */
int pos; /* position */
};
/* Declaration, definition & initialization of variables */
#ifndef EXTERN
#define EXTERN extern
#endif
#ifndef INIT
#define INIT(x)
#endif
extern int errno;
extern char **environ;
EXTERN char *myname;
EXTERN bool domake INIT(TRUE); /* Go through the motions option */
EXTERN bool ignore INIT(FALSE); /* Ignore exit status option */
EXTERN bool conterr INIT(FALSE); /* continue on errors */
EXTERN bool silent INIT(FALSE); /* Silent option */
EXTERN bool print INIT(FALSE); /* Print debuging information */
EXTERN bool rules INIT(TRUE); /* Use inbuilt rules */
EXTERN bool dotouch INIT(FALSE); /* Touch files instead of making */
EXTERN bool quest INIT(FALSE); /* Question up-to-dateness of file */
EXTERN bool useenv INIT(FALSE); /* Env. macro def. overwrite makefile def.*/
EXTERN bool dbginfo INIT(FALSE); /* Print lot of debugging information */
EXTERN bool ambigmac INIT(TRUE); /* guess undef. ambiguous macros (*,<) */
EXTERN struct name *firstname;
EXTERN char *str1;
EXTERN char *str2;
EXTERN struct str str1s;
EXTERN struct str str2s;
EXTERN struct name **suffparray; /* ptr. to array of ptrs. to name chains */
EXTERN int sizesuffarray INIT(20); /* size of suffarray */
EXTERN int maxsuffarray INIT(0); /* last used entry in suffarray */
EXTERN struct macro *macrohead;
EXTERN bool expmake; /* TRUE if $(MAKE) has been expanded */
EXTERN char *makefile; /* The make file */
EXTERN int lineno;
#ifdef tos
#ifdef LATTICE
EXTERN int _mneed INIT(60000); /* VERY important for TOS with LATTICE C*/
#endif /* LATTICE */
#endif /* tos */
#ifdef eon
#define MEMSPACE (16384)
EXTERN unsigned memspace = MEMSPACE;
#endif
#define suffix(name) strrchr(name,(int)'.')
EXTERN int _ctypech;
#define mylower(x) (islower(_ctypech=(x)) ? _ctypech :tolower(_ctypech))
#define myupper(x) (isupper(_ctypech=(x)) ? _ctypech :toupper(_ctypech))
/* Prototypes. */
struct sgtbuf;
/* check.c */
_PROTOTYPE(void prt, (void));
_PROTOTYPE(void check, (struct name *np ));
_PROTOTYPE(void circh, (void));
_PROTOTYPE(void precious, (void));
/* input.c */
_PROTOTYPE(void init, (void));
_PROTOTYPE(void strrealloc, (struct str *strs ));
_PROTOTYPE(struct name *newname, (char *name ));
_PROTOTYPE(struct name *testname, (char *name ));
_PROTOTYPE(struct depend *newdep, (struct name *np, struct depend *dp ));
_PROTOTYPE(struct cmd *newcmd, (char *str, struct cmd *cp ));
_PROTOTYPE(void newline, (struct name *np, struct depend *dp, struct cmd *cp,
int flag ));
_PROTOTYPE(void input, (FILE *fd ));
/* macro.c */
_PROTOTYPE(struct macro *getmp, (char *name ));
_PROTOTYPE(char *getmacro, (char *name ));
_PROTOTYPE(struct macro *setmacro, (char *name, char *val ));
_PROTOTYPE(struct macro *addmacro, (char *name, char *val ));
_PROTOTYPE(void setDFmacro, (char *name, char *val ));
_PROTOTYPE(void doexp, (struct str *to, char *from ));
_PROTOTYPE(void expand, (struct str *strs ));
/* main.c */
_PROTOTYPE(void main, (int argc, char **argv ));
_PROTOTYPE(void setoption, (char option ));
_PROTOTYPE(void usage, (void));
_PROTOTYPE(void fatal, (char *msg, char *a1, int a2 ));
/* make.c */
_PROTOTYPE(int dosh, (char *string, char *shell ));
_PROTOTYPE(int makeold, (char *name ));
_PROTOTYPE(void docmds1, (struct name *np, struct line *lp ));
_PROTOTYPE(void docmds, (struct name *np ));
_PROTOTYPE(int Tosexec, (char *string ));
_PROTOTYPE(time_t mstonix, (unsigned int date, unsigned int time ));
_PROTOTYPE(void getmdate, (int fd, struct sgtbuf *tbp ));
_PROTOTYPE(time_t cnvtime, (struct sgtbuf *tbp ));
_PROTOTYPE(void modtime, (struct name *np ));
_PROTOTYPE(void touch, (struct name *np ));
_PROTOTYPE(int make, (struct name *np, int level ));
_PROTOTYPE(void make1, (struct name *np, struct line *lp, struct depend *qdp,
char *basename, char *inputname ));
_PROTOTYPE(void implmacros, (struct name *np, struct line *lp,
char **pbasename, char **pinputname ));
_PROTOTYPE(void dbgprint, (int level, struct name *np, char *comment ));
/* reader.c */
_PROTOTYPE(void error, (char *msg, char *a1 ));
_PROTOTYPE(bool getline, (struct str *strs, FILE *fd ));
_PROTOTYPE(char *gettok, (char **ptr ));
/* rules.c */
_PROTOTYPE(bool dyndep, (struct name *np, char **pbasename,char **pinputname));
_PROTOTYPE(void makerules, (void));
/* archive.c */
_PROTOTYPE(int is_archive_ref, (char *name));
_PROTOTYPE(int archive_stat, (char *name, struct stat *stp));

View file

@ -1,469 +0,0 @@
/*************************************************************************
*
* m a k e : i n p u t . c
*
* Parse a makefile
*========================================================================
* Edition history
*
* # Date Comments By
* --- -------- ---------------------------------------------------- ---
* 1 ?? ??
* 2 23.08.89 new name tree structure introduced to speed up make,
* testname introduced to shrink the memory usage RAL
* 3 30.08.89 indention changed PSH,RAL
* 4 03.09.89 fixed LZ eliminated RAL
* 5 06.09.89 ; command added RAL
* ------------ Version 2.0 released ------------------------------- RAL
*
*************************************************************************/
#include "h.h"
static struct name *lastrrp;
static struct name *freerp = (struct name *)NULL;
void init()
{
if( (suffparray = (struct name **) malloc( sizesuffarray *
sizeof(struct name *))) == (struct name **) NULL)
fatal("No memory for suffarray",(char *)0,0);
if ((*suffparray = (struct name *)malloc(sizeof (struct name)))
== (struct name *)0)
fatal("No memory for name",(char *)0,0);
(*suffparray)->n_next = (struct name *)0;
if ((str1 = (char *) malloc(LZ1)) == ((char *)0))
fatal("No memory for str1",(char *)0,0);
str1s.ptr = &str1;
str1s.len = LZ1;
if ((str2 = (char *) malloc(LZ2)) == (char *)0)
fatal("No memory for str2",(char *)0,0);
str2s.ptr = &str2;
str2s.len = LZ2;
}
void strrealloc(strs)
struct str *strs;
{
strs->len *= 2;
*strs->ptr = (char *) realloc(*strs->ptr, strs->len + 16);
if(*strs->ptr == (char *) NULL)
fatal("No memory for string reallocation",(char *)0,0);
}
/*
* Intern a name. Return a pointer to the name struct
*/
struct name *newname(name)
char *name;
{
register struct name *rp;
register struct name *rrp;
register char *cp;
register int i;
register char *suff; /* ptr. to suffix in current name */
register struct name **sp; /* ptr. to ptr. to chain of names */
if ( (suff = suffix(name)) != (char *)NULL) {
for (i = 1, sp = suffparray, sp++;
i <= maxsuffarray && strcmp(suff, (*sp)->n_name) != 0;
sp++,i++);
if (i > maxsuffarray) {
if ( i >= sizesuffarray) { /* must realloc suffarray */
sizesuffarray *= 2;
if( (suffparray = (struct name **) realloc((char *) suffparray,
sizesuffarray * sizeof(struct name *))) == (struct name **) NULL)
fatal("No memory for suffarray",(char *)0,0);
}
maxsuffarray++;
sp = &suffparray[i];
if ((*sp = (struct name *)malloc(sizeof (struct name)))
== (struct name *)0)
fatal("No memory for name",(char *)0,0);
(*sp)->n_next = (struct name *)0;
if ((cp = (char *) malloc(strlen(suff)+1)) == (char *)0)
fatal("No memory for name",(char *)0,0);
strcpy(cp, suff);
(*sp)->n_name = cp;
}
}
else
sp = suffparray;
for ( rp = (*sp)->n_next, rrp = *sp; rp; rp = rp->n_next, rrp = rrp->n_next )
if (strcmp(name, rp->n_name) == 0) return rp;
if ( freerp == (struct name *)NULL) {
if ((rp = (struct name *)malloc(sizeof (struct name))) == (struct name *)0)
fatal("No memory for name",(char *)0,0);
}
else {
rp = freerp;
freerp = (struct name *)NULL;
}
rrp->n_next = rp;
rp->n_next = (struct name *)0;
if ((cp = (char *) malloc(strlen(name)+1)) == (char *)0)
fatal("No memory for name",(char *)0,0);
strcpy(cp, name);
rp->n_name = cp;
rp->n_line = (struct line *)0;
rp->n_time = (time_t)0;
rp->n_flag = 0;
lastrrp = rrp;
return rp;
}
/*
* Test a name.
* If the name already exists return the ptr. to its name structure.
* Else if the file exists 'intern' the name and return the ptr.
* Otherwise don't waste memory and return a NULL pointer
*/
struct name *testname(name)
char *name;
{
register struct name *rp;
lastrrp = (struct name *)NULL;
rp = newname( name);
if (rp->n_line || rp->n_flag & N_EXISTS)
return(rp);
modtime(rp);
if (rp->n_flag & N_EXISTS)
return(rp);
if (lastrrp != (struct name *)NULL) {
free (rp->n_name);
lastrrp->n_next = (struct name *)NULL;
freerp = rp;
}
return((struct name *)NULL);
}
/*
* Add a dependant to the end of the supplied list of dependants.
* Return the new head pointer for that list.
*/
struct depend *newdep(np, dp)
struct name *np;
struct depend *dp;
{
register struct depend *rp;
register struct depend *rrp;
if ((rp = (struct depend *)malloc(sizeof (struct depend)))
== (struct depend *)0)
fatal("No memory for dependant",(char *)0,0);
rp->d_next = (struct depend *)0;
rp->d_name = np;
if (dp == (struct depend *)0) return rp;
for (rrp = dp; rrp->d_next; rrp = rrp->d_next) ;
rrp->d_next = rp;
return dp;
}
/*
* Add a command to the end of the supplied list of commands.
* Return the new head pointer for that list.
*/
struct cmd *newcmd(str, cp)
char *str;
struct cmd *cp;
{
register struct cmd *rp;
register struct cmd *rrp;
register char *rcp;
if (rcp = strrchr(str, '\n')) *rcp = '\0'; /* Loose newline */
while (isspace(*str)) str++;
if (*str == '\0') return cp; /* If nothing left, the exit */
if ((rp = (struct cmd *)malloc(sizeof (struct cmd))) == (struct cmd *)0)
fatal("No memory for command",(char *)0,0);
rp->c_next = (struct cmd *)0;
if ((rcp = (char *) malloc(strlen(str)+1)) == (char *)0)
fatal("No memory for command",(char *)0,0);
strcpy(rcp, str);
rp->c_cmd = rcp;
if (cp == (struct cmd *)0) return rp;
for (rrp = cp; rrp->c_next; rrp = rrp->c_next) ;
rrp->c_next = rp;
return cp;
}
/*
* Add a new 'line' of stuff to a target. This check to see
* if commands already exist for the target. If flag is set,
* the line is a double colon target.
*
* Kludges:
* i) If the new name begins with a '.', and there are no dependents,
* then the target must cease to be a target. This is for .SUFFIXES.
* ii) If the new name begins with a '.', with no dependents and has
* commands, then replace the current commands. This is for
* redefining commands for a default rule.
* Neither of these free the space used by dependents or commands,
* since they could be used by another target.
*/
void newline(np, dp, cp, flag)
struct name *np;
struct depend *dp;
struct cmd *cp;
int flag;
{
bool hascmds = FALSE; /* Target has commands */
register struct line *rp;
register struct line *rrp;
/* Handle the .SUFFIXES case */
if (np->n_name[0] == '.' && !dp && !cp) {
for (rp = np->n_line; rp; rp = rrp) {
rrp = rp->l_next;
free(rp);
}
np->n_line = (struct line *)0;
np->n_flag &= ~N_TARG;
return;
}
/* This loop must happen since rrp is used later. */
for ( rp = np->n_line, rrp = (struct line *)0; rp; rrp = rp, rp = rp->l_next)
if (rp->l_cmd) hascmds = TRUE;
if (hascmds && cp && !(np->n_flag & N_DOUBLE))
/* Handle the implicit rules redefinition case */
if (np->n_name[0] == '.' && dp == (struct depend *)0) {
np->n_line->l_cmd = cp;
return;
}
else
error("Commands defined twice for target %s", np->n_name);
if (np->n_flag & N_TARG)
if (!(np->n_flag & N_DOUBLE) != !flag) /* like xor */
error("Inconsistent rules for target %s", np->n_name);
if ((rp = (struct line *)malloc(sizeof (struct line))) == (struct line *)0)
fatal("No memory for line",(char *)0,0);
rp->l_next = (struct line *)0;
rp->l_dep = dp;
rp->l_cmd = cp;
if (rrp)
rrp->l_next = rp;
else
np->n_line = rp;
np->n_flag |= N_TARG;
if (flag) np->n_flag |= N_DOUBLE;
}
/*
* Parse input from the makefile, and construct a tree structure
* of it.
*/
void input(fd)
FILE *fd;
{
char *p; /* General */
char *q;
register char *a;
struct name *np;
struct depend *dp;
struct cmd *cp;
bool dbl;
if (getline(&str1s, fd)) return; /* Read the first line */
for(;;) {
if (*str1 == TABCHAR) /* Rules without targets */
error("Rules not allowed here",(char *)0);
p = str1;
while (isspace(*p)) p++; /* Find first target */
while (((q = strchr(p, '+')) != (char *)0) &&
(q[1] == '=') && (p != q) && (q[-1] == '\\')) /* Find value */
{
a = q - 1; /* Del \ chr; move rest back */
p = q;
while(*a++ = *q++)
;
}
if (q != (char *)0 && q[1] == '=') {
*q++ = '\0'; /* Separate name and val */
*q++ = '\0'; /* Separate name and val */
while (isspace(*q))
q++;
if (p = strrchr(q, '\n'))
*p = '\0';
p = str1;
if ((a = gettok(&p)) == (char *)0)
error("No macro name",(char *)0);
addmacro(a, q);
if (getline(&str1s, fd))
return;
continue;
}
while (((q = strchr(p, '=')) != (char *)0) &&
(p != q) && (q[-1] == '\\')) /* Find value */
{
a = q - 1; /* Del \ chr; move rest back */
p = q;
while(*a++ = *q++)
;
}
if (q != (char *)0) {
*q++ = '\0'; /* Separate name and val */
while (isspace(*q))
q++;
if (p = strrchr(q, '\n'))
*p = '\0';
p = str1;
if ((a = gettok(&p)) == (char *)0)
error("No macro name",(char *)0);
setmacro(a, q);
if (getline(&str1s, fd))
return;
continue;
}
/* include? */
p = str1;
while (isspace(*p)) p++;
if (strncmp(p, "include", 7) == 0 && isspace(p[7])) {
char *old_makefile = makefile;
int old_lineno = lineno;
FILE *ifd;
p += 8;
memmove(str1, p, strlen(p)+1);
expand(&str1s);
p = str1;
while (isspace(*p)) p++;
if ((q = malloc(strlen(p)+1)) == (char *)0)
fatal("No memory for include",(char *)0,0);
strcpy(q, p);
p = q;
while ((makefile = gettok(&q)) != (char *)0) {
if ((ifd = fopen(makefile, "r")) == (FILE *)0)
fatal("Can't open %s: %s", makefile, errno);
lineno = 0;
input(ifd);
fclose(ifd);
}
free(p);
makefile = old_makefile;
lineno = old_lineno;
if (getline(&str1s, fd))
return;
continue;
}
/* Search for commands on target line --- do not expand them ! */
q = str1;
cp = (struct cmd *)0;
if ((a = strchr(q, ';')) != (char *)0) {
*a++ = '\0'; /* Separate dependents and commands */
if ( a) cp = newcmd(a, cp);
}
expand(&str1s);
p = str1;
while (isspace(*p)) p++;
while (((q = strchr(p, ':')) != (char *)0) &&
(p != q) && (q[-1] == '\\')) /* Find dependents */
{
a = q - 1; /* Del \ chr; move rest back */
p = q;
while(*a++ = *q++) ;
}
if (q == (char *)0)
error("No targets provided",(char *)0);
*q++ = '\0'; /* Separate targets and dependents */
if (*q == ':') { /* Double colon */
dbl = 1;
q++;
}
else
dbl = 0;
for (dp = (struct depend *)0; ((p = gettok(&q)) != (char *)0);)
/* get list of dep's */
{
np = newname(p); /* Intern name */
dp = newdep(np, dp); /* Add to dep list */
}
*((q = str1) + strlen(str1) + 1) = '\0';
/* Need two nulls for gettok (Remember separation) */
if (getline(&str2s, fd) == FALSE) { /* Get commands */
while (*str2 == TABCHAR) {
cp = newcmd(&str2[0], cp);
if (getline(&str2s, fd))
break;
}
}
while ((p = gettok(&q)) != (char *)0) /* Get list of targ's */
{
np = newname(p); /* Intern name */
newline(np, dp, cp, dbl);
if (!firstname && p[0] != '.')
firstname = np;
}
if (feof(fd)) /* EOF? */
return;
while (strlen(str2) >= str1s.len) strrealloc(&str1s);
strcpy(str1, str2);
}
}

View file

@ -1,232 +0,0 @@
/*************************************************************************
*
* m a k e : m a c r o . c
*
* Macro control for make
*========================================================================
* Edition history
*
* # Date Comments By
* --- -------- ---------------------------------------------------- ---
* 1 ?? ??
* 2 23.08.89 Error message corrected RAL
* 3 30.08.89 macro flags added, indention ch. PSH,RAL
* 4 03.09.89 fixed LZ eliminated, doexp(...) changed RAL
* 5 06.09.89 M_MAKE added, setDFmacro added RAL
* 6 20.09.89 work around for Minix PC ACK bug BE,RAL
* ------------ Version 2.0 released ------------------------------- RAL
*
*************************************************************************/
#include "h.h"
static char buf[256];
struct macro *getmp(name)
char *name;
{
register struct macro *rp;
for (rp = macrohead; rp; rp = rp->m_next)
if (strcmp(name, rp->m_name) == 0)
return rp;
return (struct macro *)0;
}
char *getmacro(name)
char *name;
{
struct macro *mp;
if (mp = getmp(name))
return mp->m_val;
/* else*/
return "";
}
struct macro *addmacro(name, val)
char *name;
char *val;
{
register struct macro *rp;
register char *cp;
int len_old_value;
/* Replace macro definition if it exists */
for (rp = macrohead; rp; rp = rp->m_next)
if (strcmp(name, rp->m_name) == 0) {
if(rp->m_flag & M_OVERRIDE) return rp; /* mustn't change */
break;
}
if (!rp) /* If not defined, allocate space for new */
{
fatal("Cannot add to a non-existing macro",(char *)0,0);
}
len_old_value = strlen(rp->m_val);
if ((cp = (char *) malloc(len_old_value+1+strlen(val)+1)) == (char *)0)
fatal("No memory for macro",(char *)0,0);
strcpy(cp, rp->m_val); /* Copy in old value */
cp[len_old_value] = ' ';
strcpy(cp+len_old_value+1, val); /* Copy in new value */
free(rp->m_val);
rp->m_val = cp;
return rp;
}
struct macro *setmacro(name, val)
char *name;
char *val;
{
register struct macro *rp;
register char *cp;
/* Replace macro definition if it exists */
for (rp = macrohead; rp; rp = rp->m_next)
if (strcmp(name, rp->m_name) == 0) {
if(rp->m_flag & M_OVERRIDE) return rp; /* mustn't change */
free(rp->m_val); /* Free space from old */
break;
}
if (!rp) /* If not defined, allocate space for new */
{
if ((rp = (struct macro *)malloc(sizeof (struct macro)))
== (struct macro *)0)
fatal("No memory for macro",(char *)0,0);
rp->m_next = macrohead;
macrohead = rp;
rp->m_flag = FALSE;
if ((cp = (char *) malloc(strlen(name)+1)) == (char *)0)
fatal("No memory for macro",(char *)0,0);
strcpy(cp, name);
rp->m_name = cp;
}
if ((cp = (char *) malloc(strlen(val)+1)) == (char *)0)
fatal("No memory for macro",(char *)0,0);
strcpy(cp, val); /* Copy in new value */
rp->m_val = cp;
return rp;
}
void setDFmacro(name, val)
char *name;
char *val;
{
char *c,*tmp;
int len;
static char filename[]="@F";
static char dirname[] ="@D";
setmacro(name,val);
*filename = *name;
*dirname = *name;
/* Null string -- not defined macro */
if ( !(*val)) {
setmacro(filename,"");
setmacro(dirname,"");
return;
}
if (!(c = strrchr(val,(int)'/'))) {
setmacro(filename,val);
setmacro(dirname,"./");
return;
}
setmacro(filename,c+1);
len = c - val + 1;
if((tmp = (char *) malloc(len + 1)) == (char *) 0)
fatal("No memory for tmp",(char *)0,0);
strncpy(tmp,val,len);
tmp[len] = '\0';
setmacro(dirname,tmp);
free(tmp);
return;
}
/*
* Do the dirty work for expand
*/
void doexp(to, from)
struct str *to;
char *from;
{
register char *rp;
register char *p;
char *q;
struct macro *mp;
rp = from;
p = &(*to->ptr)[to->pos];
while (*rp) {
if (*rp != '$') {
*p++ = *rp++;
to->pos++;
}
else {
q = buf;
if (*++rp == '{')
while (*++rp && *rp != '}')
*q++ = *rp;
else if (*rp == '(')
while (*++rp && *rp != ')')
*q++ = *rp;
else if (!*rp) {
*p++ = '$';
to->pos++;
goto bail;
}
else
*q++ = *rp;
*q = '\0';
if (*rp)
rp++;
if (!(mp = getmp(buf)))
mp = setmacro(buf, "");
if (mp->m_flag & M_MARK)
fatal("Infinitely recursive macro %s", mp->m_name,0);
mp->m_flag |= M_MARK;
if ( mp->m_flag & M_MAKE) expmake = TRUE;
doexp(to, mp->m_val);
p = &(*to->ptr)[to->pos];
mp->m_flag &= ~M_MARK;
}
bail:
if (to->pos >= to->len) {
strrealloc(to);
p = &(*to->ptr)[to->pos];
}
}
*p = '\0';
}
/*
* Expand any macros in str.
*/
void expand(strs)
struct str *strs;
{
char *a;
if ((a = (char *) malloc(strlen(*strs->ptr)+1)) == (char *)0)
fatal("No memory for temporary string",(char *)0,0);
strcpy(a, *strs->ptr);
strs->pos = 0;
doexp(strs, a);
free(a);
}

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -1,134 +0,0 @@
/*************************************************************************
*
* m a k e : r e a d e r . c
*
* Read in makefile
*========================================================================
* Edition history
*
* # Date Comments By
* --- -------- ---------------------------------------------------- ---
* 1 ?? ??
* 2 23.08.89 cast to NULL added RAL
* 3 30.08.89 indention changed PSH,RAL
* 4 03.09.89 fixed LZ eliminated RAL
* ------------ Version 2.0 released ------------------------------- RAL
*
*************************************************************************/
#include "h.h"
/*
* Syntax error handler. Print message, with line number, and exits.
*/
void error(msg, a1)
char *msg;
char *a1;
{
fprintf(stderr, "%s: ", myname);
fprintf(stderr, msg, a1);
if (lineno) fprintf(stderr, " in %s near line %d", makefile, lineno);
fputc('\n', stderr);
exit(1);
}
/*
* Read a line into the supplied string. Remove
* comments, ignore blank lines. Deal with quoted (\) #, and
* quoted newlines. If EOF return TRUE.
*
* The comment handling code has been changed to leave comments and
* backslashes alone in shell commands (lines starting with a tab).
* This is not what POSIX wants, but what all makes do. (KJB)
*/
bool getline(strs, fd)
struct str *strs;
FILE *fd;
{
register char *p;
char *q;
int c;
for (;;) {
strs->pos = 0;
for (;;) {
do {
if (strs->pos >= strs->len)
strrealloc(strs);
if ((c = getc(fd)) == EOF)
return TRUE; /* EOF */
(*strs->ptr)[strs->pos++] = c;
} while (c != '\n');
lineno++;
if (strs->pos >= 2 && (*strs->ptr)[strs->pos - 2] == '\\') {
(*strs->ptr)[strs->pos - 2] = '\n';
strs->pos--;
} else {
break;
}
}
if (strs->pos >= strs->len)
strrealloc(strs);
(*strs->ptr)[strs->pos] = '\0';
p = q = *strs->ptr;
while (isspace(*q)) q++;
if (*p != '\t' || *q == '#') {
while (((q = strchr(p, '#')) != (char *)0) &&
(p != q) && (q[-1] == '\\'))
{
char *a;
a = q - 1; /* Del \ chr; move rest back */
p = q;
while (*a++ = *q++)
;
}
if (q != (char *)0)
{
q[0] = '\n';
q[1] = '\0';
}
}
p = *strs->ptr;
while (isspace(*p)) /* Checking for blank */
p++;
if (*p != '\0')
return FALSE;
}
}
/*
* Get a word from the current line, surounded by white space.
* return a pointer to it. String returned has no white spaces
* in it.
*/
char *gettok(ptr)
register char **ptr;
{
register char *p;
while (isspace(**ptr)) /* Skip spaces */
(*ptr)++;
if (**ptr == '\0') /* Nothing after spaces */
return ((char *)NULL);
p = *ptr; /* word starts here */
while ((**ptr != '\0') && (!isspace(**ptr)))
(*ptr)++; /* Find end of word */
*(*ptr)++ = '\0'; /* Terminate it */
return(p);
}

View file

@ -1,314 +0,0 @@
/*************************************************************************
*
* m a k e : r u l e s . c
*
* Control of the implicit suffix rules
*========================================================================
* Edition history
*
* # Date Comments By
* --- -------- ---------------------------------------------------- ---
* 1 ?? ??
* 2 01.07.89 $<,$* bugs fixed, impl. r. ending in expl. r. added RAL
* 3 23.08.89 suffix as macro, testname intr., algorithem to find
* source dep. made more intelligent (see Readme3) RAL
* 4 30.08.89 indention changed PSH,RAL
* 5 03.09.89 fixed LZ eliminated RAL
* 6 07.09.89 rules of type '.c', .DEFAULT added, dep. search impr.RAL
* ------------ Version 2.0 released ------------------------------- RAL
*
*************************************************************************/
#include "h.h"
/*
* Dynamic dependency. This routine applies the suffis rules
* to try and find a source and a set of rules for a missing
* target. If found, np is made into a target with the implicit
* source name, and rules. Returns TRUE if np was made into
* a target.
*/
bool dyndep(np,pbasename,pinputname)
struct name *np;
char **pbasename; /* Name without suffix */
char **pinputname;
{
register char *p;
register char *q;
register char *suff; /* Old suffix */
struct name *op = (struct name *)0,*optmp; /* New dependent */
struct name *sp; /* Suffix */
struct line *lp,*nlp;
struct depend *dp,*ndp;
struct cmd *cmdp;
char *newsuff;
bool depexists = FALSE;
p = str1;
q = np->n_name;
suff = suffix(q);
while (*q && (q < suff || !suff)) *p++ = *q++;
*p = '\0';
if ((*pbasename = (char *) malloc(strlen(str1)+1)) == (char *)0 )
fatal("No memory for basename",(char *)0,0);
strcpy(*pbasename,str1);
if ( !suff) suff = p - str1 + *pbasename; /* set suffix to nullstring */
if (!((sp = newname(".SUFFIXES"))->n_flag & N_TARG)) return FALSE;
/* search all .SUFFIXES lines */
for (lp = sp->n_line; lp; lp = lp->l_next)
/* try all suffixes */
for (dp = lp->l_dep; dp; dp = dp->d_next) {
/* compose implicit rule name (.c.o)...*/
newsuff = dp->d_name->n_name;
while (strlen(suff)+strlen(newsuff)+1 >= str1s.len) strrealloc(&str1s);
p = str1;
q = newsuff;
while (*p++ = *q++) ;
p--;
q = suff;
while (*p++ = *q++) ;
/* look if the rule exists */
sp = newname(str1);
if (sp->n_flag & N_TARG) {
/* compose resulting dependency name */
while (strlen(*pbasename) + strlen(newsuff)+1 >= str1s.len)
strrealloc(&str1s);
q = *pbasename;
p = str1;
while (*p++ = *q++) ;
p--;
q = newsuff;
while (*p++ = *q++) ;
/* test if dependency file or an explicit rule exists */
if ((optmp= testname(str1)) != (struct name *)0) {
/* store first possible dependency as default */
if ( op == (struct name *)0) {
op = optmp;
cmdp = sp->n_line->l_cmd;
}
/* check if testname is an explicit dependency */
for ( nlp=np->n_line; nlp; nlp=nlp->l_next) {
for( ndp=nlp->l_dep; ndp; ndp=ndp->d_next) {
if ( strcmp( ndp->d_name->n_name, str1) == 0) {
op = optmp;
cmdp = sp->n_line->l_cmd;
ndp = (struct depend *) 0;
goto found2;
}
depexists = TRUE;
}
}
/* if no explicit dependencies : accept testname */
if (!depexists) goto found;
}
}
}
if ( op == (struct name *)0) {
if( np->n_flag & N_TARG) { /* DEFAULT handling */
if (!((sp = newname(".DEFAULT"))->n_flag & N_TARG)) return FALSE;
if (!(sp->n_line)) return FALSE;
cmdp = sp->n_line->l_cmd;
for ( nlp=np->n_line; nlp; nlp=nlp->l_next) {
if ( ndp=nlp->l_dep) {
op = ndp->d_name;
ndp = (struct depend *)0;
goto found2;
}
}
newline(np, (struct depend *)0, cmdp, 0);
*pinputname = (char *)0;
*pbasename = (char *)0;
return TRUE;
}
else return FALSE;
}
found:
ndp = newdep(op, (struct depend *)0);
found2:
newline(np, ndp, cmdp, 0);
*pinputname = op->n_name;
return TRUE;
}
/*
* Make the default rules
*/
void makerules()
{
struct cmd *cp;
struct name *np;
struct depend *dp;
#ifdef eon
setmacro("BDSCC", "asm");
/* setmacro("BDSCFLAGS", ""); */
cp = newcmd("$(BDSCC) $(BDSCFLAGS) -n $<", (struct cmd *)0);
np = newname(".c.o");
newline(np, (struct depend *)0, cp, 0);
setmacro("CC", "c");
setmacro("CFLAGS", "-O");
cp = newcmd("$(CC) $(CFLAGS) -c $<", (struct cmd *)0);
np = newname(".c.obj");
newline(np, (struct depend *)0, cp, 0);
setmacro("M80", "asm -n");
/* setmacro("M80FLAGS", ""); */
cp = newcmd("$(M80) $(M80FLAGS) $<", (struct cmd *)0);
np = newname(".mac.o");
newline(np, (struct depend *)0, cp, 0);
setmacro("AS", "zas");
/* setmacro("ASFLAGS", ""); */
cp = newcmd("$(ZAS) $(ASFLAGS) -o $@ $<", (struct cmd *)0);
np = newname(".as.obj");
newline(np, (struct depend *)0, cp, 0);
np = newname(".as");
dp = newdep(np, (struct depend *)0);
np = newname(".obj");
dp = newdep(np, dp);
np = newname(".c");
dp = newdep(np, dp);
np = newname(".o");
dp = newdep(np, dp);
np = newname(".mac");
dp = newdep(np, dp);
np = newname(".SUFFIXES");
newline(np, dp, (struct cmd *)0, 0);
#endif
#ifdef tos
#define unix
#endif
/*
* Some of the UNIX implicit rules
*/
#ifdef unix
setmacro("CC", "cc");
setmacro("CFLAGS", "");
cp = newcmd("$(CC) -S $(CFLAGS) $<", (struct cmd *)0);
np = newname(".c.s");
newline(np, (struct depend *)0, cp, 0);
cp = newcmd("$(CC) -c $(CFLAGS) $<", (struct cmd *)0);
np = newname(".c.o");
newline(np, (struct depend *)0, cp, 0);
#if this_rule_is_a_bit_too_much_of_a_good_thing
#ifdef MINIXPC
cp = newcmd("$(CC) $(CFLAGS) -i -o $@ $<", (struct cmd *)0);
#else
cp = newcmd("$(CC) $(CFLAGS) -o $@ $<", (struct cmd *)0);
#endif /* MINIXPC */
np = newname(".c");
newline(np, (struct depend *)0, cp, 0);
#endif
cp = newcmd("$(CC) -c $(CFLAGS) $<", (struct cmd *)0);
np = newname(".s.o");
newline(np, (struct depend *)0, cp, 0);
setmacro("YACC", "yacc");
/*setmacro("YFLAGS", ""); */
cp = newcmd("$(YACC) $(YFLAGS) $<", (struct cmd *)0);
cp = newcmd("mv y.tab.c $@", cp);
np = newname(".y.c");
newline(np, (struct depend *)0, cp, 0);
cp = newcmd("$(YACC) $(YFLAGS) $<", (struct cmd *)0);
cp = newcmd("$(CC) $(CFLAGS) -c y.tab.c", cp);
cp = newcmd("mv y.tab.o $@", cp);
np = newname(".y.o");
cp = newcmd("rm y.tab.c", cp);
newline(np, (struct depend *)0, cp, 0);
setmacro("FLEX", "flex");
cp = newcmd("$(FLEX) $(FLEX_FLAGS) $<", (struct cmd *)0);
cp = newcmd("mv lex.yy.c $@", cp);
np = newname(".l.c");
newline(np, (struct depend *)0, cp, 0);
cp = newcmd("$(FLEX) $(FLEX_FLAGS) $<", (struct cmd *)0);
cp = newcmd("$(CC) $(CFLAGS) -c lex.yy.c", cp);
cp = newcmd("mv lex.yy.o $@", cp);
np = newname(".l.o");
cp = newcmd("rm lex.yy.c", cp);
newline(np, (struct depend *)0, cp, 0);
np = newname(".o");
dp = newdep(np, (struct depend *)0);
np = newname(".s");
dp = newdep(np, dp);
np = newname(".c");
dp = newdep(np, dp);
np = newname(".y");
dp = newdep(np, dp);
np = newname(".l");
dp = newdep(np, dp);
np = newname(".SUFFIXES");
newline(np, dp, (struct cmd *)0, 0);
#endif /* unix */
#ifdef os9
/*
* Fairlight use an enhanced version of the C sub-system.
* They have a specialised macro pre-processor.
*/
setmacro("CC", "cc");
setmacro("CFLAGS", "-z");
cp = newcmd("$(CC) $(CFLAGS) -r $<", (struct cmd *)0);
np = newname(".c.r");
newline(np, (struct depend *)0, cp, 0);
np = newname(".ca.r");
newline(np, (struct depend *)0, cp, 0);
np = newname(".a.r");
newline(np, (struct depend *)0, cp, 0);
np = newname(".o.r");
newline(np, (struct depend *)0, cp, 0);
np = newname(".mc.r");
newline(np, (struct depend *)0, cp, 0);
np = newname(".mca.r");
newline(np, (struct depend *)0, cp, 0);
np = newname(".ma.r");
newline(np, (struct depend *)0, cp, 0);
np = newname(".mo.r");
newline(np, (struct depend *)0, cp, 0);
np = newname(".r");
dp = newdep(np, (struct depend *)0);
np = newname(".mc");
dp = newdep(np, dp);
np = newname(".mca");
dp = newdep(np, dp);
np = newname(".c");
dp = newdep(np, dp);
np = newname(".ca");
dp = newdep(np, dp);
np = newname(".ma");
dp = newdep(np, dp);
np = newname(".mo");
dp = newdep(np, dp);
np = newname(".o");
dp = newdep(np, dp);
np = newname(".a");
dp = newdep(np, dp);
np = newname(".SUFFIXES");
newline(np, dp, (struct cmd *)0, 0);
#endif
}

Some files were not shown because too many files have changed in this diff Show more