⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 genmake.pl

📁 mini http server,可以集成嵌入到程序中,实现简单的web功能
💻 PL
📖 第 1 页 / 共 2 页
字号:
#!/usr/bin/perl

#*____________________________________________________________________________*\
#*
#
# Copyright (c) 1997-2003 John Roy, Holger Zimmermann. All rights reserved.
#
# These sources, libraries and applications are
# FREE FOR COMMERCIAL AND NON-COMMERCIAL USE
# as long as the following conditions are adhered to.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# 1. Redistributions of source code must retain the above copyright
#    notice, this list of conditions and the following disclaimer. 
#
# 2. Redistributions in binary form must reproduce the above copyright
#    notice, this list of conditions and the following disclaimer in
#    the documentation and/or other materials provided with the
#    distribution.
#
# 3. The name of the author may not be used to endorse or promote products
#    derived from this software without specific prior written permission. 
#
# THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
# WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
# IN NO EVENT SHALL THE AUTHORS OR ITS CONTRIBUTORS BE LIABLE FOR ANY
# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
# GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
# OF THE POSSIBILITY OF SUCH DAMAGE.
#
#*____________________________________________________________________________*|
#*
#* $Source: /cvsroot/pi3web/Pi3Web_200/Source/Scripts/genmake.pl,v $
#* $Date: 2003/05/13 18:42:17 $
#*
# Description:
#	Generate makefiles based on templates
#*____________________________________________________________________________*/

#/*___________________________________________________________________________*\
# Global declarations:
#\*___________________________________________________________________________*/
%Names;
$name_index = 0;
@subdirs;
@all_targets;
@clean_targets;
@genmake_targets;
$line = 0;
$libpath;
$ifstate = 0;
$condition = 1;

$config_ld;
$config_ld_shared;
$config_archive;
$config_objextn;
$config_fulllib;
$config_linklib;
$config_libpath;
$config_cmdseperator;

$_=$0; s/genmake\.pl//i; $scriptdir=$_;
$basedir = $scriptdir.'..';
&toplevel( "./Config.in", "./Makefile", $scriptdir );
exit 0;

#/*___________________________________________________________________________*\
# *
# Function:
# Synopsis:
# Description:
#\*___________________________________________________________________________*/
sub toplevel
	{
	local( $infile, $outfile, $scriptdir ) = @_;
	local( $tmp );
	open( INP, $infile ) || die "Can't open file $infile: $!\n";
	$_ = $ENV{"PWD"} || `cd` || `pwd`;
	s/\n//;
	$current_directory = $_;
	print "\ngenmake.pl: In $current_directory";
	print "\ngenmake.pl: Generating makefile '$outfile' using '$infile'\n\n";
	open( OUT, '>'.$outfile ) || die "Can't open file $outfile: $!\n";
	print OUT '#*____________________________________________________________________________*\
#*
#	*** AUTOMATICALLY GENERATED FILE: DO NOT MODIFY ***
#*____________________________________________________________________________*/

#
# Read global configuration
';
#	open( CONFIG_MAK, "<$scriptdir".'/config.mak' ) || die
	open( CONFIG_MAK, "<$basedir".'/config.mak' ) || die
		"Could not open file $basedir".'/config.mak'."\n";
	print OUT "# This makefile was generated from '$basedir/config.mak'\n";
	while( <CONFIG_MAK> )
		{
		#
		# echo out the contents of config.mak into the makefile 
		print OUT $_;
		};

	print OUT $tmp;

	#
	# Read some values from config.mak
	#
	open( CFG, '<'.$basedir.'/config.mak' )
		|| die "Cannot open $basedir.'/config.mak': $!\n";

	while( <CFG> )
		{
		if ( /.*CONFIG_OBJEXTN=.*/ )
			{ s/.*CONFIG_OBJEXTN=(.*)\n$/$1/; $config_objextn=$_; }
		elsif ( /.*CONFIG_ARCHIVE=.*/ )
			{ s/.*CONFIG_ARCHIVE=(.*)\n$/$1/; $config_archive=$_; }
		elsif ( /.*CONFIG_LIBPATH=.*/ )
			{ s/.*CONFIG_LIBPATH=(.*)\n$/$1/; $config_libpath=$_; }
		elsif ( /.*CONFIG_FULLLIB=.*/ )
			{ s/.*CONFIG_FULLLIB=(.*)\n$/$1/; $config_fulllib=$_; }
		elsif ( /.*CONFIG_LINKLIB=.*/ )
			{ s/.*CONFIG_LINKLIB=(.*)\n$/$1/; $config_linklib=$_; }
		elsif ( /.*CONFIG_LD=.*/ )
			{ s/.*CONFIG_LD=(.*)\n$/$1/; $config_ld=$_; }
		elsif ( /.*CONFIG_LD_SHARED=.*/ )
			{ s/.*CONFIG_LD_SHARED=(.*)\n$/$1/; $config_ld_shared=$_; }
		elsif ( /.*CMD_SEPERATOR=.*/ )
			{ s/.*CMD_SEPERATOR=(.*)\n$/$1/; $config_cmdseperator=$_; }
		};
	close( CFG );

	print OUT '

CC=$(CONFIG_CC)
CXX=$(CONFIG_CXX)

.SUFFIXES: ';
	print OUT $config_objextn.' .cpp .cc

CFLAGS=$(CONFIG_CCOPTIMIZE) $(CONFIG_THREADED) $(CONFIG_CCNDEBUG) $(CONFIG_CCDEBUG) $(CONFIG_OS)
CXXFLAGS=$(CONFIG_CXXOPTIMIZE) $(CONFIG_THREADED) $(CONFIG_CXXNDEBUG) $(CONFIG_CXXDEBUG) $(CONFIG_OS)

default: all

';
	while(<INP>)
		{
		$_ = &processline( $_ );
		if ( /^#if\s*(.*)/ )
			{
			(!$ifstate) || die
				"Nested '#if' statements are not supported!\n";
			$condition = eval $1;
			$ifstate = 1;
			}
		elsif ( /^#elsif\s*$/ )
			{
			($ifstate eq 1) || die
				"Syntax error: '#elsif' without '#if' statement!\n";
			$ifstate = 2;
			$condition = !$condition;
			}
		elsif ( /^#endif\s*$/ )
			{
			($ifstate) || die
				"Syntax error: '#endif' without '#if' or '#elsif' statement!\n";
			$ifstate = 0;
			$condition = 1;
			}
		elsif ( /^(\s)*#/ )
			{ next; }
		elsif ( /\<subdirs\>*/i )
			{ $condition || next; &subdirectories( INP, 'all' ); }
		elsif( /\<target\>/i )
			{ $condition || next; &target( INP ); }
		elsif( /\<global\>/i )
			{ $condition || next; &global( INP );}
		next;
		};

	print OUT "\nall: @all_targets\n";

	print OUT "\ngenmake: @genmake_targets\n";

	print OUT "\nclean: @clean_targets\n";
print OUT <<END;
	\$(CMD_RM) *.dbg
	\$(CMD_RM) *.o
	\$(CMD_RM) *.obj
	\$(CMD_RM) *.exe
	\$(CMD_RM) *.so
	\$(CMD_RM) *.dll
	\$(CMD_RM) *.a
	\$(CMD_RM) *.pch 
	\$(CMD_RM) *.lib
	\$(CMD_RM) *.bak
	\$(CMD_RM) make.out
	\$(CMD_RM) core
	\$(CMD_RM) out.lst
	\$(CMD_RM) *.tmp* 
	\$(CMD_RM) *.pdb
	\$(CMD_RM) *.pch
	\$(CMD_RM) *.plg
	\$(CMD_RM) vc40.*
	\$(CMD_RM) *.idb
	\$(CMD_RM) *.ilk
	\$(CMD_RM) *.exp
	\$(CMD_RM) *.def 
	\$(CMD_RM) so_locations
	\$(CMD_RM) *.map
	\$(CMD_RM) *.res
	\$(CMD_RM) *.dws
	\$(CMD_RM) *.obr 
END
#	print OUT '$(CMD_RM) *.dbg *.o *.obj *.exe *.so *.dll *.a *.pch '."\n\t"; 
#	print OUT '$(CMD_RM) *.lib *.bak make.out core out.lst *.tmp* '."\n\t";
#	print OUT '$(CMD_RM) *.pdb *.pch vc40.* *.idb *.ilk *.exp *.def '."\n\t";
#	print OUT '$(CMD_RM) so_locations *.map *.res *.dws *.obr '."\n";
	print OUT "\n";

	print OUT "\ndist_clean: clean\n";
	print OUT "\t";
	print OUT '$(CMD_RM) Makefile'."\n\t"; 
	print OUT "\n";

#2unix:';
#	$tmp ="\n\t";
#	$tmp .= `cat $scriptdir/sed.txt` unless $^O =~ /MSWin32/;
#	print OUT $tmp;

	print OUT "\n".'.cpp'.$config_objextn.':
	$(CXX) -c $(CXXFLAGS) $(LOCAL_CXXFLAGS) $(PIINCLUDE) $<

';
	print OUT "\n".'.c'.$config_objextn.':
	$(CC) -c $(CFLAGS) $(LOCAL_CFLAGS) $(PIINCLUDE) $<

';
	print OUT "\n".'.cc'.$config_objextn.':
	$(CXX) -c $(CXXFLAGS) $(LOCAL_CXXFLAGS) $(PIINCLUDE) $<

';

	close( INP );
	close( OUT );
	};

#/*___________________________________________________________________________*\
# *
# Function:
# Synopsis:
# Description:
#\*___________________________________________________________________________*/
sub subdirectories
	{
	( $filehandle, $target ) = @_;
	local( $subdir_target, $build, @local_subdirs );
	$build='$(MAKE)';
	$subdir_target = $target;
	while( <$filehandle> )
		{
		$_ = &processline( $_ );
		if ( /^#if\s*(.*)/ )
			{
			(!$ifstate) || die
				"Nested '#if' statements are not supported!\n";
			$condition = eval $1;
			$ifstate = 1;
			}
		elsif ( /^#elsif\s*$/ )
			{
			($ifstate eq 1) || die
				"Syntax error: '#elsif' without '#if' statement!\n";
			$ifstate = 2;
			$condition = !$condition;
			}
		elsif ( /^#endif\s*$/ )
			{
			($ifstate) || die
				"Syntax error: '#endif' without '#if' or '#elsif' statement!\n";
			$ifstate = 0;
			$condition = 1;
			}
		elsif ( /^(\s)*#/ )
			{ next; }
		elsif ( /\<\/subdirs\>*/i )
			{
			$condition || next; 
			local( $tmp );
			foreach $tmp ( @local_subdirs )
				{ print OUT "\tcd $tmp $config_cmdseperator $build $subdir_target $config_cmdseperator cd ..\n"; };
			push( @subdirs, @local_subdirs );
			return;
			}
		elsif ( /^build*=*/i )
			{ $condition || next; s/^build*=//i; $build = $_; }
		elsif ( /^target*=*/i )
			{ $condition || next; s/^target*=//i; $subdir_target = $_; }
		elsif ( /\<\/.*/ )
			{ print OUT "Expecting </subdirs> at line $line\n"; }
		elsif ( /^subdirs\s*=/i )
			{
			$condition || next;
			s/^subdirs\s*=//i;
			s/\s\s/ /g;
			push( @local_subdirs, split( /\s/, $_ ) );
			}
		else
			{ die "Unknown attribute $_\n"; };
		next;
		};	
	print OUT "\n";
	return;
	};

#/*___________________________________________________________________________*\
# *
# Function:
# Synopsis:

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -