Last active
June 22, 2021 12:31
-
-
Save genedelisa/fdb6cf970d596a82a4a4e36400f8114d to your computer and use it in GitHub Desktop.
Simple Makefile for command line Swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Simple Makefile for command line Swift projects | |
# Gene De Lisa | |
PROG = example | |
SRC = src/*.swift | |
INSTALL_DIR = ./bin | |
SWIFTC=xcrun --sdk macosx swiftc | |
# this is a hack right now just to compile | |
SWIFTC_COMMON_FLAGS = -parse-as-library | |
default: debug | |
release: SWIFTC_FLAGS = -DRELEASE -O | |
release: $(PROG) | |
strip $(INSTALL_DIR)/$(PROG) # removes debug symbols | |
debug: SWIFTC_FLAGS = -DDEBUG -g | |
debug: $(PROG) | |
# canonical Swift Intermediate Language | |
# https://github.com/apple/swift/blob/main/docs/SIL.rst | |
# -emit-silgen generates raw SIL | |
# -emit-sil generates canonical SIL | |
# xcrun swiftcff -emit-sil -O -wmo main.swift | xcrun swift-demangle, | |
sil: SWIFTC_FLAGS = -O -wmo $(SWIFTC_COMMON_FLAGS) | |
sil: $(SRC) | |
$(SWIFTC) $(SWIFTC_FLAGS) $^ -emit-sil | xcrun swift-demangle | |
$(PROG): $(SRC) | |
$(SWIFTC) $(SWIFTC_FLAGS) $(SWIFTC_COMMON_FLAGS) -o $@ $^ | |
cp $(PROG) $(INSTALL_DIR) | |
clean: | |
rm -rf $(PROG) $(PROG).dSYM | |
# also remove the installed binary | |
realclean: | |
rm -rf $(PROG) $(PROG).dSYM $(INSTALL_DIR)/$(PROG) | |
# make ARGS="foo" run | |
# make run ARGS="foo" | |
run: $(PROG) | |
$(INSTALL_DIR)/$(PROG) $(ARGS) | |
.PHONY: run clean realclean |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment