#!/usr/bin/env perl my $Configuration = 'Config.txt'; my $MakeTemplate = 'MakeTemplate.txt'; my $mgen = "MakefileGeneration"; # read the config file to an assoc array open(CONFIG, $Configuration) || die "$mgen> Couldn't open the Configuration file!\n"; my %config = (); my $curSection = ''; my $delimName = '\.SECTION\s*\(\s*(\w+)\s*\)\s*(\(\s*\w+\s*=\s*<\s*[a-zA-Z\/\\\.:]+\s*>\s*\))'; my %modifiers = (); #my %modifiers = {'targetdir', '.', 'mod1', ''} some #defaults, such as current directory and so on. my $curSectionOpt; my $something; while() { if (/$delimName/) { $curSection = $1; $modifiers{$curSection} = $2; } else{ $config{$curSection} .= $_; } } close CONFIG; my @mytypes = ('DEFAULT','BEH'); # just an example open(TARGETMAKEFILE,">"); open(MAKETEMPLATE, $MakeTemplate) || die "$mgen> Couldn't open the Makefile Template file!\n"; my $copyOn = 0; while(//g){ grep(print,keys(%modifiers)); # print("\n\n"); grep(print,values(%modifiers)); # print("\n\n\n"); } while() { if (/$delimName/){ my $section = $1; $copyOn = grep(/$section/i,@mytypes); print TARGETMAKEFILE $config{$section} if $copyOn; } elsif ($copyOn) { print TARGETMAKEFILE; } } close MAKETEMPLATE;