.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 all: setup exec-in-container # rerun inside container exec-in-container: setup rsync -av $(RKT_NAME) main_bc.c Makefile $(CACHE_DIR)/alpine/build/ 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 *" # main build stuff $(APP_NAME): main_bc.c app.o $(CC) -o $@ -pipe -O3 -DAPP_NAME='"$(APP_NAME)"' -static $^ -lracket3m -lrktio -lucontext -lffi # 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 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)