Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

470 lines
17 KiB

  1. // NMAKE.H -- main header file
  2. //
  3. // Copyright (c) 1988-1990, Microsoft Corporation. All rights reserved.
  4. //
  5. // Purpose:
  6. // This file is the main header file for NMAKE and contains global typedef and
  7. // macros. Global constants are also defined here. Global data is in global.h
  8. //
  9. // Revision History:
  10. // 01-Feb-1994 HV Move messages to external file.
  11. // 15-Nov-1993 JdR Major speed improvements
  12. // 15-Oct-1993 HV Use tchar.h instead of mbstring.h directly, change STR*() to _ftcs*()
  13. // 23-Jun-1993 HV Kill the near keyword
  14. // 01-Jun-1993 HV Change #ifdef KANJI to _MBCS
  15. // 10-May-1993 HV Add _MBCS version of the string library.
  16. // 10-Jul-1992 SB Port to NTMIPS
  17. // 08-Jun-1992 SS Port to DOSX32
  18. // 02-Feb-1990 SB add definition of FILEOPEN
  19. // 04-Dec-1989 SB Changed definition of PFV to have prototype of function
  20. // which it dereferences
  21. // 01-Dec-1989 SB Contains an hack #ifdef'ed for Overlayed version
  22. // also defined REALLOC
  23. // 22-Nov-1989 SB #define FREE
  24. // 13-Nov-1989 SB Definitions CCHMAXPATH(COMP) conform with bsedos.h
  25. // 02-Oct-1989 SB added support for dynamic inline files
  26. // 14-Sep-1989 SB added inLines field to block
  27. // 04-Sep-1989 SB Added M_COMMAND_LINE but not used
  28. // 24-Aug-1989 SB Add A_DEPENDENT for NMAKE to know that it is to look for a
  29. // dependent
  30. // 16-May-1989 SB NOLOGO flag /L set up for passing to recursive builds
  31. // 24-Apr-1989 SB added CCHMAXPATH & CCHMAXPATHCOMP for OS/2 ver 1.2 support
  32. // & removed FILEINFO typedef's (not needed anymore)
  33. // 22-Feb-1989 SB changed value of MAXCMDLINELENGTH to 2k
  34. // 03-Feb-1989 SB Added struct for FILEINFO for OS2 ver 1.2
  35. // 02-Feb-1989 SB Redefined SPAWNV(P) and SYSTEM as NMAKE was really not
  36. // supporting KANJI
  37. // 31-Jan-1989 SB Changed MAXNAME to 257 for OS2 Ver 1.2 support
  38. // 21-Dec-1988 SB Added SCRIPTLIST and makeNewScriptListElement() to allow
  39. // multiple script fileseach with its KEEP/NOKEEP action
  40. // 06-Dec-1988 SB Updated Comment about bits corr to flags set
  41. // 05-Dec-1988 SB Added #define CDECL; NMAKE now uses Pascal Calling
  42. // Add SIG_IGN to handle compiler problem
  43. // 30-Nov-1988 SB Added suppport for 'z' option in setFlags()
  44. // 23-Nov-1988 SB Defined MAXCMDLINELENGTH for extmake syntax
  45. // 10-Nov-1988 SB Changed BOOL as 'unsigned short' as in 'os2.h'
  46. // 17-Aug-1988 RB Clean up.
  47. // 14-Jul-1988 rj Added dateTime to BUILDBLOCK def to support multiple
  48. // targets with the same command block.
  49. // 07-Jul-1988 rj Added targetFlag parameter to findMacro, findTarget
  50. // 15-Jun-1988 rj Add definition of EScapeCHaracter.
  51. // 25-May-1988 rb Clean up definition of LOCAL.
  52. // Better char-type defs for ECS.
  53. // Include from the LANGAPI (shared components) project
  54. #include <assert.h>
  55. #include <direct.h>
  56. #include <dos.h>
  57. #include <errno.h>
  58. #include <io.h>
  59. #include <limits.h>
  60. #include <malloc.h>
  61. #include <mbctype.h>
  62. #include <process.h>
  63. #include <share.h>
  64. #include <signal.h>
  65. #include <stdarg.h>
  66. #include <stdio.h>
  67. #include <stdlib.h>
  68. #include <tchar.h>
  69. #include "getmsg.h"
  70. #define STRICT
  71. #define NOMINMAX // windef.h
  72. #define NOGDI // wingdi.h
  73. #define NOIME // ime.h
  74. #define NOUSER // winuser.h
  75. #define NOHELP
  76. #define NOPROFILER
  77. #define NOSYSPARAMSINFO
  78. #define NONLS // winnls.h
  79. #define NOSERVICE // winsvc.h
  80. #include <windows.h>
  81. #define FILEOPEN open_file
  82. #define FREE_STRINGLIST free_stringlist
  83. #define ALLOC_STRINGLIST(type) (STRINGLIST *)alloc_stringlist()
  84. #define FREE free
  85. #define REALLOC realloc
  86. typedef char CHAR;
  87. typedef unsigned char UCHAR;
  88. typedef unsigned short USHORT;
  89. typedef unsigned long ULONG;
  90. #define NMHANDLE INT_PTR
  91. typedef void (*PFV) (void); // pointer to void function
  92. // size constants for buffers
  93. //
  94. // I impose an arbitrary limit of 128 bytes for a macro or target name.
  95. // This should be much larger than any intelligent user would need.
  96. // The value of a macro can be longer -- up to MAXBUF in length.
  97. //
  98. // The hash table for macros was only 64 pointers long. That seemed a
  99. // reasonable number, since most makefiles have fewer than 64 variables
  100. // defined. Measurements on real makefiles (P1) showed that we had almost
  101. // 8 elements per chain, so it was increased to 256 on FLAT architectures.
  102. // The hashing algorithm isn't perfect, but it should be good
  103. // enough. Even if the macro we're looking up is in a bucket w/ more
  104. // than one entry, we'll only have to chain one or two links down the
  105. // list to find it. When we add macros a bucket's list we prepend them,
  106. // so we don't have to chain at all there.
  107. #define MAXNAME 257
  108. #define MAXMACRO 256
  109. #define MAXTARGET 128
  110. #define MAXBUF 1024
  111. #define MAXSEGMENT 65535
  112. #define MAXARG MAXNAME / 2 - 1
  113. #define CHUNKSIZE 8
  114. #define MAXCMDLINELENGTH 8192
  115. // constants used by error.c
  116. //
  117. // error numbers are of the form Unxxx, where the 'U' stands for utility,
  118. // n is the 1st digit of one of the values below indicating the type of
  119. // error, and xxx is the number of the error (error messages aren't in any
  120. // order right now -- related ones should probably be grouped together
  121. // when all error messages have been added)
  122. #define FATAL_ERR 1000
  123. #define NONFATAL_ERR 2000
  124. #define WARNING_ERR 4000
  125. // other constants
  126. #define WRITE 2 // READ,WRITE,APPEND used by
  127. #define APPEND 3 // redirect() in build.c
  128. #define READ 4 // also value for access()
  129. #define ESCH '^' // general escape character
  130. typedef struct INCLUDEINFO
  131. {
  132. unsigned line;
  133. char *name;
  134. FILE *file;
  135. } INCLUDEINFO;
  136. #define MAXINCLUDE 16
  137. // STRINGLIST structure is used to construct lists that keep track of the
  138. // makefiles to read, the targets to update, the dependency list for each
  139. // target, the list of build commands for each target, and the values
  140. // for a macro.
  141. typedef struct strlist {
  142. struct strlist *next;
  143. char *text;
  144. } STRINGLIST;
  145. typedef struct inlinelist {
  146. struct inlinelist *next;
  147. char *text;
  148. char *name;
  149. BOOL fKeep;
  150. unsigned size;
  151. } INLINELIST;
  152. typedef struct scrptlist { // List used to handle multiple
  153. struct scrptlist *next; // scriptfiles
  154. char *sFile; // -- Script file name & its
  155. BOOL fKeep; // -- keep status (default nokeep)
  156. } SCRIPTLIST;
  157. typedef struct BLOCK {
  158. STRINGLIST *dependents; // dependents of the target
  159. STRINGLIST *dependentMacros; //
  160. STRINGLIST *buildCommands; // command list to build target
  161. STRINGLIST *buildMacros;
  162. UCHAR flags;
  163. time_t dateTime;
  164. } BUILDBLOCK;
  165. typedef struct bldlist {
  166. struct bldlist *next;
  167. BUILDBLOCK *buildBlock;
  168. } BUILDLIST;
  169. typedef struct BATCH { // State info for deferred batch commands
  170. struct BATCH *next;
  171. struct RULE *pRule; // batch inference rule
  172. UCHAR flags; // build flags
  173. STRINGLIST *nameList; // list of names to be "touched" (nmake -t)
  174. STRINGLIST *dollarLt; // list for constructing batch $<
  175. } BATCHLIST;
  176. typedef struct OBJECT {
  177. struct OBJECT *next;
  178. char *name;
  179. UCHAR flags2;
  180. UCHAR flags3;
  181. time_t dateTime;
  182. BUILDLIST *buildList;
  183. BATCHLIST **ppBatch; // batch list that contains this object,
  184. // if being built in batch-mode
  185. } MAKEOBJECT;
  186. typedef struct iobject { // used for dependents NOT in
  187. struct object *next; // the makefile. We add them
  188. char *name; // to the target table w/ a
  189. UCHAR flags2; // flag that says "already
  190. UCHAR flags3; // built" and then we never
  191. long datetime; // have to time-stamp again
  192. } IMPLIEDOBJECT;
  193. typedef struct RULE {
  194. struct RULE *next;
  195. struct RULE *back; // doubly-link rules for ease
  196. char *name; // in sorting later . . .
  197. STRINGLIST *buildCommands; // (# of rules is mostly small
  198. STRINGLIST *buildMacros; // so not much memory used
  199. BOOL fBatch; // TRUE if batch rule (doublecolon)
  200. } RULELIST;
  201. typedef struct deplist {
  202. struct deplist *next;
  203. char *name;
  204. time_t depTime;
  205. } DEPLIST;
  206. // Bits in flags/gFlags indicate which cmdline options are set
  207. //
  208. // -a sets FORCE_BUILD
  209. // -c sets CRYPTIC_OUTPUT (only fatal errors get displayed)
  210. // -d sets DISPLAY_FILE_DATES
  211. // -e sets USE_ENVIRON_VARS
  212. // -i sets IGNORE_EXIT_CODES
  213. // -n sets NO_EXECUTE
  214. // -p sets PRINT_INFORMATION
  215. // -q sets QUESTION_STATUS
  216. // -r sets IGNORE_EXTERN_RULES
  217. // -s sets NO_ECHO
  218. // -t sets TOUCH_TARGETS
  219. // -z sets REVERSE_BATCH_FILE (Required by PWB)
  220. // -l sets NO_LOGO (internally /l actually -nologo)
  221. //
  222. // Also included are bits for
  223. //
  224. // BUILDING_THIS_ONE - to detect cycles in dependencies
  225. // DOUBLECOLON - to indicate type of separator found between
  226. // the targets and dependencies (':' or '::')
  227. // ALREADY_BUILT - to indicate that a target has been built
  228. // OUT_OF_DATE - to indicate that this target is out of date
  229. #define F1_PRINT_INFORMATION 0x01 // "global" flags that affect
  230. #define F1_IGNORE_EXTERN_RULES 0x02 // all targets (it doesn't
  231. #define F1_USE_ENVIRON_VARS 0x04 // make sense to allow the
  232. #define F1_QUESTION_STATUS 0x08 // user to change these)
  233. #define F1_TOUCH_TARGETS 0x10
  234. #define F1_CRYPTIC_OUTPUT 0x20
  235. #define F1_NO_BATCH 0x40 // disable batching functionality
  236. #define F1_NO_LOGO 0x80
  237. #define F2_DISPLAY_FILE_DATES 0x01 // these are resettable w/in
  238. #define F2_IGNORE_EXIT_CODES 0x02 // the makefile
  239. #define F2_NO_EXECUTE 0x04 // each target keeps own copy
  240. #define F2_NO_ECHO 0x08
  241. #define F2_FORCE_BUILD 0x10 // build even if up-to-date
  242. #define F2_DOUBLECOLON 0x20 // indicates separator type
  243. #define F2_DUMP_INLINE 0x40 // dump inline files
  244. #define F3_BUILDING_THIS_ONE 0x01 // finds cyclical dependencies
  245. #define F3_ALREADY_BUILT 0x02
  246. #define F3_OUT_OF_DATE 0x04 // reuse :: bit after target
  247. // has been built
  248. #define F3_ERROR_IN_CHILD 0x08 // used to implement slash k
  249. // ----------------------------------------------------------------------------
  250. // MACRODEF structure is used to make a list of macro definitions from the
  251. // commandline, makefile, TOOLS.INI file, and environment. It contains
  252. // a flag which is set for macros defined in the command line so that
  253. // a later definition of the same macro will be ignored. It also contains
  254. // a flag that gets set when NMAKE is expanding the macro so that recursive
  255. // definitions can be detected.
  256. ///
  257. typedef struct macro {
  258. struct macro *next;
  259. char *name;
  260. STRINGLIST *values; // can just be list of size 1
  261. UCHAR flags;
  262. } MACRODEF;
  263. // Bits in flags field for macros. We really only need to know if a macro
  264. // was defined on the commandline (in which case we ignore all redefinitions),
  265. // or if we're currently expanding macros in its value (so when we look
  266. // up a macro and that bit is set we can tell that the macro is defined
  267. // recursively).
  268. #define M_EXPANDING_THIS_ONE 0x01
  269. #define M_NON_RESETTABLE 0x02
  270. #define M_ENVIRONMENT_DEF 0x04
  271. #define M_WARN_IF_RESET 0x08
  272. #define M_UNDEFINED 0x10
  273. #define M_COMMAND_LINE 0x20
  274. #define M_LITERAL 0x40 // value contains no other macros
  275. // treat $ literary
  276. // macros to simplify dealing w/ bits in flags, allocating memory, and
  277. // testing characters
  278. #define SET(A,B) ((A) |= (UCHAR)(B)) // turn bit B on in A
  279. #define CLEAR(A,B) ((A) &= (UCHAR)(~B)) // turn bit B off in A
  280. #define ON(A,B) ((A) & (UCHAR)(B)) // is bit B on in A?
  281. #define OFF(A,B) (!ON(A,B)) // is bit B off in A?
  282. #define FLIP(A,B) (ON(A,B)) ? (CLEAR(A,B)) : (SET(A,B))
  283. #define CANT_REDEFINE(A) (ON((A)->flags,M_NON_RESETTABLE) \
  284. || (ON(gFlags,F1_USE_ENVIRON_VARS) \
  285. && ON((A)->flags,M_ENVIRONMENT_DEF)))
  286. #define ALLOCATE_OBJECT(type) ((type *) allocate(sizeof(type)))
  287. #define makeNewStrListElement() ALLOC_STRINGLIST(STRINGLIST)
  288. #define makeNewInlineListElement() ALLOCATE_OBJECT(INLINELIST)
  289. #define makeNewScriptListElement() ALLOCATE_OBJECT(SCRIPTLIST)
  290. #define makeNewMacro() ALLOCATE_OBJECT(MACRODEF)
  291. #define makeNewObject() ALLOCATE_OBJECT(MAKEOBJECT)
  292. #define makeNewImpliedObject() ALLOCATE_OBJECT(MAKEOBJECT)
  293. #define makeNewBuildBlock() ALLOCATE_OBJECT(BUILDBLOCK)
  294. #define makeNewBldListElement() ALLOCATE_OBJECT(BUILDLIST)
  295. #define makeNewRule() ALLOCATE_OBJECT(RULELIST)
  296. #define MakeNewDepListElement() ALLOCATE_OBJECT(DEPLIST)
  297. #define makeNewBatchListElement() ALLOCATE_OBJECT(BATCHLIST)
  298. #define WHITESPACE(A) ((A) == ' ' || (A) == '\t')
  299. #if 1 //JdR see charmap.h
  300. // #define MACRO_CHAR(A) IS_MACROCHAR(A)
  301. // Modified MACRO_CHAR to fix handling of mbcs characters.
  302. // 'A' may combine the bytes of the mbcs char in a single value and
  303. // end up being >= 256. All values >=128 can be treated as
  304. // valid macro characters [vc98 #9973 georgiop 9/19/97]
  305. #define MACRO_CHAR(A) (IS_MACROCHAR(A) || ((unsigned)(A)) >= 128)
  306. #else
  307. #define MACRO_CHAR(A) ((A) == '_' || _istalnum(A) || ((unsigned)(A)) >= 128)
  308. #endif
  309. #define PATH_SEPARATOR(A) ((A) == '\\' || (A) == '/')
  310. #define DYNAMIC_DEP(A) ((A)[2] == '(' \
  311. && (A)[3] == '@' \
  312. && (A)[5] == ')' \
  313. && (((A)[4] == 'F' \
  314. || (A)[4] == 'D' \
  315. || (A)[4] == 'B' \
  316. || (A)[4] == 'R')))
  317. // values passed to getSpecialValue() to indicate which type of macro
  318. // we're expanding
  319. #define SPECIAL_MACRO 0x01 // $* $@ $? $< $**
  320. #define DYNAMIC_MACRO 0x02 // $$@
  321. #define X_SPECIAL_MACRO 0x03 // $(*F) $(@D) etc.
  322. #define X_DYNAMIC_MACRO 0x04 // $$(@F) $$(@D)
  323. #define DOLLAR_MACRO 0x05 // $$ -> $
  324. // Bits in elements placed in the stack (ifStack) that keeps state
  325. // information about if/else/endif directives. Here "if" directive
  326. // includes if/ifdef/ifndef/if defined().
  327. // -- used in routine lgetc() in ifexpr.c
  328. #define NMIFELSE 0x01 // set for if/ifdef etc...reset for else
  329. #define NMCONDITION 0x02 // set if condition part of if is true
  330. #define NMIGNORE 0x04 // set if if/endif block is to be ignored/skipped
  331. #define NMELSEIF 0x08 // set for else if/ifdef etc...reset for else
  332. // Values to record which of if/ifdef/ifndef/etc was seen to decide
  333. // the kind of processing to be done.
  334. #define IF_TYPE 0x01
  335. #define ELSE_TYPE 0x02
  336. #define ELSE_IF_TYPE 0x03
  337. #define ELSE_IFDEF_TYPE 0x04
  338. #define ELSE_IFNDEF_TYPE 0x05
  339. #define IFDEF_TYPE 0x06
  340. #define IFNDEF_TYPE 0x07
  341. #define ENDIF_TYPE 0x08
  342. // Values to indicate if we are reading from the raw stream or thru'
  343. // the routine lgetc() which preprocesses directives. These are used
  344. // by a routine common to lgetc() module and the lexer.
  345. #define FROMLOCAL 0x00
  346. #define FROMSTREAM 0x01
  347. // macros to simplify accessing hash tables
  348. // find() returns a STRINGLIST pointer, which is then cast to a pointer
  349. // of the appropriate structure type
  350. #define findTarget(A) (MAKEOBJECT*) find(A, MAXTARGET, \
  351. (STRINGLIST**)targetTable, \
  352. (BOOL)TRUE)
  353. // "action" flags for building target-table entries
  354. // if any of the bits in A_SUFFIX to A_RULE is set, the action routines
  355. // WON'T build a targetblock for the current target (really pseudotarget
  356. // or rule)
  357. // A_TARGET says expand names on input (dependent names get expanded when
  358. // target is built) */
  359. #define A_SUFFIX 0x01
  360. #define A_SILENT 0x02
  361. #define A_IGNORE 0x04
  362. #define A_PRECIOUS 0x08
  363. #define A_RULE 0x10
  364. #define A_TARGET 0x20
  365. #define A_STRING 0x40
  366. #define A_DEPENDENT 0x80
  367. // "build" flags used by recursive target-building function
  368. #define B_COMMANDS 0x01
  369. #define B_BUILD 0x02
  370. #define B_INMAKEFILE 0x04
  371. #define B_NOTARGET 0x08
  372. #define B_ADDDEPENDENT 0x10
  373. #define B_DOUBLECOLON 0x20
  374. #define B_DEP_OUT_OF_DATE 0x40
  375. // "command" flags used by doCommand function
  376. #define C_SILENT 0x01
  377. #define C_IGNORE 0x02
  378. #define C_ITERATE 0x04
  379. #define C_EXECUTE 0x08
  380. #define C_EXPANDED 0x10
  381. // keyword for better profiling, normally set to "static".
  382. #ifndef LOCAL
  383. #define LOCAL static
  384. #endif
  385. // GetTxtChr and UngetTxtChr are the MBCS counterparts of getc and ungetc.
  386. #ifdef _MBCS
  387. extern int GetTxtChr(FILE*);
  388. extern int UngetTxtChr(int, FILE*);
  389. #else
  390. #define GetTxtChr(a) getc(a)
  391. #define UngetTxtChr(c,f) ungetc(c,f)
  392. #endif
  393. #define strend(p) (p + _tcslen(p))
  394. #include "charmap.h"