diff --git a/Makefile b/Makefile index b3955ca40..9dae29060 100644 --- a/Makefile +++ b/Makefile @@ -55,27 +55,21 @@ NINJA := $(shell which ninja) ifneq ($(findstring +, $(MAKECMDGOALS)),) ifneq ($(NINJA),) -$(MAKECMDGOALS): $(BUILDDIR)/build.ninja $(BUILDDIR)/rules.ninja +$(MAKECMDGOALS): $(BUILDDIR)/build.ninja @ninja -f $(BUILDDIR)/build.ninja $(MAKECMDGOALS) -$(BUILDDIR)/build.ninja: Makefile - @mkdir -p $(BUILDDIR) - @echo "OBJDIR = $(OBJDIR)" > $@ - @echo "BINDIR = $(BINDIR)" >> $@ - @echo "LIBDIR = $(LIBDIR)" >> $@ - @echo "INCDIR = $(INCDIR)" >> $@ - @echo "INSDIR = $(INSDIR)" >> $@ - @echo "PLATIND = $(PLATIND)" >> $@ - @echo "PLATDEP = $(PLATDEP)" >> $@ - @echo "AR = $(AR)" >> $@ - @echo "CC = $(CC)" >> $@ - @echo "subninja $(BUILDDIR)/rules.ninja" >> $@ - else $(MAKECMDGOALS): $(BUILDDIR)/rules.mk +@make -r -f $(BUILDDIR)/rules.mk $@ \ - $(MAKEFLAGS) \ + $(MAKEFLAGS) + +endif +endif + +$(BUILDDIR)/build.ninja: first/ackbuilder.lua Makefile $(BUILD_FILES) + @mkdir -p $(BUILDDIR) + @lua5.1 first/ackbuilder.lua first/build.lua build.lua --ninja \ OBJDIR=$(OBJDIR) \ BINDIR=$(BINDIR) \ LIBDIR=$(LIBDIR) \ @@ -84,18 +78,22 @@ $(MAKECMDGOALS): $(BUILDDIR)/rules.mk PLATIND=$(PLATIND) \ PLATDEP=$(PLATDEP) \ AR=$(AR) \ - CC=$(CC) + CC=$(CC) \ + > $(BUILDDIR)/build.ninja -endif -endif - -$(BUILDDIR)/rules.ninja: first/ackbuilder.lua $(BUILD_FILES) +$(BUILDDIR)/rules.mk: first/ackbuilder.lua Makefile $(BUILD_FILES) @mkdir -p $(BUILDDIR) - @lua5.1 first/ackbuilder.lua first/build.lua build.lua --ninja > $(BUILDDIR)/rules.ninja - -$(BUILDDIR)/rules.mk: first/ackbuilder.lua $(BUILD_FILES) - @mkdir -p $(BUILDDIR) - @lua5.2 first/ackbuilder.lua first/build.lua build.lua --make > $(BUILDDIR)/rules.mk + @lua5.1 first/ackbuilder.lua first/build.lua build.lua --make \ + OBJDIR=$(OBJDIR) \ + BINDIR=$(BINDIR) \ + LIBDIR=$(LIBDIR) \ + INCDIR=$(INCDIR) \ + INSDIR=$(INSDIR) \ + PLATIND=$(PLATIND) \ + PLATDEP=$(PLATDEP) \ + AR=$(AR) \ + CC=$(CC) \ + > $(BUILDDIR)/rules.mk clean: @rm -rf $(BUILDDIR) diff --git a/first/ackbuilder.lua b/first/ackbuilder.lua index 2333461ee..c90d1d021 100644 --- a/first/ackbuilder.lua +++ b/first/ackbuilder.lua @@ -602,6 +602,12 @@ end local function install_make_emitter() emit("hide = @\n") + + function emitter:var(name, value) + -- Don't let emit insert spaces. + emit(name.."="..value.."\n") + end + function emitter:rule(name, ins, outs) emit(".INTERMEDIATE:", name, "\n") for i = 1, #ins do @@ -656,6 +662,11 @@ local function install_ninja_emitter() ) end + function emitter:var(name, value) + -- Don't let emit insert spaces. + emit(name.."="..unmake(value).."\n") + end + function emitter:rule(name, ins, outs) if (#outs == 0) then emit("build", name, ": phony", unmake(ins), "\n") @@ -853,22 +864,33 @@ do { ["make"] = function() emitter_type = install_make_emitter - return 1 + return 0 end, ["ninja"] = function() emitter_type = install_ninja_emitter - return 1 + return 0 end, + [" unrecognised"] = function(arg) error(string.format("unrecognised argument '%s'", arg)) end, [" files"] = function(files) emitter_type() + for _, f in ipairs(files) do - loadbuildfile(f) + local _, _, name, value = f:find("^([%w_]+)=(.*)$") + if name then + emitter:var(name, value) + end + end + + for _, f in ipairs(files) do + if not f:find("=") then + loadbuildfile(f) + end end end },