[Cbe-oss-dev] [PATCH 1/3] libspe2: Clean up build system
Kazunori Asayama
asayama at sm.sony.co.jp
Wed Mar 26 19:28:13 EST 2008
This is a patch to clean up the existing build system for the test
framework:
- make it easy to switch between ppc32 and ppc64.
- enable to test both of static libraries and shared libraries.
- share the same macros between Makefiles.
Signed-off-by: Kazunori Asayama <asayama at sm.sony.co.jp>
---
Makefile | 42 ++++++++++---------
libspe12/Makefile | 13 +++---
libspe12/tests/dma/Makefile | 17 +++----
libspe12/tests/elfspe/Makefile | 14 ++----
libspe12/tests/event/Makefile | 16 +++----
libspe12/tests/ft/Makefile | 15 +++----
libspe12/tests/start-stop/Makefile | 17 +++----
libspe2.spec | 11 +++--
make.defines | 79 +++++++++++++++++++++++++++++++------
tests/Makefile | 7 ---
10 files changed, 143 insertions(+), 88 deletions(-)
Index: b/make.defines
===================================================================
--- a/make.defines 2008-03-24 15:31:41.000000000 +0900
+++ b/make.defines 2008-03-26 14:14:36.000000000 +0900
@@ -17,24 +17,78 @@
#* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#*
+# USER CONFIGURATION
-X86 = $(shell if ! uname -m | grep ppc ; then echo 1 ; fi)
-
-CROSS_COMPILE = $(shell if ! grep Broadband /proc/cpuinfo ; then echo 1 ; fi)
+# ARCH: target architecture
+# undefined: compiler's default architecture
+# ppc: 32-bit PowerPC
+# ppc64: 64-bit PowerPC
+# Default value:
+# ARCH =
+
+# DEBUG: enable debugging
+# 1: enable
+# others: disable
+# Default value:
+# DEBUG =
+
+# TEST_STATIC: set static libraries as test targets
+# 1: test static libraries
+# others: test shared libraries
+#
+# Default value:
+# TEST_STATIC =
+
+# CROSS: prefix of PPU toolchain
+#
+# Default:
+#
+# (native build)
+# CROSS =
+# (cross build)
+# CROSS = ppu-
+
+# SPU_CROSS: prefix of SPU toolchain
+#
+# Default:
+# SPU_CROSS = spu-
+
+
+BUILD_ARCH = $(shell uname -m)
+
+ifneq "$(BUILD_ARCH)" "ppc"
+ifneq "$(BUILD_ARCH)" "ppc64"
+ CROSS_COMPILE = 1
+endif
+endif
-ifeq "$(X86)" "1"
+ifeq "$(CROSS_COMPILE)" "1"
CROSS ?= ppu-
- EXTRA_CFLAGS = -m32 -mabi=altivec
# RPM defined default flags may not work with this cross-compiler
override OPTFLAGS =
-endif
-ifeq "$(CROSS_COMPILE)" "1"
SYSROOT ?= ../../../sysroot
prefix ?= /usr
+ RPM_ARCH ?= noarch
else
-prefix ?= /usr/local
+ prefix ?= /usr/local
+ RPM_ARCH ?= $(ARCH)
+endif
+ifeq "$(RPM_ARCH)" ""
+ RPM_ARCH = ppc
endif
+ifeq "$(ARCH)" "ppc"
+ ARCH_CFLAGS = -m32 -mabi=altivec
+else
+ifeq "$(ARCH)" "ppc64"
+ ARCH_CFLAGS = -m64
+else
+# Use default
+ ARCH_CFLAGS =
+endif
+endif
+
+
SPU_CROSS = spu-
exec_prefix = ${prefix}
@@ -72,13 +126,16 @@ CFLAGS := -O2 -Wall -I. -fPIC -I$(TOP)/i
-Wmissing-prototypes -Wmissing-declarations \
-Wmissing-noreturn -Wredundant-decls \
-Wnested-externs -Winline -Wformat \
- ${EXTRA_CFLAGS} ${OPTFLAGS}
+ ${ARCH_CFLAGS} ${EXTRA_CFLAGS} ${OPTFLAGS}
+
+ifeq "$(TEST_STATIC)" "1"
+ TEST_LDFLAGS += -static
+endif
+
SPU_CC = $(SPU_CROSS)gcc
SPU_CFLAGS =
-#DEBUG=1
-
ifdef DEBUG
CFLAGS += -DDEBUG -g
endif
Index: b/Makefile
===================================================================
--- a/Makefile 2008-03-24 15:31:41.000000000 +0900
+++ b/Makefile 2008-03-26 14:14:36.000000000 +0900
@@ -42,7 +42,7 @@ edit = @sed \
-e 's, at includedir@,$(includedir),g' \
-e 's, at version@,$(VERSION),g'
-all: $(libspe2_SO) $(libspe2_A) libspe12-all
+all: libspe2.so $(libspe2_A) libspe12-all
dist: $(TARBALL)
@@ -112,9 +112,13 @@ $(libspe2_SO): $(libspe2_OBJS) base-all
$(libspe2_A): $(libspe2_OBJS) base-all event-all
$(CROSS)ar -r $(libspe2_A) $(libspe2_OBJS) spebase/*.o speevent/*.o $(libspe2_OBJS)
+$(libspe2_SONAME): $(libspe2_SO)
+ ln -sf $< $@
+
+libspe2.so: $(libspe2_SONAME)
+ ln -sf $< $@
PATCHES := `cat series | grep -v ^\#`
-#RPMBUILD = ppc32 rpmbuild --target=ppc
RPMBUILD = rpmbuild
PWD := $(shell pwd)
@@ -138,27 +142,22 @@ $(PWD)/.rpmmacros:
mkdir -p $(SOURCES) $(RPMS) $(SRPMS) $(BUILD)
echo -e \%_topdir $(RPM)\\n\%_sourcedir $(PWD)\\n\%_tmppath %_topdir/tmp\\n\%_version $(RELEASE) > $@
-rpm: dist checkenv $(RPM)/$(PACKAGE)-stamp
-
-$(RPM)/$(PACKAGE)-stamp: $(PWD)/.rpmmacros $(SOURCEFILES) $(SPEC)
- HOME=$(PWD) $(RPMBUILD) -ba $(SPEC) $(RPMFLAGS)
- touch $@
-
-crossrpm: dist checkenv $(RPM)/$(PACKAGE)-cross-stamp
+rpm: dist checkenv $(RPM)/$(PACKAGE)-$(RPM_ARCH)-stamp
-$(RPM)/$(PACKAGE)-cross-stamp: $(PWD)/.rpmmacros $(SOURCEFILES) $(SPEC)
- HOME=$(PWD) $(RPMBUILD) -ba $(SPEC) --target=noarch $(RPMFLAGS)
+$(RPM)/$(PACKAGE)-$(RPM_ARCH)-stamp: $(PWD)/.rpmmacros $(SOURCEFILES) $(SPEC)
+ HOME=$(PWD) $(RPMBUILD) -ba --target=$(RPM_ARCH) $(SPEC) $(RPMFLAGS)
touch $@
-.PHONY: checkenv rpm crossrpm
+rpms: rpm32 rpm64
-
-rpms: clean rpm rpm32
-
-rpm32:
- HOME=$(PWD) $(RPMBUILD) --target=ppc -ba $(SPEC) $(RPMFLAGS)
+crossrpm:
+ $(MAKE) CROSS_COMPILE=1 rpm
+rpm32:
+ $(MAKE) ARCH=ppc rpm
rpm64:
- HOME=$(PWD) $(RPMBUILD) --target=ppc64 -ba $(SPEC) $(RPMFLAGS)
+ $(MAKE) ARCH=ppc64 rpm
+
+.PHONY: checkenv rpm crossrpm rpms rpm32 rpm64
$(TARBALL): clean
ln -s . $(FULLNAME)
@@ -170,6 +169,7 @@ $(TARBALL): clean
--exclude=$(FULLNAME)/tests_hidden \
--exclude=$(FULLNAME)/patches \
--exclude=.svn \
+ --exclude=.ccache \
$(FULLNAME)
rm $(FULLNAME)
@@ -196,9 +196,10 @@ apiref: clean
-clean: base-clean event-clean elfspe-clean libspe12-clean
+clean: base-clean event-clean elfspe-clean libspe12-clean tests-clean
rm *.diff ; true
rm -rf $(libspe2_A) $(libspe2_SO) $(libspe2_OBJS)
+ rm -f libspe2.so $(libspe2_SONAME)
rm -f $(TARBALL)
rm -f $(FULLNAME)
rm -f doc/*.pdf
@@ -207,6 +208,7 @@ clean: base-clean event-clean elfspe-cle
rm -rf html
rm -rf latex
rm -f libspe2.pc
+ rm -f $(PWD)/.rpmmacros
make -C tests clean
make -C ada clean
@@ -223,6 +225,8 @@ elfspe-clean:
libspe12-clean:
$(MAKE) -C libspe12 clean
+tests-clean:
+ $(MAKE) -C tests clean
distclean: clean
rm -rf latex
Index: b/libspe2.spec
===================================================================
--- a/libspe2.spec 2008-03-24 15:31:41.000000000 +0900
+++ b/libspe2.spec 2008-03-25 19:37:14.000000000 +0900
@@ -117,17 +117,20 @@ This tool acts as a standalone loader fo
%setup
%build
-make SYSROOT=%{sysroot} %{set_optflags} prefix=%{_prefix} libdir=%{_libdir} spe_ld_dir=%{_spe_ld_dir}
+
+%define _make_flags ARCH=%{_target_cpu} SYSROOT=%{sysroot} %{set_optflags} prefix=%{_prefix} libdir=%{_libdir} spe_ld_dir=%{_spe_ld_dir}
+
+make %{_make_flags}
%if %{build_common}
-make elfspe-all SYSROOT=%{sysroot} %{set_optflags} prefix=%{_prefix} libdir=%{_libdir} spe_ld_dir=%{_spe_ld_dir}
+make elfspe-all %{_make_flags}
%endif
%install
rm -rf $RPM_BUILD_ROOT%{sysroot}
-make install DESTDIR=$RPM_BUILD_ROOT SYSROOT=%{sysroot} prefix=%{_prefix} libdir=%{_libdir} speinclude=%{_includedir2} spe_ld_dir=%{_spe_ld_dir}
+make install DESTDIR=$RPM_BUILD_ROOT %{_make_flags}
%if %{build_common}
-make elfspe-install DESTDIR=$RPM_BUILD_ROOT SYSROOT=%{sysroot} prefix=%{_prefix} libdir=%{_libdir} speinclude=%{_includedir2} spe_ld_dir=%{_spe_ld_dir}
+make elfspe-install DESTDIR=$RPM_BUILD_ROOT %{_make_flags}
%endif
mkdir -p $RPM_BUILD_ROOT%{sysroot}%{_initdir}
Index: b/libspe12/Makefile
===================================================================
--- a/libspe12/Makefile 2008-03-24 14:10:12.000000000 +0900
+++ b/libspe12/Makefile 2008-03-24 18:54:07.000000000 +0900
@@ -7,9 +7,6 @@ CFLAGS += -I$(TOP)
CFLAGS += -I$(TOP)/spebase
CFLAGS += -D_ATFILE_SOURCE
-LDFLAGS := -m32
-LDLIBS := -L$(TOP) -lspe2 -lpthread
-
MAJOR_VERSION := 1
MINOR_VERSION := 2.2
@@ -19,7 +16,7 @@ libspe12_SONAME := libspe.so.${MAJOR_VER
libspe12_OBJS := spe.o spethreads.o dma.o ps.o ../spebase/*.o
-all: $(libspe12_SO) $(libspe12_A)
+all: libspe.so $(libspe12_A)
$(libspe12_A): $(libspe12_OBJS)
ar -r $(libspe12_A) $(libspe12_OBJS)
@@ -27,6 +24,12 @@ $(libspe12_A): $(libspe12_OBJS)
$(libspe12_SO): $(libspe12_OBJS)
$(CC) $(CFLAGS) -shared -o $@ $^ -lrt -Wl,--soname=${libspe12_SONAME}
+$(libspe12_SONAME): $(libspe12_SO)
+ ln -sf $< $@
+
+libspe.so: $(libspe12_SONAME)
+ ln -sf $< $@
+
install: spe.h $(libspe12_SO) $(libspe12_A)
$(INSTALL_DIR) $(ROOT)$(libdir)
$(INSTALL_DATA) $(libspe12_A) $(ROOT)$(libdir)/$(libspe12_A)
@@ -39,4 +42,4 @@ install: spe.h $(libspe12_SO) $(libspe12
clean:
rm -f $(libspe12_SO) $(libspe12_OBJS) $(libspe12_A)
-
+ rm -f libspe.so $(libspe12_SONAME)
Index: b/libspe12/tests/dma/Makefile
===================================================================
--- a/libspe12/tests/dma/Makefile 2008-03-24 14:10:10.000000000 +0900
+++ b/libspe12/tests/dma/Makefile 2008-03-24 18:57:40.000000000 +0900
@@ -17,14 +17,13 @@
#* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#*
-CC := gcc
-SPECC := spu-gcc
-CTAGS = ctags
+TOP=../../..
-CFLAGS := -O2 -m32 -Wall -I../.. -I../../include -g
-SPECFLAGS := -O2 -Wall -I../../include -Wno-main
+include $(TOP)/make.defines
-LDFLAGS := -m32
+CFLAGS += -I../.. -I$(TOP) -I$(TOP)/spebase -g $(TEST_CFLAGS)
+
+LDFLAGS := $(ARCH_CFLAGS) $(TEST_LDFLAGS)
LIBS := -L../.. -lspe -lpthread
SPE_OBJS := spe-dma-read spe-dma-write
@@ -39,9 +38,7 @@ ppe-dma-test: ppe-dma-test.c
$(CC) -o $@ $< $(CFLAGS) $(LDFLAGS) $(LIBS)
spe-dma-read: spe-dma-read.c
- $(SPECC) $(SPECFLAGS) -o $@ $<
+ $(SPU_CC) $(SPU_CFLAGS) -o $@ $<
spe-dma-write: spe-dma-write.c
- $(SPECC) $(SPECFLAGS) -o $@ $<
-
-
+ $(SPU_CC) $(SPU_CFLAGS) -o $@ $<
Index: b/libspe12/tests/elfspe/Makefile
===================================================================
--- a/libspe12/tests/elfspe/Makefile 2008-03-24 14:10:12.000000000 +0900
+++ b/libspe12/tests/elfspe/Makefile 2008-03-24 19:00:40.000000000 +0900
@@ -17,16 +17,14 @@
#* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#*
+TOP=../../..
-CC := gcc
-SPECC := spu-gcc
+include $(TOP)/make.defines
-CFLAGS := -O2 -Wall -I../.. -I../../include -g
-SPECFLAGS := -O2 -Wall -I../../include
-SPELDFLAGS := -L/usr/spu/lib
+CFLAGS += -I../.. -I$(TOP) -I$(TOP)/spebase -g $(TEST_CFLAGS)
+LDFLAGS = $(TEST_CFLAGS)
LIBS := -L../.. -lspe -lpthread
-SPELIBS := -lc -lgloss
SPE_OBJS := spe-helloworld
OBJS := runspe
@@ -37,7 +35,7 @@ clean:
rm -f $(SPE_OBJS) $(OBJS)
$(SPE_OBJS): %: %.c
- $(SPECC) $(SPECFLAGS) $(SPELDFLAGS) -o $@ $< $(SPELIBS)
+ $(SPU_CC) $(SPU_CFLAGS) -o $@ $<
$(OBJS): %: %.c
- $(CC) $(CFLAGS) -o $@ $< $(LIBS)
+ $(CC) $(CFLAGS) -o $@ $< $(LDFLAGS) $(LIBS)
Index: b/libspe12/tests/event/Makefile
===================================================================
--- a/libspe12/tests/event/Makefile 2008-03-24 14:10:10.000000000 +0900
+++ b/libspe12/tests/event/Makefile 2008-03-24 18:57:55.000000000 +0900
@@ -17,14 +17,13 @@
#* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#*
-CC := gcc
-SPECC := spu-gcc
-CTAGS = ctags
+TOP=../../..
-CFLAGS := -O2 -m32 -Wall -g -I../..
-SPECFLAGS := -O2 -Wall
+include $(TOP)/make.defines
-LDFLAGS := -m32
+CFLAGS += -I../.. -I$(TOP) -I$(TOP)/spebase -g $(TEST_CFLAGS)
+
+LDFLAGS = $(TEST_LDFLAGS)
LIBS := -L ../.. -lspe -lpthread
SPE_OBJS := spe-start-stop
@@ -36,8 +35,7 @@ clean:
rm -f $(OBJS) $(SPE_OBJS)
ppe-start-stop: ppe-start-stop.c ../../libspe.a
- $(CC) -o $@ $< $(CFLAGS) $(LDFLAGS) $(LIBS)
+ $(CC) $(CFLAGS) -o $@ $< $(LDFLAGS) $(LIBS)
spe-start-stop: spe-start-stop.c
- $(SPECC) $(SPECFLAGS) -o $@ $<
-
+ $(SPU_CC) $(SPU_CFLAGS) -o $@ $<
Index: b/libspe12/tests/ft/Makefile
===================================================================
--- a/libspe12/tests/ft/Makefile 2008-03-24 14:10:12.000000000 +0900
+++ b/libspe12/tests/ft/Makefile 2008-03-24 19:00:19.000000000 +0900
@@ -17,15 +17,14 @@
#* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#*
-CC := gcc
-SPECC := spu-gcc
-CTAGS = ctags
+TOP=../../..
-CFLAGS := -O2 -m32 -Wall -g -I../../../../head-libspe
-SPECFLAGS := -O2 -Wall
+include $(TOP)/make.defines
-LDFLAGS := -m32
-LIBS := -L../../../spebase -L../.. -lspe -lspebase -lpthread
+CFLAGS += -I../.. -I$(TOP) -I$(TOP)/spebase -g $(TEST_CFLAGS)
+
+LDFLAGS = $(TEST_LDFLAGS)
+LIBS := -L ../.. -lspe -lpthread
SPE_OBJS := spe-test-block spe-test-pause spe-test-start-stop spe-test-mboxwait
SPE_OBJS += spe-test-ppedma spe-test-ibox2 spe-test-mbox-block
@@ -40,4 +39,4 @@ ft: ft.c
$(CC) -o $@ $< $(CFLAGS) $(LDFLAGS) $(LIBS)
$(SPE_OBJS): %: %.c
- $(SPECC) $(SPECFLAGS) -o $@ $<
+ $(SPU_CC) $(SPU_CFLAGS) -o $@ $<
Index: b/libspe12/tests/start-stop/Makefile
===================================================================
--- a/libspe12/tests/start-stop/Makefile 2008-03-24 14:10:10.000000000 +0900
+++ b/libspe12/tests/start-stop/Makefile 2008-03-24 18:56:30.000000000 +0900
@@ -17,15 +17,14 @@
#* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#*
-CC := gcc
-SPECC := spu-gcc
-CTAGS = ctags
+TOP=../../..
-CFLAGS := -O2 -m32 -Wall -g -I../../../../head-libspe
-SPECFLAGS := -O2 -Wall
+include $(TOP)/make.defines
-LDFLAGS := -m32
-LIBS := -L../../../spebase -L../.. -lspe -lspebase -lpthread
+CFLAGS += -I../.. -I$(TOP) -I$(TOP)/spebase -g $(TEST_CFLAGS)
+
+LDFLAGS = $(TEST_LDFLAGS)
+LIBS := -L ../.. -lspe -lpthread
SPE_OBJS := spe-start-stop
OBJS := ppe-start-stop
@@ -36,8 +35,8 @@ clean:
rm -f $(OBJS) $(SPE_OBJS)
ppe-start-stop: ppe-start-stop.c ../../libspe.a
- $(CC) -o $@ $< $(CFLAGS) $(LDFLAGS) $(LIBS)
+ $(CC) $(CFLAGS) -o $@ $< $(LDFLAGS) $(LIBS)
spe-start-stop: spe-start-stop.c
- $(SPECC) $(SPECFLAGS) -o $@ $<
+ $(SPU_CC) $(SPU_CFLAGS) -o $@ $<
Index: b/tests/Makefile
===================================================================
--- a/tests/Makefile 2008-03-24 14:10:14.000000000 +0900
+++ b/tests/Makefile 2008-03-26 14:14:36.000000000 +0900
@@ -21,14 +21,11 @@ TOP=..
include $(TOP)/make.defines
-
CFLAGS += -I$(TOP)/spebase
-CFLAGS += -I$(TOP)/spethread
-CFLAGS += -I$(TOP)/spegang
-CFLAGS += -I$(TOP)/speevent
CFLAGS += -I$(TOP) -g
+CFLAGS += $(TEST_CFLAGS)
-LDFLAGS := $(CFLAGS)
+LDFLAGS := $(CFLAGS) $(TEST_LDFLAGS)
LDLIBS := -L$(TOP) -lspe2 -lpthread
ALL := testsingle testsinglemini hello hellointr\
More information about the cbe-oss-dev
mailing list