From 26c50522d548e701cb250b0856591019d9349d2c Mon Sep 17 00:00:00 2001
From: Oleg Hahm <oleg@hobbykeller.org>
Date: Sun, 22 Dec 2013 20:02:59 +0100
Subject: [PATCH] simplified and unified cpu build structure

---
 Makefile                           |  2 +-
 Makefile.base                      |  2 +-
 Makefile.include                   |  2 +-
 cpu/Makefile                       | 42 ------------------------------
 cpu/Makefile.base                  | 24 -----------------
 cpu/Makefile.include               | 19 --------------
 cpu/arm_common/Makefile.include    |  4 +++
 cpu/cc430/Makefile                 |  2 +-
 cpu/cc430/Makefile.include         |  2 ++
 cpu/lpc1768/Makefile               |  3 +--
 cpu/lpc1768/Makefile.include       |  3 +++
 cpu/lpc1768/include/LPC17xx.h      |  1 -
 cpu/lpc1768/include/cpu-conf.h     |  2 ++
 cpu/lpc2387/Makefile               |  2 +-
 cpu/lpc2387/Makefile.include       |  7 +++++
 cpu/lpc_common/Makefile.include    |  3 +++
 cpu/mc1322x/Makefile               |  2 +-
 cpu/mc1322x/Makefile.include       |  7 +++++
 cpu/mc1322x/gpio.c                 | 20 +++++++-------
 cpu/msp430-common/Makefile.include |  2 ++
 cpu/msp430x16x/Makefile            |  2 +-
 cpu/msp430x16x/Makefile.include    |  4 +++
 cpu/native/Makefile.include        |  2 ++
 23 files changed, 54 insertions(+), 105 deletions(-)
 delete mode 100644 cpu/Makefile
 delete mode 100644 cpu/Makefile.base
 delete mode 100644 cpu/Makefile.include
 create mode 100644 cpu/arm_common/Makefile.include
 create mode 100644 cpu/cc430/Makefile.include
 create mode 100644 cpu/lpc1768/Makefile.include
 create mode 100644 cpu/lpc2387/Makefile.include
 create mode 100644 cpu/lpc_common/Makefile.include
 create mode 100644 cpu/mc1322x/Makefile.include
 create mode 100644 cpu/msp430-common/Makefile.include
 create mode 100644 cpu/msp430x16x/Makefile.include
 create mode 100644 cpu/native/Makefile.include

diff --git a/Makefile b/Makefile
index cd5bd421c3..1d41fa5b5e 100644
--- a/Makefile
+++ b/Makefile
@@ -1,4 +1,4 @@
-DIRS = $(RIOTCPU) core drivers sys 
+DIRS = $(RIOTCPU)/$(CPU) core drivers sys
 
 .PHONY: all clean doc
 
diff --git a/Makefile.base b/Makefile.base
index 624f74285c..500c6b6a80 100644
--- a/Makefile.base
+++ b/Makefile.base
@@ -23,7 +23,7 @@ export CFLAGS += -DVERSION=\"$(GIT_VERSION)\"
 
 .PHONY: clean
 
-include $(RIOTCPU)/Makefile.base
+include $(RIOTCPU)/$(CPU)/Makefile.include
 include $(RIOTBOARD)/$(BOARD)/Makefile.include
 
 $(BINDIR)$(MODULE).a: $(OBJ) $(ASMOBJ)
diff --git a/Makefile.include b/Makefile.include
index 31f98056a5..01311e4668 100644
--- a/Makefile.include
+++ b/Makefile.include
@@ -21,7 +21,7 @@ export BINDIR =$(CURDIR)/bin/
 
 # mandatory includes!
 include $(RIOTBOARD)/$(BOARD)/Makefile.include
-include $(RIOTCPU)/Makefile.include
+include $(RIOTCPU)/$(CPU)/Makefile.include
 include $(RIOTBASE)/Makefile.modules 
 
 # your binaries to link
