summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMichael Brown2014-06-16 17:28:20 +0200
committerMichael Brown2014-06-16 17:53:26 +0200
commit13a74e0d27a6b4781cca4646642e635cbbc94796 (patch)
tree1c43f8027d936824069458fcc7bdd94863d9d839 /src
parent[build] Check if git index actually exists (diff)
downloadipxe-13a74e0d27a6b4781cca4646642e635cbbc94796.tar.gz
ipxe-13a74e0d27a6b4781cca4646642e635cbbc94796.tar.xz
ipxe-13a74e0d27a6b4781cca4646642e635cbbc94796.zip
[debug] Allow debug message colours to be customised via DBGCOL=...
When multiple iPXE binaries are running concurrently (e.g. in the case of undionly.kpxe using an underlying iPXE driver via the UNDI interface) it would be helpful to be able to visually distinguish debug messages from each binary. Allow the range of debug colours used to be customised via the DBGCOL=... build parameter. For example: # Restrict to colours 31-33 (red, green, yellow) make DBGCOL=31-33 # Restrict to colours 34-36 (blue, magenta, cyan) make DBGCOL=34-36 Signed-off-by: Michael Brown <mcb30@ipxe.org>
Diffstat (limited to 'src')
-rw-r--r--src/Makefile.housekeeping25
-rw-r--r--src/core/debug.c17
2 files changed, 39 insertions, 3 deletions
diff --git a/src/Makefile.housekeeping b/src/Makefile.housekeeping
index f7755369..e40e7132 100644
--- a/src/Makefile.housekeeping
+++ b/src/Makefile.housekeeping
@@ -710,6 +710,31 @@ $(BIN)/version.o : ../.git/index
endif
endif
+# Debug message autocolourisation range
+#
+DBGCOL_LIST := $(BIN)/.dbgcol.list
+ifeq ($(wildcard $(DBGCOL_LIST)),)
+DBGCOL_OLD := <invalid>
+else
+DBGCOL_OLD := $(shell cat $(DBGCOL_LIST))
+endif
+ifneq ($(DBGCOL_OLD),$(DBGCOL))
+$(shell $(ECHO) "$(DBGCOL)" > $(DBGCOL_LIST))
+endif
+
+$(DBGCOL_LIST) : $(MAKEDEPS)
+
+VERYCLEANUP += $(DBGCOL_LIST)
+
+DBGCOL_COLOURS := $(subst -, ,$(DBGCOL))
+DBGCOL_MIN := $(word 1,$(DBGCOL_COLOURS))
+DBGCOL_MAX := $(word 2,$(DBGCOL_COLOURS))
+
+debug_DEPS += $(DBGCOL_LIST)
+
+CFLAGS_debug += $(if $(DBGCOL_MIN),-DDBGCOL_MIN=$(DBGCOL_MIN))
+CFLAGS_debug += $(if $(DBGCOL_MAX),-DDBGCOL_MAX=$(DBGCOL_MAX))
+
# We automatically generate rules for any file mentioned in AUTO_SRCS
# using the following set of templates. We use $(eval ...) if
# available, otherwise we generate separate Makefile fragments and
diff --git a/src/core/debug.c b/src/core/debug.c
index 2161f973..7ded4708 100644
--- a/src/core/debug.c
+++ b/src/core/debug.c
@@ -119,13 +119,24 @@ void dbg_hex_dump_da ( unsigned long dispaddr, const void *data,
}
/**
+ * Base message stream colour
+ *
+ * We default to using 31 (red foreground) as the base colour.
+ */
+#ifndef DBGCOL_MIN
+#define DBGCOL_MIN 31
+#endif
+
+/**
* Maximum number of separately coloured message streams
*
* Six is the realistic maximum; there are 8 basic ANSI colours, one
* of which will be the terminal default and one of which will be
* invisible on the terminal because it matches the background colour.
*/
-#define NUM_AUTO_COLOURS 6
+#ifndef DBGCOL_MAX
+#define DBGCOL_MAX ( DBGCOL_MIN + 6 - 1 )
+#endif
/** A colour assigned to an autocolourised debug message stream */
struct autocolour {
@@ -142,7 +153,7 @@ struct autocolour {
* @ret colour Colour ID
*/
static int dbg_autocolour ( unsigned long stream ) {
- static struct autocolour acs[NUM_AUTO_COLOURS];
+ static struct autocolour acs[ DBGCOL_MAX - DBGCOL_MIN + 1 ];
static unsigned long use;
unsigned int i;
unsigned int oldest;
@@ -180,7 +191,7 @@ static int dbg_autocolour ( unsigned long stream ) {
*/
void dbg_autocolourise ( unsigned long stream ) {
dbg_printf ( "\033[%dm",
- ( stream ? ( 31 + dbg_autocolour ( stream ) ) : 0 ) );
+ ( stream ? ( DBGCOL_MIN + dbg_autocolour ( stream ) ) :0));
}
/**