diff options
Diffstat (limited to 'v4l')
-rw-r--r-- | v4l/Makefile | 54 | ||||
-rwxr-xr-x | v4l/scripts/make_makefile.pl | 257 |
2 files changed, 162 insertions, 149 deletions
diff --git a/v4l/Makefile b/v4l/Makefile index cd3c8312c..6afa117e2 100644 --- a/v4l/Makefile +++ b/v4l/Makefile @@ -37,12 +37,49 @@ default:: config-compat.h Makefile.media links .version ################################################# # Object specific rules --include $(obj)/.kconfig.dep +# Targets which don't need Makefile.media's rules +no-makefile-media-targets := %config clean distclean release snapshot snap \ + tarball release %links start insmod load stop rmmod unload reload \ + card% update push %commit help debug ivtv% cx88-ivtv lxdialog + +# Targets which don't need .myconfig to exist, to keep us from including it +no-dot-config-targets := $(no-makefile-media-targets) %install remove + +dot-config := 1 +ifneq ($(filter $(no-dot-config-targets), $(MAKECMDGOALS)),) + ifeq ($(filter-out $(no-dot-config-targets), $(MAKECMDGOALS)),) + dot-config := 0 + endif +endif + +makefile-media := 1 +ifneq ($(filter $(no-makefile-media-targets), $(MAKECMDGOALS)),) + ifeq ($(filter-out $(no-makefile-media-targets), $(MAKECMDGOALS)),) + makefile-media := 0 + endif +endif + +ifeq ($(dot-config),1) -include $(obj)/.myconfig +endif + +ifeq ($(makefile-media),1) -include $(obj)/Makefile.media -include $(obj)/Makefile.sound +endif + +-include $(obj)/.kconfig.dep -include $(obj)/Makefile.ivtv +# make will try to automatically rebuild the Makefile and all includes, +# and if any of them change, make will start over with the updated files + +# If it doesn't exist, this rule will build Makefile.media. If it does +# exist, it will have dependency information in it, and only be rebuilt +# when necessary. +Makefile.media: + scripts/make_makefile.pl + ################################################# # CFLAGS configuration @@ -132,7 +169,7 @@ export LC_ALL ################################################# # all file compilation rule -all:: allmodconfig default +all:: default ################################################# # installation invocation rules @@ -155,9 +192,6 @@ else @uname -r|perl -ne 'if (/^([0-9]*)\.([0-9])*\.([0-9]*)(.*)$$/) { printf ("VERSION=%s\nPATCHLEVEL:=%s\nSUBLEVEL:=%s\nKERNELRELEASE:=%s.%s.%s%s\n",$$1,$$2,$$3,$$1,$$2,$$3,$$4); };' > $(obj)/.version endif -Makefile.media:: .version - scripts/make_makefile.pl $(KDIR) - release:: ifneq ($(VER),) @echo "Forcing compiling to version $(VER)." @@ -263,6 +297,13 @@ LXDIALOG_DIR := $(shell if [ -d $(KDIR)/scripts/kconfig/lxdialog ]; then echo kc LXDIALOG_LNK := $(if $(LXDIALOG_DIR),scripts/kconfig,scripts/lxdialog) LXDIALOG := $(KDIR)/scripts/$(LXDIALOG_DIR)lxdialog/lxdialog +# Rule to make a .config if one doesn't exist +# Ideally, some kind of oldconfig process would be used +.config: .version + @echo "Creating default .config file" + ./scripts/make_kconfig.pl $(KDIR) + @touch .config + .myconfig: .config Kconfig ./scripts/make_myconfig.pl @@ -281,8 +322,7 @@ config:: links $(CONF) Kconfig menuconfig:: links $(MCONF) lxdialog Kconfig $(MCONF) Kconfig -allyesconfig allmodconfig:: links .version - @echo "Creating default .config file" +allyesconfig allmodconfig:: .version ./scripts/make_kconfig.pl $(KDIR) 1 # rule to build kernel conf programs diff --git a/v4l/scripts/make_makefile.pl b/v4l/scripts/make_makefile.pl index e0a099e9b..f49edb0f8 100755 --- a/v4l/scripts/make_makefile.pl +++ b/v4l/scripts/make_makefile.pl @@ -1,186 +1,159 @@ #!/usr/bin/perl use FileHandle; -my $kernel=shift; -my $instdir = (); - +my %instdir = (); + +# Take a Makefile line of the form: +# obj-XXXXX = some_directory/ some_module.o +# +# All directories are processed by including the referenced Makefile and +# removing the directory. The modules are added to the list of modules +# to install. Prints the edited line to OUT. +# Arguments: directory Makefile is in, the objects, original line(s) from +# Makefile (with newlines intact). sub check_line($$$) { - my $dir=shift; - my $obj=shift; - my $arg=shift; - my $arg2=""; - - my $idir = $dir; - - $idir =~ s|^../linux/drivers/media/||; - - $arg=$arg." "; - - while ($arg ne "") { - if ($arg =~ m|^([^ /]+)/ |) { - my $newdir=$1; -# print "include $dir/$newdir/Makefile\n"; - open_makefile("$dir/$newdir/Makefile"); - $arg =~ s/^[^ ]+ //; - } else { - $arg =~ s/^([^ ]+ )//; - my $cur=$1; - $arg2 = $arg2.$cur; - - $cur =~ s/\s+$//; - $cur =~ s/\\$//; - $cur =~ s/\s+$//; - $cur =~ s/\.o$/.ko/; - - if ( ($cur ne "") && (! ($instdir { $idir } =~ m/($cur) /))) { - $instdir { $idir } = $instdir { $idir }.$cur." "; - } + my $dir = shift; + my $objs = shift; + my $orig = shift; + my $count = 0; + + foreach(split /\s+/, $objs) { + if (m|/$|) { # Ends in /, means it's a directory + # Delete this directory from original Makefile line + $orig =~ s/$_[ \t]*//; + $_ .= 'Makefile'; + # print STDERR "open new makefile $dir/$_\n"; + open_makefile("$dir/$_"); + next; } + + # It's a file, add it to list of files to install + s/\.o$/.ko/; + my $idir = $dir; + $idir =~ s|^../linux/drivers/media/||; + $instdir{$idir}{$_} = 1; + $count++; } - $arg2 =~ s/\s+$//; - if ($arg2 ne "") { -# print "arg=$arg2\n"; - print OUT "$obj$arg2\n"; - } + # Removing any tailling whitespace, just to be neat + $orig =~ s/[ \t]+$//mg; + + # Print out original line, less directories, if there is anything + # still there + print OUT $orig if($count); } +# Uses the string being assigned from a line of the form: +# EXTRA_CFLAGS += -Idrivers/media/something -Dwhatever +# +# All the -Idrivers/media/something options get deleted. All the source +# files are linked into the v4l directory and built from there, so and -I +# option for them is unnecessary. The line is printed to OUT if there is +# anything left after that. sub remove_includes($$) { - my $obj=shift; - my $arg=shift; - my $arg2=""; - - $arg=$arg." "; - - while ($arg ne "") { - if (!$arg =~ m|^(-I\s*[^ ]+) |) { - $arg2 = $arg2.$1; - $arg =~ s|^[^ ] ||; - } else { - $arg =~ s|^(-I\s*[^ ]+) ||; + my $flags = shift; + my $orig = shift; + my $count = 0; + + foreach(split /\s+/, $flags) { + if (m|^-Idrivers/media|) { + # Remove any -I flags from original Makefile line + $orig =~ s/$_[ \t]*//; + next; } + $count++; # Something wasn't deleted } - if ($arg2 ne "") { - print OUT "$obj$arg2\n"; - } + $orig =~ s/[ \t]+$//mg; + + # Print out original line if there is anything we didn't delete + print OUT $orig if($count); } sub open_makefile($) { - my $file= shift; + my $file = shift; my $in = new FileHandle; - my $dir= ""; - my $count=0; + my $orig; - $file=~ m|^(.*)/[^/]*$|; - $dir=$1; + $file =~ m|^(.*)/[^/]*$|; + my $dir = $1; -#print "opening $file (dir=$dir)\n"; - open $in,"$file"; + # print STDERR "opening $file (dir=$dir)\n"; + open $in, $file; while (<$in>) { - if (m|\s*#|) { + # print STDERR "Line: $_"; + # Skip comment lines + if (/^\s*#/) { print OUT $_; next; } - if (m|^\s*include|) { - next; + m/^\s*-?include/ and die "Can't handle includes! In $file"; + + # Handle line continuations + if (/\\\n$/) { + $_ .= <$in>; + redo; } - if (count==1 || m|(^\s*EXTRA_CFLAGS.*=\s*)(.*/.*)\n|) { - remove_includes($1,$2); - if (m|[\\]\n|) { - $count=1; - } else { - $count=0; - } + + # $orig is what we will print, $_ is what we will parse + $orig = $_; + # Eat line continuations in string we will parse + s/\s*\\\n\s*/ /g; + # Eat comments + s/#.*$//; + + if (/^\s*obj-.*:?=\s*(\S.*?)\s*$/) { + # print STDERR "obj matched '$1'\n"; + check_line($dir, $1, $orig); # will print line for us next; } -# if (m|(^\s*obj.*=\s*)(.*/.*)\n|) { - if (count==2 || m|(^\s*obj.*=\s*)(.*)\n|) { - check_line($dir,$1,$2); - if (m|\\\n|) { - $count=1; - } else { - $count=0; - } + if (/^\s*EXTRA_CFLAGS\s+\+?=\s*(\S.*?)\s*$/) { + # print STDERR "cflags matched '$1'\n"; + remove_includes($1, $orig); # will print line for us next; } - print OUT $_; + print OUT $orig; } close $in; } -open OUT,">Makefile.media.new"; -open_makefile ("../linux/drivers/media/Makefile"); +open OUT, '>Makefile.media' or die 'Unable to write Makefile.media'; +open_makefile('../linux/drivers/media/Makefile'); # Creating Install rule -printf OUT "media-install::\n"; -printf OUT "\t\@echo \"Stripping debug info from files:\"\n"; -printf OUT "\t\@strip --strip-debug \$(inst-m)\n\n"; - -while ( my ($key, $value) = each(%instdir) ) { - printf OUT "\t\@echo -e \"\\nInstalling \$(KDIR26)/$key files:\"\n"; - printf OUT "\t\@install -d \$(KDIR26)/$key\n"; - - printf OUT "\t\@files='$value'; "; - printf OUT "for i in \$\$files;do if [ -e \$\$i ]; then echo -n \"\$\$i \";"; - printf OUT " install -m 644 -c \$\$i \$(KDIR26)/$key; fi; done; echo;\n\n"; +print OUT "media-install::\n"; +print OUT "\t\@echo \"Stripping debug info from files:\"\n"; +print OUT "\t\@strip --strip-debug \$(inst-m)\n\n"; + +while (my ($dir, $files) = each %instdir) { + print OUT "\t\@echo -e \"\\nInstalling \$(KDIR26)/$dir files:\"\n"; + print OUT "\t\@install -d \$(KDIR26)/$dir\n"; + print OUT "\t\@for i in ", join(' ', keys %$files), ";do "; + print OUT "if [ -e \"\$\$i\" ]; then echo -n \"\$\$i \";"; + print OUT " install -m 644 -c \$\$i \$(KDIR26)/$dir; fi; done; echo;\n\n"; } -printf OUT "\t/sbin/depmod -a \${KERNELRELEASE}\n\n"; +print OUT "\t/sbin/depmod -a \${KERNELRELEASE}\n\n"; # Creating Remove rule -printf OUT "media-rminstall::\n"; -printf OUT "\t\@echo -e \"\\nRemoving old \$(DEST) files\\n\"\n"; +print OUT "media-rminstall::\n"; +print OUT "\t\@echo -e \"\\nRemoving old \$(DEST) files\\n\"\n"; -while ( my ($key, $value) = each(%instdir) ) { - printf OUT "\t\@echo -e \"\\nRemoving old \$(KDIR26)/$key files:\"\n"; - printf OUT "\t\@files='$value'; "; +while ( my ($dir, $files) = each(%instdir) ) { + print OUT "\t\@echo -e \"\\nRemoving old \$(KDIR26)/$dir files:\"\n"; + print OUT "\t\@files='", join(' ', keys %$files), "'; "; - printf OUT "for i in \$\$files;do if [ -e \$(KDIR26)/$key/\$\$i ]; then "; - printf OUT "echo -n \"\$\$i \";"; - printf OUT " rm \$(KDIR26)/$key/\$\$i; fi; done; "; + print OUT "for i in \$\$files;do if [ -e \$(KDIR26)/$dir/\$\$i ]; then "; + print OUT "echo -n \"\$\$i \";"; + print OUT " rm \$(KDIR26)/$dir/\$\$i; fi; done; "; - printf OUT "for i in \$\$files;do if [ -e \$(KDIR26)/$key/\$\$i.gz ]; then "; - printf OUT "echo -n \"\$\$i.gz \";"; - printf OUT " rm \$(KDIR26)/$key/\$\$i.gz; fi; done; echo;\n\n"; + print OUT "for i in \$\$files;do if [ -e \$(KDIR26)/$dir/\$\$i.gz ]; then "; + print OUT "echo -n \"\$\$i.gz \";"; + print OUT " rm \$(KDIR26)/$dir/\$\$i.gz; fi; done; echo;\n\n"; } +# Print dependencies of Makefile.media +print OUT "Makefile.media: ../linux/drivers/media/Makefile \\\n"; +print OUT join(" \\\n", map("\t../linux/drivers/media/$_/Makefile", keys %instdir)); +print OUT "\n"; close OUT; - -while ( my ($key, $value) = each(%config) ) { - delete $depend{$key}; -} - -open OUT,">Kconfig.kern"; -while ( my ($key, $value) = each(%depend) ) { - print OUT "# $key with $value refs\nconfig $key\n\ttristate\n\tdefault m\n\n"; -} -close OUT; - -if (open IN,"Makefile.media") { - close IN; - my $changed=0; - if (open IN,"diff Makefile.media Makefile.media.new|") { - while (<IN>) { - if ($_ ne "") { - $changed=1; - } - } - close IN; - if ($changed) { - printf("One or more linux Makefiles had changed. Makefile.media rewrited.\n"); - system ("mv Makefile.media.new Makefile.media"); - } else { - system ("rm Makefile.media.new"); - } - } -} else { - printf("Creating Makefile.media.\n"); - system "mv Makefile.media.new Makefile.media"; -} - -if (open IN,".myconfig") { - close IN; -} else { - system "./scripts/make_kconfig.pl $kernel 1"; -} |