Fix musl build on various platforms
This commit is contained in:
parent
f585abdc4f
commit
ce0ee8d538
3 changed files with 55 additions and 18 deletions
32
Makefile
32
Makefile
|
|
@ -1,9 +1,11 @@
|
|||
|
||||
LOLCAT_SRC := lolcat.c
|
||||
CENSOR_SRC := censor.c
|
||||
CFLAGS := -std=c11 -Wall -g
|
||||
LOLCAT_SRC ?= lolcat.c
|
||||
CENSOR_SRC ?= censor.c
|
||||
CFLAGS ?= -std=c11 -Wall -g
|
||||
|
||||
DESTDIR := /usr/local/bin
|
||||
DESTDIR ?= /usr/local/bin
|
||||
|
||||
include Makefile.musl
|
||||
|
||||
ifeq ($(shell uname -s),Darwin)
|
||||
LOLCAT_SRC += memorymapping/src/fmemopen.c
|
||||
|
|
@ -15,21 +17,15 @@ all: lolcat-static censor-static
|
|||
|
||||
.PHONY: install clean musl static
|
||||
|
||||
musl/lib/libc.a musl/lib/crt1.o:
|
||||
cd musl; ./configure
|
||||
make -C musl
|
||||
|
||||
musl: musl/lib/libc.a musl/lib/crt1.o
|
||||
|
||||
static: lolcat-static censor-static
|
||||
|
||||
lolcat-static: lolcat.c musl
|
||||
gcc -c $(CFLAGS) -Imusl/include -o lolcat.o $<
|
||||
gcc -s -nostartfiles -nodefaultlibs -nostdinc -static -ffunction-sections -fdata-sections -Wl,--gc-sections -o $@ lolcat.o musl/lib/crt1.o musl/lib/libc.a
|
||||
lolcat-static: lolcat.c
|
||||
gcc -c $(CFLAGS) -I$(MUSLDIR)/include -o lolcat.o $<
|
||||
gcc -s -nostartfiles -nodefaultlibs -nostdinc -static -ffunction-sections -fdata-sections -Wl,--gc-sections -o $@ lolcat.o $(MUSLDIR)/lib/crt1.o $(MUSLDIR)/lib/libc.a
|
||||
|
||||
censor-static: censor.c musl
|
||||
gcc -c $(CFLAGS) -Imusl/include -o censor.o $<
|
||||
gcc -s -nostartfiles -nodefaultlibs -nostdinc -static -ffunction-sections -fdata-sections -Wl,--gc-sections -o $@ censor.o musl/lib/crt1.o musl/lib/libc.a
|
||||
censor-static: censor.c
|
||||
gcc -c $(CFLAGS) -I$(MUSLDIR)/include -o censor.o $<
|
||||
gcc -s -nostartfiles -nodefaultlibs -nostdinc -static -ffunction-sections -fdata-sections -Wl,--gc-sections -o $@ censor.o $(MUSLDIR)/lib/crt1.o $(MUSLDIR)/lib/libc.a
|
||||
|
||||
lolcat: $(LOLCAT_SRC)
|
||||
gcc $(CFLAGS) -o $@ $^
|
||||
|
|
@ -37,11 +33,11 @@ lolcat: $(LOLCAT_SRC)
|
|||
censor: $(CENSOR_SRC)
|
||||
gcc $(CFLAGS) -o $@ $^
|
||||
|
||||
install: lolcat censor
|
||||
install: lolcat-static censor-static
|
||||
install lolcat-static $(DESTDIR)/lolcat
|
||||
install censor-static $(DESTDIR)/censor
|
||||
|
||||
clean:
|
||||
rm -f lolcat lolcat-static.o lolcat-static censor censor-static.o censor-static
|
||||
make -C musl clean
|
||||
# make -C musl clean
|
||||
|
||||
|
|
|
|||
27
Makefile.musl
Normal file
27
Makefile.musl
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
|
||||
ifneq (,$(wildcard /usr/local/musl))
|
||||
MUSLDIR ?= /usr/local/musl
|
||||
else ifneq (,$(wildcard /usr/lib/musl))
|
||||
MUSLDIR ?= /usr/lib/musl
|
||||
else ifneq (,$(wildcard musl/Makefile))
|
||||
MUSLDIR ?= musl
|
||||
lolcat-static: musl
|
||||
censor-static: musl
|
||||
else
|
||||
$(info "musl not found. If the build does not go through, consider either installing")
|
||||
$(info "musl system-wide using your favorite package manager or fetching and building a")
|
||||
$(info "local copy using:")
|
||||
$(info "$ git submodule init")
|
||||
$(info "$ git submodule update")
|
||||
$(info "$ make musl")
|
||||
endif
|
||||
$(info "Using musl at $(MUSLDIR)")
|
||||
|
||||
musl/lib/libc.a musl/lib/crt1.o: musl/config.mak
|
||||
make -C musl
|
||||
|
||||
musl/config.mak:
|
||||
cd musl; ./configure
|
||||
|
||||
musl: musl/lib/libc.a musl/lib/crt1.o
|
||||
|
||||
14
README.md
14
README.md
|
|
@ -24,6 +24,20 @@ $ yaourt -S c-lolcat
|
|||
$ make && sudo make install
|
||||
```
|
||||
|
||||
If this can't find musl and you have it installed somewhere, run
|
||||
```bash
|
||||
$ make MUSLDIR=/path/to/musl
|
||||
```
|
||||
|
||||
If you don't have a musl around yet, the easiest way to build is to run
|
||||
```bash
|
||||
$ git submodule init
|
||||
$ git submodule update
|
||||
$ make
|
||||
```
|
||||
|
||||
This will checkout and build musl in this repository's ```musl``` dir.
|
||||
|
||||
## Why?
|
||||
|
||||
This `lolcat` clone is an attempt to reduce the world's carbon dioxide emissions by optimizing inefficient code. It's >10x as fast and <0.1% as large as the original one.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue