add our own endianness check because there is apparently no proper way to check for that at compile time
parent
975cdd309d
commit
1dcf37c0fc
|
@ -4,5 +4,9 @@
|
||||||
/dependencies/*
|
/dependencies/*
|
||||||
!/dependencies/.placeholder
|
!/dependencies/.placeholder
|
||||||
|
|
||||||
|
# ignore endianness check
|
||||||
|
/.endianness
|
||||||
|
/resources/check_endianness
|
||||||
|
|
||||||
# ignore nano's temp files
|
# ignore nano's temp files
|
||||||
*.swp
|
*.swp
|
||||||
|
|
|
@ -0,0 +1,66 @@
|
||||||
|
// Copyright <year>, FOSS-VG Developers and Contributers
|
||||||
|
//
|
||||||
|
// This program is free software: you can redistribute it and/or modify it
|
||||||
|
// under the terms of the GNU Affero General Public License as published
|
||||||
|
// by the Free Software Foundation, version 3.
|
||||||
|
//
|
||||||
|
// This program is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied
|
||||||
|
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
// See the GNU Affero General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU Affero General Public License
|
||||||
|
// version 3 along with this program.
|
||||||
|
// If not, see https://www.gnu.org/licenses/agpl-3.0.en.html
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
#include <cstdint>
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
uint32_t* testInteger = new uint32_t;
|
||||||
|
*testInteger = 0x04030201;
|
||||||
|
auto data = reinterpret_cast<std::uint8_t*>(testInteger);
|
||||||
|
|
||||||
|
if (
|
||||||
|
*data == 0x01 &&
|
||||||
|
*(data+1)==0x02 &&
|
||||||
|
*(data+2)==0x03 &&
|
||||||
|
*(data+3)==0x04
|
||||||
|
) {
|
||||||
|
std::cerr << "Little Endian" << std::endl;
|
||||||
|
std::cout << "#define FOSSVG_LITTLE_ENDIAN" << std::endl;
|
||||||
|
} else if (
|
||||||
|
*data == 0x04 &&
|
||||||
|
*(data+1)==0x03 &&
|
||||||
|
*(data+2)==0x02 &&
|
||||||
|
*(data+3)==0x01
|
||||||
|
) {
|
||||||
|
std::cerr << "Big Endian" << std::endl;
|
||||||
|
std::cout << "#define FOSSVG_BIG_ENDIAN" << std::endl;
|
||||||
|
} else if (
|
||||||
|
*data == 0x03 &&
|
||||||
|
*(data+1)==0x04 &&
|
||||||
|
*(data+2)==0x01 &&
|
||||||
|
*(data+3)==0x02
|
||||||
|
) {
|
||||||
|
std::cerr << "PDP Endian (Little Word)" << std::endl;
|
||||||
|
std::cout << "#define FOSSVG_ENDIAN_LITTLE_WORD /* PDP-11-style byte-swapped words */" << std::endl;
|
||||||
|
} else if (
|
||||||
|
*data == 0x02 &&
|
||||||
|
*(data+1)==0x01 &&
|
||||||
|
*(data+2)==0x04 &&
|
||||||
|
*(data+3)==0x03
|
||||||
|
) {
|
||||||
|
std::cerr << "Honeywell Endian (Big Word)" << std::endl;
|
||||||
|
std::cout << "#define FOSSVG_ENDIAN_BIG_WORD /* Honeywell-316-style byte-swapped words */" << std::endl;
|
||||||
|
|
||||||
|
} else {
|
||||||
|
std::cerr << "Unknown Endianness" << std::endl;
|
||||||
|
std::cout << "#define FOSSVG_ENDIAN_UNKNOWN" << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
delete data;
|
||||||
|
|
||||||
|
std::cerr << "WARNING: This test may be unreliable. If you encounter issues, check the endianness of your machine and set it manually. Bi-endianness is not supported." << std::endl;
|
||||||
|
return 0;
|
||||||
|
}
|
|
@ -23,6 +23,20 @@ if [ -z "$CXXFLAGS" ]; then
|
||||||
fi
|
fi
|
||||||
CXX_WITH_FLAGS="$CXX $CXXFLAGS"
|
CXX_WITH_FLAGS="$CXX $CXXFLAGS"
|
||||||
|
|
||||||
|
# if unknown, figure out endianness
|
||||||
|
if [ -f .endianness ]; then
|
||||||
|
echo "Endianness known:"
|
||||||
|
cat .endianness
|
||||||
|
else
|
||||||
|
echo "Endianness unknown."
|
||||||
|
if [ ! -x resources/check_endianness ]; then
|
||||||
|
echo "Building endianness test."
|
||||||
|
$CXX_WITH_FLAGS -o resources/check_endianness resources/check_endianness.cpp
|
||||||
|
fi
|
||||||
|
echo "Probing endianness:"
|
||||||
|
resources/check_endianness > .endianness
|
||||||
|
fi
|
||||||
|
|
||||||
# `.cpp` files in src/lib will be automatically picked up and compiled into
|
# `.cpp` files in src/lib will be automatically picked up and compiled into
|
||||||
# dynamically linked libraries.
|
# dynamically linked libraries.
|
||||||
echo "Building libs..."
|
echo "Building libs..."
|
||||||
|
|
|
@ -16,6 +16,8 @@
|
||||||
# If not, see https://www.gnu.org/licenses/agpl-3.0.en.html
|
# If not, see https://www.gnu.org/licenses/agpl-3.0.en.html
|
||||||
|
|
||||||
rm -rv ./bin
|
rm -rv ./bin
|
||||||
|
rm -vf .endianness
|
||||||
|
rm -vf resources/check_endianness
|
||||||
mkdir -v ./bin
|
mkdir -v ./bin
|
||||||
set -v
|
set -v
|
||||||
echo -n "" > ./bin/.placeholder
|
echo -n "" > ./bin/.placeholder
|
||||||
|
|
Loading…
Reference in New Issue