Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env perl
- #
- # newdkms
- # Copyright (C) 2015 Michael Mestnik
- #
- # This program is free software: you can redistribute it and/or modify
- # it under the terms of the GNU General Public License as published by
- # the Free Software Foundation, either version 3 of the License, or
- # (at your option) any later version.
- #
- # This program is distributed in the hope that it will be useful,
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- # GNU General Public License for more details.
- #
- # You should have received a copy of the GNU General Public License
- # along with this program. If not, see <http://www.gnu.org/licenses/>.
- #
- use common::sense;
- use Getopt::Std;
- use File::Path qw(make_path remove_tree);
- use File::Copy;
- our($opt_n, $opt_v, $opt_s, $opt_H, $opt_l);
- getopts('n:v:sH:l:');
- $opt_n && $opt_v || die 'n and v requiered.';
- my $p = ($opt_s ? '/usr' : '~') . "/src/${opt_n}-${opt_v}";
- make_path("$p/patches") >= 0 || die "make_path: Failed to create $p: $!";
- my $optl = $opt_l ? "/kernel/$opt_l" : "/kernel/drivers/$opt_n";
- my $o;
- open($o, ">$p/dkms.conf") or die "Can't open dkms.conf: $!\n";
- print $o <<here;
- PACKAGE_NAME="$opt_n"
- PACKAGE_VERSION="$opt_v"
- BUILT_MODULE_NAME[0]="$opt_n"
- DEST_MODULE_LOCATION[0]="$optl"
- here
- close $o;
- open($o, ">$p/${opt_n}.c") or die "Can't open ${opt_n}.c: $!\n";
- print $o <<'here';
- /*
- *
- here
- if($opt_H){
- open my $fh, '<', \$opt_H or die $!;
- print $o qq{ *${("\n"," $_")[$_ ne '']}}
- while (<$fh>);
- close $fh;
- } else { print $o " * \n"; }
- print $o <<'here';
- *
- */
- here
- close $o;
- copy("$p/${opt_n}.c","$p/${opt_n}.h") or die "Can't copy ${opt_n}.c: $!\n";
- my $_optn = $opt_n;
- $_optn =~ y/-/_/s;
- my $u_optn = uc$_optn;
- open($o, ">>$p/${opt_n}.h") or die "Can't open ${opt_n}.h: $!\n";
- print $o qq{#define ${u_optn}_VERSION "$opt_v"\n\n};
- close $o;
- open($o, ">>$p/${opt_n}.c") or die "Can't reopen ${opt_n}.c: $!\n";
- print $o <<here;
- #include <linux/kernel.h>
- #include <linux/module.h>
- #include <linux/slab.h>
- #include <linux/init.h>
- #include <linux/types.h>
- #include "${opt_n}.h"
- MODULE_AUTHOR();
- MODULE_DESCRIPTION();
- MODULE_LICENSE();
- MODULE_VERSION(${u_optn}_VERSION);
- // static ...
- // module_param(..., uint, 0);
- // MODULE_PARM_DESC(..., "");
- static void ${_optn}_exit(void)
- {
- return;
- }
- static void ${_optn}_init(void)
- {
- return;
- }
- module_init(${_optn}_init);
- module_exit(${_optn}_exit);
- here
- close $o;
- open($o, ">$p/Kconfig") or die "Can't open ${opt_n}.c: $!\n";
- print $o <<here;
- #
- # $opt_n $opt_v
- #
- config ${u_optn}
- tristate "$opt_n $opt_v"
- # depends on
- # select
- ---help---
- Some inspiering text.
- here
- close $o;
- open($o, ">$p/Makefile") or die "Can't open ${opt_n}.c: $!\n";
- print $o <<here;
- obj-m := ${opt_n}.o
- KVER ?= \$(shell uname -r)
- KDIR ?= /lib/modules/\$(KVER)/build
- MDIR ?= /lib/modules/\$(KVER)$optl
- PWD := \$(shell pwd)
- default:
- \$(MAKE) -C \$(KDIR) SUBDIRS=\$(PWD) \$(obj-m:.o=.ko)
- install:
- install -d \$(MDIR)
- install -m 644 -c \$(obj-m:.o=.ko) \$(MDIR)
- depmod -a
- clean:
- \$(MAKE) -C \$(KDIR) SUBDIRS=\$(PWD) \$(obj-m:.o=.ko) clean
- rm -rf *.mod.c *.o *.ko .tmp_versions Module.symvers .\$(obj-m:.o=)*
- rm -rf linux/.*o.cmd linux/*.o
- here
- close $o;
- exit;
- 1;
- __END__
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement