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 *
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)
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
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
115130MAKEFLAGS += --no-builtin-rules
116131# .SUFFIXES:
117132.PHONY : clean wipe nomatch
118133.PRECIOUS : % .o
134+ .SECONDARY :
119135SHELL =/bin/bash -o pipefail
120136
121137# asure functions that return values are not ignored
@@ -135,8 +151,8 @@ CCCOLOR ?= always
135151# create a define
136152D ?= 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
141157BUILD = $(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
222239ifeq "$(CCCOLOR ) " "always"
223240@sed -i -r "s/\x1B\[(([0-9]+)(;[0-9]+)*)?[m,K,H,f,J]//g" errors.err
224241endif
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
231248ifeq "$(CCCOLOR ) " "always"
232249@sed -i -r "s/\x1B\[(([0-9]+)(;[0-9]+)*)?[m,K,H,f,J]//g" errors.err
233250endif
234- -@[ ! -s errors.err ] && echo $@ version $(VERSION) > VERSION
251+ -@[ ! -s errors.err ] && echo " $@ version " $(VERSION) > VERSION && cp VERSION BUILD || echo "$@ build "$(VERSION) > BUILD
235252
236253nomatch :
237254@echo ' makefile error: no rules for the given goal(s)' $(warning nomatch)
@@ -263,13 +280,21 @@ tags :
263280ctags -R
264281ctags -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