Skip to content

Commit 7cde8e3

Browse files
authored
Merge pull request #824 from davidgiven/ab
Update ab to the new ninja version.
2 parents 46b90d9 + 34fe6f0 commit 7cde8e3

File tree

18 files changed

+372
-230
lines changed

18 files changed

+372
-230
lines changed

.github/workflows/ccpp.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ jobs:
8888
wsl --import fedora fedora install.tar.gz
8989
wsl --set-default fedora
9090
wsl sh -c 'dnf -y install https://github.com/rpmsphere/noarch/raw/master/r/rpmsphere-release-40-1.noarch.rpm'
91-
wsl sh -c 'dnf -y install gcc gcc-c++ protobuf-c-compiler protobuf-devel fmt-devel systemd-devel sqlite-devel wxGTK-devel mingw32-gcc mingw32-gcc-c++ mingw32-zlib-static mingw32-protobuf-static mingw32-sqlite-static mingw32-wxWidgets3-static mingw32-libpng-static mingw32-libjpeg-static mingw32-libtiff-static mingw32-nsis png2ico'
91+
wsl sh -c 'dnf -y install gcc gcc-c++ protobuf-c-compiler protobuf-devel fmt-devel systemd-devel sqlite-devel wxGTK-devel mingw32-gcc mingw32-gcc-c++ mingw32-zlib-static mingw32-protobuf-static mingw32-sqlite-static mingw32-wxWidgets3-static mingw32-libpng-static mingw32-libjpeg-static mingw32-libtiff-static mingw32-nsis png2ico ninja-build'
9292
9393
- name: fix line endings
9494
run: |

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ jobs:
2424
wsl --import fedora fedora install.tar.gz
2525
wsl --set-default fedora
2626
wsl sh -c 'dnf -y install https://github.com/rpmsphere/noarch/raw/master/r/rpmsphere-release-40-1.noarch.rpm'
27-
wsl sh -c 'dnf -y install gcc gcc-c++ protobuf-c-compiler protobuf-devel fmt-devel systemd-devel sqlite-devel wxGTK-devel mingw32-gcc mingw32-gcc-c++ mingw32-zlib-static mingw32-protobuf-static mingw32-sqlite-static mingw32-wxWidgets3-static mingw32-libpng-static mingw32-libjpeg-static mingw32-libtiff-static mingw32-nsis png2ico'
27+
wsl sh -c 'dnf -y install gcc gcc-c++ protobuf-c-compiler protobuf-devel fmt-devel systemd-devel sqlite-devel wxGTK-devel mingw32-gcc mingw32-gcc-c++ mingw32-zlib-static mingw32-protobuf-static mingw32-sqlite-static mingw32-wxWidgets3-static mingw32-libpng-static mingw32-libjpeg-static mingw32-libtiff-static mingw32-nsis png2ico ninja-build'
2828
2929
- name: fix line endings
3030
run: |

Makefile

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,15 @@ ifeq ($(BUILDTYPE),windows)
1212
MINGW = i686-w64-mingw32-
1313
CC = $(MINGW)gcc
1414
CXX = $(MINGW)g++ -std=c++20
15-
CFLAGS += -g -O3
15+
CFLAGS += -g -O3 \
16+
-Wno-unknown-warning-option \
17+
-ffunction-sections \
18+
-fdata-sections
1619
CXXFLAGS += \
1720
-fext-numeric-literals \
1821
-Wno-deprecated-enum-float-conversion \
1922
-Wno-deprecated-enum-enum-conversion
20-
LDFLAGS += -static
23+
LDFLAGS += -static -Wl,--gc-sections
2124
AR = $(MINGW)ar
2225
PKG_CONFIG = $(MINGW)pkg-config -static
2326
WINDRES = $(MINGW)windres
@@ -27,6 +30,8 @@ else
2730
CC = gcc
2831
CXX = g++ -std=c++20
2932
CFLAGS = -g -O3 \
33+
-Wno-unknown-warning-option
34+
CXXFLAGS += \
3035
-Wno-deprecated-enum-float-conversion \
3136
-Wno-deprecated-enum-enum-conversion
3237
LDFLAGS =

build.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import re
99

1010
# Hack for building on Fedora/WSL; executables get the .exe extension,
11-
# build the build system detects it as Linux.
11+
# but the build system detects it as Linux.
1212
import build.toolchain
1313

1414
toolchain.Toolchain.EXE = "$(EXT)"
@@ -93,7 +93,7 @@
9393
+ c[1]
9494
+ "' '"
9595
+ c[2]
96-
+ "' $(dir $[outs[0]]) > /dev/null"
96+
+ "' $[dirname(filenameof(outs[0]))] > /dev/null"
9797
],
9898
label="CORPUSTEST",
9999
)

build/ab.mk

Lines changed: 36 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,17 @@ HOSTCC ?= gcc
1515
HOSTCXX ?= g++
1616
HOSTAR ?= ar
1717
HOSTCFLAGS ?= -g -Og
18+
HOSTCXXFLAGS ?= $(HOSTCFLAGS)
1819
HOSTLDFLAGS ?= -g
1920

2021
CC ?= $(HOSTCC)
2122
CXX ?= $(HOSTCXX)
2223
AR ?= $(HOSTAR)
2324
CFLAGS ?= $(HOSTCFLAGS)
25+
CXXFLAGS ?= $(CFLAGS)
2426
LDFLAGS ?= $(HOSTLDFLAGS)
2527

26-
export PKG_CONFIG
27-
export HOST_PKG_CONFIG
28+
NINJA ?= ninja
2829

