parser.pl 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #!/usr/bin/perl -w
  2. #Author jun.luo sumedia 2013/10/9
  3. use strict;
  4. use warnings;
  5. use Getopt::Long;
  6. use vars qw($MKName $help $RootPath @MKOutput);
  7. GetOptions(
  8. "makefile_project|M=s" => \$MKName,
  9. "root_path|R=s" => \$RootPath,
  10. "help|h" => \$help,
  11. );
  12. sub Output2File($\@)
  13. {
  14. my ($Outfile, $Content) = @_;
  15. open(OUTFILE, ">./tempFile") || die "$!\n"; # open file.
  16. my $cur = 0;
  17. my $items_count = @$Content;
  18. #Out put to given file
  19. while ($cur++ < $items_count)
  20. {
  21. print OUTFILE shift @$Content;
  22. }
  23. close(OUTFILE);
  24. #if content has changed, cover the origin file
  25. system "cmp -s $Outfile ./tempFile && rm -f ./tempFile || mv ./tempFile $Outfile";
  26. }
  27. if (!defined $MKName ||!defined $RootPath)
  28. {
  29. print "Parameter Error!\n";
  30. exit 1;
  31. }
  32. push(@MKOutput, "# This file is auto generated by $0, don't modify~~ \n\n");
  33. push(@MKOutput, "\nROOT_DIR:=$RootPath\n");
  34. push(@MKOutput, "include \$(ROOT_DIR)/env.conf\n\n");
  35. push(@MKOutput, "CFLAGS_TMP = CFLAGS\n");
  36. push(@MKOutput, "\n");
  37. push(@MKOutput, "ifeq (\$(VERSION).\$(PATCHLEVEL).\$(SUBLEVEL), \$(filter \$(VERSION).\$(PATCHLEVEL).\$(SUBLEVEL),2.6.27 2.6.35 3.0.8))\n");
  38. push(@MKOutput, " CFLAGS_TMP = EXTRA_CFLAGS\n");
  39. push(@MKOutput, "endif\n");
  40. push(@MKOutput, "\n");
  41. push(@MKOutput, "ifneq (\$(filter drivers kernel,\$(subst /, ,\$(CURDIR))),)\n");
  42. push(@MKOutput, " ifeq (\$(filter aps,\$(subst /, ,\$(CURDIR))), aps)\n");
  43. push(@MKOutput, " \$(error both aps and drivers found???)\n");
  44. push(@MKOutput, " else\n");
  45. push(@MKOutput, " # include by driver\n");
  46. push(@MKOutput, " \$(CFLAGS_TMP) += -include project.h\n");
  47. push(@MKOutput, " endif\n");
  48. push(@MKOutput, "else\n");
  49. push(@MKOutput, " ifeq (\$(filter aps,\$(subst /, ,\$(CURDIR))), aps)\n");
  50. push(@MKOutput, " # include by ap\n");
  51. push(@MKOutput, " APSDIR=\$(shell echo `pwd` | sed 's/aps\\/.*/aps/g')\n");
  52. push(@MKOutput, " \$(CFLAGS_TMP) += -include \$(APSDIR)/include/project.h\n");
  53. push(@MKOutput, " else\n");
  54. push(@MKOutput, " # include by quickbuild\n");
  55. push(@MKOutput, " ifneq (\$(filter qb,\$(subst /, ,\$(CURDIR))), qb)\n");
  56. push(@MKOutput, " #\$(error aps, drivers and qb not found???)\n");
  57. push(@MKOutput, " endif\n");
  58. push(@MKOutput, " endif\n");
  59. push(@MKOutput, "endif\n");
  60. Output2File($MKName, @MKOutput);
  61. exit 0;