From 84dc917720ff12a741bf87824bef1e6c31c9e1f2 Mon Sep 17 00:00:00 2001 From: jaseg Date: Tue, 7 Jul 2015 02:49:51 +0200 Subject: Link statically against musl --- .gitignore | 3 +-- .gitmodules | 3 +++ Makefile | 14 +++++++++++--- fgetwc_fix.c | 35 ----------------------------------- fgetwc_fix.h | 5 ----- lolcat.c | 6 ++---- musl | 1 + 7 files changed, 18 insertions(+), 49 deletions(-) create mode 100644 .gitmodules delete mode 100644 fgetwc_fix.c delete mode 100644 fgetwc_fix.h create mode 160000 musl diff --git a/.gitignore b/.gitignore index a2a2fbd..f33c7f4 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,2 @@ lolcat -.*.swo -.*.swp +lolcat.o diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..f80450c --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "musl"] + path = musl + url = git://git.musl-libc.org/musl diff --git a/Makefile b/Makefile index ff1d72d..b6ef5fe 100644 --- a/Makefile +++ b/Makefile @@ -1,11 +1,19 @@ all: lolcat -lolcat: lolcat.c fgetwc_fix.c - gcc -g -std=c99 -Wall -o lolcat lolcat.c fgetwc_fix.c +musl/lib/libc.a musl/lib/crt1.o: + cd musl; ./configure + make -C musl + +lolcat: lolcat.c musl/lib/libc.a musl/lib/crt1.o + gcc -c -std=c11 -Wall -Imusl/include -o lolcat.o lolcat.c + gcc -s -nostartfiles -nodefaultlibs -nostdinc -static -ffunction-sections -fdata-sections -Wl,--gc-sections -o lolcat lolcat.o musl/lib/crt1.o musl/lib/libc.a install: lolcat install lolcat /usr/local/bin -.PHONY: install all +clean: + rm -f lolcat lolcat.o + +.PHONY: install clean diff --git a/fgetwc_fix.c b/fgetwc_fix.c deleted file mode 100644 index 76cf52b..0000000 --- a/fgetwc_fix.c +++ /dev/null @@ -1,35 +0,0 @@ - -/* This file contains a fixed implementation of fgetwc since glibc's one is a little segfaulty when used on fmemopen'ed files. */ - -#include -#include -#include -#include -#include - -#include "fgetwc_fix.h" - -/* code blatantly ripped from newlib. If you are from newlib: newlib rocks, keep going! */ -wint_t _fgetwc_fixed(FILE *fp) { - wchar_t wc; - size_t res; - size_t nconv = 0; - char buf[MB_CUR_MAX]; - mbstate_t mbstate; - memset(&mbstate, 0, sizeof(mbstate)); - - while((buf[nconv++] = fgetc(fp)) != EOF){ - res = mbrtowc(&wc, buf, nconv, &mbstate); - if (res == (size_t)-1) /* invalid sequence */ - break; - else if (res == (size_t)-2) /* incomplete sequence */ - continue; - else if (res == 0) - return L'\0'; - else - return wc; - } - - errno = EILSEQ; - return WEOF; -} diff --git a/fgetwc_fix.h b/fgetwc_fix.h deleted file mode 100644 index 343d9f7..0000000 --- a/fgetwc_fix.h +++ /dev/null @@ -1,5 +0,0 @@ - -#include -#include - -wint_t _fgetwc_fixed(FILE *fp); diff --git a/lolcat.c b/lolcat.c index 5c4b687..324de5b 100644 --- a/lolcat.c +++ b/lolcat.c @@ -19,7 +19,7 @@ #include #include #include -#include +#include #include #include #include @@ -27,8 +27,6 @@ #include #include -#include "fgetwc_fix.h" - static char helpstr[] = "\n" "Usage: lolcat [-h horizontal_speed] [-v vertical_speed] [--] [FILES...]\n" @@ -139,7 +137,7 @@ int main(int argc, char **argv){ return 2; } - while((c = _fgetwc_fixed(f)) > 0){ + while((c = fgetwc(f)) > 0){ if(colors){ find_escape_sequences(c, &escape_state); diff --git a/musl b/musl new file mode 160000 index 0000000..fb58545 --- /dev/null +++ b/musl @@ -0,0 +1 @@ +Subproject commit fb58545f8d1c5fa32122244caeaf3625c12ddc01 -- cgit