diff --git a/cpu/Makefile b/cpu/Makefile
deleted file mode 100644
index 3988d3058b..0000000000
--- a/cpu/Makefile
+++ /dev/null
@@ -1,42 +0,0 @@
-ifeq ($(CPU),lpc1768)
- DIRS = lpc1768
-endif
-
-ifeq ($(CPU),lpc2387)
- DIRS = arm_common lpc_common lpc2387
-endif
-
-ifeq ($(CPU),mc1322x)
-	DIRS = arm_common mc1322x
-endif
-
-ifeq ($(CPU),cc430)
- DIRS = msp430-common cc430
-endif
-
-ifeq ($(CPU),msp430x16x)
- DIRS = msp430-common msp430x16x
-endif
-
-ifeq ($(CPU),native)
- DIRS = native
-endif
-
-.PHONY: cpus
-.PHONY: $(DIRS)
-
-cpus: $(DIRS)
-
-$(DIRS): 
-	@"$(MAKE)" -C $@
-
-clean:
-	@"$(MAKE)" -C lpc1768 clean
-	@"$(MAKE)" -C lpc2387 clean
-	@"$(MAKE)" -C mc1322x clean
-	@"$(MAKE)" -C lpc_common clean
-	@"$(MAKE)" -C arm_common clean
-	@"$(MAKE)" -C cc430 clean
-	@"$(MAKE)" -C msp430-common clean
-	@"$(MAKE)" -C msp430x16x clean
-	@"$(MAKE)" -C native clean
diff --git a/cpu/Makefile.base b/cpu/Makefile.base
deleted file mode 100644
index 9e83ceec69..0000000000
--- a/cpu/Makefile.base
+++ /dev/null
@@ -1,24 +0,0 @@
-ifeq ($(CPU),lpc1768)
- INCLUDES += -I$(MAKEBASE)/cpu/lpc1768/include
-endif
-ifeq ($(CPU),lpc2387)
- INCLUDES += -I$(MAKEBASE)/cpu/arm_common/include/
- INCLUDES += -I$(MAKEBASE)/cpu/lpc_common/include/
- INCLUDES += -I$(MAKEBASE)/cpu/lpc2387/include
-endif
-ifeq ($(CPU),mc1322x)
- INCLUDES += -I$(MAKEBASE)/cpu/arm_common/include/
- INCLUDES += -I$(MAKEBASE)/cpu/mc1322x/include
-endif
-ifeq ($(CPU),msp430x16x)
- INCLUDES += -I$(MAKEBASE)/cpu/msp430-common/include/
- INCLUDES += -I$(MAKEBASE)/cpu/msp430x16x/include/
-endif
-ifeq ($(CPU),cc430)
- INCLUDES += -I$(MAKEBASE)/cpu/msp430-common/include/
- INCLUDES += -I$(MAKEBASE)/cpu/cc430/include/
-endif
-ifeq ($(CPU),native)
- INCLUDES += -I$(MAKEBASE)/cpu/native/include/
-endif
-
diff --git a/cpu/Makefile.include b/cpu/Makefile.include
deleted file mode 100644
index 5498061a25..0000000000
--- a/cpu/Makefile.include
+++ /dev/null
@@ -1,19 +0,0 @@
-### Minimal setup
-ifeq ($(CPU),lpc1768)
-  export UNDEF += $(BINDIR)syscalls.o
-endif
-ifeq ($(CPU),lpc2387)
-  export USEMODULE += arm_common lpc_common
-  export UNDEF += $(BINDIR)syscalls.o $(BINDIR)lpc_syscalls.o
-  export INCLUDES += -I$(RIOTCPU)/arm_common/include
-  export INCLUDES += -I$(RIOTCPU)/lpc_common/include
-endif
-ifeq ($(CPU),mc1322x)
-  export USEMODULE += arm_common
-  export UNDEF += $(BINDIR)syscalls.o
-  export UNDEF += $(BINDIR)mc1322x_syscalls.o
-  export INCLUDES += -I$(RIOTBASE)/cpu/arm_common/include
-endif
-ifeq ($(CPU),native)
-  export INCLUDES += -I$(RIOTCPU)/native/include
-endif
diff --git a/cpu/arm_common/Makefile.include b/cpu/arm_common/Makefile.include
new file mode 100644
index 0000000000..21a06d3fa7
--- /dev/null
+++ b/cpu/arm_common/Makefile.include
@@ -0,0 +1,4 @@
+INCLUDES += -I$(MAKEBASE)/cpu/arm_common/include/
+
+export UNDEF += $(BINDIR)syscalls.o
+
diff --git a/cpu/cc430/Makefile b/cpu/cc430/Makefile
index 14776b83ff..d08377bd38 100644
--- a/cpu/cc430/Makefile
+++ b/cpu/cc430/Makefile
@@ -1,7 +1,7 @@
 MODULE = cpu
 
 INCLUDES += -I$(RIOTCPU)/$(CPU)/include -I$(RIOTBASE)/core/include -I$(RIOTBASE)/drivers/cc110x_ng/include
