Skip to content

Commit

Permalink
setup for non win32 platforms
Browse files Browse the repository at this point in the history
Signed-off-by: falkTX <[email protected]>
  • Loading branch information
falkTX committed Oct 9, 2023
1 parent 408c4ba commit 37de1d2
Show file tree
Hide file tree
Showing 9 changed files with 189 additions and 74 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
/build/
/build-screenshot/
/build-ui/
*.dll
*.exe
*.o
*.tar.gz
*.zip
qrc_*.hpp
ui_*.hpp
/systray/mod-app
/utils/win64-plugins.iss
/utils/win64-version.iss
44 changes: 36 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ TARGETS = \
build/jack/mod-host$(SO_EXT) \
build/jack/mod-midi-broadcaster$(SO_EXT) \
build/jack/mod-midi-merger$(SO_EXT) \
build/lib/libmod_utils$(SO_EXT) \
build-ui/lib/libmod_utils$(SO_EXT) \
build/default.pedalboard \
build/html \
build/mod \
Expand Down Expand Up @@ -87,6 +87,9 @@ else
TARGETS += build/libjack.so.0
TARGETS += build/libjackserver.so.0
TARGETS += build/jack/jack_alsa.so
TARGETS += build/jack/jack_alsarawmidi.so
TARGETS += build/jack/jack_portaudio.so
TARGETS += build/mod-app
endif

# ---------------------------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -203,6 +206,9 @@ all: $(TARGETS)
clean:
$(MAKE) clean -C mod-host
$(MAKE) clean -C mod-ui/utils
$(MAKE) clean -C systray
rm -rf mod-midi-merger/build
rm -rf build

plugins: $(PLUGINS)

