CVS: packaging makefile,NONE,1.1

Chris Liechti <[email protected]>
Newsgroups gmane.comp.hardware.texas-instruments.msp430.gcc.cvs
Message-ID <[email protected]>
Update of /cvsroot/mspgcc/packaging
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv11210

Added Files:
	makefile 
Log Message:
Add an other build script, actually a makefile. It can build the mspgcc 
toolchain for Linux (/opt/mspgcc) and Windows (installer).


--- NEW FILE: makefile ---
##############################################################################
# mspgcc build script
#
# Compile and install mspgcc parts.
# Most of the output from the compilers is redirected to log files.
#
# Requires:
#  - binutils, gcc, etc (cygwin on Windows)
#  - python
#
# Additionaly for the Windows installer:
#  - NSIS
#  - python extensions: ctypes, py2exe
#  - the filelist.py, filediff.py files_to_nsh.py scripts
#
# TODO:
#  - gdbproxy isn't covered here
#  - creating the PDF documentation
#
# Files and directories:
#       ./makefile      this file
#       ./archives/     the downloaded archives are located here
#       ./sf/           a cvs checkout is here (see "sf" target)
#
# [email protected]
##############################################################################

# versions
BINUTILS_VERSION        := 2.16
GCC_VERSION             := 3.2.3
GDB_VERSION             := 5.1.1

# location of the gnu source tarballs
ARCHIVES        = $(BUILDDIR)/archives
# cvs checkout of the mspgcc project (must have a subdir called "gcc", "msp430-libc" etc)
# see also "sf" taregt below
CVSFILES        = $(BUILDDIR)/sf
# if checked out in the packaging folder, the other files are one level up:
#~ CVSFILES        = ..

# due to hisroric reasons, GCC 3.2.3 patches are actualy in the 3.3 folder...
CVSFILESGCC     = $(CVSFILES)/gcc/gcc-3.3

# other vars
BUILDDATE      := $(shell date +%Y%m%d)
BUILDDIR       := $(PWD)

ifdef WINDOWS
INSTALLDIR      = $(BUILDDIR)/installed
else
# installation target directory
INSTALLDIR      = /opt/mspgcc
endif

# sites where the files are downloaded from
MIRROR          = ftp://sources.redhat.com/pub
MIRROR_BINUTILS = $(MIRROR)/binutils/releases
MIRROR_GDB      = $(MIRROR)/gdb/old-releases
MIRROR_GCC      = ftp://ftp.gnu.org/gnu/gcc

# inernal
BINUTILS        = binutils-$(BINUTILS_VERSION)
GCC             = gcc-$(GCC_VERSION)
GDB             = gdb-$(GDB_VERSION)
ifdef WINDIR
WINDOWS        := yes
endif

# external tools
NSIS           := "/c/Program Files/NSIS/makensis"
DOWONLOAD      := wget
ifdef WINDIR
# file lists are used to build the windows installer
FILELIST       := python filelist.py
FILEDIFF       := python filediff.py
FILELIST_RM    := rm
else
# file lists are not needed for linux -> do nothing
FILELIST       := @echo >/dev/null
FILEDIFF       := @echo >/dev/null
FILELIST_RM    := @echo >/dev/null
endif

# path so that binutils are found for the cross compiler, gcc for libc etc.
PATH           := $(INSTALLDIR)/bin:$(PATH)
export PATH

##############################################################################

all:
	@echo "/---------------------------------+"
	@echo "| mspgcc build and install script |"
	@echo "+---------------------------------/"
	@echo 
	@echo "Possible targets:"
	@echo "folders  create the folders for the archives and CVS files"
	@echo "sf       retrieve mspgcc patches with CVS"
	@echo "build    download build and install binutils, gcc, gdb, libraries"
	@echo 
	@echo "INSTALLDIR defaults to /opt/mspgcc. Edit this makefile if"
	@echo "this is not suitable."
	@echo 
	@echo "The installation target directory INSTALLDIR has to be writable"
	@echo "by the user that runs make. On Linux e.g. run as root:"
	@echo "# mkdir /opt/mspgcc; chown username.username /opt/mspgcc"
	@echo 
	@echo "Building everything, starting in an otherwise empty folder,"
	@echo "just the makefile in it:"
	@echo "# make folders sf build"
	@echo 

debug:
	@echo "date: $(BUILDDATE)"
	@echo $(INSTALLDIR)
	@echo $(BUILDDIR)

