Discussion:
[PATCH] csstoh: replace with a simple shell script
Mike Frysinger
2012-06-01 18:27:16 UTC
Permalink
Having a compiled program that runs during build time is a pita for
cross-compiling. Rather than make that work, convert it to a simple
shell script since that's all this is really doing. No need for C
code here.

Signed-off-by: Mike Frysinger <vapier-aBrp7R+bbdUdnm+***@public.gmane.org>
---
.gitignore | 12 +--------
src/Makefile.am | 5 +--
src/csstoh | 18 ++++++++++++++
src/csstoh.c | 69 -------------------------------------------------------
4 files changed, 21 insertions(+), 83 deletions(-)
create mode 100755 src/csstoh
delete mode 100644 src/csstoh.c

diff --git a/.gitignore b/.gitignore
index 5534072..1f6906f 100644
--- a/.gitignore
+++ b/.gitignore
@@ -4,6 +4,7 @@
*.html
*.csv
*.powertop
+.deps
ChangeLog
Makefile.in
aclocal.m4
@@ -22,7 +23,6 @@ config.h
config.log
config.status
libtool
-pevent/.deps/
pevent/Makefile
pevent/Makefile.in
po/Makefile
@@ -39,18 +39,8 @@ po/*.gmo
po/stamp-po
src/powertop
src/css.h
-src/csstoh
src/Makefile.in
-src/.deps/
src/Makefile
-src/calibrate/.deps/
-src/cpu/.deps/
-src/devices/.deps/
-src/measurement/.deps/
-src/parameters/.deps/
-src/perf/.deps/
-src/process/.deps/
-src/tuning/.deps/
m4
*.dirstamp
*.lo
diff --git a/src/Makefile.am b/src/Makefile.am
index 61d91be..53222f2 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1,8 +1,7 @@
AUTOMAKE_OPTIONS = subdir-objects
ACLOCAL_AMFLAGS = -I ../m4

-noinst_PROGRAMS = csstoh
-csstoh_SOURCES = csstoh.c
+noinst_SCRIPTS = csstoh

sbin_PROGRAMS = powertop
nodist_powertop_SOURCES = css.h
@@ -45,5 +44,5 @@ AM_LDFLAGS = $(LIBS) $(NCURSES_LIBS) $(PCIUTILS_LIBS) $(LIBNL_LIBS) $(LIBZ_LIBS)
BUILT_SOURCES = css.h
CLEANFILES = css.h
css.h: csstoh powertop.css
- ./csstoh powertop.css css.h
+ $(SHELL) $(srcdir)/csstoh powertop.css css.h

diff --git a/src/csstoh b/src/csstoh
new file mode 100755
index 0000000..51d1ec1
--- /dev/null
+++ b/src/csstoh
@@ -0,0 +1,18 @@
+#!/bin/sh
+
+in=$1
+out=$2
+
+(
+cat <<EOF
+#ifndef __INCLUDE_GUARD_CCS_H
+#define __INCLUDE_GUARD_CCS_H
+
+const char css[] =
+EOF
+sed -e 's:^:\t":' -e 's:$:\\n":' "${in}"
+cat <<EOF
+;
+#endif
+EOF
+) > "${out}"
diff --git a/src/csstoh.c b/src/csstoh.c
deleted file mode 100644
index e6b1dcf..0000000
--- a/src/csstoh.c
+++ /dev/null
@@ -1,69 +0,0 @@
-/*
- * Copyright 2010, Intel Corporation
- *
- * This file is part of PowerTOP
- *
- * This program file 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; version 2 of the License.
- *
- * 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 in a file named COPYING; if not, write to the
- * Free Software Foundation, Inc,
- * 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301 USA
- * or just google for it.
- *
- * Authors:
- * Arjan van de Ven <arjan-VuQAYsv1563Yd54FQh9/***@public.gmane.org>
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <errno.h>
-#include <string.h>
-
-int main(int argc, char **argv)
-{
- FILE *in, *out;
- char line[4096];
-
- if (argc < 2) {
- printf("Usage: csstoh cssfile header.h \n");
- exit(0);
- }
- in = fopen(argv[1], "rm");
- if (!in) {
- printf("Failed to open input file %s (%s) \n", argv[1], strerror(errno));
- exit(0);
- }
- out = fopen(argv[2], "wm");
- if (!out) {
- printf("Failed to open output file %s (%s) \n", argv[1], strerror(errno));
- exit(0);
- }
-
- fprintf(out, "#ifndef __INCLUDE_GUARD_CCS_H\n");
- fprintf(out, "#define __INCLUDE_GUARD_CCS_H\n");
- fprintf(out, "\n");
- fprintf(out, "const char css[] = \n");
-
- while (!feof(in)) {
- char *c;
- if (fgets(line, 4095, in) == NULL)
- break;
- c = strchr(line, '\n');
- if (c) *c = 0;
- fprintf(out, "\t\"%s\\n\"\n", line);
- }
- fprintf(out, ";\n");
- fprintf(out, "#endif\n");
- fclose(out);
- fclose(in);
- return EXIT_SUCCESS;
-}
--
1.7.8.6
Loading...