Skip to content

Commit

Permalink
src/Makefile: make ./snabb default target and add '.inc' files
Browse files Browse the repository at this point in the history
'make' will now build only ./snabb. If you want to create files in
bin/ (e.g. bin/snabbnfv) then use 'make bin/<program>' or 'make all'.

Files named *.inc are now (inc)luded in the executable.

Specifically, the contents of a file named

    src/foo/bar.inc

can be loaded as a string with

    require("foo.bar_inc")

This is useful in several ways:

- Command-line documentation can be written into a README file
  (visible on Github) and this can be included in the binary.

- Shell scripts can be written in .sh files and embdedded.
  (This is handy for snabbnfv shell scripts at the moment.)

- Version information could be generated and included too.
  • Loading branch information
lukego committed Feb 22, 2015
1 parent 88f4dc6 commit 3b8d459
Showing 1 changed file with 19 additions and 11 deletions.
30 changes: 19 additions & 11 deletions src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ CSRC = $(shell find . -regex '[^\#]*\.c' -printf '%P ')
CHDR = $(shell find . -regex '[^\#]*\.h' -printf '%P ')
ASM = $(shell find . -regex '[^\#]*\.dasc' -printf '%P ')
RMSRC = $(shell find . -name README.md.src -printf '%P ')
PROGRAM = $(shell find program -type d -printf '%P ')
# regexp is to include program/foo but not program/foo/bar
PROGRAM = $(shell find program -regex '^[^/]+/[^/]+' -type d -printf '%P ')
INCSRC = $(shell find . -regex '[^\#]*\.inc' -printf '%P ')

LUAOBJ := $(patsubst %.lua,obj/%_lua.o,$(LUASRC))
COBJ := $(patsubst %.c,obj/%_c.o, $(CSRC))
Expand All @@ -23,6 +25,7 @@ ASMOBJ := $(patsubst %.dasc,obj/%_dasc.o, $(ASM))
JITOBJS:= $(patsubst %,obj/jit_%.o,$(JITSRC))
EXTRAOBJS := obj/jit_tprof.o obj/jit_vmprof.o obj/strict.o
RMOBJS := $(patsubst %.src,%,$(RMSRC))
INCOBJ := $(patsubst %.inc,obj/%_inc.o, $(INCSRC))
EXE := bin/snabb $(patsubst %,bin/%,$(PROGRAM))

# TESTMODS expands to:
Expand All @@ -39,7 +42,14 @@ TESTSCRIPTS = $(shell find . -name "selftest.sh" -executable | xargs)

PATH := ../deps/luajit/usr/local/bin:$(PATH)

default: bin/snabb
snabb: $(LUAOBJ) $(HOBJ) $(COBJ) $(ASMOBJ) $(INCOBJ)
$(E) "LINK $@"
$(Q) gcc -Wl,--no-as-needed -Wl,-E -Werror -Wall -o $@ $^ \
../deps/luajit/src/libluajit.a \
-lc -ldl -lm -lrt -lpthread
@echo -n "BINARY "
@ln -fs snabb snabbswitch
@ls -sh snabb

all: $(EXE)

Expand All @@ -49,15 +59,6 @@ $(EXE): snabb

markdown: $(RMOBJS)

snabb: $(LUAOBJ) $(HOBJ) $(COBJ) $(ASMOBJ)
$(E) "LINK $@"
$(Q) gcc -Wl,--no-as-needed -Wl,-E -Werror -Wall -o $@ $^ \
../deps/luajit/src/libluajit.a \
-lc -ldl -lm -lrt -lpthread
@echo -n "BINARY "
@ln -fs snabb snabbswitch
@ls -sh snabb

test: $(TESTMODS) $(TESTSCRIPTS)

test_ci: FAIL_ON_FIRST="true"
Expand Down Expand Up @@ -130,6 +131,13 @@ $(RMOBJS): %: %.src
$(E) "MARKDOWN $@"
$(Q) scripts/process-markdown $< > $@

$(INCOBJ): obj/%_inc.o: %.inc Makefile | $(OBJDIR)
$(E) "INC $@"
@(echo -n "return [=============["; \
cat $<; \
echo "]=============]") > $(basename $@).luainc
$(Q) luajit -bg -n $(subst /,.,$*)_inc $(basename $@).luainc $@

# extra/ third party bits and pieces
obj/strict.o: extra/strict.lua | $(OBJDIR)
$(E) "LUA $@"
Expand Down

0 comments on commit 3b8d459

Please sign in to comment.