Skip to content

Commit d97b6bb

Browse files
ccxviiartifex-tor
authored andcommitted
Tweak hexdumped data to increase build portability.
Follow bin2coff layout for hexdumped data instead of trying to emulate the objcopy layout (which seems to break for the android tools). Only use the basename of the resource in hexdump / bin2coff. Ifdef on HAVE_OBJCOPY instead of _WIN32.
1 parent 08e9dc6 commit d97b6bb

File tree

7 files changed

+317
-308
lines changed

7 files changed

+317
-308
lines changed

Makefile

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,11 @@ $(OUT)/platform/x11/curl/%.o : platform/x11/%.c
9292
$(OUT)/platform/gl/%.o : platform/gl/%.c
9393
$(CC_CMD) -Wall $(GLUT_CFLAGS)
9494

95+
ifeq ($(HAVE_OBJCOPY),yes)
96+
$(OUT)/source/fitz/noto.o : source/fitz/noto.c
97+
$(CC_CMD) -Wall -Wdeclaration-after-statement -DHAVE_OBJCOPY $(THIRD_CFLAGS)
98+
endif
99+
95100
$(OUT)/source/%.o : source/%.c
96101
$(CC_CMD) -Wall -Wdeclaration-after-statement $(THIRD_CFLAGS)
97102

