From 5df0bd0cc494daddc3a78dddd69d2baffaf2659f Mon Sep 17 00:00:00 2001
From: Oleg Hahm <oleg@hobbykeller.org>
Date: Fri, 8 Feb 2013 17:37:02 +0100
Subject: [PATCH] * updated and integrated makefiles * added some auto
 dependencies

---
 board                                         |  2 +-
 core/makefile                                 |  2 +-
 .../cc110x_ng => cpu/cc430}/cc110x_cc430.c    |  0
 cpu/lpc2387/{ => gpioint}/lpc2387-gpioint.c   |  0
 cpu/lpc2387/gpioint/makefile                  |  6 +++
 cpu/lpc2387/makefile                          | 11 +++-
 cpu/lpc2387/{ => mci}/lpc2387-mci.c           |  2 +-
 cpu/lpc2387/mci/makefile                      |  6 +++
 cpu/lpc2387/{ => rtc}/lpc2387-rtc.c           |  0
 cpu/lpc2387/rtc/makefile                      |  6 +++
 dist/makefile                                 | 50 ++++++++++++-------
 drivers/cc110x/makefile                       |  4 +-
 drivers/cc110x_ng/makefile                    | 15 +++++-
 drivers/cc110x_ng/{ => spi}/cc110x_spi.c      |  0
 drivers/cc110x_ng/spi/makefile                |  6 +++
 drivers/ltc4150/ltc4150.c                     | 20 ++++----
 drivers/ltc4150/makefile                      |  2 +-
 drivers/sht11/makefile                        |  2 +-
 makefile.base                                 |  5 ++
 makefile.dep                                  | 27 ++++++++++
 makefile.modules                              |  6 ++-
 sys/{ => auto_init}/auto_init.c               |  0
 sys/auto_init/makefile                        |  5 ++
 sys/{ => config}/config.c                     |  0
 sys/config/makefile                           |  5 ++
 sys/include/ps.h                              |  2 +-
 sys/lib/makefile                              |  3 +-
 sys/makefile                                  | 24 +++++++--
 sys/posix/makefile                            |  5 ++
 sys/{ => posix}/posix_io.c                    |  0
 sys/ps/makefile                               |  5 ++
 sys/{shell => ps}/ps.c                        |  8 +--
 sys/shell/commands/makefile                   | 49 ++++++++++++++++++
 sys/shell/{cc1100.c => commands/sc_cc1100.c}  |  0
 .../{cc110x_ng.c => commands/sc_cc110x_ng.c}  |  0
 sys/shell/{disk.c => commands/sc_disk.c}      |  0
 sys/shell/{id.c => commands/sc_id.c}          |  0
 .../{ltc4150.c => commands/sc_ltc4150.c}      |  0
 sys/shell/commands/sc_ps.c                    |  6 +++
 sys/shell/{rtc.c => commands/sc_rtc.c}        |  0
 sys/shell/{sht11.c => commands/sc_sht11.c}    |  0
 sys/shell/{ => commands}/shell_commands.c     |  0
 sys/shell/makefile                            | 21 +++++++-
 sys/timex/makefile                            |  5 ++
 sys/{ => timex}/timex.c                       |  0
 sys/transceiver/makefile                      |  2 +-
 sys/uart0/makefile                            |  7 +++
 sys/{ => uart0}/uart0.c                       |  0
 sys/vtimer/makefile                           |  5 ++
 sys/{ => vtimer}/vtimer.c                     |  0
 50 files changed, 269 insertions(+), 55 deletions(-)
 rename {drivers/cc110x_ng => cpu/cc430}/cc110x_cc430.c (100%)
 rename cpu/lpc2387/{ => gpioint}/lpc2387-gpioint.c (100%)
 create mode 100644 cpu/lpc2387/gpioint/makefile
 rename cpu/lpc2387/{ => mci}/lpc2387-mci.c (99%)
 create mode 100644 cpu/lpc2387/mci/makefile
 rename cpu/lpc2387/{ => rtc}/lpc2387-rtc.c (100%)
 create mode 100644 cpu/lpc2387/rtc/makefile
 rename drivers/cc110x_ng/{ => spi}/cc110x_spi.c (100%)
 create mode 100644 drivers/cc110x_ng/spi/makefile
 create mode 100644 makefile.dep
 rename sys/{ => auto_init}/auto_init.c (100%)
 create mode 100644 sys/auto_init/makefile
 rename sys/{ => config}/config.c (100%)
 create mode 100644 sys/config/makefile
 create mode 100644 sys/posix/makefile
 rename sys/{ => posix}/posix_io.c (100%)
 create mode 100644 sys/ps/makefile
 rename sys/{shell => ps}/ps.c (95%)
 create mode 100644 sys/shell/commands/makefile
 rename sys/shell/{cc1100.c => commands/sc_cc1100.c} (100%)
 rename sys/shell/{cc110x_ng.c => commands/sc_cc110x_ng.c} (100%)
 rename sys/shell/{disk.c => commands/sc_disk.c} (100%)
 rename sys/shell/{id.c => commands/sc_id.c} (100%)
 rename sys/shell/{ltc4150.c => commands/sc_ltc4150.c} (100%)
 create mode 100644 sys/shell/commands/sc_ps.c
 rename sys/shell/{rtc.c => commands/sc_rtc.c} (100%)
 rename sys/shell/{sht11.c => commands/sc_sht11.c} (100%)
 rename sys/shell/{ => commands}/shell_commands.c (100%)
 create mode 100644 sys/timex/makefile
 rename sys/{ => timex}/timex.c (100%)
 create mode 100644 sys/uart0/makefile
 rename sys/{ => uart0}/uart0.c (100%)
 create mode 100644 sys/vtimer/makefile
 rename sys/{ => vtimer}/vtimer.c (100%)

