# TI-99/sim Makefile for Mac OS X

BIN_DIR   = appdir/bin
DATA_DIR  = appdir
SYS_BIN   = appdir/sbin
INSTALL   = /usr/bin/install

TARGETS   = \
	src/sdl/ti99sim-sdl \
	src/util/convert-ctg \
	src/util/decode \
	src/util/disk \
	src/util/dumpcpu \
	src/util/dumpgrom \
	src/util/dumpspch \
	src/util/list \
	src/util/mkspch \
	src/util/say \
	src/console/ti99sim-console

SRC_DIRS = \
	src/core \
	src/console \
	src/sdl \
	src/util

install: ti99sim
	@$(INSTALL) -d $(DATA_DIR)
	@$(INSTALL) -d $(DATA_DIR)/cartridges
	@$(INSTALL) -d $(DATA_DIR)/disks
	@$(INSTALL) -d $(DATA_DIR)/roms
	@$(INSTALL) -d $(BIN_DIR)
	@if [ -x src ]; then \
	  for target in $(TARGETS); do \
	    $(INSTALL) -s $$target $(BIN_DIR); \
	  done \
	else \
	  for target in $(notdir $(TARGETS)); do \
	    $(INSTALL) -s $$target $(BIN_DIR); \
	  done \
	fi 
	@for target in $(notdir $(TARGETS)); do \
	  ln -f -s $(BIN_DIR)/$$target $(SYS_BIN)/$$target; \
	done

uninstall:
	@for target in $(notdir $(TARGETS)); do \
	  rm -f $(BIN_DIR)/$$target; \
	  rm -f $(SYS_BIN)/$$target; \
	done

clean:
	@if [ -x src ]; then \
	  rm -f {.,include,doc}/*~; \
	  for dir in $(SRC_DIRS); do \
	    $(MAKE) -C $$dir clean; \
	  done \
	fi

dep:
	@if [ -x src ]; then \
	  for dir in $(SRC_DIRS); do \
	    $(MAKE) -C $$dir dep; \
	  done \
	fi

ti99sim:
	@if [ -x src ]; then \
	  if ! [ -r /usr/include/endian.h ]; then \
	    if [ -r /usr/include/machine/endian.h ]; then \
	      rm -f include/endian.h; \
	      ln -s /usr/include/machine/endian.h include/endian.h; \
	    fi \
	  fi; \
	  for dir in $(SRC_DIRS); do \
	    $(MAKE) -C $$dir; \
	  done \
	fi
