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

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.

Code:
# 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

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

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

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

clean:
	rm Blog${YEAR}-??.txt
The variables JAN and FEB are set to the file names for that month:
Code:
$ 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:
Code:
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:
Code:
$ 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:
Code:
$ make
Nothing to do, so nothing happens.

Let us now create a new blog entry and run make
Code:
$ 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:
Code:
$ tar xvzf pmBlog.tgz

pmBlog
pmBlog/2011-01-01_1400.txt
pmBlog/2011-01-22_2245.txt
pmBlog/2011-01-25_2209.txt
pmBlog/2011-02-01_1623.txt
pmBlog/2011-02-04_1256.txt
pmBlog/2011-02-05_0812.txt
pmBlog/Makefile
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, 75 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