diff --git a/board b/board
index 182151f463..402bc0e1b9 160000
--- a/board
+++ b/board
@@ -1 +1 @@
-Subproject commit 182151f46326e9eb6c0c48bd2ac6438c66302a13
+Subproject commit 402bc0e1b920b54e1a87329d0b496fedfeafd811
diff --git a/core/makefile b/core/makefile
index a3e669793a..ba54604b5c 100644
--- a/core/makefile
+++ b/core/makefile
@@ -1,5 +1,5 @@
 MODULE =core
 
-INCLUDES = -Iinclude/ -I../sys/include -I../sys/lib -I../sys/drivers/include -I../cpu/$(CPU)/include/ -I../..
+INCLUDES = -Iinclude/ -I../sys/include -I../sys/lib -I../sys/drivers/include -I../cpu/$(CPU)/include/ -I../.. -I../drivers/include/
 
 include $(RIOTBASE)/makefile.base
diff --git a/drivers/cc110x_ng/cc110x_cc430.c b/cpu/cc430/cc110x_cc430.c
similarity index 100%
rename from drivers/cc110x_ng/cc110x_cc430.c
rename to cpu/cc430/cc110x_cc430.c
diff --git a/cpu/lpc2387/lpc2387-gpioint.c b/cpu/lpc2387/gpioint/lpc2387-gpioint.c
similarity index 100%
rename from cpu/lpc2387/lpc2387-gpioint.c
rename to cpu/lpc2387/gpioint/lpc2387-gpioint.c
diff --git a/cpu/lpc2387/gpioint/makefile b/cpu/lpc2387/gpioint/makefile
new file mode 100644
index 0000000000..cf2b29f891
--- /dev/null
+++ b/cpu/lpc2387/gpioint/makefile
@@ -0,0 +1,6 @@
+INCLUDES = -I$(RIOTBASE)/drivers/include -I$(RIOTBASE)/sys/include -I../../net -I../include -I../../lib -I../../../.. -I../../../cpu/ -I../../../core/include -I../../
+
+MODULE =gpioint
+
+include $(MAKEBASE)/makefile.base
+
diff --git a/cpu/lpc2387/makefile b/cpu/lpc2387/makefile
index 9e47336715..a85865698a 100644
--- a/cpu/lpc2387/makefile
+++ b/cpu/lpc2387/makefile
@@ -1,7 +1,16 @@
 MODULE =cpu
 
-INCLUDES = -Iinclude -Idrivers/include -I../arm_common/include -I../../sys/lib -I../../drivers/include -I../../core/include -I../../sys/include -I../../hal/include -I../../.. 
+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 =
+ifneq (,$(findstring gpioint,$(USEMODULE)))
+	DIRS += gpioint
+endif
+ifneq (,$(findstring mci,$(USEMODULE)))
+	DIRS += mci
+endif
+ifneq (,$(findstring rtc,$(USEMODULE)))
+	DIRS += rtc
+endif
 
 all: $(BINDIR)$(MODULE).a
 	@for i in $(DIRS) ; do $(MAKE) -C $$i ; done ;
diff --git a/cpu/lpc2387/lpc2387-mci.c b/cpu/lpc2387/mci/lpc2387-mci.c
similarity index 99%
rename from cpu/lpc2387/lpc2387-mci.c
rename to cpu/lpc2387/mci/lpc2387-mci.c
index 8e044fd0e5..255853f78a 100644
--- a/cpu/lpc2387/lpc2387-mci.c
+++ b/cpu/lpc2387/mci/lpc2387-mci.c
@@ -18,7 +18,7 @@
 #include "hwtimer.h"
 #include "diskio.h"
 
-#define ENABLE_DEBUG
+//#define ENABLE_DEBUG
 #include "debug.h"
 
 extern unsigned long hwtimer_now(void);
diff --git a/cpu/lpc2387/mci/makefile b/cpu/lpc2387/mci/makefile
new file mode 100644
index 0000000000..cdffdd035d
--- /dev/null
+++ b/cpu/lpc2387/mci/makefile
@@ -0,0 +1,6 @@
+INCLUDES = -I$(RIOTBASE)/drivers/include -I$(RIOTBASE)/sys/include -I../../net -I../include -I../../lib -I../../../.. -I../../../cpu/ -I../../../core/include -I../../
+
+MODULE =mci
+
+include $(MAKEBASE)/makefile.base
+
diff --git a/cpu/lpc2387/lpc2387-rtc.c b/cpu/lpc2387/rtc/lpc2387-rtc.c
similarity index 100%
rename from cpu/lpc2387/lpc2387-rtc.c
rename to cpu/lpc2387/rtc/lpc2387-rtc.c
diff --git a/cpu/lpc2387/rtc/makefile b/cpu/lpc2387/rtc/makefile
new file mode 100644
index 0000000000..b3b66a79c8
--- /dev/null
+++ b/cpu/lpc2387/rtc/makefile
@@ -0,0 +1,6 @@
+INCLUDES = -I$(RIOTBASE)/drivers/include -I$(RIOTBASE)/core/include
+
+MODULE =rtc
+
+include $(MAKEBASE)/makefile.base
+
diff --git a/dist/makefile b/dist/makefile
index adcc39502b..33919a7b18 100644
--- a/dist/makefile
+++ b/dist/makefile
@@ -9,7 +9,7 @@
 
 #### Mandatory vars!
 
