-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile
144 lines (107 loc) · 2.66 KB
/
Makefile
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# COBOL build system main Makefile
# GnuCOBOL installation
#
GNUCOBOL_SRC ?= http://gnu.c3sl.ufpr.br/alpha/gnucobol/gnucobol-3.0-rc1.tar.xz
export GNUCOBOL_SRC
# what to build
#
PROJECTROOT ?= examples
# verbosity (run `make V=1' for extra output)
#
ifeq ("$(origin V)", "command line")
VERBOSE := $(V)
else
VERBOSE := 0
endif
ifeq ($(VERBOSE),1)
Q :=
SILENT :=
else
Q := @
SILENT := -s
endif
export Q
# per project subdirectories
#
SOURCEDIR := src/main/cobol
COPYDIR := src/main/cobol/copy
TESTDIR := src/test/cobol
BUILDBASE := build
BUILDDIR := build/main
TESTRUNDIR := build/test
TARGETDIR := target
export SOURCEDIR COPYDIR TESTDIR BUILDBASE BUILDDIR TESTRUNDIR TARGETDIR
# COBOL compiler and flags
#
COBC ?= cobc
COBFLAGS ?= --std=ibm -I $(COPYDIR)
export COBC COBFLAGS
# COBOL Unit Test Framework
#
CUTPATH := $(abspath cobol-unit-test/src/main/cobol)
CUTCOPY := $(CUTPATH)/copy
export CUTPATH CUTCOPY
# Makefile recursion
#
SUBMAKEFILE := $(abspath Makefile.sub)
GENMK := $(abspath genmk.sh)
GENMAKEFILE := build/Makefile
RECIPES := $(wildcard $(PROJECTROOT)/*/build.txt)
SUBDIRS := $(RECIPES:/build.txt=)
FIRSTSUBDIR := $(word 1, $(SUBDIRS))
TESTPASS := $(abspath $(FIRSTSUBDIR)/build/test-ok)
TESTFAIL := $(abspath $(FIRSTSUBDIR)/build/test-fail)
export GENMK GENMAKEFILE TESTPASS TESTFAIL
define make_subdirs
$(Q)for SUBDIR in $(SUBDIRS); do \
SUBDIR=$$SUBDIR $(MAKE) $(SILENT) -C $$SUBDIR -f $(SUBMAKEFILE) $(1) || exit; \
done
endef
define make_builddirs
$(Q)for SUBDIR in $(SUBDIRS); do \
SUBDIR=$$SUBDIR $(MAKE) -C $$SUBDIR/ $(SILENT) -f $(GENMAKEFILE) $(1) || exit; \
done
endef
# pretty print
#
define print_green
-@command -v tput >/dev/null && tput setaf 2 && tput bold
-@echo "$(1)"
-@command -v tput >/dev/null && tput sgr0
endef
# targets
#
.PHONY: all build genmk clean test install-cobol init-test-counters
all: build test
build: genmk
$(call make_builddirs,build)
$(call print_green,BUILD OK)
genmk:
$(call make_subdirs,genmk)
clean:
@echo [CLEAN] $(BUILDROOT)
$(Q)rm -f *~
$(call make_subdirs,clean)
test: build check-submodules init-test-counters
$(call make_builddirs,test)
@./teststats.sh "$(TESTPASS)" "$(TESTFAIL)"
init-test-counters:
$(Q)echo -n > $(TESTPASS)
$(Q)echo -n > $(TESTFAIL)
autotest: test
@echo
@echo
@echo "watching for changes..."
@echo
$(Q)while inotifywait --recursive --quiet --quiet --event modify --event move --event delete $(PROJECTROOT); do \
$(MAKE) test; \
echo ; \
echo ; \
echo "watching for changes..."; \
echo ; \
done
check-submodules:
$(Q)git submodule init
$(Q)git submodule update
install-gnucobol:
$(MAKE) -C gnucobol3 download install