Expand Down Expand Up @@ -296,8 +302,8 @@ build/jack/mod-midi-merger$(SO_EXT): mod-midi-merger/build/mod-midi-merger$(SO_E
@mkdir -p build/jack
ln -sf $(abspath $<) $@

build/lib/libmod_utils$(SO_EXT): mod-ui/utils/libmod_utils.so
@mkdir -p build/lib
build-ui/lib/libmod_utils$(SO_EXT): mod-ui/utils/libmod_utils.so
@mkdir -p build-ui/lib
ln -sf $(abspath $<) $@

build/mod-app$(APP_EXT): systray/mod-app$(APP_EXT)
Expand Down Expand Up @@ -330,18 +336,41 @@ build/jack/jack-session.conf: utils/jack-session.conf
@mkdir -p build/jack
ln -sf $(abspath $<) $@

build/mod-screenshot$(APP_EXT): utils/mod-screenshot.py $(BOOTSTRAP_FILES)
# ---------------------------------------------------------------------------------------------------------------------

build/mod-screenshot$(APP_EXT): build-screenshot/mod-screenshot$(APP_EXT)
ln -sf $(abspath $<) $@

mod-screenshot$(APP_EXT): utils/mod-screenshot.py $(BOOTSTRAP_FILES)
./utils/run.sh $(PAWPAW_TARGET) python3 utils/mod-screenshot.py build_exe
touch $@

build/mod-ui$(APP_EXT): utils/mod-ui.py utils/mod-ui-wrapper.py $(BOOTSTRAP_FILES)
rm -f build/libpython3.8.dll
# ---------------------------------------------------------------------------------------------------------------------

build/mod-ui$(APP_EXT): build-ui/mod-ui$(APP_EXT)
ln -sf $(abspath $<) $@

build/lib: build-ui/lib
ln -sf $(abspath $<) $@

build-ui/lib: build-ui/mod-ui$(APP_EXT)
touch $@

build-ui/mod-ui$(APP_EXT): utils/mod-ui.py utils/mod-ui-wrapper.py $(BOOTSTRAP_FILES)
# rm -f build/libpython3.8.dll
./utils/run.sh $(PAWPAW_TARGET) python3 utils/mod-ui.py build_exe
touch $@

mod-ui/utils/libmod_utils.so: $(BOOTSTRAP_FILES) mod-ui/utils/utils.h mod-ui/utils/utils_jack.cpp mod-ui/utils/utils_lilv.cpp
./utils/run.sh $(PAWPAW_TARGET) $(MAKE) -C mod-ui/utils

# ---------------------------------------------------------------------------------------------------------------------

mod-host/mod-host.so: $(BOOTSTRAP_FILES)
./utils/run.sh $(PAWPAW_TARGET) $(MAKE) SKIP_READLINE=1 SKIP_FFTW335=1 -C mod-host

# ---------------------------------------------------------------------------------------------------------------------

mod-midi-merger/build/mod-midi-broadcaster$(SO_EXT): mod-midi-merger/build/mod-midi-merger-standalone$(APP_EXT)
touch $@

Expand All @@ -354,8 +383,7 @@ mod-midi-merger/build/mod-midi-merger-standalone$(APP_EXT): mod-midi-merger/buil
mod-midi-merger/build/Makefile: $(BOOTSTRAP_FILES)
./utils/run.sh $(PAWPAW_TARGET) cmake -S mod-midi-merger -B mod-midi-merger/build

mod-ui/utils/libmod_utils.so: $(BOOTSTRAP_FILES) mod-ui/utils/utils.h mod-ui/utils/utils_jack.cpp mod-ui/utils/utils_lilv.cpp
./utils/run.sh $(PAWPAW_TARGET) $(MAKE) -C mod-ui/utils
# ---------------------------------------------------------------------------------------------------------------------

systray/mod-app$(APP_EXT): systray/main.cpp systray/mod-app.hpp
./utils/run.sh $(PAWPAW_TARGET) $(MAKE) -C systray
Expand Down
2 changes: 1 addition & 1 deletion PawPaw
7 changes: 5 additions & 2 deletions systray/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,17 @@ TARGET = mod-app.app/Contents/MacOS/mod-app
else ifeq ($(WINDOWS),true)
TARGET = mod-app.exe
EXTRAS = Qt5Core.dll Qt5Gui.dll Qt5Svg.dll Qt5Widgets.dll
CXXFLAGS += $(shell pkg-config --cflags portaudio-2.0)
LDFLAGS += $(shell pkg-config --libs portaudio-2.0)
LDFLAGS += -Wl,-subsystem,windows
WINDRES = $(subst gcc,windres,$(CC))
else
TARGET = mod-app
endif

ifneq ($(MACOS),true)
CXXFLAGS += $(shell pkg-config --cflags portaudio-2.0)
LDFLAGS += $(shell pkg-config --libs portaudio-2.0)
endif

ifeq ($(shell pkg-config --exists Qt5Core Qt5Gui Qt5Svg Qt5Widgets && echo true)$(WINDOWS),truefalse)
QT5_HOSTBINS = $(shell pkg-config --variable=host_bins Qt5Core)
QT5_FLAGS = $(shell pkg-config --cflags Qt5Core Qt5Gui Qt5Svg Qt5Widgets)
Expand Down
106 changes: 80 additions & 26 deletions systray/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
static const WCHAR* user_files_dir = nullptr;
#else
#include <dlfcn.h>
#include <signal.h>
#include <sys/stat.h>
#include <unistd.h>
static const char* user_files_dir = nullptr;
#endif

#if defined(__APPLE__)
Expand All @@ -24,12 +28,14 @@ static const WCHAR* user_files_dir = nullptr;

QString getUserFilesDir()
{
#ifdef _WIN32
if (user_files_dir != nullptr)
{
#ifdef _WIN32
return QString::fromWCharArray(user_files_dir);
#else
// TODO
#endif
#else
return QString::fromUtf8(user_files_dir);
#endif
}

return {};
}
Expand Down Expand Up @@ -65,6 +71,14 @@ void writeMidiChannelsToProfile(int pedalboard, int snapshot)
jsonFile.write(QJsonDocument(jsonObj).toJson());
}