2930
ifdef VERBOSE
3031
hide =
@@ -63,37 +64,33 @@ EXT ?=
6364

6465
CWD=$(shell pwd)
6566

66-
ifeq ($(AB_ENABLE_PROGRESS_INFO),true)
67-
ifeq ($(PROGRESSINFO),)
68-
# The first make invocation here has to have its output discarded or else it
69-
# produces spurious 'Leaving directory' messages... don't know why.
70-
rulecount := $(strip $(shell $(MAKE) --no-print-directory -q $(OBJ)/build.mk PROGRESSINFO=1 > /dev/null \
71-
&& $(MAKE) --no-print-directory -n $(MAKECMDGOALS) PROGRESSINFO=XXXPROGRESSINFOXXX | grep XXXPROGRESSINFOXXX | wc -l))
72-
ruleindex := 1
73-
PROGRESSINFO = "[$(ruleindex)/$(rulecount)]$(eval ruleindex := $(shell expr $(ruleindex) + 1)) "
74-
endif
75-
else
76-
PROGRESSINFO = ""
77-
endif
67+
define newline
7868

79-
PKG_CONFIG_HASHES = $(OBJ)/.pkg-config-hashes/target-$(word 1, $(shell $(PKG_CONFIG) --list-all | md5sum))
80-
HOST_PKG_CONFIG_HASHES = $(OBJ)/.pkg-config-hashes/host-$(word 1, $(shell $(HOST_PKG_CONFIG) --list-all | md5sum))
8169

82-
$(OBJ)/build.mk : $(PKG_CONFIG_HASHES) $(HOST_PKG_CONFIG_HASHES)
83-
$(PKG_CONFIG_HASHES) $(HOST_PKG_CONFIG_HASHES) &:
84-
$(hide) rm -rf $(OBJ)/.pkg-config-hashes
85-
$(hide) mkdir -p $(OBJ)/.pkg-config-hashes
86-
$(hide) touch $(PKG_CONFIG_HASHES) $(HOST_PKG_CONFIG_HASHES)
70+
endef
8771

88-
include $(OBJ)/build.mk
72+
define check_for_command
73+
$(shell command -v $1 >/dev/null || (echo "Required command '$1' missing" >/dev/stderr && kill $$PPID))
74+
endef
8975

90-
ifeq ($(OSX),yes)
91-
MAKEFLAGS += -r -j$(shell sysctl -n hw.logicalcpu)
92-
else
93-
MAKEFLAGS += -r -j$(shell nproc)
94-
endif
76+
$(call check_for_command,ninja)
77+
$(call check_for_command,cmp)
78+
$(call check_for_command,$(PYTHON))
79+
80+
pkg-config-hash = $(shell ($(PKG_CONFIG) --list-all && $(HOST_PKG_CONFIG) --list-all) | md5sum)
81+
build-files = $(shell find . -name .obj -prune -o \( -name 'build.py' -a -type f \) -print) $(wildcard build/*.py) $(wildcard config.py)
82+
build-file-timestamps = $(shell ls -l $(build-files) | md5sum)
83+
84+
# Wipe the build file (forcing a regeneration) if the make environment is different.
85+
# (Conveniently, this includes the pkg-config hash calculated above.)
9586

96-
.DELETE_ON_ERROR:
87+
ignored-variables = MAKE_RESTARTS .VARIABLES MAKECMDGOALS MAKEFLAGS MFLAGS
88+
$(shell mkdir -p $(OBJ))
89+
$(file >$(OBJ)/newvars.txt,$(foreach v,$(filter-out $(ignored-variables),$(.VARIABLES)),$(v)=$($(v))$(newline)))
90+
$(shell touch $(OBJ)/vars.txt)
91+
#$(shell diff -u $(OBJ)/vars.txt $(OBJ)/newvars.txt > /dev/stderr)
92+
$(shell cmp -s $(OBJ)/newvars.txt $(OBJ)/vars.txt || (rm -f $(OBJ)/build.ninja && echo "Environment changed --- regenerating" > /dev/stderr))
93+
$(shell mv $(OBJ)/newvars.txt $(OBJ)/vars.txt)
9794

9895
.PHONY: update-ab
9996
update-ab:
@@ -108,9 +105,15 @@ clean::
108105
$(hide) rm -rf $(OBJ)
109106

110107
export PYTHONHASHSEED = 1
111-
build-files = $(shell find . -name 'build.py') $(wildcard build/*.py) $(wildcard config.py)
112-
$(OBJ)/build.mk: Makefile $(build-files) build/ab.mk
108+
$(OBJ)/build.ninja $(OBJ)/build.targets &:
113109
@echo "AB"
114-
@mkdir -p $(OBJ)
115-
$(hide) $(PYTHON) -X pycache_prefix=$(OBJ)/__pycache__ build/ab.py -o $@ build.py \
116-
|| rm -f $@
110+
$(hide) $(PYTHON) -X pycache_prefix=$(OBJ)/__pycache__ build/ab.py \
111+
-o $(OBJ) build.py \
112+
-v $(OBJ)/vars.txt \
113+
|| (rm -f $@ && false)
114+
115+
include $(OBJ)/build.targets
116+
.PHONY: $(ninja-targets)
117+
.NOTPARALLEL:
118+
$(ninja-targets): $(OBJ)/build.ninja
119+
+$(hide) $(NINJA) -f $(OBJ)/build.ninja $@

build/ab.ninja

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
rule rule
2+
command = $command

0 commit comments

Comments
 (0)