##############################################################################
# Set up the environment
folders:
	mkdir -p $(CVSFILES)
	mkdir -p $(ARCHIVES)

##############################################################################
#### Fetch files from CVS (anonymous)
##############################################################################
.PHONY: sf
sf:
	@echo Just press enter at the following password prompt
	cd $(CVSFILES) && cvs -d:pserver:[email protected]:/cvsroot/mspgcc login
	cd $(CVSFILES) && cvs -z3 -d:pserver:[email protected]:/cvsroot/mspgcc co gcc
	cd $(CVSFILES) && cvs -z3 -d:pserver:[email protected]:/cvsroot/mspgcc co gdb
	cd $(CVSFILES) && cvs -z3 -d:pserver:[email protected]:/cvsroot/mspgcc co msp430-libc
	cd $(CVSFILES) && cvs -z3 -d:pserver:[email protected]:/cvsroot/mspgcc co libraries
	cd $(CVSFILES) && cvs -z3 -d:pserver:[email protected]:/cvsroot/mspgcc co python
	cd $(CVSFILES) && cvs -z3 -d:pserver:[email protected]:/cvsroot/mspgcc co examples


##############################################################################
#### Download archives
##############################################################################

# Targets for the single archives. Files are only downloaded if the do not
# exist yet

$(ARCHIVES)/$(BINUTILS).tar.bz2:
	cd $(ARCHIVES) && $(DOWONLOAD) $(MIRROR_BINUTILS)/$(BINUTILS).tar.bz2

$(ARCHIVES)/gcc-core-$(GCC_VERSION).tar.bz2:
	cd $(ARCHIVES) && $(DOWONLOAD) $(MIRROR_GCC)/gcc-$(GCC_VERSION)/gcc-core-$(GCC_VERSION).tar.bz2
$(ARCHIVES)/gcc-g++-$(GCC_VERSION).tar.bz2:
	cd $(ARCHIVES) && $(DOWONLOAD) $(MIRROR_GCC)/gcc-$(GCC_VERSION)/gcc-g++-$(GCC_VERSION).tar.bz2

$(ARCHIVES)/gdb-$(GDB_VERSION).tar.bz2:
	cd $(ARCHIVES) && $(DOWONLOAD) $(MIRROR_GDB)/gdb-$(GDB_VERSION).tar.bz2

##############################################################################
#### Build
##############################################################################

# The -clean rules delete the build folder, the -build rules depend on the
# -clean rules, so that a build always starts in a fresh folder.
# Once built, the -install target can be called more than once, witout
# triggering a complete rebuild

# Binutils: assembler, linker and more
binutils-clean:
	rm -rf $(BINUTILS)
binutils-build: binutils-clean $(ARCHIVES)/$(BINUTILS).tar.bz2
	tar xjf $(ARCHIVES)/$(BINUTILS).tar.bz2
	#~ @echo Applying extra mspgcc patches...
	#~ cd $(BINUTILS); patch -p1 < binutils-21x1-42x-42x0.patch
	@echo "Configure and building binutils (this takes a while)"
	cd $(BINUTILS); ./configure --target=msp430 --prefix=$(INSTALLDIR) --disable-nls >$(BUILDDIR)/binutils-build.log 2>&1
	cd $(BINUTILS); make >>$(BUILDDIR)/binutils-build.log 2>&1
	@echo binutils done
binutils-install:
	cd $(BINUTILS); make install >>$(BUILDDIR)/binutils-build.log 2>&1
	$(FILELIST) $(INSTALLDIR) >files-binutils.txt

# The compiler
# optional --program-suffix=-x.x --enable-languages=c,c++,ada,f77
gcc-clean:
	rm -rf $(GCC)
