# Generic makefile definitions to build a # universal program from source code # Yves Piguet, 2024 # Usage: # in a makefile, define: # TARGET = program name # SOURCE = list of .c files # and optionally set vapth or VPATH, CFLAGS; then # include universal.mk # This will define rules to build $(TARGET). CC = clang CXX = clang++ CFLAGS_X64 = -target x86_64-apple-macos13.0 CFLAGS_A64 = -target arm64-apple-macos13.0 $(TARGET): $(TARGET).universal mv $< $@ $(TARGET).x64: $(SOURCE:.c=.x64.o) $(TARGET).a64: $(SOURCE:.c=.a64.o) %.universal: %.x64 %.a64 lipo -create -output $@ $^ %.x64: $(CC) $(CFLAGS_X64) -o $@ $^ %.a64: $(CC) $(CFLAGS_A64) -o $@ $^ %.x64.o: %.c $(CC) $(CFLAGS) $(CFLAGS_X64) -c -o $@ $< %.a64.o: %.c $(CC) $(CFLAGS) $(CFLAGS_A64) -c -o $@ $< %.x64.o: %.cpp $(CXX) $(CXXFLAGS) $(CFLAGS_X64) -c -o $@ $< %.a64.o: %.cpp $(CXX) $(CXXFLAGS) $(CFLAGS_A64) -c -o $@ $< .PHONY: clean clean: rm -f *.x64.o *.a64.o *.x64 *.a64