########################################################################
# Makefile.in - Processed by autosetup's configure script to generate
#    the GNU make(1) file for building the PiDP-8/I software.
#
# If you are seeing this at the top of a file called Makefile and you
# intend to make edits, do that in Makefile.in.  Saying "make" will then
# re-build Makefile from that modified Makefile.in before proceeding to
# do the "make" operation.
#
# Copyright © 2015 by Oscar Vermeulen, © 2016-2021 by Warren Young
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
# IN NO EVENT SHALL THE AUTHORS LISTED ABOVE BE LIABLE FOR ANY CLAIM,
# DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
# OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
# OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#
# Except as contained in this notice, the names of the authors above
# shall not be used in advertising or otherwise to promote the sale,
# use or other dealings in this Software without prior written
# authorization from those authors.
########################################################################

# Git commit ID and time of the latest version of the SIMH 4 project on
# GitHub that has been merged into this source base.
SGCID=c5d1f8c5
SGCTM=2025-06-29T16:58:05-04:00

# C build flags for the PDP-8 simulator and its PiDP-8/I extensions.

ifeq (@BUILD_PIDP8I@, 1)
BUILD_PIDP8I_CFLAGS = -DPIDP8I -I @srcdir@/src/pidp8i -I @srcdir@/src/pinctrl
endif

SIM_CFLAGS := @CFLAGS@ @BUILDMODE@ \
	-Wno-unused-result -Wno-parentheses \
	-DUSE_READER_THREAD -DHAVE_DLOPEN=$(subst .,,@SH_SOEXT@) \
	-DSIM_ASYNCH_IO -DHAVE_GLOB \
	-DSIM_GIT_COMMIT_ID=$(SGCID) -DSIM_GIT_COMMIT_TIME=$(SGCTM) \
	-DSIM_BUILD_TOOL='autosetup+gmake' \
	-D_GNU_SOURCE \
	-U__STRICT_ANSI__ \
	-I @srcdir@/src/SIMH -I src -I src/SIMH \
	$(BUILD_PIDP8I_CFLAGS)

ifneq "@HAVE_PCRE_H@" "0"
SIM_CFLAGS += -DHAVE_PCRE_H
SIM_LFLAGS := -lpcre
endif
ifneq "@HAVE_PCREPOSIX_H@" "0"
SIM_CFLAGS += -DHAVE_PCREPOSIX_H
endif

# These CFLAGS definitions look like the're not used, but adrules.mk uses them.
PIDP8I_CFLAGS = $(SIM_CFLAGS)
SIMH_CFLAGS = $(SIM_CFLAGS)
SIMH_PDP8_CFLAGS = $(SIM_CFLAGS)

# Greatly stripped-down build options for the cc8 cross-compiler
# primarily because it's K&R C.  Building under SIM_CFLAGS spews
# pages of warnings.  The only thing we share is whether to build
# a debug or optimized version, from BUILDMODE, set by auto.def.
CC8_CROSS_CFLAGS = -w @BUILDMODE@

# Krten's d8tape doesn't need much in the way of options.  It builds
# without warnings under the supported version of Raspbian.  On some
# other OS types, it complains about one of the printf() format
# specifiers, which we cannot fix portably, so we suppress that one.
D8TAPE_CFLAGS = -Wno-format @BUILDMODE@

# Simpler options for src/misc/*.c
MISC_CFLAGS = $(BUILD_PIDP8I_CFLAGS) @BUILDMODE@ -std=c99

# Even simpler options for palbart.
PALBART_CFLAGS = @BUILDMODE@

PIDP8I_SIM = bin/pidp8i-sim
PDP8_SIM = bin/pdp8

ifeq (@BUILD_PIDP8I@, 1)
PI_BINS = \
	libexec/scanswitch \
	bin/pidp8i-test

ifeq (@BUILD_DEEPER_THOUGHT@, 1)
PI_BINS += bin/deeper
endif
endif


BINS = $(PIDP8I_SIM) @CC8_CROSS@ \
	$(PI_BINS) \
	bin/d8tape \
	bin/palbart \
	bin/ptp2txt

BIN_SCRIPTS = \
	bin/os8pkg \
	bin/pidp8i \
	bin/usb-mount \
	@srcdir@/bin/teco-pi-demo

# Some *.py files are generated by Autosetup, so they need different
# handling than the other libraries for the out-of-tree build case.
PIDP8I_DIRS := lib/pidp8i/dirs.py
PIDP8I_DIN  := @srcdir@/$(PIDP8I_DIRS).in
GENNED_PY   := \
	lib/pidp8i/__init__.py \
	lib/pidp8i/ips.py \
	lib/pidp8i/os8opts.py \
	$(PIDP8I_DIRS)

SIMH_PY     := lib/simh.py
SIMH_PY_SRC := @srcdir@/$(SIMH_PY)

# Any use of $(OS8RUN) must implicitly depend on $(OS8_TOOLTIME) disk image.
OS8RUN          = bin/os8-run

# Any use of $(OS8CP) must implicitly depend on $(OS8_TOOLTIME) disk image.
OS8CP          = bin/os8-cp

OS8SCRIPT      := lib/os8script.py
OS8RUN_PY_ALL  := $(GENNED_PY) $(OS8SCRIPT) $(SIMH_PY_SRC)
OS8RUN_SRCS    := $(OS8RUN) $(OS8RUN_PY_ALL) $(PIDP8I_DIN)

# If you edit this directory list, you should probably also edit
# the argument list to the mkadrules call in auto.def!
BUILDDIRS := \
	bin \
	libexec \
	obj/cc8/cross \
	obj/cc8/os8 \
	obj/d8tape \
	obj/misc \
	obj/pinctrl \
	obj/palbart \
	obj/os8pkg \
	obj/pidp8i \
	obj/SIMH \
	obj/SIMH/PDP8

INSTDIRS := bin etc lib/pidp8i libexec \
	share/boot share/include share/man/man1 share/media/os8 share/save

