Improve how Makefile handles multiple goals.
- Don't run BUILDSYSTEM more than once if there is more than one goal with '+'. - Don't pass goals without '+' to BUILDSYSTEM. - Use $(MAKE) because "make" might not be GNU make. For me, "make" is BSD make. - Add a comment so readers know MAKECMDGOALS is special. Over in README, remove Lua from requirements; we always ignore any installed Lua and build our own. Increase guesses for free space because we build more platforms. Don't need to type MAKEFLAGS=.
This commit is contained in:
parent
50a7031007
commit
84024ce5b6
2 changed files with 41 additions and 23 deletions
56
Makefile
56
Makefile
|
@ -63,29 +63,50 @@ PLATDEP = $(INSDIR)/lib/ack
|
||||||
|
|
||||||
.NOTPARALLEL:
|
.NOTPARALLEL:
|
||||||
|
|
||||||
MAKECMDGOALS ?= +ack +tests
|
ifeq ($(BUILDSYSTEM),)
|
||||||
BUILD_FILES = $(shell find * -name '*.lua')
|
ifneq ($(shell which ninja),)
|
||||||
|
|
||||||
ifneq ($(shell which ninja),)
|
|
||||||
BUILDSYSTEM = ninja
|
BUILDSYSTEM = ninja
|
||||||
BUILDFLAGS = $(NINJAFLAGS)
|
else
|
||||||
else
|
|
||||||
BUILDSYSTEM = make
|
BUILDSYSTEM = make
|
||||||
BUILDFLAGS = $(MAKEFLAGS)
|
endif
|
||||||
endif
|
endif
|
||||||
|
|
||||||
LUA = $(BUILDDIR)/lua
|
build-file = $(BUILDDIR)/build.$(BUILDSYSTEM)
|
||||||
|
lua-files = $(shell find * -name '*.lua')
|
||||||
|
our-lua = $(BUILDDIR)/lua
|
||||||
|
|
||||||
ifneq ($(findstring +, $(MAKECMDGOALS)),)
|
# GNU make sets MAKECMDGOALS to the list of targets from the command
|
||||||
|
# line. We look for targets with '+' and forward them to BUILDSYSTEM.
|
||||||
|
# This handles commands like
|
||||||
|
# $ make util/opt+pkg util/ego+pkg
|
||||||
|
|
||||||
$(MAKECMDGOALS): $(BUILDDIR)/build.$(BUILDSYSTEM)
|
all-goals = +ack +tests
|
||||||
@$(BUILDSYSTEM) $(BUILDFLAGS) -f $^ $(MAKECMDGOALS)
|
plus-goals := $(patsubst all,$(all-goals),$(or $(MAKECMDGOALS),all))
|
||||||
|
plus-goals := $(foreach g,$(plus-goals),$(if $(findstring +,$(g)),$(g),))
|
||||||
|
|
||||||
|
# @true silences extra message, "make: Nothing to be done..."
|
||||||
|
|
||||||
|
all: build-plus-goals
|
||||||
|
@true
|
||||||
|
|
||||||
|
ifneq ($(plus-goals),)
|
||||||
|
$(plus-goals): build-plus-goals
|
||||||
|
@true
|
||||||
endif
|
endif
|
||||||
|
|
||||||
$(BUILDDIR)/build.$(BUILDSYSTEM): first/ackbuilder.lua Makefile $(BUILD_FILES) $(LUA)
|
build-plus-goals: $(build-file)
|
||||||
|
ifeq ($(BUILDSYSTEM),ninja)
|
||||||
|
@ninja $(NINJAFLAGS) -f $(build-file) $(plus-goals)
|
||||||
|
else ifeq ($(BUILDSYSTEM),make)
|
||||||
|
# GNU make passes MAKEFLAGS in environment.
|
||||||
|
@$(MAKE) -f $(build-file) $(plus-goals)
|
||||||
|
else
|
||||||
|
$(error unknown BUILDSYSTEM = $(BUILDSYSTEM))
|
||||||
|
endif
|
||||||
|
|
||||||
|
$(build-file): first/ackbuilder.lua Makefile $(lua-files) $(our-lua)
|
||||||
@mkdir -p $(BUILDDIR)
|
@mkdir -p $(BUILDDIR)
|
||||||
@$(LUA) first/ackbuilder.lua \
|
@$(our-lua) first/ackbuilder.lua \
|
||||||
first/build.lua build.lua \
|
first/build.lua build.lua \
|
||||||
--$(BUILDSYSTEM) \
|
--$(BUILDSYSTEM) \
|
||||||
DEFAULT_PLATFORM=$(DEFAULT_PLATFORM) \
|
DEFAULT_PLATFORM=$(DEFAULT_PLATFORM) \
|
||||||
|
@ -99,17 +120,16 @@ $(BUILDDIR)/build.$(BUILDSYSTEM): first/ackbuilder.lua Makefile $(BUILD_FILES) $
|
||||||
PREFIX=$(PREFIX) \
|
PREFIX=$(PREFIX) \
|
||||||
AR=$(AR) \
|
AR=$(AR) \
|
||||||
CC=$(CC) \
|
CC=$(CC) \
|
||||||
> $(BUILDDIR)/build.$(BUILDSYSTEM)
|
> $(build-file)
|
||||||
|
|
||||||
install:
|
install:
|
||||||
mkdir -p $(PREFIX)
|
mkdir -p $(PREFIX)
|
||||||
tar cf - -C $(INSDIR) . | tar xvf - -C $(PREFIX)
|
tar cf - -C $(INSDIR) . | tar xvf - -C $(PREFIX)
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
@rm -rf $(BUILDDIR)
|
rm -rf $(BUILDDIR)
|
||||||
|
|
||||||
$(LUA): first/lua-5.1/*.c first/lua-5.1/*.h
|
$(our-lua): first/lua-5.1/*.c first/lua-5.1/*.h
|
||||||
@echo Bootstrapping build
|
@echo Bootstrapping build
|
||||||
@mkdir -p $(BUILDDIR)
|
@mkdir -p $(BUILDDIR)
|
||||||
@$(CC) -o $(LUA) -O first/lua-5.1/*.c -lm
|
@$(CC) -o $(our-lua) -O first/lua-5.1/*.c -lm
|
||||||
|
|
||||||
|
|
8
README
8
README
|
@ -53,8 +53,6 @@ Requirements:
|
||||||
|
|
||||||
- GNU make.
|
- GNU make.
|
||||||
|
|
||||||
- Lua 5.1 and the luaposix library (used by the build system).
|
|
||||||
|
|
||||||
- (optionally) ninja; if you've got this, this will be autodetected and give
|
- (optionally) ninja; if you've got this, this will be autodetected and give
|
||||||
you faster builds.
|
you faster builds.
|
||||||
|
|
||||||
|
@ -63,9 +61,9 @@ Requirements:
|
||||||
architectures. Get both the qemu-system-* platform emulators and the qemu-*
|
architectures. Get both the qemu-system-* platform emulators and the qemu-*
|
||||||
userland emulators (only works on Linux).
|
userland emulators (only works on Linux).
|
||||||
|
|
||||||
- about 40MB free in /tmp (or some other temporary directory).
|
- about 115MB free in /tmp (or some other temporary directory).
|
||||||
|
|
||||||
- about 6MB in the target directory.
|
- about 15MB in the target directory.
|
||||||
|
|
||||||
Instructions:
|
Instructions:
|
||||||
|
|
||||||
|
@ -83,7 +81,7 @@ Instructions:
|
||||||
install ninja and it'll use all your cores. If you don't have ninja, you
|
install ninja and it'll use all your cores. If you don't have ninja, you
|
||||||
can still use make for parallel builds with:
|
can still use make for parallel builds with:
|
||||||
|
|
||||||
make MAKEFLAGS='-r -j8' # or however many cores you have
|
make -r -j8 # or however many cores you have
|
||||||
|
|
||||||
...but frankly, I recommend ninja.
|
...but frankly, I recommend ninja.
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue