set.pl 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. # 11/01/2016
  2. # This program is free software; you can redistribute it and/or modify
  3. # it under the terms of the GNU General Public License as published by
  4. # the Free Software Foundation; either version 2 of the License, or
  5. # (at your option) any later version.
  6. # This program is distributed in the hope that it will be useful,
  7. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  8. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  9. # GNU General Public License for more details.
  10. # You should have received a copy of the GNU General Public License
  11. # along with this program; if not, write to the Free Software
  12. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  13. # MA 02110-1301, USA.
  14. use strict;
  15. use warnings;
  16. use File::Copy;
  17. use List::Util qw(any);
  18. sub re_read {
  19. my ($filename) = @_;
  20. my $derefs = $$filename;
  21. my $fh;
  22. open($fh, '<:encoding(UTF-8)', $derefs)
  23. or die "Could not open file '$derefs' $!";
  24. local $/ = undef; # <--- slurp mode
  25. my $concatArr = <$fh>;
  26. close($fh);
  27. return \$concatArr;
  28. }
  29. sub re_write {
  30. my ($filename,$concatArr) = @_;
  31. my $derefs = $$filename;
  32. my $fh;
  33. open($fh, '>:encoding(UTF-8)', $derefs)
  34. or die "Could not open file '$derefs' $!";
  35. print $fh $$concatArr;
  36. close($fh);
  37. return;
  38. }
  39. sub reflace_configure {
  40. my ($new) = @_;
  41. my $filename = "configure.ac";
  42. my @arr = split("\n",${re_read(\$filename)});
  43. if ($arr[9]) {
  44. $arr[9] = $$new;
  45. }
  46. my $concatArr = join("\n", @arr);
  47. re_write(\$filename,\$concatArr);
  48. return;
  49. }
  50. sub reflace_many {
  51. my ($arr,$filename) = @_;
  52. my $derefFilename = $$filename;
  53. my @arr2 = @$arr;
  54. my ($x,$arrLen) = (0,$#arr2);
  55. my $derefs = ${re_read(\$derefFilename)};
  56. for (; $x <= $arrLen; $x++) {
  57. $derefs =~ s/${$arr2[$x][0]}/${$arr2[$x][1]}/g;
  58. }
  59. re_write(\$derefFilename,\$derefs);
  60. return;
  61. }
  62. sub reflace_single {
  63. my ($ag1,$ag2,$filename) = @_;
  64. my $derefFilename = $$filename;
  65. my $derefs = ${re_read(\$derefFilename)};
  66. $derefs =~ s/$$ag1/$$ag2/g;
  67. re_write(\$derefFilename,\$derefs);
  68. return;
  69. }
  70. {
  71. if (-1 == $#ARGV) {
  72. die "No OS/Distro supplied.";
  73. }
  74. my $osEntered = uc $ARGV[0];
  75. my @osArr = (
  76. "ARCHLINUX","DEBIAN",
  77. "GENTOO","SLACKWARE",
  78. "RHEL","FRUGALWARE",
  79. "ANGSTROM","FREEBSD","OPENBSD"
  80. );
  81. my $hasMatch = any { $_ eq $osEntered } @osArr;
  82. if ($hasMatch eq "") {
  83. die "Invalid OS/Distro supplied.";
  84. }
  85. my $srcMake = "src/Makefile.am";
  86. my $defTits = "m4_define([cuRos],[$osEntered])";
  87. my $bsdCF = "-D_DEFAULT_SOURCE -L/usr/local/lib";
  88. my $posixCF = "-D_POSIX_C_SOURCE=200112L";
  89. my ($amStr, $srcStr, $bsdStr) = ("{amCF}","{srcFiles}","{bzdlibs}");
  90. my ($amCF, $srcToAppend, $bsdLibs) = ("", "", "");
  91. if ($osEntered eq "FREEBSD") {
  92. $bsdLibs = "-largp -ldevstat";
  93. $amCF = \$bsdCF;
  94. $defTits = "$defTits m4_define([FREEBZD], [tits])";
  95. $srcToAppend = "freebsd_functions.c include/freebzd.h";
  96. }
  97. elsif ($osEntered eq "OPENBSD") {
  98. $bsdLibs = "-largp -lossaudio";
  99. $amCF = \$bsdCF;
  100. $defTits = "$defTits m4_define([OPENBZD], [forSure])";
  101. $srcToAppend = "openbsd_functions.c include/openbzd.h";
  102. }
  103. else {
  104. $amCF = \$posixCF;
  105. $defTits = "$defTits m4_define([LINUKS], [cryMeAriver])";
  106. $srcToAppend = "linux_functions.c";
  107. }
  108. copy("src/Makefail.skel",$srcMake)
  109. or die "Could not copy src/Makefail.skel $!";
  110. reflace_configure(\$defTits);
  111. my @hugeArr = (
  112. [\$amStr, \$$amCF],
  113. [\$srcStr, \$srcToAppend],
  114. [\$bsdStr, \$bsdLibs]
  115. );
  116. reflace_many(\@hugeArr,\$srcMake);
  117. }