From dc86c62d8b0275b561e1384dfd3343ef270e204b Mon Sep 17 00:00:00 2001 From: cpq Date: Sat, 4 Feb 2023 01:42:41 +0000 Subject: [PATCH] Adopt Makefile for Windows. Update examples readme section --- docs/README.md | 32 ++++++++---------------------- examples/http-server/Makefile | 37 +++++++++++++++++++++-------------- 2 files changed, 30 insertions(+), 39 deletions(-) diff --git a/docs/README.md b/docs/README.md index ed176a60..d845824f 100644 --- a/docs/README.md +++ b/docs/README.md @@ -18,17 +18,9 @@ utilising Mongoose's built-in TCP/IP stack and network drivers. ## How to build and run examples The easiest way to start with Mongoose is to try to build and run examples. -The required tools are: a C/C++ compiler, the `make` utility, and `git`. - -You can follow these links for tutorials on how to install these tools on your platform of choice - -- [GCC](http://mongoose.ws/tutorials/tools/#gcc), the GNU C/C++ compiler collection - - On Windows, you might want to use "[Build Tools for Visual Studio](https://visualstudio.microsoft.com/downloads)" instead -- [GNU make](http://mongoose.ws/tutorials/tools/#gnu-make) -- [Git](http://mongoose.ws/tutorials/tools/#git) - -Now, when all required tools are installed, start a terminal/command prompt, -and download the Mongoose repository, go to the HTTP server example, build it, and run it: +Follow the [Development Environment](/tutorials/tools) tutorial to setup your +development environment: a C compiler, a `make` utility, and a `git` utility. +Start a terminal / command prompt and execute the following commands: ```sh git clone https://github.com/cesanta/mongoose @@ -36,20 +28,12 @@ cd mongoose/examples/http-server make ``` -That's it! Now start your browser, and point it to http://localhost:8000 +The above commands download Mongoose Library source code, then go into the +HTTP server example directory, and execute `make` command. It uses a +`Makefile` configuration file which is present in every example directory. +It builds an example executable and runs it. -> NOTE: if you want to build and run embedded examples too, such as -> STM32 or Raspberry Pi RP2040 examples, install an extra tool - the ARM GCC -> compiler: - -- [ARM GCC](http://mongoose.ws/tutorials/tools/#arm-gcc) - -> When done, you can build baremetal embedded examples: - -```sh -cd examples/stm32/nucleo-h743zi-baremetal -make build -``` +Now start your browser, and point it to http://localhost:8000 ## 2-minute integration guide diff --git a/examples/http-server/Makefile b/examples/http-server/Makefile index 6969218e..b5ea8c09 100644 --- a/examples/http-server/Makefile +++ b/examples/http-server/Makefile @@ -1,21 +1,28 @@ -PROG ?= example -ROOT ?= $(realpath $(CURDIR)/../..) -DEFS ?= -DMG_ENABLE_LINES=1 -DMG_ENABLE_IPV6=1 -DMG_ENABLE_SSI=1 -DMG_HTTP_DIRLIST_TIME=1 -CFLAGS ?= -I../.. -W -Wall $(DEFS) $(EXTRA) -VCFLAGS = /nologo /W3 /O2 /I../.. $(DEFS) $(EXTRA) /link /incremental:no /machine:IX86 -VC98 = docker run -it --rm -e Tmp=. -v $(ROOT):$(ROOT) -w $(CURDIR) mdashnet/vc98 +SOURCES = main.c ../../mongoose.c # Source code files +CFLAGS = -W -Wall -Wextra -g # Build options + +# Mongoose build options. See https://mongoose.ws/documentation/#build-options +CFLAGS += -I ../.. +CFLAGS += -DMG_HTTP_DIRLIST_TIME=1 -DMG_ENABLE_SSI=1 +CFLAGS += -DMG_ENABLE_LINES=1 -DMG_ENABLE_IPV6=1 + +ifeq ($(OS),Windows_NT) + # Windows settings. Assume MinGW compiler + PROG ?= example.exe # Use .exe suffix for the binary + CC = gcc # Use MinGW gcc compiler + CFLAGS += -lws2_32 # Link against Winsock library + DELETE = cmd /C del /Q /F /S # Command prompt command to delete files +else + # Mac, Linux + PROG ?= example + DELETE = rm -rf +endif all: $(PROG) $(RUN) ./$(PROG) $(ARGS) -$(PROG): main.c Makefile - $(CC) ../../mongoose.c main.c -I../.. $(CFLAGS) -o $@ - -mongoose.exe: main.c - $(VC98) wine cl ../../mongoose.c main.c $(VCFLAGS) ws2_32.lib /out:$@ - -mingw: - gcc ../../mongoose.c main.c -I../.. -W -Wall $(DEFS) -D_POSIX_C_SOURCE=200000L -lws2_32 -o mongoose.exe +$(PROG): $(SOURCES) + $(CC) $(SOURCES) $(CFLAGS) $(CFLAGS_EXTRA) -o $@ clean: - rm -rf $(PROG) *.o *.dSYM *.gcov *.gcno *.gcda *.obj *.exe *.ilk *.pdb mongoose mongoose_* mongoose.* + $(DELETE) $(PROG) *.o *.dSYM