Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 2 additions & 15 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,18 +1,5 @@
*.o
*.a
obj/
wrk

deps/luajit/src/host/buildvm
deps/luajit/src/host/buildvm_arch.h
deps/luajit/src/host/minilua
deps/luajit/src/jit/vmdef.lua
deps/luajit/src/lj_bcdef.h
deps/luajit/src/lj_ffdef.h
deps/luajit/src/lj_folddef.h
deps/luajit/src/lj_libdef.h
deps/luajit/src/lj_recdef.h
deps/luajit/src/lj_vm.s
deps/luajit/src/luajit

.idea
CMakeLists.txt
CMakeLists.txt
82 changes: 63 additions & 19 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
CFLAGS := -std=c99 -Wall -O2 -D_REENTRANT
LIBS := -lpthread -lm -lcrypto -lssl
CFLAGS += -std=c99 -Wall -O2 -D_REENTRANT
LIBS := -lm -lssl -lcrypto -lpthread

TARGET := $(shell uname -s | tr '[A-Z]' '[a-z]' 2>/dev/null || echo unknown)

ifeq ($(TARGET), sunos)
CFLAGS += -D_PTHREADS -D_POSIX_C_SOURCE=200112L
LIBS += -lsocket
else ifeq ($(TARGET), darwin)
# Per https://luajit.org/install.html: If MACOSX_DEPLOYMENT_TARGET
# is not set then it's forced to 10.4, which breaks compile on Mojave.
export MACOSX_DEPLOYMENT_TARGET = $(shell sw_vers -productVersion)
LDFLAGS += -pagezero_size 10000 -image_base 100000000
LIBS += -L/usr/local/opt/openssl/lib
CFLAGS += -I/usr/local/include -I/usr/local/opt/openssl/include
export MACOSX_DEPLOYMENT_TARGET = $(shell sw_vers -productVersion)
else ifeq ($(TARGET), linux)
CFLAGS += -D_POSIX_C_SOURCE=200809L -D_BSD_SOURCE
CFLAGS += -D_POSIX_C_SOURCE=200112L -D_BSD_SOURCE -D_DEFAULT_SOURCE
LIBS += -ldl
LDFLAGS += -Wl,-E
else ifeq ($(TARGET), freebsd)
Expand All @@ -25,43 +21,91 @@ endif
SRC := wrk.c net.c ssl.c aprintf.c stats.c script.c units.c \
ae.c zmalloc.c http_parser.c tinymt64.c hdr_histogram.c
BIN := wrk
VER ?= $(shell git describe --tags --always --dirty)

ODIR := obj
OBJ := $(patsubst %.c,$(ODIR)/%.o,$(SRC)) $(ODIR)/bytecode.o
OBJ := $(patsubst %.c,$(ODIR)/%.o,$(SRC)) $(ODIR)/bytecode.o $(ODIR)/version.o
LIBS := -lluajit-5.1 $(LIBS)

DEPS :=
CFLAGS += -I$(ODIR)/include
LDFLAGS += -L$(ODIR)/lib

ifneq ($(WITH_LUAJIT),)
CFLAGS += -I$(WITH_LUAJIT)/include
LDFLAGS += -L$(WITH_LUAJIT)/lib
else
CFLAGS += -I$(ODIR)/include/luajit-2.1
DEPS += $(ODIR)/lib/libluajit-5.1.a
endif

LDIR = deps/luajit/src
LIBS := -lluajit $(LIBS)
CFLAGS += -I$(LDIR)
LDFLAGS += -L$(LDIR)
ifneq ($(WITH_OPENSSL),)
CFLAGS += -I$(WITH_OPENSSL)/include
LDFLAGS += -L$(WITH_OPENSSL)/lib
else
DEPS += $(ODIR)/lib/libssl.a
endif

all: $(BIN)

clean:
$(RM) $(BIN) obj/*
@$(MAKE) -C deps/luajit clean
$(RM) -rf $(BIN) obj/*

$(BIN): $(OBJ)
@echo LINK $(BIN)
@$(CC) $(LDFLAGS) -o $@ $^ $(LIBS)

$(OBJ): config.h Makefile $(LDIR)/libluajit.a | $(ODIR)
$(OBJ): config.h Makefile $(DEPS) | $(ODIR)

$(ODIR):
@mkdir -p $@

$(ODIR)/bytecode.o: src/wrk.lua
@echo LUAJIT $<
@$(SHELL) -c 'cd $(LDIR) && ./luajit -b $(CURDIR)/$< $(CURDIR)/$@'
@$(SHELL) -c 'PATH=obj/bin:$(PATH) luajit -b $(CURDIR)/$< $(CURDIR)/$@'

$(ODIR)/version.o:
@echo 'const char *VERSION="$(VER)";' | $(CC) -xc -c -o $@ -

$(ODIR)/%.o : %.c
@echo CC $<
@$(CC) $(CFLAGS) -c -o $@ $<

$(LDIR)/libluajit.a:
# Dependencies

LUAJIT := $(notdir $(patsubst %.tar.gz,%,$(wildcard deps/LuaJIT*.tar.gz)))
OPENSSL := $(notdir $(patsubst %.tar.gz,%,$(wildcard deps/openssl*.tar.gz)))

OPENSSL_OPTS = no-shared no-psk no-srp no-dtls no-idea --prefix=$(abspath $(ODIR))

$(ODIR)/$(LUAJIT): deps/$(LUAJIT).tar.gz | $(ODIR)
@tar -C $(ODIR) -xf $<

$(ODIR)/$(OPENSSL): deps/$(OPENSSL).tar.gz | $(ODIR)
@tar -C $(ODIR) -xf $<

$(ODIR)/lib/libluajit-5.1.a: $(ODIR)/$(LUAJIT)
@echo Building LuaJIT...
@$(MAKE) -C $(LDIR) BUILDMODE=static
@$(MAKE) -C $< PREFIX=$(abspath $(ODIR)) BUILDMODE=static install
@cd $(ODIR)/bin && ln -s luajit-2.1.0-beta3 luajit

$(ODIR)/lib/libssl.a: $(ODIR)/$(OPENSSL)
@echo Building OpenSSL...
ifeq ($(TARGET), darwin)
@$(SHELL) -c "cd $< && ./Configure $(OPENSSL_OPTS) darwin64-x86_64-cc"
else
@$(SHELL) -c "cd $< && ./config $(OPENSSL_OPTS)"
endif
@$(MAKE) -C $< depend
@$(MAKE) -C $<
@$(MAKE) -C $< install_sw
@touch $@

# ------------

.PHONY: all clean
.PHONY: $(ODIR)/version.o

.SUFFIXES:
.SUFFIXES: .c .o .lua

Expand Down
5 changes: 5 additions & 0 deletions SCRIPTING
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ Overview
global setup -- called during thread setup
global init -- called when the thread is starting
global request -- called to generate the HTTP request
global delay -- called to get the request delay
global response -- called with HTTP response data
global done -- called with results of run

Expand All @@ -64,6 +65,7 @@ Setup
Running

function init(args)
function delay()
function request()
function response(status, headers, body)

Expand All @@ -73,6 +75,9 @@ Running
The init() function receives any extra command line arguments for the
script which must be separated from wrk arguments with "--".

delay() returns the number of milliseconds to delay sending the next
request.

request() returns a string containing the HTTP request. Building a new
request each time is expensive, when testing a high performance server
one solution is to pre-generate all requests in init() and do a quick
Expand Down
Binary file added deps/LuaJIT-2.1.0-beta3.tar.gz
Binary file not shown.
56 changes: 0 additions & 56 deletions deps/luajit/COPYRIGHT

This file was deleted.

151 changes: 0 additions & 151 deletions deps/luajit/Makefile

This file was deleted.

Loading