Browse Source

Improved building of debugging objects. You can now specify a "DEBUG="

list for any build, e.g.
  make bin/pnic.dsk DEBUG=pci,pnic
This will drag in debugging-enabled versions of pci.c and pnic.c.
tags/v0.9.3
Michael Brown 19 years ago
parent
commit
a666eb34b5
2 changed files with 38 additions and 16 deletions
  1. 11
    5
      src/Makefile
  2. 27
    11
      src/Makefile.housekeeping

+ 11
- 5
src/Makefile View File

@@ -96,12 +96,15 @@ LDFLAGS		+= $(EXTRA_LDFLAGS)
96 96
 CFLAGS_c	+= 
97 97
 CFLAGS_S 	+= -DASSEMBLY
98 98
 
99
+# Base object name of the current target
100
+#
101
+OBJECT		= $(firstword $(subst ., ,$(@F)))
102
+
99 103
 # CFLAGS for specific object files.  You can define
100 104
 # e.g. CFLAGS_rtl8139, and have those flags automatically used when
101 105
 # compiling bin/rtl8139.o.
102 106
 #
103
-OBJ_CFLAGS	= $(CFLAGS_$(basename $(@F))) \
104
-		  -DOBJECT=$(subst -,_,$(basename $(@F)))
107
+OBJ_CFLAGS	= $(CFLAGS_$(OBJECT)) -DOBJECT=$(subst -,_,$(OBJECT))
105 108
 $(BIN)/%.flags :
106 109
 	@echo $(OBJ_CFLAGS)
107 110
 
@@ -109,24 +112,27 @@ $(BIN)/%.flags :
109 112
 #
110 113
 COMPILE_c	= $(CC) $(CFLAGS) $(CFLAGS_c) $(OBJ_CFLAGS)
111 114
 RULE_c		= $(COMPILE_c) -c $< -o $@
112
-RULE_c_to_s	= $(COMPILE_c) -S -c $< -o $@ 
115
+RULE_c_to_dbg.o	= $(COMPILE_c) -DDEBUG_$(OBJECT) -c $< -o $@
113 116
 RULE_c_to_c	= $(COMPILE_c) -E -c $< > $@
117
+RULE_c_to_s	= $(COMPILE_c) -S -c $< -o $@ 
114 118
 
115 119
 PREPROCESS_S	= $(CPP) $(CFLAGS) $(CFLAGS_S) $(OBJ_CFLAGS)
116 120
 ASSEMBLE_S	= $(AS) $(ASFLAGS)
117 121
 RULE_S		= $(PREPROCESS_S) $< | $(ASSEMBLE_S) -o $@
118 122
 RULE_S_to_s	= $(PREPROCESS_S) $< > $@
119 123
 
120
-DEBUG_TARGETS	+= c s
124
+DEBUG_TARGETS	+= dbg.o c s
121 125
 
122 126
 # SRCDIRS lists all directories containing source files.
123 127
 #
124
-SRCDIRS		+= core drivers/net drivers/disk
128
+SRCDIRS		+= core drivers/bus drivers/net
129
+# drivers/disk
125 130
 
126 131
 # NON_AUTO_SRCS lists files that are excluded from the normal
127 132
 # automatic build system.
128 133
 #
129 134
 NON_AUTO_SRCS	+= core/elf_loader.c
135
+NON_AUTO_SRCS	+= drivers/net/prism2.c
130 136
 
131 137
 # Rules for finalising files.  TGT_MAKEROM_FLAGS is defined as part of
132 138
 # the automatic build system and varies by target; it includes the

+ 27
- 11
src/Makefile.housekeeping View File

@@ -111,7 +111,8 @@ define obj_template
111 111
 		 $(foreach TGT,$(DEBUG_TARGETS), \
112 112
 		    $(if $(RULE_$(3)_to_$(TGT)), \
113 113
 		    '\n$$(BIN)/$(4).$(TGT) : $(1) $$(MAKEDEPS) $$($(4)_DEPS)' \
114
-		    '\n\t$$(RULE_$(3)_to_$(TGT))\n' ) ) \
114
+		    '\n\t$$(RULE_$(3)_to_$(TGT))\n' \
115
+		    '\n$(TGT)_OBJS += $$(BIN)/$(4).$(TGT)\n' ) ) \
115 116
 		 '\n$(2) : $$($(4)_DEPS)\n' \
