+CC ?= gcc
+CFLAGS ?= -g -Wall -Wextra -I $(INCLUDE)
+RMF ?= rm -f
+WHICH ?= which
+CTAGS ?= ctags
+ETAGS ?= etags
+SED ?= sed
+
INCLUDE := ../include
-CC := gcc
-CFLAGS := -g -Wall -Wextra -I $(INCLUDE)
-RM := rm -f
COMMONSRC := word.c cmem.c cerr.c
-CASL2SRC := struct.c cmd.c hash.c
+CASL2SRC := struct.c hash.c
ASSRC := assemble.c token.c label.c
EXECSRC := exec.c dump.c
-.PHONY: all clean
+.PHONY: all version clean
+
+all: version ../casl2 ../comet2 ../dumpword ctags etags
-all: ../casl2 ../comet2 ../dumpword
+version:
+ $(MAKE) -C .. version
../casl2: casl2.o $(subst .c,.o,$(COMMONSRC) $(CASL2SRC) $(ASSRC) $(EXECSRC))
$(CC) $(CFLAGS) -o $@ $^
+ @$(RMF) *.d
../comet2: comet2.o $(subst .c,.o,$(COMMONSRC) $(CASL2SRC) $(EXECSRC))
$(CC) $(CFLAGS) -o $@ $^
+ @$(RMF) *.d
../dumpword: dumpword.o $(subst .c,.o,$(COMMONSRC))
$(CC) $(CFLAGS) -o $@ $^
+ @$(RMF) *.d
%.o: %.c
$(CC) -c $(CFLAGS) $<
%.d: %.c
- @$(CC) -MM -I $(INCLUDE) $< | sed 's/\($*\.o\):/\1 $@:/g' >$@
+ @$(CC) -MM -I $(INCLUDE) $< | $(SED) 's/\($*\.o\):/\1 $@:/g' >$@
-include $(subst .c,.d,casl2.c comet2.c dumpword.c $(COMMONSRC) $(CASL2SRC) $(ASSRC) $(EXECSRC))
-TAGS: $(INCLUDE)/*.h *.c
- @if test `which etags`; then etags $^; fi
+ctags: $(INCLUDE)/*.h *.c
+ @$(WHICH) $(CTAGS) >/dev/null && $(CTAGS) $^
+
+etags: $(INCLUDE)/*.h *.c
+ @$(WHICH) $(ETAGS) >/dev/null && $(ETAGS) $^
+
+clean: clean_cmd clean_build clean_tags
+
+clean_cmd:
+ @$(RMF) ../casl2 ../comet2 ../dumpword
+
+clean_build:
+ @$(RMF) *.o *.d
-clean:
- @rm -f ../casl2 ../comet2 ../dumpword
- @rm -f *.o *.d
+clean_tags:
+ @$(RMF) TAGS tags