From e0a001f8c0054134b6218bb523c48f6bbbb56c77 Mon Sep 17 00:00:00 2001 From: Avery Terrel Date: Sun, 6 Apr 2025 05:26:03 -0500 Subject: [PATCH 1/4] Add initial autoconf support --- .gitignore | 8 +++++++ Makefile | 63 ------------------------------------------------- Makefile.am | 1 + configure.ac | 11 +++++++++ src/.gitignore | 1 + src/Makefile.am | 7 ++++++ src/main.c | 2 +- 7 files changed, 29 insertions(+), 64 deletions(-) delete mode 100644 Makefile create mode 100644 Makefile.am create mode 100644 configure.ac create mode 100644 src/.gitignore create mode 100644 src/Makefile.am diff --git a/.gitignore b/.gitignore index 66bf841..f431b50 100644 --- a/.gitignore +++ b/.gitignore @@ -14,3 +14,11 @@ fox32.html fox32.wasm fox32.js fox32.data + +Makefile +Makefile.in +configure +config.h.in +aclocal.m4 +autom4te.cache +build-aux diff --git a/Makefile b/Makefile deleted file mode 100644 index c0f85dd..0000000 --- a/Makefile +++ /dev/null @@ -1,63 +0,0 @@ -TARGET = linux -ifeq ($(TARGET),linux) -# default is used for CC -SDL2_CONFIG = sdl2-config -CFLAGS += -g -Ofast -std=c99 -Wall -Wextra `$(SDL2_CONFIG) --cflags` -LDFLAGS += `$(SDL2_CONFIG) --libs` -else -ifeq ($(TARGET),aarch64-darwin) -SDL2_CONFIG = sdl2-config -CFLAGS += -g -Ofast -std=c99 -Wall -Wextra -I`$(SDL2_CONFIG) --prefix`/include -D_THREAD_SAFE -LDFLAGS += `$(SDL2_CONFIG) --libs` -else -ifeq ($(TARGET),mingw) -CC = x86_64-w64-mingw32-gcc -SDL2_CONFIG = /usr/local/x86_64-w64-mingw32/bin/sdl2-config -CFLAGS += -g -Ofast -std=c99 -Wall -Wextra -DWINDOWS -I/usr/local/x86_64-w64-mingw32/include -Dmain=SDL_main -LDFLAGS += -lmingw32 -lSDL2main -lSDL2 -L/usr/local/x86_64-w64-mingw32/lib -lmingw32 -lSDL2main -lSDL2 -mwindows -TARGET_FILE_EXTENSION = .exe -else -ifeq ($(TARGET),wasm) -CC = emcc -CFLAGS += -O3 -std=c99 -Wall -Wextra -LDFLAGS += -s TOTAL_MEMORY=70057984 -sALLOW_MEMORY_GROWTH=1 -sUSE_SDL=2 --preload-file fox32os.img -TARGET_EXTRADEPS = fox32os.img -TARGET_FILE_EXTENSION = .html -else -$(error unknown TARGET) -endif -endif -endif -endif - -CFILES = src/main.c \ - src/bus.c \ - src/cpu.c \ - src/disk.c \ - src/framebuffer.c \ - src/keyboard.c \ - src/mmu.c \ - src/mouse.c \ - src/screen.c \ - src/serial.c - -OBJS = $(addsuffix .o, $(basename $(CFILES))) - -.PHONY: all -all: fox32$(TARGET_FILE_EXTENSION) - -FOX32ROM_IN = fox32.rom -FOX32ROM_OUT = fox32rom.h - -$(FOX32ROM_OUT): $(FOX32ROM_IN) - xxd -i $(FOX32ROM_IN) $(FOX32ROM_OUT) - sed -i -e 's/fox32_rom/fox32rom/' $(FOX32ROM_OUT) - -fox32$(TARGET_FILE_EXTENSION): $(TARGET_EXTRADEPS) $(OBJS) - $(CC) -o $@ $(OBJS) $(LDFLAGS) - -%.o: %.c $(FOX32ROM_OUT) - $(CC) -o $@ -c $< $(CFLAGS) - -clean: - rm -rf fox32 fox32.exe fox32.wasm fox32.html fox32.data fox32.js fox32rom.h $(OBJS) diff --git a/Makefile.am b/Makefile.am new file mode 100644 index 0000000..af437a6 --- /dev/null +++ b/Makefile.am @@ -0,0 +1 @@ +SUBDIRS = src diff --git a/configure.ac b/configure.ac new file mode 100644 index 0000000..0af4ba4 --- /dev/null +++ b/configure.ac @@ -0,0 +1,11 @@ +AC_INIT([fox32], [0.7.1], [https://github.com/fox32-arch]) +AC_CONFIG_AUX_DIR([build-aux]) +AM_INIT_AUTOMAKE([foreign -Wall -Werror]) +AC_PROG_CC +AC_PROG_SED +AC_CHECK_HEADER([fox32rom.h], [], + [AC_MSG_ERROR([fox32rom.h is required but not found])]) +PKG_CHECK_MODULES([SDL], [sdl2], [], [AC_MSG_ERROR([SDL2 is required but not found])]) +AC_CONFIG_HEADERS([config.h]) +AC_CONFIG_FILES([Makefile src/Makefile]) +AC_OUTPUT diff --git a/src/.gitignore b/src/.gitignore new file mode 100644 index 0000000..39a0668 --- /dev/null +++ b/src/.gitignore @@ -0,0 +1 @@ +.deps diff --git a/src/Makefile.am b/src/Makefile.am new file mode 100644 index 0000000..345b489 --- /dev/null +++ b/src/Makefile.am @@ -0,0 +1,7 @@ +bin_PROGRAMS = fox32 +fox32_SOURCES = bus.c cpu.c disk.c framebuffer.c keyboard.c main.c mmu.c \ + mouse.c screen.c serial.c \ + bus.h cpu.h disk.h framebuffer.h keyboard.h mmu.h mouse.h \ + screen.h serial.h +fox32_CFLAGS = $(SDL_CFLAGS) +fox32_LDADD = $(SDL_LIBS) diff --git a/src/main.c b/src/main.c index 406c280..c24191f 100644 --- a/src/main.c +++ b/src/main.c @@ -22,7 +22,7 @@ #include "screen.h" #include "serial.h" -#include "../fox32rom.h" +#include #define FPS 60 #define TPF 1 From 7ec63a1c9bb531218e365051c1145306391911ba Mon Sep 17 00:00:00 2001 From: Avery Terrel Date: Sun, 6 Apr 2025 18:32:32 -0500 Subject: [PATCH 2/4] Smooth release procedure, add docs --- Makefile.am | 7 ++ build-aux/git-version-gen | 227 ++++++++++++++++++++++++++++++++++++++ configure.ac | 4 +- docs/releasing.md | 8 ++ 4 files changed, 244 insertions(+), 2 deletions(-) create mode 100755 build-aux/git-version-gen create mode 100644 docs/releasing.md diff --git a/Makefile.am b/Makefile.am index af437a6..240a205 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1 +1,8 @@ SUBDIRS = src +EXTRA_DIST = $(top_srcdir)/.version +BUILT_SOURCES = $(top_srcdir)/.version +$(top_srcdir)/.version: + echo '$(VERSION)' > $@-t + mv $@-t $@ +dist-hook: + echo '$(VERSION)' > $(distdir)/.tarball-version diff --git a/build-aux/git-version-gen b/build-aux/git-version-gen new file mode 100755 index 0000000..aa168e1 --- /dev/null +++ b/build-aux/git-version-gen @@ -0,0 +1,227 @@ +#!/bin/sh +# Print a version string. +scriptversion=2022-07-09.08; # UTC + +# Copyright (C) 2007-2024 Free Software Foundation, Inc. +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +# This script is derived from GIT-VERSION-GEN from GIT: https://git-scm.com/. +# It may be run two ways: +# - from a git repository in which the "git describe" command below +# produces useful output (thus requiring at least one signed tag) +# - from a non-git-repo directory containing a .tarball-version file, which +# presumes this script is invoked like "./git-version-gen .tarball-version". + +# In order to use intra-version strings in your project, you will need two +# separate generated version string files: +# +# .tarball-version - present only in a distribution tarball, and not in +# a checked-out repository. Created with contents that were learned at +# the last time autoconf was run, and used by git-version-gen. Must not +# be present in either $(srcdir) or $(builddir) for git-version-gen to +# give accurate answers during normal development with a checked out tree, +# but must be present in a tarball when there is no version control system. +# Therefore, it cannot be used in any dependencies. GNUmakefile has +# hooks to force a reconfigure at distribution time to get the value +# correct, without penalizing normal development with extra reconfigures. +# +# .version - present in a checked-out repository and in a distribution +# tarball. Usable in dependencies, particularly for files that don't +# want to depend on config.h but do want to track version changes. +# Delete this file prior to any autoconf run where you want to rebuild +# files to pick up a version string change; and leave it stale to +# minimize rebuild time after unrelated changes to configure sources. +# +# As with any generated file in a VC'd directory, you should add +# /.version to .gitignore, so that you don't accidentally commit it. +# .tarball-version is never generated in a VC'd directory, so needn't +# be listed there. +# +# Use the following line in your configure.ac, so that $(VERSION) will +# automatically be up-to-date each time configure is run (and note that +# since configure.ac no longer includes a version string, Makefile rules +# should not depend on configure.ac for version updates). +# +# AC_INIT([GNU project], +# m4_esyscmd([build-aux/git-version-gen .tarball-version]), +# [bug-project@example]) +# +# Then use the following lines in your Makefile.am, so that .version +# will be present for dependencies, and so that .version and +# .tarball-version will exist in distribution tarballs. +# +# EXTRA_DIST = $(top_srcdir)/.version +# BUILT_SOURCES = $(top_srcdir)/.version +# $(top_srcdir)/.version: +# echo '$(VERSION)' > $@-t +# mv $@-t $@ +# dist-hook: +# echo '$(VERSION)' > $(distdir)/.tarball-version + + +me=$0 + +year=`expr "$scriptversion" : '\([^-]*\)'` +version="git-version-gen $scriptversion + +Copyright (C) ${year} Free Software Foundation, Inc. +License GPLv3+: GNU GPL version 3 or later . +This is free software: you are free to change and redistribute it. +There is NO WARRANTY, to the extent permitted by law." + +usage="\ +Usage: $me [OPTION]... \$srcdir/.tarball-version [TAG-NORMALIZATION-SED-SCRIPT] +Print a version string. + +Options: + + --prefix PREFIX prefix of git tags (default 'v') + --fallback VERSION + fallback version to use if \"git --version\" fails + + --help display this help and exit + --version output version information and exit + +Send patches and bug reports to ." + +prefix=v +fallback= + +while test $# -gt 0; do + case $1 in + --help) echo "$usage"; exit 0;; + --version) echo "$version"; exit 0;; + --prefix) shift; prefix=${1?};; + --fallback) shift; fallback=${1?};; + -*) + echo "$0: Unknown option '$1'." >&2 + echo "$0: Try '--help' for more information." >&2 + exit 1;; + *) + if test "x$tarball_version_file" = x; then + tarball_version_file="$1" + elif test "x$tag_sed_script" = x; then + tag_sed_script="$1" + else + echo "$0: extra non-option argument '$1'." >&2 + exit 1 + fi;; + esac + shift +done + +if test "x$tarball_version_file" = x; then + echo "$usage" + exit 1 +fi + +tag_sed_script="${tag_sed_script:-s/x/x/}" + +nl=' +' + +# Avoid meddling by environment variable of the same name. +v= +v_from_git= + +# First see if there is a tarball-only version file. +# then try "git describe", then default. +if test -f $tarball_version_file +then + v=`cat $tarball_version_file` || v= + case $v in + *$nl*) v= ;; # reject multi-line output + esac + test "x$v" = x \ + && echo "$0: WARNING: $tarball_version_file is damaged" 1>&2 +fi + +if test "x$v" != x +then + : # use $v +# Otherwise, if there is at least one git commit involving the working +# directory, and "git describe" output looks sensible, use that to +# derive a version string. +elif test "`git log -1 --pretty=format:x . 2>&1`" = x \ + && v=`git describe --abbrev=4 --match="$prefix*" HEAD 2>/dev/null \ + || git describe --abbrev=4 HEAD 2>/dev/null` \ + && v=`printf '%s\n' "$v" | sed "$tag_sed_script"` \ + && case $v in + $prefix[0-9]*) ;; + *) (exit 1) ;; + esac +then + # Is this a new git that lists number of commits since the last + # tag or the previous older version that did not? + # Newer: v6.10-77-g0f8faeb + # Older: v6.10-g0f8faeb + vprefix=`expr "X$v" : 'X\(.*\)-g[^-]*$'` || vprefix=$v + case $vprefix in + *-*) : git describe is probably okay three part flavor ;; + *) + : git describe is older two part flavor + # Recreate the number of commits and rewrite such that the + # result is the same as if we were using the newer version + # of git describe. + vtag=`echo "$v" | sed 's/-.*//'` + commit_list=`git rev-list "$vtag"..HEAD 2>/dev/null` \ + || { commit_list=failed; + echo "$0: WARNING: git rev-list failed" 1>&2; } + numcommits=`echo "$commit_list" | wc -l` + v=`echo "$v" | sed "s/\(.*\)-\(.*\)/\1-$numcommits-\2/"`; + test "$commit_list" = failed && v=UNKNOWN + ;; + esac + + # Change the penultimate "-" to ".", for version-comparing tools. + # Remove the "g" to save a byte. + v=`echo "$v" | sed 's/-\([^-]*\)-g\([^-]*\)$/.\1-\2/'`; + v_from_git=1 +elif test "x$fallback" = x || git --version >/dev/null 2>&1; then + v=UNKNOWN +else + v=$fallback +fi + +v=`echo "$v" |sed "s/^$prefix//"` + +# Test whether to append the "-dirty" suffix only if the version +# string we're using came from git. I.e., skip the test if it's "UNKNOWN" +# or if it came from .tarball-version. +if test "x$v_from_git" != x; then + # Don't declare a version "dirty" merely because a timestamp has changed. + git update-index --refresh > /dev/null 2>&1 + + dirty=`exec 2>/dev/null;git diff-index --name-only HEAD` || dirty= + case "$dirty" in + '') ;; + *) # Append the suffix only if there isn't one already. + case $v in + *-dirty) ;; + *) v="$v-dirty" ;; + esac ;; + esac +fi + +# Omit the trailing newline, so that m4_esyscmd can use the result directly. +printf %s "$v" + +# Local variables: +# eval: (add-hook 'before-save-hook 'time-stamp) +# time-stamp-start: "scriptversion=" +# time-stamp-format: "%:y-%02m-%02d.%02H" +# time-stamp-time-zone: "UTC0" +# time-stamp-end: "; # UTC" +# End: diff --git a/configure.ac b/configure.ac index 0af4ba4..cb76a8f 100644 --- a/configure.ac +++ b/configure.ac @@ -1,6 +1,6 @@ -AC_INIT([fox32], [0.7.1], [https://github.com/fox32-arch]) +AC_INIT([fox32], [m4_esyscmd([build-aux/git-version-gen .tarball-version])], [https://github.com/fox32-arch]) AC_CONFIG_AUX_DIR([build-aux]) -AM_INIT_AUTOMAKE([foreign -Wall -Werror]) +AM_INIT_AUTOMAKE([tar-ustar dist-zip foreign -Wall -Werror]) AC_PROG_CC AC_PROG_SED AC_CHECK_HEADER([fox32rom.h], [], diff --git a/docs/releasing.md b/docs/releasing.md new file mode 100644 index 0000000..0d89613 --- /dev/null +++ b/docs/releasing.md @@ -0,0 +1,8 @@ +- [ ] delete /.version +- [ ] create commit "Prepare for release " +- [ ] create tag "Release " +- [ ] `autoreconf -i` +- [ ] `./configure` +- [ ] `make distcheck VERSION=` +- [ ] upload fox32-VERSION.tar.gz, fox32-VERSION.zip +- [ ] create /.version with "" contents From 9e1fccf46812739cb999aec618861723b2065f12 Mon Sep 17 00:00:00 2001 From: Avery Terrel Date: Sun, 6 Apr 2025 22:59:51 -0500 Subject: [PATCH 3/4] Portable serial configuration --- configure.ac | 21 ++++++++++++++++++++- src/bus.c | 2 +- src/main.c | 2 +- src/serial.c | 2 +- 4 files changed, 23 insertions(+), 4 deletions(-) diff --git a/configure.ac b/configure.ac index cb76a8f..abdddf8 100644 --- a/configure.ac +++ b/configure.ac @@ -1,11 +1,30 @@ -AC_INIT([fox32], [m4_esyscmd([build-aux/git-version-gen .tarball-version])], [https://github.com/fox32-arch]) +AC_INIT([fox32], + [m4_esyscmd([build-aux/git-version-gen .tarball-version])], + [https://github.com/fox32-arch]) AC_CONFIG_AUX_DIR([build-aux]) AM_INIT_AUTOMAKE([tar-ustar dist-zip foreign -Wall -Werror]) AC_PROG_CC AC_PROG_SED + AC_CHECK_HEADER([fox32rom.h], [], [AC_MSG_ERROR([fox32rom.h is required but not found])]) PKG_CHECK_MODULES([SDL], [sdl2], [], [AC_MSG_ERROR([SDL2 is required but not found])]) + +AC_ARG_ENABLE([serial], + [AS_HELP_STRING([--disable-serial], + [Disable serial support @<:@enabled@:>@])], + [], + [enable_serial=yes]) +AS_IF([test ! "x$enable_serial" = xno], [ + AC_CHECK_HEADER([sys/select.h], [], [ + AC_MSG_ERROR([sys/select.h is required but not found]) + ]) + AC_CHECK_FUNC([tcgetattr], [], [ + AC_MSG_ERROR([tcgetattr required but not found]) + ]) + ]) + +AM_CONDITIONAL([ENABLE_SERIAL], [test "x$enable_serial" != xno]) AC_CONFIG_HEADERS([config.h]) AC_CONFIG_FILES([Makefile src/Makefile]) AC_OUTPUT diff --git a/src/bus.c b/src/bus.c index 41749fd..aa57312 100644 --- a/src/bus.c +++ b/src/bus.c @@ -30,7 +30,7 @@ extern mouse_t mouse; int bus_io_read(void *user, uint32_t *value, uint32_t port) { (void) user; switch (port) { -#ifndef WINDOWS +#ifdef ENABLE_SERIAL case 0x00000000: { // serial port *value = serial_get(); break; diff --git a/src/main.c b/src/main.c index c24191f..a13fd22 100644 --- a/src/main.c +++ b/src/main.c @@ -141,7 +141,7 @@ int main(int argc, char *argv[]) { ScreenDraw(); } -#ifndef WINDOWS +#ifdef ENABLE_SERIAL serial_init(); #endif diff --git a/src/serial.c b/src/serial.c index ef80355..1a01871 100644 --- a/src/serial.c +++ b/src/serial.c @@ -1,5 +1,5 @@ #include -#ifndef WINDOWS +#ifdef ENABLE_SERIAL #include #include #include From 9d476cd52bfb7c3fdf32c3ccb634d2ce62cb06f6 Mon Sep 17 00:00:00 2001 From: Avery Terrel Date: Sun, 6 Apr 2025 23:14:59 -0500 Subject: [PATCH 4/4] Fix workflow --- .github/workflows/fox32-unstable-linux.yml | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/.github/workflows/fox32-unstable-linux.yml b/.github/workflows/fox32-unstable-linux.yml index 137636f..2d3ffe0 100644 --- a/.github/workflows/fox32-unstable-linux.yml +++ b/.github/workflows/fox32-unstable-linux.yml @@ -24,14 +24,17 @@ jobs: run: | mv fox32.rom/ download/ cp download/fox32.rom ./fox32.rom + cp download/fox32rom.h src/fox32rom.h - - name: Install libsdl2-dev and vim + - name: Install libsdl2-dev run: | sudo apt update - sudo apt install -y libsdl2-dev vim + sudo apt install -y libsdl2-dev - name: Build - run: make + run: | + ./configure + make - name: Upload Artifact uses: actions/upload-artifact@v4