.PHONY: depend cleandep

cce = gcc -E -MM -MT "$(@:d=o) $@"

# Copy all $(cc) commands w/ their targets from Makefile.mingw32, 3rd party code unnecessary
# Replace .o w/ .d, $(cc) w/ $(cce)
# Check extraordinary "OBJ): " and handle them properly
# Check all CLEAN_FILE lines, add obj files to $(OBJS4DEP)
# Run
# 	mingw32-make depend

$(OM)/%.d: $(SRC)/%.c $(NHLUAH) | $(OM)
	$(cce) $(CFLAGSU) -DENUM_PM $< -o$@

$(OM)/%.d: $(U)%.c $(NHLUAH) | $(OM)
	$(cce) $(CFLAGSU) -DENUM_PM $< -o$@

$(OR)/recover.d: $(U)recover.c | $(OR)
	$(cce) $(CFLAGSU) $< -o$@

$(OT)/tiletxt.d: $(WSHR)/tilemap.c $(NHLUAH) | $(OT)
	$(cce) $(CFLAGSU) -DTILETEXT $< -o$@

$(OT)/%.d: $(WSHR)/%.c $(NHLUAH) | $(OT)
	$(cce) $(CFLAGSU) $< -o$@

$(OT)/%.d: $(SRC)/%.c $(NHLUAH) | $(OT)
	$(cce) $(CFLAGSU) $< -o$@

$(OT)/tilete32.d: $(WSHR)/tiletext.c $(NHLUAH) | $(OT)
	$(cce) $(CFLAGSU) -DTILE_X=32 -DTILE_Y=32 $< -o$@

$(OT)/tiletx32.d: $(WSHR)/tilemap.c $(NHLUAH) | $(OT)
	$(cce) $(CFLAGSU) -DTILETEXT -DTILE_X=32 -DTILE_Y=32 $< -o$@

$(GIF32OBJ:o=d): $(WSHR)/gifread.c $(NHLUAH) | $(OT)
	$(cce) $(CFLAGSU) -DTILE_X=32 -DTILE_Y=32 $< -o$@

$(BMP32OBJ:o=d): $(WSHR)/tile2bmp.c $(NHLUAH) | $(OT)
	$(cce) $(CFLAGSU) -DTILE_X=32 -DTILE_Y=32 $< -o$@

$(OT)/panic.d: $(UTIL)/panic.c $(NHLUAH) | $(OT)
	$(cce) $(CFLAGSU) $< -o$@

$(OTM)/tilemap.d: $(WSHR)/tilemap.c $(NHLUAH) | $(OTM)
	$(cce) $(CFLAGSU) $< -o$@

$(OTM)/%.d: $(SRC)/%.c $(NHLUAH) | $(OTM)
	$(cce) $(CFLAGSU) $< -o$@

$(OU)/uudecode.d: $(SSYS)/uudecode.c | $(OU)
	$(cce) $(CFLAGS) $(CONSOLEDEF) $< -o$@

$(ODLB)/%.d: $(SRC)/%.c $(NHLUAH) | $(ODLB)
	$(cce) $(CFLAGSU) $< -o$@

$(ODLB)/%.d: $(U)%.c $(NHLUAH) | $(ODLB)
	$(cce) $(CFLAGSU) $< -o$@

$(ONHW)/%.d: $(SRC)/%.c $(NHLUAH) | $(ONHW)
	$(cce) $(CFLAGSW) $< -o$@

$(ONHW)/cppregex.d: $(SSYS)/cppregex.cpp $(NHLUAH) | $(ONHW)
	$(cce) $(CPPFLAGSW) $< -o$@

$(ONHW)/%.d: $(SSYS)/%.c $(NHLUAH) | $(ONHW)
	$(cce) $(CFLAGSW) $< -o$@

$(ONHW)/%.d: $(SNDSYS)/%.c $(NHLUAH) | $(ONHW)
	$(cce) $(CFLAGSW) $< -o$@

$(ONHW)/%.d: $(MSWSYS)/%.c $(NHLUAH) | $(ONHW)
	$(cce) $(CFLAGSW) $< -o$@

$(ONHW)/%.d: $(MSWIN)/%.c $(NHLUAH) | $(ONHW)
	$(cce) $(CFLAGSW) $< -o$@

$(ONHW)/%.d: $(WSHR)/%.c $(NHLUAH) | $(ONHW)
	$(cce) $(CFLAGSW) $< -o$@

$(ONH)/%.d: $(SRC)/%.c $(NHLUAH) | $(ONH)
	$(cce) $(CFLAGSNH) $< -o$@

$(ONH)/cppregex.d: $(SSYS)/cppregex.cpp $(NHLUAH) | $(ONH)
	$(cce) $(CPPFLAGSNH) $< -o$@

$(ONH)/%.d: $(SSYS)/%.c $(NHLUAH) | $(ONH)
	$(cce) $(CFLAGSNH) $< -o$@

$(ONH)/%.d: $(SNDSYS)/%.c $(NHLUAH) | $(ONH)
	$(cce) $(CFLAGSNH) $< -o$@

$(ONH)/%.d: $(MSWSYS)/%.c $(NHLUAH) | $(ONH)
	$(cce) $(CFLAGSNH) $< -o$@

$(ONH)/%.d: $(MSWIN)/%.c $(NHLUAH) | $(ONH)
	$(cce) $(CFLAGSNH) $< -o$@

$(ONH)/%.d: $(WSHR)/%.c $(NHLUAH) | $(ONH)
	$(cce) $(CFLAGSNH) $< -o$@

$(ONH)/%.d: $(TTY)/%.c $(NHLUAH) | $(ONH)
	$(cce) $(CFLAGSNH) $< -o$@

$(ONH)/%.d: $(WCURSES)/%.c $(NHLUAH) | $(ONH)
	$(cce) $(CFLAGSNH) $(PDCINCL) $< -o$@

OBJS4DEP = $(MOBJS) $(ROBJS) \
	   $(TOBJS) $(GIFOBJ) $(GIF32OBJ) $(PPMOBJ) $(BMP32OBJ) $(T32OBJS) $(TUCOMMON) \
	   $(TMOBJS) $(UOBJS) $(DLBOBJS) $(NHWOBJS) $(NHOBJS)
DEP_TARGETS = $(OBJS4DEP:o=d)

depend: fetchlua fetchpdcurses $(DEP_TARGETS)
	@cat $(DEP_TARGETS) > .depend

cleandep:
	@-rm -f $(DEP_TARGETS) .depend

clean: cleandep
# end of file
