私には、次のターゲットがあります。これは、を使用してテキスト/HTML リソースを配列makefile
に「コンパイル」します。unsigned char
xxd -i
結果を匿名の名前空間とヘッダー ガードでラップし、翻訳単位内および翻訳単位間の複数包含の安全性を確保します。
templates.h:
@echo "#ifndef TEMPLATES_H" > templates.h
@echo "#define TEMPLATES_H" >> templates.h
@echo "// Auto-generated file! Do not modify!" >> templates.h
@echo "// NB: arrays are not null-terminated" >> templates.h
@echo "// (anonymous namespace used to force internal linkage)" >> templates.h
@echo "namespace {" >> templates.h
@echo "namespace templates {" >> templates.h
@cd templates;\
for i in * ;\
do \
echo "Compiling $$i...";\
xxd -i $$i >> ../templates.h;\
done;\
cd ..
@echo "}" >> templates.h
@echo "}" >> templates.h
@echo "#endif" >> templates.h
そのようなリソースが 1 つしかない場合、出力は次のようになります(実際のコンテンツは編集されています)。
#ifndef TEMPLATES_H
#define TEMPLATES_H
// Auto-generated file! Do not modify!
// NB: arrays are not null-terminated
// (anonymous namespace used to force internal linkage)
namespace {
namespace templates {
unsigned char alert_email_finished_events_html[] = {
0x3c, 0x74, 0x61, 0x62, 0x6c, 0x0d, 0x0a
};
unsigned int alert_email_finished_events_html_len = 7;
}
}
#endif
__attribute__ ((unused))
これらの文字配列にGCC をプログラムで適用する最良の方法は何でしょうか? 特定の TU で最終的に使用しないリソースに関する GCC の警告は必要ありませんが、「未使用の変数」の警告を完全にオフにしたくありません。