From fb37e080f956ef0b421defbe174a921b4ad781c8 Mon Sep 17 00:00:00 2001 From: Stas Sergeev Date: Tue, 17 Dec 2024 20:25:32 +0300 Subject: [PATCH 1/3] make: sanitize variable names --- src/libc/dj64/makefile | 12 ++++++------ src/libc/dj64/parsers/mkproto.sh | 2 +- src/makefile.def | 10 ++++------ src/makefile.inc | 4 ++-- 4 files changed, 13 insertions(+), 15 deletions(-) diff --git a/src/libc/dj64/makefile b/src/libc/dj64/makefile index 64a35fd7..e2806c44 100644 --- a/src/libc/dj64/makefile +++ b/src/libc/dj64/makefile @@ -22,8 +22,8 @@ thunk_syms.o: thunk_syms.s ALL_AS_OBJS = $(addprefix ../,$(file < $(TOP)/makefile.rfo)) libc_tmp.a : $(TOP)/makefile.rfo thunk_syms.o $(ALL_AS_OBJS) @-$(RM) $@ - $(CROSS_ASAR) q $@ $(ALL_AS_OBJS) thunk_syms.o - $(CROSS_ASAR) s $@ + $(CROSS_AR) q $@ $(ALL_AS_OBJS) thunk_syms.o + $(CROSS_AR) s $@ asm_incs.h: $(GA) 0 $(TOP)/../../include >$@ @@ -78,13 +78,13 @@ $(LIB)/$(LIBS): $(TOP)/makefile.rf $(ALL_OBJS) \ $(LIB)/libc.a: libc_tmp.a plt.o | $(LIB) cp -f $< libctmp.a - $(CROSS_ASAR) q libctmp.a plt.o - $(CROSS_ASAR) s libctmp.a + $(CROSS_AR) q libctmp.a plt.o + $(CROSS_AR) s libctmp.a mv -f libctmp.a $@ $(LIB)/crt0.elf: $(LIB)/libc.a - $(CROSS_ASLD) --whole-archive $< -melf_i386 -static -o $@ - $(CROSS_ASSTRIP) --strip-debug $@ + $(CROSS_LD) --whole-archive $< -melf_i386 -static -o $@ + $(CROSS_STRIP) --strip-debug $@ chmod -x $@ $(LIB)/uplt.o: uplt.o diff --git a/src/libc/dj64/parsers/mkproto.sh b/src/libc/dj64/parsers/mkproto.sh index 5e54f518..a992196f 100755 --- a/src/libc/dj64/parsers/mkproto.sh +++ b/src/libc/dj64/parsers/mkproto.sh @@ -56,7 +56,7 @@ TF=/tmp/tagsxx TL=/tmp/a.so set -e -${CROSS_ASLD} -melf_i386 -shared -Bsymbolic -z notext -o $TL --whole-archive "$1" +${CROSS_LD} -melf_i386 -shared -Bsymbolic -z notext -o $TL --whole-archive "$1" shift PRUNES="-name libm -prune -o -name machine -prune" PRUNES="$PRUNES -o -name string.h -prune -o -name in.h -prune" diff --git a/src/makefile.def b/src/makefile.def index 0e292cc1..41429871 100644 --- a/src/makefile.def +++ b/src/makefile.def @@ -2,14 +2,12 @@ # -*- makefile -*- CROSS_PREFIX ?= i686-linux-gnu- -CROSS_GCC = $(CC) -CROSS_CPP = $(CPP) # for AS objects CROSS_AS := $(CROSS_PREFIX)as -CROSS_ASAR = $(CROSS_PREFIX)ar -CROSS_ASLD = $(CROSS_PREFIX)ld +CROSS_AR = $(CROSS_PREFIX)ar +CROSS_LD = $(CROSS_PREFIX)ld CROSS_ASCPP = $(CPP) -x assembler-with-cpp $(1) | $(CROSS_AS) --32 - -CROSS_ASSTRIP = $(CROSS_PREFIX)strip +CROSS_STRIP = $(CROSS_PREFIX)strip # for mkproto.sh -export CROSS_ASLD +export CROSS_LD diff --git a/src/makefile.inc b/src/makefile.inc index 2a408016..60020662 100644 --- a/src/makefile.inc +++ b/src/makefile.inc @@ -14,8 +14,8 @@ CPPFLAGS += -DDJ64 -D_IN_DJ64 -D__DJGPP__ -nostdinc # Moved setting of $(GCC{L}_OPT) to top of file # -XGCC = $(CROSS_GCC) @$(TOP)/../gcc.opt $(CFLAGS) -XCPP = $(CROSS_CPP) -I . -I $(TOP)/../../include $(CPPFLAGS) +XGCC = $(CC) @$(TOP)/../gcc.opt $(CFLAGS) +XCPP = $(CPP) -I . -I $(TOP)/../../include $(CPPFLAGS) XASCPP = $(call CROSS_ASCPP, -I $(TOP)/../../include $(ASFLAGS) $(1)) # Have to process with intermediate file, because with a single pipe From ad8ed439e72ed0fa840fd63d1351b9388b4147ad Mon Sep 17 00:00:00 2001 From: Stas Sergeev Date: Tue, 17 Dec 2024 20:27:24 +0300 Subject: [PATCH 2/3] make: move a few vars out of makefile.def --- src/makefile.def | 4 ---- src/makefile.inc | 4 ++++ 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/makefile.def b/src/makefile.def index 41429871..3773692f 100644 --- a/src/makefile.def +++ b/src/makefile.def @@ -6,8 +6,4 @@ CROSS_PREFIX ?= i686-linux-gnu- CROSS_AS := $(CROSS_PREFIX)as CROSS_AR = $(CROSS_PREFIX)ar CROSS_LD = $(CROSS_PREFIX)ld -CROSS_ASCPP = $(CPP) -x assembler-with-cpp $(1) | $(CROSS_AS) --32 - CROSS_STRIP = $(CROSS_PREFIX)strip - -# for mkproto.sh -export CROSS_LD diff --git a/src/makefile.inc b/src/makefile.inc index 60020662..a5463543 100644 --- a/src/makefile.inc +++ b/src/makefile.inc @@ -8,6 +8,9 @@ include $(TOP)/../makefile.def SHELL := bash -o pipefail +# for mkproto.sh +export CROSS_LD + .SUFFIXES: .o .i .c .cc .s CPPFLAGS += -DDJ64 -D_IN_DJ64 -D__DJGPP__ -nostdinc @@ -16,6 +19,7 @@ CPPFLAGS += -DDJ64 -D_IN_DJ64 -D__DJGPP__ -nostdinc # XGCC = $(CC) @$(TOP)/../gcc.opt $(CFLAGS) XCPP = $(CPP) -I . -I $(TOP)/../../include $(CPPFLAGS) +CROSS_ASCPP = $(CPP) -x assembler-with-cpp $(1) | $(CROSS_AS) --32 - XASCPP = $(call CROSS_ASCPP, -I $(TOP)/../../include $(ASFLAGS) $(1)) # Have to process with intermediate file, because with a single pipe From 92acab75eac5071299220be874f25e17f346adef Mon Sep 17 00:00:00 2001 From: Stas Sergeev Date: Tue, 17 Dec 2024 21:42:53 +0300 Subject: [PATCH 3/3] switch to autoconf --- Makefile.conf.in | 12 ++++ configure.ac | 128 ++++++++++++++++++++++++++++++++++++++ debian/control | 1 + dj64.pc.in | 2 +- dj64.spec.rpkg | 1 + dj64_s.pc.in | 2 +- dj64static.pc.in | 2 +- makefile | 25 +++----- src/djdev64/makefile | 2 +- src/djdev64/stub/makefile | 2 +- src/gcc.opt.in | 1 + src/makefile.cfg | 27 +------- src/makefile.def | 9 --- src/makefile.inc | 4 +- 14 files changed, 163 insertions(+), 55 deletions(-) create mode 100644 Makefile.conf.in create mode 100644 configure.ac create mode 100644 src/gcc.opt.in delete mode 100644 src/makefile.def diff --git a/Makefile.conf.in b/Makefile.conf.in new file mode 100644 index 00000000..a61cc41b --- /dev/null +++ b/Makefile.conf.in @@ -0,0 +1,12 @@ +prefix := @prefix@ +libdir := @libdir@ +datarootdir := @datarootdir@ + +CC := @CC@ +CPP := @CPP@ +INSTALL := @INSTALL@ + +CROSS_AS := @CROSS_AS@ +CROSS_AR := @CROSS_AR@ +CROSS_LD := @CROSS_LD@ +CROSS_STRIP := @CROSS_STRIP@ diff --git a/configure.ac b/configure.ac new file mode 100644 index 00000000..6b7d7099 --- /dev/null +++ b/configure.ac @@ -0,0 +1,128 @@ +dnl Process this file with autoconf to produce a configure script. +AC_INIT([dj64dev], [0.2]) +AC_CONFIG_FILES([Makefile.conf src/gcc.opt \ + dj64.pc \ + dj64_s.pc \ + dj64static.pc \ + djdev64.pc \ + djstub64.pc +]) + +VERSION="$PACKAGE_VERSION" +AC_SUBST(VERSION) + +AC_PROG_CC +AC_PROG_CPP +AC_PROG_INSTALL + +CFLAGS="$CFLAGS \ +-fno-common \ +-fpic \ +-ffreestanding \ +-flto=auto \ +-nostdinc \ +-ggdb3 \ +-Og \ +-Wall \ +-Wcast-qual \ +-Werror \ +-Wno-parentheses \ +-Wmissing-declarations \ +-Wmissing-prototypes \ +-Wpointer-arith \ +-Wshadow \ +-Wwrite-strings \ +-Wundef \ +-Wno-array-bounds \ +-Wno-unneeded-internal-declaration \ +-Wno-unknown-warning-option \ +-Wsign-compare" + +machine=`$CC -dumpmachine | cut -d- -f1 | sed 's/i.86/i386/'` + +if test -n "$CROSS_PREFIX"; then + AC_PATH_PROG([CROSS_AS], [${CROSS_PREFIX}as]) + if test -z "$CROSS_AS"; then + AC_MSG_ERROR([${CROSS_PREFIX}as not found, CROSS_PREFIX is wrong]) + fi +else + AC_PATH_PROGS([CROSS_AS], [i686-linux-gnu-as i386-elf-as]) +fi +if test -z "$CROSS_AS"; then + if test "$CONFIG_HOST" = "Darwin"; then + AC_MSG_ERROR([Please install i386-elf-binutils from https://github.com/nativeos/homebrew-i386-elf-toolchain]) + fi + AC_PATH_PROG([CROSS_AS], [x86_64-linux-gnu-as]) + if test -z "$CROSS_AS"; then + if test "$machine" = "i386" -o "$machine" = "x86_64"; then + CROSS_AS="$AS" + if test "$clang_as_as" = "1"; then + CROSS_ASFLAGS="$ASFLAGS -m32" + else + CROSS_ASFLAGS="--32" + fi + else + AC_PATH_PROG([CROSS_AS], [clang]) + if test -n "$CROSS_AS"; then + CROSS_ASFLAGS="-x assembler -target i686-unknown-linux-gnu -c -" + else + AC_MSG_ERROR([386 assembler not found, please install clang or binutils-i686-linux-gnu]) + fi + fi + else + CROSS_ASFLAGS="--32" + fi +fi + +if test -n "$CROSS_PREFIX"; then + AC_PATH_PROG([CROSS_LD], [${CROSS_PREFIX}ld]) + if test -z "$CROSS_LD"; then + AC_MSG_ERROR([${CROSS_PREFIX}ld not found, CROSS_PREFIX is wrong]) + fi +else + AC_PATH_PROGS([CROSS_LD], [i686-linux-gnu-ld i386-elf-ld x86_64-linux-gnu-ld ld.lld]) +fi +if test -z "$CROSS_LD"; then + if test "$machine" = "i386" -o "$machine" = "x86_64"; then + AC_PATH_PROGS([CROSS_LD], [ld]) + fi +fi +if test -z "$CROSS_LD"; then + AC_MSG_ERROR([cross-ld not found]) +fi + +if test -n "$CROSS_PREFIX"; then + AC_PATH_PROG([CROSS_AR], [${CROSS_PREFIX}ar]) + if test -z "$CROSS_AR"; then + AC_MSG_ERROR([${CROSS_PREFIX}ar not found, CROSS_PREFIX is wrong]) + fi +else + AC_PATH_PROGS([CROSS_AR], [i686-linux-gnu-ar i386-elf-ar x86_64-linux-gnu-ar llvm-ar]) +fi +if test -z "$CROSS_AR"; then + if test "$machine" = "i386" -o "$machine" = "x86_64"; then + AC_PATH_PROGS([CROSS_AR], [ar]) + fi +fi +if test -z "$CROSS_AR"; then + AC_MSG_ERROR([cross-ar not found]) +fi + +if test -n "$CROSS_PREFIX"; then + AC_PATH_PROG([CROSS_STRIP], [${CROSS_PREFIX}strip]) + if test -z "$CROSS_STRIP"; then + AC_MSG_ERROR([${CROSS_PREFIX}strip not found, CROSS_PREFIX is wrong]) + fi +else + AC_PATH_PROGS([CROSS_STRIP], [i686-linux-gnu-strip i386-elf-strip x86_64-linux-gnu-strip llvm-strip]) +fi +if test -z "$CROSS_STRIP"; then + if test "$machine" = "i386" -o "$machine" = "x86_64"; then + AC_PATH_PROGS([CROSS_STRIP], [strip]) + fi +fi +if test -z "$CROSS_STRIP"; then + AC_MSG_ERROR([cross-strip not found]) +fi + +AC_OUTPUT diff --git a/debian/control b/debian/control index 680be1fa..fd3e2bcb 100644 --- a/debian/control +++ b/debian/control @@ -7,6 +7,7 @@ Build-Depends: thunk-gen (>= 1.2~), binutils-i686-linux-gnu, universal-ctags, + autoconf, pkgconf, libelf-dev, debhelper (>= 9~) diff --git a/dj64.pc.in b/dj64.pc.in index b178e7cb..ca0accc5 100644 --- a/dj64.pc.in +++ b/dj64.pc.in @@ -1,7 +1,7 @@ Name: dj64 Description: dj64 dev suit Version: @VERSION@ -prefix=@PREFIX@ +prefix=@prefix@ makeinc=${prefix}/i386-pc-dj64/share/dj64.mk cppflags=-I${prefix}/i386-pc-dj64/include -DDJ64 -nostdinc xcppflags=${cppflags} -imacros ${prefix}/i386-pc-dj64/include/dj64/a_mac.h diff --git a/dj64.spec.rpkg b/dj64.spec.rpkg index 3ad5001f..5907a0a0 100644 --- a/dj64.spec.rpkg +++ b/dj64.spec.rpkg @@ -14,6 +14,7 @@ URL: https://github.com/stsp/dj64dev VCS: {{{ git_dir_vcs }}} Source0: {{{ git_dir_archive }}} +BuildRequires: autoconf BuildRequires: make BuildRequires: sed BuildRequires: bash diff --git a/dj64_s.pc.in b/dj64_s.pc.in index 4f5ac8d7..c3e38cac 100644 --- a/dj64_s.pc.in +++ b/dj64_s.pc.in @@ -1,6 +1,6 @@ Name: dj64_s Description: dj64 static linking Version: @VERSION@ -prefix=@PREFIX@ +prefix=@prefix@ crt0=${prefix}/i386-pc-dj64/lib/crt0.elf Libs: -L${prefix}/i386-pc-dj64/lib64 -ldj64_s -shared -Wl,-Bsymbolic diff --git a/dj64static.pc.in b/dj64static.pc.in index cc72a0a1..6403961f 100644 --- a/dj64static.pc.in +++ b/dj64static.pc.in @@ -1,5 +1,5 @@ Name: dj64static Description: dj64static libs Version: @VERSION@ -prefix=@PREFIX@ +prefix=@prefix@ Libs: --whole-archive ${prefix}/i386-pc-dj64/lib/libc.a --no-whole-archive diff --git a/makefile b/makefile index 45c275c0..51ca1831 100644 --- a/makefile +++ b/makefile @@ -1,10 +1,7 @@ TOP ?= . -prefix ?= /usr/local -libdir ?= $(prefix)/lib -INSTALL ?= install -export PKG_CONFIG_PATH = $(prefix)/share/pkgconfig:$(libdir)/pkgconfig +include Makefile.conf +export PKG_CONFIG_PATH = $(datarootdir)/pkgconfig:$(libdir)/pkgconfig -VERSION = 0.1 DJLIBC = $(TOP)/lib/libc.a DJCRT0 = $(TOP)/lib/crt0.elf DJUCRT0 = $(TOP)/lib/uplt.o @@ -44,11 +41,17 @@ export prefix .PHONY: subs dj64 djdev64 demos -all: dj64 djdev64 +all: Makefile.conf dj64 djdev64 @echo @echo "Done building. You may need to run \"sudo make install\" now." @echo "You can first run \"sudo make uninstall\" to purge the prev install." +Makefile.conf: Makefile.conf.in configure + ./configure + +configure: configure.ac + autoreconf -v -i + subs: $(MAKE) -C src @@ -111,7 +114,7 @@ uninstall: clean: demos_clean $(MAKE) -C src clean $(MAKE) -C src/djdev64 clean - $(RM) *.pc + $(RM) *.pc Makefile.conf configure $(RM) -r lib deb: @@ -121,14 +124,6 @@ rpm: make clean rpkg local && $(MAKE) clean >/dev/null -%.pc: %.pc.in makefile - sed \ - -e 's!@PREFIX[@]!$(prefix)!g' \ - -e 's!@INCLUDEDIR[@]!$(INCLUDEDIR)!g' \ - -e 's!@LIBDIR[@]!$(libdir)!g' \ - -e 's!@VERSION[@]!$(VERSION)!g' \ - $< >$@ - demos: $(MAKE) -C demos diff --git a/src/djdev64/makefile b/src/djdev64/makefile index 2c268ec6..30ac3bb3 100644 --- a/src/djdev64/makefile +++ b/src/djdev64/makefile @@ -1,5 +1,5 @@ TOP = ../.. -PREFIX ?= /usr/local +prefix ?= /usr/local PKG_CONFIG ?= pkg-config SOURCES = djdev64.c elf.c djexec.c OBJECTS = $(SOURCES:.c=.o) diff --git a/src/djdev64/stub/makefile b/src/djdev64/stub/makefile index 06e4b65b..30af7ac7 100644 --- a/src/djdev64/stub/makefile +++ b/src/djdev64/stub/makefile @@ -1,5 +1,5 @@ TOP = ../../.. -PREFIX ?= /usr/local +prefix ?= /usr/local SOURCES = coff.c elf.c util.c stub.c dpmiwrp.c dos.c OBJECTS = $(SOURCES:.c=.o) CFLAGS += -iquote ../include -fpic -ggdb3 -Wall -Og -MD \ diff --git a/src/gcc.opt.in b/src/gcc.opt.in new file mode 100644 index 00000000..d0db63d8 --- /dev/null +++ b/src/gcc.opt.in @@ -0,0 +1 @@ +@CFLAGS@ diff --git a/src/makefile.cfg b/src/makefile.cfg index 06e8b8a9..4c23e729 100644 --- a/src/makefile.cfg +++ b/src/makefile.cfg @@ -1,28 +1,5 @@ # Copyright (C) 2007 DJ Delorie, see COPYING.DJ for details config: gcc.opt - -gcc.opt: makefile.cfg - @$(RM) -f $@ - @echo "-fno-common" >>$@ - @echo "-fpic" >>$@ - @echo "-ffreestanding" >>$@ - @echo "-flto=auto" >>$@ - @echo "-nostdinc" >>$@ - @echo "-ggdb3" >>$@ - @echo "-Og" >>$@ - @echo "-Wall" >>$@ - @echo "-Wcast-qual" >>$@ - @echo "-Werror" >>$@ - @echo "-Wno-parentheses" >>$@ - @echo "-Wmissing-declarations" >>$@ - @echo "-Wmissing-prototypes" >>$@ - @echo "-Wpointer-arith" >>$@ - @echo "-Wshadow" >>$@ - @echo "-Wwrite-strings" >>$@ - @echo "-Wundef" >>$@ -# @echo "-Wcast-align" >>$@ - @echo "-Wno-array-bounds" >>$@ - @echo "-Wno-unneeded-internal-declaration" >>$@ - @echo "-Wno-unknown-warning-option" >>$@ - @echo "-Wsign-compare" >>$@ +gcc.opt: gcc.opt.in + cd .. && ./configure diff --git a/src/makefile.def b/src/makefile.def deleted file mode 100644 index 3773692f..00000000 --- a/src/makefile.def +++ /dev/null @@ -1,9 +0,0 @@ -# Copyright (C) 1998 DJ Delorie, see COPYING.DJ for details -# -*- makefile -*- - -CROSS_PREFIX ?= i686-linux-gnu- -# for AS objects -CROSS_AS := $(CROSS_PREFIX)as -CROSS_AR = $(CROSS_PREFIX)ar -CROSS_LD = $(CROSS_PREFIX)ld -CROSS_STRIP = $(CROSS_PREFIX)strip diff --git a/src/makefile.inc b/src/makefile.inc index a5463543..c2345970 100644 --- a/src/makefile.inc +++ b/src/makefile.inc @@ -4,13 +4,15 @@ # Copyright (C) 1998 DJ Delorie, see COPYING.DJ for details # -*- makefile -*- -include $(TOP)/../makefile.def +include $(TOP)/../../Makefile.conf SHELL := bash -o pipefail # for mkproto.sh export CROSS_LD +export prefix + .SUFFIXES: .o .i .c .cc .s CPPFLAGS += -DDJ64 -D_IN_DJ64 -D__DJGPP__ -nostdinc