@@ -150,12 +150,20 @@ ifneq (,$(MAKECMDGOALS))
150
150
endif
151
151
endif
152
152
153
+ .SHELLSTATUS ?= 0
154
+
153
155
ifeq ($(SETUP_PREREQS ) ,1)
154
156
# If set on: Default target or a rule requiring a scan
155
157
# Forcibly execute `make tools` since we need them for what we are doing.
156
- $(call infoshell, $(MAKE) -f make_tools.mk)
158
+ $(foreach line, $(shell $(MAKE) -f make_tools.mk | sed "s/ /__SPACE__/g"), $(info $(subst __SPACE__, ,$(line))))
159
+ ifneq ($(.SHELLSTATUS),0)
160
+ $(error Errors occurred while building tools. See error messages above for more details)
161
+ endif
157
162
# Oh and also generate mapjson sources before we use `SCANINC`.
158
- $(call infoshell, $(MAKE) generated)
163
+ $(foreach line, $(shell $(MAKE) generated | sed "s/ /__SPACE__/g"), $(info $(subst __SPACE__, ,$(line))))
164
+ ifneq ($(.SHELLSTATUS),0)
165
+ $(error Errors occurred while generating map-related sources. See error messages above for more details)
166
+ endif
159
167
endif
160
168
161
169
# Collect sources
@@ -237,7 +245,10 @@ include spritesheet_rules.mk
237
245
include json_data_rules.mk
238
246
include audio_rules.mk
239
247
248
+ # NOTE: Tools must have been built prior (FIXME)
249
+ # so you can't really call this rule directly
240
250
generated : $(AUTO_GEN_TARGETS )
251
+ @: # Silence the "Nothing to be done for `generated'" message, which some people were confusing for an error.
241
252
242
253
% .s : ;
243
254
% .png : ;
@@ -252,8 +263,6 @@ generated: $(AUTO_GEN_TARGETS)
252
263
% .lz : % ; $(GFX ) $< $@
253
264
% .rl : % ; $(GFX ) $< $@
254
265
255
- # NOTE: Tools must have been built prior (FIXME)
256
- generated : tools $(AUTO_GEN_TARGETS )
257
266
clean-generated :
258
267
-rm -f $(AUTO_GEN_TARGETS )
259
268
@@ -287,71 +296,52 @@ endif
287
296
# As a side effect, they're evaluated immediately instead of when the rule is invoked.
288
297
# It doesn't look like $(shell) can be deferred so there might not be a better way (Icedude_907: there is soon).
289
298
290
- # For C dependencies.
291
- # Args: $1 = Output file without extension (build/assets/src/data), $2 = Input file (src/data.c)
292
- define C_DEP
293
- $(call C_DEP_IMPL,$1,$2,$1)
294
- endef
295
- # Internal implementation details.
296
- # $1: Output file without extension, $2 input file, $3 temp path (if keeping)
297
- define C_DEP_IMPL
298
- $1.o: $2
299
+ $(C_BUILDDIR ) /% .o : $(C_SUBDIR ) /% .c
299
300
ifneq ($(KEEP_TEMPS ) ,1)
300
- @echo "$$ (CC1) <flags> -o $$@ $ $<"
301
- @$$ (CPP) $$ (CPPFLAGS) $$ < | $$ (PREPROC) -i $$ < charmap.txt | $$ (CC1) $$ (CFLAGS) -o - - | cat - <(echo -e ".text\n\t.align\t2, 0") | $$ (AS) $$ (ASFLAGS) -o $ $@ -
301
+ @echo "$(CC1) <flags> -o $@ $<"
302
+ @$(CPP) $(CPPFLAGS) $< | $(PREPROC) -i $< charmap.txt | $(CC1) $(CFLAGS) -o - - | cat - <(echo -e ".text\n\t.align\t2, 0") | $(AS) $(ASFLAGS) -o $@ -
302
303
else
303
- @$$ (CPP) $$ (CPPFLAGS) $$ < -o $3 .i
304
- @$$ (PREPROC) $3 .i charmap.txt | $$ (CC1) $$ (CFLAGS) -o $3 .s
305
- @echo -e ".text\n\t.align\t2, 0 @ Don't pad with nop \n" >> $3 .s
306
- $$ (AS) $$ (ASFLAGS) -o $$ @ $3 .s
304
+ @$(CPP) $(CPPFLAGS) $< -o $* .i
305
+ @$(PREPROC) $* .i charmap.txt | $(CC1) $(CFLAGS) -o $* .s
306
+ @echo -e ".text\n\t.align\t2, 0\n" >> $* .s
307
+ $(AS) $(ASFLAGS) -o $@ $* .s
307
308
endif
308
- $1.d: $2
309
- $(SCANINC ) -M $1.d $(INCLUDE_SCANINC_ARGS ) -I tools/agbcc/include $2
309
+
310
+ $(C_BUILDDIR ) /% .d : $(C_SUBDIR ) /% .c
311
+ $(SCANINC ) -M $@ $(INCLUDE_SCANINC_ARGS ) -I tools/agbcc/include $<
312
+
310
313
ifneq ($(NODEP ) ,1)
311
- $1.o : $1.d
312
- -include $1.d
314
+ -include $(addprefix $(OBJ_DIR ) /,$(C_SRCS :.c=.d))
313
315
endif
314
- endef
315
316
316
- # Create generic rules if no dependency scanning, else create the real rules
317
- ifeq ($(NODEP ) ,1)
318
- $(eval $(call C_DEP,$(C_BUILDDIR)/%,$(C_SUBDIR)/%.c))
319
- else
320
- $(foreach src,$(C_SRCS),$(eval $(call C_DEP,$(OBJ_DIR)/$(basename $(src)),$(src))))
317
+ $(ASM_BUILDDIR ) /% .o : $(ASM_SUBDIR ) /% .s
318
+ $(AS ) $(ASFLAGS ) -o $@ $<
319
+
320
+ $(ASM_BUILDDIR ) /% .d : $(ASM_SUBDIR ) /% .s
321
+ $(SCANINC ) -M $@ $(INCLUDE_SCANINC_ARGS ) -I " " $<
322
+
323
+ ifneq ($(NODEP ) ,1)
324
+ -include $(addprefix $(OBJ_DIR ) /,$(ASM_SRCS :.s=.d))
321
325
endif
322
326
323
- # Similar methodology for Assembly files
324
- # $1: Output path without extension, $2: Input file (`*.s`)
325
- define ASM_DEP
326
- $1.o: $2
327
- $$(AS ) $$(ASFLAGS ) -o $$@ $$<
328
- $(call ASM_SCANINC,$1,$2)
329
- endef
330
- # As above but first doing a preprocessor pass
331
- define ASM_DEP_PREPROC
332
- $1.o: $2
333
- $$(PREPROC ) $$< charmap.txt | $$(CPP ) $(INCLUDE_SCANINC_ARGS ) - | $$(PREPROC ) -ie $$< charmap.txt | $$(AS ) $$(ASFLAGS ) -o $$@
334
- $(call ASM_SCANINC,$1,$2)
335
- endef
336
-
337
- define ASM_SCANINC
327
+ $(C_BUILDDIR ) /% .o : $(C_SUBDIR ) /% .s
328
+ $(PREPROC ) $< charmap.txt | $(CPP ) $(INCLUDE_SCANINC_ARGS ) - | $(PREPROC ) -ie $< charmap.txt | $(AS ) $(ASFLAGS ) -o $@
329
+
330
+ $(C_BUILDDIR ) /% .d : $(C_SUBDIR ) /% .s
331
+ $(SCANINC ) -M $@ $(INCLUDE_SCANINC_ARGS ) -I " " $<
332
+
338
333
ifneq ($(NODEP ) ,1)
339
- $1.o : $1.d
340
- $1.d : $2
341
- $(SCANINC ) -M $1 .d $(INCLUDE_SCANINC_ARGS ) -I " " $2
342
- -include $1.d
334
+ -include $(addprefix $(OBJ_DIR ) /,$(C_ASM_SRCS :.s=.d))
343
335
endif
344
- endef
345
336
346
- # Dummy rules or real rules
347
- ifeq ($(NODEP ) ,1)
348
- $(eval $(call ASM_DEP,$(ASM_BUILDDIR)/%,$(ASM_SUBDIR)/%.s))
349
- $(eval $(call ASM_DEP_PREPROC,$(C_BUILDDIR)/%,$(C_SUBDIR)/%.s))
350
- $(eval $(call ASM_DEP_PREPROC,$(DATA_ASM_BUILDDIR)/%,$(DATA_ASM_SUBDIR)/%.s))
351
- else
352
- $(foreach src, $(ASM_SRCS ) , $(eval $(call ASM_DEP,$(src :% .s=$(OBJ_DIR ) /% ),$(src ) )))
353
- $(foreach src, $(C_ASM_SRCS ) , $(eval $(call ASM_DEP_PREPROC,$(src :% .s=$(OBJ_DIR ) /% ),$(src ) )))
354
- $(foreach src, $(REGULAR_DATA_ASM_SRCS ) , $(eval $(call ASM_DEP_PREPROC,$(src :% .s=$(OBJ_DIR ) /% ),$(src ) )))
337
+ $(DATA_ASM_BUILDDIR ) /% .o : $(DATA_ASM_SUBDIR ) /% .s
338
+ $(PREPROC ) $< charmap.txt | $(CPP ) $(INCLUDE_SCANINC_ARGS ) - | $(PREPROC ) -ie $< charmap.txt | $(AS ) $(ASFLAGS ) -o $@
339
+
340
+ $(DATA_ASM_BUILDDIR ) /% .d : $(DATA_ASM_SUBDIR ) /% .s
341
+ $(SCANINC ) -M $@ $(INCLUDE_SCANINC_ARGS ) -I " " $<
342
+
343
+ ifneq ($(NODEP ) ,1)
344
+ -include $(addprefix $(OBJ_DIR ) /,$(REGULAR_DATA_ASM_SRCS :.s=.d))
355
345
endif
356
346
357
347
$(OBJ_DIR ) /sym_bss.ld : sym_bss.txt
@@ -375,8 +365,10 @@ endif
375
365
# Final rules
376
366
377
367
# Elf from object files
368
+ LDFLAGS = -Map ../../$(MAP )
378
369
$(ELF ) : $(LD_SCRIPT ) $(LD_SCRIPT_DEPS ) $(OBJS )
379
370
@cd $(OBJ_DIR ) && $(LD ) $(LDFLAGS ) -T ../../$< --print-memory-usage -o ../../$@ $(OBJS_REL ) $(LIB ) | cat
371
+ @echo " cd $( OBJ_DIR) && $( LD) $( LDFLAGS) -T ../../$< --print-memory-usage -o ../../$@ <objs> <libs> | cat"
380
372
$(FIX ) $@ -t" $( TITLE) " -c$(GAME_CODE ) -m$(MAKER_CODE ) -r$(GAME_REVISION ) --silent
381
373
382
374
# Builds the rom from the elf file
0 commit comments