SIM_OBJS := \
	obj/SIMH/PDP8/pdp8_df.o \
	obj/SIMH/PDP8/pdp8_cpu.o \
	obj/SIMH/PDP8/pdp8_clk.o \
	obj/SIMH/PDP8/pdp8_ct.o \
	obj/SIMH/PDP8/pdp8_dt.o \
	obj/SIMH/PDP8/pdp8_fpp.o \
	obj/SIMH/PDP8/pdp8_lp.o \
	obj/SIMH/PDP8/pdp8_mt.o \
	obj/SIMH/PDP8/pdp8_pt.o \
	obj/SIMH/PDP8/pdp8_rf.o \
	obj/SIMH/PDP8/pdp8_rk.o \
	obj/SIMH/PDP8/pdp8_rl.o \
	obj/SIMH/PDP8/pdp8_rx.o \
	obj/SIMH/PDP8/pdp8_sys.o \
	obj/SIMH/PDP8/pdp8_td.o \
	obj/SIMH/PDP8/pdp8_tsc.o \
	obj/SIMH/PDP8/pdp8_tt.o \
	obj/SIMH/PDP8/pdp8_ttx.o \
	obj/SIMH/scp.o \
	obj/SIMH/sim_card.o \
	obj/SIMH/sim_console.o \
	obj/SIMH/sim_disk.o \
	obj/SIMH/sim_ether.o \
	obj/SIMH/sim_fio.o \
	obj/SIMH/sim_serial.o \
	obj/SIMH/sim_sock.o \
	obj/SIMH/sim_tape.o \
	obj/SIMH/sim_timer.o \
	obj/SIMH/sim_tmxr.o \
	obj/SIMH/sim_video.o

ifeq (@BUILD_PIDP8I@, 1)
GPIO_OBJS := \
	obj/pinctrl/gpiochip_bcm2712.o \
	obj/pinctrl/gpiolib.o \
	obj/pinctrl/gpiochip_bcm2835.o \
	obj/pinctrl/gpiochip_rp1.o \
	obj/pinctrl/util.o \
	obj/pidp8i/gpio-common.o
PIDP8I_OBJS := \
	obj/pidp8i/main.o
LED_OBJ := obj/pidp8i/gpio-@LED_DRIVER_MODULE@ls.o
endif

CC8_OBJS := \
	obj/cc8/cross/code8.o \
	obj/cc8/cross/data.o \
	obj/cc8/cross/error.o \
	obj/cc8/cross/expr.o \
	obj/cc8/cross/function.o \
	obj/cc8/cross/gen.o \
	obj/cc8/cross/initials.o \
	obj/cc8/cross/io.o \
	obj/cc8/cross/lex.o \
	obj/cc8/cross/main.o \
	obj/cc8/cross/preproc.o \
	obj/cc8/cross/primary.o \
	obj/cc8/cross/stmt.o \
	obj/cc8/cross/struct.o \
	obj/cc8/cross/sym.o \
	obj/cc8/cross/while.o

D8TAPE_OBJS := \
	obj/d8tape/dasm.o \
	obj/d8tape/flow.o \
	obj/d8tape/main.o \
	obj/d8tape/version.o

MISC_OBJS := \
	obj/misc/ptp2txt.o \
	obj/misc/scanswitch.o \
	obj/misc/test.o

PALBART_OBJS := obj/palbart/palbart.o

TEST_TMP_BINS = bin/os8-run bin/pdp8 bin/ptp2txt

LIBS = -lm -ldl -lpthread

