avrdude: conf-generate: Fix line endings - always generate LF endings

avrdude configuration embedding tool was generating platform
specific line endings in avrdude-slic3r.conf.h
This commit is contained in:
Vojtech Kral 2019-08-19 10:35:18 +02:00
parent 745182988d
commit baaf66d138
2 changed files with 22 additions and 16 deletions

View File

@ -86,7 +86,7 @@ add_executable(avrdude-conf-gen conf-generate.cpp)
add_custom_command( add_custom_command(
DEPENDS avrdude-conf-gen ${CMAKE_CURRENT_SOURCE_DIR}/avrdude-slic3r.conf DEPENDS avrdude-conf-gen ${CMAKE_CURRENT_SOURCE_DIR}/avrdude-slic3r.conf
OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/avrdude-slic3r.conf.h OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/avrdude-slic3r.conf.h
COMMAND $<TARGET_FILE:avrdude-conf-gen> avrdude-slic3r.conf avrdude_slic3r_conf > avrdude-slic3r.conf.h COMMAND $<TARGET_FILE:avrdude-conf-gen> avrdude-slic3r.conf avrdude_slic3r_conf avrdude-slic3r.conf.h
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
) )

View File

@ -6,36 +6,42 @@
int main(int argc, char const *argv[]) int main(int argc, char const *argv[])
{ {
if (argc != 3) { if (argc != 4) {
std::cerr << "Usage: " << argv[0] << " <file> <symbol name>" << std::endl; std::cerr << "Usage: " << argv[0] << " <file> <symbol name> <output file>" << std::endl;
return -1; return -1;
} }
const char* filename = argv[1]; const char* filename_in = argv[1];
const char* symbol = argv[2]; const char* symbol = argv[2];
const char* filename_out = argv[3];
size_t size = 0; size_t size = 0;
std::fstream file(filename); std::fstream file(filename_in, std::ios::in | std::ios::binary);
if (!file.good()) { if (!file.good()) {
std::cerr << "Cannot read file: " << filename << std::endl; std::cerr << "Cannot read file: " << filename_in << std::endl;
} }
std::cout << "/* WARN: This file is auto-generated from `" << filename << "` */" << std::endl; std::fstream output(filename_out, std::ios::out | std::ios::trunc | std::ios::binary);
std::cout << "const unsigned char " << symbol << "[] = {"; if (!output.good()) {
std::cerr << "Cannot open output file: " << filename_out << std::endl;
}
output << "/* WARN: This file is auto-generated from `" << filename_in << "` */" << std::endl;
output << "const unsigned char " << symbol << "[] = {";
char c; char c;
std::cout << std::hex; output << std::hex;
std::cout.fill('0'); output.fill('0');
for (file.get(c); !file.eof(); size++, file.get(c)) { for (file.get(c); !file.eof(); size++, file.get(c)) {
if (size % 12 == 0) { std::cout << "\n "; } if (size % 12 == 0) { output << "\n "; }
std::cout << "0x" << std::setw(2) << (unsigned)c << ", "; output << "0x" << std::setw(2) << (unsigned)c << ", ";
} }
std::cout << "\n 0, 0\n};\n"; output << "\n 0, 0\n};\n";
std::cout << std::dec; output << std::dec;
std::cout << "const size_t " << symbol << "_size = " << size << ";" << std::endl; output << "const size_t " << symbol << "_size = " << size << ";" << std::endl;
std::cout << "const size_t " << symbol << "_size_yy = " << size + 2 << ";" << std::endl; output << "const size_t " << symbol << "_size_yy = " << size + 2 << ";" << std::endl;
return 0; return 0;
} }