Pthread: stop accessing memory after it was freed
[akaros.git] / GNUmakefile
index 150ed27..7dfd0bb 100644 (file)
@@ -1,6 +1,9 @@
 # The ROS Top level Makefile
 # Make sure that 'all' is the first target
 
+# Keep make quiet.  Make sure you call make via $(MAKE), and not directly
+MAKE += -s 
+
 ############################################################################# 
 ########## Initial Setup so that we can build for different TARGETS #########
 ############################################################################# 
@@ -21,9 +24,9 @@ $(TARGET_ARCH):
        @if [ "$(ARCH_LINK)" != "$@" ];\
        then\
          $(MAKE) realclean;\
-         $(MAKE) all -j;\
+         $(MAKE) realall -j $(MAKE_JOBS);\
        else\
-         $(MAKE) real-all -j;\
+         $(MAKE) all -j $(MAKE_JOBS);\
        fi
 
 ############################################################################# 
@@ -33,16 +36,24 @@ $(TARGET_ARCH):
 # Default values for configurable Make system variables
 COMPILER := GCC
 OBJDIR := obj
-V := @
+V ?= @
 
 # Make sure that 'all' is the first target when not erroring out
-all: symlinks
+realall: symlinks
+
+# Number of make jobs to spawn.  Define it in Makelocal
+MAKE_JOBS :=
+
+# Give it a reasonable default path for initramfs to avoid build breakage
+INITRAMFS_PATHS = kern/kfs
+FIRST_INITRAMFS_PATH = $(firstword $(INITRAMFS_PATHS))
 
 # Then grab the users Makelocal file to let them override Make system variables
 # and set up other Make targets
+include Makeconfig
 -include Makelocal
 
-TOP_DIR := .
+TOP_DIR := $(shell pwd)
 ARCH_DIR := $(TOP_DIR)/kern/arch
 INCLUDE_DIR := $(TOP_DIR)/kern/include
 DOXYGEN_DIR := $(TOP_DIR)/Documentation/doxygen
@@ -80,16 +91,17 @@ endif
 endif
 
 # Default programs for compilation
+USER_CFLAGS += -O2 -std=gnu99
 ifeq ($(COMPILER),IVY)
-KERN_CFLAGS := --deputy \
-                  --no-rc-sharc \
-                  --sc-dynamic-is-error \
-                  --sc-ops=$(INCLUDE_DIR)/ivy/sharc.h \
-                  --sc-all-in-thread \
-                  --enable-precompile \
-#                  --enable-error-db \
-
-USER_CFLAGS := --deputy --enable-error-db
+KERN_CFLAGS += --deputy \
+               --no-rc-sharc \
+               --sc-dynamic-is-error \
+               --sc-ops=$(INCLUDE_DIR)/ivy/sharc.h \
+               --sc-all-in-thread \
+               --enable-precompile \
+#               --enable-error-db \
+
+USER_CFLAGS += --deputy --enable-error-db
 CC         := ivycc --gcc=$(GCCPREFIX)gcc
 else
 CC         := $(GCCPREFIX)gcc 
@@ -101,6 +113,7 @@ LD      := $(GCCPREFIX)ld
 OBJCOPY        := $(GCCPREFIX)objcopy
 OBJDUMP        := $(GCCPREFIX)objdump
 NM         := $(GCCPREFIX)nm
+STRIP   := $(GCCPREFIX)strip
 PERL    := perl
 
 EXTRAARGS ?= -std=gnu99 -Wno-attributes -fno-stack-protector -fgnu89-inline
@@ -113,10 +126,10 @@ endif
 # Universal compiler flags
 # -fno-builtin is required to avoid refs to undefined functions in the kernel.
 # Only optimize to -O1 to discourage inlining, which complicates backtraces.
-CFLAGS := $(CFLAGS) -D$(TARGET_ARCH) $(EXTRAARGS)
-CFLAGS += -O2 -pipe -MD -fno-builtin -gstabs
-CFLAGS += -Wall -Wno-format -Wno-unused -fno-strict-aliasing
-CFLAGS += -nostdinc -I$(dir $(GCC_LIB))/include
+KERN_CFLAGS += -D$(TARGET_ARCH) $(EXTRAARGS)
+KERN_CFLAGS += -O2 -pipe -MD -fno-builtin -gstabs
+KERN_CFLAGS += -Wall -Wno-format -Wno-unused -fno-strict-aliasing
+KERN_CFLAGS += -nostdinc -I$(dir $(GCC_LIB))/include
 
 # Universal loader flags
 LDFLAGS := -nostdlib
@@ -126,16 +139,54 @@ OBJDIRS :=
 
 ROS_ARCH_DIR ?= $(TARGET_ARCH)
 
+arch:
+       @echo "TARGET_ARCH=$(TARGET_ARCH)"
+
 symlinks: error
        ln -fs ../arch/$(ROS_ARCH_DIR) kern/include/arch
        ln -fs arch/$(ROS_ARCH_DIR)/boot kern/boot
-       @$(MAKE) -j real-all
+       ln -fs $(ROS_ARCH_DIR) user/parlib/include/arch
+       @$(MAKE) -j $(MAKE_JOBS) all
 
 # Include Makefrags for subdirectories
 ifneq ($(TARGET_ARCH),)
+include tests/Makefrag
 include kern/Makefrag
 endif
 
+ifeq ($(GCCPREFIX),$(TARGET_ARCH)-ros-)
+GCC_ROOT := $(shell which $(GCCPREFIX)gcc | xargs dirname)/../
+tests/: tests
+tests: install-libs
+       @$(MAKE) -j $(MAKE_JOBS) realtests
+realtests: $(TESTS_EXECS)
+# No longer automatically copying to the FS dir (deprecated)
+#      @mkdir -p fs/$(TARGET_ARCH)/tests
+#      cp -R $(OBJDIR)/$(TESTS_DIR)/* $(TOP_DIR)/fs/$(TARGET_ARCH)/tests
+
+USER_LIBS = parlib pthread c3po
+install-libs: 
+       @for i in $(USER_LIBS) ; do \
+               cd user/$$i;            \
+               $(MAKE);                \
+               $(MAKE) install;        \
+               cd ../..;               \
+       done
+
+fill-kfs: install-libs
+       @rm -rf $(FIRST_INITRAMFS_PATH)/lib
+       @cp -R $(GCC_ROOT)/$(TARGET_ARCH)-ros/lib $(FIRST_INITRAMFS_PATH)
+
+userclean:
+       @for i in $(USER_LIBS) ; do \
+               cd user/$$i;            \
+               $(MAKE) clean;          \
+               cd ../..;               \
+       done
+       @rm -rf $(OBJDIR)/$(TESTS_DIR)
+.PHONY: tests
+endif
+
 # Eliminate default suffix rules
 .SUFFIXES:
 
@@ -165,7 +216,6 @@ docs:
 doxyclean:
        rm -rf $(DOXYGEN_DIR)/rosdoc
 
-# For deleting the build
 clean:
        @rm -rf $(OBJDIR)
        @echo All clean and pretty!
@@ -173,6 +223,7 @@ clean:
 realclean: clean
        @rm -f kern/boot
        @rm -f kern/include/arch
+       @rm -f user/parlib/include/arch
 
 always:
        @: