Skip to contentSkip to conversation

csstoh shell-script for cross-compiling PowerTOP

Powertop In review Igor Zhbanov 5 participants 9 messages Jul 11, 2012

lore
Share & tools
lore

Igor Zhbanov

author
#0 lore raw

Hello!

I have tried to build PowerTOP for ARM with a cross-compiler. But PowerTOP uses internal csstoh utility that converts powertop.css to powertoh.h for inclusion in *.cpp source files.

When you use the cross-compiler (without making complicated rules in the Makefile) this utility will be compiled for ARM platform too. And you cannot run it on x86 build host.

To solve this issue (and because of simplicity of the utility) I have rewritten it in a shell script.

--8<--------------------------------------------------------------------------

Android.mk +2 -3
diff -purN powertop/Android.mk powertop-cross/Android.mk
@@ -2,12 +2,11 @@ LOCAL_PATH := $(call my-dir)
  include $(CLEAR_VARS)
 
  LOCAL_MODULE_TAGS := optional
-CSSTOH_SOURCE := $(LOCAL_PATH)/csstoh.c
  POWERTOP_CSS_SOURCE := $(LOCAL_PATH)/powertop.css
-GEN_CSSTOH := $(LOCAL_PATH)/csstoh
+GEN_CSSTOH := $(LOCAL_PATH)/csstoh.sh
  GEN_CSS_H := $(LOCAL_PATH)/css.h
  $(GEN_CSS_H):
-	$(CC) -o $(GEN_CSSTOH) $(CSSTOH_SOURCE)
+	chmod +x ./$(GEN_CSSTOH)
  	./$(GEN_CSSTOH) $(POWERTOP_CSS_SOURCE) $@
 
  LOCAL_GENERATED_SOURCES += $(GEN_CSS_H)
