1
0
mirror of https://github.com/lxsang/antd-cgi-plugin synced 2024-12-26 01:58:22 +01:00

use autotool

This commit is contained in:
lxsang 2019-11-13 16:59:44 +01:00
parent d03bcfb418
commit ee5f7588bf
6 changed files with 156 additions and 44 deletions

20
.gitignore vendored
View File

@ -3,6 +3,7 @@ plugins
build build
*._* *._*
*.d *.d
*.deb
.vscode .vscode
# Object files # Object files
*.o *.o
@ -50,6 +51,23 @@ build
*.cmd *.cmd
modules.order modules.order
Module.symvers Module.symvers
Mkfile.old Makefile.old
dkms.con dkms.con
.DS_Store .DS_Store
.*
*.cache
Makefile
antd
compile
config.guess
depcomp
install-sh
missing
libtool
config.log
config.status
config.sub
configure
aclocal.m4
ltmain.sh
Makefile.in

View File

@ -1,37 +0,0 @@
include ../../var.mk
PL_NAME=cgi
PLUGINS=$(PL_NAME).$(EXT)
APP_DIR=$(BUILDIRD)/htdocs/
OBJS = $(PLUGINS_BASE)/plugin.o
PLUGINSDEP = $(OBJS) \
cgi.o
PLUGINLIBS = libantd.$(EXT)
PCFLAGS=-W -Wall -g -D DEBUG $(PPF_FLAG)
main: $(PLUGINSDEP) $(PLUGINS) #lib
%.o: %.c
$(CC) $(PCFLAGS) -fPIC $(INCFLAG) -c $< -o $@
%.$(EXT):
-ln -s $(PBUILDIRD)/libantd.$(EXT) .
$(CC) $(PCFLAGS) $(PLUGINSDEP) $(PLUGINLIBS) -shared -o $(PBUILDIRD)/$(basename $@).$(EXT)
clean: #libclean
-rm -f *.o *.$(EXT) $(PBUILDIRD)/$(PLUGINS)
-rm $(PLUGINS_BASE)/plugin.o
.PRECIOUS: %.o
.PHONY: lib clean
full: clean main

19
Makefile.am Normal file
View File

@ -0,0 +1,19 @@
AUTOMAKE_OPTIONS = foreign
# check for system
if LINUX
AM_CPPFLAGS = -Wl,--no-as-needed
else
AM_CPPFLAGS = -Wl,-undefined,dynamic_lookup
endif
AM_CPPFLAGS += -W -Wall -g -std=c99 -fPIC
lib_LTLIBRARIES = cgi.la
cgi_la_LDFLAGS = -module -avoid-version -shared
cgi_la_SOURCES = cgi.c
EXTRA_DIST = README.md

View File

@ -19,7 +19,7 @@ When all dependencies are installed, the build can be done with a few single com
```bash ```bash
mkdir antd mkdir antd
cd antd cd antd
wget -O- https://get.bitdojo.dev/antd | bash -s "cgi" wget -O- https://get.bitdojo.dev/antd_plugin | bash -s "cgi"
``` ```
The script will ask you for a place to put the binaries (should be an absolute path, otherwise the build will fail) and the default HTTP port for the server config. The script will ask you for a place to put the binaries (should be an absolute path, otherwise the build will fail) and the default HTTP port for the server config.
@ -60,3 +60,12 @@ To run Antd server with the **cgi** plugin:
``` ```
**php** Web applications can be put on **/path/to/your/build/htdocs** **php** Web applications can be put on **/path/to/your/build/htdocs**
### Generte distribution
```sh
libtoolize
aclocal
autoconf
automake --add-missing
make distcheck
```

17
cgi.c
View File

