diff --git a/Makefile b/Makefile index d9e51f7..8a15e43 100644 --- a/Makefile +++ b/Makefile @@ -1,35 +1,45 @@ -CFLAGS = -std=c99 -Wall -LDFLAGS = -lrt -lm +MODS := io + +CPPFLAGS := -I. +CFLAGS := -std=c99 -Wall +LDFLAGS := -lrt -lm + +CFLAGS += $(MODS:%=-DHAVE_MOD_%) + +OBJS := rosella.o gc.o builtin.o interp.o reader.o $(MODS:%=mods/mod_%.o) +DEPS := $(OBJS:%.o=%.d) +GCNO := $(OBJS:%.o=%.gcno) +GCDA := $(OBJS:%.o=%.gcda) ifeq ($(DEBUG),yes) -CFLAGS += -g -PROFILE = no -dummy := $(shell rm -f rosella *.gcda *.gcno *.o) + CFLAGS += -g + PROFILE := no + dummy := $(shell rm -f rosella $(OBJS) $(GCDA) $(GCNO)) else -CFLAGS += -O3 -DNDEBUG -march=nocona + CFLAGS += -O3 -DNDEBUG -march=nocona +endif + +ifeq ($(PROFILE),yes) + CFLAGS += -fprofile-generate + LDFLAGS += -fprofile-generate +endif + +ifneq (,$(wildcard *.gcda mods/*.gcda)) + CFLAGS += -fprofile-use + dummy := $(shell rm -f rosella $(OBJS)) endif all: rosella -.PHONY: all clean +depend: $(DEPS) -ifeq ($(PROFILE),yes) -CFLAGS += -fprofile-generate -LDFLAGS += -fprofile-generate -endif - -ifneq (,$(wildcard *.gcda)) -CFLAGS += -fprofile-use -dummy := $(shell rm -f rosella *.o) -endif +.PHONY: all clean depend clean: - -rm -f rosella *.o *.gcda *.gcno + -rm -f rosella $(OBJS) $(DEPS) $(GCDA) $(GCNO) -rosella: rosella.o gc.o builtin.o interp.o reader.o io_builtin.o +%.d: %.c + $(CC) $(CPPFLAGS) -MM $< -MF $@ -MT $(<:%.c=%.o) -MT $@ -rosella.o: rosella.c gc.h builtin.h interp.h -gc.o: gc.c gc.h -builtin.o: builtin.c builtin.h interp.h gc.h -interp.o: interp.c interp.h gc.h builtin.h -reader.o: reader.c reader.h gc.h builtin.h -io_builtin.o: io_builtin.c io_builtin.h builtin.h interp.h gc.h +rosella: $(OBJS) + +-include $(DEPS) diff --git a/io_builtin.c b/mods/mod_io.c similarity index 99% rename from io_builtin.c rename to mods/mod_io.c index 3de740d..e1e87db 100644 --- a/io_builtin.c +++ b/mods/mod_io.c @@ -13,7 +13,8 @@ #include "gc.h" #include "builtin.h" #include "interp.h" -#include "io_builtin.h" + +#include "mod_io.h" static void bi_posix_open(interp_state_t *state); //static void bi_posix_openat(interp_state_t *state); @@ -24,7 +25,7 @@ static void bi_posix_write(interp_state_t *state); static void bi_posix_lseek(interp_state_t *state); static void bi_posix_close(interp_state_t *state); -void io_builtin_init(void) +void mod_io_init(void) { register_builtin(BI_IO_POSIX_OPEN, make_builtin_fn(bi_posix_open)); //register_builtin(BI_IO_POSIX_OPENAT, make_builtin_fn(bi_posix_openat)); diff --git a/io_builtin.h b/mods/mod_io.h similarity index 94% rename from io_builtin.h rename to mods/mod_io.h index 16fdd32..ce04dcd 100644 --- a/io_builtin.h +++ b/mods/mod_io.h @@ -16,7 +16,7 @@ #define BI_IO_POSIX_CLOSE "posix-close" -void io_builtin_init(void); +void mod_io_init(void); #endif /* vim:set sw=2 expandtab: */ diff --git a/reader.c b/reader.c index 23a43fa..ab6c560 100644 --- a/reader.c +++ b/reader.c @@ -15,6 +15,8 @@ #include "gc.h" #include "builtin.h" +#include "reader.h" + typedef struct reader_state { FILE *file; diff --git a/rosella.c b/rosella.c index c14393c..ba2778d 100644 --- a/rosella.c +++ b/rosella.c @@ -11,7 +11,10 @@ #include "builtin.h" #include "interp.h" #include "reader.h" -#include "io_builtin.h" + +#ifdef HAVE_MOD_io +# include "mods/mod_io.h" +#endif static void test_builtins(void); static void test_weak_boxes_and_wills(void); @@ -35,7 +38,10 @@ int main(int argc, char **argv) gc_init(256*1024, 1024*1024); builtin_init(); interpreter_init(); - io_builtin_init(); + +#ifdef HAVE_MOD_io + mod_io_init(); +#endif if (argc < 2 || (strcmp(argv[1], "-t") == 0) || (strcmp(argv[1], "--test") == 0)) {