dslinux/toolchain/ndstool Makefile raw2c.c

stsp stsp at user.in-berlin.de
Sun Aug 13 22:32:47 CEST 2006


Update of /cvsroot/dslinux/dslinux/toolchain/ndstool
In directory antilope:/tmp/cvs-serv7349

Modified Files:
	Makefile 
Added Files:
	raw2c.c 
Log Message:
Make ndstool build outside of devkitARM.


Index: Makefile
===================================================================
RCS file: /cvsroot/dslinux/dslinux/toolchain/ndstool/Makefile,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- Makefile	13 Aug 2006 20:25:28 -0000	1.1
+++ Makefile	13 Aug 2006 20:32:44 -0000	1.2
@@ -14,7 +14,6 @@
 INCLUDES	:=	include
 DATA			:=	data
 
-export PATH		:=	$(DEVKITARM)/bin:$(PATH)
 #---------------------------------------------------------------------------------
 # options for code generation
 #---------------------------------------------------------------------------------
@@ -63,7 +62,7 @@
 # list of directories containing libraries, this must be the top level containing
 # include and lib
 #---------------------------------------------------------------------------------
-LIBDIRS	:= /usr/local /c/cygwin/usr/local
+LIBDIRS		:= $(PREFIX)/lib
 
 #---------------------------------------------------------------------------------
 # no real need to edit anything past this point unless you need to add additional
@@ -79,10 +78,10 @@
 			$(foreach dir,$(DATA),$(CURDIR)/$(dir)) \
 			$(CURDIR)/DefaultArm7 $(CURDIR)/Loader
 
-export CC	:=	$(PREFIX)gcc
-export CXX	:=	$(PREFIX)g++
-export AR	:=	$(PREFIX)ar
-export OBJCOPY	:=	$(PREFIX)objcopy
+export CC	:=	gcc
+export CXX	:=	g++
+export AR	:=	ar
+export OBJCOPY	:=	objcopy
 
 #---------------------------------------------------------------------------------
 # automatically build a list of object files for our project
@@ -93,7 +92,7 @@
 BINFILES	:=	default_arm7.bin loadme.bin $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.bin)))
 BMPFILES	:=	$(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.bmp)))
 
-export OFILES	:= $(BINFILES:.bin=.o) $(BMPFILES:.bmp=.o)  $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o)
+export OFILES	:= $(filter-out default_arm7.o, $(BINFILES:.bin=.o) $(BMPFILES:.bmp=.o)  $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o))
 #---------------------------------------------------------------------------------
 # use CXX for linking C++ projects, CC for standard C
 #---------------------------------------------------------------------------------
@@ -110,9 +109,9 @@
 
 export INCLUDE	:=	$(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \
 			$(foreach dir,$(LIBDIRS),-I$(dir)/include) \
-			-I$(CURDIR)/$(BUILD)
+			-I$(CURDIR)/$(BUILD) -I$(PREFIX)/include
 
-export LIBPATHS	:=	$(foreach dir,$(LIBDIRS),-L$(dir)/lib)
+export LIBPATHS	:=	$(foreach dir,$(LIBDIRS),-L$(dir)/lib) -L$(PREFIX)/lib
 
 .PHONY: $(BUILD) clean
 
@@ -121,10 +120,9 @@
 	@echo $(PATH)
 	@[ -d $@ ] || mkdir -p $@
 	@make PassMeIncludes
-	@make -C DefaultArm7
-	@make -C Loader
+	@cc -o raw2c raw2c.c
+	@make -C Loader CC=$(CROSS)gcc
 	@make --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile
-	@./ndstool -@ DefaultArm7/default_arm7.bin && echo For official devkitPro releases, add this SHA1 hash of default ARM7 binary to data/arm7_sha1_homebrew.bin and recompile. || echo -n
 
 #---------------------------------------------------------------------------------
 .PHONY: PassMeIncludes
@@ -141,7 +139,7 @@
 	@echo clean ...
 	@make -C DefaultArm7 clean
 	@make -C Loader clean
-	@rm -fr $(BUILD) $(OUTPUT)
+	@rm -fr $(BUILD) $(OUTPUT) raw2c
 
 #---------------------------------------------------------------------------------
 all: clean $(BUILD)
@@ -164,7 +162,6 @@
 $(OUTPUT): $(OFILES)
 	@echo linking
 	@$(LD) $(LDFLAGS) $(OFILES) $(LIBPATHS) $(LIBS) -o $(OUTPUT)$(EXEEXT)
-	-@( cd $(OUTPUTDIR); upx -q -9 $(TARGET)$(EXEEXT) )
 
 #---------------------------------------------------------------------------------
 # Compile Targets for C/C++
@@ -190,13 +187,13 @@
 %.c	:	%.bmp
 #---------------------------------------------------------------------------------
 	@echo $(notdir $<)
-	@raw2c $<
+	@$(NDSTOOL_SRCDIR)/raw2c $<
  
 #---------------------------------------------------------------------------------
 %.c	:	%.bin
 #---------------------------------------------------------------------------------
 	@echo $(notdir $<)
-	@raw2c $<
+	@$(NDSTOOL_SRCDIR)/raw2c $<
 
 -include $(DEPENDS)
 

--- NEW FILE: raw2c.c ---
/*---------------------------------------------------------------------------------


  - WinterMute <wntrmute at gmail.com>
  http://www.devkitpro.org
---------------------------------------------------------------------------------*/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <sys/param.h>


char	srcName[MAXPATHLEN], dstName[MAXPATHLEN];	// file name buffers
static char	baseFileName[MAXPATHLEN];		// source file name without extension
static char	ArrayName[MAXPATHLEN];		// source file name without extension

//---------------------------------------------------------------------------------
// Parse file name. Put file name without extension in
// baseFileName, and return:
//---------------------------------------------------------------------------------
void parseFileName(char *str) {
//---------------------------------------------------------------------------------
	int	i;
	char	*cptr;


	strcpy(baseFileName, str);
	strcpy(srcName, str);


	cptr = strrchr(str, '.');
	if (!cptr) {						// if '.' not found, then append default extension
		strcat(srcName, ".bin");
	}
	else {
		i = (int) (cptr - str);	// get offset of '.' character
		baseFileName[i] = '\0';
	}

	if ((cptr = strrchr(baseFileName,'\\'))) {
		strcpy(ArrayName, cptr+1);
	} else if ((cptr = strrchr(baseFileName, '/'))) {
		strcpy(ArrayName, cptr+1);
	} else {
		strcpy(ArrayName, baseFileName);
	}

}

//---------------------------------------------------------------------------------
long fsize(FILE* f) {
//---------------------------------------------------------------------------------
	long size;
	long temp = ftell(f);

	fseek(f,0,SEEK_END);

	size = ftell(f);

	fseek(f, temp, SEEK_SET);

	return size;
}


static const char head[] = "/*\n  This file was autogenerated by raw2c.\nVisit http://www.devkitpro.org\n*/\n\n";
static const char comment[] = "//---------------------------------------------------------------------------------\n";

void Help() {}

//---------------------------------------------------------------------------------
void usage () {
//---------------------------------------------------------------------------------
	fprintf(stderr,	"Usage:\traw2c filename<ext>\n"
					"\tConverts a binary file to C array and header\n"
					"\tdefault input extension is .bin\n");
}

//---------------------------------------------------------------------------------
static void MakeSource(FILE* Infile, FILE* Outfile, FILE *Headerfile, int size) {
//---------------------------------------------------------------------------------

	unsigned long int counter = 0UL;
	unsigned long int length;
	unsigned char thisElement;
	rewind(Infile);
	rewind(Outfile);
	length = fsize(Infile);

	fprintf(Headerfile, head); /* Put top comment into source */
	fprintf(Headerfile, comment); /* Put separator comment into source */
	fprintf(Headerfile, "#ifndef _%s_h_\n",ArrayName);
	fprintf(Headerfile, "#define _%s_h_\n",ArrayName);
	fprintf(Headerfile, comment); /* Put separator comment into source */
	fprintf(Headerfile, "extern const unsigned char %s[];\n",ArrayName);
	fprintf(Headerfile, "extern const int %s_size;\n",ArrayName);
	fprintf(Headerfile, comment); /* Put separator comment into source */
	fprintf(Headerfile, "#endif //_%s_h_\n",ArrayName);
	fprintf(Headerfile, comment); /* Put separator comment into source */

	fprintf(Outfile, head); /* Put top comment into source */
	fprintf(Outfile, "const unsigned char %s[] = {\n\t", ArrayName);

	while ( counter < length ) {


		if ( fread(&thisElement, 1, 1, Infile) >= 1 ) {
			fprintf(Outfile,"0x%02x", thisElement);
		}

		counter++;
		if ( counter < length ) /* More to go */
 		fprintf(Outfile, ", ");

		if ( !((counter) % 16) ) {
			fputc('\n', Outfile);
			fputc('\t', Outfile);
		}

	}

	fprintf(Outfile, "\n};\n");
	fprintf(Outfile,"const int %s_size = sizeof(%s);\n",ArrayName,ArrayName);
	return;
}

//---------------------------------------------------------------------------------
int main (int argc, char* argv[]) {
//---------------------------------------------------------------------------------
	int elementSize;
	int a;

	FILE *fInfile, *fCfile, *fHfile;

	fprintf(stderr,"Raw2C by WinterMute\n");
	if (argc < 2) {
		usage();
		return -1;
	}
	for (a=1; a<argc; a++) {

		if (argv[a][0] == '-')
		{
			switch (argv[a][1])
			{
				case 'h':
					Help();
					break;
				case 's':
					elementSize = atoi(&argv[a][2]);
					break;
				default:
				{
					printf("Unknown option: %s\n", argv[a]);
					Help();
					break;
				}
			}
		} else {
			parseFileName(argv[a]);
		}
	}

	fInfile = fopen(srcName, "rb");

	strcpy(dstName, ArrayName);
	strcat(dstName, ".c");
	fCfile = fopen(dstName, "wb");

	strcpy(dstName, ArrayName);
	strcat(dstName, ".h");
	fHfile = fopen(dstName, "wb");

	MakeSource(fInfile,fCfile,fHfile,1);

	fclose(fInfile);
	fclose(fCfile);
	fclose(fHfile);


	return EXIT_SUCCESS;
}






More information about the dslinux-commit mailing list