Skip to content

Commit

Permalink
Merge pull request #21 from stsp/aconf
Browse files Browse the repository at this point in the history
Aconf
  • Loading branch information
stsp authored Dec 17, 2024
2 parents ab41574 + 92acab7 commit 2cc0f63
Show file tree
Hide file tree
Showing 16 changed files with 176 additions and 70 deletions.
12 changes: 12 additions & 0 deletions Makefile.conf.in
Original file line number Diff line number Diff line change
@@ -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@
128 changes: 128 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions debian/control
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Build-Depends:
thunk-gen (>= 1.2~),
binutils-i686-linux-gnu,
universal-ctags,
autoconf,
pkgconf,
libelf-dev,
debhelper (>= 9~)
Expand Down
2 changes: 1 addition & 1 deletion dj64.pc.in
Original file line number Diff line number Diff line change
@@ -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
Expand Down
1 change: 1 addition & 0 deletions dj64.spec.rpkg
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion dj64_s.pc.in
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion dj64static.pc.in
Original file line number Diff line number Diff line change
@@ -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
25 changes: 10 additions & 15 deletions makefile
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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:
Expand All @@ -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

Expand Down
2 changes: 1 addition & 1 deletion src/djdev64/makefile
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/djdev64/stub/makefile
Original file line number Diff line number Diff line change
@@ -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 \
Expand Down
1 change: 1 addition & 0 deletions src/gcc.opt.in
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@CFLAGS@
12 changes: 6 additions & 6 deletions src/libc/dj64/makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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 >$@
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/libc/dj64/parsers/mkproto.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
27 changes: 2 additions & 25 deletions src/makefile.cfg
Original file line number Diff line number Diff line change
@@ -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
15 changes: 0 additions & 15 deletions src/makefile.def

This file was deleted.

12 changes: 9 additions & 3 deletions src/makefile.inc
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,24 @@
# 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

# 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)
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
Expand Down

0 comments on commit 2cc0f63

Please sign in to comment.