-all mostlyclean clean:
+all mostlyclean clean install:
@$(MAKE) -C src --no-print-directory $@
@$(MAKE) -C libsrc --no-print-directory $@
%:
@$(MAKE) -C libsrc --no-print-directory $@
-.PHONY: all mostlyclean clean avail unavail bin lib
+.PHONY: all mostlyclean clean install avail unavail bin lib
.SUFFIXES:
.SUFFIXES:
-.PHONY: all lib $(TARGETS) mostlyclean clean
+.PHONY: all lib $(TARGETS) mostlyclean clean install
ifndef TARGET
+datadir = $(prefix)/share/cc65
+
+INSTALLDIRS = ../asminc ../cfg ../include \
+ $(filter-out $(wildcard ../include/*.*),$(wildcard ../include/*)) \
+ ../lib ../targetutil $(addprefix ../,$(DRVTYPES))
+
+INSTALL = install
+
all lib: $(TARGETS)
$(TARGETS):
clean:
$(call RMDIR,../wrk ../lib ../targetutil $(addprefix ../,$(DRVTYPES)))
+install:
+ $(foreach dir,$(INSTALLDIRS),$(INSTALL_recipe))
+
+##########
+
+define INSTALL_recipe
+
+$(if $(prefix),,$(error variable `prefix' must be set))
+$(INSTALL) -d $(subst ..,$(DESTDIR)$(datadir),$(dir))
+$(INSTALL) -m644 $(dir)/* $(subst ..,$(DESTDIR)$(datadir),$(dir))
+
+endef
+
+##########
+
else # TARGET
CA65FLAGS =
sim65 \
sp65
-ifdef prefix
- CA65_INC = $(prefix)/lib/cc65/asminc
- CC65_INC = $(prefix)/lib/cc65/include
- LD65_LIB = $(prefix)/lib/cc65/lib
- LD65_OBJ = $(prefix)/lib/cc65/lib
- LD65_CFG = $(prefix)/lib/cc65/cfg
-else
- CA65_INC := $(abspath ../asminc)
- CC65_INC := $(abspath ../include)
- LD65_LIB := $(abspath ../lib)
- LD65_OBJ := $(abspath ../lib)
- LD65_CFG := $(abspath ../cfg)
-endif
+bindir := $(prefix)/bin
+datadir := $(if $(prefix),$(prefix)/share/cc65,$(abspath ..))
+
+CA65_INC = $(datadir)/asminc
+CC65_INC = $(datadir)/include
+LD65_LIB = $(datadir)/lib
+LD65_OBJ = $(datadir)/lib
+LD65_CFG = $(datadir)/cfg
CFLAGS += -MMD -MP -O -std=c89 -I common \
-Wall -Wextra -Wno-char-subscripts -Werror $(USER_CFLAGS) \
LDLIBS += -lm
+INSTALL = install
+
.SUFFIXES:
-.PHONY: all bin $(PROGS) mostlyclean clean avail unavail
+.PHONY: all bin $(PROGS) mostlyclean clean install avail unavail
all bin: $(PROGS)
clean:
$(RM) -r ../wrk ../bin
+install:
+ $(if $(prefix),,$(error variable `prefix' must be set))
+ $(INSTALL) -d $(DESTDIR)$(bindir)
+ $(INSTALL) ../bin/* $(DESTDIR)$(bindir)
+
avail:
$(foreach prog,$(PROGS),$(AVAIL_recipe))