Makefile
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
CFLAGS = -Wall -Wextra -g -Os
LDFLAGS =
SOURCES = xyw.c xywasm.c xywvm.c devices/system.c devices/terminal.c devices/clock.c devices/file.c devices/beeper.c
OBJS = xyw.o xywasm.o xywvm.o devices/system.o devices/terminal.o devices/clock.o devices/file.o devices/beeper.o
UNAME_S := $(shell uname -s)
HAVE_ALSA := $(shell \
printf 'int main(void){return 0;}\n' | \
$(CC) -x c - -lasound -o /dev/null >/dev/null 2>&1 && echo 1)
# beeper.c picks its audio backend at compile time via #ifdef, so the only
# thing the Makefile needs to do is link the matching system library.
ifeq ($(OS),Windows_NT)
BIN := xyw.exe
LDFLAGS += -lwinmm
else ifeq ($(UNAME_S),Darwin)
LDFLAGS += -framework AudioToolbox -framework CoreFoundation
else ifeq ($(HAVE_ALSA),1)
# Only link -lasound if the ALSA headers are actually installed
LDFLAGS += -lasound
# Fallback to libossaudio
else ifeq ($(HAVE_OSSAUDIO),1)
LDLIBS += -lossaudio
else
# No audio backend (beeper will throw an error)
CFLAGS += -DXYW_NO_AUDIO_BACKEND
endif
.PHONY: clean test
xyw: $(OBJS)
$(CC) $(CFLAGS) $(OBJS) -o xyw $(LDFLAGS)
xyw.o: xyw.c xyw.h
$(CC) $(CFLAGS) -c xyw.c -o xyw.o
xywvm.o: xywvm.c xyw.h
$(CC) $(CFLAGS) -c xywvm.c -o xywvm.o
xywasm.o: xywasm.c xyw.h
$(CC) $(CFLAGS) -c xywasm.c -o xywasm.o
devices/system.o: devices/system.c devices/system.h xyw.h
$(CC) $(CFLAGS) -c devices/system.c -o devices/system.o
devices/terminal.o: devices/terminal.c devices/terminal.h xyw.h
$(CC) $(CFLAGS) -c devices/terminal.c -o devices/terminal.o
devices/clock.o: devices/clock.c devices/clock.h xyw.h
$(CC) $(CFLAGS) -c devices/clock.c -o devices/clock.o
devices/file.o: devices/file.c devices/file.h xyw.h
$(CC) $(CFLAGS) -c devices/file.c -o devices/file.o
devices/beeper.o: devices/beeper.c devices/beeper.h xyw.h
$(CC) $(CFLAGS) -c devices/beeper.c -o devices/beeper.o
test:
./test.sh
ifeq ($(OS),Windows_NT)
else
@stty sane
endif
clean:
rm -f xyw xyw.exe $(OBJS)
|