1
0
mirror of https://github.com/wg/wrk synced 2025-01-08 06:52:55 +08:00
wrk/Makefile

111 lines
2.6 KiB
Makefile
Raw Permalink Normal View History

2016-03-20 15:26:48 +08:00
CFLAGS += -std=c99 -Wall -O2 -D_REENTRANT
2019-04-18 09:48:58 +08:00
LIBS := -lm -lssl -lcrypto -lpthread
2013-01-12 15:21:02 +08:00
2014-05-15 19:11:07 +08:00
TARGET := $(shell uname -s | tr '[A-Z]' '[a-z]' 2>/dev/null || echo unknown)
2013-01-12 15:21:02 +08:00
ifeq ($(TARGET), sunos)
2013-04-07 13:37:24 +08:00
CFLAGS += -D_PTHREADS -D_POSIX_C_SOURCE=200112L
LIBS += -lsocket
2013-08-18 12:38:06 +08:00
else ifeq ($(TARGET), darwin)
export MACOSX_DEPLOYMENT_TARGET = $(shell sw_vers -productVersion)
2013-08-18 19:37:21 +08:00
else ifeq ($(TARGET), linux)
2018-01-21 14:00:58 +08:00
CFLAGS += -D_POSIX_C_SOURCE=200112L -D_BSD_SOURCE -D_DEFAULT_SOURCE
2013-08-18 19:37:21 +08:00
LIBS += -ldl
LDFLAGS += -Wl,-E
else ifeq ($(TARGET), freebsd)
CFLAGS += -D_DECLARE_C99_LDBL_MATH
2013-08-18 12:38:06 +08:00
LDFLAGS += -Wl,-E
2013-01-12 15:21:02 +08:00
endif
2012-03-18 14:16:09 +08:00
2013-08-18 12:38:06 +08:00
SRC := wrk.c net.c ssl.c aprintf.c stats.c script.c units.c \
2015-02-11 10:31:55 +08:00
ae.c zmalloc.c http_parser.c
2012-03-18 14:16:09 +08:00
BIN := wrk
2016-03-20 16:03:36 +08:00
VER ?= $(shell git describe --tags --always --dirty)
2012-03-18 14:16:09 +08:00
ODIR := obj
2016-03-20 16:03:36 +08:00
OBJ := $(patsubst %.c,$(ODIR)/%.o,$(SRC)) $(ODIR)/bytecode.o $(ODIR)/version.o
2016-03-20 15:26:48 +08:00
LIBS := -lluajit-5.1 $(LIBS)
2012-03-18 14:16:09 +08:00
2016-03-20 15:26:48 +08:00
DEPS :=
2016-03-20 14:55:25 +08:00
CFLAGS += -I$(ODIR)/include
LDFLAGS += -L$(ODIR)/lib
2016-03-20 15:26:48 +08:00
ifneq ($(WITH_LUAJIT),)
CFLAGS += -I$(WITH_LUAJIT)/include
LDFLAGS += -L$(WITH_LUAJIT)/lib
else
2018-01-21 13:47:22 +08:00
CFLAGS += -I$(ODIR)/include/luajit-2.1
2018-01-21 13:05:34 +08:00
DEPS += $(ODIR)/lib/libluajit-5.1.a
2016-03-20 15:26:48 +08:00
endif
ifneq ($(WITH_OPENSSL),)
CFLAGS += -I$(WITH_OPENSSL)/include
LDFLAGS += -L$(WITH_OPENSSL)/lib
else
DEPS += $(ODIR)/lib/libssl.a
endif
2013-08-18 12:38:06 +08:00
2012-03-18 14:16:09 +08:00
all: $(BIN)
clean:
2016-03-20 14:55:25 +08:00
$(RM) -rf $(BIN) obj/*
2012-03-18 14:16:09 +08:00
$(BIN): $(OBJ)
2013-08-18 12:38:06 +08:00
@echo LINK $(BIN)
@$(CC) $(LDFLAGS) -o $@ $^ $(LIBS)
2012-03-18 14:16:09 +08:00
2016-03-20 14:55:25 +08:00
$(OBJ): config.h Makefile $(DEPS) | $(ODIR)
2012-03-18 14:16:09 +08:00
$(ODIR):
2013-08-18 12:38:06 +08:00
@mkdir -p $@
2021-02-06 07:38:22 +08:00
$(ODIR)/bytecode.c: src/wrk.lua $(DEPS)
2013-08-18 12:38:06 +08:00
@echo LUAJIT $<
2021-02-06 07:38:22 +08:00
@$(SHELL) -c 'PATH="obj/bin:$(PATH)" luajit -b "$(CURDIR)/$<" "$(CURDIR)/$@"'
2012-03-18 14:16:09 +08:00
2016-03-20 16:03:36 +08:00
$(ODIR)/version.o:
@echo 'const char *VERSION="$(VER)";' | $(CC) -xc -c -o $@ -
2012-03-18 14:16:09 +08:00
$(ODIR)/%.o : %.c
2013-08-18 12:38:06 +08:00
@echo CC $<
@$(CC) $(CFLAGS) -c -o $@ $<
2016-03-20 14:55:25 +08:00
# Dependencies
LUAJIT := $(notdir $(patsubst %.zip,%,$(wildcard deps/LuaJIT*.zip)))
2016-03-20 14:55:25 +08:00
OPENSSL := $(notdir $(patsubst %.tar.gz,%,$(wildcard deps/openssl*.tar.gz)))
2017-02-05 13:05:52 +08:00
OPENSSL_OPTS = no-shared no-psk no-srp no-dtls no-idea --prefix=$(abspath $(ODIR))
2016-03-20 14:55:25 +08:00
$(ODIR)/$(LUAJIT): deps/$(LUAJIT).zip | $(ODIR)
echo $(LUAJIT)
@unzip -nd $(ODIR) $<
2016-03-20 14:55:25 +08:00
$(ODIR)/$(OPENSSL): deps/$(OPENSSL).tar.gz | $(ODIR)
@tar -C $(ODIR) -xf $<
$(ODIR)/lib/libluajit-5.1.a: $(ODIR)/$(LUAJIT)
@echo Building LuaJIT...
2016-03-20 14:55:25 +08:00
@$(MAKE) -C $< PREFIX=$(abspath $(ODIR)) BUILDMODE=static install
2018-01-21 13:47:22 +08:00
@cd $(ODIR)/bin && ln -s luajit-2.1.0-beta3 luajit
2016-03-20 14:55:25 +08:00
$(ODIR)/lib/libssl.a: $(ODIR)/$(OPENSSL)
@echo Building OpenSSL...
@$(SHELL) -c "cd $< && ./config $(OPENSSL_OPTS)"
2017-02-05 13:05:52 +08:00
@$(MAKE) -C $< depend
@$(MAKE) -C $<
@$(MAKE) -C $< install_sw
@touch $@
2016-03-20 14:55:25 +08:00
# ------------
2012-03-18 14:16:09 +08:00
.PHONY: all clean
2016-03-20 16:03:36 +08:00
.PHONY: $(ODIR)/version.o
2012-03-18 14:16:09 +08:00
.SUFFIXES:
2013-08-18 12:38:06 +08:00
.SUFFIXES: .c .o .lua
2012-03-18 14:16:09 +08:00
2013-08-18 12:38:06 +08:00
vpath %.c src
vpath %.h src
vpath %.lua scripts