From 5a54e33e9e6f506f1ba852cfd45394ac8d8d4071 Mon Sep 17 00:00:00 2001 From: Ivan Tatarinov Date: Mon, 17 May 2021 11:59:05 +0300 Subject: [PATCH] Updated `utils/Makefile`, `Makefile` to follow GNU standards --- Makefile | 54 ++++------- utils/Makefile | 250 +++++++++++++++++++++++++++++-------------------- 2 files changed, 166 insertions(+), 138 deletions(-) diff --git a/Makefile b/Makefile index b039a09..7b02406 100644 --- a/Makefile +++ b/Makefile @@ -15,30 +15,19 @@ include sdk/common.mk -INSTALL_DIR=SD +# Use uppercase for FAT filesystem +prefix ?= SD +exec_prefix ?= $(prefix) +bindir ?= $(exec_prefix)/BIN -UTILS_TARGETS=\ - BACK16M\ - BACKZX2\ - BACKZXD\ - BACKUP\ - CORCLEAN\ - COREBIOS\ - ROMSBACK\ - ROMSUPGR\ - UPGR16M\ - UPGRZX2\ - UPGRZXD\ - UPGRADE - -UTILS_INSTALL_DIR=$(INSTALL_DIR)/BIN +INSTALL ?= install +INSTALL_PROGRAM ?= $(INSTALL) +RM = rm -f SOFTWARE_TARGETS=\ ESPRST\ IWCONFIG -SOFTWARE_INSTALL_DIR=$(INSTALL_DIR)/BIN - .PHONY: all all:\ install-utils\ @@ -48,36 +37,27 @@ all:\ # utils .PHONY: install-utils -install-utils: $(foreach t,$(UTILS_TARGETS),$(UTILS_INSTALL_DIR)/$(t)) | utils - -# $1 = target -define utils_rule = -$$(UTILS_INSTALL_DIR)/$1: utils/build/$1 | utils - mv $$< $$@ -utils/build/$1: | utils - $$(MAKE) -w -C $$| build/$$(@F) -endef - -$(foreach t,$(UTILS_TARGETS),$(eval $(call utils_rule,$(t)))) +install-utils: | utils + $(MAKE) -w -C $| bindir=$(shell realpath --relative-to=$| $(bindir)) install .PHONY: clean-utils clean-utils: | utils $(MAKE) -w -C $| clean .PHONY: uninstall-utils -uninstall-utils: clean-utils - rm -f $(foreach t,$(UTILS_TARGETS),$(UTILS_INSTALL_DIR)/$(t)) +uninstall-utils: clean-utils | utils + $(MAKE) -w -C $| bindir=$(shell realpath --relative-to=$| $(bindir)) uninstall # software .PHONY: install-software -install-software: $(foreach t,$(SOFTWARE_TARGETS),$(SOFTWARE_INSTALL_DIR)/$(t)) +install-software: $(foreach t,$(SOFTWARE_TARGETS),$(DESTDIR)$(bindir)/$(t)) -$(SOFTWARE_INSTALL_DIR)/ESPRST: software/esprst/esprst - mv $< $@ +$(DESTDIR)$(bindir)/ESPRST: software/esprst/esprst + $(INSTALL) $< $@ -$(SOFTWARE_INSTALL_DIR)/IWCONFIG: software/iwconfig/IWCONFIG - mv $< $@ +$(DESTDIR)$(bindir)/IWCONFIG: software/iwconfig/IWCONFIG + $(INSTALL) $< $@ software/esprst/esprst: | software/esprst $(MAKE) -w -C $| @@ -94,7 +74,7 @@ clean-software: |\ .PHONY: uninstall-software uninstall-software: clean-software - rm -f $(foreach t,$(SOFTWARE_TARGETS),$(SOFTWARE_INSTALL_DIR)/$(t)) + $(RM) $(foreach t,$(SOFTWARE_TARGETS),$(DESTDIR)$(bindir)/$(t)) # clean diff --git a/utils/Makefile b/utils/Makefile index 4fa787f..3c7de30 100644 --- a/utils/Makefile +++ b/utils/Makefile @@ -1,24 +1,48 @@ +# SPDX-FileCopyrightText: 2021 Ivan Tatarinov +# +# SPDX-License-Identifier: GPL-3.0-or-later +# # Supported environments: # * GNU on Linux, FreeBSD etc. # * GNU on Windows NT (using MinGW/MSYS/Cygwin/WSL) # # Build: -# make +# make [ ...] +# Install / Uninstall: +# make [prefix=] install | uninstall # Clean: -# make clean +# make clean | distclean # -# SPDX-FileCopyrightText: 2021 Ivan Tatarinov -# -# SPDX-License-Identifier: GPL-3.0-or-later +# where: +# is one of values for `BINS' variable prefixed with "build/" +# (see target `all' below). +# is a prefix directory to install files into. include ../sdk/common.mk -INC_DIR = ../sdk/include -BUILD_DIR = build -AS = sjasmplus -AFLAGS = --nobanner -I$(INC_DIR) +srcdir = . +# Use uppercase for FAT filesystem +prefix ?= . +exec_prefix ?= $(prefix) +bindir ?= $(exec_prefix)/BIN -TARGETS=\ +# Disable execution mode for FAT filesystem +INSTALL ?= install +INSTALL_PROGRAM ?= $(INSTALL) -m 644 +RM = rm -f + +INCLUDEDIR = ../sdk/include +AS = sjasmplus +ifeq ($(USE_SJASMPLUS_VERSION),sjasmplus) +AFLAGS = --nobanner +else ifeq ($(USE_SJASMPLUS_VERSION),z00m128) +AFLAGS = --nologo +else +AFLAGS = +endif +AFLAGS += -I$(INCLUDEDIR) + +BINS=\ BACK16M\ BACKZX2\ BACKZXD\ @@ -32,131 +56,155 @@ TARGETS=\ UPGRZXD\ UPGRADE -.PHONY: all -all: $(foreach t,$(TARGETS),$(BUILD_DIR)/$(t)) +TMPS=\ + back32m.def\ + upgr32m.def -$(BUILD_DIR): +.PHONY: all +all: $(foreach t,$(BINS),build/$(t)) + +build\ +$(DESTDIR)$(bindir): mkdir -p $@ -$(BUILD_DIR)/BACK16M: back16m.asm\ - $(INC_DIR)/zxuno.def\ - $(INC_DIR)/esxdos.def\ - Print.inc\ - rdflsh.inc\ - rst28.inc\ - | $(BUILD_DIR) +build/BACK16M: $(srcdir)/back16m.asm\ + $(INCLUDEDIR)/zxuno.def\ + $(INCLUDEDIR)/esxdos.def\ + $(INCLUDEDIR)/Print.inc\ + $(INCLUDEDIR)/rdflsh.inc\ + $(INCLUDEDIR)/rst28.inc\ + | build $(AS) $(AFLAGS) --raw=$@ $< -$(BUILD_DIR)/BACKZX2: back32m.asm\ - $(INC_DIR)/zxuno.def\ - $(INC_DIR)/esxdos.def\ - Print.inc\ - rdflsh.inc\ - rst28.inc\ - | $(BUILD_DIR) +build/BACKZX2: $(srcdir)/back32m.asm\ + $(INCLUDEDIR)/zxuno.def\ + $(INCLUDEDIR)/esxdos.def\ + $(INCLUDEDIR)/Print.inc\ + $(INCLUDEDIR)/rdflsh.inc\ + $(INCLUDEDIR)/rst28.inc\ + | build echo ' define zxdos 1' >back32m.def $(AS) $(AFLAGS) --raw=$@ $< rm -f back32m.def -$(BUILD_DIR)/BACKZXD: back32m.asm\ - $(INC_DIR)/zxuno.def\ - $(INC_DIR)/esxdos.def\ - Print.inc\ - rdflsh.inc\ - rst28.inc\ - | $(BUILD_DIR) +build/BACKZXD: $(srcdir)/back32m.asm\ + $(INCLUDEDIR)/zxuno.def\ + $(INCLUDEDIR)/esxdos.def\ + $(INCLUDEDIR)/Print.inc\ + $(INCLUDEDIR)/rdflsh.inc\ + $(INCLUDEDIR)/rst28.inc\ + | build echo ' define zxdos 0' >back32m.def $(AS) $(AFLAGS) --raw=$@ $< rm -f back32m.def -$(BUILD_DIR)/BACKUP: backup.asm\ - $(INC_DIR)/zxuno.def\ - $(INC_DIR)/esxdos.def\ - Print.inc\ - rdflsh.inc\ - rst28.inc\ - | $(BUILD_DIR) +build/BACKUP: $(srcdir)/backup.asm\ + $(INCLUDEDIR)/zxuno.def\ + $(INCLUDEDIR)/esxdos.def\ + $(INCLUDEDIR)/Print.inc\ + $(INCLUDEDIR)/rdflsh.inc\ + $(INCLUDEDIR)/rst28.inc\ + | build $(AS) $(AFLAGS) --raw=$@ $< -$(BUILD_DIR)/CORCLEAN: corclean.asm\ - $(INC_DIR)/zxuno.def\ - Print.inc\ - rdflsh.inc\ - wrflsh.inc\ - rst28.inc\ - | $(BUILD_DIR) +build/CORCLEAN: $(srcdir)/corclean.asm\ + $(INCLUDEDIR)/zxuno.def\ + $(INCLUDEDIR)/Print.inc\ + $(INCLUDEDIR)/rdflsh.inc\ + $(INCLUDEDIR)/wrflsh.inc\ + $(INCLUDEDIR)/rst28.inc\ + | build $(AS) $(AFLAGS) --raw=$@ $< -$(BUILD_DIR)/COREBIOS: corebios.asm\ - $(INC_DIR)/zxuno.def\ - $(INC_DIR)/esxdos.def\ - Print.inc\ - rdflsh.inc\ - wrflsh.inc\ - rst28.inc\ - | $(BUILD_DIR) +build/COREBIOS: $(srcdir)/corebios.asm\ + $(INCLUDEDIR)/zxuno.def\ + $(INCLUDEDIR)/esxdos.def\ + $(INCLUDEDIR)/Print.inc\ + $(INCLUDEDIR)/rdflsh.inc\ + $(INCLUDEDIR)/wrflsh.inc\ + $(INCLUDEDIR)/rst28.inc\ + | build $(AS) $(AFLAGS) --raw=$@ $< -$(BUILD_DIR)/ROMSBACK: romsback.asm\ - $(INC_DIR)/zxuno.def\ - $(INC_DIR)/esxdos.def\ - Print.inc\ - rdflsh.inc\ - rst28.inc\ - | $(BUILD_DIR) +build/ROMSBACK: $(srcdir)/romsback.asm\ + $(INCLUDEDIR)/zxuno.def\ + $(INCLUDEDIR)/esxdos.def\ + $(INCLUDEDIR)/Print.inc\ + $(INCLUDEDIR)/rdflsh.inc\ + $(INCLUDEDIR)/rst28.inc\ + | build $(AS) $(AFLAGS) --raw=$@ $< -$(BUILD_DIR)/ROMSUPGR: romsupgr.asm\ - $(INC_DIR)/zxuno.def\ - $(INC_DIR)/esxdos.def\ - Print.inc\ - rdflsh.inc\ - wrflsh.inc\ - rst28.inc\ - | $(BUILD_DIR) +build/ROMSUPGR: $(srcdir)/romsupgr.asm\ + $(INCLUDEDIR)/zxuno.def\ + $(INCLUDEDIR)/esxdos.def\ + $(INCLUDEDIR)/Print.inc\ + $(INCLUDEDIR)/rdflsh.inc\ + $(INCLUDEDIR)/wrflsh.inc\ + $(INCLUDEDIR)/rst28.inc\ + | build $(AS) $(AFLAGS) --raw=$@ $< -$(BUILD_DIR)/UPGR16M: upgr16m.asm\ - $(INC_DIR)/zxuno.def\ - $(INC_DIR)/esxdos.def\ - Print.inc\ - wrflsh.inc\ - rst28.inc\ - | $(BUILD_DIR) +build/UPGR16M: $(srcdir)/upgr16m.asm\ + $(INCLUDEDIR)/zxuno.def\ + $(INCLUDEDIR)/esxdos.def\ + $(INCLUDEDIR)/Print.inc\ + $(INCLUDEDIR)/wrflsh.inc\ + $(INCLUDEDIR)/rst28.inc\ + | build $(AS) $(AFLAGS) --raw=$@ $< -$(BUILD_DIR)/UPGRZX2: upgr32m.asm\ - $(INC_DIR)/zxuno.def\ - $(INC_DIR)/esxdos.def\ - Print.inc\ - wrflsh.inc\ - rst28.inc\ - | $(BUILD_DIR) +build/UPGRZX2: $(srcdir)/upgr32m.asm\ + $(INCLUDEDIR)/zxuno.def\ + $(INCLUDEDIR)/esxdos.def\ + $(INCLUDEDIR)/Print.inc\ + $(INCLUDEDIR)/wrflsh.inc\ + $(INCLUDEDIR)/rst28.inc\ + | build echo ' define zxdos 1' >upgr32m.def $(AS) $(AFLAGS) --raw=$@ $< rm -f upgr32m.def -$(BUILD_DIR)/UPGRZXD: upgr32m.asm\ - $(INC_DIR)/zxuno.def\ - $(INC_DIR)/esxdos.def\ - Print.inc\ - wrflsh.inc\ - rst28.inc\ - | $(BUILD_DIR) +build/UPGRZXD: $(srcdir)/upgr32m.asm\ + $(INCLUDEDIR)/zxuno.def\ + $(INCLUDEDIR)/esxdos.def\ + $(INCLUDEDIR)/Print.inc\ + $(INCLUDEDIR)/wrflsh.inc\ + $(INCLUDEDIR)/rst28.inc\ + | build echo ' define zxdos 0' >upgr32m.def $(AS) $(AFLAGS) --raw=$@ $< rm -f upgr32m.def -$(BUILD_DIR)/UPGRADE: upgrade.asm\ - $(INC_DIR)/zxuno.def\ - $(INC_DIR)/esxdos.def\ - Print.inc\ - wrflsh.inc\ - rst28.inc\ - | $(BUILD_DIR) +build/UPGRADE: $(srcdir)/upgrade.asm\ + $(INCLUDEDIR)/zxuno.def\ + $(INCLUDEDIR)/esxdos.def\ + $(INCLUDEDIR)/Print.inc\ + $(INCLUDEDIR)/wrflsh.inc\ + $(INCLUDEDIR)/rst28.inc\ + | build $(AS) $(AFLAGS) --raw=$@ $< +# $1 = target +define install_bin_rule = +$$(DESTDIR)$$(bindir)/$1: build/$1 | $$(DESTDIR)$$(bindir) + $$(INSTALL_PROGRAM) $$< $$@ +endef + +$(foreach t,$(BINS),$(eval $(call install_bin_rule,$(t)))) + +.PHONY: install +install: $(foreach t,$(BINS),$(DESTDIR)$(bindir)/$(t)) + +.PHONY: uninstall +uninstall: + $(RM) $(foreach t,$(BINS),$(DESTDIR)$(bindir)/$(t)) + .PHONY: clean clean: - rm -f back32m.def upgr32m.def - rm -f $(foreach t,$(TARGETS),$(BUILD_DIR)/$(t)) + rm -f $(TMPS) $(foreach t,$(BINS),build/$(t)) + +.PHONY: distclean +distclean: + rm -f $(TMPS) + rm -rf build/*