From de7a7fe271ed487714b928589fd459b24b4ac598 Mon Sep 17 00:00:00 2001
From: uz <uz@b7a2c559-68d2-44c3-8de9-860c34a00d81>
Date: Mon, 28 Sep 2009 15:31:03 +0000
Subject: [PATCH] New version by Greg King.

git-svn-id: svn://svn.cc65.org/cc65/trunk@4254 b7a2c559-68d2-44c3-8de9-860c34a00d81
---
 make/gcc.mak | 123 ++++++++++++++++++++++++++++++---------------------
 1 file changed, 73 insertions(+), 50 deletions(-)

diff --git a/make/gcc.mak b/make/gcc.mak
index 2c41415d7..5ae2eb854 100644
--- a/make/gcc.mak
+++ b/make/gcc.mak
@@ -6,12 +6,13 @@
 
 # Goals that are supported by the cc65 package
 .PHONY:	all bins libs docs samples tests clean zap
-.PHONY:	uninstall install install-bins install-libs install-docs
+.PHONY:	uninstall install install-bins install-libs install-docs install-samps
 
 # If SYS is defined on this makefile's command-line, then we want it to go
 # to "samples" and "tests", but not to the other rules.  So, we disable a
 # feature of GNU make that would have given ${SYS} to every sub-make.
-MAKEOVERRIDES=
+#MAKEOVERRIDES=
+# (That trick has been disabled.)
 
 # The install prefix and directories
 prefix		= /usr/local
@@ -22,12 +23,14 @@ datadir		= $(prefix)/share
 docdir		= $(datadir)/doc
 libdir		= $(exec_prefix)/lib
 
-CC65DATA	= $(libdir)/cc65
-CC65DOC		= $(docdir)/cc65
+CC65_DOC	= $(docdir)/cc65
+CC65_HOME	= $(libdir)/cc65
 
-CC65ASM		= $(CC65DATA)/asminc
-CC65INC		= $(CC65DATA)/include
-CC65LIB		= $(CC65DATA)/lib
+CA65_INC	= $(CC65_HOME)/asminc
+CC65_INC	= $(CC65_HOME)/include
+LD65_CFG	= $(CC65_HOME)/cfg
+LD65_LIB	= $(CC65_HOME)/lib
+LD65_OBJ	= $(CC65_HOME)/obj
 
 # Programs
 
@@ -55,7 +58,9 @@ endif
 all:	bins libs docs $(SYS:%=samples tests)
 
 bins:
-	@$(MAKE) -C src -f make/gcc.mak CC65_INC=\\\"${CC65INC}/\\\" CC65_LIB=\\\"${CC65LIB}/\\\"
+	@$(MAKE) -C src -f make/gcc.mak CA65_INC=\\\"${CA65_INC}/\\\" \
+	  CC65_INC=\\\"${CC65_INC}/\\\" LD65_CFG=\\\"${LD65_CFG}/\\\" \
+	  LD65_LIB=\\\"${LD65_LIB}/\\\" LD65_OBJ=\\\"${LD65_OBJ}/\\\"
 
 libs:
 	@$(MAKE) -C libsrc
@@ -78,23 +83,29 @@ tests:
 	-@$(MAKE) -k -C testcode/lib prefix=$(prefix) $(SYS:%=SYS=%)
 
 clean zap:
-	$(MAKE) -C src -f make/gcc.mak $@
-	$(MAKE) -C libsrc $@
-	$(MAKE) -C doc $@
-	$(MAKE) -C samples $@
-#	$(MAKE) -C testcode/lib $@ $(SYS:%=SYS=%)
+	@$(MAKE) -C src -f make/gcc.mak $@
+	@$(MAKE) -C libsrc $@
+	@$(MAKE) -C doc $@
+	@$(MAKE) -C samples $@
+#	@$(MAKE) -C testcode/lib $@ $(SYS:%=SYS=%)
 
 uninstall:	install-test
 	cd $(bindir) && $(RM) ar65${EXT} ca65${EXT} cc65${EXT} cl65${EXT} \
 	  co65${EXT} da65${EXT} ld65${EXT} od65${EXT} grc${EXT} ca65html
