CC ?= gcc CFLAGS = -Isrc -Os -fdiagnostics-color=always -fmax-errors=5 LDFLAGS = LDLIBS = COSMO_LIBDIR = ./libcosmo COSMO_PREFLAGS = -g -static -nostdlib -nostdinc -fno-pie -no-pie -mno-red-zone COSMO_PREFLAGS += -fno-omit-frame-pointer -pg -mnop-mcount -mno-tls-direct-seg-refs COSMO_PREFLAGS += -include $(COSMO_LIBDIR)/cosmopolitan.h -Idummy COSMO_POSTFLAGS += -Wl,--gc-sections -fuse-ld=bfd -Wl,--gc-sections COSMO_POSTFLAGS += -Wl,-T,$(COSMO_LIBDIR)/ape.lds COSMO_POSTFLAGS += $(COSMO_LIBDIR)/crt.o $(COSMO_LIBDIR)/ape-no-modify-self.o $(COSMO_LIBDIR)/cosmopolitan.a COSMO_FILES = $(COSMO_LIBDIR)/ape-copy-self.o $(COSMO_LIBDIR)/ape-no-modify-self.o COSMO_FILES += $(COSMO_LIBDIR)/ape.lds $(COSMO_LIBDIR)/ape.o $(COSMO_LIBDIR)/crt.o COSMO_FILES += $(COSMO_LIBDIR)/cosmopolitan.a $(COSMO_LIBDIR)/cosmopolitan.h DUMMY_HEADERS = arpa/inet.h assert.h dirent.h dlfcn.h errno.h fcntl.h inttypes.h limits.h locale.h math.h netdb.h pthread.h sched.h signal.h stdarg.h stddef.h stdint.h stdio.h stdlib.h string.h sys/ioctl.h sys/socket.h sys/stat.h sys/syscall.h sys/time.h sys/types.h sys/utsname.h termios.h time.h unistd.h wchar.h DUMMY_MISSING = $(foreach header,$(DUMMY_HEADERS),$(if $(wildcard dummy/$(header)),,dummy/$(header))) TARGET = kuroko OBJS = $(patsubst %.c, %.o, $(filter-out src/kuroko.c,$(sort $(wildcard src/*.c)))) HEADERS = $(wildcard src/kuroko/*.h) GENMODS = modules/codecs/sbencs.krk modules/codecs/dbdata.krk ifdef KRK_DISABLE_DOCS CFLAGS += -DKRK_NO_DOCUMENTATION -Wno-unused-value endif ifndef KRK_DISABLE_RLINE BIN_OBJS += src/vendor/rline.o else CFLAGS += -DNO_RLINE endif ifdef KRK_DISABLE_DEBUG CFLAGS += -DKRK_DISABLE_DEBUG endif ifdef KRK_DISABLE_DYNAMIC BIN_OBJS += src/modules/module_math.o src/modules/module_random.o src/modules/module_socket.o src/modules/module_timeit.o src/modules/module_wcwidth.o CFLAGS += -DKRK_DISABLE_DYNAMIC -DSTATIC_ONLY endif ifdef KRK_DISABLE_THREADS CFLAGS += -DKRK_DISABLE_THREADS else CFLAGS += -DKRK_MEDIOCRE_TLS endif ifdef KRK_NO_DISASSEMBLY CFLAGS += -DKRK_NO_DISASSEMBLY=1 endif ifdef KRK_NO_TRACING CFLAGS += -DKRK_NO_TRACING=1 endif ifdef KRK_NO_STRESS_GC CFLAGS += -DKRK_NO_STRESS_GC=1 endif HEADERS += $(COSMO_LIBDIR)/cosmopolitan.h BIN_OBJS += $(OBJS) all: $(TARGET).com $(GENMODS) dummy/%.h: mkdir -p dummy && touch $@ dummy/arpa/%.h: mkdir -p dummy/arpa && touch $@ dummy/sys/%.h: mkdir -p dummy/sys && touch $@ %.o: %.c $(HEADERS) $(DUMMY_MISSING) $(CC) $(CFLAGS) $(COSMO_PREFLAGS) -c -o $@ $< $(TARGET).com.dbg: src/$(TARGET).c $(BIN_OBJS) $(HEADERS) $(DUMMY_MISSING) $(CC) $(CFLAGS) $(LDFLAGS) $(COSMO_PREFLAGS) -o $@ $< $(BIN_OBJS) $(LDLIBS) $(COSMO_POSTFLAGS) $(TARGET).com: $(TARGET).com.dbg objcopy -S -O binary $< $@ .PHONY: test test: @for i in test/*.krk; do echo $$i; KUROKO_TEST_ENV=1 $(TESTWRAPPER) ./$(TARGET).com.dbg $$i > $$i.actual; diff $$i.expect $$i.actual || exit 1; rm $$i.actual; done .PHONY: clean clean: -rm -f $(OBJS) $(TARGET).com $(TARGET).com.dbg src/*.o src/vendor/*.o # special cases: modules/codecs/sbencs.krk: tools/codectools/gen_sbencs.krk tools/codectools/encodings.json tools/codectools/indexes.json | $(TARGET).com.dbg ./$(TARGET).com.dbg tools/codectools/gen_sbencs.krk modules/codecs/dbdata.krk: tools/codectools/gen_dbdata.krk tools/codectools/encodings.json tools/codectools/indexes.json | $(TARGET).com.dbg ./$(TARGET).com.dbg tools/codectools/gen_dbdata.krk