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

+ 27
- 11
src/Makefile.housekeeping View File

111
 		 $(foreach TGT,$(DEBUG_TARGETS), \
111
 		 $(foreach TGT,$(DEBUG_TARGETS), \
112
 		    $(if $(RULE_$(3)_to_$(TGT)), \
112
 		    $(if $(RULE_$(3)_to_$(TGT)), \
113
 		    '\n$$(BIN)/$(4).$(TGT) : $(1) $$(MAKEDEPS) $$($(4)_DEPS)' \
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
 		 '\n$(2) : $$($(4)_DEPS)\n' \
116
 		 '\n$(2) : $$($(4)_DEPS)\n' \
116
 		 '\nTAGS : $$($(4)_DEPS)\n' \
117
 		 '\nTAGS : $$($(4)_DEPS)\n' \
117
 		>> $(2)
118
 		>> $(2)
222
 TGT_MAKEROM_FLAGS = $(strip $(MAKEROM_FLAGS_$(TGT_ROM_NAME)) \
223
 TGT_MAKEROM_FLAGS = $(strip $(MAKEROM_FLAGS_$(TGT_ROM_NAME)) \
223
        $(if $(TGT_PCI_VENDOR),$(strip -p $(TGT_PCI_VENDOR),$(TGT_PCI_DEVICE))))
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
 # Print out all derived information for a given target.
235
 # Print out all derived information for a given target.
226
 #
236
 #
227
 $(BIN)/%.info :
237
 $(BIN)/%.info :
242
 	@echo 'LD target flags      : $(TGT_LD_FLAGS)'
252
 	@echo 'LD target flags      : $(TGT_LD_FLAGS)'
243
 	@echo
253
 	@echo
244
 	@echo 'makerom target flags : $(TGT_MAKEROM_FLAGS)'
254
 	@echo 'makerom target flags : $(TGT_MAKEROM_FLAGS)'
255
+	@echo
256
+	@echo 'Debugging objects    : $(DEBUG_OBJECTS)'
245
 
257
 
246
 # Build an intermediate object file from the objects required for the
258
 # Build an intermediate object file from the objects required for the
247
 # specified target.
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
 # Show a linker map for the specified target
275
 # Show a linker map for the specified target
254
 #
276
 #
376
 	rm -f $(BIN)/$*
398
 	rm -f $(BIN)/$*
377
 	$(MAKE) $(MAKEFLAGS) $(BIN)/$*
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
 # Clean-up
401
 # Clean-up
386
 #
402
 #
387
 clean :
403
 clean :

Loading…
Cancel
Save