-DIRS =
+DIRS = $(RIOTCPU)/msp430-common
 
 all: $(BINDIR)$(MODULE).a
 	@for i in $(DIRS) ; do "$(MAKE)" -C $$i ; done ;
diff --git a/cpu/cc430/Makefile.include b/cpu/cc430/Makefile.include
new file mode 100644
index 0000000000..901122b7a6
--- /dev/null
+++ b/cpu/cc430/Makefile.include
@@ -0,0 +1,2 @@
+ INCLUDES += -I$(MAKEBASE)/cpu/cc430/include/
+
diff --git a/cpu/lpc1768/Makefile b/cpu/lpc1768/Makefile
index 4d2bc58f26..263b41a374 100644
--- a/cpu/lpc1768/Makefile
+++ b/cpu/lpc1768/Makefile
@@ -7,8 +7,7 @@ CC_SYMBOLS = -DTARGET_LPC1769 -DTOOLCHAIN_GCC_ARM -DNDEBUG -D__CORTEX_M3
 LD_FLAGS = -mcpu=cortex-m3 -mthumb -Wl,--gc-sections,-Map=$(PROJECT).map,--cref --specs=nano.specs
 LD_SYS_LIBS = -lc -lgcc -lnosys
 
-INCLUDES = -Iinclude
-INCLUDES += -I$(RIOTBASE)/core/include -I$(RIOTBASE)/sys/include -I$(RIOTBASE)/sys/lib 
+INCLUDES = -Iinclude -I$(RIOTBASE)/core/include -I$(RIOTBASE)/sys/include -I$(RIOTBASE)/sys/lib 
 
 all: $(BINDIR)$(MODULE).a
 
diff --git a/cpu/lpc1768/Makefile.include b/cpu/lpc1768/Makefile.include
new file mode 100644
index 0000000000..bacb82189b
--- /dev/null
+++ b/cpu/lpc1768/Makefile.include
@@ -0,0 +1,3 @@
+INCLUDES += -I$(MAKEBASE)/cpu/lpc1768/include
+
+export UNDEF += $(BINDIR)syscalls.o
diff --git a/cpu/lpc1768/include/LPC17xx.h b/cpu/lpc1768/include/LPC17xx.h
index 377fdf240a..bdc57c0d89 100644
--- a/cpu/lpc1768/include/LPC17xx.h
+++ b/cpu/lpc1768/include/LPC17xx.h
@@ -97,7 +97,6 @@ typedef enum IRQn
 
 
 #include "core_cm3.h"                       /* Cortex-M3 processor and core peripherals           */
-#include "system_LPC17xx.h"                 /* System Header                                      */
 
 
 /******************************************************************************/
diff --git a/cpu/lpc1768/include/cpu-conf.h b/cpu/lpc1768/include/cpu-conf.h
index 624edc7fbb..1e426ce447 100644
--- a/cpu/lpc1768/include/cpu-conf.h
+++ b/cpu/lpc1768/include/cpu-conf.h
@@ -13,6 +13,8 @@
 #endif
 
 #define KERNEL_CONF_STACKSIZE_IDLE		1000
