Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Amiga support #26

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions Makefile.amiga
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# Usage:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add the name of this file to the EXTRA_DIST = list in Makefile.am.

Copy link
Author

@tehKaiN tehKaiN Mar 3, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done! This file is temporary until I find a way to force autotools to not use libtool on Amiga build.

# "make" - recommended: builds lib and app
# "make clean" - removes all tmp files
# "make lib" - builds only lib
# "make app" - builds only app if lib is present

CC = m68k-amigaos-gcc
AR = m68k-amigaos-ar
INCLUDES_APP = -Isrc -Ilib/public -I.
INCLUDES_LIB = -Ilib
CC_FLAGS_COMMON = -Wall -Wsign-compare -std=c11 -O3 -fomit-frame-pointer -fbaserel
CC_FLAGS_APP = $(INCLUDES_APP) $(CC_FLAGS_COMMON)
CC_FLAGS_LIB = $(INCLUDES_LIB) $(CC_FLAGS_COMMON)

# LTO for Amiga since every optimization counts!
LDFLAGS = -noixemul -flto

PACKER_SRC_DIR = $(ROOT)/src
TMP_DIR = tmp

LIB_IGNORE = \
lib/lh_new_decoder.c \
lib/pma_common.c \
lib/bit_stream_reader.c \
lib/tree_decode.c \
lib/lha_arch_win32.c \
lib/lha_arch_unix.c

LIB_SRCS = $(filter-out $(LIB_IGNORE), $(wildcard lib/*.c))
LIB_OBJS = $(addprefix $(TMP_DIR)/lib_, $(notdir $(LIB_SRCS:.c=.o)))

APP_SRCS = $(wildcard src/*.c)
APP_OBJS = $(addprefix $(TMP_DIR)/app_, $(notdir $(APP_SRCS:.c=.o)))

#------------------------------------------------------------------------- Goals

lhasa: lib app

lib: lib/public/liblhasa.a

app: bin/lhasa

clean:
@echo Removing tmp and lib contents
$(RM) tmp/*.o
$(RM) lib/public/liblhasa.a

#----------------------------------------------------------------- How it's made

tmp/lib_%.o: lib/%.c
@echo Building: $<
@$(CC) $(CC_FLAGS_LIB) -c -o $@ $<

tmp/app_%.o: src/%.c
@echo Building: $<
@$(CC) $(CC_FLAGS_APP) -c -o $@ $<

lib/public/liblhasa.a: $(LIB_OBJS)
@echo linking $@
@$(AR) rcs $@ $(LIB_OBJS)

bin/lhasa: lib/public/liblhasa.a $(APP_OBJS)
@echo linking $@
@$(CC) $(CC_FLAGS_LIB) -o $@ $(APP_OBJS) -llhasa -Wall $(LDFLAGS) -Llib/public

5 changes: 4 additions & 1 deletion lib/lha_arch.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,12 @@ CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

#define LHA_ARCH_UNIX 1
#define LHA_ARCH_WINDOWS 2
#define LHA_ARCH_AMIGA 3

#ifdef _WIN32
#if defined(_WIN32)
#define LHA_ARCH LHA_ARCH_WINDOWS
#elif defined(__amigaos__)
#define LHA_ARCH LHA_ARCH_AMIGA
#else
#define LHA_ARCH LHA_ARCH_UNIX
#endif
Expand Down
121 changes: 121 additions & 0 deletions lib/lha_arch_amiga.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
/*
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think if you add the name of this file to the SRC = list in lib/Makefile.am that will probably get you ~most of the way to a working autotools compile.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!


Copyright (c) 2012, Simon Howard

Permission to use, copy, modify, and/or distribute this software
for any purpose with or without fee is hereby granted, provided
that the above copyright notice and this permission notice appear
in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR
CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

*/

//
// Architecture-specific files for compilation on Amiga.
//

#define _GNU_SOURCE
#include "lha_arch.h"

#if LHA_ARCH == LHA_ARCH_AMIGA

#include <stdio.h>
#include <errno.h>
#include <fcntl.h>
#include <unistd.h>
#include <utime.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <stdlib.h>

int lha_arch_vasprintf(char **result, char *fmt, va_list args)
{
int len;
va_list args2;
va_copy(args2, args);
char szTmp[2];
len = vsnprintf(szTmp, 2, fmt, args2);
va_end(args2);
if (len >= 0) {
*result = malloc(len + 1);
if (*result != NULL) {
va_copy(args2, args);
return vsprintf(*result, fmt, args);
va_end(args2);
}
}
*result = NULL;
return -1;
}

void lha_arch_set_binary(FILE *handle)
{
// No-op on Amiga systems: there is no difference between
// "text" and "binary" files.
}

int lha_arch_mkdir(char *path, unsigned int unix_perms)
{
return mkdir(path, unix_perms) == 0;
}

int lha_arch_chown(char *filename, int unix_uid, int unix_gid)
{
return 1;
}

int lha_arch_chmod(char *filename, int unix_perms)
{
return 1;
}

int lha_arch_utime(char *filename, unsigned int timestamp)
{
struct utimbuf times;

times.actime = (time_t) timestamp;
times.modtime = (time_t) timestamp;

return utime(filename, &times) == 0;
}

FILE *lha_arch_fopen(char *filename, int unix_uid, int unix_gid, int unix_perms)
{
return fopen(filename, "wb");
}

LHAFileType lha_arch_exists(char *filename)
{
struct stat statbuf;

if (stat(filename, &statbuf) != 0) {
if (errno == ENOENT) {
return LHA_FILE_NONE;
} else {
return LHA_FILE_ERROR;
}
}

if (S_ISDIR(statbuf.st_mode)) {
return LHA_FILE_DIRECTORY;
} else {
return LHA_FILE_FILE;
}
}

int lha_arch_symlink(char *path, char *target)
{
return 1;
}

#endif /* LHA_ARCH_AMIGA */


18 changes: 11 additions & 7 deletions src/list.c
Original file line number Diff line number Diff line change
Expand Up @@ -232,12 +232,14 @@ static ListColumn size_column = {

// Compression ratio

static float compression_percent(size_t compressed, size_t uncompressed)
static size_t compression_permilles(size_t compressed, size_t uncompressed)
{
// Calculated permilles instead of float percents
// On Amiga there's no FPU, avoiding soft floats makes code more optimizable
if (uncompressed > 0) {
return ((float) compressed * 100.0f) / (float) uncompressed;
return (compressed * 1000) / uncompressed;
} else {
return 100.0f;
return 1000;
}
}

Expand All @@ -246,8 +248,9 @@ static void ratio_column_print(LHAFileHeader *header)
if (!strcmp(header->compress_method, "-lhd-")) {
printf("******");
} else {
printf("%5.1f%%", compression_percent(header->compressed_length,
header->length));
size_t permilles = compression_permilles(header->compressed_length,
header->length);
printf("%d.%d%%", permilles/10, permilles % 10);
}
}

Expand All @@ -256,8 +259,9 @@ static void ratio_column_footer(FileStatistics *stats)
if (stats->length == 0) {
printf("******");
} else {
printf("%5.1f%%", compression_percent(stats->compressed_length,
stats->length));
size_t permilles = compression_permilles(stats->compressed_length,
stats->length);
printf("%d.%d%%", permilles/10, permilles % 10);
}
}

Expand Down