-# this has to be the absolute path of the feuerware-base dir
+# this has to be the absolute path of the RIOT-base dir
 export RIOTBASE =$(CURDIR)/../RIOT
 export RIOTBOARD =$(CURDIR)/../RIOT/board
 
@@ -26,9 +26,17 @@ export AS = $(PREFIX)as
 export LINK = $(PREFIX)gcc
 export SIZE = $(PREFIX)size
 export OBJCOPY = $(PREFIX)objcopy
+FLASH = lpc2k_pgm
+TERM = pyterm.py
 LINKFLAGS = -gdwarf-2 -mcpu=arm7tdmi-s -static -lgcc -nostartfiles -T$(RIOTBASE)/cpu/$(CPU)/linkerscript.x
 
-## Modules to include. No autodependencies!
+PROJBINDIR = bin
+
+ifeq ($(strip $(PORT)),)
+	PORT = /dev/ttyUSB0
+endif
+
+## Modules to include. 
 
 #USEMODULE += nanopan5375_proprietary
 #USEMODULE += sys
@@ -57,9 +65,6 @@ LINKFLAGS = -gdwarf-2 -mcpu=arm7tdmi-s -static -lgcc -nostartfiles -T$(RIOTBASE)
 #USEMODULE += net_kernel
 #USEMODULE += net_mm
 
-# mandatory include! 
-include $(RIOTBASE)/makefile.modules 
-
 #### Project Config 
 
 # name of your project
@@ -68,6 +73,9 @@ PROJECT = hello-world
 # for easy switching of boards
 export BOARD = msba2
 
+# mandatory include! 
+include $(RIOTBASE)/makefile.modules 
+
 # if you want to publish the board into the sources as an uppercase #define
 BB = $(shell echo $(BOARD)|tr 'a-z' 'A-Z')
 CFLAGS += -DBOARD_$(BB)
@@ -75,31 +83,37 @@ export CFLAGS
 
 # your binaries to link
 BASELIBS += $(RIOTBOARD)/$(BOARD)/bin/$(BOARD)_base.a
-BASELIBS += bin/project.a
+BASELIBS += $(PROJBINDIR)/project.a
 
-INCLUDES = -I$(RIOTBOARD)/$(BOARD)/include -I$(RIOTBASE)/core/include -I$(RIOTBASE)/cpu/$(CPU)/include -I$(RIOTBASE)/cpu/arm_common/include -I$(RIOTBASE)/sys/lib
+INCLUDES = -I$(RIOTBOARD)/$(BOARD)/include -I$(RIOTBASE)/core/include -I$(RIOTBASE)/cpu/$(CPU)/include -I$(RIOTBASE)/cpu/arm_common/include -I$(RIOTBASE)/sys/lib -I$(RIOTBASE)/sys/include/ -I$(RIOTBASE)/drivers/include/
 
 export INCLUDES
 
-## make script for your project. Build feuerware-base here!
-all: bin/$(PROJECT).a
+## make script for your project. Build RIOT-base here!
+all: $(PROJBINDIR)/$(PROJECT).a
+	@echo "Building project $(PROJECT) for $(BOARD) w/ MCU $(CPU)."
 	$(MAKE) -C $(RIOTBOARD)
 	$(MAKE) -C $(RIOTBASE)
-	$(LINK) $(LINKFLAGS) $(UNDEF) -o bin/$(PROJECT).elf -Wl,--start-group $(BASELIBS) -lm -Wl,--end-group  -Wl,-Map=bin/$(PROJECT).map
-	$(SIZE) bin/$(PROJECT).elf
-	$(OBJCOPY) -O ihex bin/$(PROJECT).elf bin/$(PROJECT).hex
+	$(LINK) $(LINKFLAGS) $(UNDEF) -o $(PROJBINDIR)/$(PROJECT).elf -Wl,--start-group $(BASELIBS) -lm -Wl,--end-group  -Wl,-Map=$(PROJBINDIR)/$(PROJECT).map
+	$(SIZE) $(PROJBINDIR)/$(PROJECT).elf
+	$(OBJCOPY) -O ihex $(PROJBINDIR)/$(PROJECT).elf $(PROJBINDIR)/$(PROJECT).hex
 
 ## your make rules
 ## Only basic example - modify it for larger projects!!
 
-bin/$(PROJECT).a: bin/$(PROJECT).o
-	$(AR) -rc bin/project.a bin/$(PROJECT).o 
+$(PROJBINDIR)/$(PROJECT).a: $(PROJBINDIR)/$(PROJECT).o
+	$(AR) -rc $(PROJBINDIR)/project.a $(PROJBINDIR)/$(PROJECT).o 
 	