-	$(RM) -R $(CC65DATA) $(CC65DOC)
+	$(RM) -R $(CC65_HOME) $(CC65_DOC)
 
 install:	install-test install-dirs install-bins install-libs install-docs
 	@echo
-	@echo 'You can export some shell environment variables:'
+	@echo 'If you put the files into non-standard directories, then'
+	@echo 'you might need to export some shell environment variables:'
 	@echo
-	@echo 'CC65_INC=$(CC65INC)'
-	@echo 'CC65_LIB=$(CC65LIB)'
+	@echo 'CC65_HOME=$(CC65_HOME)'
+	@echo ' or'
+	@echo 'CA65_INC=$(CA65_INC)'
+	@echo 'CC65_INC=$(CC65_INC)'
+	@echo 'LD65_CFG=$(LD65_CFG)'
+	@echo 'LD65_LIB=$(LD65_LIB)'
+	@echo 'LD65_OBJ=$(LD65_OBJ)'
 	@echo
 
 .PHONY:	install-test
@@ -108,64 +119,76 @@ install-test:
 	  fi 2>/dev/null
 
 .PHONY:	install-dirs
-install-dirs:
-	[ -d $(bindir) ] || $(MKDIR) $(bindir)
-	[ -d $(datadir) ] || $(MKDIR) $(datadir)
-	[ -d $(docdir) ] || $(MKDIR) $(docdir)
-	[ -d $(libdir) ] || $(MKDIR) $(libdir)
-	[ -d $(CC65DOC) ] || $(MKDIR) $(CC65DOC)
-	[ -d $(CC65DATA) ] || $(MKDIR) $(CC65DATA)
-	[ -d $(CC65ASM) ] || $(MKDIR) $(CC65ASM)
-	[ -d $(CC65LIB) ] || $(MKDIR) $(CC65LIB)
-	[ -d $(CC65INC) ] || $(MKDIR) $(CC65INC)
-	[ -d $(CC65INC)/em ] || $(MKDIR) $(CC65INC)/em
-	[ -d $(CC65INC)/geos ] || $(MKDIR) $(CC65INC)/geos
-	[ -d $(CC65INC)/joystick ] || $(MKDIR) $(CC65INC)/joystick
-	[ -d $(CC65INC)/mouse ] || $(MKDIR) $(CC65INC)/mouse
-	[ -d $(CC65INC)/sys ] || $(MKDIR) $(CC65INC)/sys
-	[ -d $(CC65INC)/tgi ] || $(MKDIR) $(CC65INC)/tgi
-	[ -d $(CC65DATA)/emd ] || $(MKDIR) $(CC65DATA)/emd
-	[ -d $(CC65DATA)/joy ] || $(MKDIR) $(CC65DATA)/joy
-	[ -d $(CC65DATA)/mou ] || $(MKDIR) $(CC65DATA)/mou
-	[ -d $(CC65DATA)/ser ] || $(MKDIR) $(CC65DATA)/ser
-	[ -d $(CC65DATA)/tgi ] || $(MKDIR) $(CC65DATA)/tgi
+install-dirs:	$(bindir) $(datadir) $(docdir) $(libdir) \
+		$(CC65_DOC) $(CC65_HOME) \
+		$(CA65_INC) $(CC65_INC) \
+		$(CC65_INC)/em $(CC65_INC)/geos $(CC65_INC)/joystick \
+		$(CC65_INC)/mouse $(CC65_INC)/sys $(CC65_INC)/tgi \
+		$(LD65_CFG) $(LD65_LIB) $(LD65_OBJ) \
+		$(CC65_HOME)/emd $(CC65_HOME)/joy $(CC65_HOME)/mou \
+		$(CC65_HOME)/ser $(CC65_HOME)/tgi
+
+$(bindir) $(datadir) $(docdir) $(libdir) \
+$(CC65_DOC) $(CC65_HOME) \
+$(CA65_INC) $(CC65_INC) \
+$(LD65_CFG) $(LD65_LIB) $(LD65_OBJ):
+	$(MKDIR) $@
+
+$(CC65_HOME)/% $(CC65_INC)/% $(CC65_DOC)/%:
+	$(MKDIR) $@
 
 install-bins:
 	for f in ar65 ca65 cc65 cl65 co65 da65 ld65 od65 grc; \
