Skip to content

Commit cf1f432

Browse files
committed
First swatch of ab buildfiles. cemcom.ansi builds.
1 parent 25cd8e8 commit cf1f432

File tree

36 files changed

+2221
-111
lines changed

36 files changed

+2221
-111
lines changed

Makefile

Lines changed: 11 additions & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,16 @@ else
1515
ACK_TEMP_DIR ?= $(TMPDIR)
1616
endif
1717

18+
INSDIR = $(OBJ)/staging
19+
1820
# Where is the ACK going to be installed, eventually? If you don't want to
1921
# install it and just want to run the ACK from the build directory
2022
# ($(TMPDIR)/ack-build/staging, by default), leave this as $(INSDIR).
2123

2224
ifeq ($(OS),Windows_NT)
2325
PREFIX ?= c:/ack
2426
else
25-
PREFIX ?= /usr/local
27+
PREFIX ?= /opt/pkg/ack
2628
#PREFIX = $(INSDIR)
2729
endif
2830

@@ -35,122 +37,22 @@ BUILDDIR ?= $(ACK_TEMP_DIR)/ack-build
3537
CFLAGS ?= -g \
3638
-Werror=return-type \
3739
-Werror=implicit-function-declaration \
38-
-Werror=strict-prototypes
40+
-Werror=strict-prototypes \
41+
-DUNREACHABLE_CODE='__builtin_unreachable()' \
42+
-DNORETURN=_Noreturn
43+
44+
HOSTCFLAGS = $(CFLAGS)
3945

4046
LDFLAGS ?= -g
4147

4248
# Various commands.
4349

44-
AR ?= ar
45-
CC ?= gcc
4650
LUA ?= lua
4751

48-
# Which build system to use; use 'ninja' or 'make' (in lower case). Leave
49-
# blank to autodetect.
50-
51-
BUILDSYSTEM ?=
52-
53-
# Build flags for ninja.
54-
55-
NINJAFLAGS ?=
56-
57-
# Build flags for make.
58-
59-
MAKEFLAGS ?=
60-
61-
# ======================================================================= #
62-
# END OF CONFIGURATION #
63-
# ======================================================================= #
64-
65-
# You shouldn't need to change anything below this point unless you are
66-
# actually developing ACK.
67-
68-
OBJDIR = $(abspath $(BUILDDIR)/obj)
69-
BINDIR = $(abspath $(BUILDDIR)/bin)
70-
LIBDIR = $(abspath $(BUILDDIR)/lib)
71-
INCDIR = $(abspath $(BUILDDIR)/include)
72-
INSDIR = $(abspath $(BUILDDIR)/staging)
52+
.PHONY: all
53+
all: +all
7354

7455
PLATIND = $(INSDIR)/share/ack
7556
PLATDEP = $(INSDIR)/lib/ack
7657

77-
MANDATORYCFLAGS = \
78-
-DUNREACHABLE_CODE='__builtin_unreachable()' \
79-
-DNORETURN=_Noreturn
80-
81-
MANDATORYLDFLAGS =
82-
83-
.NOTPARALLEL:
84-
85-
ifeq ($(BUILDSYSTEM),)
86-
ifneq ($(shell which ninja),)
87-
BUILDSYSTEM = ninja
88-
else
89-
BUILDSYSTEM = make
90-
endif
91-
endif
92-
93-
build-file = $(BUILDDIR)/build.$(BUILDSYSTEM)
94-
lua-files = $(shell find . -name 'build*.lua')
95-
our-lua = $(BUILDDIR)/lua
96-
97-
# GNU make sets MAKECMDGOALS to the list of targets from the command
98-
# line. We look for targets with '+' and forward them to BUILDSYSTEM.
99-
# This handles commands like
100-
# $ make util/opt+pkg util/ego+pkg
101-
102-
all-goals = +ack +tests
103-
plus-goals := $(patsubst all,$(all-goals),$(or $(MAKECMDGOALS),all))
104-
plus-goals := $(foreach g,$(plus-goals),$(if $(findstring +,$(g)),$(g),))
105-
106-
# @true silences extra message, "make: Nothing to be done..."
107-
108-
all: build-plus-goals
109-
@true
110-
111-
ifneq ($(plus-goals),)
112-
$(plus-goals): build-plus-goals
113-
@true
114-
endif
115-
116-
build-plus-goals: $(build-file)
117-
ifeq ($(BUILDSYSTEM),ninja)
118-
@ninja $(NINJAFLAGS) -f $(build-file) $(plus-goals)
119-
else ifeq ($(BUILDSYSTEM),make)
120-
# GNU make passes MAKEFLAGS in environment.
121-
@$(MAKE) -f $(build-file) $(plus-goals)
122-
else
123-
$(error unknown BUILDSYSTEM = $(BUILDSYSTEM))
124-
endif
125-
126-
$(build-file): first/ackbuilder.lua Makefile $(lua-files)
127-
@mkdir -p $(BUILDDIR)
128-
@$(LUA) first/ackbuilder.lua \
129-
first/build.lua build.lua \
130-
--$(BUILDSYSTEM) \
131-
LUA=$(LUA) \
132-
DEFAULT_PLATFORM=$(DEFAULT_PLATFORM) \
133-
OBJDIR=$(OBJDIR) \
134-
BINDIR=$(BINDIR) \
135-
LIBDIR=$(LIBDIR) \
136-
INCDIR=$(INCDIR) \
137-
INSDIR=$(INSDIR) \
138-
PLATIND=$(PLATIND) \
139-
PLATDEP=$(PLATDEP) \
140-
PREFIX="$(PREFIX)" \
141-
AR=$(AR) \
142-
CC=$(CC) \
143-
CFLAGS="$(MANDATORYCFLAGS) $(CFLAGS)" \
144-
LDFLAGS="$(MANDATORYLDFLAGS) $(LDFLAGS)" \
145-
> $(build-file)
146-
147-
ack-setup.exe: etc/windows-installer.nsi
148-
makensis -dBUILDDIR=$(BUILDDIR)/staging -dOUTFILE="$$(realpath $@)" $<
149-
150-
install:
151-
mkdir -p $(PREFIX)
152-
tar cf - -C $(INSDIR) . | tar xvf - -C $(PREFIX)
153-
154-
clean:
155-
rm -rf $(BUILDDIR)
156-
58+
include build/ab.mk

