diff --git a/Makefile.am b/Makefile.am new file mode 100644 index 0000000..2f41259 --- /dev/null +++ b/Makefile.am @@ -0,0 +1,4 @@ +SUBDIRS=src + +ACLOCAL_AMFLAGS=-I m4 +EXTRA_DIST=autogen.sh CMakeLists.txt diff --git a/autogen.sh b/autogen.sh new file mode 100755 index 0000000..ae2d948 --- /dev/null +++ b/autogen.sh @@ -0,0 +1,27 @@ +#!/bin/sh +# Run this to generate all the initial makefiles, etc. + +LIBTOOLIZE=${LIBTOOLIZE:-libtoolize} +LIBTOOLIZE_FLAGS="--copy --force" +ACLOCAL=${ACLOCAL:-aclocal} +AUTOHEADER=${AUTOHEADER:-autoheader} +AUTOMAKE=${AUTOMAKE:-automake} +AUTOMAKE_FLAGS="--add-missing --copy" +AUTOCONF=${AUTOCONF:-autoconf} + +ARGV0=$0 + +set -e + + +run() { + echo "$ARGV0: running \`$@'" + $@ +} + +run $LIBTOOLIZE $LIBTOOLIZE_FLAGS +run $ACLOCAL $ACLOCAL_FLAGS +run $AUTOHEADER +run $AUTOMAKE $AUTOMAKE_FLAGS +run $AUTOCONF +echo "Now type './configure ...' and 'make' to compile." diff --git a/configure.ac b/configure.ac new file mode 100644 index 0000000..bd281d1 --- /dev/null +++ b/configure.ac @@ -0,0 +1,167 @@ +# -*- Autoconf -*- +# Process this file with autoconf to produce a configure script. + +AC_PREREQ(2.61) +AC_INIT([lighttpd], [2.0.0~alpha], [contact@lighttpd.net]) +AC_CONFIG_SRCDIR([src/main/lighttpd.c]) +AC_CONFIG_HEADER([include/lighttpd/config.h]) +AC_CONFIG_MACRO_DIR([m4]) + +AM_INIT_AUTOMAKE([-Wall -Werror foreign]) + +dnl check environment +AC_USE_SYSTEM_EXTENSIONS + +# Checks for programs. +AC_PROG_CC +AC_PROG_MAKE_SET +AC_PROG_INSTALL +# AC_PROG_RANLIB + +dnl libtool +AC_DISABLE_STATIC +AC_ENABLE_SHARED + +AC_PROG_LIBTOOL + +# Checks for header files. +AC_HEADER_STDC +AC_HEADER_SYS_WAIT +AC_CHECK_HEADERS([ \ + stddef.h \ + sys/mman.h \ + sys/sendfile.h \ + sys/types.h \ + sys/uio.h \ + sys/un.h \ +]) + +# Checks for libraries. + +# glib/gthread (gthread includes glib) +PKG_CHECK_MODULES(GTHREAD, gthread-2.0 >= 2.16.0, [],[AC_MSG_ERROR("gthread-2.0 >= 2.16.0 not found")]) +# gmodule +PKG_CHECK_MODULES(GMODULE, gmodule-2.0 >= 2.16.0, [],[AC_MSG_ERROR("gmodule-2.0 >= 2.16.0 not found")]) + +AC_MSG_CHECKING(for libev support) +AC_ARG_WITH(libev, + AC_HELP_STRING([--with-libev@<:@=PATH@:>@],[Search for libev in PATH/include and PATH/lib]), + [WITH_LIBEV=$withval],[WITH_LIBEV=/usr]) + +AC_CHECK_HEADERS([ev.h],[ + AC_CHECK_LIB([ev], [ev_loop], [ + AC_SUBST(LIBEV_CFLAGS, []) + AC_SUBST(LIBEV_LIBS, [-lev]) + ])],[ + AC_MSG_ERROR([libev not found]) + ] +) + +dnl Check for lua +AC_MSG_CHECKING(for lua) +AC_ARG_WITH(lua, AC_HELP_STRING([--with-lua],[lua engine for mod_magnet]), +[WITH_LUA=$withval],[WITH_LUA=no]) + +AC_MSG_RESULT($WITH_LUA) +if test "$WITH_LUA" != "no"; then + # try pkgconfig + if test "$WITH_LUA" = "yes"; then + LUAPC=lua + else + LUAPC=$WITH_LUA + fi + + PKG_CHECK_MODULES(LUA, $LUAPC >= 5.1, [ + AC_DEFINE([HAVE_LUA], [1], [liblua]) + AC_DEFINE([HAVE_LUA_H], [1], [lua.h]) + ],[ + # for debian based systems + PKG_CHECK_MODULES(LUA, lua5.1 >= 5.1, [ + AC_DEFINE([HAVE_LUA], [1], [liblua]) + AC_DEFINE([HAVE_LUA_H], [1], [lua.h]) + ],[ + # for freebsd + PKG_CHECK_MODULES(LUA, lua-5.1 >= 5.1, [ + AC_DEFINE([HAVE_LUA], [1], [liblua]) + AC_DEFINE([HAVE_LUA_H], [1], [lua.h]) + ],[ + AC_MSG_ERROR([lua not found]) + ]) + ]) + ]) + + AC_SUBST(LUA_CFLAGS) + AC_SUBST(LUA_LIBS) + USE_LUA=true +fi + +AM_CONDITIONAL(USE_LUA, test "$USE_LUA" = "true") + +# Checks for typedefs, structures, and compiler characteristics. +AC_C_CONST +AC_TYPE_UID_T +AC_TYPE_PID_T +AC_TYPE_SIZE_T +AC_HEADER_TIME + +## solaris needs -lsocket -lnsl +AC_SEARCH_LIBS([socket],[socket]) +AC_SEARCH_LIBS([inet_addr],[nsl socket]) + +# Checks for library functions. +AC_CHECK_FUNCS([ \ + chroot \ + gmtime_r \ + inet_aton \ + inet_ntop \ + localtime_r \ + madvise \ + mmap \ + posix_fadvise \ + sendfile \ + sendfile64 \ + sendfilev \ + writev \ +]) + +dnl Check for IPv6 support + +AC_ARG_ENABLE(ipv6, + AC_HELP_STRING([--disable-ipv6],[disable IPv6 support]), + [case "${enableval}" in + yes) ipv6=true ;; + no) ipv6=false ;; + *) AC_MSG_ERROR(bad value ${enableval} for --enable-ipv6) ;; + esac],[ipv6=true]) + +if test x$ipv6 = xtrue; then + AC_CACHE_CHECK([for IPv6 support], ac_cv_ipv6_support, + [AC_TRY_LINK([ #include +#include +#include ], [struct sockaddr_in6 s; struct in6_addr t=in6addr_any; int i=AF_INET6; s; t.s6_addr[0] = 0; ], + [ac_cv_ipv6_support=yes], [ac_cv_ipv6_support=no])]) + + if test "$ac_cv_ipv6_support" = yes; then + AC_DEFINE(HAVE_IPV6,1,[Whether to enable IPv6 support]) + fi +fi + +# check for extra compiler options (warning options) +if test "${GCC}" = "yes"; then + CFLAGS="${CFLAGS} -Wall -W -Wshadow -pedantic -std=gnu99" +fi + +AC_ARG_ENABLE(extra-warnings, + AC_HELP_STRING([--enable-extra-warnings],[enable extra warnings (gcc specific)]), + [case "${enableval}" in + yes) extrawarnings=true ;; + no) extrawarnings=false ;; + *) AC_MSG_ERROR(bad value ${enableval} for --enable-extra-warnings) ;; + esac],[extrawarnings=false]) + +if test x$extrawarnings = xtrue; then + CFLAGS="${CFLAGS} -g -O2 -g2 -Wall -Wmissing-declarations -Wdeclaration-after-statement -Wno-pointer-sign -Wcast-align -Winline -Wsign-compare -Wnested-externs -Wpointer-arith -Wl,--as-needed -Wformat-security" +fi + +AC_CONFIG_FILES([Makefile src/Makefile src/common/Makefile src/main/Makefile src/angel/Makefile src/modules/Makefile]) +AC_OUTPUT diff --git a/include/lighttpd/settings.h b/include/lighttpd/settings.h index 4d6000a..80d6a4b 100644 --- a/include/lighttpd/settings.h +++ b/include/lighttpd/settings.h @@ -34,7 +34,7 @@ #ifdef HAVE_CONFIG_H -#include +# include #endif #if defined HAVE_LIBSSL && defined HAVE_OPENSSL_SSL_H diff --git a/src/Makefile.am b/src/Makefile.am new file mode 100644 index 0000000..630edf8 --- /dev/null +++ b/src/Makefile.am @@ -0,0 +1,2 @@ + +SUBDIRS=common main modules angel diff --git a/src/angel/Makefile.am b/src/angel/Makefile.am new file mode 100644 index 0000000..dc4de0a --- /dev/null +++ b/src/angel/Makefile.am @@ -0,0 +1,23 @@ + +bin_PROGRAMS=lighttpd-angel +common_cflags=-I$(top_srcdir)/include -I$(top_builddir)/include + +lighttpd_angel_shared_src= \ + angel_config_parser.c \ + angel_log.c \ + angel_plugin.c \ + angel_plugin_core.c \ + angel_proc.c \ + angel_server.c \ + angel_value.c + +BUILT_SOURCES=angel_config_parser.c + +angel_config_parser.c: angel_config_parser.rl + ragel -C -T1 -o $@ $< + +lighttpd_angel_SOURCES=angel_main.c $(lighttpd_angel_shared_src) + +lighttpd_angel_CPPFLAGS=$(common_cflags) $(GTHREAD_CFLAGS) $(GMODULE_CFLAGS) $(LIBEV_CFLAGS) $(LUA_CFLAGS) -DDEFAULT_LIBDIR='"$(pkglibdir)"' +lighttpd_angel_LDFLAGS=-export-dynamic $(GTHREAD_LIBS) $(GMODULE_LIBS) $(LIBEV_LIBS) $(LUA_LIBS) +lighttpd_angel_LDADD=../common/libcommon.a diff --git a/src/common/Makefile.am b/src/common/Makefile.am new file mode 100644 index 0000000..531e88b --- /dev/null +++ b/src/common/Makefile.am @@ -0,0 +1,24 @@ + +noinst_LIBRARIES=libcommon.a +common_cflags=-I$(top_srcdir)/include -I$(top_builddir)/include + +common_src= \ + angel_connection.c \ + angel_data.c \ + encoding.c \ + idlist.c \ + ip_parsers.c \ + module.c \ + radix.c \ + sys-files.c \ + sys-socket.c \ + utils.c \ + waitqueue.c + +BUILT_SOURCES=ip_parsers.c + +ip_parsers.c: ip_parsers.rl + ragel -C -T1 -o $@ $< + +libcommon_a_SOURCES=$(common_src) +libcommon_a_CPPFLAGS=$(common_cflags) $(GTHREAD_CFLAGS) $(GMODULE_CFLAGS) $(LIBEV_CFLAGS) $(LUA_CFLAGS) diff --git a/src/main/Makefile.am b/src/main/Makefile.am new file mode 100644 index 0000000..f3cdd23 --- /dev/null +++ b/src/main/Makefile.am @@ -0,0 +1,64 @@ + +bin_PROGRAMS=lighttpd +common_cflags=-I$(top_srcdir)/include -I$(top_builddir)/include + +lighttpd_shared_src= \ + angel.c \ + angel_fake.c \ + actions.c \ + chunk.c \ + chunk_parser.c \ + collect.c \ + condition.c \ + config_parser.c \ + connection.c \ + environment.c \ + etag.c \ + filter_chunked.c \ + http_headers.c \ + http_request_parser.c \ + http_response_parser.c \ + lighttpd-glue.c \ + log.c \ + network.c \ + network_write.c network_writev.c \ + network_sendfile.c \ + options.c \ + plugin.c \ + profiler.c \ + request.c \ + response.c \ + server.c \ + stat_cache.c \ + throttle.c \ + url_parser.c \ + value.c \ + virtualrequest.c \ + worker.c \ + \ + plugin_core.c + +if USE_LUA +lighttpd_shared_src+= \ + actions_lua.c \ + condition_lua.c \ + config_lua.c \ + value_lua.c +endif + +BUILT_SOURCES=config_parser.c http_request_parser.c http_response_parser.c url_parser.c + +config_parser.c: config_parser.rl + ragel -C -T0 -o $@ $< +http_request_parser.c: http_request_parser.rl + ragel -C -T1 -o $@ $< +http_response_parser.c: http_response_parser.rl + ragel -C -T1 -o $@ $< +url_parser.c: url_parser.rl + ragel -C -T1 -o $@ $< + +lighttpd_SOURCES=lighttpd.c $(lighttpd_shared_src) + +lighttpd_CPPFLAGS=$(common_cflags) $(GTHREAD_CFLAGS) $(GMODULE_CFLAGS) $(LIBEV_CFLAGS) $(LUA_CFLAGS) -DDEFAULT_LIBDIR='"$(pkglibdir)"' +lighttpd_LDFLAGS=-export-dynamic $(GTHREAD_LIBS) $(GMODULE_LIBS) $(LIBEV_LIBS) $(LUA_LIBS) +lighttpd_LDADD=../common/libcommon.a diff --git a/src/main/lighttpd.c b/src/main/lighttpd.c index f6d1893..9c11ebc 100644 --- a/src/main/lighttpd.c +++ b/src/main/lighttpd.c @@ -4,7 +4,11 @@ #include #ifdef HAVE_LUA_H -#include +# include +#endif + +#ifndef DEFAULT_LIBDIR +# define DEFAULT_LIBDIR "/usr/local/lib/lighttpd" #endif void plugin_core_init(liServer *srv, liPlugin *p); @@ -17,7 +21,7 @@ int main(int argc, char *argv[]) { gboolean free_config_path = TRUE; gchar *config_path = NULL; - const gchar *def_module_dir = "/usr/local/lib"; /* TODO: configure module-dir with make-system */ + const gchar *def_module_dir = DEFAULT_LIBDIR; const gchar *module_dir = def_module_dir; gboolean luaconfig = FALSE; gboolean test_config = FALSE; @@ -30,7 +34,7 @@ int main(int argc, char *argv[]) { { "config", 'c', 0, G_OPTION_ARG_FILENAME, &config_path, "filename/path of the config", "PATH" }, { "lua", 'l', 0, G_OPTION_ARG_NONE, &luaconfig, "use the lua config frontend", NULL }, { "test", 't', 0, G_OPTION_ARG_NONE, &test_config, "test config and exit", NULL }, - { "module-dir", 'm', 0, G_OPTION_ARG_STRING, &module_dir, "module directory", "PATH" }, + { "module-dir", 'm', 0, G_OPTION_ARG_STRING, &module_dir, "module directory [default: " DEFAULT_LIBDIR "]", "PATH" }, { "version", 'v', 0, G_OPTION_ARG_NONE, &show_version, "show version and exit", NULL }, { "angel", 0, G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_NONE, &use_angel, "spawned by angel", NULL }, { NULL, 0, 0, 0, NULL, NULL, NULL } @@ -64,9 +68,9 @@ int main(int argc, char *argv[]) { if (show_version) { g_print("%s-%s - a fast and lightweight webserver\n", PACKAGE_NAME, PACKAGE_VERSION); g_print("Build date: %s\n", PACKAGE_BUILD_DATE); - #ifdef LIGHTTPD_REVISION +#ifdef LIGHTTPD_REVISION g_print("Revision: %s\n", LIGHTTPD_REVISION); - #endif +#endif return 0; } diff --git a/src/main/worker.c b/src/main/worker.c index 74a21dd..c10db18 100644 --- a/src/main/worker.c +++ b/src/main/worker.c @@ -1,8 +1,8 @@ -#include - #include +#include + static liConnection* worker_con_get(liWorker *wrk); void worker_con_put(liConnection *con); @@ -438,7 +438,7 @@ void li_worker_free(liWorker *wrk) { } void li_worker_run(liWorker *wrk) { - #ifdef LIGHTY_OS_LINUX +#ifdef LIGHTY_OS_LINUX /* sched_setaffinity is only available on linux */ cpu_set_t mask; @@ -457,7 +457,7 @@ void li_worker_run(liWorker *wrk) { ERROR(wrk->srv, "%s", "cpu 0 not enabled, no affinity set"); } } - #endif +#endif ev_loop(wrk->loop, 0); } diff --git a/src/modules/Makefile.am b/src/modules/Makefile.am new file mode 100644 index 0000000..842a218 --- /dev/null +++ b/src/modules/Makefile.am @@ -0,0 +1,66 @@ +install_libs = + +common_cflags = -I$(top_srcdir)/include -I$(top_builddir)/include +common_cflags += $(GTHREAD_CFLAGS) $(GMODULE_CFLAGS) $(LIBEV_CFLAGS) $(LUA_CFLAGS) +common_libadd = $(GTHREAD_LIBS) $(GMODULE_LIBS) $(LIBEV_LIBS) $(LUA_LIBS) +common_ldflags = -module -export-dynamic -avoid-version -no-undefined $(common_libadd) + +AM_CPPFLAGS = $(common_cflags) + +install_libs += mod_access.la +mod_access_la_SOURCES = mod_access.c +mod_access_la_LDFLAGS = -module -export-dynamic -avoid-version -no-undefined + +install_libs += mod_accesslog.la +mod_accesslog_la_SOURCES = mod_accesslog.c +mod_accesslog_la_LDFLAGS = -module -export-dynamic -avoid-version -no-undefined + +install_libs += mod_balancer.la +mod_balancer_la_SOURCES = mod_balancer.c +mod_balancer_la_LDFLAGS = -module -export-dynamic -avoid-version -no-undefined + +install_libs += mod_cache_disk_etag.la +mod_cache_disk_etag_la_SOURCES = mod_cache_disk_etag.c +mod_cache_disk_etag_la_LDFLAGS = -module -export-dynamic -avoid-version -no-undefined + +install_libs += mod_debug.la +mod_debug_la_SOURCES = mod_debug.c +mod_debug_la_LDFLAGS = -module -export-dynamic -avoid-version -no-undefined + +install_libs += mod_dirlist.la +mod_dirlist_la_SOURCES = mod_dirlist.c +mod_dirlist_la_LDFLAGS = -module -export-dynamic -avoid-version -no-undefined + +install_libs += mod_expire.la +mod_expire_la_SOURCES = mod_expire.c +mod_expire_la_LDFLAGS = -module -export-dynamic -avoid-version -no-undefined + +install_libs += mod_fastcgi.la +mod_fastcgi_la_SOURCES = mod_fastcgi.c +mod_fastcgi_la_LDFLAGS = -module -export-dynamic -avoid-version -no-undefined + +install_libs += mod_fortune.la +mod_fortune_la_SOURCES = mod_fortune.c +mod_fortune_la_LDFLAGS = -module -export-dynamic -avoid-version -no-undefined + +install_libs += mod_redirect.la +mod_redirect_la_SOURCES = mod_redirect.c +mod_redirect_la_LDFLAGS = -module -export-dynamic -avoid-version -no-undefined + +install_libs += mod_rewrite.la +mod_rewrite_la_SOURCES = mod_rewrite.c +mod_rewrite_la_LDFLAGS = -module -export-dynamic -avoid-version -no-undefined + +install_libs += mod_rrd.la +mod_rrd_la_SOURCES = mod_rrd.c +mod_rrd_la_LDFLAGS = -module -export-dynamic -avoid-version -no-undefined + +install_libs += mod_status.la +mod_status_la_SOURCES = mod_status.c +mod_status_la_LDFLAGS = -module -export-dynamic -avoid-version -no-undefined + +install_libs += mod_vhost.la +mod_vhost_la_SOURCES = mod_vhost.c +mod_vhost_la_LDFLAGS = -module -export-dynamic -avoid-version -no-undefined + +pkglib_LTLIBRARIES=$(install_libs)