-bin/$(PROJECT).o: main.c 
-	$(CC) $(CFLAGS) $(BOARDINCLUDE) $(INCLUDES) -c main.c -o bin/$(PROJECT).o
+$(PROJBINDIR)/$(PROJECT).o: main.c 
+	$(CC) $(CFLAGS) $(BOARDINCLUDE) $(INCLUDES) -c main.c -o $(PROJBINDIR)/$(PROJECT).o
 
 clean:
 	$(MAKE) -C $(RIOTBOARD) clean
 	$(MAKE) -C $(RIOTBASE) clean
-	rm -f bin/*
-	
+	rm -f $(PROJBINDIR)/*
+
+flash: all
+	$(FLASH) $(PORT) $(PROJBINDIR)/$(PROJECT).hex
+
+term:
+	$(TERM) $(PORT)
diff --git a/drivers/cc110x/makefile b/drivers/cc110x/makefile
index b2e8042825..b3519713c7 100644
--- a/drivers/cc110x/makefile
+++ b/drivers/cc110x/makefile
@@ -1,6 +1,6 @@
-INCLUDES = -I../../include -I../../net -I../include -I../../lib -I../../../.. -I../../../cpu/ -I../../../core/include -I../../
+INCLUDES = -I$(RIOTBASE)/sys/include -I../../net -I../include -I../../lib -I../../../.. -I../../../cpu/ -I../../../core/include -I../../
 
-MODULE =cc110x
+MODULE =cc110x_ng
 
 include $(MAKEBASE)/makefile.base
 
diff --git a/drivers/cc110x_ng/makefile b/drivers/cc110x_ng/makefile
index f8a7cfa78d..c6490934a2 100644
--- a/drivers/cc110x_ng/makefile
+++ b/drivers/cc110x_ng/makefile
@@ -1,5 +1,16 @@
-INCLUDES = -I../../include -I../../net -I../include -I../../lib -I../../../.. -I../../../cpu/ -I../../../core/include -I../../ -Iinclude/
+INCLUDES = -I$(RIOTBASE)/sys/include -I../../net -I../include -I../../lib -I../../../.. -I../../../cpu/ -I$(RIOTBASE)/core/include -I../../ -Iinclude/
 MODULE =cc110x_ng
-include $(MAKEBASE)/makefile.base
 
+DIRS =
+ifneq (,$(findstring msba2,$(BOARD)))
+	DIRS += spi 
+endif
+
+all: $(BINDIR)$(MODULE).a
+	@for i in $(DIRS) ; do $(MAKE) -C $$i ; done ;
+
+include $(RIOTBASE)/makefile.base
+
+clean::
+	@for i in $(DIRS) ; do $(MAKE) -C $$i clean ; done ;
 
diff --git a/drivers/cc110x_ng/cc110x_spi.c b/drivers/cc110x_ng/spi/cc110x_spi.c
similarity index 100%
rename from drivers/cc110x_ng/cc110x_spi.c
rename to drivers/cc110x_ng/spi/cc110x_spi.c
diff --git a/drivers/cc110x_ng/spi/makefile b/drivers/cc110x_ng/spi/makefile
new file mode 100644
index 0000000000..1d02bec101
--- /dev/null
+++ b/drivers/cc110x_ng/spi/makefile
@@ -0,0 +1,6 @@
+INCLUDES = -I$(RIOTBASE)/sys/include -I../../net -I../include -I../../lib -I../../../.. -I../../../cpu/ -I$(RIOTBASE)/core/include -I../../ -Iinclude/
+
+MODULE =cc110x_spi
+
+include $(MAKEBASE)/makefile.base
+
diff --git a/drivers/ltc4150/ltc4150.c b/drivers/ltc4150/ltc4150.c
index 9f4134b5c9..70c4a4ac11 100644
--- a/drivers/ltc4150/ltc4150.c
+++ b/drivers/ltc4150/ltc4150.c
@@ -58,15 +58,15 @@ static double mAh_to_Joule(double mAh) {
     return (SUPPLY_VOLTAGE * mAh * 3600);
 }
 
-uint32_t ltc4150_get_last_int_duration_us() {
+uint32_t ltc4150_get_last_int_duration_us(void) {
     return HWTIMER_TICKS_TO_US(last_int_duration);
 }
 
-double ltc4150_get_current_mA() {
+double ltc4150_get_current_mA(void) {
     return 1000000000/(ltc4150_get_last_int_duration_us()*(_GFH * _R_SENSE));
 }
 
-double __attribute__((__no_instrument_function__)) ltc4150_get_total_mAh() {
+double __attribute__((__no_instrument_function__)) ltc4150_get_total_mAh(void) {
     return coulomb_to_mA(int_to_coulomb(int_count));
 }
 
@@ -74,23 +74,23 @@ double ltc4150_get_total_Joule(void) {
     return mAh_to_Joule(ltc4150_get_total_mAh());
 }
 
-double ltc4150_get_avg_mA() {
+double ltc4150_get_avg_mA(void) {
     return (int_to_coulomb(int_count)*1000000000)/HWTIMER_TICKS_TO_US(last_int_time - start_time);
 }
 
-int ltc4150_get_interval() {
+int ltc4150_get_interval(void) {
     return HWTIMER_TICKS_TO_US(last_int_time - start_time);
 }
 
-unsigned long __attribute__((__no_instrument_function__)) ltc4150_get_intcount() {
+unsigned long __attribute__((__no_instrument_function__)) ltc4150_get_intcount(void) {
     return int_count;
 }
 
-void ltc4150_init() {
+void ltc4150_init(void) {
     ltc4150_arch_init();
 }
 
-void ltc4150_start() {
+void ltc4150_start(void) {
     ltc4150_disable_int();
     int_count = 0;
     uint32_t now = hwtimer_now();
@@ -100,11 +100,11 @@ void ltc4150_start() {
     ltc4150_enable_int();
 }
 
-void ltc4150_stop() {
+void ltc4150_stop(void) {
     ltc4150_disable_int();
 }
 
-void __attribute__((__no_instrument_function__)) ltc4150_interrupt()
+void __attribute__((__no_instrument_function__)) ltc4150_interrupt(void)
 {
     uint32_t now = hwtimer_now();
     if (now >= last_int_time) {
diff --git a/drivers/ltc4150/makefile b/drivers/ltc4150/makefile
index 56eb0df1f9..b1ca863065 100644
--- a/drivers/ltc4150/makefile
+++ b/drivers/ltc4150/makefile
@@ -1,4 +1,4 @@
-INCLUDES = -I../../include -I../../lib -I../../../cpu/$(CPU)/include -I../../../cpu/ -I../../../hal/include -I../../../core/include -I../../config -I../include
+INCLUDES = -I$(RIOTBASE)/core/include -I../include/
 MODULE =ltc4150
 include $(MAKEBASE)/makefile.base
 
diff --git a/drivers/sht11/makefile b/drivers/sht11/makefile
index ac4e9acf92..bfc0a2b08e 100644
--- a/drivers/sht11/makefile
+++ b/drivers/sht11/makefile
@@ -1,4 +1,4 @@
-INCLUDES = -I../../include -I../../lib -I../../../cpu/$(CPU)/include -I../../../cpu/ -I../../../hal/include -I../../../core/include -I../../config -I../include
+INCLUDES = -I$(RIOTBASE)/core/include -I../include -I$(RIOTBOARD)/$(BOARD)
 MODULE =sht11
 include $(MAKEBASE)/makefile.base
 
diff --git a/makefile.base b/makefile.base
index 9de16b5149..65474687c9 100644
--- a/makefile.base
+++ b/makefile.base
@@ -20,6 +20,11 @@ ifeq ($(CPU),cc430)
  INCLUDES += -I$(MAKEBASE)/cpu/msp430-common/include/
  INCLUDES += -I$(MAKEBASE)/cpu/cc430/include/
 endif
+ifeq ($(BOARD),msba2)
+ INCLUDES += -I$(RIOTBOARD)/msba2/include/
+ INCLUDES += -I$(RIOTBOARD)/msba2-common/include/
+ INCLUDES += -I$(RIOTBOARD)/msba2-common/drivers/include/
+endif
 
 $(BINDIR)$(MODULE).a: $(OBJ) $(ASMOBJ)
 	$(AR) -rc $(BINDIR)$(MODULE).a $(OBJ) $(ASMOBJ)
diff --git a/makefile.dep b/makefile.dep
new file mode 100644
index 0000000000..4582bee5d2
--- /dev/null
+++ b/makefile.dep
@@ -0,0 +1,27 @@
+ifneq (,$(findstring vtimer,$(USEMODULE)))
+	ifeq (,$(findstring hwtimer,$(USEMODULE)))
+		USEMODULE += hwtimer
+	endif
+	ifeq (,$(findstring timex,$(USEMODULE)))
+		USEMODULE += timex
+	endif
+endif
+
+ifneq (,$(findstring uart0,$(USEMODULE)))
+	ifeq (,$(findstring lib,$(USEMODULE)))
+		USEMODULE += lib	
+	endif
+endif
+
+ifneq (,$(findstring cc110x_ng,$(USEMODULE)))
+  ifneq (,$(findstring msba2,$(BOARD)))
+  	USEMODULE += cc110x_spi
+	ifeq (,$(findstring gpioint,$(USEMODULE)))
+		USEMODULE += gpioint
+	endif
+	ifeq (,$(findstring hwtimer,$(USEMODULE)))
+		USEMODULE += hwtimer
+	endif
+  endif
+endif
+
diff --git a/makefile.modules b/makefile.modules
index a3c7584120..675cdaf24f 100644
--- a/makefile.modules
+++ b/makefile.modules
@@ -20,7 +20,11 @@ USEMODULE += cpu core sys
 endif
 ED = $(USEMODULE:%=-D MODULE_%)
 EXTDEFINES = $(shell echo $(ED)|tr 'a-z' 'A-Z')
-export BASELIBS=$(USEMODULE:%= $(BINDIR)%.a)
+BL=$(USEMODULE:%= $(BINDIR)%.a)
+# exclude hwtimer, because it is part of the kernel but the define is needed for auto_init
+export BASELIBS = $(shell echo $(BL)|sed 's/[^ ]*hwtimer.a//')
 CFLAGS += $(EXTDEFINES)
 
+include $(RIOTBASE)/makefile.dep
+
 export USEMODULE
diff --git a/sys/auto_init.c b/sys/auto_init/auto_init.c
similarity index 100%
rename from sys/auto_init.c
rename to sys/auto_init/auto_init.c
diff --git a/sys/auto_init/makefile b/sys/auto_init/makefile
new file mode 100644
index 0000000000..ffa6c4d6c6
--- /dev/null
+++ b/sys/auto_init/makefile
@@ -0,0 +1,5 @@
+INCLUDES = -I../include -I$(RIOTBASE)/core/include/ -I$(RIOTBASE)/drivers/include
+MODULE =auto_init
+
+include $(RIOTBASE)/makefile.base
+
diff --git a/sys/config.c b/sys/config/config.c
similarity index 100%
rename from sys/config.c
rename to sys/config/config.c
diff --git a/sys/config/makefile b/sys/config/makefile
new file mode 100644
index 0000000000..ea4db12a31
--- /dev/null
+++ b/sys/config/makefile
@@ -0,0 +1,5 @@
+INCLUDES = -I../include -I$(RIOTBASE)/core/include
+MODULE =config
+
+include $(RIOTBASE)/makefile.base
+
diff --git a/sys/include/ps.h b/sys/include/ps.h
index 876edab77f..25cc8cf18f 100644
--- a/sys/include/ps.h
+++ b/sys/include/ps.h
@@ -1,7 +1,7 @@
 #ifndef __PS_H
 #define __PS_H 
 
-void thread_print_all();
+void thread_print_all(void);
 void _ps_handler(char*);
 
 #endif /* __PS_H */
diff --git a/sys/lib/makefile b/sys/lib/makefile
index 982135d366..39621155ee 100644
--- a/sys/lib/makefile
+++ b/sys/lib/makefile
@@ -1,6 +1,5 @@
 INCLUDES = -I../include -I../drivers/include -I../lib -I../../cpu/$(CPU)/include -I../../cpu/ -I../lib/cmdengine -I../net -I../../hal/include -I../../core/include -I../config
-MODULE =shell
+MODULE =lib
 
 include $(RIOTBASE)/makefile.base
 
-
diff --git a/sys/makefile b/sys/makefile
index 88fc7b6632..8e6ae25b3b 100644
--- a/sys/makefile
+++ b/sys/makefile
@@ -2,6 +2,9 @@
 INCLUDES = -Iinclude -I$(RIOTBASE)/drivers/ -I$(RIOTBASE)/drivers/include -Ilib -I../.. -I../cpu/$(CPU)/include -I../cpu/ -Ilib/cmdengine -Inet -I../hal/include -I../core/include -Iconfig
 
 MODULE =sys
+ifneq (,$(findstring auto_init,$(USEMODULE)))
+    DIRS += auto_init
+endif
 ifneq (,$(findstring config,$(USEMODULE)))
     DIRS += config
 endif
@@ -20,6 +23,9 @@ endif
 ifneq (,$(findstring mprint,$(USEMODULE)))
     DIRS += mprint
 endif
