summaryrefslogtreecommitdiff
path: root/addconfigh.awk
blob: 55c041b31d478881a4552aff75bc55f7d72b8fe8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/usr/bin/awk -f

# This script adds
#
#          #include <config.h>
#
# before the first #include line it finds.

function do_writeout ()
{
    if (output && writeout)
	system ("mv " output " " input );
}

{
    if (FNR == 1)
    {
	do_writeout();
    
#	beginning of a file
	
	input = FILENAME;
	output = FILENAME "-new";
	n_includes = 0;
	writeout = 1;
	done = 0;
    }
}

/\#include/ {
    if (n_includes == 0 && /\#include <config.h>/)
    {
	print "skipping " FILENAME
	writeout = 0;
	
	nextfile;
    }
    
    ++n_includes;
    if (!done) {
	print "#ifdef HAVE_CONFIG_H" > output;
	print "#include <config.h>"  > output;
	print "#endif"		     > output;
	  
	done = 1;
    }
}

{
    print > output
} 


END {
    do_writeout();
}