+
+#define UART0_BUFSIZE                   (128)
 /** @} */
 
 #endif /* CPU_CONF_H */
diff --git a/cpu/lpc2387/Makefile b/cpu/lpc2387/Makefile
index 627ac79289..461827d5f9 100644
--- a/cpu/lpc2387/Makefile
+++ b/cpu/lpc2387/Makefile
@@ -1,7 +1,7 @@
 MODULE =cpu
 
 INCLUDES = -I../include -Idrivers/include -I../arm_common/include -I../../sys/lib -I../../drivers/include -I../../core/include -I../../sys/include -I../../hal/include -I../../.. 
-DIRS =
+DIRS = $(RIOTCPU)/arm_common $(RIOTCPU)/lpc_common
 ifneq (,$(findstring gpioint,$(USEMODULE)))
 	DIRS += gpioint
 endif
diff --git a/cpu/lpc2387/Makefile.include b/cpu/lpc2387/Makefile.include
new file mode 100644
index 0000000000..92ada63482
--- /dev/null
+++ b/cpu/lpc2387/Makefile.include
@@ -0,0 +1,7 @@
+INCLUDES += -I$(RIOTCPU)/lpc2387/include
+
+include $(RIOTCPU)/arm_common/Makefile.include
+include $(RIOTCPU)/lpc_common/Makefile.include
+
+export USEMODULE += arm_common lpc_common
+
diff --git a/cpu/lpc_common/Makefile.include b/cpu/lpc_common/Makefile.include
new file mode 100644
index 0000000000..d90912db90
--- /dev/null
+++ b/cpu/lpc_common/Makefile.include
@@ -0,0 +1,3 @@
+INCLUDES += -I$(RIOTCPU)/lpc_common/include
+
+export UNDEF += $(BINDIR)lpc_syscalls.o
diff --git a/cpu/mc1322x/Makefile b/cpu/mc1322x/Makefile
index 706aac84a5..cb7f2993a0 100644
--- a/cpu/mc1322x/Makefile
+++ b/cpu/mc1322x/Makefile
@@ -1,6 +1,6 @@
 MODULE =cpu
 
-DIRS =
+DIRS = $(RIOTCPU)/arm_common
 ifneq (,$(findstring mc1322x_adc,$(USEMODULE)))
   DIRS += adc
 endif
diff --git a/cpu/mc1322x/Makefile.include b/cpu/mc1322x/Makefile.include
new file mode 100644
index 0000000000..9bc7621575
--- /dev/null
+++ b/cpu/mc1322x/Makefile.include
@@ -0,0 +1,7 @@
+INCLUDES += -I$(MAKEBASE)/cpu/mc1322x/include
+
+include $(RIOTCPU)/arm_common/Makefile.include
+
+export UNDEF += $(BINDIR)mc1322x_syscalls.o
+
+export USEMODULE += arm_common
diff --git a/cpu/mc1322x/gpio.c b/cpu/mc1322x/gpio.c
index f238d052da..197e9351e4 100644
--- a/cpu/mc1322x/gpio.c
+++ b/cpu/mc1322x/gpio.c
@@ -10,19 +10,19 @@
 
 #include "gpio.h"
 
-inline void gpio_pad_dir(volatile uint64_t data) 
+static inline void gpio_pad_dir(volatile uint64_t data) 
 {
         GPIO->PAD_DIR0 = (data & 0xffffffff);
         GPIO->PAD_DIR1 = (data >> 32);
 }
 
-inline void gpio_data(volatile uint64_t data) 
+static inline void gpio_data(volatile uint64_t data) 
 {
         GPIO->DATA0 = (data & 0xffffffff);
         GPIO->DATA1 = (data >> 32);
 }
 