+ifneq (,$(findstring ps,$(USEMODULE)))
+    DIRS += ps
+endif
 ifneq (,$(findstring sync_read,$(USEMODULE)))
     DIRS += sync_read
 endif
@@ -29,21 +35,33 @@ endif
 ifneq (,$(findstring sysmon,$(USEMODULE)))
     DIRS += sysmon
 endif
-ifneq (,$(findstring utimer,$(USEMODULE)))
-    DIRS += utimer
-endif
 ifneq (,$(findstring mqueue,$(USEMODULE)))
     DIRS += mqueue
 endif
+ifneq (,$(findstring posix,$(USEMODULE)))
+    DIRS += posix
+endif
 ifneq (,$(findstring shell,$(USEMODULE)))
     DIRS += shell
 endif
+ifneq (,$(findstring shell_commands,$(USEMODULE)))
+    DIRS += shell/commands
+endif
+ifneq (,$(findstring timex,$(USEMODULE)))
+    DIRS += timex
+endif
 ifneq (,$(findstring tracelog,$(USEMODULE)))
     DIRS += tracelog
 endif
 ifneq (,$(findstring transceiver,$(USEMODULE)))
     DIRS += transceiver
 endif
+ifneq (,$(findstring uart0,$(USEMODULE)))
+    DIRS += uart0
+endif
+ifneq (,$(findstring vtimer,$(USEMODULE)))
+    DIRS += vtimer
+endif
 
 all: $(BINDIR)$(MODULE).a 
 	@for i in $(DIRS) ; do $(MAKE) -C $$i ; done ;
