From 36d238914c1cf376514c0f374182f42b60209dc6 Mon Sep 17 00:00:00 2001 From: Sami Samhuri Date: Sat, 23 Apr 2011 20:55:18 -0700 Subject: [PATCH] use a build directory instead of polluting src/ --- .gitignore | 3 +-- Makefile | 12 +++++++++--- Readme.md | 12 +++++++++--- src/Makefile | 37 +++++++++++++++++++++++++------------ test/Makefile | 6 ++---- 5 files changed, 46 insertions(+), 24 deletions(-) diff --git a/.gitignore b/.gitignore index 1b83f4b..41d513c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,5 @@ *.o -lake -lake.a +build test/* !test/*.[ch] !test/Makefile diff --git a/Makefile b/Makefile index 8c745f0..2ad0b30 100644 --- a/Makefile +++ b/Makefile @@ -1,12 +1,18 @@ all: - cd src && make clean && make - mv src/lake ./lake + cd src && make all + +lake: + cd src && make lake + +repl: + cd src && make repl clean: cd src && make clean + -rm -f lake test: - cd src && make lake.a + cd src && make lake cd test && make test_clean: diff --git a/Readme.md b/Readme.md index 0cbe9ba..a1a6d21 100644 --- a/Readme.md +++ b/Readme.md @@ -12,11 +12,11 @@ Compiling & Running Portable C99, only dep is glib, nothing to configure, no documentation! -Install glib 2.x using your package manager, for me it's either `brew install glib` or `sudo aptitude install glib`. Once you have glib just run: +Install glib 2.x using your package manager, for me it's either `brew install glib` or `sudo aptitude install glib`. Once you have glib you can build the repl: - $ make && ./lake + $ make repl && build/repl -That will drop you at a repl. There are booleans, symbols, integers, strings, lists, dotted lists (pairs), lambdas, a few special forms, and some primitive functions. +There are booleans, symbols, integers, strings, lists, dotted lists (pairs), lambdas, a few special forms, and some primitive functions. You can evaluate these as you expect in a Scheme repl: > #t #t @@ -37,6 +37,12 @@ That will drop you at a repl. There are booleans, symbols, integers, strings, li Hooray! That sure is repl-ish. +If you want to build a static library: + + $ make lake + +The binary will be in `build/lake.a` and you may do with it as you like. + Lake's special forms are: * `quote` diff --git a/src/Makefile b/src/Makefile index 4cb2839..5bb711b 100644 --- a/src/Makefile +++ b/src/Makefile @@ -1,20 +1,33 @@ +LAKE_BUILD = ../build CC = gcc CFLAGS := -Wall -g $(shell pkg-config --cflags glib-2.0) LFLAGS := $(shell pkg-config --libs glib-2.0) -LAKE_OBJS = env.o int.o str.o sym.o parse.o list.o eval.o \ - symtable.o fn.o dlist.o primitive.o comment.o lake.o -OBJS = $(LAKE_OBJS) repl.o +LAKE_OBJS = $(LAKE_BUILD)/comment.o \ + $(LAKE_BUILD)/dlist.o \ + $(LAKE_BUILD)/env.o \ + $(LAKE_BUILD)/eval.o \ + $(LAKE_BUILD)/fn.o \ + $(LAKE_BUILD)/int.o \ + $(LAKE_BUILD)/lake.o \ + $(LAKE_BUILD)/list.o \ + $(LAKE_BUILD)/parse.o \ + $(LAKE_BUILD)/primitive.o \ + $(LAKE_BUILD)/str.o \ + $(LAKE_BUILD)/sym.o \ + $(LAKE_BUILD)/symtable.o -all: lake +all: lake repl -lake: $(OBJS) - $(CC) $(CFLAGS) $(LFLAGS) $^ -o $@ +repl: $(LAKE_OBJS) $(LAKE_BUILD)/repl.o + $(CC) $(CFLAGS) $(LFLAGS) $^ -o $(LAKE_BUILD)/$@ -lake.a: $(LAKE_OBJS) - rm -f $@ - ar cq $@ $(LAKE_OBJS) +$(LAKE_BUILD)/%.o: %.c + @mkdir -p $(dir $@) + $(CC) $(CFLAGS) -c $< -o $@ + +lake: $(LAKE_OBJS) + rm -f $(LAKE_BUILD)/$@.a + ar cq $(LAKE_BUILD)/$@.a $(LAKE_OBJS) -# use touch to prevent errors in case files do not exist clean: - @touch dummy.o lake - rm -f *.o lake + -rm -rf $(LAKE_BUILD) diff --git a/test/Makefile b/test/Makefile index bc952dd..b4aafa5 100644 --- a/test/Makefile +++ b/test/Makefile @@ -1,7 +1,7 @@ CC = gcc CFLAGS := -Wall -g -I../src $(shell pkg-config --cflags glib-2.0) LFLAGS := $(shell pkg-config --libs glib-2.0) -DEPS = minunit.h ../src/lake.a +DEPS = minunit.h ../build/lake.a TESTS = test_comment test_dlist test_env all: $(TESTS) @@ -23,9 +23,7 @@ test_env: $(DEPS) test_env.o test_eval: $(DEPS) test_eval.o $(CC) $(CFLAGS) $(LFLAGS) $^ -o $@ -# use touch to prevent errors in case files do not exist clean: - @touch dummy.o $(TESTS) - rm -f *.o $(TESTS) + -rm -f *.o $(TESTS) .PHONY: all $(TESTS)