libucmake-app_lib
276 lines
| 9.1 KiB
| text/plain
|
TextLexer
jeandet@pc-de-jeandet3.LAB-LPP.LOCAL
|
r18 | #!/bin/bash | ||
#/*------------------------------------------------------------------------------ | ||||
#-- This file is a part of the libuc, microcontroler library | ||||
#-- Copyright (C) 2011, Alexis Jeandet | ||||
#-- | ||||
#-- This program 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; either version 3 of the License, or | ||||
#-- (at your option) any later version. | ||||
#-- | ||||
#-- 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; if not, write to the Free Software | ||||
#-- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||||
#------------------------------------------------------------------------------- | ||||
#-- Author : Alexis Jeandet | ||||
#-- Mail : alexis.jeandet@gmail.com | ||||
#-------------------------------------------------------------------------------*/ | ||||
OBJDIR="obj" | ||||
BINDIR="bin" | ||||
INC_LIBS_DEPS="" | ||||
BIN_LIBS_DEPS="" | ||||
function generateObjrules { | ||||
SRCS=`getFilesList $PROJECTFILE SOURCES | sed 's/SOURCES//' | sed 's/+=//'` | ||||
if [ "$1" == "Makefile" ] ; then | ||||
SRCS=`getFilesList $PROJECTFILE SOURCES | sed 's/SOURCES//' | sed 's/+=//'` | ||||
else | ||||
TEMP=`getFilesList $PROJECTFILE $1.SOURCES` | ||||
if [ -z "$TEMP" ] ; then | ||||
SRCS=`getFilesList $PROJECTFILE '*'.SOURCES | sed 's/*\.SOURCES//' | sed 's/+=//'` | ||||
else | ||||
SRCS=`getFilesList $PROJECTFILE $1.SOURCES | sed "s/$1"'\.SOURCES//' | sed 's/+=//'` | ||||
fi | ||||
fi | ||||
for src in $SRCS | ||||
do | ||||
obj=`echo $src| sed 's/\.c/\.o/g' | sed 's/\.s/\.o/g'` | ||||
echo "$OBJDIR/$obj: $src "'$(OBJDIR) | ||||
$(LIBUC_CC) -O3 -I $(INCLUDES) -c $(CFLAGS) $< -o $@ | ||||
' | ||||
done | ||||
} | ||||
function generateObjlist { | ||||
if [ "$1" == "Makefile" ] ; then | ||||
OBJS=`getFilesList $PROJECTFILE SOURCES | sed 's/SOURCES//' | sed 's/+=//'| sed 's/\.c/\.o/g' | sed 's/\.s/\.o/g'` | ||||
else | ||||
TEMP=`getFilesList $PROJECTFILE $1.SOURCES` | ||||
if [ -z "$TEMP" ] ; then | ||||
OBJS=`getFilesList $PROJECTFILE '*'.SOURCES | sed 's/*\.SOURCES//' | sed 's/+=//'| sed 's/\.c/\.o/g' | sed 's/\.s/\.o/g'` | ||||
else | ||||
OBJS=`getFilesList $PROJECTFILE $1.SOURCES | sed "s/$1"'\.SOURCES//' | sed 's/+=//'| sed 's/\.c/\.o/g' | sed 's/\.s/\.o/g'` | ||||
fi | ||||
fi | ||||
for obj in $OBJS | ||||
do | ||||
echo "$OBJDIR/$obj \\" | ||||
done | ||||
} | ||||
function applib-run { | ||||
if [ $1 == "lib" ] ; then | ||||
tmplt="lib" | ||||
else | ||||
tmplt="bin" | ||||
fi | ||||
Targets $PROJECTFILE | ||||
if [ -z "$TARGETS" ] ; then | ||||
TARGETS="Makefile" | ||||
else | ||||
echo "Multi target" | ||||
fi | ||||
for ITEMS in $TARGETS | ||||
do | ||||
if [ "$ITEMS" == "Makefile" ] ; then | ||||
MAKEFILE="Makefile" | ||||
ITEMS="" | ||||
else | ||||
MAKEFILE="$ITEMS.mk" | ||||
fi | ||||
echo 'PROJECTDIR = `pwd`'> $MAKEFILE | ||||
echo "LIBUC = $libuc2" >> $MAKEFILE | ||||
Target $PROJECTFILE $ITEMS | ||||
Arch $PROJECTFILE $ITEMS | ||||
Cpumodel $PROJECTFILE $ITEMS | ||||
Bspname $PROJECTFILE $ITEMS | ||||
Objdir $PROJECTFILE | ||||
Bindir $PROJECTFILE | ||||
Libs_Inc $PROJECTFILE $ITEMS | ||||
Libs_Link $PROJECTFILE $ITEMS | ||||
HeadersInstallPath $PROJECTFILE $ITEMS | ||||
TargetInstallPath $PROJECTFILE $ITEMS | ||||
getBSP $PROJECTFILE $ITEMS | ||||
ExtractCFLAGS $PROJECTFILE $ITEMS | ||||
ExtractLDFLAGS $PROJECTFILE $ITEMS | ||||
ExtractODFLAGS $PROJECTFILE $ITEMS | ||||
echo "Current BSP is $BSP" | ||||
echo $SRCFILES >> $MAKEFILE | ||||
if [ "$MAKEFILE" == "Makefile" ] ; then | ||||
getFilesList $PROJECTFILE HEADERS >> Makefile | ||||
getFilesList $PROJECTFILE SOURCES | sed 's/SOURCES/SOURCES/' >> Makefile | ||||
else | ||||
TEMP=`getFilesList $PROJECTFILE $ITEMS.HEADERS` | ||||
if [ -z "$TEMP" ] ; then | ||||
getFilesList $PROJECTFILE '*'.HEADERS | sed 's/*\.'// >> $MAKEFILE | ||||
else | ||||
getFilesList $PROJECTFILE $ITEMS.HEADERS | sed s/$ITEMS'\.'// >> $MAKEFILE | ||||
fi | ||||
TEMP=`getFilesList $PROJECTFILE $ITEMS.SOURCES` | ||||
if [ -z "$TEMP" ] ; then | ||||
getFilesList $PROJECTFILE '*'.SOURCES | sed 's/*\.'SOURCES/SOURCES/ >> $MAKEFILE | ||||
else | ||||
getFilesList $PROJECTFILE $ITEMS.SOURCES | sed s/$ITEMS'\.'SOURCES/SOURCES/ >> $MAKEFILE | ||||
fi | ||||
fi | ||||
if [ "$TARGET" == "libbsp" ] ; then | ||||
mkdir -p $libuc2/bsp/cfg/$BSPNAME | ||||
echo "CPUMODEL = $CPUMODEL" > $libuc2/bsp/cfg/$BSPNAME/bsp.mk | ||||
echo "ARCH = $ARCH" >> $libuc2/bsp/cfg/$BSPNAME/bsp.mk | ||||
fi | ||||
echo "=========================================================================" | ||||
echo " M A K E F I L E G E N E R A T I O N " | ||||
echo "-------------------------------------------------------------------------" | ||||
echo " Template = library " | ||||
echo " Architecture = $ARCH " | ||||
echo " Output file = $TARGET " | ||||
echo "=========================================================================" | ||||
echo "" | ||||
echo " Start Writing Makefile ..." | ||||
echo "OBJDIR = $OBJDIR" >> $MAKEFILE | ||||
echo "BINDIR = $BINDIR" >> $MAKEFILE | ||||
echo "OBJECTFILES = `generateObjlist $MAKEFILE`">> $MAKEFILE | ||||
echo " " >> $MAKEFILE | ||||
echo "ARCH = $ARCH" >> $MAKEFILE | ||||
echo "CPUMODEL = $CPUMODEL" >> $MAKEFILE | ||||
echo "ARCHFOLDER = "'$(LIBUC)'"/rules/$ARCH" >> $MAKEFILE | ||||
echo "TARGET=$TARGET">> $MAKEFILE | ||||
echo "LIBUC_INCLUDES=$INCLUDES">> $MAKEFILE | ||||
echo "LIBUC_LIBRARIES=$LIBRARIES">> $MAKEFILE | ||||
echo "TARGETINSTALLPATH=$TARGETINSTALLPATH">> $MAKEFILE | ||||
echo "HEADERSINSTALLPATH=$HEADERSINSTALLPATH">> $MAKEFILE | ||||
echo "BSP=$BSP">> $MAKEFILE | ||||
echo ' | ||||
#--------------------------------------------------------------------------------- | ||||
# LIBRARY DEFINITIONS | ||||
#--------------------------------------------------------------------------------- | ||||
LIBUC_LIBS_DIR = $(LIBUC)/lib/bin/$(ARCH) | ||||
LIBUC_INC_DIR = $(LIBUC)/lib/includes | ||||
LIBUC_CFG_DIR = $(LIBUC)/lib/cfg | ||||
include $(LIBUC)/rules/common/libsrules.mk | ||||
#--------------------------------------------------------------------------------- | ||||
# BOARD SUPORT PACKAGES | ||||
#--------------------------------------------------------------------------------- | ||||
LIBUC_BSP_DIR=$(LIBUC)/bsp | ||||
LIBUC_BSP_BIN_DIR= $(LIBUC_BSP_DIR)/bin | ||||
LIBUC_BSP_INC_DIR= $(LIBUC_BSP_DIR)/includes | ||||
LIBUC_BSP_CFG_DIR= $(LIBUC_BSP_DIR)/cfg | ||||
LIBUC_BSP = -L $(LIBUC_BSP_BIN_DIR)/$(BSP) -static -lbsp | ||||
LIBUC_BSP_INC = -I $(LIBUC_BSP_INC_DIR)/$(BSP) | ||||
' >> $MAKEFILE | ||||
if [ "$tmplt" == "bin" ] ; then | ||||
echo 'include $(LIBUC_BSP_CFG_DIR)/$(BSP)/bsp.mk' >> $MAKEFILE | ||||
fi | ||||
echo 'include $(ARCHFOLDER)/rules.mk' >> $MAKEFILE | ||||
echo 'INCLUDES += -I ./ -I $(LIBUC_INC_DIR) $(LIBUC_INCLUDES) $(LIBUC_BSP_INC)' >> $MAKEFILE | ||||
echo "$CFLAGS" >> $MAKEFILE | ||||
echo "$LDFLAGS" >> $MAKEFILE | ||||
echo "$ODFLAGS" >> $MAKEFILE | ||||
echo '' >> $MAKEFILE | ||||
echo "all:$tmplt" >> $MAKEFILE | ||||
echo " @echo Code compiled" >> $MAKEFILE | ||||
echo '' >> $MAKEFILE | ||||
echo '.SUFFIXES: .o .c .s | ||||
.c.o: | ||||
$(LIBUC_CC) -O3 -I $(INCLUDES) -c $(CFLAGS) $< -o $@ | ||||
.s.o: | ||||
$(LIBUC_CC) -O3 -I $(INCLUDES) -c $(CFLAGS) $< -o $@ | ||||
bin: $(BINDIR)/$(TARGET).elf $(BINDIR)/$(TARGET).bin $(BINDIR)/$(TARGET).hex | ||||
@echo "compile bin" | ||||
lib: $(BINDIR)/$(TARGET).a | ||||
@echo "compile lib" | ||||
$(BINDIR)/$(TARGET).a: $(OBJECTFILES) | ||||
mkdir -p $(BINDIR) | ||||
$(LIBUC_AR) rcs $@ $(OBJECTFILES) | ||||
$(OBJDIR): | ||||
mkdir -p $(OBJDIR) | ||||
%.elf: $(LINKER_SCRIPT) $(APPOBJECTFILES) $(OBJECTFILES) | ||||
mkdir -p $(BINDIR) | ||||
$(LIBUC_CC) $(LIBUC_LDFLAGS) $(LIBUC_CFLAGS) -T $^ -o $@ $(LIBUC_BSP) $(LIBUC_LIBRARIES) | ||||
$(LIBUC_OBJDUMP) $(LIBUC_ODFLAGS) $@ > $(@:.elf=.dump) | ||||
$(LIBUC_SIZE) $@ | ||||
%.bin: %.elf $(BIN_LIBS_DEPS) | ||||
$(LIBUC_OBJCOPY) $(LIBUC_CPFLAGS) -O binary $< $*.bin | ||||
@echo "BIN_LIBS_DEPS" | ||||
@echo $(BIN_LIBS_DEPS) | ||||
%.hex: %.elf | ||||
$(LIBUC_OBJCOPY) $(LIBUC_CPFLAGS) -O ihex $< $*.hex | ||||
$(TARGETINSTALLPATH)/$(TARGET).a: $(BINDIR)/$(TARGET).a | ||||
mkdir -p $(TARGETINSTALLPATH) | ||||
cp $(BINDIR)/$(TARGET).a $(TARGETINSTALLPATH)/$(TARGET).a | ||||
libinstall: $(TARGETINSTALLPATH)/$(TARGET).a | ||||
@if [ -z $(HEADERSINSTALLPATH) ] ; then echo "No headers to install" ; else mkdir -p $(HEADERSINSTALLPATH) ; fi | ||||
@if [ -z "$(HEADERS)" ] ; then echo "No headers to install" ; else echo "cp -f $(HEADERS) $(HEADERSINSTALLPATH)/" ; cp -f $(HEADERS) $(HEADERSINSTALLPATH)/ ; fi | ||||
clean: | ||||
rm -f *.o *.d *.bin *.hex *.dump *.map *.a *.elf | ||||
rm -f $(OBJECTFILES) | ||||
rm -f $(BINDIR)/*.bin | ||||
rm -f $(BINDIR)/*.hex | ||||
rm -f $(BINDIR)/*.dump | ||||
rm -f $(BINDIR)/*.map | ||||
rm -f $(BINDIR)/*.a | ||||
rm -f $(BINDIR)/*.elf | ||||
rm -f $(DEVSOURCESND) | ||||
rm -f $(ASMDEVSOURCESND) | ||||
distclean: clean libclean | ||||
rm -f $(TARGETINSTALLPATH)/*.bin | ||||
rm -f $(TARGETINSTALLPATH)/*.a | ||||
rm -f Makefile | ||||
' >> $MAKEFILE | ||||
generateObjrules $MAKEFILE >> $MAKEFILE | ||||
echo 'install:'"$tmplt"'install | ||||
' >> $MAKEFILE | ||||
echo 'libclean:' >> $MAKEFILE | ||||
echo ' rm -f $(TARGETINSTALLPATH)/$(TARGET).a' >> $MAKEFILE | ||||
echo " Makefile writing finished" | ||||
echo "" | ||||
echo "=========================================================================" | ||||
echo "" | ||||
done | ||||
if [ "$TARGETS" == "Makefile" ] ; then | ||||
MAKEFILE="Makefile" | ||||
else | ||||
for mktargt in "all" "install" " clean" "distclean" | ||||
do | ||||
echo "" >> Makefile | ||||
echo "$mktargt:" >> Makefile | ||||
for ITEMS in $TARGETS | ||||
do | ||||
echo " make $mktargt -f $MAKEFILE" >> Makefile | ||||
done | ||||
echo "" >> Makefile | ||||
done | ||||
fi | ||||
} | ||||