diff --git a/sys/posix/makefile b/sys/posix/makefile
new file mode 100644
index 0000000000..4ce0d5187e
--- /dev/null
+++ b/sys/posix/makefile
@@ -0,0 +1,5 @@
+INCLUDES = -I../include -I$(RIOTBASE)/core/include
+MODULE =posix
+
+include $(RIOTBASE)/makefile.base
+
diff --git a/sys/posix_io.c b/sys/posix/posix_io.c
similarity index 100%
rename from sys/posix_io.c
rename to sys/posix/posix_io.c
diff --git a/sys/ps/makefile b/sys/ps/makefile
new file mode 100644
index 0000000000..6c374d75a4
--- /dev/null
+++ b/sys/ps/makefile
@@ -0,0 +1,5 @@
+INCLUDES = -I../include -I$(RIOTBASE)/core/include/ -I$(RIOTBASE)/drivers/include
+MODULE =ps
+
+include $(RIOTBASE)/makefile.base
+
diff --git a/sys/shell/ps.c b/sys/ps/ps.c
similarity index 95%
rename from sys/shell/ps.c
rename to sys/ps/ps.c
index 6c3226fead..fb7fcacf5f 100644
--- a/sys/shell/ps.c
+++ b/sys/ps/ps.c
@@ -18,8 +18,7 @@ const char *state_names[] = {
 /**
  * @brief Prints a list of running threads including stack usage to stdout.
  */
-void thread_print_all(void)
-{
+void thread_print_all(void) {
     extern unsigned long hwtimer_now(void);
     const char queued_name[] = {'_', 'Q'};
     int i;
@@ -49,8 +48,3 @@ void thread_print_all(void)
     }
     printf("\t%5s %-21s|%13s%6s %5i\n", "|", "SUM", "|", "|", overall_stacksz);
 }
-
-void _ps_handler(char* unnused) {
-    thread_print_all();
-}
-
diff --git a/sys/shell/commands/makefile b/sys/shell/commands/makefile
new file mode 100644
index 0000000000..1008c51a7c
--- /dev/null
+++ b/sys/shell/commands/makefile
@@ -0,0 +1,49 @@
+#SRC = cc1100.c cc110x_ng.c disk.c id.c ltc4150.c ps.c rtc.c shell.c shell_commands.c sht11.c
+SRC = shell_commands.c sc_id.c
+INCLUDES = -I../../../core/include -I../../include -I../../../drivers/include/
+
+#cc1100.c  cc110x_ng.c  disk.c  id.c  Jamfile  ltc4150.c  makefile  makefile.commands  ps.c  rtc.c  shell.c  shell_commands.c  sht11.c
+ifneq (,$(findstring cc110x_ng,$(USEMODULE)))
+	INCLUDES += -I$(RIOTBASE)/drivers/cc110x_ng/include/
+	SRC += sc_cc110x_ng.c
+endif
+ifneq (,$(findstring cc110x,$(USEMODULE)))
+	INCLUDES += -I$(RIOTBASE)/drivers/cc110x/
+	SRC += sc_cc1100.c
+endif
+ifneq (,$(findstring mci,$(USEMODULE)))
+	SRC += sc_disk.c
+endif
+ifneq (,$(findstring ltc4150,$(USEMODULE)))
+	SRC += sc_ltc4150.c
+endif
+ifneq (,$(findstring ps,$(USEMODULE)))
+	SRC += sc_ps.c
+endif
+ifneq (,$(findstring rtc,$(USEMODULE)))
+	SRC += sc_rtc.c
+endif
+ifneq (,$(findstring sht11,$(USEMODULE)))
+	SRC += sc_sht11.c
+endif
+
+OBJ = $(SRC:%.c=$(BINDIR)%.o)
+DEP = $(SRC:%.c=$(BINDIR)%.d)
+
+MODULE =shell_commands
+
+$(BINDIR)$(MODULE).a: $(OBJ)
+	$(AR) rc $(BINDIR)$(MODULE).a $(OBJ)
+
+# pull in dependency info for *existing* .o files
+-include $(OBJ:.o=.d)
+
+# compile and generate dependency info
+$(BINDIR)%.o: %.c
+	$(CC) $(CFLAGS) $(PROJECTINCLUDE) $(BOARDINCLUDE) $(INCLUDES) -c $*.c -o $(BINDIR)$*.o
+	$(CC) $(CFLAGS) $(PROJECTINCLUDE) $(BOARDINCLUDE) $(INCLUDES) -MM $*.c > $(BINDIR)$*.d
+	@printf "$(BINDIR)"|cat - $(BINDIR)$*.d > /tmp/riot_out && mv /tmp/riot_out $(BINDIR)$*.d
+
+# remove compilation products
+clean::
+	rm -f $(BINDIR)$(MODULE).a $(OBJ) $(DEP) $(ASMOBJ)
diff --git a/sys/shell/cc1100.c b/sys/shell/commands/sc_cc1100.c
similarity index 100%
rename from sys/shell/cc1100.c
rename to sys/shell/commands/sc_cc1100.c
diff --git a/sys/shell/cc110x_ng.c b/sys/shell/commands/sc_cc110x_ng.c
similarity index 100%
rename from sys/shell/cc110x_ng.c
rename to sys/shell/commands/sc_cc110x_ng.c
diff --git a/sys/shell/disk.c b/sys/shell/commands/sc_disk.c
similarity index 100%
rename from sys/shell/disk.c
rename to sys/shell/commands/sc_disk.c
diff --git a/sys/shell/id.c b/sys/shell/commands/sc_id.c
similarity index 100%
rename from sys/shell/id.c
rename to sys/shell/commands/sc_id.c
diff --git a/sys/shell/ltc4150.c b/sys/shell/commands/sc_ltc4150.c
similarity index 100%
rename from sys/shell/ltc4150.c
rename to sys/shell/commands/sc_ltc4150.c
diff --git a/sys/shell/commands/sc_ps.c b/sys/shell/commands/sc_ps.c
new file mode 100644
index 0000000000..2064e32c3d
--- /dev/null
+++ b/sys/shell/commands/sc_ps.c
@@ -0,0 +1,6 @@
+#include "ps.h"
+
+void _ps_handler(char* unnused) {
+    thread_print_all();
+}
+
diff --git a/sys/shell/rtc.c b/sys/shell/commands/sc_rtc.c
similarity index 100%
rename from sys/shell/rtc.c
rename to sys/shell/commands/sc_rtc.c
diff --git a/sys/shell/sht11.c b/sys/shell/commands/sc_sht11.c
similarity index 100%
rename from sys/shell/sht11.c
rename to sys/shell/commands/sc_sht11.c
diff --git a/sys/shell/shell_commands.c b/sys/shell/commands/shell_commands.c
similarity index 100%
rename from sys/shell/shell_commands.c
rename to sys/shell/commands/shell_commands.c
diff --git a/sys/shell/makefile b/sys/shell/makefile
index 982135d366..3b88abc0d6 100644
--- a/sys/shell/makefile
+++ b/sys/shell/makefile
@@ -1,6 +1,23 @@
-INCLUDES = -I../include -I../drivers/include -I../lib -I../../cpu/$(CPU)/include -I../../cpu/ -I../lib/cmdengine -I../net -I../../hal/include -I../../core/include -I../config
+SRC = shell.c
+OBJ = $(SRC:%.c=$(BINDIR)%.o)
+DEP = $(SRC:%.c=$(BINDIR)%.d)
+INCLUDES = -I../include
+
 MODULE =shell
 
-include $(RIOTBASE)/makefile.base
+$(BINDIR)$(MODULE).a: $(OBJ)
+	$(AR) rc $(BINDIR)$(MODULE).a $(OBJ)
+
+# pull in dependency info for *existing* .o files
+-include $(OBJ:.o=.d)
 
+# compile and generate dependency info
+$(BINDIR)%.o: %.c
+	$(CC) $(CFLAGS) $(PROJECTINCLUDE) $(BOARDINCLUDE) $(INCLUDES) -c $*.c -o $(BINDIR)$*.o
+	$(CC) $(CFLAGS) $(PROJECTINCLUDE) $(BOARDINCLUDE) $(INCLUDES) -MM $*.c > $(BINDIR)$*.d
+	@printf "$(BINDIR)"|cat - $(BINDIR)$*.d > /tmp/riot_out && mv /tmp/riot_out $(BINDIR)$*.d
 
+# remove compilation products
+clean::
+	rm -f $(BINDIR)$(MODULE).a $(OBJ) $(DEP) $(ASMOBJ)
+	
diff --git a/sys/timex/makefile b/sys/timex/makefile
new file mode 100644
index 0000000000..1ef2448bf3
--- /dev/null
+++ b/sys/timex/makefile
@@ -0,0 +1,5 @@
+INCLUDES = -I../include 
+MODULE =timex
+
+include $(RIOTBASE)/makefile.base
+
diff --git a/sys/timex.c b/sys/timex/timex.c
similarity index 100%
rename from sys/timex.c
rename to sys/timex/timex.c
diff --git a/sys/transceiver/makefile b/sys/transceiver/makefile
index 43efa202bc..8216bd217f 100644
--- a/sys/transceiver/makefile
+++ b/sys/transceiver/makefile
@@ -1,4 +1,4 @@
-INCLUDES = -I../include -I../drivers/include -I../drivers/cc110x_ng/include -I../lib -I../../cpu/$(CPU)/include -I../../cpu/ -I../net -I../../hal/include -I../../core/include -I../config
+INCLUDES = -I../include -I$(RIOTBAE)/drivers/include -I$(RIOTBASE)/drivers/cc110x_ng/include -I../lib -I../../cpu/$(CPU)/include -I../../cpu/ -I../net -I../../hal/include -I../../core/include -I../config
 MODULE =transceiver
 
 include $(MAKEBASE)/makefile.base
diff --git a/sys/uart0/makefile b/sys/uart0/makefile
new file mode 100644
index 0000000000..72c2cbda2e
--- /dev/null
+++ b/sys/uart0/makefile
@@ -0,0 +1,7 @@
+INCLUDES = -I../include -I../drivers/include -I../lib -I../../cpu/$(CPU)/include -I../../cpu/ -I../lib/cmdengine -I../net -I../../hal/include -I../../core/include -I../config
+
+MODULE =uart0
+
+include $(MAKEBASE)/makefile.base
+
+
diff --git a/sys/uart0.c b/sys/uart0/uart0.c
similarity index 100%
rename from sys/uart0.c
rename to sys/uart0/uart0.c
diff --git a/sys/vtimer/makefile b/sys/vtimer/makefile
new file mode 100644
index 0000000000..6c1df6e8e5
--- /dev/null
+++ b/sys/vtimer/makefile
@@ -0,0 +1,5 @@
+INCLUDES = -I../include -I$(RIOTBASE)/core/include/ -I$(RIOTBASE)/drivers/include
+MODULE =vtimer
+
+include $(RIOTBASE)/makefile.base
+
diff --git a/sys/vtimer.c b/sys/vtimer/vtimer.c
similarity index 100%
rename from sys/vtimer.c
rename to sys/vtimer/vtimer.c
-- 
GitLab