2013-03-03 17:24:41 +08:00
|
|
|
CFLAGS := -std=c99 -Wall -O2 -D_REENTRANT
|
2016-03-20 14:55:25 +08:00
|
|
|
LIBS := -lpthread -lm -lssl -lcrypto
|
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
|
2013-03-03 17:24:41 +08:00
|
|
|
LIBS += -lsocket
|
2013-08-18 12:38:06 +08:00
|
|
|
else ifeq ($(TARGET), darwin)
|
|
|
|
LDFLAGS += -pagezero_size 10000 -image_base 100000000
|
2013-08-18 19:37:21 +08:00
|
|
|
else ifeq ($(TARGET), linux)
|
2015-02-07 16:03:17 +08:00
|
|
|
CFLAGS += -D_POSIX_C_SOURCE=200112L -D_BSD_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
|
|
|
|
|
|
|
|
ODIR := obj
|
2013-11-16 11:06:29 +08:00
|
|
|
OBJ := $(patsubst %.c,$(ODIR)/%.o,$(SRC)) $(ODIR)/bytecode.o
|
2012-03-18 14:16:09 +08:00
|
|
|
|
2016-03-20 14:55:25 +08:00
|
|
|
LIBS := -lluajit-5.1 $(LIBS)
|
|
|
|
CFLAGS += -I$(ODIR)/include
|
|
|
|
LDFLAGS += -L$(ODIR)/lib
|
|
|
|
DEPS := $(ODIR)/lib/libluajit-5.1.a $(ODIR)/lib/libssl.a
|
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
|
|
|
|
2013-11-16 11:06:29 +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
|
|
|
|
2013-11-16 11:06:29 +08:00
|
|
|
$(ODIR):
|
2013-08-18 12:38:06 +08:00
|
|
|
@mkdir -p $@
|
|
|
|
|
2013-12-07 13:09:44 +08:00
|
|
|
$(ODIR)/bytecode.o: src/wrk.lua
|
2013-08-18 12:38:06 +08:00
|
|
|
@echo LUAJIT $<
|
2016-03-20 14:55:25 +08:00
|
|
|
@$(SHELL) -c 'obj/bin/luajit -b $(CURDIR)/$< $(CURDIR)/$@'
|
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 %.tar.gz,%,$(wildcard deps/LuaJIT*.tar.gz)))
|
|
|
|
OPENSSL := $(notdir $(patsubst %.tar.gz,%,$(wildcard deps/openssl*.tar.gz)))
|
|
|
|
|
|
|
|
OPENSSL_OPTS = no-shared no-ssl2 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)
|
2013-11-16 11:06:29 +08:00
|
|
|
@echo Building LuaJIT...
|
2016-03-20 14:55:25 +08:00
|
|
|
@$(MAKE) -C $< PREFIX=$(abspath $(ODIR)) BUILDMODE=static install
|
|
|
|
|
|
|
|
$(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 install
|
|
|
|
|
|
|
|
# ------------
|
2012-03-18 14:16:09 +08:00
|
|
|
|
|
|
|
.PHONY: all clean
|
|
|
|
.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
|