@@ -144,7 +149,7 @@ generated/%.otf.c : %.otf $(HEXDUMP_EXE) ; $(QUIET_GEN) $(MKTGTDIR) ; $(HEXDUMP_
144149
generated/%.ttf.c : %.ttf $(HEXDUMP_EXE) ; $(QUIET_GEN) $(MKTGTDIR) ; $(HEXDUMP_EXE) -s $@ $<
145150
generated/%.ttc.c : %.ttc $(HEXDUMP_EXE) ; $(QUIET_GEN) $(MKTGTDIR) ; $(HEXDUMP_EXE) -s $@ $<
146151

147-
ifeq ($(OS),Linux)
152+
ifeq ($(HAVE_OBJCOPY),yes)
148153
MUPDF_OBJ += $(FONT_BIN:%=$(OUT)/%.o)
149154
$(OUT)/%.cff.o : %.cff ; $(OBJCOPY_CMD)
150155
$(OUT)/%.otf.o : %.otf ; $(OBJCOPY_CMD)

Makerules

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ else ifeq ($(OS),MACOS)
8686
RANLIB = xcrun ranlib
8787

8888
else ifeq ($(OS),Linux)
89+
HAVE_OBJCOPY := yes
90+
8991
ifeq ($(shell pkg-config --exists freetype2 && echo yes),yes)
9092
SYS_FREETYPE_CFLAGS := $(shell pkg-config --cflags freetype2)
9193
SYS_FREETYPE_LIBS := $(shell pkg-config --libs freetype2)

platform/win32/bin2coff.rules

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<CustomBuildRule
88
Name="bin2coff (ttf)"
99
DisplayName="bin2coff (ttf)"
10-
CommandLine="Release\bin2coff.exe $(InputPath) $(IntDir)\$(InputName)_ttf.obj _binary_resources_fonts_$(InputName)_ttf $(PlatformName)"
10+
CommandLine="Release\bin2coff.exe $(InputPath) $(IntDir)\$(InputName)_ttf.obj _binary_$(InputName)_ttf $(PlatformName)"
1111
Outputs="$(IntDir)\$(InputName)_ttf.obj"
1212
FileExtensions="*.ttf"
1313
ExecutionDescription="Embedding TTF"
@@ -18,7 +18,7 @@
1818
<CustomBuildRule
1919
Name="bin2coff (otf)"
2020
DisplayName="bin2coff (otf)"
21-
CommandLine="Release\bin2coff.exe $(InputPath) $(IntDir)\$(InputName)_otf.obj _binary_resources_fonts_$(InputName)_otf $(PlatformName)"
21+
CommandLine="Release\bin2coff.exe $(InputPath) $(IntDir)\$(InputName)_otf.obj _binary_$(InputName)_otf $(PlatformName)"
2222
Outputs="$(IntDir)\$(InputName)_otf.obj"
2323
FileExtensions="*.otf"
2424
ExecutionDescription="Embedding OTF"
@@ -29,7 +29,7 @@
2929
<CustomBuildRule
3030
Name="bin2coff (cff)"
3131
DisplayName="bin2coff (cff)"
32-
CommandLine="Release\bin2coff.exe $(InputPath) $(IntDir)\$(InputName)_cff.obj _binary_resources_fonts_$(InputName)_cff $(PlatformName)"
32+
CommandLine="Release\bin2coff.exe $(InputPath) $(IntDir)\$(InputName)_cff.obj _binary_$(InputName)_cff $(PlatformName)"
3333
Outputs="$(IntDir)\$(InputName)_cff.obj"
3434
FileExtensions="*.cff"
3535
ExecutionDescription="Embedding CFF"
@@ -40,7 +40,7 @@
4040
<CustomBuildRule
4141
Name="bin2coff (ttc)"
4242
DisplayName="bin2coff (ttc)"
43-
CommandLine="Release\bin2coff.exe $(InputPath) $(IntDir)\$(InputName)_ttc.obj _binary_resources_fonts_$(InputName)_ttc $(PlatformName)"
43+
CommandLine="Release\bin2coff.exe $(InputPath) $(IntDir)\$(InputName)_ttc.obj _binary_$(InputName)_ttc $(PlatformName)"
4444
Outputs="$(IntDir)\$(InputName)_ttc.obj"
4545
FileExtensions="*.ttc"
4646
ExecutionDescription="Embedding TTC"

scripts/fontdump.nmake

Lines changed: 288 additions & 288 deletions
Large diffs are not rendered by default.

scripts/hexdump.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ main(int argc, char **argv)
3737
{
3838
FILE *fo;
3939
FILE *fi;
40-
char filename[256];
40+
char name[256];
4141
char *basename;
4242
char *p;
4343
int i, optind, size;
@@ -81,16 +81,16 @@ main(int argc, char **argv)
8181
else
8282
basename = argv[i];
8383

84-
if (strlen(basename) >= sizeof(filename))
84+
if (strlen(basename) >= sizeof(name))
8585
{
8686
fclose(fi);
8787
fclose(fo);
8888
fprintf(stderr, "hexdump: filename '%s' too long\n", basename);
8989
return 1;
9090
}
9191

92-
strcpy(filename, argv[i]);
93-
for (p = filename; *p; ++p)
92+
strcpy(name, basename);
93+
for (p = name; *p; ++p)
9494
{
9595
if (*p == '/' || *p == '.' || *p == '\\' || *p == '-')
9696
*p = '_';
@@ -100,11 +100,11 @@ main(int argc, char **argv)
100100
size = ftell(fi);
101101
fseek(fi, 0, SEEK_SET);
102102

103-
fprintf(fo, "const unsigned char _binary_%s_start[%d] =", filename, size);
103+
fprintf(fo, "const unsigned char _binary_%s[%d] =", name, size);
104104
fprintf(fo, string ? "\n" : " {\n");
105105
hexdump(fo, fi);
106106
fprintf(fo, string ? ";\n" : "};\n");
107-
fprintf(fo, "const unsigned char _binary_%s_end;\n", filename);
107+
fprintf(fo, "unsigned int _binary_%s_size = %d;\n", name, size);
108108

109109
fclose(fi);
110110
}

scripts/runfontdump.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ done
2222

2323
for FILE in $FONTS
2424
do
25-
NAME=$(echo _binary_$FILE | tr '/.-' '___')
25+
NAME=$(echo _binary_$(basename $FILE) | tr '/.-' '___')
2626
OBJ=$(echo generated/$FILE.obj)
2727
OBJ64=$(echo generated/$FILE.x64.obj)
2828
DIR=$(dirname $OBJ)

source/fitz/noto.c

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,20 +45,22 @@
4545
#define TOFU_EMOJI
4646
#endif
4747

48-
#ifdef _WIN32
48+
#ifdef HAVE_OBJCOPY
4949
#define RETURN(FORGE,NAME) \
5050
do { \
51-
extern unsigned char _binary_resources_fonts_##NAME[]; \
52-
extern unsigned int _binary_resources_fonts_##NAME##_size; \
53-
return *size = _binary_resources_fonts_##NAME##_size, _binary_resources_fonts_##NAME; \
51+
extern unsigned char _binary_resources_fonts_##FORGE##_##NAME##_start; \
52+
extern unsigned char _binary_resources_fonts_##FORGE##_##NAME##_end; \
53+
return *size = \
54+
&_binary_resources_fonts_##FORGE##_##NAME##_end - \
55+
&_binary_resources_fonts_##FORGE##_##NAME##_start, \
56+
&_binary_resources_fonts_##FORGE##_##NAME##_start; \
5457
} while (0)
5558
#else
5659
#define RETURN(FORGE,NAME) \
5760
do { \
58-
extern const unsigned char _binary_resources_fonts_##FORGE##_##NAME##_start[]; \
59-
extern const unsigned char _binary_resources_fonts_##FORGE##_##NAME##_end; \
60-
return *size = &_binary_resources_fonts_##FORGE##_##NAME##_end - _binary_resources_fonts_##FORGE##_##NAME##_start, \
61-
_binary_resources_fonts_##FORGE##_##NAME##_start; \
61+
extern unsigned char _binary_##NAME[]; \
62+
extern unsigned int _binary_##NAME##_size; \
63+
return *size = _binary_##NAME##_size, _binary_##NAME; \
6264
} while (0)
6365
#endif
6466

0 commit comments

Comments
 (0)