set(CPACK_PACKAGE_VERSION_MAJOR "1")
set(CPACK_PACKAGE_VERSION_MINOR "2")
set(CPACK_PACKAGE_VERSION_PATCH "3")
+if(CMAKE_BUILD_TYPE MATCHES RELEASE)
+ set(ASSETS_PATH "${CMAKE_INSTALL_PREFIX}/share/${PROJECT_NAME}/htdocs")
+else()
+ set(ASSETS_PATH "${PROJECT_SOURCE_DIR}/htdocs")
+endif()
option(WITH_MPD_HOST_CHANGE "Let users of the web frontend change the MPD Host" ON)
-option(WITH_DYNAMIC_SERVING "Serve file of ./htdocs dynamically (development)" OFF)
+option(WITH_DYNAMIC_ASSETS "Serve assets dynamically (e.g for development/packaging)" OFF)
option(WITH_IPV6 "enable IPv6 support" ON)
find_package(LibMPDClient REQUIRED)
include(CheckCSourceCompiles)
-set(CMAKE_C_FLAGS "-std=gnu99 -Wall")
+set(CMAKE_C_FLAGS "-std=gnu99 -Wall")
set(CMAKE_C_FLAGS_DEBUG "-ggdb -pedantic")
if(WITH_IPV6)
- set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS NS_ENABLE_IPV6)
+ set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS NS_ENABLE_IPV6)
endif()
file(GLOB RESOURCES
- RELATIVE ${PROJECT_SOURCE_DIR}
- htdocs/js/*
- htdocs/assets/*
- htdocs/css/*.min.css
- htdocs/fonts/*
- htdocs/index.html
-)
-
-if(CMAKE_CROSSCOMPILING)
- set(MKDATA_EXE ${PROJECT_SOURCE_DIR}/htdocs/mkdata.pl)
-else()
- set(MKDATA_EXE $<TARGET_FILE:mkdata>)
- set(MKDATA_TARGET mkdata)
- add_executable(mkdata htdocs/mkdata.c)
-endif()
-
-add_custom_command(OUTPUT ${PROJECT_BINARY_DIR}/assets.c
- COMMAND ${MKDATA_EXE} ${RESOURCES} > ${PROJECT_BINARY_DIR}/assets.c
- WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
- DEPENDS ${RESOURCES} ${MKDATA_TARGET}
+ RELATIVE ${PROJECT_SOURCE_DIR}
+ htdocs/js/*
+ htdocs/assets/*
+ htdocs/css/*.min.css
+ htdocs/fonts/*
+ htdocs/index.html
)
set(SOURCES
src/ympd.c
- src/http_server.c
src/mpd_client.c
src/mongoose.c
src/json_encode.c
- assets.c
)
+if(NOT WITH_DYNAMIC_ASSETS)
+ if(CMAKE_CROSSCOMPILING)
+ set(MKDATA_EXE ${PROJECT_SOURCE_DIR}/tools/mkdata.pl)
+ else()
+ set(MKDATA_EXE $<TARGET_FILE:mkdata>)
+ set(MKDATA_TARGET mkdata)
+ add_executable(mkdata tools/mkdata.c)
+ endif()
+
+ add_custom_command(OUTPUT ${PROJECT_BINARY_DIR}/assets.c
+ COMMAND ${MKDATA_EXE} ${RESOURCES} > ${PROJECT_BINARY_DIR}/assets.c
+ WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
+ DEPENDS ${RESOURCES} ${MKDATA_TARGET}
+ )
+ list(APPEND SOURCES src/http_server.c assets.c)
+endif()
+
add_executable(ympd ${SOURCES})
target_link_libraries(ympd ${LIBMPDCLIENT_LIBRARY} ${CMAKE_THREAD_LIBS_INIT})
install(TARGETS ympd DESTINATION bin)
install(FILES ympd.1 DESTINATION ${CMAKE_INSTALL_PREFIX}/share/man/man1)
+if(WITH_DYNAMIC_ASSETS)
+ install(DIRECTORY htdocs DESTINATION share/${PROJECT_NAME})
+endif()
+++ /dev/null
-/* This program is used to embed arbitrary data into a C binary. It takes
- * a list of files as an input, and produces a .c data file that contains
- * contents of all these files as collection of char arrays.
- *
- * Usage: ./mkdata <this_file> <file1> [file2, ...] > embedded_data.c
- */
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <err.h>
-#include <errno.h>
-#include <string.h>
-
-const char* header =
-"#include <stddef.h>\n"
-"#include <string.h>\n"
-"#include <sys/types.h>\n"
-"#include \"src/http_server.h\"\n"
-"\n"
-"static const struct embedded_file embedded_files[] = {\n";
-
-const char* footer =
-" {NULL, NULL, NULL, 0}\n"
-"};\n"
-"\n"
-"const struct embedded_file *find_embedded_file(const char *name) {\n"
-" const struct embedded_file *p;\n"
-" for (p = embedded_files; p->name != NULL; p++)\n"
-" if (!strcmp(p->name, name))\n"
-" return p;\n"
-" return NULL;\n"
-"}\n";
-
-static const char* get_mime(char* filename)
-{
- const char *extension = strrchr(filename, '.');
- if(!strcmp(extension, ".js"))
- return "application/javascript";
- if(!strcmp(extension, ".css"))
- return "text/css";
- if(!strcmp(extension, ".ico"))
- return "image/vnd.microsoft.icon";
- if(!strcmp(extension, ".woff"))
- return "application/font-woff";
- if(!strcmp(extension, ".ttf"))
- return "application/x-font-ttf";
- if(!strcmp(extension, ".eot"))
- return "application/octet-stream";
- if(!strcmp(extension, ".svg"))
- return "image/svg+xml";
- if(!strcmp(extension, ".html"))
- return "text/html";
- return "text/plain";
-}
-
-int main(int argc, char *argv[])
-{
- int i, j, buf;
- FILE *fd;
-
- if(argc <= 1)
- err(EXIT_FAILURE, "Usage: ./%s <this_file> <file1> [file2, ...] > embedded_data.c", argv[0]);
-
- for(i = 1; i < argc; i++)
- {
- fd = fopen(argv[i], "r");
- if(!fd)
- err(EXIT_FAILURE, "%s", argv[i]);
-
- printf("static const unsigned char v%d[] = {", i);
-
- j = 0;
- while((buf = fgetc(fd)) != EOF)
- {
- if(!(j % 12))
- putchar('\n');
-
- printf(" %#04x, ", buf);
- j++;
- }
- printf(" 0x00\n};\n\n");
- fclose(fd);
- }
- fputs(header, stdout);
-
- for(i = 1; i < argc; i++)
- {
- printf(" {\"%s\", v%d, \"%s\", sizeof(v%d) - 1}, \n",
- argv[i]+6, i, get_mime(argv[i]), i);
- }
-
- fputs(footer, stdout);
- return EXIT_SUCCESS;
-}
+++ /dev/null
-#!/usr/bin/perl
-# This program is used to embed arbitrary data into a C binary. It takes
-# a list of files as an input, and produces a .c data file that contains
-# contents of all these files as collection of char arrays.
-#
-# Usage: perl <this_file> <file1> [file2, ...] > embedded_data.c
-
-use File::Basename;
-
-%mimetypes = (
- js => 'application/javascript',
- css => 'text/css',
- ico => 'image/vnd.microsoft.icon',
- woff => 'application/font-woff',
- ttf => 'application/x-font-ttf',
- eot => 'application/octet-stream',
- svg => 'image/svg+xml',
- html => 'text/html'
-);
-
-foreach my $i (0 .. $#ARGV) {
- open FD, '<:raw', $ARGV[$i] or die "Cannot open $ARGV[$i]: $!\n";
- printf("static const unsigned char v%d[] = {", $i);
- my $byte;
- my $j = 0;
- while (read(FD, $byte, 1)) {
- if (($j % 12) == 0) {
- print "\n";
- }
- printf ' %#04x,', ord($byte);
- $j++;
- }
- print " 0x00\n};\n";
- close FD;
-}
-
-print <<EOS;
-#include <stddef.h>
-#include <string.h>
-#include <sys/types.h>
-#include "src/http_server.h"
-
-static const struct embedded_file embedded_files[] = {
-EOS
-
-foreach my $i (0 .. $#ARGV) {
- my ($ext) = $ARGV[$i] =~ /([^.]+)$/;
- my $mime = $mimetypes{$ext};
- $ARGV[$i] =~ s/htdocs//;
- print " {\"$ARGV[$i]\", v$i, \"$mime\", sizeof(v$i) - 1},\n";
-}
-
-print <<EOS;
- {NULL, NULL, NULL, 0}
-};
-
-const struct embedded_file *find_embedded_file(const char *name) {
- const struct embedded_file *p;
- for (p = embedded_files; p->name != NULL; p++)
- if (!strcmp(p->name, name))
- return p;
- return NULL;
-}
-
-EOS
#define YMPD_VERSION_MAJOR ${CPACK_PACKAGE_VERSION_MAJOR}
#define YMPD_VERSION_MINOR ${CPACK_PACKAGE_VERSION_MINOR}
#define YMPD_VERSION_PATCH ${CPACK_PACKAGE_VERSION_PATCH}
-#define SRC_PATH "${PROJECT_SOURCE_DIR}/htdocs"
+#define SRC_PATH "${ASSETS_PATH}"
#cmakedefine WITH_MPD_HOST_CHANGE
-#cmakedefine WITH_DYNAMIC_SERVING
+#cmakedefine WITH_DYNAMIC_ASSETS
#endif
else
return MG_TRUE;
} else
-#ifdef WITH_DYNAMIC_SERVING
+#ifdef WITH_DYNAMIC_ASSETS
return MG_FALSE;
#else
return callback_http(c);
atexit(bye);
error_msg = mg_set_option(server, "listening_port", "8080");
-#ifdef WITH_DYNAMIC_SERVING
+#ifdef WITH_DYNAMIC_ASSETS
mg_set_option(server, "document_root", SRC_PATH);
#endif
--- /dev/null
+/* This program is used to embed arbitrary data into a C binary. It takes
+ * a list of files as an input, and produces a .c data file that contains
+ * contents of all these files as collection of char arrays.
+ *
+ * Usage: ./mkdata <this_file> <file1> [file2, ...] > embedded_data.c
+ */
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <err.h>
+#include <errno.h>
+#include <string.h>
+
+const char* header =
+"#include <stddef.h>\n"
+"#include <string.h>\n"
+"#include <sys/types.h>\n"
+"#include \"src/http_server.h\"\n"
+"\n"
+"static const struct embedded_file embedded_files[] = {\n";
+
+const char* footer =
+" {NULL, NULL, NULL, 0}\n"
+"};\n"
+"\n"
+"const struct embedded_file *find_embedded_file(const char *name) {\n"
+" const struct embedded_file *p;\n"
+" for (p = embedded_files; p->name != NULL; p++)\n"
+" if (!strcmp(p->name, name))\n"
+" return p;\n"
+" return NULL;\n"
+"}\n";
+
+static const char* get_mime(char* filename)
+{
+ const char *extension = strrchr(filename, '.');
+ if(!strcmp(extension, ".js"))
+ return "application/javascript";
+ if(!strcmp(extension, ".css"))
+ return "text/css";
+ if(!strcmp(extension, ".ico"))
+ return "image/vnd.microsoft.icon";
+ if(!strcmp(extension, ".woff"))
+ return "application/font-woff";
+ if(!strcmp(extension, ".ttf"))
+ return "application/x-font-ttf";
+ if(!strcmp(extension, ".eot"))
+ return "application/octet-stream";
+ if(!strcmp(extension, ".svg"))
+ return "image/svg+xml";
+ if(!strcmp(extension, ".html"))
+ return "text/html";
+ return "text/plain";
+}
+
+int main(int argc, char *argv[])
+{
+ int i, j, buf;
+ FILE *fd;
+
+ if(argc <= 1)
+ err(EXIT_FAILURE, "Usage: ./%s <this_file> <file1> [file2, ...] > embedded_data.c", argv[0]);
+
+ for(i = 1; i < argc; i++)
+ {
+ fd = fopen(argv[i], "r");
+ if(!fd)
+ err(EXIT_FAILURE, "%s", argv[i]);
+
+ printf("static const unsigned char v%d[] = {", i);
+
+ j = 0;
+ while((buf = fgetc(fd)) != EOF)
+ {
+ if(!(j % 12))
+ putchar('\n');
+
+ printf(" %#04x, ", buf);
+ j++;
+ }
+ printf(" 0x00\n};\n\n");
+ fclose(fd);
+ }
+ fputs(header, stdout);
+
+ for(i = 1; i < argc; i++)
+ {
+ printf(" {\"%s\", v%d, \"%s\", sizeof(v%d) - 1}, \n",
+ argv[i]+6, i, get_mime(argv[i]), i);
+ }
+
+ fputs(footer, stdout);
+ return EXIT_SUCCESS;
+}
--- /dev/null
+#!/usr/bin/perl
+# This program is used to embed arbitrary data into a C binary. It takes
+# a list of files as an input, and produces a .c data file that contains
+# contents of all these files as collection of char arrays.
+#
+# Usage: perl <this_file> <file1> [file2, ...] > embedded_data.c
+
+use File::Basename;
+
+%mimetypes = (
+ js => 'application/javascript',
+ css => 'text/css',
+ ico => 'image/vnd.microsoft.icon',
+ woff => 'application/font-woff',
+ ttf => 'application/x-font-ttf',
+ eot => 'application/octet-stream',
+ svg => 'image/svg+xml',
+ html => 'text/html'
+);
+
+foreach my $i (0 .. $#ARGV) {
+ open FD, '<:raw', $ARGV[$i] or die "Cannot open $ARGV[$i]: $!\n";
+ printf("static const unsigned char v%d[] = {", $i);
+ my $byte;
+ my $j = 0;
+ while (read(FD, $byte, 1)) {
+ if (($j % 12) == 0) {
+ print "\n";
+ }
+ printf ' %#04x,', ord($byte);
+ $j++;
+ }
+ print " 0x00\n};\n";
+ close FD;
+}
+
+print <<EOS;
+#include <stddef.h>
+#include <string.h>
+#include <sys/types.h>
+#include "src/http_server.h"
+
+static const struct embedded_file embedded_files[] = {
+EOS
+
+foreach my $i (0 .. $#ARGV) {
+ my ($ext) = $ARGV[$i] =~ /([^.]+)$/;
+ my $mime = $mimetypes{$ext};
+ $ARGV[$i] =~ s/htdocs//;
+ print " {\"$ARGV[$i]\", v$i, \"$mime\", sizeof(v$i) - 1},\n";
+}
+
+print <<EOS;
+ {NULL, NULL, NULL, 0}
+};
+
+const struct embedded_file *find_embedded_file(const char *name) {
+ const struct embedded_file *p;
+ for (p = embedded_files; p->name != NULL; p++)
+ if (!strcmp(p->name, name))
+ return p;
+ return NULL;
+}
+
+EOS