gcc-build: gcc-clean \
            $(ARCHIVES)/gcc-core-$(GCC_VERSION).tar.bz2 \
            #~ $(ARCHIVES)/gcc-g++-$(GCC_VERSION).tar.bz2 \
            #~ $(ARCHIVES)/gcc-ada-$(GCC_VERSION).tar.bz2 \
            #~ $(ARCHIVES)/gcc-g77-$(GCC_VERSION).tar.bz2
	tar xjf $(ARCHIVES)/gcc-core-$(GCC_VERSION).tar.bz2
	#~ tar xjf $(ARCHIVES)/gcc-g++-$(GCC_VERSION).tar.bz2
	#~ tar xjf $(ARCHIVES)/gcc-ada-$(GCC_VERSION).tar.bz2
	#~ tar xjf $(ARCHIVES)/gcc-g77-$(GCC_VERSION).tar.bz2
	#~ tar xjf $(ARCHIVES)/gcc-java-$(GCC_VERSION).tar.bz2
	@echo Applying mspgcc patches
	cp -r $(CVSFILESGCC)/* $(GCC)
ifdef WINDOWS
	@echo Applying patch for oooooooold windoze
	cd $(GCC); patch -p1 < ../gcc-3.2.3-cygwin.patch #win98 patch
endif
	@echo "Configuring and building msp430-gcc (this takes a while)"
	cd $(GCC); ./configure --target=msp430 --prefix=$(INSTALLDIR) --disable-nls >$(BUILDDIR)/gcc-build.log 2>&1
	cd $(GCC); make >>$(BUILDDIR)/gcc-build.log 2>&1
	@echo msp430-gcc done
gcc-install:
	$(FILELIST) $(INSTALLDIR) >files-before.txt
	cd $(GCC); make install >>$(BUILDDIR)/gcc-build.log 2>&1
	$(FILELIST) $(INSTALLDIR) >files-after.txt
	$(FILEDIFF) files-before.txt files-after.txt >files-gcc.txt
	$(FILELIST_RM) files-before.txt files-after.txt

# The debugger
gdb-clean:
	rm -rf $(GDB)
gdb-build: gdb-clean \
            $(ARCHIVES)/gdb-$(GDB_VERSION).tar.bz2
	tar xjf $(ARCHIVES)/gdb-$(GDB_VERSION).tar.bz2
	@echo Applying mspgcc patches
	cp -r $(CVSFILES)/gdb/gdb-$(GDB_VERSION)/* $(GDB)
	@echo "Configuring and building msp430-gdb (this takes a while)"
	cd $(GDB); ./configure --target=msp430 --prefix=$(INSTALLDIR) --disable-nls >$(BUILDDIR)/gdb-build.log 2>&1
	cd $(GDB); make >>$(BUILDDIR)/gdb-build.log 2>&1
	@echo msp430-gdb done
gdb-install:
	$(FILELIST) $(INSTALLDIR) >files-before.txt
	cd $(GDB); make install >>$(BUILDDIR)/gdb-build.log 2>&1
	$(FILELIST) $(INSTALLDIR) >files-after.txt
	$(FILEDIFF) files-before.txt files-after.txt >files-gdb.txt
	$(FILELIST_RM) files-before.txt files-after.txt

# C library for the cross compiler
msp430-libc-clean:
	rm -rf msp430-libc
msp430-libc-build: msp430-libc-clean
	cp -r $(CVSFILES)/msp430-libc .
	cd msp430-libc/src; cat Makefile | sed -e 's^/usr/local/msp430^$(INSTALLDIR)^' > Makefile-new
	cd msp430-libc/src; rm Makefile
	cd msp430-libc/src; mv Makefile-new Makefile
	mkdir -p msp430-libc/src/msp1 msp430-libc/src/msp2
	cd msp430-libc/src; make >$(BUILDDIR)/libc-build.log 2>&1
msp430-libc-install:
	$(FILELIST) $(INSTALLDIR) >files-before.txt
	cd msp430-libc/src; make install >>$(BUILDDIR)/libc-build.log 2>&1
	$(FILELIST) $(INSTALLDIR) >files-after.txt
	$(FILEDIFF) files-before.txt files-after.txt >files-libc.txt
	$(FILELIST_RM) files-before.txt files-after.txt


msp430-gdbproxy:
	cp msp430-gdbproxy.exe $(INSTALLDIR)/bin/msp430-gdbproxy.exe

# (lib)MSP430mspgcc.dll/so (lib)HIL.dll/so and giveio, loadrv on windows.
libmspgcc-clean:
	rm -rf libmspgcc
libmspgcc-build: libmspgcc-clean
	mkdir libmspgcc
	cp -r $(CVSFILES)/jtag/* libmspgcc/
	cd libmspgcc; make >$(BUILDDIR)/libmspgcc-build.log 2>&1
libmspgcc-install:
ifdef WINDOWS
	cp libmspgcc/msp430/MSP430mspgcc.dll $(INSTALLDIR)/bin
	cp libmspgcc/hardware_access/HIL.dll $(INSTALLDIR)/bin
	mkdir -p $(INSTALLDIR)/giveio
	cd libmspgcc/hardware_access/giveio; \
            cp install_giveio.bat remove_giveio.bat status_giveio.bat \
            loaddrv.exe giveio.sys README.txt \
            $(INSTALLDIR)/giveio
else
	cd libmspgcc/msp430; make install LIB_PREFIX=$(INSTALLDIR)/lib >>$(BUILDDIR)/libmspgcc-build.log 2>&1
	cd libmspgcc/hardware_access; make install LIB_PREFIX=$(INSTALLDIR)/lib >>$(BUILDDIR)/libmspgcc-build.log 2>&1
endif

# Examples. Cleanup the examples folder and install them.
examples-build:
	rm -rf examples
	mkdir examples
	cp -r $(CVSFILES)/examples/* examples
	cd examples; make clean >$(BUILDDIR)/examples.log 2>&1
	rm -rf `find examples/ -name CVS -type d`
examples-install:
ifdef WINDOWS
	cp -r examples $(INSTALLDIR) >>$(BUILDDIR)/examples.log 2>&1
else
	mkdir -p $(INSTALLDIR)/share/doc/mspgcc-examples
	cp -r examples/* $(INSTALLDIR)/share/doc/mspgcc-examples >>$(BUILDDIR)/examples.log 2>&1
endif
	$(FILELIST) $(INSTALLDIR)/examples >files-examples.txt

# Addon mspgcc libraries: libmspgcc libcommandline and more
libraries-build:
	rm -rf libraries
	mkdir libraries
	cp -r $(CVSFILES)/libraries/* libraries
	cd libraries; make >$(BUILDDIR)/libraries.log 2>&1
libraries-install:
	$(FILELIST) $(INSTALLDIR) >files-before.txt
	cd libraries; make PREFIX=$(INSTALLDIR) install >>$(BUILDDIR)/libraries.log 2>&1
	$(FILELIST) $(INSTALLDIR) >files-after.txt
	$(FILEDIFF) files-before.txt files-after.txt >files-libraries.txt
	$(FILELIST_RM) files-before.txt files-after.txt

# Documenation. Currently depends on prebuilt PDFs
docs-install:
	rm -rf $(INSTALLDIR)/docs
	mkdir $(INSTALLDIR)/docs
ifdef WINDOWS
	cp mspgcc-manual.pdf mspgcc-faq.pdf $(INSTALLDIR)/docs
	$(FILELIST) $(INSTALLDIR)/docs >files-docs.txt
else
	mkdir -p $(INSTALLDIR)/share/doc/mspgcc-doc
	cp mspgcc-manual.pdf mspgcc-faq.pdf $(INSTALLDIR)/share/doc/mspgcc-doc
endif

# msp430-jtag, msp430-bsl and more tools
pytools-build:
	rm -rf python
	mkdir python
	cp -r $(CVSFILES)/python/* python/
ifdef WINDOWS
	cp libmspgcc/msp430/MSP430mspgcc.dll python/
	cp libmspgcc/hardware_access/HIL.dll python/
	cd python/win32 && rm -rf ../build; python setup-bsl-py2exe.py
	cd python/win32 && rm -rf ../build; python setup-jtag-py2exe.py
	cd python/win32 && rm -rf ../build; python setup-downloader-py2exe.py
else
	rm -r python/CVS python/msp430/CVS
	echo "#!/bin/bash" >python/msp430-jtag
	echo "# Wrapper script for msp430-jtag.py. It passes the location" >>python/msp430-jtag
	echo "# of the mspgcc libraries in environment variables." >>python/msp430-jtag
	echo "export LIBMSPGCC_PATH=$(INSTALLDIR)/lib" >>python/msp430-jtag
	echo "export LD_LIBRARY_PATH=$$LD_LIBRARY_PATH:$(INSTALLDIR)/lib" >>python/msp430-jtag
	echo "exec $(INSTALLDIR)/bin/msp430-jtag-unwrapped \$$@" >>python/msp430-jtag
endif
# this installs the msp430 python library only for the mspgcc tools
# windows: the py2exe'd files are just copied
# linux: to correctly install the library for the system wide python,
# "python setup.py install" should be run
# msp430-jtag is installed with a wrapper script, that way, the libmspgcc and
# libHIL libraries do not need to be installed system wide.
pytools-install:
ifdef WINDOWS
	cp -r python/bin/* $(INSTALLDIR)/bin
else
	install python/msp430-jtag $(INSTALLDIR)/bin/msp430-jtag
	install python/msp430-jtag.py $(INSTALLDIR)/bin/msp430-jtag-unwrapped
	install python/msp430-bsl.py $(INSTALLDIR)/bin/msp430-bsl
	install python/msp430-ram-usage.py $(INSTALLDIR)/bin/msp430-ram-usage
	install python/titext2ihex.py $(INSTALLDIR)/bin/titext2ihex
	cp -r python/msp430 $(INSTALLDIR)/bin
endif

# strip executables so that they get smaller
stripfiles:
ifdef WINDOWS
	strip $(INSTALLDIR)/bin/*.exe
	strip $(INSTALLDIR)/msp430/bin/*.exe
	strip $(INSTALLDIR)/lib/gcc-lib/msp430/$(GCC_VERSION)/*.exe
else
	for FILE in $(INSTALLDIR)/bin/* $(INSTALLDIR)/msp430/bin/* $(INSTALLDIR)/lib/gcc-lib/msp430/$(GCC_VERSION)/*; do test -x $$FILE && strip $$FILE; done
endif

# create a file with a timestamp
stamp:
	echo >$(INSTALLDIR)/stamp.txt "Build date: $(BUILDDATE)"

##############################################################################
#### High level targets
##############################################################################

# Build and install step by step.
#
# e.g. to build gcc, it is required to have a working msp430 binutils this
# is ensured by first building and installing them, then building and
# installing gcc and so on.
#
# On Windows, stripfiles must be called before the python tools are installed
# or they will be broken.
build:  binutils-build          binutils-install \
        gcc-build               gcc-install \
        msp430-libc-build       msp430-libc-install \
        gdb-build               gdb-install \
        libmspgcc-build         libmspgcc-install \
        stripfiles \
        pytools-build           pytools-install \
        libraries-buils         libraries-install

# Examples and documentation
build-addon: examples-build examples-install  docs-install

# Build everything and the windows installer
build-installer:  build build-addon  windows-installer

ifdef WINDOWS
# Remove the installation directory. Only useful Windows, where the install
# directory is a fresh folder.
# Dangerus on other systems, e.g. it would be a bad idea to remove
# /usr/local on linux, thus disabled.
clean-installdir:
	rm -rf $(INSTALLDIR)
endif

# If the build directory is still intact, re-install everyting
install-only: binutils-install gcc-install \
              msp430-libc-install gdb-install \
              libmspgcc-install libraries-install \
              stripfiles \
              pytools-install \
              examples-install docs-install

##############################################################################
#### Windows installer
##############################################################################

# file list -> NSIS include conversion

msp430-binutils-install.nsh: files-binutils.txt
	python files-to_nsh.py files-binutils.txt binutils $(INSTALLDIR)

msp430-gcc-install.nsh: files-gcc.txt
	python files-to_nsh.py files-gcc.txt gcc $(INSTALLDIR)

msp430-gdb-install.nsh: files-gdb.txt
	python files-to_nsh.py files-gdb.txt gdb $(INSTALLDIR)

msp430-libc-install.nsh: files-libc.txt
	python files-to_nsh.py files-libc.txt libc $(INSTALLDIR)

msp430-docs-install.nsh: files-docs.txt
	python files-to_nsh.py files-docs.txt docs $(INSTALLDIR)

msp430-examples-install.nsh: files-examples.txt
	python files-to_nsh.py files-examples.txt examples $(INSTALLDIR)

msp430-libraries-install.nsh: files-libraries.txt
	python files_to_nsh.py files-libraries.txt libraries $(INSTALLDIR)

# process all the file lists, build installer
windows-installer: stamp msp430-binutils-install.nsh msp430-gcc-install.nsh \
            msp430-gdb-install.nsh msp430-libc-install.nsh \
            msp430-docs-install.nsh msp430-examples-install.nsh
	$(NSIS) mspgcc-full-install.nsi



-------------------------------------------------------
SF.Net email is sponsored by:
Tame your development challenges with Apache's Geronimo App Server. Download
it for free - -and be entered to win a 42" plasma tv or your very own
Sony(tm)PSP.  Click here to play: http://sourceforge.net/geronimo.php
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.