#ifndef _WIN32
static void signal(int)
{
qApp->setQuitOnLastWindowClosed(true);
qApp->quit();
}
#endif

int main(int argc, char* argv[])
{
// TODO set branding here
Expand All @@ -80,35 +94,75 @@ int main(int argc, char* argv[])
}

#ifdef _WIN32
WCHAR wc[MAX_PATH + 256] = {};
GetModuleFileNameW(GetModuleHandleW(nullptr), wc, sizeof(wc)/sizeof(wc[0]));
WCHAR path[MAX_PATH + 256] = {};

GetModuleFileNameW(GetModuleHandleW(nullptr), path, sizeof(path)/sizeof(path[0]));

if (wchar_t* const wcc = wcsrchr(wc, '\\'))
if (wchar_t* const wcc = wcsrchr(path, '\\'))
*wcc = 0;

const QString cwd(QString::fromWCharArray(wc));
SetCurrentDirectoryW(wc);
const QString cwd(QString::fromWCharArray(path));
SetCurrentDirectoryW(path);

WCHAR path[(MAX_PATH + 256) * 2] = {};
std::wcscat(path, wc);
std::wcscat(path, L"\\data\\lv2;");
std::wcscat(path, wc);
std::wcscat(path, L"\\plugins");
SetEnvironmentVariableW(L"LV2_PATH", path);
WCHAR lv2path[(MAX_PATH + 256) * 2] = {};
std::wcscat(lv2path, path);
std::wcscat(lv2path, L"\\plugins;");

if (SHGetSpecialFolderPathW(nullptr, path, CSIDL_MYDOCUMENTS, FALSE))
{
std::wcscat(path, L"\\MOD App");
_wmkdir(path);
SetEnvironmentVariableW(L"MOD_DATA_DIR", path);
SHGetSpecialFolderPathW(nullptr, path, CSIDL_MYDOCUMENTS, FALSE);

std::wcscat(path, L"\\user-files");
_wmkdir(path);
user_files_dir = path;
}
std::wcscat(path, L"\\MOD App");
_wmkdir(path);
SetEnvironmentVariableW(L"MOD_DATA_DIR", path);

std::wcscat(lv2path, path);
std::wcscat(lv2path, L"\\data\\lv2;");
SetEnvironmentVariableW(L"LV2_PATH", lv2path);

std::wcscat(path, L"\\user-files");
_wmkdir(path);
user_files_dir = path;
#else
// TODO
const QString cwd;
char path[PATH_MAX + 256] = {};

Dl_info info = {};
dladdr((void*)main, &info);
std::strncpy(path, info.dli_fname, sizeof(path));

if (char* const c = strrchr(path, '/'))
*c = 0;

const QString cwd(QString::fromUtf8(path));
chdir(path);

const size_t pathlen = std::strlen(path);
std::memcpy(path + pathlen, "/jack", 6);
setenv("JACK_DRIVER_DIR", path, 1);

char lv2path[(PATH_MAX + 256) * 2] = {};
std::strncat(lv2path, path, pathlen);
std::strcat(lv2path, "/plugins:");

// TODO fetch user docs dir
std::memcpy(path + pathlen, "/data", 6);

// std::strcat(path, "/MOD App");
mkdir(path, 0777);
setenv("MOD_DATA_DIR", path, 1);

std::strcat(lv2path, path);
std::strcat(lv2path, "/lv2");
setenv("LV2_PATH", lv2path, 1);

std::strcat(path, "/user-files");
mkdir(path, 0777);
user_files_dir = path;

struct sigaction sig = {};
sig.sa_handler = signal;
sig.sa_flags = SA_RESTART;
sigemptyset(&sig.sa_mask);
sigaction(SIGTERM, &sig, nullptr);
sigaction(SIGINT, &sig, nullptr);
#endif

app.setQuitOnLastWindowClosed(false);
Expand Down
Loading

0 comments on commit 37de1d2

Please sign in to comment.