# HG changeset patch # User Josef 'Jeff' Sipek # Date 1501107508 -10800 # Node ID 3ae73be13d33fed211af43f8955006aadb1a26bd Initial commit Signed-off-by: Josef 'Jeff' Sipek diff -r 000000000000 -r 3ae73be13d33 .hgignore --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/.hgignore Thu Jul 27 01:18:28 2017 +0300 @@ -0,0 +1,13 @@ +syntax: glob + +galleryd + +hgversion.h + +Makefile +CMakeCache.txt +CMakeFiles/ +cmake_install.cmake +config.h + +CTestTestfile.cmake diff -r 000000000000 -r 3ae73be13d33 CMakeLists.txt --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/CMakeLists.txt Thu Jul 27 01:18:28 2017 +0300 @@ -0,0 +1,75 @@ +# +# Copyright (c) 2017 Josef 'Jeff' Sipek +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. +# + +cmake_minimum_required(VERSION 2.8.12.2) + +enable_testing() + +include(config.cmake) + +add_definitions( + -D__EXTENSIONS__ + -D_REENTRANT +) + +add_compile_options( + -Wall + -O2 + -g + -std=gnu99 + -fno-omit-frame-pointer + $<$:-fno-inline-small-functions> + $<$:-fno-inline-functions-called-once> +) + +include_directories( + ${JEFFPC_INCLUDE_DIR} +) + +add_custom_target(revisiontag ALL) + +add_custom_command(TARGET revisiontag + COMMAND ${CMAKE_COMMAND} + -DSOURCE_DIR=${CMAKE_CURRENT_SOURCE_DIR} + -DBINARY_DIR=${CMAKE_CURRENT_BINARY_DIR} + -P ${CMAKE_CURRENT_SOURCE_DIR}/cmake/hg.cmake +) + +add_executable(galleryd + version.c +) + +target_link_libraries(galleryd + ${JEFFPC_LIBRARY} + ${JEFFPC_COMM_LIBRARY} +) + +add_dependencies(galleryd revisiontag) + +function(simple_c_test type section bin data) + add_test(NAME "${type}:${section}:${data}" + COMMAND "${CMAKE_BINARY_DIR}/test_${bin}" + "${CMAKE_CURRENT_SOURCE_DIR}/${data}" + ) +endfunction() + +#add_subdirectory(test) diff -r 000000000000 -r 3ae73be13d33 cmake/Modules/Findjeffpc.cmake --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cmake/Modules/Findjeffpc.cmake Thu Jul 27 01:18:28 2017 +0300 @@ -0,0 +1,69 @@ +# +# Copyright (c) 2016-2017 Josef 'Jeff' Sipek +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. +# + +# +# Find the libjeffpc includes and library. +# +# This module defines: +# JEFFPC_INCLUDE_DIR +# JEFFPC_LIBRARY +# JEFFPC_COMM_LIBRARY +# JEFFPC_FOUND +# +# Use the following variables to help locate the library and header files. +# WITH_JEFFPC_LIB=x - directory containing libjeffpc.so +# WITH_JEFFPC_COMM_LIB=x - directory containing libjeffpc-comm.so +# WITH_JEFFPC_INCLUDES=x - directory containing jeffpc/jeffpc.h +# WITH_JEFFPC=x - same as setting WITH_JEFFPC_LIB=x/lib and +# WITH_JEFFPC_INCLUDES=x/include +# + +if (WITH_JEFFPC) + if (NOT WITH_JEFFPC_LIB) + set(WITH_JEFFPC_LIB "${WITH_JEFFPC}/lib") + endif() + if (NOT WITH_JEFFPC_COMM_LIB) + set(WITH_JEFFPC_COMM_LIB "${WITH_JEFFPC}/lib") + endif() + if (NOT WITH_JEFFPC_INCLUDES) + set(WITH_JEFFPC_INCLUDES "${WITH_JEFFPC}/include") + endif() +endif() + +find_path(JEFFPC_INCLUDE_DIR jeffpc/jeffpc.h + PATHS ${WITH_JEFFPC_INCLUDES}) +find_library(JEFFPC_LIBRARY NAMES jeffpc + PATHS ${WITH_JEFFPC_LIB} +) +find_library(JEFFPC_COMM_LIBRARY NAMES jeffpc-comm + PATHS ${WITH_JEFFPC_COMM_LIB} +) + +# +# Handle the QUIETLY and REQUIRED arguments and set JEFFPC_FOUND to TRUE if +# all listed variables are TRUE. +# +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(JEFFPC DEFAULT_MSG JEFFPC_LIBRARY + JEFFPC_INCLUDE_DIR) +find_package_handle_standard_args(JEFFPC_COMM DEFAULT_MSG JEFFPC_COMM_LIBRARY + JEFFPC_INCLUDE_DIR) diff -r 000000000000 -r 3ae73be13d33 cmake/hg.cmake --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cmake/hg.cmake Thu Jul 27 01:18:28 2017 +0300 @@ -0,0 +1,63 @@ +# +# Copyright (c) 2017 Josef 'Jeff' Sipek +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. +# + +find_package(Hg) + +macro(gethgrev varname template) + set(${varname} "unknown") + + if(HG_FOUND) + execute_process( + COMMAND ${HG_EXECUTABLE} log -r . --template ${template} + WORKING_DIRECTORY ${SOURCE_DIR} + OUTPUT_VARIABLE ${varname} + RESULT_VARIABLE res_var + ) + if(NOT ${res_var} EQUAL 0) + set(${varname} "unknown") + endif() + endif() +endmacro() + +gethgrev(HG_COMMIT "{node}") + +# TODO: if there are uncommitted changes, append -dirty +gethgrev(VERSION + "{ifeq(latesttagdistance,0,\"{latesttag}\",\"{latesttag}-{latesttagdistance}-{node|short}\")}") + +if(${HG_COMMIT} STREQUAL "unknown") + message(WARNING "Failed to get revision info from Mercurial.") +endif() + +set(vstring "/* hgversion.h - Generated by cmake. Changes will be lost! */\n" + "#ifndef __BLAHGD_VERSION_H\n" + "#define __BLAHGD_VERSION_H\n" + "#define HG_COMMIT \"${HG_COMMIT}\"\n" + "#define VERSION \"${VERSION}\"\n" + "#endif\n") + +file(WRITE hgversion.h.txt ${vstring}) +# copy the file to the final header only if the version changes +# reduces needless rebuilds +execute_process(COMMAND ${CMAKE_COMMAND} -E copy_if_different + hgversion.h.txt ${BINARY_DIR}/hgversion.h) +execute_process(COMMAND ${CMAKE_COMMAND} -E remove hgversion.h.txt) diff -r 000000000000 -r 3ae73be13d33 config.cmake --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/config.cmake Thu Jul 27 01:18:28 2017 +0300 @@ -0,0 +1,45 @@ +# +# Copyright (c) 2017 Josef 'Jeff' Sipek +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. +# + +include(CheckFunctionExists) + +set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules") +find_package(jeffpc) + +macro(set_default name default) + if(NOT DEFINED ${name}) + message("-- Defaulting ${name} to ${default}") + set(${name} ${default}) + else() + message("-- User set ${name} to ${${name}}") + endif() +endmacro() + +set_default(DEFAULT_SCGI_PORT 2017) +set_default(DEFAULT_SCGI_THREADS 32) + +set_default(DEFAULT_DATA_DIR "./data") +set_default(DEFAULT_WEB_DIR "./web") + +set_default(BASE_URL "http://www.josefsipek.net/photos") + +configure_file(config.h.in config.h) diff -r 000000000000 -r 3ae73be13d33 config.h.in --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/config.h.in Thu Jul 27 01:18:28 2017 +0300 @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2017 Josef 'Jeff' Sipek + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#ifndef __CONFIG_H +#define __CONFIG_H + +/* settings */ +#cmakedefine DEFAULT_SCGI_PORT ${DEFAULT_SCGI_PORT} +#cmakedefine DEFAULT_SCGI_THREADS ${DEFAULT_SCGI_THREADS} + +#cmakedefine DEFAULT_DATA_DIR "${DEFAULT_DATA_DIR}" +#cmakedefine DEFAULT_WEB_DIR "${DEFAULT_WEB_DIR}" + +/* + * config alist symbol names + */ + +#define CONFIG_SCGI_PORT "scgi-port" +#define CONFIG_SCGI_THREADS "scgi-threads" +#define CONFIG_DATA_DIR "data-dir" +#define CONFIG_WEB_DIR "web-dir" +#define CONFIG_BASE_URL "base-url" + +/* + * prototypes, etc. for config.c + */ + +#include + +struct config { + uint16_t scgi_port; + uint64_t scgi_threads; + struct str *data_dir; + struct str *web_dir; + struct str *base_url; +}; + +extern struct config config; + +extern int config_load(const char *fname); + +#endif diff -r 000000000000 -r 3ae73be13d33 version.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/version.c Thu Jul 27 01:18:28 2017 +0300 @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2017 Josef 'Jeff' Sipek + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "hgversion.h" +#include "version.h" + +const char version_string[] = VERSION; diff -r 000000000000 -r 3ae73be13d33 version.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/version.h Thu Jul 27 01:18:28 2017 +0300 @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2017 Josef 'Jeff' Sipek + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#ifndef __VERSION_H +#define __VERSION_H + +extern const char version_string[]; + +#endif