-inline uint64_t gpio_data_get(volatile uint64_t bits) {
+static inline uint64_t gpio_data_get(volatile uint64_t bits) {
         uint64_t rdata = 0;
 
         rdata = GPIO->DATA0 & (bits & 0xffffffff);
@@ -31,43 +31,43 @@ inline uint64_t gpio_data_get(volatile uint64_t bits) {
         return rdata;
 }
 
-inline void gpio_pad_pu_en(volatile uint64_t data) 
+static inline void gpio_pad_pu_en(volatile uint64_t data) 
 {
         GPIO->PAD_PU_EN0 = (data & 0xffffffff);
         GPIO->PAD_PU_EN1 = (data >> 32);
 }
 
-inline void gpio_data_sel(volatile uint64_t data) 
+static inline void gpio_data_sel(volatile uint64_t data) 
 {
         GPIO->DATA_SEL0 = (data & 0xffffffff);
         GPIO->DATA_SEL1 = (data >> 32);
 }
 
-inline void gpio_pad_pu_sel(volatile uint64_t data) 
+static inline void gpio_pad_pu_sel(volatile uint64_t data) 
 {
         GPIO->PAD_PU_SEL0 = (data & 0xffffffff);
         GPIO->PAD_PU_SEL1 = (data >> 32);
 }
 
-inline void gpio_data_set(volatile uint64_t data) 
+static inline void gpio_data_set(volatile uint64_t data) 
 {
         GPIO->DATA_SET0 = (data & 0xffffffff);
         GPIO->DATA_SET1 = (data >> 32);
 }
 
-inline void gpio_data_reset(volatile uint64_t data) 
+static inline void gpio_data_reset(volatile uint64_t data) 
 {
         GPIO->DATA_RESET0 = (data & 0xffffffff);
         GPIO->DATA_RESET1 = (data >> 32);
 }
 
-inline void gpio_pad_dir_set(volatile uint64_t data) 
+static inline void gpio_pad_dir_set(volatile uint64_t data) 
 {
         GPIO->PAD_DIR_SET0 = (data & 0xffffffff);
         GPIO->PAD_DIR_SET1 = (data >> 32);
 }
 
-inline void gpio_pad_dir_reset(volatile uint64_t data) 
+static inline void gpio_pad_dir_reset(volatile uint64_t data) 
 {
         GPIO->PAD_DIR_RESET0 = (data & 0xffffffff);
         GPIO->PAD_DIR_RESET1 = (data >> 32);
diff --git a/cpu/msp430-common/Makefile.include b/cpu/msp430-common/Makefile.include
new file mode 100644
index 0000000000..bd2f745e30
--- /dev/null
+++ b/cpu/msp430-common/Makefile.include
@@ -0,0 +1,2 @@
+INCLUDES += -I$(MAKEBASE)/cpu/msp430-common/include/
+
diff --git a/cpu/msp430x16x/Makefile b/cpu/msp430x16x/Makefile
index 421e3af303..0d95efd3a9 100644
--- a/cpu/msp430x16x/Makefile
+++ b/cpu/msp430x16x/Makefile
@@ -1,7 +1,7 @@
 MODULE =cpu
 
 INCLUDES = -I../include -I$(RIOTBASE)/core/include
-DIRS =
+DIRS = $(RIOTCPU)/msp430-common/
 
 all: $(BINDIR)$(MODULE).a
 	@for i in $(DIRS) ; do "$(MAKE)" -C $$i ; done ;
diff --git a/cpu/msp430x16x/Makefile.include b/cpu/msp430x16x/Makefile.include
new file mode 100644
index 0000000000..b9dcae6d05
--- /dev/null
+++ b/cpu/msp430x16x/Makefile.include
@@ -0,0 +1,4 @@
+INCLUDES += -I$(RIOTCPU)/msp430x16x/include/
+
+include $(RIOTCPU)/msp430-common/Makefile.include
+
diff --git a/cpu/native/Makefile.include b/cpu/native/Makefile.include
new file mode 100644
index 0000000000..54626e3344
--- /dev/null
+++ b/cpu/native/Makefile.include
@@ -0,0 +1,2 @@
+export INCLUDES += -I$(RIOTCPU)/native/include
+
-- 
GitLab