nlehuen / ctst

A plain C implementation of the Ternary Search Tree structure with Ruby bindings

This URL has Read+Write access

nlehuen User (author)
Sun Apr 19 07:13:53 -0700 2009
commit  dfb8562fc5b0412973272d94a9544a402f30682e
tree    91b537bdc09004079683fc576dd4f5b77e932a10
parent  bd059e86061cf0cc93f27b21ef93b182efcee350
ctst / Makefile-core
100644 83 lines (67 sloc) 2.614 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# Got this from http://www.cs.oberlin.edu/~jwalker/makeTmpl/
# don't need to actually change these varibles
EXT:=c
H_EXT=h
CXX:=gcc
RM:=rm -rf
MKDIR:=mkdir -p
 
# macros to move files from the source area to the objects area
TO_OBJS=$(strip $(patsubst $(SRC)/%,$(OBJS)/%,$(1)))
TO_SRC=$(strip $(patsubst $(OBJS)/%,$(SRC)/%,$(1)))
 
SRC_DIRS:=$(strip $(shell find $(SRC) -type d))
OBJS_DIRS:=$(strip $(patsubst $(SRC)/%,$(OBJS)/%,$(SRC_DIRS)))
ALL_CODE_FILES:=$(strip $(foreach DIR,$(SRC_DIRS), $(wildcard $(DIR)/*.$(EXT))))
ALL_OBJECT_FILES:=$(strip $(addsuffix .o, $(basename $(call TO_OBJS,$(ALL_CODE_FILES)))))
ALL_HEADER_FILES:=$(strip $(foreach DIR,$(SRC_DIRS), $(wildcard $(DIR)/*.$(H_EXT))))
ALL_SRC_FILES:=$(ALL_CODE_FILES) $(ALL_HEADER_FILES)
 
.PHONY: world prebuild postbuild clean final run restore backup
 
# Make everything in debug
world: CXXFLAGS:=$(BASE_FLAGS) $(DEBUG_FLAGS)
world: CXXLFLAGS:=$(BASE_LFLAGS) $(DEBUG_LFLAGS)
world: $(OUT)/depend.mk prebuild $(TARGET) postbuild
 
# Make a final build
final: CXXFLAGS:=$(BASE_FLAGS) $(FINAL_FLAGS)
final: CXXLFLAGS:=$(BASE_LFLAGS) $(FINAL_LFLAGS)
final: clean $(OUT)/depend.mk prebuild $(TARGET) postbuild
$(RM) $(OBJS)
 
# Make and run
run: world
$(TARGET)
 
# Make everything go away (be clean)
clean:
$(RM) run
$(RM) $(OUT)
$(RM) $(TARGET)
clear
@ls --color
 
# Restore the most recent temp backup
restore:
-mv -i $(SRC) $(SRC).old
tar -xzf backup/current-build.tar.gz
 
backup:
@$(MKDIR) backup/
@tar -czf backup/$(basename $(notdir $(TARGET)))-`date +%Y-%m-%d-%H%M`.tar.gz $(SRC)/
@echo "Backup Successful!"
 
# This is the actual code dependencies section
$(TARGET): $(ALL_OBJECT_FILES)
$(CXX) $(CXXFLAGS) $(CXXLFLAGS) $+ -o $@
 
%.o:
$(CXX) $(CXXFLAGS) -c $(call TO_SRC,$(basename $@).$(EXT)) -o $@
 
-include $(OUT)/depend.mk
 
# Support dependecies
$(OUT)/depend.mk: $(ALL_SRC_FILES)
@$(MKDIR) $(OUT)
@$(RM) $(OUT)/depend.mk
set -e; $(CXX) -MM $(ALL_CODE_FILES) | sed -e "s,\.$(EXT)\.o,\.o," -e "s|^\(.*\)\.o: $(SRC)/\([^ ]*/\)\([^ /]*\)|\2\1.o: $(SRC)/\2\3|" -e "s,.*\.o,$(OBJS)/&," >> $(OUT)/depend.mk
 
prebuild:
# clear
@$(MKDIR) $(OBJS)
@for dir in $(OBJS_DIRS); do $(MKDIR) $${dir}; done
 
postbuild:
ifeq ($(GEN_RUN),yes)
@ln -sf $(TARGET) run
endif
@$(MKDIR) backup/
-@mv -f backup/$(basename $(notdir $(TARGET)))-last-build.tar.gz backup/$(basename $(notdir $(TARGET)))-last-build.tar.gz.old
@tar -czf backup/$(basename $(notdir $(TARGET)))-last-build.tar.gz $(SRC)/
@$(RM) backup/$(basename $(notdir $(TARGET)))-last-build.tar.gz.old