@ -1,6 +1,6 @@
#include <sys/wait.h> #include <sys/wait.h>
#include "plugin.h" #include "antd/plugin.h"
#include "ini.h" #include "antd/ini.h"
dictionary cgi_bin = NULL; dictionary cgi_bin = NULL;
static int ini_handle(void *user_data, const char *section, const char *name, static int ini_handle(void *user_data, const char *section, const char *name,
@ -30,6 +30,10 @@ void init()
{ {
LOG("Can't load '%s'\n", file); LOG("Can't load '%s'\n", file);
} }
else
{
LOG("CGI config loaded\n");
}
free(cnf); free(cnf);
free(file); free(file);
} }
@ -184,18 +188,19 @@ void *handle(void *data)
char buf[BUFFLEN]; char buf[BUFFLEN];
int status; int status;
antd_task_t *task = NULL; antd_task_t *task = NULL;
task = antd_create_task(NULL, data, NULL,rq->client->last_io);
task->priority++;
list env_vars = NULL; list env_vars = NULL;
char *bin = get_cgi_bin(rq); char *bin = get_cgi_bin(rq);
if (!bin) if (!bin)
{ {
LOG("No cgi bin found\n"); LOG("No cgi bin found\n");
unknow(cl); unknow(cl);
task = antd_create_task(NULL, data, NULL,rq->client->last_io);
task->priority++;
return task; return task;
} }
env_vars = get_env_vars(rq); env_vars = get_env_vars(rq);
// now exec the cgi bin // now exec the cgi bin
LOG("Execute the cgi bin\n");
item np = env_vars; item np = env_vars;
int size = list_size(env_vars); int size = list_size(env_vars);
char **envs = (char **)malloc((size + 1) * sizeof(*envs)); char **envs = (char **)malloc((size + 1) * sizeof(*envs));
@ -277,5 +282,7 @@ void *handle(void *data)
waitpid(pid, &status, 0); waitpid(pid, &status, 0);
free(envs); free(envs);
list_free(&env_vars); list_free(&env_vars);
task = antd_create_task(NULL, data, NULL,rq->client->last_io);
task->priority++;
return task; return task;
} }

96
configure.ac Normal file
View File

@ -0,0 +1,96 @@
# initialise autoconf and set up some basic information about the program were packaging
AC_INIT([cgi], [1.0.0b], [xsang.le@gmail.com])
# Were going to use automake for this project
# [subdir-objects] if needed
AM_INIT_AUTOMAKE()
# dependencies
# C compiler
AC_PROG_CC
# libtool for linking
AC_PROG_LIBTOOL
# check if sqlite3 header exists
use_db=no
has_antd=no
AC_CHECK_HEADER([sqlite3.h],[
AC_DEFINE([USE_DB], [1],[Use sqlite3])
use_db=yes
# check if the library exists
],[])
AC_CHECK_LIB([sqlite3],[sqlite3_open],[],[
if test "$use_db" = "yes"; then
AC_MSG_ERROR([Unable to find sqlite3 shared library])
fi
])
# check for lib antd
AC_CHECK_HEADER([antd/plugin.h],[
has_antd=yes
# check if the library exists
],[
AC_MSG_ERROR([Unable to find antd, please install it first])
])
AC_CHECK_LIB([antd],[antd_send],[],[
if test "$has_antd" = "yes"; then
AC_MSG_ERROR([Unable to find antd shared library, please install it first])
fi
])
# check for pthread
AC_CHECK_LIB([pthread], [pthread_create], [], [
AC_MSG_ERROR([libpthread is not found])])
# check for dl
AC_CHECK_LIB([dl], [dlopen], [], [
AC_MSG_ERROR([unable to find dlopen()])
])
AC_DEFINE([_GNU_SOURCE], [1],[Use GNU source])
# AC_CANONICAL_HOST is needed to access the 'host_os' variable
# debug option
AC_ARG_ENABLE([debug],
[ --enable-debug Turn on debugging],
[case "${enableval}" in
yes) AC_DEFINE([DEBUG], [1],[Enable debug]) ;;
no) ;;
*) AC_MSG_ERROR([bad value ${enableval} for --enable-debug]) ;;
esac],[debug=false])
AC_CANONICAL_HOST
build_linux=no
build_windows=no
build_mac=no
# Detect the target system
case "${host_os}" in
linux*)
AC_DEFINE([LINUX], [1],[Linux system])
build_linux=yes
;;
darwin*)
build_mac=yes
AC_DEFINE([MACOS], [1],[MacOS system])
;;
*)
AC_MSG_ERROR(["OS $host_os is not supported"])
;;
esac
# case for window:
# cygwin*|mingw*)
# build_windows=yes
# ;;
# Pass the conditionals to automake
AM_CONDITIONAL([DB], [test "$use_db" = "yes"])
AM_CONDITIONAL([LINUX], [test "$build_linux" = "yes"])
AM_CONDITIONAL([WINDOWS], [test "$build_windows" = "yes"])
AM_CONDITIONAL([OSX], [test "$build_mac" = "yes"])
# find a file called Makefile.in, substitute placeholders
# like @PACKAGE_VERSION@ with values like 0.1.0a,
# and write the results to Makefile.
AC_CONFIG_FILES([Makefile])
# output the script:
AC_OUTPUT