racket-static/Makefile

96 lines
3.1 KiB
Makefile
Raw Normal View History

2020-10-13 08:37:53 +00:00
.PHONY: all setup clean mrproper
APP_NAME=run
RKT_NAME=$(APP_NAME).rkt
####################################################################################################
# download urls for stuff
RKT_DIST=racket-minimal-7.8-src.tgz
# what's in the racket tgz
RKT_DIR=racket-7.8
RKT_URL="https://mirror.racket-lang.org/installers/7.8/$(RKT_DIST)"
ALPINE_DIST=alpine-minirootfs-3.12.0-x86_64.tar.gz
ALPINE_URL="http://dl-cdn.alpinelinux.org/alpine/v3.12/releases/x86_64/$(ALPINE_DIST)"
# container is built and stored in here
CACHE_DIR=.cache
PATCHELF=patchelf
OBJCOPY=$(CROSS_COMPILE)objcopy
OBJDUMP=$(CROSS_COMPILE)objdump
2020-10-13 08:37:53 +00:00
all: setup exec-in-container
# rerun inside container
exec-in-container: setup
rsync -avR $(RKT_NAME) main_bc.c startup.c Makefile scripts/crimes.c scripts/crimes.h \
$(CACHE_DIR)/alpine/build/
sudo chmod 777 $(CACHE_DIR)/alpine/build $(CACHE_DIR)/alpine/build/scripts
2020-10-13 08:37:53 +00:00
sudo systemd-nspawn -UD $(CACHE_DIR)/alpine -- sh -c "cd build; make $(APP_NAME)"
cp $(CACHE_DIR)/alpine/build/$(APP_NAME) .
clean-in-container:
sudo systemd-nspawn -UD $(CACHE_DIR)/alpine -- sh -c "cd build; rm -rf *"
2020-10-13 08:37:53 +00:00
# main build stuff
DEBUG_CFLAGS=-g3 -no-pie -fno-pie
$(APP_NAME): main_bc.c app.o scripts/crimes startup.bin
# $(CC) -o $@ -pipe -O3 -DAPP_NAME='"$(APP_NAME)"' -static $^ -lracket3m -lrktio -lucontext -lffi
$(CC) -o $@ -pipe -O3 $(DEBUG_CFLAGS) -DAPP_NAME='"$(APP_NAME)"' -Wl,-eelf_crimes \
main_bc.c app.o /usr/lib/libracket3m.a /usr/lib/librktio.a /usr/lib/libffi.a /lib/libucontext.a
$(PATCHELF) --remove-needed $$($(OBJDUMP) -x $@ | grep NEEDED | awk '{print $$2}') $@
$(OBJCOPY) --remove-section .interp -- $@
scripts/crimes $@
scripts/crimes: scripts/crimes.c scripts/crimes.h
$(CC) -o $@ -pipe -O3 -g0 $<
startup.elf: startup.c
$(CC) -flto -O3 -g3 -Wl,-z,norelro -ffunction-sections -fdata-sections -static -pipe \
-Wl,-ecrimes_startup_run -fno-stack-protector -nostartfiles -fpie -pie -o $@ $<
startup.bin: startup.elf
$(OBJCOPY) -O binary $< $@
2020-10-13 08:37:53 +00:00
# this is faster than --c-mods by a lot
# it's less portable but like, we're containerized already so it'll work
app.o: app.zo
$(LD) -r -b binary $< -o $@
app.zo: $(RKT_NAME)
raco ctool --mods $@ $<
clean:
$(RM) $(APP_NAME) *.zo *.o
$(RM) scripts/crimes startup.bin startup.elf
2020-10-13 08:37:53 +00:00
mrproper: clean
sudo $(RM) -rf $(CACHE_DIR)/alpine
$(RM) -rf $(CACHE_DIR)/alpine
# setup stuff
setup: $(CACHE_DIR)/.setup
$(CACHE_DIR)/.setup: $(CACHE_DIR)/$(ALPINE_DIST) $(CACHE_DIR)/$(RKT_DIST)
-mkdir -p $(CACHE_DIR)/alpine
sudo rm -rf $(CACHE_DIR)/alpine
mkdir $(CACHE_DIR)/alpine
tar xf "$(CACHE_DIR)/$(ALPINE_DIST)" -C $(CACHE_DIR)/alpine
tar xf "$(CACHE_DIR)/$(RKT_DIST)" -C $(CACHE_DIR)/alpine
cp scripts/setup.sh $(CACHE_DIR)/alpine/setup.sh
cp scripts/repositories.conf $(CACHE_DIR)/alpine/etc/apk/repositories
mkdir $(CACHE_DIR)/alpine/build
chmod 777 $(CACHE_DIR)/alpine/build
sudo systemd-nspawn -UD $(CACHE_DIR)/alpine -- sh /setup.sh
touch $@
$(CACHE_DIR)/$(ALPINE_DIST):
-mkdir -p $(CACHE_DIR)/alpine
wget -O $@ $(ALPINE_URL)
$(CACHE_DIR)/$(RKT_DIST):
-mkdir -p $(CACHE_DIR)/alpine
wget -O $@ $(RKT_URL)