build.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
from build.ab import export
2+
3+
export(
4+
name="all",
5+
deps=[
6+
"util/amisc+all",
7+
"util/arch+all",
8+
"util/led+all",
9+
"util/ncgg",
10+
"util/LLgen",
11+
"lang/cem/cemcom-ansi+all",
12+
],
13+
)

build/_objectify.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import sys
2+
from functools import partial
3+
4+
if len(sys.argv) != 3:
5+
sys.exit("Usage: %s <file> <symbol>" % sys.argv[0])
6+
filename = sys.argv[1]
7+
symbol = sys.argv[2]
8+
9+
print("const uint8_t " + symbol + "[] = {")
10+
n = 0
11+
with open(filename, "rb") as in_file:
12+
for c in iter(partial(in_file.read, 1), b""):
13+
print("0x%02X," % ord(c), end="")
14+
n += 1
15+
if n % 16 == 0:
16+
print()
17+
print("};")
18+
19+
print("const size_t " + symbol + "_len = sizeof(" + symbol + ");")

build/_sandbox.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#!/usr/bin/python3
2+
3+
from os.path import *
4+
import argparse
5+
import os
6+
import shutil
7+
8+
9+
def main():
10+
parser = argparse.ArgumentParser()
11+
parser.add_argument("-s", "--sandbox")
12+
parser.add_argument("-v", "--verbose", action="store_true")
13+
parser.add_argument("-l", "--link", action="store_true")
14+
parser.add_argument("-e", "--export", action="store_true")
15+
parser.add_argument("files", nargs="*")
16+
args = parser.parse_args()
17+
18+
assert args.sandbox, "You must specify a sandbox directory"
19+
assert args.link ^ args.export, "You can't link and export at the same time"
20+
21+
if args.link:
22+
os.makedirs(args.sandbox, exist_ok=True)
23+
for f in args.files:
24+
sf = join(args.sandbox, f)
25+
if args.verbose:
26+
print("link", sf)
27+
os.makedirs(dirname(sf), exist_ok=True)
28+
try:
29+
os.link(abspath(f), sf)
30+
except PermissionError:
31+
shutil.copy(f, sf)
32+
33+
if args.export:
34+
for f in args.files:
35+
sf = join(args.sandbox, f)
36+
if args.verbose:
37+
print("export", sf)
38+
df = dirname(f)
39+
if df:
40+
os.makedirs(df, exist_ok=True)
41+
os.rename(sf, f)
42+
43+
44+
main()

