Makefile 3.36 KB
Newer Older
1 2 3
# vim: ts=8 noet sw=8 ai cin smarttab

PROG = unit_test
4 5 6

MONGOOSE_DIR = ..

7
SRC_DIR = ../src
8 9 10 11 12 13 14 15 16 17

COMMON_DIR_PUB = ../src/common
COMMON_DIR_DEV = ../../common

ifneq ("$(wildcard ../../fw/defs)","")
COMMON_PARENT = ../..
else
COMMON_PARENT = $(SRC_DIR)
endif

18
TEST_SOURCES = unit_test.c test_util.c test_main.c
19 20
AMALGAMATED_SOURCES = ../mongoose.c
KRYPTON_PATH = $(REPO_ROOT)/krypton
21 22 23 24 25

# Our dev repo and public mongoose repo have different layouts, so here
# we make it work on both
VPATH = $(MONGOOSE_DIR) $(SRC_DIR) $(COMMON_DIR_PUB) $(COMMON_DIR_DEV) $(COMMON_PARENT)

26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
# or Krypton, or mbedTLS
SSL ?= OpenSSL

COMMON_FEATURE_FLAGS = \
	-DKR_MODULE_LINES \
	-DMG_ENABLE_COAP \
	-DMG_ENABLE_DNS_SERVER \
	-DMG_ENABLE_HTTP_SSI_EXEC \
	-DMG_ENABLE_HTTP_WEBDAV \
	-DMG_ENABLE_MQTT_BROKER \
	-DMG_ENABLE_SOCKS \
	-DMG_ENABLE_SYNC_RESOLVER \
	-DMG_ENABLE_THREADS \
	-DMG_DISABLE_DAV_AUTH \
	-DMG_INTERNAL="" \
	-DMG_MODULE_LINES \
	-DMG_CALLOC=test_calloc \
	-DMG_MALLOC=test_malloc \
	-DMG_ENABLE_POLL_UNTIL \
	-DMG_ENABLE_SNTP -DMG_SNTP_NO_DELAY_CORRECTION \
	-DMG_ENABLE_HTTP_STREAMING_MULTIPART
UNIX_FEATURE_FLAGS=-DMG_ENABLE_IPV6 -DMG_ENABLE_SSL
48 49 50
# TODO: remove -Wno-deprecated-declarations once deprecated
# `mg_http_parse_header()` is removed from mongoose.
CFLAGS = -W -Wall -Wundef -Werror -Wno-deprecated-declarations -g -O0 -Wno-multichar -D__USE_MISC \
51
	 $(COMMON_FEATURE_FLAGS) $(UNIX_FEATURE_FLAGS) \
52 53
	 $(patsubst %,-I%,$(subst :, ,$(VPATH))) \
	 -include unit_test.h -pthread $(CFLAGS_EXTRA)
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69

LDFLAGS = -lm

ifeq "$(SSL)" "OpenSSL"
# OpenSSL is the default
LDFLAGS += -lcrypto -lssl
endif
ifeq "$(SSL)" "Krypton"
CFLAGS += $(KRYPTON_PATH)/krypton.c -I$(KRYPTON_PATH)
endif
ifeq "$(SSL)" "mbedTLS"
CFLAGS += -DMG_SSL_IF=MG_SSL_IF_MBEDTLS -DMG_SSL_MBED_DUMMY_RANDOM
LDFLAGS += -lmbedcrypto -lmbedtls -lmbedx509
endif

include test.mk
70
include $(SRC_DIR)/mg_modules.mk
71 72 73 74 75 76 77 78 79

# http://crossgcc.rts-software.org/doku.php?id=compiling_for_win32
MINGW_GCC=/usr/local/gcc-4.8.0-qt-4.8.4-for-mingw32/win32-gcc/bin/i586-mingw32-gcc

.PHONY: $(PROG).exe $(PROG)_mingw.exe

$(PROG)_mingw.exe: Makefile
	$(MINGW_GCC) $(AMALGAMATED_SOURCES) -o $(PROG)_mingw.exe -W -Wall -Werror

80
$(PROG).exe: $(AMALGAMATED_SOURCES) data/cgi/index.cgi.exe test_sources_resolved
81 82 83 84 85
ifndef VC6_DIR
	$(error Please set VC6_DIR)
endif
	Include=$(VC6_DIR)/include Lib=$(VC6_DIR)/lib \
	wine $(VC6_DIR)/bin/cl \
86
	  $(TEST_SOURCES_RESOLVED) $(AMALGAMATED_SOURCES) \
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
	  /MD /I. /I.. /Zi \
	  /FIunit_test.h \
	  /I$(REPO_ROOT) \
	  $(COMMON_FEATURE_FLAGS) $(CFLAGS_EXTRA) \
	  -DMG_ENABLE_SSL $(KRYPTON_PATH)/krypton.c -I$(KRYPTON_PATH) \
	  kernel32.lib advapi32.lib \
	  /Fe$@
	cp data/cgi/index.cgi.exe data/cgi/index.cgi

win: $(PROG).exe
	wine $(PROG).exe $(TEST_FILTER)

# CGI test program.

$(PROG)-%: data/cgi/index.cgi

data/cgi/index.cgi: index_cgi.c ccgi-1.2/ccgi.c
	@echo -e "CC\tindex.cgi"
	@mkdir -p data/cgi
	@$(CC) -Wall -Werror -o $@ $^ -Iccgi-1.2

data/cgi/index.cgi.exe: index_cgi.c ccgi-1.2/ccgi.c
	@echo -e "CC\tindex.cgi.exe"
	@mkdir -p data/cgi
	Include=$(VC6_DIR)/include Lib=$(VC6_DIR)/lib \
	wine $(VC6_DIR)/bin/cl \
	  /MD /Iccgi-1.2 /Zi index_cgi.c ccgi-1.2/ccgi.c /Fe$@

clean: clean_index_cgi

clean_index_cgi:
	@echo -e "CLEAN\tindex.cgi"
	@rm -f data/cgi/index.cgi*

# Interactive:
#   docker run -v $(CURDIR)/../..:/cesanta -t -i --entrypoint=/bin/bash cesanta/mongoose_test
docker:
	docker run --rm -v $(CURDIR)/../..:/cesanta cesanta/mongoose_test