diff --git a/examples/Makefile b/examples/Makefile index 8b1313a6b08cacddfe45aa20377f417c82ebe49b..7759464be88c8a7a961d2aaffbaad89e1a1e4d43 100644 --- a/examples/Makefile +++ b/examples/Makefile @@ -2,7 +2,10 @@ # All rights reserved SUBDIRS = $(sort $(dir $(wildcard */))) -X = $(SUBDIRS) + +ifeq ($(OS), Windows_NT) + SUBDIRS:=$(filter-out load_balancer/ netcat/ raspberry_pi_mjpeg_led/, $(SUBDIRS)) +endif .PHONY: $(SUBDIRS) diff --git a/examples/api_server/Makefile b/examples/api_server/Makefile index 9face7f6c407be0009a351905ef6285045c84fd2..4886a593628f6c7bb2d8d149b57e1de885c213f9 100644 --- a/examples/api_server/Makefile +++ b/examples/api_server/Makefile @@ -1,12 +1,15 @@ PROG = api_server SOURCES = $(PROG).c sqlite3.c db_plugin_sqlite.c ../../mongoose.c -CFLAGS = -W -Wall -pthread $(CFLAGS_EXTRA) +CFLAGS = -W -Wall $(CFLAGS_EXTRA) + ifeq ($(OS), Windows_NT) + CFLAGS += -lws2_32 -D_MG_PROVIDE_STRNLEN + CC = mingw32-gcc else UNAME_S := $(shell uname -s) ifeq ($(UNAME_S), Linux) - CFLAGS += -ldl -lm + CFLAGS += -ldl -lm -pthread endif endif diff --git a/examples/captive_dns_server/Makefile b/examples/captive_dns_server/Makefile index 86640fd3927d4288672593b48774dc36ba6769ab..ff6b2053f9a3c3c2bff8c168697d712213479096 100644 --- a/examples/captive_dns_server/Makefile +++ b/examples/captive_dns_server/Makefile @@ -1,4 +1,4 @@ PROG = captive_dns_server -MODULE_CFLAGS=-DMG_ENABLE_DNS_SERVER - -include ../rules.mk +MODULE_CFLAGS=-DMG_ENABLE_DNS_SERVER -DMG_ENABLE_IPV6 +SSL_LIB=openssl +include ../examples.mk diff --git a/examples/coap_client/Makefile b/examples/coap_client/Makefile index 1726c41c106e87587c3415441cd00ea763b8edcb..c169d2ee6d9d3383bcdb9aaafa548041e81d476d 100644 --- a/examples/coap_client/Makefile +++ b/examples/coap_client/Makefile @@ -1,14 +1,3 @@ PROG = coap_client -SOURCES = $(PROG).c ../../mongoose.c -CFLAGS = -W -Wall -I../.. $(CFLAGS_EXTRA) -DMG_ENABLE_COAP - -all: $(PROG) - -$(PROG): $(SOURCES) - $(CC) $(SOURCES) -o $@ $(CFLAGS) - -$(PROG).exe: $(SOURCES) - cl $(SOURCES) /I../.. /MD /Fe$@ - -clean: - rm -rf *.gc* *.dSYM *.exe *.obj *.o a.out $(PROG) +MODULE_CFLAGS = -DMG_ENABLE_COAP +include ../examples.mk diff --git a/examples/coap_server/Makefile b/examples/coap_server/Makefile index c2920f95d75d574545fdadbda6975eaccf99dd3a..c192f51b00f56c58a8cd3551b29e31d25c11f4e2 100644 --- a/examples/coap_server/Makefile +++ b/examples/coap_server/Makefile @@ -1,14 +1,3 @@ PROG = coap_server -SOURCES = $(PROG).c ../../mongoose.c -CFLAGS = -W -Wall -I../.. $(CFLAGS_EXTRA) -DMG_ENABLE_COAP - -all: $(PROG) - -$(PROG): $(SOURCES) - $(CC) $(SOURCES) -o $@ $(CFLAGS) - -$(PROG).exe: $(SOURCES) - cl $(SOURCES) /I../.. /MD /Fe$@ - -clean: - rm -rf *.gc* *.dSYM *.exe *.obj *.o a.out $(PROG) +MODULE_CFLAGS = -DMG_ENABLE_COAP +include ../examples.mk diff --git a/examples/examples.mk b/examples/examples.mk index 4d5815d745d48b39cb135d27df43ee872b55f230..7edd607d1451e3513a90ad88410d2dd66fa762c6 100644 --- a/examples/examples.mk +++ b/examples/examples.mk @@ -3,6 +3,24 @@ CFLAGS = -g -W -Wall -I../.. -Wno-unused-function $(CFLAGS_EXTRA) $(MODULE_CFLAG all: $(PROG) +ifeq ($(OS), Windows_NT) +# TODO(alashkin): enable SSL in Windows +CFLAGS += -lws2_32 -D_MG_PROVIDE_STRNLEN +CC = mingw32-gcc +else +ifeq ($(SSL_LIB),openssl) +CFLAGS += -DMG_ENABLE_SSL -lssl -lcrypto +else ifeq ($(SSL_LIB), krypton) +CFLAGS += -DMG_ENABLE_SSL ../../../krypton/krypton.c +endif +CFLAGS += -lpthread +endif + +ifeq ($(JS), yes) + V7_PATH = ../../deps/v7 + CFLAGS_EXTRA += -DMG_ENABLE_JAVASCRIPT -I $(V7_PATH) $(V7_PATH)/v7.c +endif + $(PROG): $(SOURCES) $(CC) $(SOURCES) -o $@ $(CFLAGS) diff --git a/examples/http_client/Makefile b/examples/http_client/Makefile index 93932ad015206f5e387504b9b5d5910fda4cf011..c801491ab4995dba89f76faba204b507e859f9a2 100644 --- a/examples/http_client/Makefile +++ b/examples/http_client/Makefile @@ -1,14 +1,3 @@ PROG = http_client -SOURCES = $(PROG).c ../../mongoose.c -CFLAGS = -W -Wall -I../.. -DMG_ENABLE_SSL -lssl -lcrypto -pthread $(CFLAGS_EXTRA) - -all: $(PROG) - -$(PROG): $(SOURCES) - $(CC) $(SOURCES) -o $@ $(CFLAGS) - -$(PROG).exe: $(SOURCES) - cl $(SOURCES) /I../.. /MD /Fe$@ - -clean: - rm -rf *.gc* *.dSYM *.exe *.obj *.o a.out $(PROG) +SSL_LIB=open_ssl +include ../examples.mk diff --git a/examples/json_rpc_server/Makefile b/examples/json_rpc_server/Makefile index 84ea60494cb4d8edc12c0e5fdc7353d635ce0fee..5ba4097197816a784d18c0c62023d1eb0dd4e821 100644 --- a/examples/json_rpc_server/Makefile +++ b/examples/json_rpc_server/Makefile @@ -1,14 +1,2 @@ PROG = json_rpc_server -SOURCES = $(PROG).c ../../mongoose.c -CFLAGS = -W -Wall -I../.. -pthread $(CFLAGS_EXTRA) - -all: $(PROG) - -$(PROG): $(SOURCES) - $(CC) $(SOURCES) -o $@ $(CFLAGS) - -$(PROG).exe: $(SOURCES) - cl $(SOURCES) /I../.. /MD /Fe$@ - -clean: - rm -rf *.gc* *.dSYM *.exe *.obj *.o a.out $(PROG) +include ../examples.mk diff --git a/examples/mqtt_broker/Makefile b/examples/mqtt_broker/Makefile index f97d4000044130be64118f854e9dee27ad3a4ab2..b289e3380234f784a17693ab03b7051e01a36306 100644 --- a/examples/mqtt_broker/Makefile +++ b/examples/mqtt_broker/Makefile @@ -1,14 +1,4 @@ PROG = mqtt_broker -SOURCES = $(PROG).c ../../mongoose.c -CFLAGS = -W -Wall -I../.. -pthread -DMG_ENABLE_SSL -DMG_ENABLE_MQTT_BROKER -lssl -lcrypto $(CFLAGS_EXTRA) - -all: $(PROG) - -$(PROG): $(SOURCES) - $(CC) $(SOURCES) -o $@ $(CFLAGS) - -$(PROG).exe: $(SOURCES) - cl $(SOURCES) /I../.. /DMG_ENABLE_SSL /DMG_ENABLE_MQTT_BROKER /MD /Fe$@ - -clean: - rm -rf *.gc* *.dSYM *.exe *.obj *.o a.out $(PROG) +MODULE_CFLAGS = -DMG_ENABLE_MQTT_BROKER +SSL_LIB=open_ssl +include ../examples.mk diff --git a/examples/mqtt_client/Makefile b/examples/mqtt_client/Makefile index 7ad990dd19643ff2876ca484be1d7dea95a3f507..d6c4ed939bf7a71554dfb064be16cbf9d63751be 100644 --- a/examples/mqtt_client/Makefile +++ b/examples/mqtt_client/Makefile @@ -1,14 +1,4 @@ PROG = mqtt_client -SOURCES = $(PROG).c ../../mongoose.c -CFLAGS = -W -Wall -I../.. -pthread -DMG_ENABLE_SSL -lssl -lcrypto $(CFLAGS_EXTRA) - -all: $(PROG) - -$(PROG): $(SOURCES) - $(CC) $(SOURCES) -o $@ $(CFLAGS) - -$(PROG).exe: $(SOURCES) - cl $(SOURCES) /I../.. /DMG_ENABLE_SSL /MD /Fe$@ - -clean: - rm -rf *.gc* *.dSYM *.exe *.obj *.o a.out $(PROG) +MODULE_CFLAGS = -DMG_ENABLE_MQTT_BROKER +SSL_LIB=open_ssl +include ../examples.mk diff --git a/examples/multithreaded_restful_server/Makefile b/examples/multithreaded_restful_server/Makefile index 7e7db3b14b43915236b185c5e7eee35adbbbcf12..54fddd794b1c8e89b5dd8edac15453427816208e 100644 --- a/examples/multithreaded_restful_server/Makefile +++ b/examples/multithreaded_restful_server/Makefile @@ -1,18 +1,4 @@ PROG = multithreaded_restful_server -SOURCES = $(PROG).c ../../mongoose.c -APP_FLAGS = -DMG_ENABLE_THREADS $(CFLAGS_EXTRA) - -ifeq ($(OS), Windows_NT) -APP_FLAGS += advapi32.lib -endif - -all: $(PROG) - -$(PROG): $(SOURCES) - $(CC) $(SOURCES) -o $@ -W -Wall -I../.. -pthread $(APP_FLAGS) - -$(PROG).exe: $(SOURCES) - cl $(SOURCES) /I../.. /MD /Fe$@ $(APP_FLAGS) - -clean: - rm -rf *.gc* *.dSYM *.exe *.obj *.o a.out $(PROG) +MODULE_CFLAGS = -DMG_ENABLE_THREADS +SSL_LIB=open_ssl +include ../examples.mk diff --git a/examples/netcat/Makefile b/examples/netcat/Makefile index 71b75b920c611a3eb7afdb73f6218b29c16a989d..c71d7fe8c4a1b2b22bc35ac001175a709396adbe 100644 --- a/examples/netcat/Makefile +++ b/examples/netcat/Makefile @@ -1,14 +1,4 @@ PROG = nc -SOURCES = $(PROG).c ../../mongoose.c -CFLAGS = -W -Wall -I../.. -pthread -DMG_ENABLE_SSL -DMG_ENABLE_THREADS -lssl -lcrypto $(CFLAGS_EXTRA) - -all: $(PROG) - -$(PROG): $(SOURCES) - $(CC) $(SOURCES) -o $@ $(CFLAGS) - -$(PROG).exe: $(SOURCES) - cl $(SOURCES) /I../.. /DMG_ENABLE_SSL /MD /Fe$@ - -clean: - rm -rf *.gc* *.dSYM *.exe *.obj *.o a.out $(PROG) +MODULE_CFLAGS=-DMG_ENABLE_THREADS +SSL_LIB=open_ssl +include ../examples.mk diff --git a/examples/publish_subscribe/Makefile b/examples/publish_subscribe/Makefile index 98f2900ae9e9e5ac1b52bb3b48107d07c11317d0..3a4f9886b93423a824f4508b7a5294fed4b3b141 100644 --- a/examples/publish_subscribe/Makefile +++ b/examples/publish_subscribe/Makefile @@ -1,14 +1,3 @@ PROG = publish_subscribe -SOURCES = $(PROG).c ../../mongoose.c -CFLAGS = -W -Wall -I../.. -DMG_ENABLE_THREADS -pthread $(CFLAGS_EXTRA) - -all: $(PROG) - -$(PROG): $(SOURCES) - $(CC) $(SOURCES) -o $@ $(CFLAGS) - -$(PROG).exe: $(SOURCES) - cl $(SOURCES) /I../.. /MD /Fe$@ - -clean: - rm -rf *.gc* *.dSYM *.exe *.obj *.o a.out $(PROG) +MODULE_CFLAGS=-DMG_ENABLE_THREADS +include ../examples.mk diff --git a/examples/restful_client/Makefile b/examples/restful_client/Makefile index 9a05d79905aac0bd506b7bf72b02f501e1e06b51..a7ab34d090945424387f768b2f829491aad4eabe 100644 --- a/examples/restful_client/Makefile +++ b/examples/restful_client/Makefile @@ -1,14 +1,2 @@ PROG = restful_client -SOURCES = $(PROG).c ../../mongoose.c -CFLAGS = -W -Wall -I../.. -pthread $(CFLAGS_EXTRA) - -all: $(PROG) - -$(PROG): $(SOURCES) - $(CC) $(SOURCES) -o $@ $(CFLAGS) - -$(PROG).exe: $(SOURCES) - cl $(SOURCES) /I../.. /MD /Fe$@ - -clean: - rm -rf *.gc* *.dSYM *.exe *.obj *.o a.out $(PROG) +include ../examples.mk diff --git a/examples/restful_server/Makefile b/examples/restful_server/Makefile index 4e48d637a9f82b17c8d4c20ba21317569d56c1d3..3ab02afd8ad8e4134d2a2c9cfba13aeda4775903 100644 --- a/examples/restful_server/Makefile +++ b/examples/restful_server/Makefile @@ -1,25 +1,2 @@ PROG = restful_server -SOURCES = $(PROG).c ../../mongoose.c -CFLAGS = -W -Wall -I../.. $(CFLAGS_EXTRA) - -ifeq ($(SSL), openssl) - CFLAGS += -DMG_ENABLE_SSL -lssl -lcrypto -lcrypto -else ifeq ($(SSL), krypton) - CFLAGS += -DMG_ENABLE_SSL ../../../krypton/krypton.c -endif - -ifeq ($(JS), yes) - V7_PATH = ../../deps/v7 - CFLAGS_EXTRA += -DMG_ENABLE_JAVASCRIPT -I $(V7_PATH) $(V7_PATH)/v7.c -endif - -all: $(PROG) - -$(PROG): $(SOURCES) - $(CC) $(SOURCES) -o $@ $(CFLAGS) - -$(PROG).exe: $(SOURCES) - cl $(SOURCES) /I../.. /MD /DMG_ENABLE_THREADS /Fe$@ advapi32.lib - -clean: - rm -rf *.gc* *.dSYM *.exe *.obj *.o a.out $(PROG) +include ../examples.mk diff --git a/examples/restful_server_s3/Makefile b/examples/restful_server_s3/Makefile index 224555f49aa51d2e6bd3aa8cc6eab3134fa6dcd6..2e7e35289131cec232dc3d6e6f2741e60aa1081e 100644 --- a/examples/restful_server_s3/Makefile +++ b/examples/restful_server_s3/Makefile @@ -1,20 +1,4 @@ PROG = restful_server_s3 -SOURCES = $(PROG).c ../../mongoose.c -CFLAGS = -W -Wall -I../.. $(CFLAGS_EXTRA) +SSL_LIB=open_ssl +include ../examples.mk -ifeq ($(SSL), openssl) - CFLAGS += -DMG_ENABLE_SSL -lssl -lcrypto -lcrypto -else ifeq ($(SSL), krypton) - CFLAGS += -DMG_ENABLE_SSL ../../../krypton/krypton.c -endif - -all: $(PROG) - -$(PROG): $(SOURCES) - $(CC) $(SOURCES) -o $@ $(CFLAGS) - -$(PROG).exe: $(SOURCES) - cl $(SOURCES) /I../.. /MD /DMG_ENABLE_THREADS /Fe$@ advapi32.lib - -clean: - rm -rf *.gc* *.dSYM *.exe *.obj *.o a.out $(PROG) diff --git a/examples/rules.mk b/examples/rules.mk deleted file mode 100644 index 775c1d088e01e97c9a4b0a2e146326cbeeae7db4..0000000000000000000000000000000000000000 --- a/examples/rules.mk +++ /dev/null @@ -1,13 +0,0 @@ -SOURCES = $(PROG).c ../../mongoose.c -CFLAGS = -W -Wall -I../.. -pthread -DMG_ENABLE_SSL -DMG_ENABLE_IPV6 -DMG_ENABLE_THREADS -lssl -lcrypto $(CFLAGS_EXTRA) $(MODULE_CFLAGS) - -all: $(PROG) - -$(PROG): $(SOURCES) - $(CC) $(SOURCES) -g -o $@ $(CFLAGS) - -$(PROG).exe: $(SOURCES) - cl $(SOURCES) /I../.. /DMG_ENABLE_SSL /MD /Fe$@ - -clean: - rm -rf *.gc* *.dSYM *.exe *.obj *.o a.out $(PROG) diff --git a/examples/settings_panel_for_a_device/Makefile b/examples/settings_panel_for_a_device/Makefile index ff57b6f4520f264bf11e5ce1538459254ff38f4b..374049eebbea928532581a94a518bd5178e06991 100644 --- a/examples/settings_panel_for_a_device/Makefile +++ b/examples/settings_panel_for_a_device/Makefile @@ -1,11 +1,3 @@ PROG = settings_panel -SOURCES = $(PROG).c ../../mongoose.c -CFLAGS = -W -Wall -I../.. -DMG_ENABLE_SSL -lssl -lcrypto $(CFLAGS_EXTRA) - -all: $(PROG) - -$(PROG): $(SOURCES) - $(CC) $(SOURCES) -o $@ $(CFLAGS) - -clean: - rm -rf *.gc* *.dSYM *.exe *.obj *.o a.out $(PROG) +SSL_LIB=openssl +include ../examples.mk diff --git a/examples/simplest_web_server/Makefile b/examples/simplest_web_server/Makefile index f792e4c798f367a3485411d906daa86fcedbef18..d26ead16fa75dbc29158dc6e90396f425c89c6f1 100644 --- a/examples/simplest_web_server/Makefile +++ b/examples/simplest_web_server/Makefile @@ -1,15 +1,3 @@ PROG = simplest_web_server -SOURCES = $(PROG).c ../../mongoose.c -CFLAGS = -W -Wall -I../.. $(CFLAGS_EXTRA) -DMG_DISABLE_DAV_AUTH \ - -DMG_ENABLE_FAKE_DAVLOCK - -all: $(PROG) - -$(PROG): $(SOURCES) - $(CC) $(SOURCES) -o $@ $(CFLAGS) - -$(PROG).exe: $(SOURCES) - cl $(SOURCES) /I../.. /MD /Fe$@ - -clean: - rm -rf *.gc* *.dSYM *.exe *.obj *.o a.out $(PROG) +MODULE_CFLAGS=-DMG_DISABLE_DAV_AUTH -DMG_ENABLE_FAKE_DAVLOCK +include ../examples.mk diff --git a/examples/tcp_echo_server/Makefile b/examples/tcp_echo_server/Makefile index 22fee1b6dfcaa27bd317d9bc1cb8345f3ac6d2e1..87a88cdfc97a8adf81bf57dac32bcdadda0d0664 100644 --- a/examples/tcp_echo_server/Makefile +++ b/examples/tcp_echo_server/Makefile @@ -1,14 +1,2 @@ PROG = echo_server -SOURCES = $(PROG).c ../../mongoose.c -CFLAGS = -W -Wall -I../.. -pthread $(CFLAGS_EXTRA) - -all: $(PROG) - -$(PROG): $(SOURCES) - $(CC) $(SOURCES) -o $@ $(CFLAGS) - -$(PROG).exe: $(SOURCES) - cl $(SOURCES) /I../.. /MD /Fe$@ - -clean: - rm -rf *.gc* *.dSYM *.exe *.obj *.o a.out $(PROG) +include ../examples.mk diff --git a/examples/websocket_chat/Makefile b/examples/websocket_chat/Makefile index 780276ef46b09cd72e1e384e13df8920553fa807..ae1e7cc6be856e1668ea503bfed8b3b8b006bf7e 100644 --- a/examples/websocket_chat/Makefile +++ b/examples/websocket_chat/Makefile @@ -1,12 +1,2 @@ -# Copyright (c) 2014 Cesanta Software -# All rights reserved - PROG = websocket_chat -CFLAGS = -W -Wall -I../.. -pthread -g -O0 $(CFLAGS_EXTRA) -SOURCES = $(PROG).c ../../mongoose.c - -$(PROG): $(SOURCES) - $(CC) -o $(PROG) $(SOURCES) $(CFLAGS) - -clean: - rm -rf $(PROG) *.exe *.dSYM *.obj *.exp .*o *.lib +include ../examples.mk