build/ab.mk

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
MAKENOT4 := $(if $(findstring 3.9999, $(lastword $(sort 3.9999 $(MAKE_VERSION)))),yes,no)
2+
MAKE4.3 := $(if $(findstring 4.3, $(firstword $(sort 4.3 $(MAKE_VERSION)))),yes,no)
3+
MAKE4.1 := $(if $(findstring no_no,$(MAKENOT4)_$(MAKE4.3)),yes,no)
4+
5+
ifeq ($(MAKENOT3),yes)
6+
$(error You need GNU Make 4.x for this (if you're on OSX, use gmake).)
7+
endif
8+
9+
OBJ ?= .obj
10+
PYTHON ?= python3
11+
PKG_CONFIG ?= pkg-config
12+
HOST_PKG_CONFIG ?= $(PKG_CONFIG)
13+
ECHO ?= echo
14+
CP ?= cp
15+
16+
HOSTCC ?= gcc
17+
HOSTCXX ?= g++
18+
HOSTAR ?= ar
19+
HOSTCFLAGS ?= -g -Og
20+
HOSTLDFLAGS ?= -g
21+
22+
HOSTDMD ?= ldmd2
23+
HOSTDFLAGS ?= -g
24+
HOSTDLINKFLAGS ?=
25+
26+
CC ?= $(HOSTCC)
27+
CXX ?= $(HOSTCXX)
28+
AR ?= $(HOSTAR)
29+
CFLAGS ?= $(HOSTCFLAGS)
30+
LDFLAGS ?= $(HOSTLDFLAGS)
31+
32+
DMD ?= $(HOSTDMD)
33+
DFLAGS ?= $(HOSTDFLAGS)
34+
DLINKFLAGS ?= $(HOSTDLINKFLAGS)
35+
36+
export PKG_CONFIG
37+
export HOST_PKG_CONFIG
38+
39+
ifdef VERBOSE
40+
hide =
41+
else
42+
ifdef V
43+
hide =
44+
else
45+
hide = @
46+
endif
47+
endif
48+
49+
WINDOWS := no
50+
OSX := no
51+
LINUX := no
52+
ifeq ($(OS),Windows_NT)
53+
WINDOWS := yes
54+
else
55+
UNAME_S := $(shell uname -s)
56+
ifeq ($(UNAME_S),Linux)
57+
LINUX := yes
58+
endif
59+
ifeq ($(UNAME_S),Darwin)
60+
OSX := yes
61+
endif
62+
endif
63+
64+
ifeq ($(OS), Windows_NT)
65+
EXT ?= .exe
66+
endif
67+
EXT ?=
68+
69+
CWD=$(shell pwd)
70+
71+
ifeq ($(PROGRESSINFO),)
72+
# The first make invocation here has to have its output discarded or else it
73+
# produces spurious 'Leaving directory' messages... don't know why.
74+
rulecount := $(strip $(shell $(MAKE) --no-print-directory -q $(OBJ)/build.mk PROGRESSINFO=1 > /dev/null \
75+
&& $(MAKE) --no-print-directory -n $(MAKECMDGOALS) PROGRESSINFO=XXXPROGRESSINFOXXX | grep XXXPROGRESSINFOXXX | wc -l))
76+
ruleindex := 1
77+
PROGRESSINFO = "[$(ruleindex)/$(rulecount)]$(eval ruleindex := $(shell expr $(ruleindex) + 1))"
78+
endif
79+
80+
PKG_CONFIG_HASHES = $(OBJ)/.pkg-config-hashes/target-$(word 1, $(shell $(PKG_CONFIG) --list-all | md5sum))
81+
HOST_PKG_CONFIG_HASHES = $(OBJ)/.pkg-config-hashes/host-$(word 1, $(shell $(HOST_PKG_CONFIG) --list-all | md5sum))
82+
83+
$(OBJ)/build.mk : $(PKG_CONFIG_HASHES) $(HOST_PKG_CONFIG_HASHES)
84+
$(PKG_CONFIG_HASHES) $(HOST_PKG_CONFIG_HASHES) &:
85+
$(hide) rm -rf $(OBJ)/.pkg-config-hashes
86+
$(hide) mkdir -p $(OBJ)/.pkg-config-hashes
87+
$(hide) touch $(PKG_CONFIG_HASHES) $(HOST_PKG_CONFIG_HASHES)
88+
89+
include $(OBJ)/build.mk
90+
91+
MAKEFLAGS += -r -j$(shell nproc)
92+
.DELETE_ON_ERROR:
93+
94+
.PHONY: update-ab
95+
update-ab:
96+
@echo "Press RETURN to update ab from the repository, or CTRL+C to cancel." \
97+
&& read a \
98+
&& (curl -L https://github.com/davidgiven/ab/releases/download/dev/distribution.tar.xz | tar xvJf -) \
99+
&& echo "Done."
100+
101+
.PHONY: clean
102+
clean::
103+
@echo CLEAN
104+
$(hide) rm -rf $(OBJ)
105+
106+
export PYTHONHASHSEED = 1
107+
build-files = $(shell find . -name 'build.py') $(wildcard build/*.py) $(wildcard config.py)
108+
$(OBJ)/build.mk: Makefile $(build-files) build/ab.mk
109+
@echo "AB"
110+
@mkdir -p $(OBJ)
111+
$(hide) $(PYTHON) -X pycache_prefix=$(OBJ)/__pycache__ build/ab.py -o $@ build.py \
112+
|| rm -f $@

0 commit comments

Comments
 (0)