#!/usr/bin/perl -w #Author jun.luo sumedia 2013/10/9 use strict; use warnings; use Getopt::Long; use vars qw($MKName $help $RootPath @MKOutput); GetOptions( "makefile_project|M=s" => \$MKName, "root_path|R=s" => \$RootPath, "help|h" => \$help, ); sub Output2File($\@) { my ($Outfile, $Content) = @_; open(OUTFILE, ">./tempFile") || die "$!\n"; # open file. my $cur = 0; my $items_count = @$Content; #Out put to given file while ($cur++ < $items_count) { print OUTFILE shift @$Content; } close(OUTFILE); #if content has changed, cover the origin file system "cmp -s $Outfile ./tempFile && rm -f ./tempFile || mv ./tempFile $Outfile"; } if (!defined $MKName ||!defined $RootPath) { print "Parameter Error!\n"; exit 1; } push(@MKOutput, "# This file is auto generated by $0, don't modify~~ \n\n"); push(@MKOutput, "\nROOT_DIR:=$RootPath\n"); push(@MKOutput, "include \$(ROOT_DIR)/env.conf\n\n"); push(@MKOutput, "CFLAGS_TMP = CFLAGS\n"); push(@MKOutput, "\n"); push(@MKOutput, "ifeq (\$(VERSION).\$(PATCHLEVEL).\$(SUBLEVEL), \$(filter \$(VERSION).\$(PATCHLEVEL).\$(SUBLEVEL),2.6.27 2.6.35 3.0.8))\n"); push(@MKOutput, " CFLAGS_TMP = EXTRA_CFLAGS\n"); push(@MKOutput, "endif\n"); push(@MKOutput, "\n"); push(@MKOutput, "ifneq (\$(filter drivers kernel,\$(subst /, ,\$(CURDIR))),)\n"); push(@MKOutput, " ifeq (\$(filter aps,\$(subst /, ,\$(CURDIR))), aps)\n"); push(@MKOutput, " \$(error both aps and drivers found???)\n"); push(@MKOutput, " else\n"); push(@MKOutput, " # include by driver\n"); push(@MKOutput, " \$(CFLAGS_TMP) += -include project.h\n"); push(@MKOutput, " endif\n"); push(@MKOutput, "else\n"); push(@MKOutput, " ifeq (\$(filter aps,\$(subst /, ,\$(CURDIR))), aps)\n"); push(@MKOutput, " # include by ap\n"); push(@MKOutput, " APSDIR=\$(shell echo `pwd` | sed 's/aps\\/.*/aps/g')\n"); push(@MKOutput, " \$(CFLAGS_TMP) += -include \$(APSDIR)/include/project.h\n"); push(@MKOutput, " else\n"); push(@MKOutput, " # include by quickbuild\n"); push(@MKOutput, " ifneq (\$(filter qb,\$(subst /, ,\$(CURDIR))), qb)\n"); push(@MKOutput, " #\$(error aps, drivers and qb not found???)\n"); push(@MKOutput, " endif\n"); push(@MKOutput, " endif\n"); push(@MKOutput, "endif\n"); Output2File($MKName, @MKOutput); exit 0;