xref: /OK3568_Linux_fs/buildroot/support/scripts/expunge-gconv-modules (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun#!/usr/bin/env bash
2*4882a593Smuzhiyun
3*4882a593Smuzhiyun# This script is used to generate a gconv-modules file that takes into
4*4882a593Smuzhiyun# account only the gconv modules installed by Buildroot. It receives
5*4882a593Smuzhiyun# on its standard input the original complete gconv-modules file from
6*4882a593Smuzhiyun# the toolchain, and as arguments the list of gconv modules that were
7*4882a593Smuzhiyun# actually installed, and writes on its standard output the new
8*4882a593Smuzhiyun# gconv-modules file.
9*4882a593Smuzhiyun
10*4882a593Smuzhiyun# The format of gconv-modules is precisely documented in the
11*4882a593Smuzhiyun# file itself. It consists of two different directives:
12*4882a593Smuzhiyun#   module  FROMSET  TOSET  FILENAME  COST
13*4882a593Smuzhiyun#   alias   ALIAS  REALNAME
14*4882a593Smuzhiyun# and that's what this script parses and generates.
15*4882a593Smuzhiyun#
16*4882a593Smuzhiyun# There are two kinds of 'module' directives:
17*4882a593Smuzhiyun#   - the first defines conversion of a charset to/from INTERNAL representation
18*4882a593Smuzhiyun#   - the second defines conversion of a charset to/from another charset
19*4882a593Smuzhiyun# we handle each with slightly different code, since the second never has
20*4882a593Smuzhiyun# associated aliases.
21*4882a593Smuzhiyun
22*4882a593Smuzhiyungawk -v files="${1}" '
23*4882a593Smuzhiyun$1 == "alias" {
24*4882a593Smuzhiyun    aliases[$3] = aliases[$3] " " $2;
25*4882a593Smuzhiyun}
26*4882a593Smuzhiyun$1 == "module" && $2 != "INTERNAL" && $3 == "INTERNAL" {
27*4882a593Smuzhiyun    file2internals[$4] = file2internals[$4] " " $2;
28*4882a593Smuzhiyun    mod2cost[$2] = $5;
29*4882a593Smuzhiyun}
30*4882a593Smuzhiyun$1 == "module" && $2 != "INTERNAL" && $3 != "INTERNAL" {
31*4882a593Smuzhiyun    file2cset[$4] = file2cset[$4] " " $2 ":" $3;
32*4882a593Smuzhiyun    mod2cost[$2] = $5;
33*4882a593Smuzhiyun}
34*4882a593Smuzhiyun
35*4882a593SmuzhiyunEND {
36*4882a593Smuzhiyun    nb_files = split(files, all_files);
37*4882a593Smuzhiyun    for(f = 1; f <= nb_files; f++) {
38*4882a593Smuzhiyun        file = all_files[f];
39*4882a593Smuzhiyun        printf("# Modules and aliases for: %s\n", file);
40*4882a593Smuzhiyun        nb_mods = split(file2internals[file], mods);
41*4882a593Smuzhiyun        for(i = 1; i <= nb_mods; i++) {
42*4882a593Smuzhiyun            nb_aliases = split(aliases[mods[i]], mod_aliases);
43*4882a593Smuzhiyun            for(j = 1; j <= nb_aliases; j++) {
44*4882a593Smuzhiyun                printf("alias\t%s\t%s\n", mod_aliases[j], mods[i]);
45*4882a593Smuzhiyun            }
46*4882a593Smuzhiyun            printf("module\t%s\t%s\t%s\t%d\n", mods[i], "INTERNAL", file, mod2cost[mods[i]]);
47*4882a593Smuzhiyun            printf("module\t%s\t%s\t%s\t%d\n", "INTERNAL", mods[i], file, mod2cost[mods[i]]);
48*4882a593Smuzhiyun            printf("\n" );
49*4882a593Smuzhiyun        }
50*4882a593Smuzhiyun        printf("%s", nb_mods != 0 ? "\n" : "");
51*4882a593Smuzhiyun        nb_csets = split(file2cset[file], csets);
52*4882a593Smuzhiyun        for(i = 1; i <= nb_csets; i++) {
53*4882a593Smuzhiyun            split(csets[i], cs, ":");
54*4882a593Smuzhiyun            printf("module\t%s\t%s\t%s\t%d\n", cs[1], cs[2], file, mod2cost[cs[1]]);
55*4882a593Smuzhiyun        }
56*4882a593Smuzhiyun        printf("%s", nb_csets != 0 ? "\n\n" : "");
57*4882a593Smuzhiyun    }
58*4882a593Smuzhiyun}
59*4882a593Smuzhiyun'
60