SpriteHTTPD - embedded HTTP server with read-only filesystem and templating, originally developed for ESP8266, now stand-alone and POSIX compatible.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
spritehttpd/Makefile

187 lines
4.4 KiB

.PHONY: clean all lib demo fstool mbedtls
# -*- Settings -*-
DEBUG = 1
PLATFORM ?= POSIX # POSIX or ARM
# -*- Target names & dirs -*-
LIBBASENAME = spritehttpd
LIB_TARGET = ./lib$(LIBBASENAME).a
DEMO_TARGET = ./spritehttpd-demo
FSTOOL_TARGET = ./espfstool # Note: keep ./ here so it can be called when building demo
LIB_DIR = spritehttpd
DEMO_DIR = demo
FSTOOL_DIR = fstool
# -*- Shurtcut targets -*-
all: demo lib fstool
demo: $(DEMO_TARGET)
lib: $(LIB_TARGET)
fstool: $(FSTOOL_TARGET)
# -*- Tools -*-
HOST_CC = gcc
ifeq ($(PLATFORM),ARM)
CC = arm-none-eabi-gcc
AR = arm-none-eabi-ar
else
# Probably posix
CC = gcc
AR = ar
endif
# -*- CFLAGS -*-
# Common variables
GIT_HASH = $(shell git rev-parse --short HEAD)
# These flags are used by all targets
COMMON_CFLAGS = -Wall -Wextra -Werror \
-Wshadow -Wfloat-equal -Wundef -Wpointer-arith -Wcast-align -Wstrict-prototypes -Wwrite-strings -Wunreachable-code -Wconversion -Winit-self \
-Wnull-dereference -Winfinite-recursion \
-std=gnu99 -DGIT_HASH='"$(GIT_HASH)"' -ffunction-sections -fdata-sections
# The final binary linker should use -Wl,--gc-sections to take advantage of -ffunction-sections and -fdata-sections
LIB_CFLAGS = $(COMMON_CFLAGS) -c -fPIC
FSTOOL_CFLAGS = $(COMMON_CFLAGS) -DZLIB_CONST -lz
DEMO_CFLAGS = $(COMMON_CFLAGS)
ifeq ($(DEBUG), 1)
COMMON_CFLAGS += -DDEBUG -Og -ggdb
else
FSTOOL_CFLAGS += -O2
DEMO_CFLAGS += -O2
LIB_CFLAGS += -DNDEBUG -Os
endif
# -*- MbedTLS -*-
MBEDTLS_BASE_DIR=spritehttpd/lib/mbedtls-3.3.0/
MBEDTLS_INCLUDE_DIR=$(MBEDTLS_BASE_DIR)/include
MBEDTLS_LIB_DIR=$(MBEDTLS_BASE_DIR)/library
# spritehttpd/lib/mbedtls-3.3.0/library/libmbedcrypto.a
# spritehttpd/lib/mbedtls-3.3.0/library/libmbedtls.a
# spritehttpd/lib/mbedtls-3.3.0/library/libmbedx509.a
mbedtls:
# TODO specify GCC version etc ...
$(MAKE) -C $(MBEDTLS_BASE_DIR) lib -j `nproc` CC=$(CC) AR=$(AR)
# -*- Library -*-
LIB_SOURCES = \
lib/espfs/espfs.c \
lib/heatshrink/heatshrink_decoder.c \
src/utils/base64.c \
src/utils/sha1.c \
src/httpd.c \
src/httpd-auth.c \
src/httpd-utils.c \
src/httpd-loop.c \
src/httpd-heap.c \
src/cgi-espfs.c \
src/cgi-redirects.c \
src/cgi-websocket.c
LIB_INCLUDE_DIRS = \
src \
include \
lib/heatshrink \
lib/espfs
ifeq ($(PLATFORM),ARM)
LIB_SOURCES += src/port/httpd-freertos.c
else
LIB_SOURCES += src/port/httpd-posix.c
endif
LIB_SOURCES := $(addprefix $(LIB_DIR)/, $(LIB_SOURCES))
LIB_OBJS = $(LIB_SOURCES:.c=.o)
LIB_CFLAGS += $(addprefix -I$(LIB_DIR)/, $(LIB_INCLUDE_DIRS))
# This is only used for the library files. TODO restrict it somehow
%.o: %.c
$(CC) $(LIB_CFLAGS) -o $@ $<
$(LIB_TARGET): $(LIB_OBJS)
$(AR) rcs $@ $^
# -*- Demo -*-
# these won't have dir prefix added - they can refer to other dirs
DEMO_FS_C_FILE = $(DEMO_DIR)/staticfiles.fs.c
DEMO_SOURCES = \
$(DEMO_DIR)/server_demo.c \
$(DEMO_FS_C_FILE)
DEMO_INCLUDE_DIRS = \
$(DEMO_DIR) \
$(LIB_DIR)/include
DEMO_STATIC_FILES = \
index.html \
kocour.jpg \
template.tpl.txt
DEMO_OBJS = $(DEMO_SOURCES:.c=.o)
DEMO_STATIC_FILES := $(addprefix $(DEMO_DIR)/staticfiles/, $(DEMO_STATIC_FILES))
DEMO_CFLAGS += $(addprefix -I, $(DEMO_INCLUDE_DIRS))
$(DEMO_FS_C_FILE): $(FSTOOL_TARGET) $(DEMO_STATIC_FILES)
# Create the FS image & convert it to a C file for embedding in the binary.
# This can be split to two commands if you want to inspect the binary image (specify output and input file instead of -)
$(FSTOOL_TARGET) -P --gzip=jpg -o - --strip=$(DEMO_DIR)/staticfiles $(DEMO_STATIC_FILES) \
| $(FSTOOL_TARGET) -M -o $@ -i -
$(DEMO_TARGET): $(DEMO_SOURCES) $(LIB_TARGET) mbedtls
$(CC) $(DEMO_CFLAGS) $(DEMO_SOURCES) \
-o $@ -l$(LIBBASENAME) -L. -L$(MBEDTLS_LIB_DIR) -lmbedtls -lmbedx509 -lmbedcrypto
# -*- FS builder -*-
FSTOOL_SOURCES = \
$(FSTOOL_DIR)/main.c \
$(FSTOOL_DIR)/parsing.c \
$(LIB_DIR)/lib/heatshrink/heatshrink_encoder.c \
$(LIB_DIR)/lib/heatshrink/heatshrink_decoder.c \
$(LIB_DIR)/lib/espfs/espfs.c
FSTOOL_INCLUDE_DIRS = \
$(FSTOOL_DIR) \
$(LIB_DIR)/lib/heatshrink/ \
$(LIB_DIR)/lib/espfs/
FSTOOL_CFLAGS += $(addprefix -I, $(FSTOOL_INCLUDE_DIRS))
$(FSTOOL_TARGET): $(FSTOOL_SOURCES)
$(HOST_CC) $(FSTOOL_CFLAGS) $^ -o $@
# -*- Clean -*-
clean:
rm -f $(FSTOOL_TARGET) $(DEMO_TARGET) $(LIB_TARGET) $(DEMO_FS_C_FILE)
find . -type f \( \
-name '*.o' \
-o -name '*.d' \
-o -name '*.a' \
-o -name '*.elf' \
-o -name '*.bin' \
\) -delete