xco

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

Makefile (1892B)


      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 # XCO_MT changes struct layouts, so the MT build is a separate archive;
     25 # every object and test in the mt tree compiles with -DXCO_MT.
     26 MT_OBJS := $(SRCS:%.c=$(BUILD)/mt/%.o)
     27 MT_LIB  := $(BUILD)/mt/libxco_mt.a
     28 
     29 TEST_SRCS := tests/test_xco.c tests/test_event.c tests/test_op.c
     30 TEST_BINS := $(TEST_SRCS:tests/%.c=$(BUILD)/%)
     31 
     32 # The ST suite also runs against the MT build (an MT library with no
     33 # threads attached must behave identically), plus the MT-only suite.
     34 MT_TEST_BINS := $(TEST_SRCS:tests/%.c=$(BUILD)/mt/%) $(BUILD)/mt/test_mt
     35 
     36 all: $(LIB) $(MT_LIB)
     37 
     38 $(LIB): $(OBJS)
     39 	$(AR) rcs $@ $^
     40 
     41 $(MT_LIB): $(MT_OBJS)
     42 	$(AR) rcs $@ $^
     43 
     44 $(BUILD)/mt/%.o: %.c
     45 	@mkdir -p $(dir $@)
     46 	$(CC) -DXCO_MT $(CPPFLAGS) $(CFLAGS) -c -o $@ $<
     47 
     48 $(BUILD)/%.o: %.c
     49 	@mkdir -p $(dir $@)
     50 	$(CC) $(CPPFLAGS) $(CFLAGS) -c -o $@ $<
     51 
     52 $(BUILD)/mt/test_%: tests/test_%.c $(MT_LIB)
     53 	@mkdir -p $(dir $@)
     54 	$(CC) -DXCO_MT -I. $(CPPFLAGS) $(CFLAGS) -o $@ $< $(MT_LIB) -lpthread
     55 
     56 $(BUILD)/test_%: tests/test_%.c $(LIB)
     57 	@mkdir -p $(dir $@)
     58 	$(CC) -I. $(CPPFLAGS) $(CFLAGS) -o $@ $< $(LIB)
     59 
     60 test: $(TEST_BINS) $(MT_TEST_BINS)
     61 	@for t in $(TEST_BINS) $(MT_TEST_BINS); do echo "==> $$t"; $$t || exit 1; done
     62 
     63 clean:
     64 	rm -rf $(BUILD)
     65 
     66 .PHONY: all clean test