-	  do $(INSTALL_STRIP) src/$$f/$$f${EXT} $(bindir) || exit 1; \
+	  do $(INSTALL_STRIP) src/$$f/$$f${EXT} $(bindir) || exit $$?; \
 	  done
 	$(INSTALL_PROG) src/ca65html/ca65html $(bindir)
 
 install-libs:
 	for f in asminc/*.inc; \
-	  do $(INSTALL_DATA) $$f $(CC65ASM) || exit 1; \
+	  do $(INSTALL_DATA) $$f $(CA65_INC) || exit $$?; \
 	  done
 	for f in include/*.h; \
-	  do $(INSTALL_DATA) $$f $(CC65INC) || exit 1; \
+	  do $(INSTALL_DATA) $$f $(CC65_INC) || exit $$?; \
 	  done
 	for d in em geos joystick mouse sys tgi; \
 	  do for f in include/$$d/*.h; \
-	    do $(INSTALL_DATA) $$f $(CC65INC)/$$d || exit 1; \
-	    done || exit 1; \
+	    do $(INSTALL_DATA) $$f $(CC65_INC)/$$d || exit $$?; \
+	    done || exit $$?; \
 	  done
 	for f in libsrc/*.lib; \
-	  do $(INSTALL_DATA) $$f $(CC65LIB) || exit 1; \
+	  do $(INSTALL_DATA) $$f $(LD65_LIB) || exit $$?; \
+	  done
+	for f in libsrc/*-*.o; \
+	  do $(INSTALL_DATA) $$f $(LD65_OBJ) || exit $$?; \
 	  done
 	for d in emd joy mou ser tgi; \
 	  do for f in libsrc/*.$$d; \
-	    do $(INSTALL_DATA) $$f $(CC65DATA)/$$d || exit 1; \
-	    done || exit 1; \
+	    do $(INSTALL_DATA) $$f $(CC65_HOME)/$$d || exit $$?; \
+	    done || exit $$?; \
+	  done
+	for f in src/ld65/cfg/*-*.cfg; \
+	  do $(INSTALL_DATA) $$f $(LD65_CFG) || exit $$?; \
 	  done
 
 install-docs:
-	for f in src/ld65/cfg/*.cfg src/ca65/macpack/*.mac; \
-	  do $(INSTALL_DATA) $$f $(CC65DOC) || exit 1; \
+	for f in src/ca65/macpack/*.mac; \
+	  do $(INSTALL_DATA) $$f $(CC65_DOC) || exit $$?; \
 	  done
 	for f in readme.1st compile.txt CREDITS BUGS internal.txt newvers.txt; \
-	  do $(INSTALL_DATA) doc/$$f $(CC65DOC) || exit 1; \
+	  do $(INSTALL_DATA) doc/$$f $(CC65_DOC) || exit $$?; \
 	  done
 	if [ -f doc/index.htm* ]; \
 	  then for f in doc/*.htm*; \
-	    do $(INSTALL_DATA) $$f $(CC65DOC) || exit 1; \
+	    do $(INSTALL_DATA) $$f $(CC65_DOC) || exit $$?; \
 	    done; \
 	  fi
+
+install-samps:	${addprefix $(CC65_DOC)/, $(shell find samples -type d)}
+	@$(MAKE) -C samples zap
+	for d in `find samples -type d`; \
+	  do for f in $$d/*; \
+	    do if [ -f $$f ]; \
+	      then $(INSTALL_DATA) $$f $(CC65_DOC)/$$d || exit $$?; \
+	      fi; \
+	    done || exit $$?; \
+	  done