FictionTools/z88dk/src/z80asm/libfile.c
/*-----------------------------------------------------------------------------
*	make library from list of files; convert each source to object file name 
*----------------------------------------------------------------------------*/
make library from list of files; convert each source to object file name
make library from list of files ; convert each source to object file name
void make_library(const char *lib_filename, argv_t *src_files)
{
	ByteArray *obj_file_data;
	FILE	*lib_file;
	const char *obj_filename;
	size_t	 fptr, obj_size;
	lib_filename = search_libfile(lib_filename);
	if ( lib_filename == NULL )
		return;					
	if (opts.verbose)
		printf("Creating library '%s'\n", path_canon(lib_filename));
	lib_file = xfopen( lib_filename, "wb" );	
	xfwrite_cstr(Z80libhdr, lib_file);
	for (char **pfile = argv_front(src_files); *pfile; pfile++)
	{
		fptr = ftell( lib_file );
		obj_filename  = get_obj_filename( *pfile );
		obj_file_data = read_obj_file_data( obj_filename );
		if ( obj_file_data == NULL )
		{
			xfclose(lib_file);			
			remove(lib_filename);
			return;
		}
		obj_size = ByteArray_size( obj_file_data );
		if (pfile + 1 == argv_back(src_files))
			xfwrite_dword(-1, lib_file);
        else
            xfwrite_dword(fptr + 4 + 4 + obj_size,  lib_file); 
        xfwrite_dword(obj_size, lib_file);
		xfwrite_bytes((char *)ByteArray_item(obj_file_data, 0), obj_size, lib_file);
	}
	xfclose( lib_file );
}
void make_library ( const char * lib_filename , argv_t * src_files ) { ByteArray * obj_file_data ; FILE * lib_file ; const char * obj_filename ; size_t fptr , obj_size ; lib_filename = search_libfile ( lib_filename ) ; if ( lib_filename == NULL ) return ; if ( opts . verbose ) printf ( " \n " , path_canon ( lib_filename ) ) ; lib_file = xfopen ( lib_filename , " " ) ; xfwrite_cstr ( Z80libhdr , lib_file ) ; for ( char * * pfile = argv_front ( src_files ) ; * pfile ; pfile ++ ) { fptr = ftell ( lib_file ) ; obj_filename = get_obj_filename ( * pfile ) ; obj_file_data = read_obj_file_data ( obj_filename ) ; if ( obj_file_data == NULL ) { xfclose ( lib_file ) ; remove ( lib_filename ) ; return ; } obj_size = ByteArray_size ( obj_file_data ) ; if ( pfile + 1 == argv_back ( src_files ) ) xfwrite_dword ( -1 , lib_file ) ; else xfwrite_dword ( fptr + 4 + 4 + obj_size , lib_file ) ; xfwrite_dword ( obj_size , lib_file ) ; xfwrite_bytes ( ( char * ) ByteArray_item ( obj_file_data , 0 ) , obj_size , lib_file ) ; } xfclose ( lib_file ) ; }
make library from list of files; convert each source to object file name
make library from list of files ; convert each source to object file name
/* ERROR */ /* write library header */ /* write each object file */ /* read object file */ /* error */ /* write file pointer of next file, or -1 if last */ /* write module size */ /* write module */ /* close and write lib file */