# Make everything
.PHONY: all
all:
	$(MAKE) -C debug_lib_src
	$(MAKE) -C arm7
	$(MAKE) -C arm9
	$(MAKE) -C monitor

.PNOHY: clean
clean:
	$(MAKE) -C debug_lib_src clean
	$(MAKE) -C arm7 clean
	$(MAKE) -C arm9 clean
	$(MAKE) -C monitor clean

# Make the TAGS file
.PHONY: TAGS
TAGS:
	etags -i $(DEVKITPRO)/libnds-src/TAGS $(shell find . -name '*.[ch]')


# Make a tarball
the_pwd = $(shell pwd)
this_dir = $(notdir $(the_pwd))
above_dir = $(dir $(the_pwd))
tar_file = $(this_dir).tar.bz2

found_source_files = $(shell find . -name *.[ch])
found_asm_files = $(shell find . -name *.asm)
found_make_files = $(shell find . -name Makefile)
found_make_other_files = $(shell find . -name Makefile.*)
found_text_files = $(shell find . -iname *.txt)
found_bmp_files = $(shell find . -iname *.bmp)
found_lib_files = $(shell find libs -name *.a)
found_ld_files = $(shell find . -name *.ld)
found_specs_files = $(shell find . -name *.specs)

temp_files_for_tar = $(found_source_files) $(found_asm_files) \
	$(found_make_files) $(found_make_other_files) \
	$(found_text_files) $(found_bmp_files) \
	$(found_lib_files) $(found_ld_files) $(found_specs_files)
files_for_tar = $(subst ./,,$(temp_files_for_tar))

.PHONY : tarball
tarball :
	cd $(above_dir); \
	tar --create --bzip2 --dereference --file $(the_pwd)/$(tar_file) \
		$(addprefix $(this_dir)/,$(files_for_tar))
