# This is for GNU make; other versions of make may not run correctly.

MAIN_PROGRAM = hfviewer
SRC = main.c

include Makefile.defs

# object files
RELEASE_OBJ = $(patsubst %.c,obj/%.o,$(notdir $(SRC)))
DEBUG_OBJ = $(patsubst %.c,obj_debug/%.o,$(notdir $(SRC)))

# how to make the main target (debug mode, the default)
$(MAIN_PROGRAM): $(DEBUG_OBJ)
	$(LINK) $(DEBUG_LINKFLAGS) -o $@ $^ $(LINK_LIBS)

# how to make the main target (release mode)
$(MAIN_PROGRAM)_release: $(RELEASE_OBJ)
	$(LINK) $(RELEASE_LINKFLAGS) -o $@ $^ $(LINK_LIBS)

.PHONY: release
release: $(MAIN_PROGRAM)_release

.PHONY: debug
debug: $(MAIN_PROGRAM)

# how to compile each file
.SUFFIXES:
obj/%.o:
	$(CC) -c $(RELEASE_FLAGS) -o $@ $<
obj_debug/%.o:
	$(CC) -c $(DEBUG_FLAGS) -o $@ $<

# cleaning up
.PHONY: clean
clean:
	-rm -f obj/*.o $(MAIN_PROGRAM) obj_debug/*.o $(MAIN_PROGRAM)_release *core

# dependencies are automatically generated
.PHONY: depend
depend:
	-mkdir obj
	-rm -f obj/depend
	$(foreach srcfile,$(SRC),$(DEPEND) -I $(SIZZLE_DIR)/ -MM $(srcfile) -MT $(patsubst %.c,obj/%.o,$(notdir $(srcfile))) >> obj/depend;)
	-mkdir obj_debug
	-rm -f obj_debug/depend
	$(foreach srcfile,$(SRC),$(DEPEND) -I $(SIZZLE_DIR)/ -MM $(srcfile) -MT $(patsubst %.c,obj_debug/%.o,$(notdir $(srcfile))) >> obj_debug/depend;)

-include obj/depend
-include obj_debug/depend
