Adopt Makefile for Windows. Update examples readme section

This commit is contained in:
cpq 2023-02-04 01:42:41 +00:00
parent 43e48d2ba6
commit dc86c62d8b
2 changed files with 30 additions and 39 deletions

View File

@ -18,17 +18,9 @@ utilising Mongoose's built-in TCP/IP stack and network drivers.
## How to build and run examples ## How to build and run examples
The easiest way to start with Mongoose is to try 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`. Follow the [Development Environment](/tutorials/tools) tutorial to setup your
development environment: a C compiler, a `make` utility, and a `git` utility.
You can follow these links for tutorials on how to install these tools on your platform of choice Start a terminal / command prompt and execute the following commands:
- [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:
```sh ```sh
git clone https://github.com/cesanta/mongoose git clone https://github.com/cesanta/mongoose
@ -36,20 +28,12 @@ cd mongoose/examples/http-server
make 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 Now start your browser, and point it to http://localhost:8000
> 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
```
## 2-minute integration guide ## 2-minute integration guide

View File

@ -1,21 +1,28 @@
PROG ?= example SOURCES = main.c ../../mongoose.c # Source code files
ROOT ?= $(realpath $(CURDIR)/../..) CFLAGS = -W -Wall -Wextra -g # Build options
DEFS ?= -DMG_ENABLE_LINES=1 -DMG_ENABLE_IPV6=1 -DMG_ENABLE_SSI=1 -DMG_HTTP_DIRLIST_TIME=1
CFLAGS ?= -I../.. -W -Wall $(DEFS) $(EXTRA) # Mongoose build options. See https://mongoose.ws/documentation/#build-options
VCFLAGS = /nologo /W3 /O2 /I../.. $(DEFS) $(EXTRA) /link /incremental:no /machine:IX86 CFLAGS += -I ../..
VC98 = docker run -it --rm -e Tmp=. -v $(ROOT):$(ROOT) -w $(CURDIR) mdashnet/vc98 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) all: $(PROG)
$(RUN) ./$(PROG) $(ARGS) $(RUN) ./$(PROG) $(ARGS)
$(PROG): main.c Makefile $(PROG): $(SOURCES)
$(CC) ../../mongoose.c main.c -I../.. $(CFLAGS) -o $@ $(CC) $(SOURCES) $(CFLAGS) $(CFLAGS_EXTRA) -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
clean: clean:
rm -rf $(PROG) *.o *.dSYM *.gcov *.gcno *.gcda *.obj *.exe *.ilk *.pdb mongoose mongoose_* mongoose.* $(DELETE) $(PROG) *.o *.dSYM