Defect #762 ยป msys.patch
| makefile | ||
|---|---|---|
|
nul := /dev/null
|
||
|
kernel := $(shell uname -s)
|
||
|
machine := $(shell uname -m)
|
||
|
ifeq "$(kernel)" "Linux"
|
||
|
environment := linux.cpp posix.cpp ansi.cpp
|
||
|
machine := $(shell uname -m)
|
||
|
ifeq "$(machine)" "i686"
|
||
|
hostenvironments := amd32linux
|
||
|
else ifeq "$(machine)" "x86_64"
|
||
| ... | ... | |
|
else ifeq "$(kernel)" "Darwin"
|
||
|
environment := darwin.cpp posix.cpp ansi.cpp
|
||
|
machine := $(shell uname -m)
|
||
|
ifeq "$(machine)" "i686"
|
||
|
hostenvironments := amd32darwin
|
||
|
else ifeq "$(machine)" "x86_64"
|
||
| ... | ... | |
|
toolchain := clang
|
||
|
endif
|
||
|
else ifdef MSYSTEM
|
||
|
environment := linux.cpp posix.cpp ansi.cpp
|
||
|
ifeq "$(machine)" "i686"
|
||
|
hostenvironments := win32
|
||
|
else ifeq "$(machine)" "x86_64"
|
||
|
hostenvironments := win64
|
||
|
else
|
||
|
hostenvironments :=
|
||
|
endif
|
||
|
ifndef toolchain
|
||
|
ifeq "$(MSYSTEM)" "CLANG64"
|
||
|
toolchain := clang
|
||
|
else ifeq "$(MSYSTEM)" "CLANGARM64"
|
||
|
toolchain := clang
|
||
|
else
|
||
|
toolchain := gcc
|
||
|
endif
|
||
|
endif
|
||
|
else
|
||
|
environment := $(error unknown posix environment)
|
||
|
endif
|
||
| tools/driver.hpp | ||
|---|---|---|
|
#include "error.hpp"
|
||
|
#include "format.hpp"
|
||
|
#include <cstdio>
|
||
|
#include <cstdlib>
|
||
|
#include <fstream>
|
||
|
#include <iostream>
|
||
| ... | ... | |
|
#if __has_include (<unistd.h>)
|
||
|
#include <unistd.h>
|
||
|
#elif __has_include (<io.h>)
|
||
|
#include <cstdio>
|
||
|
#include <io.h>
|
||
|
#endif
|
||
| ... | ... | |
|
if (!last)
|
||
|
{
|
||
|
#if __has_include (<unistd.h>) || __has_include (<io.h>)
|
||
|
if (isatty (fileno (stdin)) && isatty (fileno (stdout)))
|
||
|
#if __has_include (<unistd.h>)
|
||
|
if (isatty (STDIN_FILENO) && isatty (STDOUT_FILENO))
|
||
|
#elif __has_include (<io.h>)
|
||
|
if (_isatty (_fileno (stdin)) && _isatty (_fileno (stdout)))
|
||
|
#endif
|
||
|
std::cout << name << " Build " __DATE__ " Copyright (C) Florian Negele\n"
|
||
| utilities/linux.cpp | ||
|---|---|---|
|
// You should have received a copy of the GNU General Public License
|
||
|
// along with the ECS. If not, see <https://www.gnu.org/licenses/>.
|
||
|
#define _POSIX_C_SOURCE 200809L
|
||
|
#include "system.hpp"
|
||
|
#include <climits>
|
||
| ... | ... | |
|
const char* sys::get_name ()
|
||
|
{
|
||
|
struct utsname name;
|
||
|
if (uname (&name)) return nullptr;
|
||
|
if (!std::strcmp (name.machine, "i686")) return "amd32linux";
|
||
|
if (!std::strcmp (name.machine, "x86_64")) return "amd64linux";
|
||
|
if (!std::strcmp (name.machine, "armv7l")) return "arma32linux";
|
||
|
if (!std::strcmp (name.machine, "armv8l")) return "arma32linux";
|
||
|
if (!std::strcmp (name.machine, "aarch64")) return "arma64linux";
|
||
|
if (!std::strcmp (name.machine, "mips")) return "mips32linux";
|
||
|
struct utsname name; if (uname (&name)) return nullptr;
|
||
|
if (!std::strcmp (name.sysname, "Linux"))
|
||
|
if (!std::strcmp (name.machine, "i686")) return "amd32linux";
|
||
|
else if (!std::strcmp (name.machine, "x86_64")) return "amd64linux";
|
||
|
else if (!std::strcmp (name.machine, "armv7l")) return "arma32linux";
|
||
|
else if (!std::strcmp (name.machine, "armv8l")) return "arma32linux";
|
||
|
else if (!std::strcmp (name.machine, "aarch64")) return "arma64linux";
|
||
|
else if (!std::strcmp (name.machine, "mips")) return "mips32linux";
|
||
|
else;
|
||
|
else if (!std::strncmp (name.sysname, "MINGW", 5) || !std::strncmp (name.sysname, "MSYS", 4))
|
||
|
if (!std::strcmp (name.machine, "i686")) return "win32";
|
||
|
else if (!std::strcmp (name.machine, "x86_64")) return "win64";
|
||
|
else;
|
||
|
return nullptr;
|
||
|
}
|
||
| utilities/posix.cpp | ||
|---|---|---|
|
// You should have received a copy of the GNU General Public License
|
||
|
// along with the ECS. If not, see <https://www.gnu.org/licenses/>.
|
||
|
#define _POSIX_C_SOURCE 200809L
|
||
|
#include "ansi.hpp"
|
||
|
#include "system.hpp"
|
||
| ... | ... | |
|
namespace sys
|
||
|
{
|
||
|
struct file {int fd = -1; ~file () {if (fd != -1) close (fd);} void read (std::string& string) {if (int size; fd != -1 && !ioctl (fd, FIONREAD, &size)) string.resize (size), ::read (fd, string.data (), size); else string.clear ();}};
|
||
|
struct file {int fd = -1; ~file () {close ();} void close () {if (fd != -1) ::close (fd), fd = -1;} void read (std::string& string) {string.clear (); std::array<char, 128> buffer; while (const auto size = ::read (fd, buffer.data (), buffer.size ())) if (size > 0) string.append (buffer.data (), buffer.data () + size); else break;}};
|
||
|
struct pipe {file in, out; pipe () {::pipe (&in.fd);}};
|
||
|
struct duplicate : file {const int original; explicit duplicate (const int o) : file {dup (o)}, original {o} {} void redirect (const int to) {if (original != -1 && to != -1) dup2 (to, original);}};
|
||
|
struct capture : pipe, duplicate {std::string& string; capture (const int stream, std::string& s) : duplicate {stream}, string {s} {redirect (out.fd);} ~capture () {in.read (string); redirect (fd);}};
|
||
|
struct capture : pipe, duplicate {std::string& string; capture (const int stream, std::string& s) : duplicate {stream}, string {s} {redirect (out.fd);} ~capture () {redirect (fd); out.close (); in.read (string);}};
|
||
|
struct output : capture {static output* current; output (const int stream, std::string& s) : capture {stream, s} {current = this;} ~output () {current = nullptr;} void acquire () {redirect (out.fd);} void release () {redirect (fd);}};
|
||
|
}
|
||
| utilities/windows.cpp | ||
|---|---|---|
|
#include <array>
|
||
|
#include <cstdlib>
|
||
|
#include <io.h>
|
||
|
#include <iostream>
|
||
|
#include <windows.h>
|
||
| ... | ... | |
|
const char* sys::get_name ()
|
||
|
{
|
||
|
SYSTEM_INFO info;
|
||
|
GetNativeSystemInfo (&info);
|
||
|
SYSTEM_INFO info; GetNativeSystemInfo (&info);
|
||
|
if (info.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_INTEL) return "win32";
|
||
|
if (info.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64) return "win64";
|
||
|
return nullptr;
|
||
| ... | ... | |
|
bool sys::is_terminal (const std::ios& stream)
|
||
|
{
|
||
|
return &stream == &std::cin && _isatty (_fileno (stdin)) || &stream == &std::cout && _isatty (_fileno (stdout)) || &stream == &std::cerr && _isatty (_fileno (stderr));
|
||
|
const auto nStdHandle = &stream == &std::cin ? STD_INPUT_HANDLE : &stream == &std::cout ? STD_OUTPUT_HANDLE : &stream == &std::cerr ? STD_ERROR_HANDLE : 0;
|
||
|
return nStdHandle && GetFileType (GetStdHandle (nStdHandle)) == FILE_TYPE_CHAR;
|
||
|
}
|
||
|
std::ostream& sys::operator << (std::ostream& stream, const color color)
|
||
|
{
|
||
|
if (!is_terminal (stream)) return stream;
|
||
|
const auto nStdHandle = &stream == &std::cout ? STD_OUTPUT_HANDLE : &stream == &std::cerr ? STD_ERROR_HANDLE : 0; if (!nStdHandle) return stream;
|
||
|
const auto hConsoleOutput = GetStdHandle (nStdHandle); if (hConsoleOutput == NULL || hConsoleOutput == INVALID_HANDLE_VALUE) return stream;
|
||
|
const auto hConsoleOutput = GetStdHandle (nStdHandle); if (GetFileType (hConsoleOutput) != FILE_TYPE_CHAR) return stream;
|
||
|
enum Color : WORD {Normal, Black = FOREGROUND_INTENSITY, Red = FOREGROUND_RED | FOREGROUND_INTENSITY, Blue = FOREGROUND_BLUE | FOREGROUND_INTENSITY, Green = FOREGROUND_GREEN | FOREGROUND_INTENSITY, Cyan = Blue | Green, Magenta = Red | Blue, Yellow = Red | Green, White = Red | Green | Blue, Invalid = 0xffff};
|
||
|
static constexpr std::array colors {Black, Blue, Cyan, Green, Magenta, Normal, Red, White, Yellow};
|
||
|
static WORD attributes[] {Invalid, Invalid}; auto& attribute = attributes[nStdHandle - STD_ERROR_HANDLE];
|
||