[9] | 1 | /*************************************************************************
|
---|
| 2 | *
|
---|
| 3 | * m a k e : h . h
|
---|
| 4 | *
|
---|
| 5 | * include file for make
|
---|
| 6 | *========================================================================
|
---|
| 7 | * Edition history
|
---|
| 8 | *
|
---|
| 9 | * # Date Comments By
|
---|
| 10 | * --- -------- ---------------------------------------------------- ---
|
---|
| 11 | * 1 ?? ??
|
---|
| 12 | * 2 23.08.89 LZ increased,N_EXISTS added,suffix as macro added RAL
|
---|
| 13 | * 3 30.08.89 macro flags added, indention changed PSH,RAL
|
---|
| 14 | * 4 03.09.89 fixed LZ eliminated, struct str added,... RAL
|
---|
| 15 | * 5 06.09.89 TABCHAR,M_MAKE added RAL
|
---|
| 16 | * 6 09.09.89 tos support added, EXTERN,INIT,PARMS added PHH,RAL
|
---|
| 17 | * 7 17.09.89 __STDC__ added, make1 decl. fixed , N_EXEC added RAL
|
---|
| 18 | * ------------ Version 2.0 released ------------------------------- RAL
|
---|
| 19 | *
|
---|
| 20 | *************************************************************************/
|
---|
| 21 |
|
---|
| 22 | #ifdef unix
|
---|
| 23 | #include <sys/types.h>
|
---|
| 24 | #include <sys/stat.h>
|
---|
| 25 | #include <errno.h>
|
---|
| 26 | #include <stdlib.h>
|
---|
| 27 | #include <string.h>
|
---|
| 28 | #include <time.h>
|
---|
| 29 | #include <utime.h>
|
---|
| 30 | #include <stdio.h>
|
---|
| 31 | #include <limits.h>
|
---|
| 32 | #endif
|
---|
| 33 |
|
---|
| 34 | #ifdef eon
|
---|
| 35 | #include <sys/stat.h>
|
---|
| 36 | #include <sys/err.h>
|
---|
| 37 | #endif
|
---|
| 38 |
|
---|
| 39 | #ifdef os9
|
---|
| 40 | #include <time.h>
|
---|
| 41 | #include <os9.h>
|
---|
| 42 | #include <modes.h>
|
---|
| 43 | #include <direct.h>
|
---|
| 44 | #include <errno.h>
|
---|
| 45 | #endif
|
---|
| 46 |
|
---|
| 47 | #ifdef tos
|
---|
| 48 | struct DOSTIME {short time,date; }; /* time structure of TOS */
|
---|
| 49 |
|
---|
| 50 | #ifdef LATTICE
|
---|
| 51 | #include <error.h>
|
---|
| 52 | #include <sys/types.h>
|
---|
| 53 | #include <sys/stat.h>
|
---|
| 54 | #include <osbind.h>
|
---|
| 55 | #endif /* LATTICE */
|
---|
| 56 |
|
---|
| 57 | #ifdef TURBO
|
---|
| 58 | #include <tos.h>
|
---|
| 59 | #include <errno.h>
|
---|
| 60 | #include <string.h>
|
---|
| 61 | #endif /* TURBO */
|
---|
| 62 |
|
---|
| 63 | #endif /* tos */
|
---|
| 64 |
|
---|
| 65 | #include <ctype.h>
|
---|
| 66 | #include <stdio.h>
|
---|
| 67 | #include <assert.h>
|
---|
| 68 |
|
---|
| 69 | #ifdef eon
|
---|
| 70 | #define MNOENT ER_NOTF
|
---|
| 71 | #else
|
---|
| 72 | #define MNOENT ENOENT
|
---|
| 73 | #endif
|
---|
| 74 |
|
---|
| 75 | #ifndef uchar
|
---|
| 76 | #ifdef os9
|
---|
| 77 | #define uchar char
|
---|
| 78 | #define void int
|
---|
| 79 | #define fputc putc
|
---|
| 80 | #else
|
---|
| 81 | #define uchar unsigned char
|
---|
| 82 | #endif
|
---|
| 83 | #endif
|
---|
| 84 |
|
---|
| 85 | #define bool uchar
|
---|
| 86 | #ifndef time_t
|
---|
| 87 | #define time_t long
|
---|
| 88 | #endif
|
---|
| 89 | #define TRUE (1)
|
---|
| 90 | #define FALSE (0)
|
---|
| 91 | #define max(a,b) ((a)>(b)?(a):(b))
|
---|
| 92 |
|
---|
| 93 | #ifdef unix
|
---|
| 94 | #define DEFN1 "makefile"
|
---|
| 95 | #define DEFN2 "Makefile"
|
---|
| 96 | #endif
|
---|
| 97 | #ifdef eon
|
---|
| 98 | #define DEFN1 "makefile"
|
---|
| 99 | #define DEFN2 "Makefile"
|
---|
| 100 | #endif
|
---|
| 101 | #ifdef tos
|
---|
| 102 | #define DEFN1 "makefile."
|
---|
| 103 | #define DEFN2 (char *)0
|
---|
| 104 | #endif
|
---|
| 105 | #ifdef os9
|
---|
| 106 | #define DEFN1 "makefile"
|
---|
| 107 | #define DEFN2 (char *)0
|
---|
| 108 | #endif
|
---|
| 109 |
|
---|
| 110 |
|
---|
| 111 | #ifdef os9
|
---|
| 112 | #define TABCHAR ' '
|
---|
| 113 | #else
|
---|
| 114 | #define TABCHAR '\t'
|
---|
| 115 | #endif
|
---|
| 116 |
|
---|
| 117 | #define LZ1 (2048) /* Initial input/expand string size */
|
---|
| 118 | #define LZ2 (256) /* Initial input/expand string size */
|
---|
| 119 |
|
---|
| 120 |
|
---|
| 121 |
|
---|
| 122 | /*
|
---|
| 123 | * A name. This represents a file, either to be made, or existant
|
---|
| 124 | */
|
---|
| 125 |
|
---|
| 126 | struct name
|
---|
| 127 | {
|
---|
| 128 | struct name *n_next; /* Next in the list of names */
|
---|
| 129 | char *n_name; /* Called */
|
---|
| 130 | struct line *n_line; /* Dependencies */
|
---|
| 131 | time_t n_time; /* Modify time of this name */
|
---|
| 132 | uchar n_flag; /* Info about the name */
|
---|
| 133 | };
|
---|
| 134 |
|
---|
| 135 | #define N_MARK 0x01 /* For cycle check */
|
---|
| 136 | #define N_DONE 0x02 /* Name looked at */
|
---|
| 137 | #define N_TARG 0x04 /* Name is a target */
|
---|
| 138 | #define N_PREC 0x08 /* Target is precious */
|
---|
| 139 | #define N_DOUBLE 0x10 /* Double colon target */
|
---|
| 140 | #define N_EXISTS 0x20 /* File exists */
|
---|
| 141 | #define N_ERROR 0x40 /* Error occured */
|
---|
| 142 | #define N_EXEC 0x80 /* Commands executed */
|
---|
| 143 |
|
---|
| 144 | /*
|
---|
| 145 | * Definition of a target line.
|
---|
| 146 | */
|
---|
| 147 | struct line
|
---|
| 148 | {
|
---|
| 149 | struct line *l_next; /* Next line (for ::) */
|
---|
| 150 | struct depend *l_dep; /* Dependents for this line */
|
---|
| 151 | struct cmd *l_cmd; /* Commands for this line */
|
---|
| 152 | };
|
---|
| 153 |
|
---|
| 154 |
|
---|
| 155 | /*
|
---|
| 156 | * List of dependents for a line
|
---|
| 157 | */
|
---|
| 158 | struct depend
|
---|
| 159 | {
|
---|
| 160 | struct depend *d_next; /* Next dependent */
|
---|
| 161 | struct name *d_name; /* Name of dependent */
|
---|
| 162 | };
|
---|
| 163 |
|
---|
| 164 |
|
---|
| 165 | /*
|
---|
| 166 | * Commands for a line
|
---|
| 167 | */
|
---|
| 168 | struct cmd
|
---|
| 169 | {
|
---|
| 170 | struct cmd *c_next; /* Next command line */
|
---|
| 171 | char *c_cmd; /* Command line */
|
---|
| 172 | };
|
---|
| 173 |
|
---|
| 174 |
|
---|
| 175 | /*
|
---|
| 176 | * Macro storage
|
---|
| 177 | */
|
---|
| 178 | struct macro
|
---|
| 179 | {
|
---|
| 180 | struct macro *m_next; /* Next variable */
|
---|
| 181 | char *m_name; /* Called ... */
|
---|
| 182 | char *m_val; /* Its value */
|
---|
| 183 | uchar m_flag; /* Infinite loop check */
|
---|
| 184 | };
|
---|
| 185 |
|
---|
| 186 |
|
---|
| 187 | #define M_MARK 0x01 /* for infinite loop check */
|
---|
| 188 | #define M_OVERRIDE 0x02 /* command-line override */
|
---|
| 189 | #define M_MAKE 0x04 /* for MAKE macro */
|
---|
| 190 |
|
---|
| 191 | /*
|
---|
| 192 | * String
|
---|
| 193 | */
|
---|
| 194 | struct str
|
---|
| 195 | {
|
---|
| 196 | char **ptr; /* ptr to real ptr. to string */
|
---|
| 197 | int len; /* length of string */
|
---|
| 198 | int pos; /* position */
|
---|
| 199 | };
|
---|
| 200 |
|
---|
| 201 |
|
---|
| 202 | /* Declaration, definition & initialization of variables */
|
---|
| 203 |
|
---|
| 204 | #ifndef EXTERN
|
---|
| 205 | #define EXTERN extern
|
---|
| 206 | #endif
|
---|
| 207 |
|
---|
| 208 | #ifndef INIT
|
---|
| 209 | #define INIT(x)
|
---|
| 210 | #endif
|
---|
| 211 |
|
---|
| 212 | extern int errno;
|
---|
| 213 | extern char **environ;
|
---|
| 214 |
|
---|
| 215 | EXTERN char *myname;
|
---|
| 216 | EXTERN bool domake INIT(TRUE); /* Go through the motions option */
|
---|
| 217 | EXTERN bool ignore INIT(FALSE); /* Ignore exit status option */
|
---|
| 218 | EXTERN bool conterr INIT(FALSE); /* continue on errors */
|
---|
| 219 | EXTERN bool silent INIT(FALSE); /* Silent option */
|
---|
| 220 | EXTERN bool print INIT(FALSE); /* Print debuging information */
|
---|
| 221 | EXTERN bool rules INIT(TRUE); /* Use inbuilt rules */
|
---|
| 222 | EXTERN bool dotouch INIT(FALSE); /* Touch files instead of making */
|
---|
| 223 | EXTERN bool quest INIT(FALSE); /* Question up-to-dateness of file */
|
---|
| 224 | EXTERN bool useenv INIT(FALSE); /* Env. macro def. overwrite makefile def.*/
|
---|
| 225 | EXTERN bool dbginfo INIT(FALSE); /* Print lot of debugging information */
|
---|
| 226 | EXTERN bool ambigmac INIT(TRUE); /* guess undef. ambiguous macros (*,<) */
|
---|
| 227 | EXTERN struct name *firstname;
|
---|
| 228 | EXTERN char *str1;
|
---|
| 229 | EXTERN char *str2;
|
---|
| 230 | EXTERN struct str str1s;
|
---|
| 231 | EXTERN struct str str2s;
|
---|
| 232 | EXTERN struct name **suffparray; /* ptr. to array of ptrs. to name chains */
|
---|
| 233 | EXTERN int sizesuffarray INIT(20); /* size of suffarray */
|
---|
| 234 | EXTERN int maxsuffarray INIT(0); /* last used entry in suffarray */
|
---|
| 235 | EXTERN struct macro *macrohead;
|
---|
| 236 | EXTERN bool expmake; /* TRUE if $(MAKE) has been expanded */
|
---|
| 237 | EXTERN char *makefile; /* The make file */
|
---|
| 238 | EXTERN int lineno;
|
---|
| 239 |
|
---|
| 240 | #ifdef tos
|
---|
| 241 | #ifdef LATTICE
|
---|
| 242 | EXTERN int _mneed INIT(60000); /* VERY important for TOS with LATTICE C*/
|
---|
| 243 | #endif /* LATTICE */
|
---|
| 244 | #endif /* tos */
|
---|
| 245 | #ifdef eon
|
---|
| 246 | #define MEMSPACE (16384)
|
---|
| 247 | EXTERN unsigned memspace = MEMSPACE;
|
---|
| 248 | #endif
|
---|
| 249 |
|
---|
| 250 | #define suffix(name) strrchr(name,(int)'.')
|
---|
| 251 |
|
---|
| 252 | EXTERN int _ctypech;
|
---|
| 253 | #define mylower(x) (islower(_ctypech=(x)) ? _ctypech :tolower(_ctypech))
|
---|
| 254 | #define myupper(x) (isupper(_ctypech=(x)) ? _ctypech :toupper(_ctypech))
|
---|
| 255 |
|
---|
| 256 | /* Prototypes. */
|
---|
| 257 | struct sgtbuf;
|
---|
| 258 |
|
---|
| 259 | /* check.c */
|
---|
| 260 | _PROTOTYPE(void prt, (void));
|
---|
| 261 | _PROTOTYPE(void check, (struct name *np ));
|
---|
| 262 | _PROTOTYPE(void circh, (void));
|
---|
| 263 | _PROTOTYPE(void precious, (void));
|
---|
| 264 |
|
---|
| 265 | /* input.c */
|
---|
| 266 | _PROTOTYPE(void init, (void));
|
---|
| 267 | _PROTOTYPE(void strrealloc, (struct str *strs ));
|
---|
| 268 | _PROTOTYPE(struct name *newname, (char *name ));
|
---|
| 269 | _PROTOTYPE(struct name *testname, (char *name ));
|
---|
| 270 | _PROTOTYPE(struct depend *newdep, (struct name *np, struct depend *dp ));
|
---|
| 271 | _PROTOTYPE(struct cmd *newcmd, (char *str, struct cmd *cp ));
|
---|
| 272 | _PROTOTYPE(void newline, (struct name *np, struct depend *dp, struct cmd *cp,
|
---|
| 273 | int flag ));
|
---|
| 274 | _PROTOTYPE(void input, (FILE *fd ));
|
---|
| 275 |
|
---|
| 276 | /* macro.c */
|
---|
| 277 | _PROTOTYPE(struct macro *getmp, (char *name ));
|
---|
| 278 | _PROTOTYPE(char *getmacro, (char *name ));
|
---|
| 279 | _PROTOTYPE(struct macro *setmacro, (char *name, char *val ));
|
---|
| 280 | _PROTOTYPE(void setDFmacro, (char *name, char *val ));
|
---|
| 281 | _PROTOTYPE(void doexp, (struct str *to, char *from ));
|
---|
| 282 | _PROTOTYPE(void expand, (struct str *strs ));
|
---|
| 283 |
|
---|
| 284 | /* main.c */
|
---|
| 285 | _PROTOTYPE(void main, (int argc, char **argv ));
|
---|
| 286 | _PROTOTYPE(void setoption, (char option ));
|
---|
| 287 | _PROTOTYPE(void usage, (void));
|
---|
| 288 | _PROTOTYPE(void fatal, (char *msg, char *a1, int a2 ));
|
---|
| 289 |
|
---|
| 290 | /* make.c */
|
---|
| 291 | _PROTOTYPE(int dosh, (char *string, char *shell ));
|
---|
| 292 | _PROTOTYPE(int makeold, (char *name ));
|
---|
| 293 | _PROTOTYPE(void docmds1, (struct name *np, struct line *lp ));
|
---|
| 294 | _PROTOTYPE(void docmds, (struct name *np ));
|
---|
| 295 | _PROTOTYPE(int Tosexec, (char *string ));
|
---|
| 296 | _PROTOTYPE(time_t mstonix, (unsigned int date, unsigned int time ));
|
---|
| 297 | _PROTOTYPE(void getmdate, (int fd, struct sgtbuf *tbp ));
|
---|
| 298 | _PROTOTYPE(time_t cnvtime, (struct sgtbuf *tbp ));
|
---|
| 299 | _PROTOTYPE(void modtime, (struct name *np ));
|
---|
| 300 | _PROTOTYPE(void touch, (struct name *np ));
|
---|
| 301 | _PROTOTYPE(int make, (struct name *np, int level ));
|
---|
| 302 | _PROTOTYPE(void make1, (struct name *np, struct line *lp, struct depend *qdp,
|
---|
| 303 | char *basename, char *inputname ));
|
---|
| 304 | _PROTOTYPE(void implmacros, (struct name *np, struct line *lp,
|
---|
| 305 | char **pbasename, char **pinputname ));
|
---|
| 306 | _PROTOTYPE(void dbgprint, (int level, struct name *np, char *comment ));
|
---|
| 307 |
|
---|
| 308 | /* reader.c */
|
---|
| 309 | _PROTOTYPE(void error, (char *msg, char *a1 ));
|
---|
| 310 | _PROTOTYPE(bool getline, (struct str *strs, FILE *fd ));
|
---|
| 311 | _PROTOTYPE(char *gettok, (char **ptr ));
|
---|
| 312 |
|
---|
| 313 | /* rules.c */
|
---|
| 314 | _PROTOTYPE(bool dyndep, (struct name *np, char **pbasename,char **pinputname));
|
---|
| 315 | _PROTOTYPE(void makerules, (void));
|
---|
| 316 |
|
---|
| 317 | /* archive.c */
|
---|
| 318 | _PROTOTYPE(int is_archive_ref, (char *name));
|
---|
| 319 | _PROTOTYPE(int archive_stat, (char *name, struct stat *stp));
|
---|