Skip to content

Commit 3123c70

Browse files
committed
Add utility perl script to generate MSVC source list
This makes it obsolete to keep MSVC files in sync manually whenever we add, remove or rename a source file.
1 parent 8d312a1 commit 3123c70

File tree

4 files changed

+122
-0
lines changed

4 files changed

+122
-0
lines changed

utils/README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
This directory contains some utilities that are not essential for LibSass.
2+
3+
# perl update-builds.pl
4+
5+
This will update 3rd party build files from `Makefile.conf`, which
6+
is the master index file for all required sources and headers.

utils/build-skeletons/libsass.targets

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
2+
<ItemGroup Label="LibSass Includes">{{includes}}</ItemGroup>
3+
<ItemGroup Label="LibSass Headers">{{headers}}</ItemGroup>
4+
<ItemGroup Label="LibSass Sources">{{sources}}</ItemGroup>
5+
<ItemGroup Label="LibSass Compatibility">
6+
<ClCompile Condition="$(VisualStudioVersion) &lt; 14.0" Include="$(LIBSASS_SRC_DIR)\c99func.c" />
7+
</ItemGroup>
8+
</Project>
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<ItemGroup>
4+
<Filter Include="Resources">
5+
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
6+
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
7+
</Filter>
8+
<Filter Include="Headers">
9+
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
10+
<Extensions>h;hh;hpp;hxx;hm;in;inl;inc;xsd</Extensions>
11+
</Filter>
12+
<Filter Include="Sources">
13+
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
14+
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
15+
</Filter>
16+
</ItemGroup>
17+
<ItemGroup Label="Includes">{{includes}}</ItemGroup>
18+
<ItemGroup Label="Headers">{{headers}}</ItemGroup>
19+
<ItemGroup Label="Sources">{{sources}}</ItemGroup>
20+
</Project>

utils/update-builds.pl

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
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

Comments
 (0)