View Single Post
  #9   (View Single Post)  
Old 25th January 2011
J65nko J65nko is offline
Join Date: May 2008
Location: Budel - the Netherlands
Posts: 3,503

I just hacked a sample Makefile which shows how easy it is to append a file or blog entry to a main file without editing the main file
Actually it allows you to create a file out of small building blocks. You only have to deal with the building blocks.

# Makefile to create a blog

#Jan 25 22:12 2011-01-25_2209.txt
#Jan 25 22:12 2011-01-22_2245.txt
#Jan 25 22:13 2011-01-01_1400.txt
#Jan 25 22:15 2011-02-01_1623.txt
#Jan 25 22:16 2011-02-04_1256.txt

YEAR = 2011

JAN !=  ls ${YEAR}-01*
FEB !=  ls ${YEAR}-02* 

# maybe better to use a year dir with a subdir for each month
# JAN	!=  ls ${YEAR}/01/*txt
# but then the Makefile has to be adjusted

all:	Blog${YEAR}-01.txt  Blog${YEAR}-02.txt

	@echo ${YEAR} ${JAN}
	@echo ${YEAR} ${FEB}

Blog${YEAR}-01.txt: ${JAN}
	cat ${.ALLSRC} > ${.TARGET}

Blog${YEAR}-02.txt: ${FEB}
	cat ${.ALLSRC} > ${.TARGET}

	rm Blog${YEAR}-??.txt
The variables JAN and FEB are set to the file names for that month:
$ make test
2011 2011-01-01_1400.txt 2011-01-22_2245.txt 2011-01-25_2209.txt
2011 2011-02-01_1623.txt 2011-02-04_1256.txt
Explanation of the Makefile rule:
Blog${YEAR}-01.txt: ${JAN}
	cat ${.ALLSRC} > ${.TARGET}
The "Blog${YEAR}-01.txt" is the target, or the file to be created.
The dependencies are the source files defined by the JAN variable 2011-01-01_1400.txt, 2011-01-22_2245.txt and 2011-01-25_2209.txt.

If the target 'Blog2011-01.txt' does not exist it will be created.
If one of it's dependent files is edited and has a newer time stamp than the target, the target will be recreated.
After adding a new blog entry file, the target will again be recreated.

Invoking make without any arguments will create or recreate if necessary, the all target, which is the first and thus default target:
$ make
cat 2011-01-01_1400.txt 2011-01-22_2245.txt 2011-01-25_2209.txt > Blog2011-01.txt
cat 2011-02-01_1623.txt 2011-02-04_1256.txt > Blog2011-02.txt
Running make for a second time:
$ make
Nothing to do, so nothing happens.

Let us now create a new blog entry and run make
$ vi 2011-02-05_0812.txt

$ make

cat 2011-02-01_1623.txt 2011-02-04_1256.txt 2011-02-05_0812.txt > Blog2011-02.txt
Because dependency 2011-02-05_0812.txt is newer than the target, the target has to be recreated.

To experiment, you can download the attachment and extract with:
$ tar xvzf pmBlog.tgz

It will create a directory 'pmBlog' (poor man Blog), the Makefile and some tiny test files to play with.
Attached Files
File Type: tgz pmBlog.tgz (664 Bytes, 29 views)
You don't need to be a genius to debug a pf.conf firewall ruleset, you just need the guts to run tcpdump
Reply With Quote