|
| 1 | +#!/usr/bin/perl |
| 2 | + |
| 3 | +use strict; |
| 4 | +use warnings; |
| 5 | + |
| 6 | +# Installed via `cpan install File::Slurp` |
| 7 | +# Alternative `cpanm install File::Slurp` |
| 8 | +use File::Slurp qw(read_file write_file); |
| 9 | + |
| 10 | +my $tmpl_msvc_head = <<EOTMPL; |
| 11 | + <ClInclude Include="\$(LIBSASS_HEADERS_DIR)\\%s" /> |
| 12 | +EOTMPL |
| 13 | + |
| 14 | +my $tmpl_msvc_inc = <<EOTMPL; |
| 15 | + <ClInclude Include="\$(LIBSASS_INCLUDES_DIR)\\%s" /> |
| 16 | +EOTMPL |
| 17 | + |
| 18 | +my $tmpl_msvc_src = <<EOTMPL; |
| 19 | + <ClCompile Include="\$(LIBSASS_SRC_DIR)\\%s" /> |
| 20 | +EOTMPL |
| 21 | + |
| 22 | +my $tmpl_msvc_filter_head = <<EOTMPL; |
| 23 | + <ClInclude Include="\$(LIBSASS_INCLUDES_DIR)\\%s"> |
| 24 | + <Filter>Library Includes</Filter> |
| 25 | + </ClInclude> |
| 26 | +EOTMPL |
| 27 | + |
| 28 | +my $tmpl_msvc_filter_inc = <<EOTMPL; |
| 29 | + <ClInclude Include="\$(LIBSASS_INCLUDES_DIR)\\%s"> |
| 30 | + <Filter>LibSass Headers</Filter> |
| 31 | + </ClInclude> |
| 32 | +EOTMPL |
| 33 | + |
| 34 | +my $tmpl_msvc_filter_src = <<EOTMPL; |
| 35 | + <ClCompile Include="\$(LIBSASS_SRC_DIR)\\%s"> |
| 36 | + <Filter>LibSass Sources</Filter> |
| 37 | + </ClCompile> |
| 38 | +EOTMPL |
| 39 | + |
| 40 | +# parse source files directly from libsass makefile |
| 41 | +open(my $fh, "<", "../Makefile.conf") or |
| 42 | + die "../Makefile.conf not found"; |
| 43 | +my $srcfiles = join "", <$fh>; close $fh; |
| 44 | + |
| 45 | +my (@INCFILES, @HPPFILES, @SOURCES, @CSOURCES); |
| 46 | +# parse variable out (this is hopefully tolerant enough) |
| 47 | +if ($srcfiles =~ /^\s*INCFILES\s*=\s*((?:.*(?:\\\r?\n))*.*)/m) { |
| 48 | + @INCFILES = grep { $_ } split /(?:\s|\\\r?\n)+/, $1; |
| 49 | +} else { die "Did not find c++ INCFILES in libsass/Makefile.conf"; } |
| 50 | +if ($srcfiles =~ /^\s*HPPFILES\s*=\s*((?:.*(?:\\\r?\n))*.*)/m) { |
| 51 | + @HPPFILES = grep { $_ } split /(?:\s|\\\r?\n)+/, $1; |
| 52 | +} else { die "Did not find c++ HPPFILES in libsass/Makefile.conf"; } |
| 53 | +if ($srcfiles =~ /^\s*SOURCES\s*=\s*((?:.*(?:\\\r?\n))*.*)/m) { |
| 54 | + @SOURCES = grep { $_ } split /(?:\s|\\\r?\n)+/, $1; |
| 55 | +} else { die "Did not find c++ SOURCES in libsass/Makefile.conf"; } |
| 56 | +if ($srcfiles =~ /^\s*CSOURCES\s*=\s*((?:.*(?:\\\r?\n))*.*)/m) { |
| 57 | + @CSOURCES = grep { $_ } split /(?:\s|\\\r?\n)+/, $1; |
| 58 | +} else { die "Did not find c++ CSOURCES in libsass/Makefile.conf"; } |
| 59 | + |
| 60 | +sub renderTemplate($@) { |
| 61 | + my $str = "\n"; |
| 62 | + my $tmpl = shift; |
| 63 | + foreach my $inc (@_) { |
| 64 | + $str .= sprintf($tmpl, $inc); |
| 65 | + } |
| 66 | + $str .= " "; |
| 67 | + return $str; |
| 68 | +} |
| 69 | + |
| 70 | +@INCFILES = map { s/\//\\/gr } @INCFILES; |
| 71 | +@HPPFILES = map { s/\//\\/gr } @HPPFILES; |
| 72 | +@SOURCES = map { s/\//\\/gr } @SOURCES; |
| 73 | +@CSOURCES = map { s/\//\\/gr } @CSOURCES; |
| 74 | + |
| 75 | +my $targets = read_file("build-skeletons/libsass.targets"); |
| 76 | +$targets =~s /\{\{includes\}\}/renderTemplate($tmpl_msvc_inc, @INCFILES)/eg; |
| 77 | +$targets =~s /\{\{headers\}\}/renderTemplate($tmpl_msvc_head, @HPPFILES)/eg; |
| 78 | +$targets =~s /\{\{sources\}\}/renderTemplate($tmpl_msvc_src, @SOURCES, @CSOURCES)/eg; |
| 79 | +warn "Generating ../win/libsass.targets\n"; |
| 80 | +write_file("../win/libsass.targets", $targets); |
| 81 | + |
| 82 | +my $filters = read_file("build-skeletons/libsass.vcxproj.filters"); |
| 83 | +$filters =~s /\{\{includes\}\}/renderTemplate($tmpl_msvc_filter_inc, @INCFILES)/eg; |
| 84 | +$filters =~s /\{\{headers\}\}/renderTemplate($tmpl_msvc_filter_head, @HPPFILES)/eg; |
| 85 | +$filters =~s /\{\{sources\}\}/renderTemplate($tmpl_msvc_filter_src, @SOURCES, @CSOURCES)/eg; |
| 86 | +warn "Generating ../win/libsass.vcxproj.filters\n"; |
| 87 | +write_file("../win/libsass.vcxproj.filters", $filters); |
| 88 | + |
0 commit comments