.PHONY: all build gtags check doc info html doc-inner install uninstall install-info uninstall-info install-casl2lib uninstall-casl2lib version gittag clean clean-src clean-gtags clean-test clean-doc clean-doc-inner
-GTAGS := gtags
-RMF := rm -f
-WHICH := which
+CMD := casl2 comet2 dumpword
+
+CAT := cat
+CP := cp
ECHO := echo
+GITTAG := git tag
+GTAGS := gtags
INSTALL := install
SED := sed
-CAT := cat
-XARGS := xargs
-GITTAG := git tag
+WHICH := which
prefix ?= ~
bindir ?= $(prefix)/bin
VERSION = $(shell $(CAT) VERSION)
VERSIONFILES = include/package.h test/system/casl2/opt_v/0.txt test/system/comet2/opt_v/0.txt test/system/dumpword/opt_v/0.txt
-all: build docall gtags
+all: build doc gtags
-build:
+build: version
$(MAKE) -C src all
+ $(CP) $(addprefix src/,$(CMD)) ./
gtags:
- @$(WHICH) $(GTAGS) >/dev/null && $(GTAGS) || $(ECHO) "$(GTAGS): not found"
+ $(if $(strip $(shell $(WHICH) $(GTAGS))),$(GTAGS),@$(ECHO) '$(GTAGS): not found')
+
+doc:
+ $(MAKE) -C doc base
+ $(MAKE) INSTALL
+
+INSTALL: doc/install.txt
+ $(CP) $< $@
docall:
$(MAKE) -C doc all
install: casl2 comet2 dumpword install-info install-casl2lib
$(INSTALL) -d $(bindir)
- $(INSTALL) casl2 comet2 dumpword $(bindir)/
+ $(INSTALL) $(CMD) $(bindir)/
uninstall: uninstall-info uninstall-casl2lib
- $(RMF) $(bindir)/casl2 $(bindir)/comet2 $(bindir)/dumpword
+ $(RM) $(prefix $(bindir)/,$(CMD))
install-info:
$(MAKE) -C doc install-info
@$(ECHO) "YACASL2 Version: $(VERSION)"
$(VERSIONFILES): VERSION
- $(SED) -e "s/@@VERSION@@/$(VERSION)/g" $@.version >$@
+ @$(SED) -e "s/@@VERSION@@/$(VERSION)/g" $@.version >$@
gittag: VERSION
$(GITTAG) $(VERSION)
-clean: clean-src clean-gtags clean-doc clean-doc-inner clean-version
+clean: clean-cmd clean-src clean-gtags clean-doc clean-doc-inner clean-version
+
+clean-cmd:
+ @$(RM) $(CMD)
clean-src:
@$(MAKE) -sC src clean
clean-gtags:
- @$(RMF) GPATH GRTAGS GSYMS GTAGS
+ @$(RM) GPATH GRTAGS GSYMS GTAGS
clean-doc:
@$(MAKE) -sC doc clean
clean-doc-inner:
@$(MAKE) -sC doc_inner clean
+clean-version:
+ @$(RM) $(VERSIONFILES)
+
clean-test:
@$(MAKE) -sC test clean
-
-clean-version:
- @$(RMF) $(VERSIONFILES)
-MANUAL = manual
-INSTALLDOC = install
-CASL2SPEC = casl2_spec
-MANUAL_SYSINFO = yacasl2.info
-CSS = style.css
-
-MV ?= mv
-CP ?= cp
-MKDIR ?= mkdir
-RMF = rm -f
-RMRF ?= rm -rf
-PTEX ?= ptex
-TEXI2DVI ?= texi2dvi
-DVI2PDF ?= dvipdfmx
-MAKEINFO ?= gmakeinfo
-INSTALL ?= install
-INSTALL-INFO ?= ginstall-info
-GZIP = gzip
+DOCS := install manual
+
+CSS := style.css
+
+CP := cp
+DVIPDFMX := dvipdfmx
+GZIP := gzip
+INSTALL := install
+INSTALL-INFO := install-info
+MKDIR := mkdir
+RMR := rm -rf
+TEX := ptex
+TEXI2DVI := TEX=ptex texi2dvi
+TEX2DVI_FLAGS = -q --texinfo=@afourpaper
prefix ?= ~
infodir ?= $(prefix)/share/info
-.PHONY: all info html htmls pdf install-info uninstall-info clean clean-textmp
+.PHONY: base all info html htmls pdf install-info uninstall-info clean clean-textmp
.INTERMEDIATE: *.dvi
-base: ../INSTALL $(MANUAL_SYSINFO) $(MANUAL).html
+base: install.txt info html
-all: info html htmls pdf ../INSTALL $(MANUAL_SYSINFO)
+all: base htmls pdf
-info: $(MANUAL_SYSINFO) $(INSTALLDOC).info
+info: yacasl2.info
-html: $(MANUAL).html $(INSTALLDOC).html
+html: $(addsuffix .html,$(DOCS))
-htmls: $(MANUAL)_html
+htmls: $(addsuffix _html,$(DOCS))
-pdf: $(INSTALLDOC).pdf $(MANUAL).pdf
+pdf: $(addsuffix .pdf,$(DOCS))
-$(MANUAL_SYSINFO): $(MANUAL).texi
- $(MAKEINFO) $<
+yacasl2.info: manual.texi
+ $(MAKEINFO) $(MAKEINFO_FLAGS) $<
-%.html: %.texi $(CSS)
+$(addsuffix .html,$(DOCS)) $(addsuffix _html,$(DOCS)): $(CSS)
+
+%.html: %.texi
$(MAKEINFO) -o $@ --no-split --html --css-include=$(CSS) $<
-%_html: %.texi $(CSS)
- $(INSTALL) -d $@
- $(INSTALL) $(CSS) $@/
+%_html: %.texi
+ if test ! -e $@; then $(MKDIR) $@; fi
+ $(CP) $(CSS) $@/
$(MAKEINFO) -o $@ --html --css-ref=$(CSS) $<
%.pdf: %.dvi
- $(DVI2PDF) $<
-
-%.dvi: %.texi
- TEX=$(PTEX) $(TEXI2DVI) -q --texinfo=@afourpaper -o $@ $<
- @$(MAKE) clean-textmp
+ $(DVIPDFMX) $<
%.txt: %.texi
$(MAKEINFO) --no-headers --disable-encoding -o $@ $<
-install-info: $(MANUAL_SYSINFO)
+install-info: yacasl2.info
$(INSTALL) -d $(infodir)
- $(INSTALL) $(MANUAL_SYSINFO) $(infodir)/
- $(INSTALL-INFO) $(infodir)/$(MANUAL_SYSINFO) $(infodir)/dir
- $(GZIP) -f $(infodir)/$(MANUAL_SYSINFO)
-
-uninstall-info: $(MANUAL).info
- $(INSTALL-INFO) --delete $(infodir)/$(MANUAL_SYSINFO) $(infodir)/dir
- $(RMF) $(infodir)/$(MANUAL_SYSINFO)*
-
-$(INSTALLDOC).html: $(INSTALLDOC).texi $(CSS)
- $(MAKEINFO) -o $@ --no-split --html --css-include=$(CSS) $<
+ $(INSTALL) $< $(infodir)/
+ $(INSTALL-INFO) $(infodir)/$< $(infodir)/dir
+ $(GZIP) -f $(infodir)/$<
-../INSTALL: $(INSTALLDOC).txt
- $(CP) $< $@
+uninstall-info:
+ $(INSTALL-INFO) --delete $(infodir)/yacasl2.info $(infodir)/dir
+ $(RM) $(infodir)/yacasl2.info
clean: clean-textmp
- @$(RMRF) *_html *.info *.html *.pdf *.dvi *.txt
+ @$(RMR) *_html *.info *.html *.pdf *.dvi *.txt
clean-textmp:
- @$(RMF) *.aux *.cp *.cps *.fn *.ky *.log *.pg *.pgs *.tmp *.toc *.tp *.vr
+ @$(RM) *.aux *.cp *.cps *.fn *.ky *.log *.pg *.pgs *.tmp *.toc *.tp *.vr
-CC ?= gcc
-CFLAGS ?= -g -Wall -Wextra -I $(INCLUDE)
-RMF ?= rm -f
-WHICH ?= which
-CTAGS ?= ctags
-ETAGS ?= etags
-SED ?= sed
+INCLUDEDIR := ../include
+INCLUDE = -I $(INCLUDEDIR)
-INCLUDE := ../include
+# コマンド
+CC := gcc
+CFLAGS := -g -Wall -Wextra $(INCLUDE)
+CTAGS := ctags
+ETAGS := etags
+SED := sed
+WHICH := which
-COMMONSRC := word.c cmem.c cerr.c
-CASL2SRC := struct.c hash.c
-ASSRC := assemble.c token.c label.c
-EXECSRC := exec.c dump.c
+# ソースの分類
+CMDOBJ := casl2 comet2 dumpword
+COMMONOBJ := word cmem cerr
+CASL2OBJ := struct hash
+ASOBJ := assemble token label
+EXECOBJ := exec dump
-.PHONY: all version clean
+.PHONY: all build tag clean
-all: version ../casl2 ../comet2 ../dumpword ctags etags
+all: build tag
-version:
- $(MAKE) -C .. version
+# ヘッダファイルの依存関係を.dファイルに出力する
+%.d: %.c
+ @($(CC) -MM -I $(INCLUDEDIR) $< | $(SED) 's/\($*\.o\):/\1 $@:/g' >$@ && echo '$@ is created from $<')
-../casl2: casl2.o $(subst .c,.o,$(COMMONSRC) $(CASL2SRC) $(ASSRC) $(EXECSRC))
- $(CC) $(CFLAGS) -o $@ $^
- @$(RMF) *.d
+# .dファイルからヘッダファイルの依存関係を取得する
+# ターゲットに clean が含まれている場合は除く
+ifneq ($(findstring $(MAKECMDGOALS),clean),clean)
+ -include $(addsuffix .d,$(CMDOBJ) $(COMMONOBJ) $(CASL2OBJ) $(ASOBJ) $(EXECOBJ))
+endif
-../comet2: comet2.o $(subst .c,.o,$(COMMONSRC) $(CASL2SRC) $(EXECSRC))
- $(CC) $(CFLAGS) -o $@ $^
- @$(RMF) *.d
+# casl2、comet2、dumpwordのビルド
+build: $(CMDOBJ)
-../dumpword: dumpword.o $(subst .c,.o,$(COMMONSRC))
- $(CC) $(CFLAGS) -o $@ $^
- @$(RMF) *.d
+casl2: casl2.o $(addsuffix .o,$(COMMONOBJ) $(CASL2OBJ) $(ASOBJ) $(EXECOBJ))
-%.o: %.c
- $(CC) -c $(CFLAGS) $<
+comet2: comet2.o $(addsuffix .o,$(COMMONOBJ) $(CASL2OBJ) $(EXECOBJ))
-%.d: %.c
- @$(CC) -MM -I $(INCLUDE) $< | $(SED) 's/\($*\.o\):/\1 $@:/g' >$@
+dumpword: dumpword.o $(addsuffix .o,$(COMMONOBJ))
--include $(subst .c,.d,casl2.c comet2.c dumpword.c $(COMMONSRC) $(CASL2SRC) $(ASSRC) $(EXECSRC))
+# tagファイル作成 - ctags & etags
+# コマンドがない場合はなにもしない
+tag: tags TAGS
-ctags: $(INCLUDE)/*.h *.c
- @$(WHICH) $(CTAGS) >/dev/null && $(CTAGS) $^
+tags: $(INCLUDEDIR)/*.h *.c
+ $(if $(strip $(shell $(WHICH) $(CTAGS))),$(CTAGS) $^,@$(ECHO) '$(CTAGS): not found')
-etags: $(INCLUDE)/*.h *.c
- @$(WHICH) $(ETAGS) >/dev/null && $(ETAGS) $^
+TAGS: $(INCLUDEDIR)/*.h *.c
+ $(if $(strip $(shell $(WHICH) $(ETAGS))),$(ETAGS) $^,@$(ECHO) '$(ETAGS): not found')
-clean: clean_cmd clean_build clean_tags
+# makeで生成したファイルの削除
+clean: clean-cmd clean-work clean-tag
-clean_cmd:
- @$(RMF) ../casl2 ../comet2 ../dumpword
+clean-cmd:
+ @$(RM) casl2 comet2 dumpword
-clean_build:
- @$(RMF) *.o *.d
+clean-work:
+ @$(RM) *.o *.d
-clean_tags:
- @$(RMF) TAGS tags
+clean-tag:
+ @$(RM) TAGS tags