diff --git a/.gitignore b/.gitignore index d60c22d..f48c7c1 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,4 @@ libcgi.so autom4te.cache configure src/config.h +*swp diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..9499879 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,76 @@ +# +# Copyright 2013,2016 Alexander Dahl +# +cmake_minimum_required(VERSION 2.8.8) + +project(cgi) +string(TOUPPER ${PROJECT_NAME} PROJECT_NAME_UC) +string(TOLOWER ${PROJECT_NAME} PROJECT_NAME_LC) +set(LIBPREFIX ${PROJECT_NAME}) +set(LIBPREFIX_LC ${PROJECT_NAME_LC}) +set(LIBPREFIX_UC ${PROJECT_NAME_UC}) + +set(PROJECT_VERSION_MAJOR 1) +set(PROJECT_VERSION_MINOR 1) +set(PROJECT_VERSION_PATCH 0) +set(PROJECT_VERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}") +message(STATUS "PROJECT_VERSION: ${PROJECT_VERSION}") + +set(CGI_DESCRIPTION "A C library to build CGI applications.") +set(CGI_URL "https://github.com/rafaelsteil/libcgi") + +# includes +include(CMakePackageConfigHelpers) # cmake 2.8.8 +include(FeatureSummary) +include(GNUInstallDirs) # cmake 2.8.5 + +# additional compiler flags +add_definitions(-Wall -Wextra -Wcast-align) + +# subdirectories +add_subdirectory("src") + +# cmake package stuff +configure_package_config_file(${PROJECT_NAME_LC}-config.cmake.in + "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME_LC}-config.cmake" + INSTALL_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}" + PATH_VARS CMAKE_INSTALL_INCLUDEDIR + NO_CHECK_REQUIRED_COMPONENTS_MACRO +) +write_basic_package_version_file( + "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME_LC}-config-version.cmake" + VERSION ${PROJECT_VERSION} + COMPATIBILITY SameMajorVersion +) +install(FILES + "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME_LC}-config.cmake" + "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME_LC}-config-version.cmake" + DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}" +) + +# pkg-config stuff +configure_file( + "${CMAKE_CURRENT_SOURCE_DIR}/libcgi.pc.cmake.in" + "${CMAKE_CURRENT_BINARY_DIR}/libcgi.pc" + @ONLY +) +install(FILES + "${CMAKE_CURRENT_BINARY_DIR}/libcgi.pc" + DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig" +) + +# feature summary +message(STATUS "CMAKE_BUILD_TYPE: ${CMAKE_BUILD_TYPE}") +feature_summary(WHAT ALL) + +# packaging +set(CPACK_PACKAGE_NAME "libcgi") +set(CPACK_PACKAGE_VERSION_MAJOR ${PROJECT_VERSION_MAJOR}) +set(CPACK_PACKAGE_VERSION_MINOR ${PROJECT_VERSION_MINOR}) +set(CPACK_PACKAGE_VERSION_PATCH ${PROJECT_VERSION_PATCH}) +set(CPACK_PACKAGE_VERSION ${PROJECT_VERSION}) +set(CPACK_PACKAGE_DESCRIPTION_FILE "${PROJECT_SOURCE_DIR}/README.md") +set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "${CGI_DESCRIPTION}") +set(CPACK_SOURCE_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}") +set(CPACK_SOURCE_IGNORE_FILES "/\\\\.kdev4/;\\\\.kdev4$;/\\\\.git/;\\\\.gitignore;\\\\.swp$") +include(CPack) diff --git a/Makefile.in b/Makefile.in deleted file mode 100644 index a28a2d0..0000000 --- a/Makefile.in +++ /dev/null @@ -1,94 +0,0 @@ -INSTALL = @INSTALL@ -D -LN_S = @LN_S@ -INSTALL_PROGRAM = @INSTALL_PROGRAM@ -D -INSTALL_DATA = @INSTALL_DATA@ -D - -prefix = @prefix@ -exec_prefix = @exec_prefix@ - -SHAREDOPT = -shared -shared -fPIC -Wl,-soname,libcgi.so.0 -libdir = $(prefix)/lib -incdir = $(prefix)/include/libcgi -mandir = $(prefix)/man/man3 -SHELL = /bin/sh -EXTRA_LIBS = - -INCS = -Isrc -FLAGS = -Wall -D_REENTRANT - -OBJS = src/error.o src/cgi.o src/session.o src/base64.o src/md5.o \ - src/string.o src/general.o src/list.o src/cookie.o - -SHOBJS = $(OBJS:.o=.sh.o) - -%.o: %.c - $(CC) $(FLAGS) -c $*.c -o $@ - -%.sh.o: %.c - $(CC) $(FLAGS) -fPIC -c $*.c -o $@ - -all: src/libcgi.so src/libcgi.a - - @echo "" - @echo "" - @echo "" - @echo "+---------------------------------------+" - @echo "| Thanks for using LibCGI |" - @echo "+---------------------------------------+" - @echo "| LibCGI is getting better because |" - @echo "| people like you are using it. So, if |" - @echo "| LibCGI is helping you in some way, |" - @echo "| please help us to improve it, sending |" - @echo "| suggestions, bug reports, bug fixes, |" - @echo "| and specially improvment code. |" - @echo "| You can subscribe to the mailing list |" - @echo "| or send a mail to the author. |" - @echo "+---------------------------------------+" - @echo "" - - -shared: src/libcgi.so - $(INSTALL) -m 0644 src/libcgi.so $(DESTDIR)$(libdir) - -src/libcgi.a: $(OBJS) - $(AR) rc src/libcgi.a $(OBJS) - -src/libcgi.so: $(SHOBJS) - $(CC) $(SHAREDOPT) -o src/libcgi.so.0 $(SHOBJS) $(EXTRA_LIBS) - -install: - $(INSTALL) -m 0644 src/libcgi.a $(DESTDIR)/$(libdir)/libcgi.a - $(INSTALL) -m 0644 src/libcgi.so.0 $(DESTDIR)/$(libdir)/libcgi.so.0 - $(LN_S) libcgi.so.0 $(DESTDIR)/$(libdir)/libcgi.so - $(INSTALL) -m 0644 src/cgi.h $(DESTDIR)/$(incdir)/cgi.h - $(INSTALL) -m 0644 src/session.h $(DESTDIR)/$(incdir)/session.h - -src/error.o: src/error.c src/error.h -src/cgi.o: src/cgi.c src/cgi.h -src/session.o: src/session.c src/session.h -src/base64.o: src/base64.c -src/md5.o: src/md5.c -src/string.o: src/string.c -src/cookie.o: src/cookie.c -src/general.o: src/general.c -src/list.o: src/list.c - -clean: - find src/ -name *.o -exec rm -f {} \; - find src/ -name *.a -exec rm -f {} \; - find src/ -name *.so -exec rm -f {} \; - -uninstall: clean - rm -f $(libdir)/libcgi.* - rm -f $(incdir)/cgi.h - rm -f $(incdir)/session.h - rm -f $(mandir)/libcgi* - -install_man: - cp doc/man/man3/libcgi_base64.3 $(DESTDIR)$(mandir) - cp doc/man/man3/libcgi_cgi.3 $(DESTDIR)$(mandir) - cp doc/man/man3/libcgi_general.3 $(DESTDIR)$(mandir) - cp doc/man/man3/libcgi_string.3 $(DESTDIR)$(mandir) - cp doc/man/man3/libcgi_session.3 $(DESTDIR)$(mandir) - cp doc/man/man3/libcgi_cookie.3 $(DESTDIR)$(mandir) - diff --git a/README.md b/README.md index c9b8be0..1e268f4 100644 --- a/README.md +++ b/README.md @@ -6,10 +6,22 @@ It was my first Open Source project, somewhere back in the 2000s and somethings. Building -------- -* Type _./configure_ and then _make_ -* To clean, type _make clean_ -* To remove library files, type _make uninstall_ -* At the _examples/_ directory you'll find some code to start with +LibCGI is built with [CMake](https://cmake.org/). One quick way: + +* create a build directory and change into it + + mkdir build + cd build + +* call cmake + + cmake .. + +* build it + + make + +Of course every other way CMake provides would also work, see CMake documentation. TODO ---- diff --git a/autogen.sh b/autogen.sh deleted file mode 100755 index 038a19d..0000000 --- a/autogen.sh +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/bash - -for i in `/usr/bin/which autoconf`; do - $i -done - diff --git a/cgi-config.cmake.in b/cgi-config.cmake.in new file mode 100644 index 0000000..fa2ed2b --- /dev/null +++ b/cgi-config.cmake.in @@ -0,0 +1,21 @@ +# +# Copyright 2013,2016 Alexander Dahl +# + +# paths +@PACKAGE_INIT@ +set_and_check(CGI_INCLUDE_DIRS "@PACKAGE_CMAKE_INSTALL_INCLUDEDIR@/lib@PROJECT_NAME@") + +# targets +get_filename_component(_dir "${CMAKE_CURRENT_LIST_FILE}" PATH) +if(NOT TARGET @PROJECT_NAME@-shared) + include("${_dir}/@PROJECT_NAME@-targets.cmake") +endif(NOT TARGET @PROJECT_NAME@-shared) +set(CGI_LIBRARIES @PROJECT_NAME@-shared) + +# feature summary +include(FeatureSummary) +set_package_properties(@PROJECT_NAME_UC@ PROPERTIES + DESCRIPTION "@CGI_DESCRIPTION@" + URL "@CGI_URL@" +) diff --git a/configure.in b/configure.in deleted file mode 100644 index e0aaca7..0000000 --- a/configure.in +++ /dev/null @@ -1,16 +0,0 @@ -AC_INIT(src/cgi.c) -AC_CONFIG_HEADER(src/config.h) - -dnl Searching for a compiler -AC_PROG_CC -AC_PROG_INSTALL -AC_PROG_LN_S - -AC_DEFINE(HAVE_MD5) - -dnl Check headers -AC_HEADER_STDC - -dnl Generate Makefile -AC_OUTPUT(Makefile) - diff --git a/examples/guestbook/Makefile.am b/examples/guestbook/Makefile.am deleted file mode 100644 index e69de29..0000000 diff --git a/examples/redirect/Makefile.am b/examples/redirect/Makefile.am deleted file mode 100644 index e69de29..0000000 diff --git a/examples/session/session_ex2/Makefile.am b/examples/session/session_ex2/Makefile.am deleted file mode 100644 index e69de29..0000000 diff --git a/examples/simple_form/Makefile.am b/examples/simple_form/Makefile.am deleted file mode 100644 index e69de29..0000000 diff --git a/install-sh b/install-sh deleted file mode 100755 index 89fc9b0..0000000 --- a/install-sh +++ /dev/null @@ -1,238 +0,0 @@ -#! /bin/sh -# -# install - install a program, script, or datafile -# This comes from X11R5. -# -# Calling this script install-sh is preferred over install.sh, to prevent -# `make' implicit rules from creating a file called install from it -# when there is no Makefile. -# -# This script is compatible with the BSD install script, but was written -# from scratch. -# - - -# set DOITPROG to echo to test this script - -# Don't use :- since 4.3BSD and earlier shells don't like it. -doit="${DOITPROG-}" - - -# put in absolute paths if you don't have them in your path; or use env. vars. - -mvprog="${MVPROG-mv}" -cpprog="${CPPROG-cp}" -chmodprog="${CHMODPROG-chmod}" -chownprog="${CHOWNPROG-chown}" -chgrpprog="${CHGRPPROG-chgrp}" -stripprog="${STRIPPROG-strip}" -rmprog="${RMPROG-rm}" -mkdirprog="${MKDIRPROG-mkdir}" - -tranformbasename="" -transform_arg="" -instcmd="$mvprog" -chmodcmd="$chmodprog 0755" -chowncmd="" -chgrpcmd="" -stripcmd="" -rmcmd="$rmprog -f" -mvcmd="$mvprog" -src="" -dst="" -dir_arg="" - -while [ x"$1" != x ]; do - case $1 in - -c) instcmd="$cpprog" - shift - continue;; - - -d) dir_arg=true - shift - continue;; - - -m) chmodcmd="$chmodprog $2" - shift - shift - continue;; - - -o) chowncmd="$chownprog $2" - shift - shift - continue;; - - -g) chgrpcmd="$chgrpprog $2" - shift - shift - continue;; - - -s) stripcmd="$stripprog" - shift - continue;; - - -t=*) transformarg=`echo $1 | sed 's/-t=//'` - shift - continue;; - - -b=*) transformbasename=`echo $1 | sed 's/-b=//'` - shift - continue;; - - *) if [ x"$src" = x ] - then - src=$1 - else - # this colon is to work around a 386BSD /bin/sh bug - : - dst=$1 - fi - shift - continue;; - esac -done - -if [ x"$src" = x ] -then - echo "install: no input file specified" - exit 1 -else - true -fi - -if [ x"$dir_arg" != x ]; then - dst=$src - src="" - - if [ -d $dst ]; then - instcmd=: - else - instcmd=mkdir - fi -else - -# Waiting for this to be detected by the "$instcmd $src $dsttmp" command -# might cause directories to be created, which would be especially bad -# if $src (and thus $dsttmp) contains '*'. - - if [ -f $src -o -d $src ] - then - true - else - echo "install: $src does not exist" - exit 1 - fi - - if [ x"$dst" = x ] - then - echo "install: no destination specified" - exit 1 - else - true - fi - -# If destination is a directory, append the input filename; if your system -# does not like double slashes in filenames, you may need to add some logic - - if [ -d $dst ] - then - dst="$dst"/`basename $src` - else - true - fi -fi - -## this sed command emulates the dirname command -dstdir=`echo $dst | sed -e 's,[^/]*$,,;s,/$,,;s,^$,.,'` - -# Make sure that the destination directory exists. -# this part is taken from Noah Friedman's mkinstalldirs script - -# Skip lots of stat calls in the usual case. -if [ ! -d "$dstdir" ]; then -defaultIFS=' -' -IFS="${IFS-${defaultIFS}}" - -oIFS="${IFS}" -# Some sh's can't handle IFS=/ for some reason. -IFS='%' -set - `echo ${dstdir} | sed -e 's@/@%@g' -e 's@^%@/@'` -IFS="${oIFS}" - -pathcomp='' - -while [ $# -ne 0 ] ; do - pathcomp="${pathcomp}${1}" - shift - - if [ ! -d "${pathcomp}" ] ; - then - $mkdirprog "${pathcomp}" - else - true - fi - - pathcomp="${pathcomp}/" -done -fi - -if [ x"$dir_arg" != x ] -then - $doit $instcmd $dst && - - if [ x"$chowncmd" != x ]; then $doit $chowncmd $dst; else true ; fi && - if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dst; else true ; fi && - if [ x"$stripcmd" != x ]; then $doit $stripcmd $dst; else true ; fi && - if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dst; else true ; fi -else - -# If we're going to rename the final executable, determine the name now. - - if [ x"$transformarg" = x ] - then - dstfile=`basename $dst` - else - dstfile=`basename $dst $transformbasename | - sed $transformarg`$transformbasename - fi - -# don't allow the sed command to completely eliminate the filename - - if [ x"$dstfile" = x ] - then - dstfile=`basename $dst` - else - true - fi - -# Make a temp file name in the proper directory. - - dsttmp=$dstdir/#inst.$$# - -# Move or copy the file name to the temp name - - $doit $instcmd $src $dsttmp && - - trap "rm -f ${dsttmp}" 0 && - -# and set any options; do chmod last to preserve setuid bits - -# If any of these fail, we abort the whole thing. If we want to -# ignore errors from any of these, just make sure not to ignore -# errors from the above "$doit $instcmd $src $dsttmp" command. - - if [ x"$chowncmd" != x ]; then $doit $chowncmd $dsttmp; else true;fi && - if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dsttmp; else true;fi && - if [ x"$stripcmd" != x ]; then $doit $stripcmd $dsttmp; else true;fi && - if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dsttmp; else true;fi && - -# Now rename the file to the real destination. - - $doit $rmcmd -f $dstdir/$dstfile && - $doit $mvcmd $dsttmp $dstdir/$dstfile - -fi && - - -exit 0 diff --git a/libcgi.pc.cmake.in b/libcgi.pc.cmake.in new file mode 100644 index 0000000..8ad919a --- /dev/null +++ b/libcgi.pc.cmake.in @@ -0,0 +1,9 @@ +libdir=@CMAKE_INSTALL_FULL_LIBDIR@ +includedir=@CMAKE_INSTALL_FULL_INCLUDEDIR@ + +Name: libcgi +Description: @CGI_DESCRIPTION@ +URL: @CGI_URL@ +Version: @PROJECT_VERSION@ +Libs: -L${libdir} -lcgi +Cflags: -I${includedir} diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt new file mode 100644 index 0000000..f32d22e --- /dev/null +++ b/src/CMakeLists.txt @@ -0,0 +1,50 @@ +# +# Copyright 2013,2016 Alexander Dahl +# +configure_file( + "${CMAKE_CURRENT_SOURCE_DIR}/config.h.cmake.in" + "${CMAKE_CURRENT_BINARY_DIR}/config.h" +) + +include_directories( + "${CMAKE_CURRENT_BINARY_DIR}" +) + +set(CGI_SRC + base64.c + cgi.c + cookie.c + error.c + general.c + list.c + # md5.c + session.c + string.c +) + +# create binary +add_library(${PROJECT_NAME}-shared SHARED ${CGI_SRC}) +set_target_properties(${PROJECT_NAME}-shared PROPERTIES + OUTPUT_NAME ${PROJECT_NAME} + SOVERSION ${PROJECT_VERSION_MAJOR} + VERSION ${PROJECT_VERSION} +) + +# install binary +install(TARGETS ${PROJECT_NAME}-shared + EXPORT ${PROJECT_NAME}-targets + LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" +) + +# install cmake targets +install(EXPORT ${PROJECT_NAME}-targets + DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}" +) + +# install headers +install(FILES + cgi.h + error.h + session.h + DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/lib${PROJECT_NAME}" +) diff --git a/src/config.h.cmake.in b/src/config.h.cmake.in new file mode 100644 index 0000000..29271cf --- /dev/null +++ b/src/config.h.cmake.in @@ -0,0 +1 @@ +#define HAVE_MD5 0 diff --git a/src/config.h.in b/src/config.h.in deleted file mode 100644 index 5758000..0000000 --- a/src/config.h.in +++ /dev/null @@ -1,5 +0,0 @@ -#define HAVE_MD5 0 -#define HAVE_TYPES 0 -#define HAVE_SOCKET 0 -#define HAVE_NETDB 0 -#define HAVE_NETINET 0