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

175 lines
3.8 KiB

.PHONY: clean all lib demo fstool
# -*- 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
# -*- 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/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_SOURCES = \
$(DEMO_DIR)/server_demo.c \
$(DEMO_DIR)/staticfiles.bin.c
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/staticfiles.bin.c: $(FSTOOL_TARGET) $(DEMO_STATIC_FILES)
# Create the FS image
$(FSTOOL_TARGET) \
--compress=1 \
--gzip-exts=jpg \
--output=demo/staticfiles.bin \
--c-output=demo/staticfiles.bin.c \
--strip-path=demo/staticfiles \
$(DEMO_STATIC_FILES)
# Show content of the image
$(FSTOOL_TARGET) -p demo/staticfiles.bin
$(DEMO_TARGET): $(DEMO_SOURCES) $(LIB_TARGET)
$(CC) $(DEMO_CFLAGS) $(DEMO_SOURCES) \
-o $@ -l$(LIBBASENAME) -L.
# -*- 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)
find . -type f \( \
-name '*.o' \
-o -name '*.embed.c' \
-o -name '*.d' \
-o -name '*.a' \
-o -name '*.elf' \
-o -name '*.bin' \
\) -delete