Skip to content

Commit

Permalink
Avoid platform sed differences
Browse files Browse the repository at this point in the history
  • Loading branch information
timangus committed Sep 8, 2020
1 parent d92c749 commit 1166b28
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 5 deletions.
14 changes: 9 additions & 5 deletions Makefile
Expand Up @@ -264,6 +264,7 @@ VORBISDIR=$(MOUNT_DIR)/libvorbis-1.3.6
OPUSDIR=$(MOUNT_DIR)/opus-1.2.1
OPUSFILEDIR=$(MOUNT_DIR)/opusfile-0.9
ZDIR=$(MOUNT_DIR)/zlib
TOOLSDIR=$(MOUNT_DIR)/tools
Q3ASMDIR=$(MOUNT_DIR)/tools/asm
LBURGDIR=$(MOUNT_DIR)/tools/lcc/lburg
Q3CPPDIR=$(MOUNT_DIR)/tools/lcc/cpp
Expand Down Expand Up @@ -1222,9 +1223,7 @@ endef
define DO_REF_STR
$(echo_cmd) "REF_STR $<"
$(Q)rm -f $@
$(Q)echo "const char *fallbackShader_$(notdir $(basename $<)) =" >> $@
$(Q)cat $< | sed -e 's/^\(.*\)$$/\"\1\\n\"/' >> $@
$(Q)echo ";" >> $@
$(Q)$(STRINGIFY) $< $@
endef

define DO_BOT_CC
Expand Down Expand Up @@ -1490,6 +1489,7 @@ Q3RCC = $(B)/tools/q3rcc$(TOOLS_BINEXT)
Q3CPP = $(B)/tools/q3cpp$(TOOLS_BINEXT)
Q3LCC = $(B)/tools/q3lcc$(TOOLS_BINEXT)
Q3ASM = $(B)/tools/q3asm$(TOOLS_BINEXT)
STRINGIFY = $(B)/tools/stringify$(TOOLS_BINEXT)

LBURGOBJ= \
$(B)/tools/lburg/lburg.o \
Expand Down Expand Up @@ -1583,6 +1583,10 @@ $(Q3LCC): $(Q3LCCOBJ) $(Q3RCC) $(Q3CPP)
$(echo_cmd) "LD $@"
$(Q)$(TOOLS_CC) $(TOOLS_CFLAGS) $(TOOLS_LDFLAGS) -o $@ $(Q3LCCOBJ) $(TOOLS_LIBS)

$(STRINGIFY):
$(echo_cmd) "CC $@"
$(Q)$(TOOLS_CC) $(TOOLS_CFLAGS) $(TOOLS_LDFLAGS) -o $@ $(TOOLSDIR)/stringify.c $(TOOLS_LIBS)

define DO_Q3LCC
$(echo_cmd) "Q3LCC $<"
$(Q)$(Q3LCC) $(BASEGAME_CFLAGS) -o $@ $<
Expand Down Expand Up @@ -2725,7 +2729,7 @@ $(B)/renderergl1/%.o: $(RGL1DIR)/%.c
$(B)/renderergl1/tr_altivec.o: $(RGL1DIR)/tr_altivec.c
$(DO_REF_CC_ALTIVEC)

$(B)/renderergl2/glsl/%.c: $(RGL2DIR)/glsl/%.glsl
$(B)/renderergl2/glsl/%.c: $(RGL2DIR)/glsl/%.glsl $(STRINGIFY)
$(DO_REF_STR)

$(B)/renderergl2/glsl/%.o: $(B)/renderergl2/glsl/%.c
Expand Down Expand Up @@ -2950,7 +2954,7 @@ toolsclean2:
@echo "TOOLS_CLEAN $(B)"
@rm -f $(TOOLSOBJ)
@rm -f $(TOOLSOBJ_D_FILES)
@rm -f $(LBURG) $(DAGCHECK_C) $(Q3RCC) $(Q3CPP) $(Q3LCC) $(Q3ASM)
@rm -f $(LBURG) $(DAGCHECK_C) $(Q3RCC) $(Q3CPP) $(Q3LCC) $(Q3ASM) $(STRINGIFY)

distclean: clean toolsclean
@rm -rf $(BUILD_DIR)
Expand Down
51 changes: 51 additions & 0 deletions code/tools/stringify.c
@@ -0,0 +1,51 @@
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include <libgen.h>

int main(int argc, char **argv)
{
FILE *ifp;
FILE *ofp;
char buffer[1024];

if(argc < 3)
return 1;

char *inFile = argv[1];
char *outFile = argv[2];

ifp = fopen(inFile, "r");
if(!ifp)
return 2;

ofp = fopen(outFile, "w");
if(!ofp)
return 3;

// Strip extension
char *base = basename(inFile);
*strrchr(base, '.') = '\0';

fprintf(ofp, "const char *fallbackShader_%s =\n", base);

while(fgets(buffer, sizeof(buffer), ifp))
{
// Strip trailing whitespace from line
char *end = buffer + strlen(buffer) - 1;
while(end > buffer && isspace(*end))
end--;

end[1] = '\0';

// Write line enquoted, with a newline
fprintf(ofp, "\"%s\\n\"\n", buffer);
}

fprintf(ofp, ";\n");

fclose(ifp);
fclose(ofp);

return 0;
}

0 comments on commit 1166b28

Please sign in to comment.