Skip to content

Commit cc5b3bf

Browse files
committed
makefile euler3
1 parent 915d6b4 commit cc5b3bf

File tree

1 file changed

+39
-14
lines changed

1 file changed

+39
-14
lines changed

makefile

Lines changed: 39 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#***************************************************************************
2-
#* Autoversion makefile v.20170112.001402 (euler) *
3-
#* Copyright (C) 2014-2017 by Ruben Carlo Benante <rcb@beco.cc> *
2+
#* Autoversion makefile v.20190725.134357 (euler3) *
3+
#* Copyright (C) 2014-2019 by Ruben Carlo Benante <rcb@beco.cc> *
44
#* *
55
#* This makefile sets BUILD and allows to set MAJOR.MINOR version, *
66
#* DEBUG and OBJ to compile a range of different targets *
@@ -52,6 +52,11 @@
5252
# $ make ex1.bf.x
5353
# - Portugol:
5454
# $ make ex1.gpt.x
55+
# - Project Euler:
56+
# + Create a new template, say, number pe42.c:
57+
# $ make pe42.c
58+
# + Compile pe42.c with:
59+
# $ make pe42.x SRC=projecteuler.c
5560
#
5661
# * Directly from vim editor command line:
5762
# - Normal C program (ex1.c)
@@ -94,6 +99,14 @@
9499
# $ make wipe
95100
#
96101
# Log:
102+
# 2019-03-25:
103+
# * To create a source template for Project Euler now uses:
104+
# - make pe42.c
105+
# * And to compile:
106+
# - make pe42.x SRC=projecteuler.c
107+
# * Added target .SECONDARY to avoid deleting pe42.c
108+
# 2018-07-25:
109+
# * Generates BUILD when compiled with errors and VERSION when clean compiled
97110
# 2017-03-03:
98111
# * added -fdiagnostics-color=always to colorize tee output
99112
# * added -pg -fprofile-arcs to allow gprof command on debug
@@ -110,12 +123,15 @@
110123
# * added _FORTIFY_SOURCE=1 to help catch overflows
111124
# 2017-03-18:
112125
# * added -lcurl to link with libcurl
126+
# 2018-06-20:
127+
# * added help about euler, and echo how to compile
113128

114129
# disable builtin rules with MAKEFLAGS and .SUFFIXES
115130
MAKEFLAGS += --no-builtin-rules
116131
#.SUFFIXES:
117132
.PHONY: clean wipe nomatch
118133
.PRECIOUS: %.o
134+
.SECONDARY:
119135
SHELL=/bin/bash -o pipefail
120136

121137
# asure functions that return values are not ignored
@@ -135,8 +151,8 @@ CCCOLOR ?= always
135151
# create a define
136152
D ?= D_
137153
# project Euler exercise number
138-
N ?= 0
139-
PENAME := $(shell printf '%-8s' pe$(N).c)
154+
# N ?= 0
155+
# PENAME := $(shell printf '%-8s' pe$(N).c)
140156
# build date
141157
BUILD = $(shell date +"%g%m%d.%H%M%S")
142158
# build date inside binary code
@@ -219,19 +235,20 @@ endif
219235
# Inclui VERSION, data de BUILD e DEBUG (opcional).
220236
%.x : %.c $(OBJ) $(SRC)
221237
-$(CC) $(CFLAGS) $(CPPFLAGS) $(LDLIBS) $^ -o $@ 2>&1 | tee errors.err
238+
@#@echo $@ version $(VERSION) > VERSION
222239
ifeq "$(CCCOLOR)" "always"
223240
@sed -i -r "s/\x1B\[(([0-9]+)(;[0-9]+)*)?[m,K,H,f,J]//g" errors.err
224241
endif
225-
-@[ ! -s errors.err ] && echo $@ version $(VERSION) > VERSION
242+
-@[ ! -s errors.err ] && echo "$@ version "$(VERSION) > VERSION && cp VERSION BUILD || echo "$@ build "$(VERSION) > BUILD
226243

227244
# override built-in rules for mathing everything (exactly the same rule as %.x above)
228245
% : %.c $(OBJ) $(SRC)
229246
-$(CC) $(CFLAGS) $(CPPFLAGS) $(LDLIBS) $^ -o $@ 2>&1 | tee errors.err
230-
@echo $@ version $(VERSION) > VERSION
247+
@#@echo $@ version $(VERSION) > VERSION
231248
ifeq "$(CCCOLOR)" "always"
232249
@sed -i -r "s/\x1B\[(([0-9]+)(;[0-9]+)*)?[m,K,H,f,J]//g" errors.err
233250
endif
234-
-@[ ! -s errors.err ] && echo $@ version $(VERSION) > VERSION
251+
-@[ ! -s errors.err ] && echo "$@ version "$(VERSION) > VERSION && cp VERSION BUILD || echo "$@ build "$(VERSION) > BUILD
235252

236253
nomatch :
237254
@echo 'makefile error: no rules for the given goal(s)' $(warning nomatch)
@@ -263,13 +280,21 @@ tags :
263280
ctags -R
264281
ctags -R -x | less -F
265282

266-
# Gera um novo peN
267-
euler :
268-
@cp -i peN.c pe$(N).c
269-
@sed -i 's/PEN.c /$(PENAME)/' pe$(N).c
270-
@sed -i 's/PEN pe ## N/PEN pe ## $(N)/' pe$(N).c
271-
@sed -i 's/Proj. Euler problem #PEN/Proj. Euler problem #$(N)/' pe$(N).c
272-
@echo "pe$(N).c"
283+
# Gera um novo template peN.c para Project Euler, questao N
284+
pe%.c :
285+
@if [[ -s "pe$(*).c" ]] ; then \
286+
echo Found source code pe$(*).c ; \
287+
else \
288+
cp -i peN.c pe$(*).c ; \
289+
sed -i 's/PEN.c /$(shell printf '%-8s' pe$(*).c)/' pe$(*).c ; \
290+
sed -i 's/PEN pe ## N/PEN pe ## $(*)/' pe$(*).c ; \
291+
sed -i 's/SPEN "pe" "N"/SPEN "pe" "$(*)"/' pe$(*).c ; \
292+
sed -i 's/Proj. Euler problem #PEN/Proj. Euler problem #$(*)/' pe$(*).c ; \
293+
sed -i 's/PEN(/pe$(*)(/' pe$(*).c ; \
294+
echo "Created ....... : pe$(*).c" ; \
295+
echo "Compile with .. : make pe$(*).x SRC=projecteuler.c" ; \
296+
fi
297+
@echo '................: Good luck!'
273298

274299
#* ------------------------------------------------------------------- *
275300
#* makefile config for Vim modeline *

0 commit comments

Comments
 (0)