Have you definitely done a clean after modifying your makefile? There aren't any left over .o files anywhere?
When I wanted to add assembly files to my project I found that the gcc assembler was just not useable. I used vasm instead and named the files I wanted it to assemble with a different suffix so that I could create a separate process within the makefile for them. Then you're free to do what you want without breaking any existing stuff.
Edit: I see you need -xassembler-with-cpp. My solution won't work for you if this is the case, unless you can break that into a separate step.
Edit 2: How do you stop it from trying to assemble the generated a.mingw.s file? Also, are you on the latest preview version of the vscode extension?
Edit 3: This works for me, apart from that pesky a.mingw.s, using the latest preview extension. I've added a test.s file with one test function included. Not an exhaustive test, but no errors. I would still recommend adding in vasm instead though.
Code:
# to generate assembler listing with LTO, add to LDFLAGS: -Wa,-adhln=$@.listing,--listing-rhs-width=200
# for better annotations add -dA -dP
# to generate assembler source with LTO, add to LDFLAGS: -save-temps=cwd
forward-to-backward = $(subst /,\,$1)
subdirs := $(wildcard */)
VPATH = $(subdirs)
cpp_sources := $(wildcard *.cpp) $(wildcard $(addsuffix *.cpp,$(subdirs)))
cpp_objects := $(addprefix obj/,$(patsubst %.cpp,%.o,$(notdir $(cpp_sources))))
c_sources := $(wildcard *.c) $(wildcard $(addsuffix *.c,$(subdirs)))
c_objects := $(addprefix obj/,$(patsubst %.c,%.o,$(notdir $(c_sources))))
s_sources := $(wildcard *.s) $(wildcard $(addsuffix *.s,$(subdirs)))
s_objects := $(addprefix obj/,$(patsubst %.s,%.o,$(notdir $(s_sources))))
objects := $(cpp_objects) $(c_objects) $(s_objects)
# https://stackoverflow.com/questions/4036191/sources-from-subdirectories-in-makefile/4038459
# http://www.microhowto.info/howto/automatically_generate_makefile_dependencies.html
OUT = a.mingw
CC = m68k-amiga-elf-gcc
CCFLAGS = -g -MP -MMD -m68000 -Ofast -nostdlib -Wextra -Wno-unused-function -Wno-volatile-register-var -fomit-frame-pointer -fno-tree-loop-distribution -flto -fwhole-program -fno-exceptions
ASFLAGS = -Wa,-g,--register-prefix-optional
LDFLAGS = -Wl,--emit-relocs,-Ttext=0,-Map=$(OUT).map
all: $(OUT).exe
$(OUT).exe: $(OUT).elf
$(info Elf2Hunk $(OUT).exe)
@elf2hunk $(OUT).elf $(OUT).exe
$(OUT).elf: $(objects)
$(info Linking a.mingw.elf)
@$(CC) $(CCFLAGS) $(LDFLAGS) $(objects) -o $@
@m68k-amiga-elf-objdump --disassemble --no-show-raw-ins --visualize-jumps -S $@ >$(OUT).s
clean:
$(info Cleaning...)
@del /q obj $(OUT).* 2>nul || rmdir obj 2>nul || ver>nul
-include $(objects:.o=.d)
$(cpp_objects) : obj/%.o : %.cpp
@if not exist "$(call forward-to-backward,$(dir $@))" mkdir $(call forward-to-backward,$(dir $@))
$(info Compiling $<)
@$(CC) $(CCFLAGS) -c -o $@ $(CURDIR)/$<
$(c_objects) : obj/%.o : %.c
@if not exist "$(call forward-to-backward,$(dir $@))" mkdir $(call forward-to-backward,$(dir $@))
$(info Compiling $<)
@$(CC) $(CCFLAGS) -c -o $@ $(CURDIR)/$<
$(s_objects): obj/%.o : %.s
$(info Assembling $<)
@$(CC) $(CCFLAGS) $(ASFLAGS) -c -o $@ $(CURDIR)/$<
Edit 4: changing the m68k-amiga-elf-objdump line that creates a.mingw.s to create a .txt file instead doesn't seem to break anything.