ASM_PTS     := $(wildcard @srcdir@/src/asm/*.pal)
ASM_PTS     := $(subst @srcdir@/src/asm,bin,$(ASM_PTS))
ASM_PTS     := $(ASM_PTS:.pal=-pal.pt)
FC_EX_PTS   := $(wildcard @srcdir@/examples/*.fc)
FC_EX_PTS   := $(subst @srcdir@/examples,bin,$(FC_EX_PTS))
FC_EX_PTS   := $(FC_EX_PTS:.fc=-focal.pt)
PAL_EX_PTS  := $(wildcard @srcdir@/examples/*.pal)
PAL_EX_PTS  := $(subst @srcdir@/examples,bin,$(PAL_EX_PTS))
PAL_EX_PTS  := $(PAL_EX_PTS:.pal=-pal.pt)
LISTINGS    := $(ASM_PTS:-pal.pt=.lst) $(PAL_EX_PTS:-pal.pt=.lst)
LISTINGS    := $(subst bin/,obj/,$(LISTINGS))
BOOTSCRIPTS := $(LISTINGS:.lst=.script)
BOOTSCRIPTS := $(subst obj/,boot/,$(BOOTSCRIPTS)) \
	boot/1.script \
	boot/5.script

# List of *.in files from auto.def file, except for this present file
# (Makefile.in) which is handled separately.  This list should only
# change when the list of "make-template" calls in auto.def changes.
# 
# The OS8RUN_INFILES set of files are those which, if changed, require
# rebuilding the OS/8 media.  Touching the combined set merely causes
# a reconfig and build.
#
# The PRECIOUS set are those whose outfiles we want make(1) to treat as
# "precious", meaning it won't delete files generated by a target if the
# rule being processed to create that target fails.
# 
# The rest have no special treatment.
OS8RUN_INFILES = \
	@srcdir@/lib/pidp8i/__init__.py.in \
	@srcdir@/lib/pidp8i/ips.py.in \
	@srcdir@/media/os8/init.tx.in \
	@srcdir@/media/os8/3finit.tx.in \
	@srcdir@/media/os8/ock-init.tx.in \
	@srcdir@/src/pidp8i/main.c.in \
	$(PIDP8I_DIN)
PRECIOUS_INFILES = \
	@srcdir@/Makefile.in \
    @srcdir@/examples/Makefile.in \
    @srcdir@/src/Makefile.in \
    @srcdir@/src/cc8/Makefile.in \
    @srcdir@/src/SIMH/Makefile.in \
    @srcdir@/src/SIMH/PDP8/Makefile.in
INFILES = \
	@srcdir@/tools/os8-progtest.in \
	@srcdir@/bin/os8pkg.in \
	@srcdir@/bin/os8-cp.in \
	@srcdir@/tools/os8-cmp.in \
	@srcdir@/bin/os8-run.in \
	@srcdir@/bin/teco-pi-demo.in \
	@srcdir@/bin/pidp8i.in \
	@srcdir@/boot/0.script.in \
	@srcdir@/boot/2.script.in \
	@srcdir@/boot/3.script.in \
	@srcdir@/boot/4.script.in \
	@srcdir@/boot/6.script.in \
	@srcdir@/boot/7.script.in \
	@srcdir@/boot/run.script.in \
	@srcdir@/boot/run-v3f.script.in \
	@srcdir@/boot/run-v3d.script.in \
	@srcdir@/boot/run-ock.script.in \
	@srcdir@/boot/tss8.script.in \
	@srcdir@/etc/pidp8i.service.in \
	@srcdir@/etc/sudoers.in \
	@srcdir@/etc/usb-mount@.service.in \
	@srcdir@/lib/os8script.py.in \
	@srcdir@/lib/os8util.py.in \
	@srcdir@/lib/simh.py.in \
	@srcdir@/lib/pidp8i/util.py \
	@srcdir@/examples/host/class-os8script-demo.py.in \
	@srcdir@/src/pidp8i/gpio-common.c.in \
	@srcdir@/tools/simh-bisect.in \
	@srcdir@/tools/simh-update.in \
	$(OS8RUN_INFILES)
OS8RUN_OUTFILES := $(subst @srcdir@/,,$(OS8RUN_INFILES))
OS8RUN_OUTFILES := $(subst .in,,$(OS8RUN_OUTFILES))
PRECIOUS_OUTFILES := $(subst @srcdir@/,,$(PRECIOUS_INFILES))
PRECIOUS_OUTFILES := $(subst .in,,$(PRECIOUS_OUTFILES))
OUTFILES := $(subst @srcdir@/,,$(INFILES))
OUTFILES := $(subst .in,,$(OUTFILES))

OS8_SRC_RK05 = @OS8_SRC_RK05@
OS8_BASELINE = bin/@OS8_BASELINE@
OS8_TOOLTIME = bin/@OS8_TOOLTIME@

# auto.defs will select as OS8_RUNTIME either V3D_RUNTIME or OCK_RUNTIME disk image.
V3D_RUNTIME = bin/v3d.rk05
OCK_RUNTIME = bin/ock.rk05
OS8_RUNTIME = bin/@OS8_RUNTIME@

OS8_RK05S = \
	$(OS8_BASELINE) \
	$(V3D_RUNTIME) \
	$(OS8_SRC_RK05) \
	$(OS8_OCK_DIST_RK05) \
	$(OS8_OCK_PATCHED_RK05) \
	$(OCK_RUNTIME)



INC_SCRIPTS_DIR = @srcdir@/scripts/include
MISC_SCRIPTS_DIR = @srcdir@/scripts/misc
OS8_SCRIPTS_DIR = @srcdir@/scripts/os8

V3D_DIST_SCRIPT = $(OS8_SCRIPTS_DIR)/v3d/dist-rk05.os8
V3D_SRC_SCRIPT = $(OS8_SCRIPTS_DIR)/v3d/src-rk05.os8
V3D_PATCH_SCRIPT = $(OS8_SCRIPTS_DIR)/v3d/patch-rk05.os8
V3D_RK05_SCRIPT = $(OS8_SCRIPTS_DIR)/v3d/boot-rk05.os8

V3F_SRCDIR = @srcdir@/src/os8/v3f
V3F_BUILD_RK05 = obj/v3f-build.rk05
V3F_MANIFEST = actions.txt

V3F_MADE_RK05 = bin/v3f-made.rk05

V3F_MAKER = $(OS8_SCRIPTS_DIR)/v3f/control.os8

# OS/8 Combined Kit. Build from Source.
# We build each object rk05 image in one large script
# Because otherwise mmake would have terrible race conditions.
# We cut the tree up into chunks to fit them on rk05 images:
# SYS: The System Head and device Handlers and key system CUSPS.
# CUSPS: The remaining Commonly Used System Programs (CUSPS)
# BF2: BASIC and FORTRAN II
# FIV: FORTRAN IV

OS8_OCK_SRCDIR = @srcdir@/src/os8/ock

OS8_OCK_SYS_SRC_RK05 = obj/ock-sys-src.rk05
OS8_OCK_SYS_OBJ_RK05 = bin/ock-sys-obj.rk05
OS8_OCK_SYS_MAKER = $(OS8_SCRIPTS_DIR)/ock/sys-build.os8

OS8_OCK_CUSPS_SRC_RK05 = obj/ock-cusps-src.rk05
OS8_OCK_CUSPS_OBJ_RK05 = bin/ock-cusps-obj.rk05
OS8_OCK_CUSPS_MAKER = $(OS8_SCRIPTS_DIR)/ock/cusps-build.os8

OS8_OCK_BF2_SRC_RK05 = obj/ock-bf2-src.rk05
OS8_OCK_BF2_OBJ_RK05 = bin/ock-bf2-obj.rk05
OS8_OCK_BF2_MAKER = $(OS8_SCRIPTS_DIR)/ock/bf2-build.os8

OS8_OCK_FIV_SRC_RK05 = obj/ock-fiv-src.rk05
OS8_OCK_FIV_OBJ_RK05 = bin/ock-fiv-obj.rk05
OS8_OCK_FIV_MAKER = $(OS8_SCRIPTS_DIR)/ock/fiv-build.os8

OS8_OCK_DIST_RK05 = bin/ock-dist.rk05
OS8_OCK_DIST_MAKER = $(OS8_SCRIPTS_DIR)/ock/dist-rk05.os8
OS8_OCK_PATCHED_RK05 = bin/ock-patched.rk05
OS8_OCK_PATCHED_MAKER = $(OS8_SCRIPTS_DIR)/ock/patch-rk05.os8
OS8_OCK_BOOT_MAKER = $(OS8_SCRIPTS_DIR)/ock/boot-rk05.os8

ALL_TU56_SCRIPT = $(OS8_SCRIPTS_DIR)/all-tu56.os8

CUSP_COPYIN_SCRIPT = $(INC_SCRIPTS_DIR)/cusp-copyin.os8

OS8_BOOT_TAPE = bin/@OS8_BOOT_TAPE@
V3D_TC08_TU56 = bin/v3d-tc08.tu56
V3D_TD12K_TU56 = bin/v3d-td12k.tu56
V3F_TC08_TU56 = bin/v3f-tc08.tu56
V3F_TD12K_TU56 = bin/v3f-td12k.tu56
V3F_BOOT_TAPE= bin/v3f-@OS8_TAPE_DEVICE@.tu56


# Absolute version of --prefix passed to configure.
PREFIX = @ABSPREFIX@

# Normally unset.  Prepended to PREFIX to install files to a
# different tree than / (e.g. for distribution build/CI scripts).
# https://www.gnu.org/prep/standards/html_node/DESTDIR.html
DESTDIR = 

RCFILE := $(PREFIX)/etc/pidp8i.rc

CLTXT = /boot/cmdline.txt

ADF := adrules.mk

OS8_PKGS_SELECTED = @OS8_PKGS_SELECTED@
OS8_PKGS_SELECTED_NAMES = @OS8_PKGS_SELECTED_NAMES@
PKGS_INCLUDE = obj/os8pkg/pkgs.os8

#### TARGETS ###########################################################

.PHONY: all tags
.PRECIOUS: $(PRECIOUS_OUTFILES)

all: \
	$(OUTFILES) $(PRECIOUS_OUTFILES) \
	$(BUILDDIRS) $(BINS) $(BOOTSCRIPTS) $(LISTINGS) \
	$(ASM_PTS) $(FC_EX_PTS) $(PAL_EX_PTS) \
	$(OS8_TOOLTIME) pkg_all \
	$(OS8_RK05S) $(V3F_MADE_RK05) $(V3D_TC08_TU56) \
	$(V3D_TD12K_TU56) $(V3F_TC08_TU56) $(V3F_TD12K_TU56)

clean:
	@rm -f $(BINS) $(BOOTSCRIPTS) $(ASM_PTS) $(PAL_EX_PTS) $(LISTINGS) \
		$(OUTFILES) $(ADF) \
		config.log cscope.out tags \
		bin/*.pt bin/*.rk05 bin/*.save bin/*.tu56 bin/txt2ptp \
		lib/*.pyc lib/*/*.pyc lib/pidp8i/dirs.py lib/pidp8i/util.py \
		lib/pidp8i/ips.py \
		obj/*.log obj/*.pt obj/os8.opts obj/os8pkg/* obj/*.rk05 \
		src/config.h src/e8/e8defs.pa \
		@srcdir@/examples/*.err
	@find obj \( -name \*.o -o -name \*.d \) -delete
	@-rmdir -p $(BUILDDIRS) 2> /dev/null || true

distclean: clean
	@rm -f \
		$(PRECIOUS_OUTFILES) \
		config.log \
		autosetup/jimsh0 \
		src/config.h

ctags tags:
	ctags -R @srcdir@/src @srcdir@/lib
ifeq (@HAVE_PROG_CSCOPE@, 1)
	cscope -bR -s@srcdir@
endif

install: install-target install-system

install-target: all instdirs
	@echo Installing to $(PREFIX)...

	@# Install most bin/* stuff and set their perms
	@for f in $(BINS) ; do \
		dest=$(PREFIX)/$$f ; \
		echo "Installing binary $$dest..." ; \
		@INSTALL@ -m 755 -D -s $$f $(DESTDIR)$$dest ; \
	done
	@for f in $(BIN_SCRIPTS) ; do \
		dest=$(PREFIX)/bin/$$(basename $$f) ; \
		echo "Installing script $$dest..." ; \
		@INSTALL@ -m 755 -D $$f $(DESTDIR)$$dest ; \
	done
	@echo "Installing txt2ptp symlink..."
	@ln -f $(DESTDIR)$(PREFIX)/bin/ptp2txt $(DESTDIR)$(PREFIX)/bin/txt2ptp
	@(	test -e $(DESTDIR)@MEDIADIR@/os8/os8.rk05 || \
		test -e $(DESTDIR)@MEDIADIR@/os8/os8v3d-bin.rk05 || \
		test -e $(DESTDIR)@MEDIADIR@/os8/v3d.rk05) && \
		echo "Skipping media image and SIMH boot script reinstall." || \
		$(MAKE) mediainstall
	@ln -f $(DESTDIR)$(PREFIX)/bin/pidp8i-sim $(DESTDIR)$(PREFIX)/bin/pdp8  # run w/o PiDP-8/I extensions
	@ln -f $(DESTDIR)$(PREFIX)/bin/pidp8i-sim $(DESTDIR)$(PREFIX)/bin/pidp8i-sim-nls  # run with forced NLS mode
	@ln -f $(DESTDIR)$(PREFIX)/bin/pidp8i-sim $(DESTDIR)$(PREFIX)/bin/pidp8i-sim-ils  # run with forced ILS mode

	@# Install CC8 stuff if built
	@test -n "@CC8_CROSS@" && \
		echo "Installing cc8 cross-compiler..." ; \
		@INSTALL@ -m 755 bin/cc8 $(DESTDIR)$(PREFIX)/bin && \
		@INSTALL@ -m 644 @srcdir@/src/cc8/include/* $(DESTDIR)$(PREFIX)/share/include

	@# Install palbart stuff
	@@INSTALL@ -m 755 bin/palbart $(DESTDIR)$(PREFIX)/bin
	@@INSTALL@ -m 644 @srcdir@/src/palbart/palbart.1 $(DESTDIR)$(PREFIX)/share/man/man1

	@# Install os8-run and its dependencies
	@echo "Installing os8-run..."
	@@INSTALL@ -m 775 -g @INSTGRP@ $(OS8RUN) $(DESTDIR)$(PREFIX)/bin
	@( for src in $(OS8RUN_PY_ALL) ; do \
		test -e $$src || src=@srcdir@/$$src ; \
		dest=$(PREFIX)/$$(echo $$src | sed -e 's_^@srcdir@/__') ; \
		echo "Installing $$src to $$dest..." ; \
	    @INSTALL@ -m 644 -g @INSTGRP@ -D $${src}  $(DESTDIR)$${dest}  ; \
	  done \
	)
	@sed -e 's#^build =.*#build = "$(PREFIX)"#' \
	     -e 's#^media =.*#media = os.path.join (build, "share/media/")#' \
	     -e 's#^os8mo =.*#os8mo = os8mi#' \
		 < $(PIDP8I_DIRS) > $(DESTDIR)$(PREFIX)/$(PIDP8I_DIRS)
	@chgrp @INSTGRP@ $(DESTDIR)$(PREFIX)/$(PIDP8I_DIRS)

	# Same for os8-cp, building on above
	@echo "Installing os8-cp..."
	@@INSTALL@ -m 775 -g @INSTGRP@ $(OS8CP) $(DESTDIR)$(PREFIX)/bin

	@# We need a directory for PIDs and such in some cases
	@@INSTALL@ -d -m 755 $(DESTDIR)$(PREFIX)/run

install-system: install-target
	@echo Installing system files and programs...

	@(test -x /sbin/setcap && \
		for f in $(PREFIX)/bin/pidp8i-* ; do \
			echo "Setting real-time priority capabilities on $$(basename $$f)..." ; \
			/sbin/setcap 'cap_sys_nice=eip' $(DESTDIR)$$f ; \
		done \
	) || true

	@# If this is a Debian-type system, install needed helper programs
	@test -x /usr/bin/apt-get -a ! -x /usr/bin/screen && apt-get -y install screen || true

	@# Remove usbmount: we've replaced that with bin/usb-mount and friends.
	@(test -x /usr/bin/apt-get -a -d /etc/usbmount && \
		apt-get -y remove usbmount > /dev/null 2>&1 \
	) || true

ifeq (@USB_AUTOMOUNT@, 1)
	@# Install the usb-mount systemd unit file and udev rules
	@(  test -d /etc/systemd && \
		@INSTALL@ -m 644 etc/usb-mount@.service /etc/systemd/system && \
		@INSTALL@ -m 644 @srcdir@/etc/udev.rules /etc/udev/rules.d/68-usb-mount.rules && \
		sed -i -e 's/MountFlags=slave/MountFlags=shared/' \
			/lib/systemd/system/systemd-udevd.service && \
		/bin/systemctl daemon-reload && \
		udevadm control --reload-rules && \
		udevadm trigger \
	) || true
endif

	@# Disable competing services if this is a Raspberry Pi
	@(test -x /bin/systemctl && /bin/systemctl disable deeper pidp8 2> /dev/null || true)

	@# Get rid of the old SysV init file if upgrading an older system.
	@(test -e /etc/init.d/pidp8i -a -e /etc/rc5.d/S*pidp8i && \
		/bin/systemctl disable pidp8i && \
		rm -f /etc/init.d/pidp8i \
	) || true

	@# Install the systemd unit file if this system is systemd based.
	@(test -x /bin/systemctl && \
		sudo -i -u @INSTUSR@ $(DESTDIR)$(PREFIX)/bin/pidp8i install && \
		/bin/loginctl enable-linger @INSTUSR@ \
	) || true

	@# Give the install user permission to use GPIO if done on a Pi
	@grep -q '^gpio:' /etc/group && usermod -a -G gpio @INSTUSR@ || true

	@# Give the install user permission to shut down and reboot the Pi
	@# if this is a systemd/sudo based system.
	@(	test -d /etc/sudoers.d -a -w /etc/sudoers.d -a -x /bin/systemctl && \
		@INSTALL@ -m 440 -o root -g root @srcdir@/etc/sudoers \
		    /etc/sudoers.d/099_pidp8i \
	) || true

	@# Install runtime config file if there isn't one there already.
	@test -f $(DESTDIR)$(RCFILE) || @INSTALL@ -m 644 -o @INSTUSR@ @srcdir@/etc/pidp8i.rc $(DESTDIR)$(RCFILE)

	@# Add installation bin dir to the non-root user's PATH unless it's
	@# already in there or we aren't running under sudo.
	@(for p in .profile .bash_profile ; do \
		test -n "$$SUDO_USER" -a -w "/home/$$SUDO_USER/$$p" && \
			! grep -qF "$(PREFIX)/bin" "/home/$$SUDO_USER/$$p" && \
			echo "export PATH=\$$PATH:$(PREFIX)/bin" >> "/home/$$SUDO_USER/$$p" ; \
	done) || true

	@# Ditto for MANPATH
	@(for p in .profile .bash_profile ; do \
		test -n "$$SUDO_USER" -a -w "/home/$$SUDO_USER/$$p" && \
			! grep -qF "$(PREFIX)/share/man" "/home/$$SUDO_USER/$$p" && \
			echo "export MANPATH=\$$MANPATH:$(PREFIX)/share/man" >> "/home/$$SUDO_USER/$$p" ; \
		done \
	) || true

	@# If serial mod is disabled, turn off serial console and kgdb stuff
	@# in case they were enabled previously, else they will fight with
	@# our use of GPIO.
	@(  test -z "@PCB_SERIAL_MOD_ANY@" -a -r $(CLTXT) && ! -w $(CLTXT) && \
		cp -p $(CLTXT) "$(CLTXT)"_orig && \
		sed -e 's/console\=[a-zA-Z0-9]+,[0-9]+ //' \
		    -e  's/kgdboc\=[a-zA-Z0-9]+,[0-9]+ //' -i $(CLTXT) \
	) || true

instdirs:
	@echo "Creating installation directory tree..."
	@for d in $(INSTDIRS) ; do @INSTALL@ -m 755 -o @INSTUSR@ -g @INSTGRP@ -d $(DESTDIR)$(PREFIX)/$$d ; done

mediainstall: instdirs
	@echo "[Re]installing OS and program media..."
	@cd @srcdir@ ; \
	find media \( \
		-name \*.bin  -o \
		-name \*.dsk  -o \
		-name \*.rk05 -o \
		-name \*.tu56 \
	\) -exec @INSTALL@ -D -m 664 -o @INSTUSR@ -g @INSTGRP@ {} $(DESTDIR)$(PREFIX)/share/{} \;
	@@INSTALL@ -m 644 -o @INSTUSR@ -g @INSTGRP@ bin/*.rk05 $(DESTDIR)$(PREFIX)/share/media/os8
	@@INSTALL@ -m 644 -o @INSTUSR@ -g @INSTGRP@ bin/*.tu56 $(DESTDIR)$(PREFIX)/share/media/os8
	for f in boot/*.script ; do \
		sed -e 's#%HOME%/\.pidp8i-#@SHAREDIR@/save/#' < $$f > $(DESTDIR)@SHAREDIR@/$$f ; \
		chown @INSTUSR@:@INSTGRP@ $(DESTDIR)@SHAREDIR@/$$f ; \
		chmod 664 $(DESTDIR)@SHAREDIR@/$$f ; \
	done

# Called by test-os8-run
# Minimizes dependencies to provoke minimal rebuilds.
# Builds cc8.tu56, copying in rather than rebuilding source and demo files.
os8-sys: test-tmp-tools
	$(OS8RUN)@OS8_OPTS@ $(V3D_DIST_SCRIPT)
	$(OS8RUN)@OS8_OPTS@ $(V3D_PATCH_SCRIPT)
	$(OS8RUN)@OS8_OPTS@ $(V3D_RK05_SCRIPT)

reconfig:
	find . -name \*.d -delete
	@AUTOREMAKE@

release: all
	@srcdir@/tools/mkrel

run: $(PIDP8I_SIM)
	@-libexec/scanswitch > /dev/null ; \
		if [ $$? = 127 ] ; then $(PDP8_SIM) boot/run.script ; \
                         else $(PIDP8I_SIM) boot/run.script ; fi 

runf run-v3f: $(PIDP8I_SIM) $(V3F_BOOT_TAPE)
	$(PIDP8I_SIM) boot/run-v3f.script

run-v3d: $(PIDP8I_SIM) $(V3D_RUNTIME)
	$(PIDP8I_SIM) boot/run-v3d.script

run-ock: $(PIDP8I_SIM) $(OCK_RUNTIME)
	$(PIDP8I_SIM) boot/run-ock.script

run-tss8: $(PIDP8I_SIM)
	$(PIDP8I_SIM) boot/tss8.script

simh-update simh-update-f:
	@@srcdir@/tools/simh-update $(subst simh-update,,$@)

# Enable this target only if all of the test-os8-run prereqs
# were installed at configure time.
ifeq (@CAN_TEST_OS8_RUN@, 1)
test-os8-run:
	tools/test-os8-run -g && tools/test-os8-run -e
endif

test-tmp-tools:
	@echo "Installing os8-run dependencies..."
	@( for src in $(OS8RUN_PY_ALL) ; do \
		test -e $$src || src=@srcdir@/$$src ; \
		dest=./$$(echo $$src | sed -e 's_^@srcdir@/__') ; \
		echo "Installing $$src to $$dest..." ; \
	    @INSTALL@ -m 644 -g @INSTGRP@ -D $${src}  $${dest}  ; \
	! test -e $${src}c || \
	    @INSTALL@ -m 644 -g @INSTGRP@ -D $${src}c $${dest}c ; \
	  done \
	)
	@( for src in $(TEST_TMP_BINS) ; do \
		test -e $$src || src=@srcdir@/$$src ; \
		dest=./$$(echo $$src | sed -e 's_^@srcdir@/__') ; \
		echo "Installing $$src to $$dest..." ; \
	    @INSTALL@ -m 755 -g @INSTGRP@ -D $${src}  $${dest}  ; \
	  done \
	)
	@( cd ./bin ; \
	   echo "Installing txt2ptp symlink..." ; \
	   ln -f ptp2txt txt2ptp ; \
	)
	@(  echo "To build cc8.tu56 copy in files from @srcdir@/obj/cc8/os8" ; \
	    mkdir -p obj/cc8/os8 ;\
	    cp -p @srcdir@/obj/cc8/os8/* obj/cc8/os8 ; \
	)


# Build the OS/8 binary media needed by 0.script.
#
# We use order-only prerequisites for the simulator here because we only
# care that it *exists*, not whether it is newer than the previously
# built RK05 media or not.
#
# Also notice that the init.tx file is not a prerequisite: we purposely
# do not rebiuld the RK05 media just because the configure script was
# re-run, which *always* regenerates the init.tx file because the
# timestamp always changes from one run to the next.  (Until computers
# get fast enough to do a complete re-configure in under a second,
# anyway!)  The thing is, we only want the RK05 bin media rebuilt when
# the configure --*-os8-* options change.  *That* is when we care about
# the updated init.tx file, not before.  We needn't even make it an
# order-only prereq because configure and the INFILES rules above ensure
# that it always exists.
V3D_DIST_SRCS := \
	$(OS8RUN) $(PIDP8I_DIN) \
	lib/pidp8i/dirs.py \
	lib/pidp8i/util.py \
	$(V3D_DIST_SCRIPT) \
	@srcdir@/src/os8/v3d/SYSTEM/LCSYS.BI \
	@srcdir@/src/os8/v3d/SYSTEM/UCSYS.BI \
	@srcdir@/src/os8/v3d/BASIC/LCBAS.BI \
	@srcdir@/src/os8/v3d/BASIC/UCBAS.BI \
	@srcdir@/media/os8/al-*-ba-*.tu56 \
	@srcdir@/media/os8/subsys/*.tu56

# Temporary: We depend on ALL the patches, but really we've picked them over.
V3D_PATCHES := \
	@srcdir@/patches/os8/v3d/*.patch8

# Dependency on the contents of the v3f source directory.
V3F_SOURCES := \
	@srcdir@/src/os8/v3f/*.PA \
	@srcdir@/src/os8/v3f/*.MA \
	@srcdir@/src/os8/v3f/*.BI

# Dependency on the contents of the ock source directory.
OS8_OCK_SYS_SOURCES := \
	@srcdir@/src/os8/ock/SYSTEM/*.PA \
	@srcdir@/src/os8/ock/SYSTEM/*.MA \
	@srcdir@/src/os8/ock/SYSTEM/*.BI \
	@srcdir@/src/os8/ock/HANDLERS/*.PA \
	@srcdir@/src/os8/ock/CUSPS/*.MA \
	@srcdir@/src/os8/ock/CUSPS/*.BI \
	@srcdir@/src/os8/ock/CUSPS/*.HL

OS8_OCK_CUSPS_SOURCES :=\
	@srcdir@/src/os8/ock/CUSPS/*.PA

OS8_OCK_BF2_SOURCES := \
	@srcdir@/src/os8/ock/LANGUAGE/BASIC/*.PA \
	@srcdir@/src/os8/ock/LANGUAGE/BASIC/*.BA \
	@srcdir@/src/os8/ock/LANGUAGE/BASIC/*.BI \
	@srcdir@/src/os8/ock/LANGUAGE/FORTRAN2/*.PA \
	@srcdir@/src/os8/ock/LANGUAGE/FORTRAN2/*.CO \
	@srcdir@/src/os8/ock/LANGUAGE/FORTRAN2/LIBRARY/*.SB

OS8_OCK_FIV_SOURCES := \
	@srcdir@/src/os8/ock/LANGUAGE/FORTRAN4/*.PA \
	@srcdir@/src/os8/ock/LANGUAGE/FORTRAN4/*.BI \
	@srcdir@/src/os8/ock/LANGUAGE/FORTRAN4/LIBRARY/*.RA

# We could make FIV conditional here.
OS8_OCK_DIST_SRCS := \
	$(OS8RUN) $(PIDP8I_DIN) \
	lib/pidp8i/dirs.py \
	lib/pidp8i/util.py \
	$(OS8_OCK_DIST_MAKER) \
	@srcdir@/media/os8/al-*-ba-*.tu56 \
	@srcdir@/media/os8/subsys/*.tu56 \
	$(OS8_OCK_SYS_OBJ_RK05) $(OS8_OCK_CUSPS_OBJ_RK05) \
	$(OS8_OCK_BF2_OBJ_RK05) $(OS8_OCK_FIV_OBJ_RK05)

OCK_PATCHES := \
	@srcdir@/patches/os8/ock/*.patch8

$(OS8_BASELINE): $(V3D_DIST_SRCS) | $(PIDP8I_SIM) $(OS8RUN_OUTFILES)
	$(OS8RUN)@OS8_OPTS@ $(V3D_DIST_SCRIPT)

$(OS8_TOOLTIME): $(V3D_PATCH_SCRIPT) $(OS8_BASELINE) $(V3D_PATCHES) | $(PIDP8I_SIM) $(OS8RUN_OUTFILES)
	$(OS8RUN)@OS8_OPTS@ $(V3D_PATCH_SCRIPT)

-include obj/os8pkg/*.mk

# Extension of "all" rule to build all packages now that we've included
# the rules for doing so. If you move the autosetup variable below into
# the "all" target dependency list, it won't work because it references
# undefined variables.
pkg_all:@OS8_PKGS_ALL@

test: all
	tools/os8-progtest -x @OS8_PKGS_TESTING@

$(V3D_RUNTIME): $(V3D_RK05_SCRIPT) $(OS8_TOOLTIME) $(PKGS_INCLUDE) $(OS8_PKGS_SELECTED) | $(PIDP8I_SIM) $(OS8RUN_OUTFILES)
	$(OS8RUN) @OS8_OPTS@ $(V3D_RK05_SCRIPT)


$(OS8_OCK_PATCHED_RK05): $(OS8_OCK_PATCHED_MAKER) $(OS8_OCK_DIST_RK05) $(OCK_PATCHES) | $(PIDP8I_SIM) $(OS8RUN_OUTFILES)
	$(OS8RUN)@OS8_OPTS@ $(OS8_OCK_PATCHED_MAKER)

$(OCK_RUNTIME): $(OS8_OCK_BOOT_MAKER) $(OS8_OCK_PATCHED_RK05) $(PKGS_INCLUDE) $(OS8_PKGS_SELECTED) | $(PIDP8I_SIM) $(OS8RUN_OUTFILES)
	$(OS8RUN)@OS8_OPTS@ $(OS8_OCK_BOOT_MAKER)

# To build the magic includer, we should depend on all the created packages.
# Then a newly created one that we care about will drive creation of the include script.
$(PKGS_INCLUDE): $(OS8_PKGS_SELECTED)
	bin/os8pkg include $(OS8_PKGS_SELECTED_NAMES)


# Also build an OS/8 source disk, as a convenience to avoid the 
# need to mount up the 7 source tapes in succession.
#
# Using an order-only dependency for the simulator and the bin disk: we
# only need *a* version of each, they don't have to be recent!
OS8_SRC_SRCS = \
	$(OS8RUN) $(PIDP8I_DIN) \
	lib/pidp8i/dirs.py \
	lib/pidp8i/util.py \
	$(V3D_SRC_SCRIPT) \
	@srcdir@/media/os8/al-*-sa-*.tu56

$(OS8_SRC_RK05): $(OS8_BASELINE) $(OS8_SRC_SRCS) | $(PIDP8I_SIM) $(OS8_TOOLTIME)
	$(OS8RUN)@OS8_OPTS@ $(V3D_SRC_SCRIPT)

# Build the source disk for OS/8 V3F
$(V3F_BUILD_RK05): $(V3F_SRCDIR)/$(V3F_MANIFEST) $(V3F_SOURCES) | $(OS8_TOOLTIME)
	rm -f $(V3F_BUILD_RK05)
	cd $(V3F_SRCDIR); @builddir@/$(OS8CP) -v --action-file $(V3F_MANIFEST)

# Make a disk with binaries assembled from the V3F source disk
$(V3F_MADE_RK05): $(V3F_BUILD_RK05) $(V3F_MAKER)
	$(OS8RUN) $(V3F_MAKER)

# Build the source disk for OS/8 OCK SYS Component.
$(OS8_OCK_SYS_SRC_RK05): $(OS8_OCK_SYS_SOURCES) | $(OS8_TOOLTIME)
	@builddir@/$(OS8CP) -v -rk1 $(OS8_OCK_SYS_SRC_RK05) -z -a $(OS8_OCK_SYS_SOURCES) RKA1:

# Make a disk with binaries assembled from the OS8_OCK SYS source disk
$(OS8_OCK_SYS_OBJ_RK05): $(OS8_OCK_SYS_SRC_RK05) $(OS8_OCK_SYS_MAKER)
	$(OS8RUN) $(OS8_OCK_SYS_MAKER)

# Build the source disk for OS/8 OCK CUSPS Component.
$(OS8_OCK_CUSPS_SRC_RK05): $(OS8_OCK_CUSPS_SOURCES) | $(OS8_TOOLTIME)
	@builddir@/$(OS8CP) -v -rk1 $(OS8_OCK_CUSPS_SRC_RK05) -z -a $(OS8_OCK_CUSPS_SOURCES) RKA1:

# Make a disk with binaries assembled from the OS8_OCK SYS source disk
$(OS8_OCK_CUSPS_OBJ_RK05): $(OS8_OCK_CUSPS_SRC_RK05) $(OS8_OCK_CUSPS_MAKER)
	$(OS8RUN) $(OS8_OCK_CUSPS_MAKER)

# Build the source disk for OS/8 OCK BASIC and FORTRAN II Component.
$(OS8_OCK_BF2_SRC_RK05): $(OS8_OCK_BF2_SOURCES) | $(OS8_TOOLTIME)
	@builddir@/$(OS8CP) -v -rk1 $(OS8_OCK_BF2_SRC_RK05) -z -a $(OS8_OCK_BF2_SOURCES) RKA1:

# Make a disk with binaries assembled from the OS8_OCK FIRTRAN II source disk
$(OS8_OCK_BF2_OBJ_RK05): $(OS8_OCK_BF2_SRC_RK05) $(OS8_OCK_BF2_MAKER)
	$(OS8RUN) $(OS8_OCK_BF2_MAKER)

# Build the source disk for OS/8 OCK FORTRAN IV Component.
$(OS8_OCK_FIV_SRC_RK05): $(OS8_OCK_FIV_SOURCES) | $(OS8_TOOLTIME)
	@builddir@/$(OS8CP) -v -rk1 $(OS8_OCK_FIV_SRC_RK05) -z -a $(OS8_OCK_FIV_SOURCES) RKA1:

# Make a disk with binaries assembled from the OS8_OCK FORTRAN IV source disk
$(OS8_OCK_FIV_OBJ_RK05): $(OS8_OCK_FIV_SRC_RK05) $(OS8_OCK_FIV_MAKER)
	$(OS8RUN) $(OS8_OCK_FIV_MAKER)

$(OS8_OCK_DIST_RK05): $(OS8_OCK_DIST_SRCS) | $(PIDP8I_SIM) $(OS8RUN_OUTFILES)
	$(OS8RUN)@OS8_OPTS@ $(OS8_OCK_DIST_MAKER)

# Make a bootable OS/8 v3f TCO8 DECtape image
$(V3F_TC08_TU56): $(V3F_MADE_RK05) $(ALL_TU56_SCRIPT) $(CUSP_COPYIN_SCRIPT)
	$(OS8RUN)@OS8_OPTS@ $(ALL_TU56_SCRIPT) --enable v3f

# Make a bootable OS/8 v3f TD8E 12K DECtape image
$(V3F_TD12K_TU56): $(V3F_MADE_RK05) $(ALL_TU56_SCRIPT) $(CUSP_COPYIN_SCRIPT)
	$(OS8RUN)@OS8_OPTS@ $(ALL_TU56_SCRIPT) --enable v3f --enable td12k

# Make a bootable OS/8 v3d TCO8 DECtape image
$(V3D_TC08_TU56): $(ALL_TU56_SCRIPT) $(CUSP_COPYIN_SCRIPT) | $(OS8_TOOLTIME) 
	$(OS8RUN)@OS8_OPTS@ $(ALL_TU56_SCRIPT)

# Make a bootable OS/8 v3d TD8E 12K DECtape image
$(V3D_TD12K_TU56): $(ALL_TU56_SCRIPT) $(CUSP_COPYIN_SCRIPT) | $(OS8_TOOLTIME) 
	$(OS8RUN)@OS8_OPTS@ $(ALL_TU56_SCRIPT) --enable td12k

# Rule for building PAL assembly language programs in src/asm/*.pal.
obj/%.lst bin/%-pal.pt: @srcdir@/src/asm/%.pal bin/palbart
	bin/palbart -lr $< || cat obj/$*.err
	mv @srcdir@/src/asm/$*.lst obj
	mv @srcdir@/src/asm/$*.rim bin/$*-pal.pt

# Ditto for those in examples/*.pal.
obj/%.lst bin/%-pal.pt: @srcdir@/examples/%.pal bin/palbart
	bin/palbart -lr $< || cat obj/$*.err
	mv @srcdir@/examples/$*.lst obj
	mv @srcdir@/examples/$*.rim bin/$*-pal.pt

# Rule for converting ASCII FOCAL examples in examples/*.fc to
# bin/*-focal.pt.
bin/%-focal.pt: @srcdir@/examples/%.fc bin/txt2ptp
	bin/txt2ptp < $< > bin/$*-focal.pt

# Rule for translating PAL assembly language program listings to SIMH
# boot scripts.
boot/%.script: obj/%.lst
	@srcdir@/tools/mkbootscript $<

# Rules for making aliases of named example programs translated to boot
# scripts as special numbered boot scripts
boot/1.script: boot/hs-rim-loader.script
	ln -f $< $@
boot/5.script: boot/ac-mq-blinker.script
	ln -f $< $@

# Rule for using the cross compiler to create SABR .sb files
# CC8 builds in current working dir.  So we move the file.
obj/cc8/os8/%.sb: @srcdir@/src/cc8/os8/%.c bin/cc8
	cd @srcdir@/src/cc8/os8; ../../../bin/cc8 $*.c
	mv  @srcdir@/src/cc8/os8/$*.sb $@

# Rule for processing cc8 examples into a form usable
# by the native OS/8 C compiler.
obj/cc8/os8/%.c: @srcdir@/src/cc8/examples/%.c
	sed '/^#include/d' $< > $@

$(BUILDDIRS):
	mkdir -p $@

$(PIDP8I_SIM): $(SIM_OBJS) $(GPIO_OBJS)  $(PIDP8I_OBJS) $(LED_OBJ)
	$(CC) -o $@ $^ $(LIBS) $(SIM_LFLAGS)
	ln -f bin/pidp8i-sim bin/pdp8
	ln -f bin/pidp8i-sim bin/pidp8i-sim-nls
	ln -f bin/pidp8i-sim bin/pidp8i-sim-ils

bin/cc8: $(CC8_OBJS)
	$(CC) $(CC8_CROSS_CFLAGS) -o $@ $^ $(LIBS)

bin/d8tape: $(D8TAPE_OBJS)
	$(CC) $(D8TAPE_CFLAGS) -o $@ $^

bin/palbart: $(PALBART_OBJS)
	$(CC) $(PALBART_CFLAGS) -o $@ $^

bin/ptp2txt: obj/misc/ptp2txt.o
	$(CC) -o $@ $^
	ln -f bin/ptp2txt bin/txt2ptp

bin/txt2ptp: bin/ptp2txt
	ln -f bin/ptp2txt bin/txt2ptp

# The deeper, pidp8i-test, and scanswitch programs only make sense if we
# have actual PiDP8i hardware
ifeq (@BUILD_PIDP8I@, 1)
bin/pidp8i-test: $(GPIO_OBJS) obj/misc/test.o obj/pidp8i/gpio-nls.o
	$(CC) -o $@ $(CFLAGS) $^ $(LIBS) -lncurses

bin/deeper: obj/misc/deeper.o $(LED_OBJ) $(GPIO_OBJS)
	$(CC) -o $@ $(CFLAGS) $^ $(LIBS)

libexec/scanswitch: $(GPIO_OBJS) obj/misc/scanswitch.o obj/pidp8i/gpio-nls.o
	$(CC) -o $@ $(CFLAGS) $^ $(LIBS)
endif

doc/e8-manual.pdf: doc/e8-manual.md
	tools/mkmanpdf doc/e8-manual

# Reconfigure whenever one of the *.in or autosetup files changes unless
# this is "make clean".
# 
# We purposely list only one of the OUTFILES on the left hand side
# because to list them all is to invite Make to run N copies of the
# configure script in parallel up to the limit of -j or the number of
# files in INFILES, whichever is lower.  Order-only prerequisites can't
# help here (|) as that only affects the right hand side.
ifeq ($(findstring clean,$(MAKECMDGOALS)),)
media/os8/init.tx: $(INFILES) $(PRECIOUS_INFILES) @AUTODEPS@
	@AUTOREMAKE@ && $(MAKE)

# Also do it if the autodep tool is newer than its output, suggesting
# that if re-run, it would generate different output.
$(ADF): @srcdir@/tools/mkadrules
	@AUTOREMAKE@ && $(MAKE)
endif

# Rebuild simulator if the version string tool changes, since its output
# may have changed.
src/pidp8i/gpio-common.c: @srcdir@/tools/version

# Pull in *.d files generated by the autodependency mechanism.  See the
# header comment of tools/mkadrules.
-include \
	$(SIM_OBJS:.o=.d) \
	$(CC8_OBJS:.o=.d) \
	$(D8TAPE_OBJS:.o=.d) \
	$(PALBART_OBJS:.o=.d) \
	$(GPIO_OBJS_OBJS:.o=.d) \
	$(PIDP8I_OBJS:.o=.d) \
	$(LED_OBJ:.o=.d) \
	$(MISC_OBJS:.o=.d)

-include $(ADF)

