# $Header: /CVSROOT/tinolib/old/Makefile.proto,v 1.31 2006/10/03 20:26:52 tino Exp $ # One Makefile to rule them all .. the babble now is in README # This actually is a meta-Makefile, a template for AWK to create a real Makefile. # It's a little bit like sendmail.cf, only far more limited. # Comments are not preserved, but CVS-lines are copied dequoted. # Variables are taken from MAKE-Variables, however only simple # assignments can be tracked, no high-level MAKE constructs, please! # As a special: If a line exactly is "Makefile::" the rest of the file # is ignored. This is to parse "Makefile.tino" more easily. (In # nearly all cases you can use "Makefile:" instead.) # Rules start with #Xline where line is the rest and X is a letter like # C Output "line" unchanged, several empty "line"s are ignored # S starts a ruleset, "line" gives the list of variables to loop over # N count the number of content arguments in the variable list # This is like S but only expands to the count of content parts. # The rulesets are only processed once where ranges say if to # output a line or not. It's like an "if N contents then output" # Most time used to set a variable which is unset otherwise: # #N VAR # #R#0# VAR=defaultvalue # R Are ruleset lines which are expanded for each VARIABLE content. # Note that content parts which show up multiple or which are not # of a proper form (valid -_.+/a-zA-Z0-9) are ignored! # #v# is expanded to the content part # #p# is like #v# but with / replaced by _ (a/b.c becomes a_b.c) # #c# is the count of the content part (that's a number) # #[!][-]from[-[to]]# are ranges # Ranges can show anywhere in the line and expand to nothing. # Ranges hinder the output of the line if they are not satisfied. # They can be "ored" together, so any range satisfied outputs the line. # #2##4# outputs the line for content part 2 and 4 # #2# outputs the line for content part 2 # #!2# outputs the line for all content parts except 2 # #-4# outputs the line for parts 0 to 4 (0 is for the N case) # #4-# outputs the line starting at parts 4 # #2-4# outputs the line for parts 2 to 4 # #!2-4# outputs the line for parts 0, 1, 5 and above # #include(name) reads a file "name" and outputs it here. # Only valid in a ruleset. # This is used to catch the "gcc -M" output (filename.d). # Warning! You can do funny things like ##c## which first expands # to #n# where n is the count of the part, thus selects all parts. # However this are mainly sideeffects not to use! # Copyright (C)2004-2006 Valentin Hilbig, webmaster@scylla-charybdis.com # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # # $Log: Makefile.proto,v $ # Revision 1.31 2006/10/03 20:26:52 tino # Ubuntu has no gawk as awk, so gawk used instead of awk # # Revision 1.30 2006/07/29 23:36:21 tino # Allow VERSIONFILE to be different from $(PROG1) # # Revision 1.29 2006/07/17 14:37:30 tino # latest changes successful # # Revision 1.28 2006/06/16 20:30:38 tino # typo ${ instead $( # # Revision 1.27 2006/06/11 19:47:25 tino # See ChangeLog # # Revision 1.26 2006/01/29 17:49:52 tino # Improved documentation and "make test" # # Revision 1.25 2005/12/05 02:11:12 tino # Copyright and COPYLEFT added # Expand PROGS into single names #C #C# Automatically generated from "PROGS" above #S PROGS #R PROG#c#=#v# #C #C# Override those in Makefile.tino if needed: #N STD_CFLAGS #R#0# STD_CFLAGS=-g -Wall -O3 #N STD_LDFLAGS #R#0# STD_LDFLAGS= #N STD_LDLIBS #R#0# STD_LDLIBS= #N INSTALLPATH #R#0# INSTALLPATH=$(HOME) #NBIN PATH #R#0# #s#PATH=bin #NSBIN PATH #R#0# #s#PATH=sbin #NLIB PATH #R#0# #s#PATH=lib #NETC PATH #R#0# #s#PATH=etc #NMAN PATH #R#0# #s#PATH=man #NSMAN PATH #R#0# #s#PATH=share/man #NINF PATH #R#0# #s#PATH=info #NSINF PATH #R#0# #s#PATH=share/info #C #C# Except for the compiler generated dependencies at the end #C# from here no changes shall be needed. # Do not define those yourself! CFLAGS=$(DBG_FLAGS) $(ADD_CFLAGS) $(STD_CFLAGS) -I$(HERE) LDFLAGS=$(DBG_LDFLAGS) $(ADD_LDFLAGS) $(STD_LDFLAGS) LDLIBS=$(DBG_LDLIBS) $(ADD_LDLIBS) $(STD_LDLIBS) VERSIONFILE=$(PROG1)_version VERSIONNAME=$(VERSIONFILE) COMMON= \ $(VERSIONFILE).h \ $(TINOINC) \ $(TINOLIB) \ #S TINOCOPY #R #p# \ GAWK=awk TOUCH=touch # Following prorgrams shall not be needed in future! CP=cp STRIP=strip HERE=$(PWD) #C #C# Semi-automatically generated for CygWin (*.exe) PROGS_EXE= \ #S PROGS #R $(PROG#c#).exe \ .PHONY: all static install it clean distclean dist tar diff always ######################################################################## #C #C# Targets considered to work for all systems with GNU MAKE and GNU AWK all: $(SUBDIRS) $(PROGS) #C #C# To use this you need to do: #C# ln -s tinolib/diet . #C# make static #C# This is experimental. static: [ -f diet.distignore~ ] || $(MAKE) clean $(TOUCH) diet.distignore~ $(MAKE) -C diet $(MAKE) CC="diet/tinodiet.sh --tinodiet" # The latter MAKE fails if there is no tinolib. This is normal! # We let Makefile depend on Makefile.md5, # so we can "redo" it if needed. # We "touch" it so that hopefully MAKE re-reads Makefile then. Makefile: Makefile.md5 $(TOUCH) Makefile # Makefile.md5 is a forced target to always execute it to check, # if Makefile must be redone. # I cannot make this depend on tino/ as you might not have this directory! # I don't want to depend this on a shell either, so I must use AWK! Makefile.md5: $(VERSIONFILE).h always @$(GAWK) -vHERE="$(HERE)" -vMAKE="$(MAKE)" -vTINOCOPY="$(TINOCOPY)" 'BEGIN { \ if ((getline < "tino/Makefile")>0 && \ (getline < "tino/Makefile.proto")>0 && \ (getline < "tino/Makefile.awk")>-1) \ system(MAKE " -C tino tino HERE='\''" HERE "'\'' TINOCOPY='\''" TINOCOPY "'\''"); \ else if ((getline < "Makefile.md5")<0) \ printf "" >"Makefile.md5"; \ }' $(VERSIONFILE).h: VERSION $(GAWK) -vPROG="$(VERSIONNAME)" '{ print "#define " toupper(PROG) " \"" $$0 "\"" }' VERSION > "$(VERSIONFILE).h" #C #C# Poor man's install #C# Generated from PROGS and INSTALL* above install: #S PROGS #R $(RM) "$(INSTALLPATH)/bin/$(PROG#c#)" #R $(CP) "$(PROG#c#)" "$(INSTALLPATH)/bin/$(PROG#c#)" #R $(STRIP) "$(INSTALLPATH)/bin/$(PROG#c#)" #SINSTALL BIN SBIN LIB ETC MAN SMAN INF SINF #R $(RM) "$(INSTALLPATH)/$(#s#PATH)/#v#" #R $(CP) "#v#" "$(INSTALLPATH)/$(#s#PATH)/#v#" #S SUBDIRS #R -$(MAKE) -C #v# install HERE="$(HERE)" INSTALLPATH="$(INSTALLPATH)" ######################################################################## #C #C# Special targets considered to work for all unix like systems #C# like CygWin # Makefile helping target, see tino/Makefile # In case you are in a subdirectory, # make this the first rule and let it cd up. it: all [ ".$(PWD)" != ".$(HERE)" ] || [ -f VERSION ] || \ { UP="`dirname "$(HERE)"`"; $(MAKE) -C"$$UP" it HERE="$$UP"; } clean: $(RM) *.o *.d *~ .*~ */*~ $(CLEAN) -$(MAKE) -C tino clean HERE="$(HERE)" #S SUBDIRS CLEANDIRS #R -$(MAKE) -C #v# clean HERE="$(HERE)" distclean: clean $(RM) "$(VERSIONFILE).h" $(PROGS) $(PROGS_EXE) $(DISTCLEAN) $(RM) core core.* -$(MAKE) -C tino distclean HERE="$(HERE)" #S SUBDIRS CLEANDIRS #R $(MAKE) -C #v# distclean HERE="$(HERE)" ######################################################################## #C #C# Special targets in presence of tinolib #C# (subdirectory tino) dist: distclean -$(MAKE) -C tino dist HERE="$(HERE)" DEBUGS="$(DBG_CFLAGS)$(DBG_LDFLAGS)$(DBG_LDLIBS)" tar: distclean -$(MAKE) -C tino tar HERE="$(HERE)" diff: -$(MAKE) -C tino diff HERE="$(HERE)" #C #C# Automatically generated from $(SUBDIRS): #S SUBDIRS #R.PHONY: #v# #R#v#: #R @$(MAKE) -C "$@" all HERE="$(HERE)" #C #C# automatically generated dependencies #S PROGS #R $(PROG#c#).o:: $(COMMON) #R $(PROG#c#): $(PROG#c#).o $(OBJS) $(LIBS) #S TINOCOPY #R #p#: Makefile.md5 #R $(TOUCH) #p# #C #C# compiler generated dependencies, remove if incorrect #S PROGS #R #R# included: #v#.d #R$(PROG#c#).o::#include(#v#.d)