Skip to content

Instantly share code, notes, and snippets.

@lpereira
Created June 19, 2019 14:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lpereira/74b20da890af2994c9b845131f0bfe4c to your computer and use it in GitHub Desktop.
Save lpereira/74b20da890af2994c9b845131f0bfe4c to your computer and use it in GitHub Desktop.
project lwan {
language = c
}
configure {
# If matched, creates a HAVE_SQLITE define in the config file,
# and enables a SQLITE feature that can be used for dependency
# testing, and, if linking against this library, adds automatically
# its CFLAGS and LDFLAGS.
pkg_config sqlite3 {
at_least_ver = 3.6.20
optional = yes
feature = SQLITE
}
# Both luajit and the other possible lua packages expose the same
# feature. If luajit matches first, then the pkg_config block
# below isn't tested.
pkg_config luajit {
at_least_ver = 2.0
at_most_ver = 2.0.999
optional = yes
feature = LUA
}
pkg_config lua lua51 lua5.1 lua-5.1 {
at_least_ver = 5.1.0
at_most_ver = 5.1.999
optional = yes
feature = LUA
}
# A library block tests if it can find for instance a
# "lib$LIBNAME.so" file somewhere. If it finds, a feature can
# be defined. If one feature is defined, the other block isn't
# tested.
bool_option alternative_malloc {
library tcmalloc_minimal tcmalloc {
feature = ALTMALLOC
}
library jemalloc {
feature = ALTMALLOC
}
}
library z {
include = zlib.h
feature = ZLIB
}
# If an include has been found, it defines the VALGRIND_H feature,
# and the HAVE_VALGRIND_H macro in the config file
has_include valgrind.h
# This defines the LINUX_CAPABILITY_H feature
has_include linux/capability.h
has_include sys/epoll.h
has_include alloca.h
has_function kqueue {
# This defines the KQUEUE feature, and HAVE_KQUEUE config
include = sys/time.h sys/types.h sys/event.h
}
has_function getauxval { include = sys/auxv.h }
has_function rawmemchr {
include = string.h
gnu_source = yes
}
has_function get_current_dir_name {
include = unistd.h
gnu_source = yes
}
has_function reallocarray {
include = stdlib.h
default_source = yes
gnu_source = yes
}
has_function pipe2 {
include = unistd.h
gnu_source = yes
}
has_function accept4 {
include = sys/types.h sys/socket.h
gnu_source = yes
}
has_function readahead {
include = fcntl.h
gnu_souce = yes
}
has_function mkostemp {
include = stdlib.h
gnu_source = yes
default_source = yes
}
compiles BUILTIN_CPU_INIT { code = """__builtin_cpu_init();""" }
compiles BUILTON_CLZLL { code = """__builtin_clzll(0);""" }
compiles BUILTIN_FPCLASSIFY { code = """__builtin_fpclassify(0, 0, 0, 0, 0, 0.0f); """ }
compiles BUILTIN_CRC32 {
code = """__builtin_ia32_crc32hi(0, 0);"""
# This checks if the above code builds, and appens -mcrc32
# to the flags. If it builds, CFLAGS gets amended with that
# too.
add_to CFLAGS { -mcrc32 }
}
compiles STATIC_ASSERT { code = """_Static_assert(1, "");""" }
# This tests each and every flag, and if any of them are available,
# add to RELEASE_CFLAGS
cc_add_flags_if RELEASE_CFLAGS {
-mtune=native
-march=native
-malign-data=abi
-fno-asynchronous-unwind-tables
-ffat-lto-objects
}
# Same for EXEC_LDFLAGS
cc_add_flags_if EXEC_LDFLAGS {
-Wl,-bind_at_load
-Wl,-z,now
-Wl,-z,relro
-Wl,-z,noexecstack
}
cc_add_flags_if CFLAGS {
-fstack-protector-explicit
-fno-plt
-Wduplicated-cond
-Wduplicated-branches
-Wlogical-op
-Wdouble-promotion
-Wno-unused-parameter
-Wstringop-truncation
-Wvla
-Wall
-Wextra
-Wshadow
-Wconversion
}
add_to CFLAGS { -std=gnu99 }
add_to CFLAGS { -D_FILE_OFFSET_BITS=64 }
link_options { static_whole_archive = yes }
}
generator mimegen {
sources {
src/lib/hash.c
src/lib/murmur3.c
src/lib/missing.c
src/bin/tools/mimegen.c
}
depends ZOPFLI { feature = MIMEGEN_COMPRESS_LIB }
depends ZLIB { feature = MIMEGEN_COMPRESS_LIB }
}
generator bin2hex {
sources {
src/lib/tools/bin2hex.c
}
}
generate mime-types.h {
depends MIMEGEN
depends_files { src/bin/tools/mime.types }
# This uses the environment variable expansion in the configuration
# parser.
command_line = """
${BIN_DIR}/mimegen ${ROOT_DIR}/src/bin/tools/mime.types
"""
capture_stdout_to = mime-types.h
}
generate auto-index-icons.h {
depends BIN2HEX
depends_files {
wwwroot/icons/back.gif
wwwroot/icons/file.gif
wwwroot/icons/folder.gif
}
command_line = """
${BIN_DIR}/bin2hex
${ROOT_DIR}/wwwroot/icons/back.gif back_gif
${ROOT_DIR}/wwwroot/icons/file.gif file_gif
${ROOT_DIR}/wwwroot/icons/folder.gif folder_gif
"""
capture_stdout_to = auto-index-icons.h
}
library lwan {
sources src/lib/*.c {
depends LUA {
glob = src/lib/lwan*-lua.c
}
}
depends = MIME_TYPES_H
depends = AUTO_INDEX_ICONS_H
shared {
symbol_filter = src/lib/liblwan.sym
link_with LUA { optional = yes }
link_with ZLIB
}
static
}
binary lwan {
link_with LWAN_STATIC
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment