~bl4ckb0ne/boson

1eebe4d73a4484cd26d3b5569bb7737127c12bd0 — Simon Zeni a month ago eb8abea
improve build process
M .builds/alpine.yml => .builds/alpine.yml +5 -2
@@ 6,8 6,11 @@ sources:
tasks:
  - build: |
      cd boson
      mkdir build
      cd build
      ../configure
      make
  - ninja: |
      cd boson
      ./boson ninjabuild
      ninja -C ninjabuild
      ./build/boson bosonbuild
      samu -C bosonbuild

M .builds/archlinux.yml => .builds/archlinux.yml +6 -3
@@ 7,8 7,11 @@ sources:
tasks:
  - build: |
      cd boson
      CC=clang make
      mkdir build
      cd build
      CC=clang ../configure
      make
  - ninja: |
      cd boson
      ./boson ninjabuild
      samu -C ninjabuild
      ./build/boson bosonbuild
      samu -C bosonbuild

M .builds/freebsd.yml => .builds/freebsd.yml +6 -4
@@ 1,14 1,16 @@
image: freebsd/latest
packages:
  - gmake
  - samurai
sources:
  - https://git.sr.ht/~bl4ckb0ne/boson
tasks:
  - build: |
      cd boson
      gmake
      mkdir build
      cd build
      ../configure
      make
  - ninja: |
      cd boson
      ./boson ninjabuild
      samu -C ninjabuild
      ./build/boson bosonbuild
      samu -C bosonbuild

M Makefile => Makefile +24 -35
@@ 1,39 1,28 @@
.POSIX:
VERSION=0.0.1

INCLUDE=-Iinclude
FLAGS=-g -Wall -Wextra -Werror -Wno-unused-parameter -DVERSION='"$(VERSION)"' -fno-common $(CFLAGS)
LDFLAGS=-static

OUTDIR?=build
.DEFAULT_GOAL=all

OBJECTS=\
	$(OUTDIR)/getopt_long.o \
	$(OUTDIR)/hash_table.o \
	$(OUTDIR)/log.o \
	$(OUTDIR)/ninja.o \
	$(OUTDIR)/options.o \
	$(OUTDIR)/object.o \
	$(OUTDIR)/builtin.o \
	$(OUTDIR)/interpreter.o \
	$(OUTDIR)/ast.o \
	$(OUTDIR)/token.o \
	$(OUTDIR)/lexer.o \
	$(OUTDIR)/parser.o \
	$(OUTDIR)/setup.o \
	$(OUTDIR)/main.o

$(OUTDIR)/%.o: src/%.c
	@mkdir -p $(OUTDIR)
	cc -std=c11 -pedantic -c -o $@ $(FLAGS) $(INCLUDE) $<

boson: $(OBJECTS)
	cc $(LDFLAGS) -o $@ $^

all: boson
.SUFFIXES:
OUTDIR=.build
include $(OUTDIR)/config.mk

boson: $(boson_objects)
	@printf 'CCLD\t$@\n'
	@$(CC) $(LDFLAGS) -o $@ $(boson_objects) $(LIBS)

.SUFFIXES: .c .o .ha

.c.o:
	@printf 'CC\t$@\n'
	@$(CC) -c $(CFLAGS) -o $@ $<

docs:

clean:
	rm -rf boson $(OUTDIR)
	@rm -f boson $(boson_objects)

distclean: clean
	@rm -rf "$(OUTDIR)"

install: boson
	mkdir -p $(DESTDIR)$(BINDIR)
	install -m755 boson $(DESTDIR)$(BINDIR)/boson

.PHONY: all clean
.PHONY: docs clean distclean install

M README.md => README.md +25 -3
@@ 5,12 5,33 @@ on portability and simplicity.

## Status

`boson` is currently a work in progress. It is not yet in a usable state. Don't
expect it to be able to build your project.
`boson` is currently a work in progress. There's a lot to do, don't expect it
to be able to build your project.


