1
0
mirror of https://github.com/SuperBFG7/ympd synced 2025-06-06 08:24:09 +00:00

Removed option to compile assets in executeable

This commit is contained in:
jcorporation 2018-05-24 17:26:07 +01:00
parent 956812b472
commit 361882d5af
7 changed files with 6 additions and 191 deletions

View File

@ -12,7 +12,6 @@ else()
endif() endif()
option(WITH_MPD_HOST_CHANGE "Let users of the web frontend change the MPD Host" ON) option(WITH_MPD_HOST_CHANGE "Let users of the web frontend change the MPD Host" ON)
option(WITH_DYNAMIC_ASSETS "Serve assets dynamically (e.g for development/packaging)" ON)
option(WITH_IPV6 "enable IPv6 support" ON) option(WITH_IPV6 "enable IPv6 support" ON)
option(WITH_SSL "enable SSL support" ON) option(WITH_SSL "enable SSL support" ON)
@ -53,28 +52,9 @@ set(SOURCES
src/json_encode.c src/json_encode.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(mympd ${SOURCES}) add_executable(mympd ${SOURCES})
target_link_libraries(mympd ${LIBMPDCLIENT_LIBRARY} ${CMAKE_THREAD_LIBS_INIT} ${OPENSSL_LIBRARIES}) target_link_libraries(mympd ${LIBMPDCLIENT_LIBRARY} ${CMAKE_THREAD_LIBS_INIT} ${OPENSSL_LIBRARIES})
install(TARGETS mympd DESTINATION bin) install(TARGETS mympd DESTINATION bin)
install(FILES mympd.1 DESTINATION ${CMAKE_INSTALL_PREFIX}/share/man/man1) install(FILES mympd.1 DESTINATION ${CMAKE_INSTALL_PREFIX}/share/man/man1)
if(WITH_DYNAMIC_ASSETS) install(DIRECTORY htdocs DESTINATION share/${PROJECT_NAME})
install(DIRECTORY htdocs DESTINATION share/${PROJECT_NAME})
endif()

View File

@ -26,7 +26,7 @@ Unix Build Instructions
1. install dependencies. cmake, libmpdclient (dev), and OpenSSL (dev) are available from all major distributions. 1. install dependencies. cmake, libmpdclient (dev), and OpenSSL (dev) are available from all major distributions.
2. create build directory ```cd /path/to/src; mkdir build; cd build``` 2. create build directory ```cd /path/to/src; mkdir build; cd build```
3. create makefile ```cmake .. -DCMAKE_INSTALL_PREFIX:PATH=/usr -DWITH_DYNAMIC_ASSETS=ON -DCMAKE_BUILD_TYPE=RELEASE``` 3. create makefile ```cmake .. -DCMAKE_INSTALL_PREFIX:PATH=/usr -DCMAKE_BUILD_TYPE=RELEASE```
4. build ```make``` 4. build ```make```
5. install ```sudo make install``` or just run with ```./ympd``` 5. install ```sudo make install``` or just run with ```./ympd```
6. Link your mpd music directory to ```/path/to/src/htdocs/library``` and put ```folder.jpg``` files in your album directories 6. Link your mpd music directory to ```/path/to/src/htdocs/library``` and put ```folder.jpg``` files in your album directories
@ -63,4 +63,5 @@ To run ympd with SSL support:
Copyright Copyright
--------- ---------
ympd: 2013-2014 <andy@ndyk.de> ympd: 2013-2014 <andy@ndyk.de>
myMPD: 2018 <mail@jcgames.de> myMPD: 2018 <mail@jcgames.de>

View File

@ -11,7 +11,7 @@ Environment=MYMPD_USER=nobody
Environment=DIGEST= Environment=DIGEST=
Environment=LOCALPORT= Environment=LOCALPORT=
EnvironmentFile=/etc/default/mympd EnvironmentFile=/etc/default/mympd
ExecStart=/usr/bin/ympd --user $MYMPD_USER --webport $WEB_PORT --host $MPD_HOST --port $MPD_PORT $DIGEST $LOCALPORT ExecStart=/usr/bin/mympd --user $MYMPD_USER --webport $WEB_PORT --host $MPD_HOST --port $MPD_PORT $DIGEST $LOCALPORT
Type=simple Type=simple
[Install] [Install]

View File

@ -24,6 +24,5 @@
#define YMPD_VERSION_PATCH ${CPACK_PACKAGE_VERSION_PATCH} #define YMPD_VERSION_PATCH ${CPACK_PACKAGE_VERSION_PATCH}
#define SRC_PATH "${ASSETS_PATH}" #define SRC_PATH "${ASSETS_PATH}"
#cmakedefine WITH_MPD_HOST_CHANGE #cmakedefine WITH_MPD_HOST_CHANGE
#cmakedefine WITH_DYNAMIC_ASSETS
#endif #endif

View File

@ -54,11 +54,7 @@ static int server_callback(struct mg_connection *c, enum mg_event ev) {
else else
return MG_TRUE; return MG_TRUE;
} else } else
#ifdef WITH_DYNAMIC_ASSETS return MG_FALSE;
return MG_FALSE;
#else
return callback_http(c);
#endif
case MG_AUTH: case MG_AUTH:
// no auth for websockets since mobile safari does not support it // no auth for websockets since mobile safari does not support it
if ( (mpd.gpass == NULL) || (c->is_websocket) || ((mpd.local_port > 0) && (c->local_port == mpd.local_port)) ) if ( (mpd.gpass == NULL) || (c->is_websocket) || ((mpd.local_port > 0) && (c->local_port == mpd.local_port)) )
@ -85,11 +81,9 @@ int main(int argc, char **argv)
char *webport = "8080"; char *webport = "8080";
atexit(bye); atexit(bye);
#ifdef WITH_DYNAMIC_ASSETS
mg_set_option(server, "document_root", SRC_PATH); mg_set_option(server, "document_root", SRC_PATH);
#endif
mg_set_option(server, "auth_domain", "ympd"); mg_set_option(server, "auth_domain", "mympd");
mpd.port = 6600; mpd.port = 6600;
mpd.local_port = 0; mpd.local_port = 0;
mpd.gpass = NULL; mpd.gpass = NULL;

View File

@ -1,94 +0,0 @@
/* 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;
}

View File

@ -1,65 +0,0 @@
#!/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