.gitignore +0 -1
diff -purN powertop/.gitignore powertop-cross/.gitignore
@@ -39,7 +39,6 @@ po/*.gmo
  po/stamp-po
  src/powertop
  src/css.h
-src/csstoh
  src/Makefile.in
  src/.deps/
  src/Makefile
src/csstoh.sh +45 -0

45 lines not on this page · raw message

src/Makefile.am +3 -5
diff -purN powertop/src/Makefile.am powertop-cross/src/Makefile.am
@@ -1,9 +1,6 @@
  AUTOMAKE_OPTIONS = subdir-objects
  ACLOCAL_AMFLAGS = -I ../m4
 
-noinst_PROGRAMS = csstoh
-csstoh_SOURCES = csstoh.c
-
  sbin_PROGRAMS = powertop
  nodist_powertop_SOURCES = css.h
 
@@ -44,6 +41,7 @@ AM_LDFLAGS = $(LIBS) $(NCURSES_LIBS) $(P
 
  BUILT_SOURCES = css.h
  CLEANFILES = css.h
-css.h: csstoh powertop.css
-	./csstoh powertop.css css.h
+css.h: powertop.css
+	chmod +x ./csstoh.sh
+	./csstoh.sh powertop.css css.h
 

--8<--------------------------------------------------------------------------

Thank you.

Signature · 9 lines
Best regards,
Igor Zhbanov,
Expert Software Engineer,
phone: +7 (495) 797 25 00 ext 3806
e-mail: i.zhbanov(a)samsung.com

ASWG, Moscow R&D center, Samsung Electronics
12 Dvintsev street, building 1
127018, Moscow, Russian Federation
Android.mk +2 -3
diff -purN powertop/Android.mk powertop-cross/Android.mk
@@ -2,12 +2,11 @@ LOCAL_PATH := $(call my-dir)
 include $(CLEAR_VARS)
 
 LOCAL_MODULE_TAGS := optional
-CSSTOH_SOURCE := $(LOCAL_PATH)/csstoh.c
 POWERTOP_CSS_SOURCE := $(LOCAL_PATH)/powertop.css
-GEN_CSSTOH := $(LOCAL_PATH)/csstoh
+GEN_CSSTOH := $(LOCAL_PATH)/csstoh.sh
 GEN_CSS_H := $(LOCAL_PATH)/css.h
 $(GEN_CSS_H):
-	$(CC) -o $(GEN_CSSTOH) $(CSSTOH_SOURCE)
+	chmod +x ./$(GEN_CSSTOH)
 	./$(GEN_CSSTOH) $(POWERTOP_CSS_SOURCE) $@
 
 LOCAL_GENERATED_SOURCES += $(GEN_CSS_H)
.gitignore +0 -1
diff -purN powertop/.gitignore powertop-cross/.gitignore
@@ -39,7 +39,6 @@ po/*.gmo
 po/stamp-po
 src/powertop
 src/css.h
-src/csstoh
 src/Makefile.in
 src/.deps/
 src/Makefile
src/csstoh.sh +45 -0

45 lines not on this page · raw message

src/Makefile.am +3 -5
diff -purN powertop/src/Makefile.am powertop-cross/src/Makefile.am
@@ -1,9 +1,6 @@
 AUTOMAKE_OPTIONS = subdir-objects
 ACLOCAL_AMFLAGS = -I ../m4 
 
-noinst_PROGRAMS = csstoh
-csstoh_SOURCES = csstoh.c 
-
 sbin_PROGRAMS = powertop
 nodist_powertop_SOURCES = css.h
 
@@ -44,6 +41,7 @@ AM_LDFLAGS = $(LIBS) $(NCURSES_LIBS) $(P
 
 BUILT_SOURCES = css.h
 CLEANFILES = css.h
-css.h: csstoh powertop.css
-	./csstoh powertop.css css.h
+css.h: powertop.css
+	chmod +x ./csstoh.sh
+	./csstoh.sh powertop.css css.h
 
#1 lore raw
Quoted 6 lines · Igor Zhbanov

Hello!

I have tried to build PowerTOP for ARM with a cross-compiler. But PowerTOP uses internal csstoh utility that converts powertop.css to powertoh.h for inclusion in *.cpp source files.

Quoted 6 lines

When you use the cross-compiler (without making complicated rules in the Makefile) this utility will be compiled for ARM platform too. And you cannot run it on x86 build host.

To solve this issue (and because of simplicity of the utility) I have rewritten it in a shell script.

Why /bin/bash?

The script doesn't depend on any bashisms so /bin/sh should be enough, right?

Why all the games with chmod?
$(SHELL) csstoh.sh powertop.css css.h should also run the script correctly, shouldn't it?

/MF

author
#2 lore raw

Here is the new version:

--8<--Cut-here----------------------------------------------------------------

Android.mk +2 -4
diff -purN powertop/Android.mk powertop-csstoh/Android.mk
@@ -2,13 +2,11 @@ LOCAL_PATH := $(call my-dir)
  include $(CLEAR_VARS)
 
  LOCAL_MODULE_TAGS := optional
-CSSTOH_SOURCE := $(LOCAL_PATH)/csstoh.c
  POWERTOP_CSS_SOURCE := $(LOCAL_PATH)/powertop.css
-GEN_CSSTOH := $(LOCAL_PATH)/csstoh
+GEN_CSSTOH := $(LOCAL_PATH)/csstoh.sh
  GEN_CSS_H := $(LOCAL_PATH)/css.h
  $(GEN_CSS_H):
-	$(CC) -o $(GEN_CSSTOH) $(CSSTOH_SOURCE)
-	./$(GEN_CSSTOH) $(POWERTOP_CSS_SOURCE) $@
+	$(SHELL) ./$(GEN_CSSTOH) $(POWERTOP_CSS_SOURCE) $@
 
  LOCAL_GENERATED_SOURCES += $(GEN_CSS_H)
 
.gitignore +0 -1
diff -purN powertop/.gitignore powertop-csstoh/.gitignore
@@ -39,7 +39,6 @@ po/*.gmo
  po/stamp-po
  src/powertop
  src/css.h
-src/csstoh
  src/Makefile.in
  src/.deps/
  src/Makefile
src/csstoh.sh +44 -0

44 lines not on this page · raw message

src/Makefile.am +2 -5
diff -purN powertop/src/Makefile.am powertop-csstoh/src/Makefile.am
@@ -1,9 +1,6 @@
  AUTOMAKE_OPTIONS = subdir-objects
  ACLOCAL_AMFLAGS = -I ../m4
 
-noinst_PROGRAMS = csstoh
-csstoh_SOURCES = csstoh.c
-
  sbin_PROGRAMS = powertop
  nodist_powertop_SOURCES = css.h
 
@@ -44,6 +41,6 @@ AM_LDFLAGS = $(LIBS) $(NCURSES_LIBS) $(P
 
  BUILT_SOURCES = css.h
  CLEANFILES = css.h
-css.h: csstoh powertop.css
-	./csstoh powertop.css css.h
+css.h: powertop.css
+	$(SHELL) ./csstoh.sh powertop.css css.h
 

--8<--------------------------------------------------------------------------

Quoted 25 lines · Magnus Fromreide
Quoted 6 lines · Igor Zhbanov

Hello!

I have tried to build PowerTOP for ARM with a cross-compiler. But PowerTOP uses internal csstoh utility that converts powertop.css to powertoh.h for inclusion in *.cpp source files.

Quoted 6 lines

When you use the cross-compiler (without making complicated rules in the Makefile) this utility will be compiled for ARM platform too. And you cannot run it on x86 build host.

To solve this issue (and because of simplicity of the utility) I have rewritten it in a shell script.

Why /bin/bash?

The script doesn't depend on any bashisms so /bin/sh should be enough, right?

Why all the games with chmod?
$(SHELL) csstoh.sh powertop.css css.h should also run the script correctly, shouldn't it?

/MF

Signature · 9 lines
Best regards,
Igor Zhbanov,
Expert Software Engineer,
phone: +7 (495) 797 25 00 ext 3806
e-mail: i.zhbanov(a)samsung.com

ASWG, Moscow R&D center, Samsung Electronics
12 Dvintsev street, building 1
127018, Moscow, Russian Federation
Android.mk +2 -4
diff -purN powertop/Android.mk powertop-csstoh/Android.mk
@@ -2,13 +2,11 @@ LOCAL_PATH := $(call my-dir)
 include $(CLEAR_VARS)
 
 LOCAL_MODULE_TAGS := optional
-CSSTOH_SOURCE := $(LOCAL_PATH)/csstoh.c
 POWERTOP_CSS_SOURCE := $(LOCAL_PATH)/powertop.css
-GEN_CSSTOH := $(LOCAL_PATH)/csstoh
+GEN_CSSTOH := $(LOCAL_PATH)/csstoh.sh
 GEN_CSS_H := $(LOCAL_PATH)/css.h
 $(GEN_CSS_H):
-	$(CC) -o $(GEN_CSSTOH) $(CSSTOH_SOURCE)
-	./$(GEN_CSSTOH) $(POWERTOP_CSS_SOURCE) $@
+	$(SHELL) ./$(GEN_CSSTOH) $(POWERTOP_CSS_SOURCE) $@
 
 LOCAL_GENERATED_SOURCES += $(GEN_CSS_H)
 
.gitignore +0 -1
diff -purN powertop/.gitignore powertop-csstoh/.gitignore
@@ -39,7 +39,6 @@ po/*.gmo
 po/stamp-po
 src/powertop
 src/css.h
-src/csstoh
 src/Makefile.in
 src/.deps/
 src/Makefile
src/csstoh.sh +44 -0

44 lines not on this page · raw message

src/Makefile.am +2 -5
diff -purN powertop/src/Makefile.am powertop-csstoh/src/Makefile.am
@@ -1,9 +1,6 @@
 AUTOMAKE_OPTIONS = subdir-objects
 ACLOCAL_AMFLAGS = -I ../m4 
 
-noinst_PROGRAMS = csstoh
-csstoh_SOURCES = csstoh.c 
-
 sbin_PROGRAMS = powertop
 nodist_powertop_SOURCES = css.h
 
@@ -44,6 +41,6 @@ AM_LDFLAGS = $(LIBS) $(NCURSES_LIBS) $(P
 
 BUILT_SOURCES = css.h
 CLEANFILES = css.h
-css.h: csstoh powertop.css
-	./csstoh powertop.css css.h
+css.h: powertop.css
+	$(SHELL) ./csstoh.sh powertop.css css.h
 
#3 lore raw
Quoted 4 lines · Igor Zhbanov

Here is the new version:

--8<--Cut-here----------------------------------------------------------------

Hello,

Igor, could you please inline patch as "git diff -u -p" output, not as attachment.

Thanks,

	-ss
#4 lore raw

Dear Igor, dear Sergey,

Am Mittwoch, den 11.07.2012, 10:36 +0300 schrieb Sergey Senozhatsky:

Quoted 6 lines · Igor Zhbanov
Quoted 3 lines

Here is the new version:

--8<--Cut-here----------------------------------------------------------------

Igor, could you please inline patch as "git diff -u -p" output, not as attachment.

        $ git commit -a
        $ git format-patch -1

is the preferred way as far as I know. Please see my other message, I sent in reply to »[Powertop] Device list sort function bug«.

Thanks,

Paul

author
#5 lore raw

Here is the formatted version of the patch:

From 06ee265b637bd75e2147631f49454c2c82be827e Mon Sep 17 00:00:00 2001
From: Igor Zhbanov<i.zhbanov(a)samsung.com>
Date: Wed, 11 Jul 2012 12:44:39 +0400
Subject: [PATCH] csstoh shell-script for cross-compiling PowerTOP

I have tried to build PowerTOP for ARM with a cross-compiler. But PowerTOP uses internal csstoh utility that converts powertop.css to powertoh.h for inclusion in *.cpp source files.

When you use the cross-compiler (without making complicated rules in the Makefile) this utility will be compiled for ARM platform too. And you cannot run it on x86 build host.

To solve this issue (and because of simplicity of the utility) I have rewritten it in a shell script.

---
  .gitignore      |    1 -
  src/Makefile.am |    7 ++-----
  2 files changed, 2 insertions(+), 6 deletions(-)
.gitignore +0 -1
index 5534072..35f0df6 100644
@@ -39,7 +39,6 @@ po/*.gmo
  po/stamp-po
  src/powertop
  src/css.h
-src/csstoh
  src/Makefile.in
  src/.deps/
  src/Makefile
src/Makefile.am +2 -5
index c77b2aa..15e5feb 100644
@@ -1,9 +1,6 @@
  AUTOMAKE_OPTIONS = subdir-objects
  ACLOCAL_AMFLAGS = -I ../m4
 
-noinst_PROGRAMS = csstoh
-csstoh_SOURCES = csstoh.c
-
  sbin_PROGRAMS = powertop
  nodist_powertop_SOURCES = css.h
 
@@ -44,6 +41,6 @@ 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
+css.h: powertop.css
+	$(SHELL) ./csstoh.sh powertop.css css.h
 
Signature · 1 line
1.7.5.4
Quoted 19 lines · Paul Menzel

Dear Igor, dear Sergey,

Am Mittwoch, den 11.07.2012, 10:36 +0300 schrieb Sergey Senozhatsky:

Quoted 5 lines · Igor Zhbanov
Quoted 3 lines

Here is the new version:

--8<--Cut-here----------------------------------------------------------------

Igor, could you please inline patch as "git diff -u -p" output, not as attachment.

         $ git commit -a
         $ git format-patch -1

is the preferred way as far as I know. Please see my other message, I sent in reply to »[Powertop] Device list sort function bug«.

Thanks,

Paul

Signature · 9 lines
Best regards,
Igor Zhbanov,
Expert Software Engineer,
phone: +7 (495) 797 25 00 ext 3806
e-mail: i.zhbanov(a)samsung.com

ASWG, Moscow R&D center, Samsung Electronics
12 Dvintsev street, building 1
127018, Moscow, Russian Federation
#6 lore raw

Am Mittwoch, den 11.07.2012, 12:47 +0400 schrieb Igor Zhbanov:

Quoted 1 line

Here is the formatted version of the patch:

Thanks, unfortunately something is incomplete.

Quoted 13 lines

From 06ee265b637bd75e2147631f49454c2c82be827e Mon Sep 17 00:00:00 2001
From: Igor Zhbanov<i.zhbanov(a)samsung.com>
Date: Wed, 11 Jul 2012 12:44:39 +0400
Subject: [PATCH] csstoh shell-script for cross-compiling PowerTOP

I have tried to build PowerTOP for ARM with a cross-compiler. But PowerTOP uses internal csstoh utility that converts powertop.css to powertoh.h for inclusion in *.cpp source files.

When you use the cross-compiler (without making complicated rules in the Makefile) this utility will be compiled for ARM platform too. And you cannot run it on x86 build host.

Quoted 6 lines

To solve this issue (and because of simplicity of the utility) I have rewritten it in a shell script.

---
  .gitignore      |    1 -
  src/Makefile.am |    7 ++-----
  2 files changed, 2 insertions(+), 6 deletions(-)

Git does not know about your new file csstoh.sh yet.

    $ git add src/csstoh.sh # explicitly needed, because the file is not yet tracked
    $ git commit --amend -a
    $ git format-patch -1
Quoted 37 lines
.gitignore +0 -1
index 5534072..35f0df6 100644
@@ -39,7 +39,6 @@ po/*.gmo
  po/stamp-po
  src/powertop
  src/css.h
-src/csstoh
  src/Makefile.in
  src/.deps/
  src/Makefile
src/Makefile.am +2 -5
index c77b2aa..15e5feb 100644
@@ -1,9 +1,6 @@
  AUTOMAKE_OPTIONS = subdir-objects
  ACLOCAL_AMFLAGS = -I ../m4
 
-noinst_PROGRAMS = csstoh
-csstoh_SOURCES = csstoh.c
-
  sbin_PROGRAMS = powertop
  nodist_powertop_SOURCES = css.h
 
@@ -44,6 +41,6 @@ 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
+css.h: powertop.css
+	$(SHELL) ./csstoh.sh powertop.css css.h
 
Signature · 1 line
1.7.5.4

Thanks,

Paul

PS: In the license header the copyright year is missing if I am not mistaken.
PPS: Is that also the right license header? Probably you just copied it from some existing file. So it should be fine.

author
#7 lore raw

PATCH 1/1 csstoh shell-script for cross-compiling PowerTOP

It was impossible to build PowerTOP for ARM with a cross-compiler because PowerTOP uses internal csstoh utility that converts powertop.css to powertoh.h for inclusion in *.cpp source files.

When you use the cross-compiler (without making complicated rules in the Makefile) this utility will be compiled for ARM platform too. And you cannot run it on x86 build host.

To solve this issue I have rewritten it in a shell script.

---
 .gitignore      |    1 -
 src/Makefile.am |    7 ++-----
 src/csstoh.sh   |   44 ++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 46 insertions(+), 6 deletions(-)
 create mode 100644 src/csstoh.sh
.gitignore +0 -1
index 5534072..35f0df6 100644
@@ -39,7 +39,6 @@ po/*.gmo
 po/stamp-po
 src/powertop
 src/css.h
-src/csstoh
 src/Makefile.in
 src/.deps/
 src/Makefile
src/Makefile.am +2 -5
index c77b2aa..15e5feb 100644
@@ -1,9 +1,6 @@
 AUTOMAKE_OPTIONS = subdir-objects
 ACLOCAL_AMFLAGS = -I ../m4 
 
-noinst_PROGRAMS = csstoh
-csstoh_SOURCES = csstoh.c 
-
 sbin_PROGRAMS = powertop
 nodist_powertop_SOURCES = css.h
 
@@ -44,6 +41,6 @@ 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
+css.h: powertop.css
+	$(SHELL) ./csstoh.sh powertop.css css.h
 
src/csstoh.sh new file +44 -0

44 lines not on this page · raw message

Signature · 1 line
1.7.5.4
#8 lore raw
Quoted 9 lines · Igor Zhbanov

It was impossible to build PowerTOP for ARM with a cross-compiler because PowerTOP uses internal csstoh utility that converts powertop.css to powertoh.h for inclusion in *.cpp source files.

When you use the cross-compiler (without making complicated rules in the Makefile) this utility will be compiled for ARM platform too. And you cannot run it on x86 build host.

To solve this issue I have rewritten it in a shell script.

So, while this approach is correct, it's a clear case where basically autotools is not used properly and should be able to solve the problem for you, and this tool cuold remain a binary program.

In this case it's probably not worth it, since the program is so small, but I'd like for everyone to realize that there is a lot of support in autotools for using HOSTCC and building _noinst programs etc. - autotools has excellent crosscompilation support.

Auke