home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Usenet 1994 October
/
usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso
/
misc
/
volume14
/
dmake
/
part03
< prev
next >
Wrap
Text File
|
1990-07-26
|
40KB
|
1,488 lines
Newsgroups: comp.sources.misc
subject: v14i013: dmake version 3.5 part 3/21
From: dvadura@watdragon.waterloo.edu (Dennis Vadura)
Sender: allbery@uunet.UU.NET (Brandon S. Allbery - comp.sources.misc)
Posting-number: Volume 14, Issue 13
Submitted-by: dvadura@watdragon.waterloo.edu (Dennis Vadura)
Archive-name: dmake/part03
#!/bin/sh
# this is part 3 of a multipart archive
# do not concatenate these parts, unpack them in order with /bin/sh
# file unix/arlib.c continued
#
CurArch=3
if test ! -r s2_seq_.tmp
then echo "Please unpack part 1 first!"
exit 1; fi
( read Scheck
if test "$Scheck" != $CurArch
then echo "Please unpack part $Scheck next!"
exit 1;
else exit 0; fi
) < s2_seq_.tmp || exit 1
echo "x - Continuing file unix/arlib.c"
sed 's/^X//' << 'SHAR_EOF' >> unix/arlib.c
X check to see if the specified lib is cached. If so then return that time
X stamp instead of looking into the library. */
Xchar *name;
Xchar *lib;
X{
X FILE *f;
X int rv;
X time_t mtime;
X struct ar_args args;
X
X /* Check the cache first (if there is a cache) */
X if( _check_cache(name, lib, &mtime, FALSE) ) return( mtime );
X
X /* Open the lib file and perform the scan of the members, looking
X * for our particular member. If cacheing is enabled it will be
X * taken care of automatically during the scan. */
X
X args.lib = lib;
X args.member = name;
X args.time = (time_t)0L;
X
X if( (f = fopen(lib, "r")) == NIL(FILE) ) return( (time_t)0L );
X rv = ar_scan(f, time_function, &args );
X fclose( f );
X
X if( rv < 0 ) Fatal("(%s): Invalid library format", lib);
X
X return( args.time );
X}
X
X
Xint
Xtouch_arch(name, lib)/*
X=======================
X Look for module 'name' inside 'lib'. If compiled with cacheing then first
X check to see if the specified lib is cached. If so then set that time
X stamp and write it into the library. Returns 0 on success, non-zero
X on failure. */
Xchar *name;
Xchar *lib;
X{
X FILE *f;
X int rv;
X struct ar_args args;
X
X /* Open the lib file and perform the scan of the members, looking
X * for our particular member. If cacheing is enabled it will be
X * taken care of automatically during the scan. */
X
X args.lib = lib;
X args.member = name;
X args.time = (time_t)0L;
X
X if( (f = fopen(lib, "r+")) == NIL(FILE) ) return( (time_t)1L );
X rv = ar_scan(f, touch_function, &args );
X fclose( f );
X
X if( rv < 0 ) Fatal("(%s): Invalid library format", lib);
X
X return( 0 );
X}
X
X
X
Xstatic int
Xtime_function(f, arp, argp)/*
X=============================
X get library member's time, if it matches than return it in argp, if
X cacheing is enabled than cache the library members also. */
XFILE *f; /* library file */
Xstruct AR *arp; /* library member header */
Xstruct ar_args *argp;
X{
X int rv = _cache_member( arp->ar_name, argp->lib, arp->ar_time );
X
X if( strcmp(argp->member, arp->ar_name) == 0 ) {
X argp->time = arp->ar_time;
X
X if( arp->ar_time == 0 && !(Glob_attr & A_SILENT) )
X Warning( "(%s): Can't extract library member timestamp; using EPOCH",
X argp->member);
X
X return( rv ); /* 1 => no cacheing, 0 => cacheing */
X }
X
X return( FALSE ); /* continue scan */
X}
X
X
X
Xstatic int
Xtouch_function(f, arp, argp)/*
X==============================
X Update library member's time stamp, and write new time value into cache
X if required. */
XFILE *f; /* library file */
Xstruct AR *arp; /* library member header */
Xstruct ar_args *argp;
X{
X extern time_t time ANSI(( time_t * ));
X time_t now = time((time_t*) NULL); /* Current time. */
X
X if( strcmp(argp->member, arp->ar_name) == 0 ) {
X _check_cache( argp->member, argp->lib, &now, TRUE );
X ar_touch(f, now );
X
X return( TRUE );
X }
X
X return( FALSE ); /* continue scan */
X}
X
X
X
X
Xstatic int
Xar_scan(f, function, arg)/*
X===========================
X Scan the opened archive, and call the given function for each member found.
X The function will be called with the file positioned at the beginning of
X the member and it can read up to arp->ar_size bytes of the archive member.
X If the function returns 1, we stop and return 1. We return 0 at the end
X of the archive, or -1 if the archive has invalid format. This interface
X is more general than required by "make", but it can be used by other
X utilities. */
Xregister FILE *f;
Xint (*function) ANSI((FILE *, struct AR *, struct ar_args *));
Xstruct ar_args *arg;
X{
X extern long atol ANSI((char *));
X register char *p;
X struct ar_hdr arhdr; /* external archive header */
X off_t offset; /* member seek offset */
X
X#if ASCARCH
X char magic[SARMAG];
X#else
X unsigned short word;
X#endif
X
X fseek( f, 0L, 0 ); /* Start at the beginning of the archive file */
X
X#if ASCARCH
X fread( magic, sizeof(magic), 1, f );
X if( strncmp(magic, ARMAG, SARMAG) != 0 ) return( -1 );
X#else
X fread( (char*)&word, sizeof(word), 1, f );
X if( word != ARMAG ) return( -1 );
X#endif
X
X /* scan the library, calling `function' for each member
X */
X while( 1 ) {
X if( fread((char*) &arhdr, sizeof(arhdr), 1, f) != 1 ) break;
X offset = ftell(f);
X strncpy(_ar.ar_name, arhdr.ar_name, sizeof(arhdr.ar_name));
X
X for( p = &_ar.ar_name[sizeof(arhdr.ar_name)];
X --p >= _ar.ar_name && *p == ' ';);
X
X p[1] = '\0';
X if( *p == '/' ) *p = 0; /* Only SysV has trailing '/' */
X
X#if ASCARCH
X if( strncmp(arhdr.ar_fmag, ARFMAG, sizeof(arhdr.ar_fmag)) != 0 )
X return( -1 );
X _ar.ar_time = atol(arhdr.ar_date);
X _ar.ar_size = atol(arhdr.ar_size);
X#else
X _ar.ar_time = arhdr.ar_date;
X _ar.ar_size = atol(arhdr.ar_size);
X#endif
X
X
X#if DECODE_ALL_AR_FIELDS
X#if ASCARCH
X _ar.ar_mode = atoi(arhdr.ar_mode);
X _ar.ar_uid = atoi(arhdr.ar_uid);
X _ar.ar_gid = atoi(arhdr.ar_gid);
X#else
X _ar.ar_mode = arhdr.ar_mode;
X _ar.ar_size = arhdr.ar_size;
X _ar.ar_uid = arhdr.ar_uid;
X _ar.ar_gid = arhdr.ar_gid;
X#endif
X#endif
X
X if( (*function)(f, &_ar, arg) ) return( 1 );
X fseek( f, offset + (_ar.ar_size+1 & ~1L), 0 );
X }
X
X if( !feof(f) ) return( -1 );
X return 0;
X}
X
X
X
Xstatic int
Xar_touch( f, now )/*
X====================
X touch module header timestamp. */
XFILE *f;
Xtime_t now;
X{
X struct ar_hdr arhdr; /* external archive header */
X
X fseek(f, - (off_t) (sizeof(arhdr) - sizeof(arhdr.ar_name)), 1);
X
X#if ASCARCH
X fprintf(f, "%lu", now);
X#else
X fwrite((char *)now, sizeof(now), 1, f);
X#endif
X
X return( ferror(f) ? 0 : 1 );
X}
X
X
X#if LC
Xtypedef struct mem {
X time_t m_time; /* modify time of member*/
X struct mem *m_next; /* next member in lib */
X char m_valid; /* valid cache entry */
X char m_name[1]; /* lib member name */
X} MEM, *MEMPTR;
X
Xtypedef struct lib {
X struct lib *lb_next; /* next library in list */
X struct mem *lb_members; /* list of lib members */
X char lb_valid; /* valid cache entry */
X char *lb_name; /* library name */
X} LIB, *LIBPTR;
X
Xstatic LIBPTR _cache = NIL(LIB);
Xstatic MEMPTR _find_member ANSI(( LIBPTR, char * ));
X
Xstatic int
X_check_cache( name, lib, pmtime, touch )/*
X==========================================
X Check to see if we have cached member in lib, if so return time in pmtime
X and return TRUE, otherwise return FALSE, if touch is TRUE then touch
X the archive member instead. */
Xchar *name;
Xchar *lib;
Xtime_t *pmtime;
Xint touch;
X{
X register MEMPTR mp;
X register LIBPTR lp;
X
X for( lp=_cache; lp != NIL(LIB) && lp->lb_name != lib; lp=lp->lb_next );
X if( lp == NIL(LIB) ) return( FALSE );
X
X mp = _find_member( lp, name );
X if( mp == NIL(MEM) || !mp->m_valid ) return( FALSE );
X
X if( touch == TRUE )
X {
X mp->m_time = *pmtime;
X mp->m_valid = 1;
X }
X else
X *pmtime = mp->m_time;
X
X lp->lb_valid = 1;
X lp->lb_members = mp;
X
X return( TRUE );
X}
X
X
X
Xstatic int
X_cache_member( name, lib, mtime )/*
X===================================
X Cache name in lib along with it's time */
Xchar *name;
Xchar *lib;
Xtime_t mtime;
X{
X register MEMPTR mp;
X register LIBPTR lp;
X
X for( lp=_cache;
X lp != NIL(LIB) && lp->lb_name != NIL(char) && lp->lb_name != lib;
X lp=lp->lb_next);
X
X if( lp == NIL(LIB) )
X {
X lp = (LIBPTR) malloc(sizeof(LIB));
X if( lp == NIL(LIB) ) No_ram();
X
X lp->lb_name = lib;
X lp->lb_members = NIL(MEM);
X lp->lb_next = _cache;
X lp->lb_valid = 0;
X _cache = lp;
X }
X
X /* On UNIX ar does not allow multiple copies of the same .o file to live
X * in the same AR file. If this is not TRUE then use the commented out
X * version to set the value of mp. */
X
X /*mp = _find_member(lp, name);*/
X mp = NIL(MEM);
X
X if( mp == NIL(MEM) )
X {
X mp = (MEMPTR) malloc(sizeof(char)*offsetof(MEM,m_name[strlen(name)+1]));
X if( mp == NIL(MEM) ) No_ram();
X
X strcpy( mp->m_name, name );
X mp->m_time = mtime;
X
X if( lp->lb_members == NIL(MEM) ) {
X mp->m_next = mp;
X lp->lb_members = mp;
X }
X else {
X mp->m_next = lp->lb_members->m_next;
X lp->lb_members->m_next = mp;
X lp->lb_members = mp;
X }
X }
X else
X mp->m_time = mtime;
X
X mp->m_valid = 1;
X
X return( lp->lb_valid );
X}
X
X
Xstatic MEMPTR
X_find_member( lp, name )
XLIBPTR lp;
Xchar *name;
X{
X register MEMPTR mp = lp->lb_members;
X
X if( mp == NIL(MEM) ) return(mp);
X
X do {
X if( !strcmp(mp->m_name, name ) ) return( mp );
X mp = mp->m_next;
X }
X while( mp != lp->lb_members );
X
X return( NIL(MEM) );
X}
X#endif
X
X
X
Xvoid
Xvoid_lcache( lib, member )/*
X============================
X Void the library cache for lib. If member is NIL(char) then nuke all
X of the members, if member is NOT NIL(char) then invalidate only that
X member. */
Xchar *lib;
Xchar *member;
X{
X#if LC
X register LIBPTR lp;
X register MEMPTR mp;
X register MEMPTR tmp;
X
X for( lp=_cache; lp != NIL(LIB) && lp->lb_name != lib; lp=lp->lb_next );
X if( lp == NIL(LIB) ) return;
X
X if( member == NIL(char) ) {
X mp = lp->lb_members;
X do {
X tmp = mp->m_next;
X (void) free( mp );
X mp = tmp;
X } while( mp != lp->lb_members );
X
X lp->lb_valid = 0;
X lp->lb_members = NIL(MEM);
X lp->lb_name = NIL(char);
X }
X else {
X mp=lp->lb_members;
X do {
X if( strcmp( member, mp->m_name) == 0 ) {
X lp->lb_members = mp->m_next;
X mp->m_valid = 0;
X }
X
X mp=mp->m_next;
X } while( mp != lp->lb_members );
X }
X#endif
X}
SHAR_EOF
echo "File unix/arlib.c is complete"
chmod 0440 unix/arlib.c || echo "restore of unix/arlib.c fails"
echo mkdir - unix/386ix
mkdir unix/386ix
echo "x - extracting unix/386ix/time.h (Text)"
sed 's/^X//' << 'SHAR_EOF' > unix/386ix/time.h &&
X/*
X** Berkeley get this wrong!
X*/
X#ifndef TIME_h
X#define TIME_h
X
Xtypedef long time_t; /* this is the thing we use */
X
X#endif TIME_h
X
SHAR_EOF
chmod 0640 unix/386ix/time.h || echo "restore of unix/386ix/time.h fails"
echo "x - extracting unix/386ix/stdlib.h (Text)"
sed 's/^X//' << 'SHAR_EOF' > unix/386ix/stdlib.h &&
X#ifndef _STDLIB_INCLUDED_
X#define _STDLIB_INCLUDED_
X
Xextern /*GOTO*/ _exit();
Xextern /*GOTO*/ exit();
Xextern /*GOTO*/ abort();
Xextern int system();
Xextern char *getenv();
Xextern char *calloc();
Xextern char *malloc();
Xextern char *realloc();
Xextern free();
Xextern int errno;
X
X#ifndef EIO
X# include <errno.h>
X#endif
X
X#endif /* _STDLIB_INCLUDED_ */
SHAR_EOF
chmod 0640 unix/386ix/stdlib.h || echo "restore of unix/386ix/stdlib.h fails"
echo "x - extracting unix/386ix/stdarg.h (Text)"
sed 's/^X//' << 'SHAR_EOF' > unix/386ix/stdarg.h &&
X/*
X * stdarg.h
X *
X * defines ANSI style macros for accessing arguments of a function which takes
X * a variable number of arguments
X *
X */
X
X#if !defined(__STDARG)
X#define __STDARG
X
Xtypedef char *va_list;
X
X#define va_dcl int va_alist
X#define va_start(ap,v) ap = (va_list)&va_alist
X#define va_arg(ap,t) ((t*)(ap += sizeof(t)))[-1]
X#define va_end(ap) ap = NULL
X#endif
SHAR_EOF
chmod 0640 unix/386ix/stdarg.h || echo "restore of unix/386ix/stdarg.h fails"
echo "x - extracting unix/386ix/startup.mk (Text)"
sed 's/^X//' << 'SHAR_EOF' > unix/386ix/startup.mk &&
X# Generic UNIX DMAKE startup file. Customize to suit your needs.
X# Should work for both SYSV, and BSD 4.3
X# See the documentation for a description of internally defined macros.
X#
X# Disable warnings for macros redefined here that were given
X# on the command line.
X__.SILENT := $(.SILENT)
X.SILENT := yes
X
X# Configuration parameters for DMAKE startup.mk file
X# Set these to NON-NULL if you wish to turn the parameter on.
X_HAVE_RCS := yes # yes => RCS is installed.
X_HAVE_SCCS := yes # yes => SCCS is installed.
X
X# Applicable suffix definitions
XA := .a # Libraries
XE := # Executables
XF := .f # Fortran
XO := .o # Objects
XP := .p # Pascal
XS := .s # Assembler sources
XV := ,v # RCS suffix
X
X# Recipe execution configurations
XSHELL := /bin/sh
XSHELLFLAGS := -ce
XGROUPSHELL := $(SHELL)
XGROUPFLAGS :=
XSHELLMETAS := |();&<>?*][$$:\\#`'"
XGROUPSUFFIX :=
X
X# Standard C-language command names and flags
X CPP := /lib/cpp # C-preprocessor
X CC := cc # C-compiler and flags
X CFLAGS =
X
X AS := as # Assembler and flags
X ASFLAGS =
X
X LD = $(CC) # Loader and flags
X LDFLAGS =
X LDLIBS =
X
X# Definition of $(MAKE) macro for recursive makes.
X MAKE = $(MAKECMD) $(MFLAGS)
X
X# Definition of Print command for this system.
X PRINT = lpr
X
X# Language and Parser generation Tools and their flags
X YACC := yacc # standard yacc
X YFLAGS =
X YTAB := y.tab # yacc output files name stem.
X
X LEX := lex # standard lex
X LFLAGS =
X LEXYY := lex.yy # lex output file
X
X# Other Compilers, Tools and their flags
X PC := pc # pascal compiler
X RC := f77 # ratfor compiler
X FC := f77 # fortran compiler
X
X CO := co # check out for RCS
X COFLAGS := -q
X
X AR := ar # archiver
X ARFLAGS = ruv
X
X RM := /bin/rm # remove a file command
X RMFLAGS =
X
X# Implicit generation rules for making inferences.
X# We don't provide .yr or .ye rules here. They're obsolete.
X# Rules for making *$O
X %$O : %.c ; $(CC) $(CFLAGS) -c $<
X %$O : %$P ; $(PC) $(PFLAGS) -c $<
X %$O : %$S ; $(AS) $<
X %$O : %.cl ; class -c $<
X %$O : %.e %.r %.F %$F
X $(FC) $(RFLAGS) $(EFLAGS) $(FFLAGS) -c $<
X
X# Executables
X %$E : %$O ; $(LD) $(LDFLAGS) -o $@ $< $(LDLIBES)
X
X# lex and yacc rules
X %.c : %.y ; $(YACC) $(YFLAGS) $<; mv $(YTAB).c $@
X %.c : %.l ; $(LEX) $(LFLAGS) $<; mv $(LEXYY).c $@
X
X# This rule tells how to make *.out from it's immediate list of prerequisites
X# UNIX only.
X %.out :; $(LD) $(LDFLAGS) -o $@ $^ $(LDLIBS)
X
X# RCS support
X.IF $(_HAVE_RCS)
X % : %$V $$(@:d)RCS/$$(@:f)$V;- $(CO) $(COFLAGS) $@
X .NOINFER : %$V $$(@:d)RCS/$$(@:f)$V
X.END
X
X# SCCS support
X.IF $(_HAVE_SCCS)
X % : s.% ; get $@
X .NOINFER : s.%
X.END
X
X# Recipe to make archive files.
X%$A :
X[
X $(AR) $(ARFLAGS) $@ $?
X $(RM) $(RMFLAGS) $?
X ranlib $@
X]
X
X# DMAKE uses this recipe to remove intermediate targets
X.REMOVE :; $(RM) -f $<
X
X# AUGMAKE extensions for SYSV compatibility
X@B = $(@:b)
X@D = $(@:d)
X@F = $(@:f)
X*B = $(*:b)
X*D = $(*:d)
X*F = $(*:f)
X<B = $(<:b)
X<D = $(<:d)
X<F = $(<:f)
X?B = $(?:b)
X?F = $(?:f)
X?D = $(?:d)
X
X# Turn warnings back to previous setting.
X.SILENT := $(__.SILENT)
X
X# Local startup file if any
X.INCLUDE .IGNORE: "_startup.mk"
SHAR_EOF
chmod 0640 unix/386ix/startup.mk || echo "restore of unix/386ix/startup.mk fails"
echo "x - extracting unix/386ix/make.sh (Text)"
sed 's/^X//' << 'SHAR_EOF' > unix/386ix/make.sh &&
Xmkdir objects
Xcc -c -DHELP -I. -Icommon -Iunix -Iunix/386ix -O infer.c
Xmv infer.o objects
Xcc -c -DHELP -I. -Icommon -Iunix -Iunix/386ix -O make.c
Xmv make.o objects
Xcc -c -DHELP -I. -Icommon -Iunix -Iunix/386ix -O stat.c
Xmv stat.o objects
Xcc -c -DHELP -I. -Icommon -Iunix -Iunix/386ix -O expand.c
Xmv expand.o objects
Xcc -c -DHELP -I. -Icommon -Iunix -Iunix/386ix -O string.c
Xmv string.o objects
Xcc -c -DHELP -I. -Icommon -Iunix -Iunix/386ix -O hash.c
Xmv hash.o objects
Xcc -c -DHELP -I. -Icommon -Iunix -Iunix/386ix -O dag.c
Xmv dag.o objects
Xcc -c -DHELP -I. -Icommon -Iunix -Iunix/386ix -O dmake.c
Xmv dmake.o objects
Xcc -c -DHELP -I. -Icommon -Iunix -Iunix/386ix -O path.c
Xmv path.o objects
Xcc -c -DHELP -I. -Icommon -Iunix -Iunix/386ix -O imacs.c
Xmv imacs.o objects
Xcc -c -DHELP -I. -Icommon -Iunix -Iunix/386ix -O sysintf.c
Xmv sysintf.o objects
Xcc -c -DHELP -I. -Icommon -Iunix -Iunix/386ix -O parse.c
Xmv parse.o objects
Xcc -c -DHELP -I. -Icommon -Iunix -Iunix/386ix -O getinp.c
Xmv getinp.o objects
Xcc -c -DHELP -I. -Icommon -Iunix -Iunix/386ix -O quit.c
Xmv quit.o objects
Xcc -c -DHELP -I. -Icommon -Iunix -Iunix/386ix -O basename.c
Xmv basename.o objects
Xcc -c -DHELP -I. -Icommon -Iunix -Iunix/386ix -O dump.c
Xmv dump.o objects
Xcc -c -DHELP -I. -Icommon -Iunix -Iunix/386ix -O macparse.c
Xmv macparse.o objects
Xcc -c -DHELP -I. -Icommon -Iunix -Iunix/386ix -O rulparse.c
Xmv rulparse.o objects
Xcc -c -DHELP -I. -Icommon -Iunix -Iunix/386ix -O percent.c
Xmv percent.o objects
Xcc -c -DHELP -I. -Icommon -Iunix -Iunix/386ix -O unix/arlib.c
Xmv arlib.o objects
Xcc -c -DHELP -I. -Icommon -Iunix -Iunix/386ix -O unix/dirbrk.c
Xmv dirbrk.o objects
Xcc -c -DHELP -I. -Icommon -Iunix -Iunix/386ix -O unix/explode.c
Xmv explode.o objects
Xcc -c -DHELP -I. -Icommon -Iunix -Iunix/386ix -O unix/rmprq.c
Xmv rmprq.o objects
Xcc -c -DHELP -I. -Icommon -Iunix -Iunix/386ix -O unix/ruletab.c
Xmv ruletab.o objects
Xcc -c -DHELP -I. -Icommon -Iunix -Iunix/386ix -O unix/runargv.c
Xmv runargv.o objects
Xcc -o dmake objects/infer.o objects/make.o objects/stat.o objects/expand.o objects/string.o objects/hash.o objects/dag.o objects/dmake.o objects/path.o objects/imacs.o objects/sysintf.o objects/parse.o objects/getinp.o objects/quit.o objects/basename.o objects/dump.o objects/macparse.o objects/rulparse.o objects/percent.o objects/arlib.o objects/dirbrk.o objects/explode.o objects/rmprq.o objects/ruletab.o objects/runargv.o
SHAR_EOF
chmod 0640 unix/386ix/make.sh || echo "restore of unix/386ix/make.sh fails"
echo "x - extracting unix/386ix/config.mk (Text)"
sed 's/^X//' << 'SHAR_EOF' > unix/386ix/config.mk &&
X# This is the SysV R3 UNIX configuration file for DMAKE
X# It simply modifies the values of SRC, and checks to see if
X# OSENVIRONMENT is defined. If so it includes the appropriate
X# config.mk file.
X#
X# It also sets the values of .SOURCE.c and .SOURCE.h to include the local
X# directory.
X#
Xosrdir := $(OS)$(DIRSEPSTR)$(OSRELEASE)
X
X# The following sources are required for SysV R3
XSRC += #zero for now. we do have some .h's though
X
X#.SOURCE.c : $(osrdir)
X.SOURCE.h : $(osrdir)
X
X# Local configuration modifications for CFLAGS, there's local SysV includes
X# too.
XCFLAGS += -I$(osrdir)
X
X# See if we modify anything in the lower levels.
X.IF $(OSENVIRONMENT) != $(NULL)
X .INCLUDE .IGNORE : $(osrdir)$(DIRSEPSTR)$(OSENVIRONMENT)$(DIRSEPSTR)config.mk
X.END
SHAR_EOF
chmod 0640 unix/386ix/config.mk || echo "restore of unix/386ix/config.mk fails"
echo "x - extracting unix/386ix/config.h (Text)"
sed 's/^X//' << 'SHAR_EOF' > unix/386ix/config.h &&
X/* RCS -- $Header$
X-- SYNOPSIS -- Configurarion include file.
X--
X-- DESCRIPTION
X-- There is one of these for each specific machine configuration.
X-- It can be used to further tweek the machine specific sources
X-- so that they compile.
X--
X-- AUTHOR
X-- Dennis Vadura, dvadura@watdragon.uwaterloo.ca
X-- CS DEPT, University of Waterloo, Waterloo, Ont., Canada
X--
X-- COPYRIGHT
X-- Copyright (c) 1990 by Dennis Vadura. All rights reserved.
X--
X-- This program is free software; you can redistribute it and/or
X-- modify it under the terms of the GNU General Public License
X-- (version 1), as published by the Free Software Foundation, and
X-- found in the file 'LICENSE' included with this distribution.
X--
X-- This program is distributed in the hope that it will be useful,
X-- but WITHOUT ANY WARRANTY; without even the implied warrant of
X-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
X-- GNU General Public License for more details.
X--
X-- You should have received a copy of the GNU General Public License
X-- along with this program; if not, write to the Free Software
X-- Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
X--
X-- LOG
X-- $Log$
X*/
X
X/* define this for configurations that don't have the coreleft function
X * so that the code compiles. To my knowledge coreleft exists only on
X * Turbo C, but it is needed here since the function is used in many debug
X * macros. */
X#define coreleft() 0L
X
X/* Define the getcwd function that is used in the code, since BSD does
X * not have getcwd, but call it getwd instead. */
Xextern char *getcwd ANSI((char *, int));
X
X/* Define setvbuf, SysV doesn't have one */
X#define setvbuf(fp, bp, type, len) setbuf( fp, NULL );
X
X/* NCR Tower's don't define size_t */
X#ifdef tower
Xtypedef long size_t;
X#endif
SHAR_EOF
chmod 0640 unix/386ix/config.h || echo "restore of unix/386ix/config.h fails"
echo "x - extracting unix/386ix/ar.h (Text)"
sed 's/^X//' << 'SHAR_EOF' > unix/386ix/ar.h &&
X#define PORTAR 1
X#include "/usr/include/ar.h"
SHAR_EOF
chmod 0640 unix/386ix/ar.h || echo "restore of unix/386ix/ar.h fails"
echo "x - extracting sysintf.c (Text)"
sed 's/^X//' << 'SHAR_EOF' > sysintf.c &&
X/* RCS -- $Header: /u2/dvadura/src/generic/dmake/src/RCS/sysintf.c,v 1.1 90/07/21 11:06:34 dvadura Exp $
X-- SYNOPSIS -- system independent interface
X--
X-- DESCRIPTION
X-- These are the routines constituting the system interface.
X-- The system is taken to be essentially POSIX conformant.
X-- The original code was extensively revised by T J Thompson at MKS,
X-- and the library cacheing was added by Eric Gisin at MKS. I then
X-- revised the code yet again, to improve the lib cacheing, and to
X-- make it a little more portable.
X--
X-- The following is a list of routines that are required by this file
X-- in order to work. These routines are provided as functions by the
X-- standard C lib of the target system or as #defines in system/sysintf.h
X-- or via appropriate C code in the system/ directory for the given
X-- system.
X--
X-- The first group must be provided by a file in the system/ directory
X-- the second group is ideally provided by the C lib. However, there
X-- are instances where the C lib implementation of the specified routine
X-- does not exist, or is incorrect. In these instances the routine
X-- must be provided by the the user in the system/ directory of dmake.
X-- (For example, the bsd/ dir contains code for putenv(), and tempnam())
X--
X-- DMAKE SPECIFIC:
X-- seek_arch()
X-- touch_arch()
X-- void_lcache()
X-- runargv()
X-- STAT()
X--
X-- C-LIB SPECIFIC: (should be present in your C-lib)
X-- utime()
X-- time()
X-- getenv()
X-- putenv()
X-- getcwd()
X-- signal()
X-- chdir()
X-- tempnam()
X--
X-- AUTHOR
X-- Dennis Vadura, dvadura@watdragon.uwaterloo.ca
X-- CS DEPT, University of Waterloo, Waterloo, Ont., Canada
X--
X-- COPYRIGHT
X-- Copyright (c) 1990 by Dennis Vadura. All rights reserved.
X--
X-- This program is free software; you can redistribute it and/or
X-- modify it under the terms of the GNU General Public License
X-- (version 1), as published by the Free Software Foundation, and
X-- found in the file 'LICENSE' included with this distribution.
X--
X-- This program is distributed in the hope that it will be useful,
X-- but WITHOUT ANY WARRANTY; without even the implied warrant of
X-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
X-- GNU General Public License for more details.
X--
X-- You should have received a copy of the GNU General Public License
X-- along with this program; if not, write to the Free Software
X-- Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
X--
X-- LOG
X-- $Log: sysintf.c,v $
X * Revision 1.1 90/07/21 11:06:34 dvadura
X * Initial Revision Version 3.5
X *
X*/
X
X#include <stdio.h>
X#include "extern.h"
X#include "sysintf.h"
X#include "alloc.h"
X
X/*
X** Tries to stat the file name. Returns 0 if the file
X** does not exist. Note that if lib is not null it tries to stat
X** the name found inside lib.
X**
X** If member is NOT nil then look for the library object which defines the
X** symbol given by name. If found _strdup the name and return make the
X** pointer pointed at by sym point at it. Not handled for now!
X*/
Xtime_t
XDo_stat(name, lib, member)
Xchar *name;
Xchar *lib;
Xchar **member;
X{
X struct stat buf;
X time_t seek_arch();
X
X if( member != NIL(char *) )
X Fatal("Library symbol names not supported");
X
X if( lib != NIL(char) )
X return( seek_arch(basename(name), lib) );
X else
X return( (STAT(name, &buf) == -1) ? (time_t)0 : buf.st_mtime );
X}
X
X
X
X/* Touch existing file to force modify time to present.
X */
Xint
XDo_touch(name, lib, member)
Xchar *name;
Xchar *lib;
Xchar **member;
X{
X if( member != NIL(char *) )
X Fatal("Library symbol names not supported");
X
X if (lib != NIL(char))
X return( touch_arch(basename(name), lib) );
X else
X return( utime(name, NIL(time_t)) );
X}
X
X
X
Xvoid
XVoid_lib_cache( lib_name, member_name )/*
X=========================================
X Void the library cache for lib lib_name, and member member_name. */
Xchar *lib_name;
Xchar *member_name;
X{
X VOID_LCACHE( lib_name, member_name );
X}
X
X
X
X/*
X** return the current time
X*/
Xtime_t
XDo_time()
X{
X extern time_t time();
X return (time((time_t*)0));
X}
X
X
X
X/*
X** Execute the string passed in as a command and return
X** the return code. The command line arguments are
X** assumed to be separated by spaces or tabs. The first
X** such argument is assumed to be the command.
X**
X** If group is true then this is a group of commands to be fed to the
X** the shell as a single unit. In this case cmd is of the form
X** "file" indicating the file that should be read by the shell
X** in order to execute the command group.
X*/
Xint
XDo_cmnd(cmd, group, do_it, target, how, ignore, last)
Xchar *cmd;
Xint group;
Xint do_it;
XCELLPTR target;
XHOWPTR how;
Xint ignore;
Xint last;
X{
X int i;
X
X if( !do_it ) {
X if( last && !Doing_bang ) Update_time_stamp( target, how );
X return(0);
X }
X
X if( Max_proc == 1 ) Wait_for_completion = TRUE;
X if( (i = runargv(target, how, ignore, group, last, cmd)) == -1 )
X Quit();
X
X /* NOTE: runargv must return either 0 or 1, 0 ==> command executed, and
X * we waited for it to return, 1 ==> command started and is running
X * concurrently with make process. */
X return(i);
X}
X
X
X/* Take a command and pack it into an argument vector to be executed. */
Xvoid
XPack_argv( argv, maxargv, group, cmd )
Xchar **argv;
Xint maxargv;
Xint group;
Xchar *cmd;
X{
X int i;
X
X if( group || (*_strpbrk(cmd, Shell_metas) != '\0') ) {
X char* sh = group ? GShell : Shell;
X
X if( sh != NIL(char) ) {
X argv[0] = sh;
X argv[1] = group ? GShell_flags : Shell_flags;
X
X if( argv[1] == NIL(char) ) {
X argv[1] = cmd;
X argv[2] = NIL(char);
X }
X else {
X argv[2] = cmd;
X argv[3] = NIL(char);
X }
X }
X else if( group )
X Fatal("GROUPSHELL macro not defined");
X else
X Fatal("SHELL macro not defined");
X }
X else {
X i = 0;
X
X do {
X if( i == maxargv )
X Fatal( "Argument limit exceeded, maximum number of arguments %d",
X maxargv );
X
X while( iswhite(*cmd) ) ++cmd;
X if( *cmd ) argv[i++] = cmd;
X
X while( *cmd != '\0' && !iswhite(*cmd) ) ++cmd;
X if( *cmd ) *cmd++ = '\0';
X } while( *cmd );
X
X argv[i] = NIL(char);
X }
X}
X
X
X/*
X** Return the value of ename from the environment
X** if ename is not defined in the environment then
X** NIL(char) should be returned
X*/
Xchar *
XRead_env_string(ename)
Xchar *ename;
X{
X extern char *getenv();
X return( getenv(ename) );
X}
X
X
X
X/*
X** Set the value of the environment string ename to value.
X** Returns 0 if success, non-zero if failure
X*/
Xint
XWrite_env_string(ename, value)
Xchar *ename;
Xchar *value;
X{
X extern int putenv();
X char* p;
X char* envstr = _stradd(ename, value, FALSE);
X
X p = envstr+strlen(ename); /* Don't change this code, _stradd does not */
X *p++ = '='; /* add the space if *value is 0, it does */
X if( !*value ) *p = '\0'; /* allocate enough memory for one though. */
X
X return( putenv(envstr) );
X}
X
X
X
Xvoid
XReadEnvironment()
X{
X extern char **Rule_tab;
X extern char **environ;
X char **rsave;
X
X rsave = Rule_tab;
X Rule_tab = environ;
X Readenv = TRUE;
X
X Parse( NIL(FILE) );
X
X Readenv = FALSE;
X Rule_tab = rsave;
X}
X
X
X
X/*
X** All we have to catch is SIG_INT
X*/
Xvoid
XCatch_signals(fn)
Xvoid (*fn)();
X{
X if( signal(SIGINT, SIG_IGN) != SIG_IGN )
X signal( SIGINT, fn );
X if( signal(SIGQUIT, SIG_IGN) != SIG_IGN )
X signal( SIGQUIT, fn );
X}
X
X
X
X/*
X** Clear any previously set signals
X*/
Xvoid
XClear_signals()
X{
X if( signal(SIGINT, SIG_IGN) != SIG_IGN )
X signal( SIGINT, SIG_DFL );
X if( signal(SIGQUIT, SIG_IGN) != SIG_IGN )
X signal( SIGQUIT, SIG_DFL );
X}
X
X
X
X/*
X** Set program name
X*/
Xvoid
XProlog(argc, argv)
Xint argc;
Xchar* argv[];
X{
X Pname = (argc == 0) ? DEF_MAKE_PNAME : argv[0];
X}
X
X
X
X/*
X** Do any clean up for exit.
X*/
Xvoid
XEpilog(ret_code)
Xint ret_code;
X{
X exit( ret_code );
X}
X
X
X
X/*
X** Use the built-in functions of the operating system to get the current
X** working directory.
X*/
Xchar *
XGet_current_dir()
X{
X static char buf[MAX_PATH_LEN+1];
X
X return( getcwd(buf, sizeof(buf)) );
X}
X
X
X
X/*
X** change working directory
X*/
Xint
XSet_dir(path)
Xchar* path;
X{
X return( chdir(path) );
X}
X
X
X
X/*
X** return switch char
X*/
Xchar
XGet_switch_char()
X{
X return( getswitchar() );
X}
X
X
X
X/*
X** Generate a temporary file name and open the file for writing.
X** If a name cannot be generated or the file cannot be opened
X** return -1, else return the fileno of the open file.
X** and update the source file pointer to point at the new file name.
X** Note that the new name should be freed when the file is removed.
X*/
XFILE*
XOpen_temp(path, suff)
Xchar **path;
Xchar *suff;
X{
X extern char *tempnam();
X
X *path = _strjoin( tempnam(NIL(char), "mk"), suff, -1, TRUE );
X return( fopen(*path, "w") );
X}
X
X
X/*
X** Open a new temporary file and set it up for writing.
X*/
XFILE *
XStart_temp( suffix, cp, how, fname )
Xchar *suffix;
XCELLPTR cp;
XHOWPTR how;
Xchar **fname;
X{
X FILE *fp;
X char *tmpname;
X char *name;
X FILELISTPTR new;
X
X name = cp->CE_NAME;
X if( (fp = Open_temp( &tmpname, suffix)) == NIL(FILE) )
X Fatal("Cannot open temp file `%s' while making `%s'", tmpname, name );
X
X TALLOC( new, 1, FILELIST );
X
X new->fl_next = how->hw_files;
X new->fl_name = tmpname;
X new->fl_file = fp; /* indicates temp file is open */
X
X how->hw_files = new;
X *fname = tmpname;
X
X return( fp );
X}
X
X
X/*
X** Close a previously used temporary file.
X*/
Xvoid
XClose_temp(how, file)
XHOWPTR how;
XFILE *file;
X{
X FILELISTPTR fl;
X
X for( fl=how->hw_files; fl && fl->fl_file != file; fl=fl->fl_next );
X if( fl ) {
X fl->fl_file = NIL(FILE);
X fclose(file);
X }
X}
X
X
X/*
X** Clean-up, and close all temporary files associated with a target.
X*/
Xvoid
XUnlink_temp_files( how )/*
X==========================
X Unlink the tempfiles if any exist. Make sure you close the files first
X though. This ensures that under DOS there is no disk space lost. */
XHOWPTR how;
X{
X FILELISTPTR next;
X
X while( how->hw_files != NIL(FILELIST) ) {
X if( how->hw_files->fl_file ) fclose( how->hw_files->fl_file );
X
X if( Verbose )
X printf( "%s: Left temp file [%s]\n", Pname, how->hw_files->fl_name );
X else
X (void) unlink( how->hw_files->fl_name );
X
X FREE( how->hw_files->fl_name );
X next = how->hw_files->fl_next;
X FREE(how->hw_files);
X how->hw_files = next;
X }
X}
X
X
Xvoid
XHandle_result(status, ignore, abort_flg, target)
Xint status;
Xint ignore;
Xint abort_flg;
XCELLPTR target;
X{
X status = ((status&0xff)==0 ? status>>8
X : (status & 0xff)==SIGTERM ? -1
X : (status & 0x7f)+128);
X
X if( status )
X if( !abort_flg ) {
X fprintf( stderr, "%s: Error code %d, while making '%s'",
X Pname, status, target->ce_fname );
X
X if( ignore || Continue ) {
X fputs( " (Ignored)\n", stderr );
X }
X else {
X fputc( '\n', stderr );
X
X if( !(target->ce_attr & A_PRECIOUS) )
X if( unlink( target->ce_fname ) == 0 )
X fprintf(stderr,"%s: '%s' removed.\n",Pname,target->ce_fname);
X
X Quit();
X }
X }
X else if( !(target->ce_attr & A_PRECIOUS) )
X unlink( target->ce_fname );
X}
X
X
Xvoid
XUpdate_time_stamp( cp, how )
XCELLPTR cp;
XHOWPTR how;
X{
X HASHPTR hp;
X CELLPTR tcp;
X int tmpflg;
X
X how->hw_flag |= F_MADE;
X Unlink_temp_files( how );
X
X /* do the time only at end, of MULTI recipe targets, or immediately
X * for non-MULTI recipe targets. */
X tmpflg = cp->ce_flag & F_MULTI;
X
X if( (tmpflg && cp->CE_HOW == how) || !tmpflg ) {
X tcp = cp;
X do {
X if( tcp->ce_attr & A_LIBRARY )
X Void_lib_cache( tcp->ce_fname, NIL(char) );
X else if( !Touch && (tcp->ce_attr & A_LIBRARYM) )
X Void_lib_cache( tcp->ce_lib, tcp->ce_fname );
X
X if( Trace ) {
X tcp->ce_time = Do_time();
X tcp->ce_flag |= F_STAT; /* pretend we stated ok */
X
X if( tcp->ce_fname == NIL(char) )
X tcp->ce_fname = tcp->CE_NAME;
X }
X else {
X Stat_target( tcp, TRUE );
X if( tcp->ce_time == (time_t) 0L )
X tcp->ce_time = Do_time();
X }
X
X if( Verbose )
X printf( "%s: <<<< Set [%s] time stamp to %ld\n",
X Pname, tcp->CE_NAME, tcp->ce_time );
X
X tcp->ce_flag |= F_MADE;
X tcp = tcp->ce_all;
X }
X while( tcp != NIL(CELL) && tcp != cp );
X }
X else if( tmpflg )
X cp->ce_flag |= F_STAT;
X
X
X /* Scan the list of prerequisites and if we find one that is
X * marked as being removable, (ie. an inferred intermediate node
X * then remove it. We remove a prerequisite by running the recipe
X * associated with the special target .REMOVE, with $< set to
X * the list of prerequisites to remove. */
X
X if( (hp = Get_name( ".REMOVE", Defs, FALSE, NIL(CELL) )) != NIL(HASH) ) {
X register LINKPTR dp;
X int flag = FALSE;
X int rem;
X int attr;
X
X tcp = hp->CP_OWNR;
X tcp->ce_flag |= F_TARGET;
X Clear_prerequisites( tcp->CE_HOW );
X
X for( dp = how->hw_prq; dp != NIL(LINK); dp = dp->cl_next ) {
X register CELLPTR prq = dp->cl_prq;
X
X attr = Glob_attr | prq->ce_attr;
X rem = (prq->ce_flag & F_REMOVE) &&
X (prq->ce_flag & F_MADE ) &&
X !(attr & A_PRECIOUS) &&
X !Force;
X
X if( rem ) {
X CELLPTR tmp = prq;
X do {
X (Add_prerequisite(tcp->CE_HOW, prq, FALSE))->cl_flag |= F_TARGET;
X prq->ce_flag &= ~F_REMOVE;
X prq = prq->ce_all;
X }
X while( prq != NIL(CELL) && prq != tmp );
X flag = TRUE;
X }
X }
X
X if( flag ) Remove_prq( tcp );
X }
X}
SHAR_EOF
chmod 0440 sysintf.c || echo "restore of sysintf.c fails"
echo "x - extracting struct.h (Text)"
sed 's/^X//' << 'SHAR_EOF' > struct.h &&
X/* RCS -- $Header: /u2/dvadura/src/generic/dmake/src/RCS/struct.h,v 1.1 90/07/19 13:55:36 dvadura Exp $
X-- SYNOPSIS -- structure definitions
X--
X-- DESCRIPTION
X-- dmake main data structure definitions. See each of the individual
X-- struct declarations for more detailed information on the defined
X-- fields and their use.
X--
X-- AUTHOR
X-- Dennis Vadura, dvadura@watdragon.uwaterloo.ca
X-- CS DEPT, University of Waterloo, Waterloo, Ont., Canada
X--
X-- COPYRIGHT
X-- Copyright (c) 1990 by Dennis Vadura. All rights reserved.
X--
X-- This program is free software; you can redistribute it and/or
X-- modify it under the terms of the GNU General Public License
X-- (version 1), as published by the Free Software Foundation, and
X-- found in the file 'LICENSE' included with this distribution.
X--
X-- This program is distributed in the hope that it will be useful,
X-- but WITHOUT ANY WARRANTY; without even the implied warrant of
X-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
X-- GNU General Public License for more details.
X--
X-- You should have received a copy of the GNU General Public License
X-- along with this program; if not, write to the Free Software
X-- Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
X--
X-- LOG
X-- $Log: struct.h,v $
X * Revision 1.1 90/07/19 13:55:36 dvadura
X * Initial Revision of Version 3.5
X *
X*/
X
X#ifndef _STRUCT_INCLUDED_
X#define _STRUCT_INCLUDED_
X
X#include <sys/types.h>
X#include "itypes.h"
X
X/* The following struct is the cell used in the hash table.
X * NOTE: It contains the actual hash value. This allows the hash table
X * insertion to compare hash values and to do a string compare only
X * for entries that have matching hash_key values. This elliminates
X * 99.9999% of all extraneous string compare operations when searching
X * a hash table chain for matching entries. */
X
Xtypedef struct hcell {
X struct hcell *ht_next; /* next entry in the hash table */
X char *ht_name; /* name of this cell */
X char *ht_value; /* cell value if and */
X uint32 ht_hash; /* actual hash_value of cell */
X int ht_flag; /* flags belonging to hash entry */
X
X /* NOTE: some macros have corresponding variables defined
X * that control program behaviour. For these macros a
X * bit of ht_flag indicates the variable value will be set, and the
X * type of the value that will be set.
X *
X * The struct below contains a mask for bit variables, and a
X * pointer to the global STATIC location for that variable.
X * String and char variables point to the same place as ht_value
X * and must be updated when ht_value changes, bit variables must
X * have their value recomputed. See Def_macro code for more
X * details.
X *
X * NOTE: Macro variables and Targets are always distinct. Thus
X * the value union contains pointers back at cells that own
X * a particular name entry. A conflict in this can never
X * arise, ie pointers at cells will never be used as
X * values for a macro variable, since the cell and macro
X * name spaces are completely distinct. */
X
X struct {
X int mv_mask; /* bit mask for bit variable */
X union {
X char** mv_svar;/* ptr to string valued glob var */
X char* mv_cvar;/* ptr to char valued glob var */
X uint16* mv_bvar;/* ptr to bit valued glob var */
X int* mv_ivar;/* ptr to int valued glob var */
X
X struct {
X struct tcell* ht_owner;/* ptr to CELL owning name */
X struct tcell* ht_root; /* rootdir ptr for hash */
X } ht;
X } val;
X } var; /* variable's static equivalent */
X} HASH, *HASHPTR;
X
X#define MV_MASK var.mv_mask
X#define MV_SVAR var.val.mv_svar
X#define MV_CVAR var.val.mv_cvar
X#define MV_BVAR var.val.mv_bvar
X#define MV_IVAR var.val.mv_ivar
X#define CP_OWNR var.val.ht.ht_owner
X#define CP_ROOT var.val.ht.ht_root
X
X
X
X/* This struct holds the list of temporary files that have been created.
SHAR_EOF
echo "End of part 3"
echo "File struct.h is continued in part 4"
echo "4" > s2_seq_.tmp
exit 0