xco

Concurrency for C
git clone https://git.ryansepassi.com/git/xco.git
Log | Files | Refs | README

Makefile (1157B)


      1 # xco — minimal asymmetric coroutines.
      2 #
      3 # Per-platform selection: PLATFORM names a directory under platform/.
      4 # The build adds -Iplatform/$(PLATFORM) (so xco_platform_internal.h
      5 # resolves to that platform's copy) and compiles
      6 # platform/$(PLATFORM)/xco_platform.c.
      7 #
      8 # All build artifacts land under build/, mirroring the source tree.
      9 
     10 CC       ?= cc
     11 AR       ?= ar
     12 CFLAGS   ?= -std=c11 -Wall -Wextra -O2 -g
     13 
     14 PLATFORM    ?= $(shell uname -m | sed 's/aarch64/arm64/')
     15 PLATFORMDIR := platform/$(PLATFORM)
     16 BUILD       := build
     17 
     18 CPPFLAGS += -Iplatform -I$(PLATFORMDIR)
     19 
     20 SRCS := xco.c $(PLATFORMDIR)/xco_platform.c
     21 OBJS := $(SRCS:%.c=$(BUILD)/%.o)
     22 LIB  := $(BUILD)/libxco.a
     23 
     24 TEST_SRCS := tests/test_xco.c tests/test_event.c tests/test_op.c
     25 TEST_BINS := $(TEST_SRCS:tests/%.c=$(BUILD)/%)
     26 
     27 all: $(LIB)
     28 
     29 $(LIB): $(OBJS)
     30 	$(AR) rcs $@ $^
     31 
     32 $(BUILD)/%.o: %.c
     33 	@mkdir -p $(dir $@)
     34 	$(CC) $(CPPFLAGS) $(CFLAGS) -c -o $@ $<
     35 
     36 $(BUILD)/test_%: tests/test_%.c $(LIB)
     37 	@mkdir -p $(dir $@)
     38 	$(CC) -I. $(CPPFLAGS) $(CFLAGS) -o $@ $< $(LIB)
     39 
     40 test: $(TEST_BINS)
     41 	@for t in $(TEST_BINS); do echo "==> $$t"; $$t || exit 1; done
     42 
     43 clean:
     44 	rm -rf $(BUILD)
     45 
     46 .PHONY: all clean test