[![builds.sr.ht status](https://builds.sr.ht/~bl4ckb0ne/boson.svg)][6]

## Requirements

`boson` requires various POSIX interfaces and a compiler offering `c11` support.
`boson` requires various POSIX interfaces and a compiler offering c11 support.

## Building

You can either use the Makefile:

```
mkdir build
cd build
../configure
make
```

Or the meson file

```
meson build
ninja -C build
```

## Contributing



@@ 23,3 44,4 @@ questions regarding usage or development
[3]: https://lists.sr.ht/~bl4ckb0ne/boson
[4]: https://webchat.oftc.net/?channels=boson
[5]: https://www.oftc.net
[6]: https://builds.sr.ht/~bl4ckb0ne/boson

A config.sh => config.sh +198 -0
@@ 0,0 1,198 @@
outdir=${OUTDIR:-.build}
srcdir=${SRCDIR:-$(dirname "$0")}
AR=${AR:-ar}
AS=${AS:-as}
CC=${CC:-cc}
CFLAGS=${CFLAGS:-}
LDFLAGS=${LDFLAGS:-}
LD=${LD:-ld}
QBE=${QBE:-qbe}
SCDOC=${SCDOC:-scdoc}

for arg
do
	case "$arg" in
		--bindir=*)
			BINDIR=${arg#*=}
			;;
		--libdir=*)
			LIBDIR=${arg#*=}
			;;
		--mandir=*)
			MANDIR=${arg#*=}
			;;
		--prefix=*)
			PREFIX=${arg#*=}
			if [ "$PREFIX" = "/usr" ]
			then
				SYSCONFDIR=/etc
			fi
			;;
		--sharedir=*)
			SHAREDIR=${arg#*=}
			;;
		--sysconfdir=*)
			SYSCONFDIR=${arg#*=}
			;;
		*)
			option "$arg"
			;;
	esac
done

subdir() {
	eval ". $srcdir/$1/configure"
}

genrules() {
	target="$1"
	shift
	printf '# Begin generated rules for %s\n' "$target"
	for file in "$@"
	do
		ext="${file#*.}"
		file="${file%.*}"
		deps=
		printf '%s.o: %s.%s%s\n' "$file" "$file" "$ext" "$deps"
	done
	printf '%s_objects=\\\n' "$target"
	n=0
	for file in "$@"
	do
		file="${file%.*}"
		n=$((n+1))
		if [ $n -eq $# ]
		then
			printf '\t%s.o\n' "$file"
		else
			printf '\t%s.o \\\n' "$file"
		fi
	done
	printf '# End generated rules for %s\n' "$target"
}

append_cflags() {
	for flag
	do
		CFLAGS="$(printf '%s \\\n\t%s' "$CFLAGS" "$flag")"
	done
}

test_cflags() {
	[ ! -e "$outdir"/check.c ] && cat <<-EOF > "$outdir"/check.c
	int main(void) { return 0; }
	EOF
	werror=""
	case "$CFLAGS" in
		*-Werror*)
			werror="-Werror"
			;;
	esac
	if $CC $werror "$@" -o /dev/null "$outdir"/check.c >/dev/null 2>&1
	then
		append_cflags "$@"
	else
		return 1
	fi
}

find_library() {
	name="$1"
	pc="$2"
	printf "Checking for %s... " "$name"
	if ! pkg-config "$pc" 2>/dev/null
	then
		printf "NOT FOUND\n"
		printf "Tried pkg-config %s\n" "$pc"
		return 1
	fi
	printf "OK\n"
	CFLAGS="$CFLAGS $(pkg-config --cflags "$pc")"
	LIBS="$LIBS $(pkg-config --libs "$pc")"
}

docs() { true; }

run_configure() {
	mkdir -p $outdir

	for flag in -g -std=c11 -D_XOPEN_SOURCE=700 \
		-Wall -Wextra -Werror -pedantic \
		-Wno-unused-parameter
	do
		printf "Checking for %s... " "$flag"
		if test_cflags "$flag"
		then
			echo yes
		else
			echo no
		fi
	done

	append_cflags "-DVERSION='\"$1\"'"

	printf "Creating $outdir/config.mk... "
	cat <<-EOF > "$outdir"/config.mk
	CC=$CC
	AS=$AS
	LD=$LD
	QBE=$QBE
	SCDOC=$SCDOC
	LIBS=$LIBS
	PREFIX=${PREFIX:-/usr/local}
	OUTDIR=${outdir}
	SRCDIR=${srcdir}
	BINDIR?=${BINDIR:-\$(PREFIX)/bin}
	SHAREDIR?=${SHAREDIR:-\$(PREFIX)/share}
	SYSCONFDIR?=${SYSCONFDIR:-\$(PREFIX)/etc}
	LIBDIR?=${LIBDIR:-\$(PREFIX)/lib}
	MANDIR?=${MANDIR:-\$(PREFIX)/share/man}
	VARLIBDIR?=${MANDIR:-\$(PREFIX)/var/lib}
	CACHE=\$(OUTDIR)/cache
	CFLAGS=${CFLAGS}
	CFLAGS+=-Iinclude -I\$(OUTDIR)
	CFLAGS+=-DPREFIX='"\$(PREFIX)"'
	CFLAGS+=-DLIBDIR='"\$(LIBDIR)"'
	CFLAGS+=-DVARLIBDIR='"\$(VARLIBDIR)"'
	CFLAGS+=-DSYSCONFDIR='"\$(SYSCONFDIR)"'
	LDFLAGS=${LDFLAGS}

	all: ${all}
	EOF

	for target in $all
	do
		$target >>"$outdir"/config.mk
	done
	echo done

	if [ "$srcdir" = "." ]
	then
		return
	fi

	populate() (
		path="$1"
		mkdir -p "${path#$srcdir/}"
		fullpath() ( cd "$1" && pwd )
		for orig in "$path"/*
		do
			link="${orig#$srcdir/}"
			if [ -d "$orig" ]
			then
				mkdir -p $link
				populate "$orig"
			elif [ -f "$orig" ]
			then
				ln -sf "$(fullpath "$path")"/"$(basename "$orig")" "$link"
			fi
		done
	)

	printf "Populating build dir... "
	populate "$srcdir/doc"
	populate "$srcdir/include"
	populate "$srcdir/src"
	ln -sf "$srcdir"/Makefile ./
	echo done
}

A configure => configure +26 -0
@@ 0,0 1,26 @@
#!/bin/sh -e
srcdir=${SRCDIR:-$(dirname "$0")}

eval ". $srcdir/config.sh"

boson() {
	genrules boson \
		src/getopt_long.c \
		src/hash_table.c \
		src/log.c \
		src/ninja.c \
		src/options.c \
		src/object.c \
		src/builtin.c \
		src/interpreter.c \
		src/ast.c \
		src/token.c \
		src/lexer.c \
		src/parser.c \
		src/setup.c \
		src/main.c
}

all="boson"

run_configure 0.0.1

M src/ninja.c => src/ninja.c +2 -2
@@ 4,13 4,13 @@
#include "interpreter.h"
#include "options.h"

#define _POSIX_C_SOURCE 200112L
#define _XOPEN_SOURCE 500
#define _XOPEN_SOURCE 700

#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <sys/wait.h>

#define PATH_MAX 4096


M src/parser.c => src/parser.c +0 -2
@@ 4,8 4,6 @@
#include "token.h"
#include "log.h"

#define _POSIX_C_SOURCE 200112L

#include <assert.h>
#include <stdio.h>
#include <stdlib.h>

M src/setup.c => src/setup.c +1 -1
@@ 1,4 1,4 @@
#define _XOPEN_SOURCE 500
#define _XOPEN_SOURCE 700

#include "setup.h"
#include "log.h"