116 117
 		 '\nTAGS : $$($(4)_DEPS)\n' \
117 118
 		>> $(2)
@@ -222,6 +223,15 @@ TGT_LD_FLAGS	= $(foreach SYM,$(TGT_LD_PREFIX) $(TGT_LD_DRIVERS) obj_config,\
222 223
 TGT_MAKEROM_FLAGS = $(strip $(MAKEROM_FLAGS_$(TGT_ROM_NAME)) \
223 224
        $(if $(TGT_PCI_VENDOR),$(strip -p $(TGT_PCI_VENDOR),$(TGT_PCI_DEVICE))))
224 225
 
226
+# Calculate list of debugging versions of objects to be included in
227
+# the target.
228
+#
229
+COMMA		:= ,
230
+DEBUG_OBJECTS	= $(foreach D,$(subst $(COMMA), ,$(DEBUG)),$(BIN)/$(D).dbg.o)
231
+$(foreach OBJ,$(filter-out $(dbg.o_OBJS),$(DEBUG_OBJECTS)), \
232
+	$(error $(OBJ) is not a valid debug object) \
233
+)
234
+
225 235
 # Print out all derived information for a given target.
226 236
 #
227 237
 $(BIN)/%.info :
@@ -242,13 +252,25 @@ $(BIN)/%.info :
242 252
 	@echo 'LD target flags      : $(TGT_LD_FLAGS)'
243 253
 	@echo
244 254
 	@echo 'makerom target flags : $(TGT_MAKEROM_FLAGS)'
255
+	@echo
256
+	@echo 'Debugging objects    : $(DEBUG_OBJECTS)'
245 257
 
246 258
 # Build an intermediate object file from the objects required for the
247 259
 # specified target.
248
-#
249
-$(BIN)/%.tmp : $(BLIB) $(MAKEDEPS) $(LDSCRIPT)
250
-	$(LD) $(LDFLAGS) -T $(LDSCRIPT) $(TGT_LD_FLAGS) $< -o $@ \
251
-		-Map $(BIN)/$*.tmp.map
260
+# 
261
+# If it's a debugging version, force a link to take place by making
262
+# this target depend on a phony target, and mark the resulting files
263
+# as being older than BLIB, so that any subsequent images will do a
264
+# fresh link.  Otherwise, you won't get what you expect when you do
265
+# e.g. "make DEBUG=pci bin/pnic.dsk ; make bin/pnic.dsk ; make
266
+# DEBUG=pci bin/pnic.dsk"
267
+#
268
+$(BIN)/%.tmp : $(BLIB) $(MAKEDEPS) $(LDSCRIPT) \
269
+	       $(DEBUG_OBJECTS) $(if $(DEBUG),force_relink)
270
+	$(LD) $(LDFLAGS) -T $(LDSCRIPT) $(TGT_LD_FLAGS) \
271
+		$(DEBUG_OBJECTS) $(BLIB) -o $@ -Map $(BIN)/$*.tmp.map
272
+	$(if $(DEBUG_OBJECTS),$(TOUCH) -r $(BLIB) -B 2 $@ $(BIN)/$*.tmp.map)
273
+.PHONY : force_relink
252 274
 
253 275
 # Show a linker map for the specified target
254 276
 #
@@ -376,12 +398,6 @@ $(BIN)/%.rebuild :
376 398
 	rm -f $(BIN)/$*
377 399
 	$(MAKE) $(MAKEFLAGS) $(BIN)/$*
378 400
 
379
-# Build a debugging version of an object
380
-#
381
-$(BIN)/%.o.dbg :
382
-	rm -f $(BIN)/$*.o
383
-	$(MAKE) $(MAKEFLAGS) EXTRA_CFLAGS+=-Ddebug_$* $(BIN)/$*.o
384
-
385 401
 # Clean-up
386 402
 #
387 403
 clean :

Loading…
Cancel
Save