sleipnir / gen_tools_am

#!/usr/bin/env perl

my $default_ggo_flags = "-u -N -e";
my %tools_ggo_flags = (
                     BNFunc => '-C -N -e',
                     BNServer => '-C -N -e',
                     Dat2Graph => '-C -N -e',
                     Explainer => '-C -N -e',
                     OntoFitter => '-C -u -N -e',
                     OntoShell => '-C -N -e',
                     OntoTrimmer => '-C -N -e',
                     );

my $tools_common_cflags1 = "\$(SLEIPNIR_CFLAGS)";
my $tools_common_cflags2 = " \$(LOG4CPP_CFLAGS) \$(PTHREAD_CFLAGS)";
my $tools_common_libs1 = "\$(SLEIPNIR_LIBS)";
my $tools_common_libs2 = " \$(LOG4CPP_LIBS) \$(PTHREAD_LIBS)";

# packages are: SMILE, SVM_PERF, READLINE, PTHREADS, BOOST, VOWPAL_WABBIT, LIBSVM
# ordering is important for linking
my %tools_other_packages = (
                            BNConverter => ['SMILE'],
                            BNCreator => ['SMILE'],
                            BNEvaluator => ['SMILE'],
                            BNServer => ['SMILE', 'BOOST'],
                            BNTester => ['SMILE'],
                            BNTruster => ['SMILE'],
                            BNUnraveler => ['SMILE'],
                            BNWeaver => ['SMILE'],
                            BNs2Txt => ['SMILE'],
                            SpeciesConnector => ['SMILE'],
#                           BNWrangler => ['SMILE'],
                            Contexter  => ['SMILE'],
                            Counter  => ['SMILE'],
                            DSLConverter  => ['SMILE'],
                            Data2DB  => ['SMILE'],
                                DBCombiner => ['SMILE'],
                                SeekTest => ['GSL'],
                                SeekReader => ['GSL'],
                                SeekEvaluator => ['GSL'],
                                SeekPrep => ['GSL'],
                                SeekMiner => ['GSL'],
                                SeekServer => ['GSL'],
                                SeekPValue => ['GSL'],
                                SeekGeneRecommender => ['GSL'],
                                SeekAggregatedDataset => ['GSL'],
                                SeekIterative => ['GSL'],
                                PCLServer => ['GSL'],
                            Dab2Dad  => ['SMILE'],
                            Dab2DB  => ['SMILE'],
                            Data2Svm => ['SVM_PERF'],
                            Edges2Posteriors => ['SMILE'],
                            MEFIT  => ['SMILE'],
                            OntoShell => ['READLINE'],
                            SVMer => ['SVM_PERF'],
                            SVMperfer => ['SVM_PERF'],
                            SVMfe => ['SVM_PERF'],
                            SVMmulticlass => ['SVM_MULTICLASS'],
                            SVMhierarchy => ['SVM_HIERARCHY'],
                            SVMperfing => ['SVM_PERF'],
                            LibSVMer => ['LIBSVM'],
                            VWer => ['VOWPAL_WABBIT'],
                            );

if (opendir(TOOLSDIR, "tools")) {
    my $dent;
    while ($dent = readdir(TOOLSDIR)) {
        next if ($dent =~ /^\.\.?$/);
        if (-d "tools/$dent") {
            if (opendir(TOOLDIR, "tools/$dent")) {
                my @src_files;
                my @header_files;
                my $ggo_file;
                my $dent2;
                while ($dent2 = readdir(TOOLDIR)) {
                    next if ($dent2 =~ /^cmdline\.[ch]$/);
                    if ($dent2 =~ /\.(c|cpp)$/) {
                        push(@src_files, $dent2);
                    } elsif ($dent2 =~ /\.h$/) {
                        push(@header_files, $dent2);
                    } elsif ($dent2 =~ /\.ggo$/) {
                        $ggo_file = $dent2;
                    }
                }
                close(TOOLDIR);
                if (open(AM_MAKEFILE, "> tools/$dent/Makefile.am")) {
                    print AM_MAKEFILE "bin_PROGRAMS = $dent\n";
                    my $extra_cflags = "";
                    my $extra_libs = "";
                    my $pkgs = $tools_other_packages{$dent};
                    for (my $i = 0; $i <= $#$pkgs; $i++) {
                        $extra_cflags .= " \$(".$pkgs->[$i]."_CFLAGS)";
                        $extra_libs .= " \$(".$pkgs->[$i]."_LIBS)";
                    }
                    print AM_MAKEFILE "AM_CPPFLAGS = ".$tools_common_cflags1.$extra_cflags.$tools_common_cflags2."\n";
                    print AM_MAKEFILE "LDADD = ".$tools_common_libs1.$extra_libs.$tools_common_libs2."\n";
#                   print AM_MAKEFILE "AM_CPPFLAGS = \$(SLEIPNIR_CFLAGS) \$(SMILE_CFLAGS) \$(SVM_PERF_CFLAGS) \$(GENGETOPT_CFLAGS) \$(LOG4CPP_CFLAGS) \$(BOOST_CFLAGS) \$(READLINE_CFLAGS)\n";
#                   print AM_MAKEFILE "LDADD = \$(SLEIPNIR_LIBS) \$(SMILE_LIBS) \$(SVM_PERF_LIBS) \$(GENGETOPT_LIBS) \$(LOG4CPP_LIBS) \$(BOOST_LIBS) \$(READLINE_LIBS)\n";
                    if ($ggo_file) {
                        print AM_MAKEFILE "\nif WITH_GENGETOPT\n";
                        print AM_MAKEFILE "gengetopt = \$(prog_gengetopt)\n";
                        print AM_MAKEFILE "BUILT_SOURCES = cmdline.c cmdline.h\n";
                        print AM_MAKEFILE "cmdline.c cmdline.h: $ggo_file\n";
#			print AM_MAKEFILE "cmdline.c: $ggo_file\n";
                        print AM_MAKEFILE "\t\$(gengetopt) -i".$ggo_file." --default-optional ";
                        if ($tools_ggo_flags{$dent}) {
                            print AM_MAKEFILE $tools_ggo_flags{$dent};
                        } else {
                            print AM_MAKEFILE $default_ggo_flags;
                        }
                        print AM_MAKEFILE "\nendif\n";
                        push(@src_files, "cmdline.c");
                        push(@header_files, "cmdline.h");
                    }
                    print AM_MAKEFILE $dent."_SOURCES = ", join(" ", @src_files), " \\\n\t", join(" ", @header_files), "\n";
                    close(AM_MAKEFILE);
                }
            } else {
                die;
            }
        }
    }
    close(TOOLSDIR);
} else {
    die;
}
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.