@@ -1,157 +1,164 | |||
|
1 | 1 | #!/bin/bash |
|
2 | 2 | #/*------------------------------------------------------------------------------ |
|
3 | 3 | #-- This file is a part of the libuc, microcontroler library |
|
4 | 4 | #-- Copyright (C) 2011, Alexis Jeandet |
|
5 | 5 | #-- |
|
6 | 6 | #-- This program is free software; you can redistribute it and/or modify |
|
7 | 7 | #-- it under the terms of the GNU General Public License as published by |
|
8 | 8 | #-- the Free Software Foundation; either version 3 of the License, or |
|
9 | 9 | #-- (at your option) any later version. |
|
10 | 10 | #-- |
|
11 | 11 | #-- This program is distributed in the hope that it will be useful, |
|
12 | 12 | #-- but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 | 13 | #-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14 | 14 | #-- GNU General Public License for more details. |
|
15 | 15 | #-- |
|
16 | 16 | #-- You should have received a copy of the GNU General Public License |
|
17 | 17 | #-- along with this program; if not, write to the Free Software |
|
18 | 18 | #-- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
19 | 19 | #------------------------------------------------------------------------------- |
|
20 | 20 | #-- Author : Alexis Jeandet |
|
21 | 21 | #-- Mail : alexis.jeandet@gmail.com |
|
22 | 22 | #-------------------------------------------------------------------------------*/ |
|
23 | 23 | TEMPLATE="" |
|
24 | 24 | ARCH="" |
|
25 | 25 | TARGET="" |
|
26 | 26 | SRCFILES="" |
|
27 | 27 | INCLUDES="" |
|
28 | 28 | LIBRARIES="" |
|
29 | 29 | HEADERSINSTALLPATH="" |
|
30 | 30 | TARGETINSTALLPATH="" |
|
31 | BSP="generic" | |
|
31 | 32 | |
|
32 | 33 | function getFilesList { |
|
33 | 34 | sed ':a;N;$!ba;s/\\\n/ /g' $1 | sed ':a;N;$!ba;s/\\ \n/ /g' | grep -i $2 | sed 's/\t//g' |
|
34 | 35 | } |
|
35 | 36 | |
|
36 | 37 | |
|
37 | 38 | function Template { |
|
38 | 39 | TEMPLATE=`more $1 | grep -i "TEMPLATE " | sed s/TEMPLATE// | sed s/=// | sed 's/^[ \t]*//;s/[ \t]*$//'` |
|
39 | 40 | } |
|
40 | 41 | |
|
41 | 42 | function Arch { |
|
42 | 43 | ARCH=`more $1 | grep -i "ARCH " | sed s/ARCH// | sed s/=// | sed 's/^[ \t]*//;s/[ \t]*$//'` |
|
43 | 44 | } |
|
44 | 45 | |
|
45 | 46 | function Target { |
|
46 | 47 | TARGET=`more $1 | grep -i "TARGET " | sed s/TARGET// | sed s/=// | sed 's/^[ \t]*//;s/[ \t]*$//'` |
|
47 | 48 | } |
|
48 | 49 | |
|
49 | 50 | function Libs_Inc { |
|
50 | 51 | INCLUDEStmp=`more $1 | grep -i "LIBS " | sed s/LIBS// |sed s/+//|sed s/=//| sed 's/^[ \t]*//;s/[ \t]*$//'` |
|
51 | 52 | for FILES in $INCLUDEStmp |
|
52 | 53 | do |
|
53 | 54 | INCLUDES+='$('"LIBUC_INC_DIR_$FILES) " |
|
54 | 55 | done |
|
55 | 56 | } |
|
56 | 57 | function Libs_Link { |
|
57 | 58 | LIBRARIEStmp=`more $1 | grep -i "LIBS " | sed s/LIBS// |sed s/+//|sed s/=//| sed 's/^[ \t]*//;s/[ \t]*$//'` |
|
58 | 59 | for FILES in $LIBRARIEStmp |
|
59 | 60 | do |
|
60 | 61 | LIBRARIES+='$('"LIBUC_LIBS_DIR_$FILES) "'$('"LIBUC_LIBS_$FILES) " |
|
61 | 62 | done |
|
62 | 63 | } |
|
63 | 64 | |
|
64 | 65 | function HeadersInstallPath { |
|
65 | 66 | HEADERSINSTALLPATH=`more $1 | grep -i "HEADERSINSTALLPATH" | sed s/HEADERSINSTALLPATH// | sed s/=// | sed 's/^[ \t]*//;s/[ \t]*$//'` |
|
66 | 67 | } |
|
67 | 68 | |
|
68 | 69 | function TargetInstallPath { |
|
69 | 70 | TARGETINSTALLPATH=`more $1 | grep -i "TARGETINSTALLPATH" | sed s/TARGETINSTALLPATH// | sed s/=// | sed 's/^[ \t]*//;s/[ \t]*$//'` |
|
70 | 71 | } |
|
71 | 72 | |
|
73 | function getBSP { | |
|
74 | BSP=`more $1 | grep -i "BSP" | sed s/BSP// | sed s/=// | sed 's/^[ \t]*//;s/[ \t]*$//'` | |
|
75 | } | |
|
76 | ||
|
72 | 77 | if [ -z "$1" ] ; then |
|
73 | 78 | echo "try to find a project file ..." |
|
74 | 79 | TMP=`ls *.pro` |
|
75 | 80 | i=1 |
|
76 | 81 | for Files in $TMP |
|
77 | 82 | do |
|
78 | 83 | echo "found $Files" |
|
79 | 84 | PROJECTFILES[i]=$Files |
|
80 | 85 | i=$((i + 1)) |
|
81 | 86 | done |
|
82 | 87 | if [ -z "${PROJECTFILES[1]}" ]; then |
|
83 | 88 | exit |
|
84 | 89 | else |
|
85 | 90 | PROJECTFILE=${PROJECTFILES[1]} |
|
86 | 91 | fi |
|
87 | 92 | |
|
88 | 93 | else |
|
89 | 94 | PROJECTFILE=$1 |
|
90 | 95 | fi |
|
91 | 96 | |
|
92 | 97 | CURRENTDIR=`pwd` |
|
93 | 98 | Template $PROJECTFILE |
|
99 | echo "Template = $TEMPLATE" | |
|
94 | 100 | echo '' > Makefile |
|
95 | 101 | echo 'PROJECTDIR = `pwd`'>> Makefile |
|
96 | 102 | echo "LIBUC = $libuc2" >> Makefile |
|
97 | 103 | |
|
98 | if(echo $TEMPLATE|grep -i 'dir'); then | |
|
104 | if(echo $TEMPLATE | grep -i 'dir'); then | |
|
99 | 105 | |
|
100 | 106 | echo 'include $(LIBUC)/rules/common/rules.mk' >> Makefile |
|
101 | 107 | SUBDIRS=`getFilesList $PROJECTFILE SUBDIRS | sed 's/SUBDIRS//' | sed 's/=//' | sed 's/+//' ` |
|
102 | 108 | CURRENTDIR=`pwd` |
|
103 | echo $CURRENTDIR | |
|
104 | 109 | echo "" >> Makefile |
|
105 | 110 | echo 'all:subdir' >> Makefile |
|
106 | 111 | for DIRS in $SUBDIRS |
|
107 | 112 | do |
|
113 | echo "enter $DIRS" | |
|
108 | 114 | cd $DIRS |
|
115 | echo "run $0" | |
|
109 | 116 | $0 |
|
110 | 117 | cd $CURRENTDIR |
|
118 | echo "exit $DIRS" | |
|
111 | 119 | if [ -e "$DIRS/Makefile" ]; then |
|
112 | 120 | echo " make -C $DIRS">> Makefile |
|
113 | 121 | fi |
|
114 | 122 | done |
|
115 | 123 | echo " @echo Code compiled" >> Makefile |
|
116 | 124 | echo "" >> Makefile |
|
117 | 125 | else |
|
118 | 126 | Target $PROJECTFILE |
|
119 | 127 | Arch $PROJECTFILE |
|
120 | 128 | Libs_Inc $PROJECTFILE |
|
121 | 129 | Libs_Link $PROJECTFILE |
|
122 | 130 | HeadersInstallPath $PROJECTFILE |
|
123 | 131 | TargetInstallPath $PROJECTFILE |
|
132 | getBSP $PROJECTFILE | |
|
124 | 133 | echo $SRCFILES >> Makefile |
|
125 | 134 | getFilesList $PROJECTFILE HEADERS >> Makefile |
|
126 | 135 | getFilesList $PROJECTFILE SOURCES >> Makefile |
|
127 | 136 | echo 'OBJECTFILES = $(SOURCES:.c=.o)'>> Makefile |
|
128 | 137 | echo "ARCH = "'$(LIBUC)'"/rules/$ARCH" >> Makefile |
|
129 | 138 | echo "TARGET=$TARGET">> Makefile |
|
130 | 139 | echo "LIBUC_INCLUDES=$INCLUDES">> Makefile |
|
131 | 140 | echo "LIBUC_LIBRARIES=$LIBRARIES">> Makefile |
|
132 | 141 | echo "TARGETINSTALLPATH=$TARGETINSTALLPATH">> Makefile |
|
133 | 142 | echo "HEADERSINSTALLPATH=$HEADERSINSTALLPATH">> Makefile |
|
143 | echo "BSP=$BSP">> Makefile | |
|
134 | 144 | echo 'include $(ARCH)/rules.mk' >> Makefile |
|
135 | 145 | |
|
136 | 146 | if(echo $TEMPLATE|grep -i app); then |
|
137 | 147 | echo '' >> Makefile |
|
138 | 148 | echo 'all:bin' >> Makefile |
|
139 | 149 | echo " @echo Code compiled" >> Makefile |
|
140 | 150 | else |
|
141 | 151 | if(echo $TEMPLATE|grep -i lib); then |
|
142 | 152 | echo '' >> Makefile |
|
143 | 153 | echo 'all:lib' >> Makefile |
|
144 | 154 | echo " @echo Code compiled" >> Makefile |
|
145 | 155 | fi |
|
146 | 156 | fi |
|
147 | 157 | fi |
|
148 | 158 | |
|
149 | echo $TEMPLATE | |
|
150 | echo $TARGET | |
|
151 | echo $ARCH | |
|
152 | 159 | |
|
153 | 160 | |
|
154 | 161 | |
|
155 | 162 | |
|
156 | 163 | |
|
157 | 164 |
@@ -1,148 +1,157 | |||
|
1 | 1 | #/*------------------------------------------------------------------------------ |
|
2 | 2 | #-- This file is a part of the libuc, microcontroler library |
|
3 | 3 | #-- Copyright (C) 2011, Alexis Jeandet |
|
4 | 4 | #-- |
|
5 | 5 | #-- This program is free software; you can redistribute it and/or modify |
|
6 | 6 | #-- it under the terms of the GNU General Public License as published by |
|
7 | 7 | #-- the Free Software Foundation; either version 3 of the License, or |
|
8 | 8 | #-- (at your option) any later version. |
|
9 | 9 | #-- |
|
10 | 10 | #-- This program is distributed in the hope that it will be useful, |
|
11 | 11 | #-- but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 | 12 | #-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 | 13 | #-- GNU General Public License for more details. |
|
14 | 14 | #-- |
|
15 | 15 | #-- You should have received a copy of the GNU General Public License |
|
16 | 16 | #-- along with this program; if not, write to the Free Software |
|
17 | 17 | #-- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
18 | 18 | #------------------------------------------------------------------------------- |
|
19 | 19 | #-- Author : Alexis Jeandet |
|
20 | 20 | #-- Mail : alexis.jeandet@gmail.com |
|
21 | 21 | #-------------------------------------------------------------------------------*/ |
|
22 | 22 | |
|
23 | 23 | #--------------------------------------------------------------------------------- |
|
24 | 24 | # GCC EXECUTABLES |
|
25 | 25 | #--------------------------------------------------------------------------------- |
|
26 | 26 | LIBUC_PREFIX = arm-none-eabi- |
|
27 | 27 | LIBUC_CC = $(LIBUC_PREFIX)gcc |
|
28 | 28 | LIBUC_CXX = $(LIBUC_PREFIX)g++ |
|
29 | 29 | LIBUC_AR = $(LIBUC_PREFIX)ar |
|
30 | 30 | LIBUC_AS = $(LIBUC_PREFIX)as |
|
31 | 31 | LIBUC_LD = $(LIBUC_PREFIX)ld |
|
32 | 32 | LIBUC_SIZE = $(LIBUC_PREFIX)size |
|
33 | 33 | LIBUC_STRIP = $(LIBUC_PREFIX)strip -s |
|
34 | 34 | LIBUC_READELF = $(LIBUC_PREFIX)readelf |
|
35 | 35 | LIBUC_OBJCOPY=$(LIBUC_PREFIX)objcopy |
|
36 | 36 | LIBUC_OBJDUMP=$(LIBUC_PREFIX)objdump |
|
37 | 37 | |
|
38 | 38 | |
|
39 | 39 | |
|
40 | 40 | #--------------------------------------------------------------------------------- |
|
41 | 41 | # GCC FLAGS |
|
42 | 42 | #--------------------------------------------------------------------------------- |
|
43 | 43 | LIBUC_FMCU = -mcpu=cortex-m3 |
|
44 | 44 | LIBUC_CFLAGS = $(LIBUC_FMCU) |
|
45 | 45 | LIBUC_CFLAGS = --std=gnu99 -fgnu89-inline -mcpu=cortex-m3 -mthumb |
|
46 | 46 | LIBUC_CFLAGS += -ffunction-sections -fdata-sections |
|
47 | 47 | LIBUC_LDFLAGS = --gc-sections |
|
48 | 48 | LIBUC_ODFLAGS = -x --syms |
|
49 | 49 | LIBUC_CPFLAGS = |
|
50 | 50 | LIBUC_CFLAGS_WARN_ON = -Wall |
|
51 | 51 | LIBUC_CFLAGS_WARN_OFF = -w |
|
52 | 52 | LIBUC_CFLAGS_RELEASE = -O2 |
|
53 | 53 | LIBUC_CFLAGS_DEBUG = -g |
|
54 | 54 | LIBUC_CFLAGS_RELEASE_WITH_DEBUGINFO += -O2 -g |
|
55 | 55 | LIBUC_CFLAGS_STATIC_LIB = -fPIC |
|
56 | 56 | LIBUC_CFLAGS_SOFT_FPU = -msoft-float |
|
57 | 57 | LIBUC_CFLAGS_HARD_FPU = |
|
58 | 58 | |
|
59 | 59 | LIBUC_CXXFLAGS = $(LIBUC_FMCU) |
|
60 | 60 | LIBUC_CXXFLAGS += -g -gdwarf-2 |
|
61 | 61 | LIBUC_CXXFLAGS += -Wextra -Wundef -Wcast-align -mthumb -msoft-float |
|
62 | 62 | LIBUC_CXXFLAGS_WARN_ON = -Wall |
|
63 | 63 | LIBUC_CXXFLAGS_WARN_OFF = -w |
|
64 | 64 | LIBUC_CXXFLAGS_RELEASE = -O2 |
|
65 | 65 | LIBUC_CXXFLAGS_DEBUG = -g |
|
66 | 66 | LIBUC_CXXFLAGS_RELEASE_WITH_DEBUGINFO += -O2 -g |
|
67 | 67 | LIBUC_CXXFLAGS_STATIC_LIB = -fPIC |
|
68 | 68 | LIBUC_CXXFLAGS_SOFT_FPU = -msoft-float |
|
69 | 69 | LIBUC_CXXFLAGS_HARD_FPU = |
|
70 | 70 | |
|
71 | 71 | LIBUC_LIBS = |
|
72 | 72 | LIBUC_LIBS_UART = -luart |
|
73 | 73 | LIBUC_LIBS_SPI = -lspi |
|
74 | 74 | LIBUC_LIBS_IIC = -liic |
|
75 | 75 | LIBUC_LIBS_ADC = -ladc |
|
76 | 76 | |
|
77 | 77 | LIBUC_LIBS_DIR = $(LIBUC)/lib/bin/lpc17XX |
|
78 | 78 | LIBUC_LIBS_DIR_UART = -L $(LIBUC_LIBS_DIR)/UART |
|
79 | 79 | LIBUC_LIBS_DIR_SPI = -L $(LIBUC_LIBS_DIR)/SPI |
|
80 | 80 | LIBUC_LIBS_DIR_IIC = -L $(LIBUC_LIBS_DIR)/IIC |
|
81 | 81 | LIBUC_LIBS_DIR_ADC = -L $(LIBUC_LIBS_DIR)/ADC |
|
82 | 82 | |
|
83 | 83 | LIBUC_INC_DIR = $(LIBUC)/lib/includes/lpc17XX |
|
84 | 84 | LIBUC_INC_DIR_UART = -I $(LIBUC_INC_DIR)/UART |
|
85 | 85 | LIBUC_INC_DIR_SPI = -I $(LIBUC_INC_DIR)/SPI |
|
86 | 86 | LIBUC_INC_DIR_IIC = -I $(LIBUC_INC_DIR)/IIC |
|
87 | 87 | LIBUC_INC_DIR_ADC = -I $(LIBUC_INC_DIR)/ADC |
|
88 | 88 | |
|
89 | ||
|
90 | #--------------------------------------------------------------------------------- | |
|
91 | # BOARD SUPORT PACKAGES | |
|
92 | #--------------------------------------------------------------------------------- | |
|
93 | LIBUC_BSP_DIR=$(LIBUC)/bsp | |
|
94 | LIBUC_BSP_BIN_DIR= $(LIBUC_BSP_DIR)/bin | |
|
95 | LIBUC_BSP_INC_DIR= $(LIBUC_BSP_DIR)/includes | |
|
96 | LIBUC_BSP = -L $(LIBUC_BSP_BIN_DIR)/$(BSP) -lbsp | |
|
97 | LIBUC_BSP_INC = -I $(LIBUC_BSP_INC_DIR)/$(BSP) | |
|
89 | 98 | #--------------------------------------------------------------------------------- |
|
90 | 99 | # DEVICE SPECIAL FILES |
|
91 | 100 | #--------------------------------------------------------------------------------- |
|
92 | 101 | LINKER_SCRIPT = $(ARCH)/LPC17xx.ld |
|
93 | 102 | SOURCES += $(ARCH)/startup_LPC17xx.c $(ARCH)/core_cm3.c $(ARCH)/system_LPC17xx.c |
|
94 | 103 | LPC17XX_INCDIR=$(ARCH) |
|
95 | 104 | |
|
96 | 105 | |
|
97 | 106 | all: |
|
98 | 107 | @echo "lpc17XX-arm-noabi-gcc rules" |
|
99 | 108 | |
|
100 | 109 | |
|
101 | 110 | bin: $(TARGET).bin $(TARGET).hex |
|
102 | 111 | @echo "compile bin" |
|
103 | 112 | |
|
104 | 113 | |
|
105 | 114 | |
|
106 | 115 | lib: $(TARGET).a |
|
107 | 116 | @echo "compile lib" |
|
108 | 117 | |
|
109 | 118 | %.a: $(OBJECTFILES) |
|
110 | 119 | mkdir -p $(TARGETINSTALLPATH) |
|
111 | 120 | mkdir -p $(HEADERSINSTALLPATH) |
|
112 | 121 | ar rcs $(TARGETINSTALLPATH)/$@ $(OBJECTFILES) |
|
113 | 122 | cp $(HEADERS) $(HEADERSINSTALLPATH)/ |
|
114 | 123 | |
|
115 | 124 | |
|
116 | 125 | %.o: %.c |
|
117 | $(LIBUC_CC) -I $(LPC17XX_INCDIR) $(LIBUC_INCLUDES) -MM $< -MF $*.d -MP | |
|
118 | $(LIBUC_CC) -I $(LPC17XX_INCDIR) $(LIBUC_INCLUDES) -c $(LIBUC_CFLAGS) $< -o $@ | |
|
126 | $(LIBUC_CC) -I $(LPC17XX_INCDIR) $(LIBUC_INCLUDES) $(LIBUC_BSP_INC) -MM $< -MF $*.d -MP | |
|
127 | $(LIBUC_CC) -I $(LPC17XX_INCDIR) $(LIBUC_INCLUDES) $(LIBUC_BSP_INC) -c $(LIBUC_CFLAGS) $< -o $@ | |
|
119 | 128 | |
|
120 | 129 | |
|
121 | 130 | %.elf: $(LINKER_SCRIPT) $(OBJECTFILES) |
|
122 | $(LIBUC_LD) -Map $(@:.elf=.map) $(LIBUC_LDFLAGS) $(LIBUC_LIBRARIES) -T $^ -o $@ | |
|
131 | $(LIBUC_LD) -Map $(@:.elf=.map) $(LIBUC_LDFLAGS) $(LIBUC_LIBRARIES) $(LIBUC_BSP) -T $^ -o $@ | |
|
123 | 132 | $(LIBUC_OBJDUMP) $(LIBUC_ODFLAGS) $@ > $(@:.elf=.dump) |
|
124 | 133 | $(LIBUC_SIZE) $@ |
|
125 | 134 | |
|
126 | 135 | %.bin: %.elf |
|
127 | 136 | $(LIBUC_OBJCOPY) $(LIBUC_CPFLAGS) -O binary $< $*.bin |
|
128 | 137 | |
|
129 | 138 | |
|
130 | 139 | %.hex: %.elf |
|
131 | 140 | $(LIBUC_OBJCOPY) $(LIBUC_CPFLAGS) -O ihex $< $*.hex |
|
132 | 141 | |
|
133 | 142 | |
|
134 | 143 | clean: |
|
135 | 144 | rm -f *.o *.d *.bin *.hex *.dump *.map *.a |
|
136 | 145 | |
|
137 | 146 | distclean: |
|
138 | 147 | rm -f $(TARGETINSTALLPATH)/*.bin |
|
139 | 148 | rm -f $(TARGETINSTALLPATH)/*.a |
|
140 | 149 | |
|
141 | 150 | |
|
142 | 151 | |
|
143 | 152 | |
|
144 | 153 | |
|
145 | 154 | |
|
146 | 155 | |
|
147 | 156 | |
|
148 | 157 |
General Comments 0
You need to be logged in to leave comments.
Login now