Skip to content

Commit

Permalink
HackStudio: Check for make command on startup
Browse files Browse the repository at this point in the history
  • Loading branch information
deoxxa authored and awesomekling committed Dec 28, 2019
1 parent fa8cec6 commit f5412f1
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions DevTools/HackStudio/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include <LibGUI/GWidget.h>
#include <LibGUI/GWindow.h>
#include <stdio.h>
#include <sys/wait.h>
#include <unistd.h>

NonnullRefPtrVector<EditorWrapper> g_all_editor_wrappers;
Expand Down Expand Up @@ -91,6 +92,7 @@ Editor& current_editor()
static void build(TerminalWrapper&);
static void run(TerminalWrapper&);
void open_file(const String&);
bool make_is_available();

int main(int argc, char** argv)
{
Expand All @@ -109,6 +111,9 @@ int main(int argc, char** argv)
widget->set_layout(make<GBoxLayout>(Orientation::Vertical));
widget->layout()->set_spacing(0);

if (!make_is_available())
GMessageBox::show("The 'make' command is not available. You probably want to install the binutils, gcc, and make ports from the root of the Serenity repository.", "Error", GMessageBox::Type::Error, GMessageBox::InputType::OK, g_window);

if (chdir("/home/anon/little") < 0) {
perror("chdir");
return 1;
Expand Down Expand Up @@ -578,3 +583,21 @@ void open_file(const String& filename)

current_editor().set_focus(true);
}

bool make_is_available()
{
auto pid = fork();
if (pid < 0)
return false;

if (!pid) {
int rc = execlp("make", "make", "--version", nullptr);
ASSERT(rc < 0);
perror("execl");
exit(127);
}

int wstatus;
waitpid(pid, &wstatus, 0);
return WEXITSTATUS(wstatus) == 0;
}

0 comments on commit f5412f1

Please sign in to comment.