Link statically against musl

This commit is contained in:
jaseg 2015-07-07 02:49:51 +02:00
parent 5bd8c7dcca
commit 84dc917720
7 changed files with 18 additions and 49 deletions

3
.gitignore vendored
View file

@ -1,3 +1,2 @@
lolcat
.*.swo
.*.swp
lolcat.o

3
.gitmodules vendored Normal file
View file

@ -0,0 +1,3 @@
[submodule "musl"]
path = musl
url = git://git.musl-libc.org/musl

View file

@ -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

View file

@ -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 <stdlib.h>
#include <wchar.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#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;
}

View file

@ -1,5 +0,0 @@
#include <wchar.h>
#include <stdint.h>
wint_t _fgetwc_fixed(FILE *fp);

View file

@ -19,7 +19,7 @@
#include <stdio.h>
#include <wchar.h>
#include <ctype.h>
#include <error.h>
#include <err.h>
#include <errno.h>
#include <stdlib.h>
#include <string.h>
@ -27,8 +27,6 @@
#include <unistd.h>
#include <sys/time.h>
#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);

1
musl Submodule

@ -0,0 +1 @@
Subproject commit fb58545f8d1c5fa32122244caeaf3625c12ddc01