Usermode - Working on new build/makefile system
authorJohn Hodge <[email protected]>
Wed, 7 Dec 2011 15:48:30 +0000 (23:48 +0800)
committerJohn Hodge <[email protected]>
Wed, 7 Dec 2011 15:48:30 +0000 (23:48 +0800)
Usermode/Libraries/acess.ld_src/rules.mk [new file with mode: 0644]
Usermode/Libraries/ld-acess.so_src/arch/x86.asm.h
Usermode/Libraries/ld-acess.so_src/arch/x86_64.asm.h
Usermode/Libraries/ld-acess.so_src/rules.mk [new file with mode: 0644]
Usermode/Libraries/libc.so_src/rules.mk [new file with mode: 0644]
Usermode/Libraries/libgcc.so_src/rules.mk [new file with mode: 0644]
Usermode/Libraries/rules.mk [new file with mode: 0644]
Usermode/body.mk [new file with mode: 0644]
Usermode/footer.mk [new file with mode: 0644]
Usermode/header.mk [new file with mode: 0644]
Usermode/rules.mk [new file with mode: 0644]

diff --git a/Usermode/Libraries/acess.ld_src/rules.mk b/Usermode/Libraries/acess.ld_src/rules.mk
new file mode 100644 (file)
index 0000000..f2f3de0
--- /dev/null
@@ -0,0 +1,20 @@
+include $(BASE)header.mk
+
+# Variables
+BIN = $(OUTPUTDIR)Libs/acess.ld
+
+# Rules
+.PHONY: all-$(DIR)
+
+all-$(DIR): $(BIN)
+clean-$(DIR):
+       $(RM) $(BIN)
+
+$(BIN):        $(DIR)/acess_$(ARCHDIR).ld.h
+       @mkdir -p $(dir $(BIN))
+       cpp -nostdinc -U i386 -P -C $< -o $@ -D__LIBDIR=$(OUTPUTDIR)Libs
+
+$(DIR)/acess_$(ARCHDIR).ld.h:
+       $(LD) --verbose | awk '{ if( substr($$0,0,5) == "====="){ bPrint = !bPrint; } else { if(bPrint){ print $$0;} } }' | sed 's/SEARCH_DIR\(.*\)/SEARCH_DIR(__LIBDIR)/' > $@
+
+include $(BASE)footer.mk
index 1f5ba1f..7780ee8 100644 (file)
@@ -2,7 +2,7 @@
 ; AcssMicro - System Calls
 ; ========================
 
-%include "../../../Kernel/include/syscalls.inc.asm"
+#include "../../../../Kernel/include/syscalls.h"
 
 [bits 32]
 [section .data]
index 9c52098..9f7be4e 100644 (file)
@@ -2,7 +2,7 @@
 ; AcssMicro - System Calls
 ; ========================
 
-%include "../../../Kernel/include/syscalls.inc.asm"
+#include "../../../../Kernel/include/syscalls.h"
 
 [bits 64]
 
diff --git a/Usermode/Libraries/ld-acess.so_src/rules.mk b/Usermode/Libraries/ld-acess.so_src/rules.mk
new file mode 100644 (file)
index 0000000..2c86441
--- /dev/null
@@ -0,0 +1,42 @@
+# Acess2 - ld-acess
+include $(BASE)header.mk
+
+# Variables
+SRCS := main.c lib.c loadlib.c export.c elf.c pe.c
+SRCS += arch/$(ARCHDIR).$(ASSUFFIX)
+BIN  := $(OUTPUTDIR)Libs/ld-acess.so
+XOBJ := $(call fcn_mkobj,_stublib.o)
+XBIN := $(OUTPUTDIR)Libs/libld-acess.so
+
+CFLAGS-$(DIR) := -Wall -fno-builtin -fno-leading-underscore -fno-stack-protector -fPIC -g
+CPPFLAGS-$(DIR) := $(CPPFLAGS-$(PDIR))
+LDFLAGS-$(DIR) := -g -T $(DIR)/arch/$(ARCHDIR).ld -Map $(call fcn_mkobj,map.txt) --export-dynamic
+
+OBJ := $(call fcn_src2obj,$(SRCS))
+ALL_OBJ := $(ALL_OBJ) $(OBJ)
+OBJ-$(DIR) := $(OBJ) $(XOBJ)
+BIN-$(DIR) := $(BIN) $(XBIN)
+
+# Rules
+.PHONY: all-$(DIR) clean-$(DIR)
+
+all-$(DIR): $(BIN-$(DIR))
+clean-$(DIR): clean-%: 
+       $(eval BIN=$(BIN-$*/))
+       $(eval OBJ=$(OBJ-$*/))
+       $(RM) $(BIN) $(OBJ)
+
+$(BIN): $(OBJ)
+
+# Stub library
+$(XBIN): $(call fcn_mkobj,_stublib.c.o)
+       @echo [LD] -shared -o libld-acess.so
+       @$(LD) -shared -o $@ $<
+
+# Handle preprocessed files
+$(DIR)/%: $(DIR)/%.h
+       @echo [CPP] -o $@
+       @mkdir -p $(dir $@)
+       @$(CPP) $(CPPFLAGS-$(DIR)) -P -D__ASSEMBLER__ $< -o $@
+
+include $(BASE)footer.mk
diff --git a/Usermode/Libraries/libc.so_src/rules.mk b/Usermode/Libraries/libc.so_src/rules.mk
new file mode 100644 (file)
index 0000000..5bc4289
--- /dev/null
@@ -0,0 +1,19 @@
+# libc
+
+include $(BASE)header.mk
+
+# Variables
+SRCS := stub.c heap.c stdlib.c env.c fileIO.c string.c select.c
+SRCS += arch/$(ARCHDIR).$(ASSUFFIX)
+# signals.c
+BIN  := $(OUTPUTDIR)Libs/libc.so
+
+CFLAGS-$(DIR) := $(CFLAGS-$(PDIR)) -g
+CPPFLAGS-$(DIR) := $(CPPFLAGS-$(PDIR))
+LDFLAGS-$(DIR) := $(LDFLAGS-$(PDIR))
+
+include $(BASE)body.mk
+
+$(BIN): $(OBJ) $(OUTPUTDIR)Libs/libgcc.so
+
+include $(BASE)footer.mk
diff --git a/Usermode/Libraries/libgcc.so_src/rules.mk b/Usermode/Libraries/libgcc.so_src/rules.mk
new file mode 100644 (file)
index 0000000..ce2c6cc
--- /dev/null
@@ -0,0 +1,16 @@
+# libgcc
+include $(BASE)header.mk
+
+# Variables
+SRCS := libgcc.c
+BIN  := $(OUTPUTDIR)Libs/libgcc.so
+
+CFLAGS-$(DIR) := $(CFLAGS-$(PDIR))
+CPPFLAGS-$(DIR) := $(CPPFLAGS-$(PDIR))
+LDFLAGS-$(DIR) := $(LDFLAGS-$(PDIR))
+
+include $(BASE)body.mk
+
+$(BIN): $(OBJ)
+
+include $(BASE)footer.mk
diff --git a/Usermode/Libraries/rules.mk b/Usermode/Libraries/rules.mk
new file mode 100644 (file)
index 0000000..e7e9302
--- /dev/null
@@ -0,0 +1,17 @@
+include $(BASE)header.mk
+
+# Rules
+ASFLAGS-$(DIR)  := -D ARCHDIR=$(ARCHDIR) -D __ASSEMBLER__=1
+CPPFLAGS-$(DIR) := -I$(ACESSDIR)/Usermode/include/ -DARCHDIR=$(ARCHDIR) -DARCHDIR_is_$(ARCHDIR)=1
+CFLAGS-$(DIR)   := -g -Wall -fPIC -fno-stack-protector -O3
+LDFLAGS-$(DIR)  := -g -nostdlib -shared -I/Acess/Libs/ld-acess.so -lld-acess -e SoMain -x -L$(OUTPUTDIR)Libs/ --no-undefined
+
+SUB_DIRS = $(wildcard $(DIR)*/rules.mk)
+
+.PHONY: all-$(DIR) clean-$(DIR)
+all-$(DIR): open-$(DIR) $(addprefix all-,$(dir $(SUB_DIRS))) close-$(DIR) 
+clean-$(DIR): $(addprefix clean-,$(dir $(SUB_DIRS)))
+
+include $(SUB_DIRS)
+
+include $(BASE)footer.mk
diff --git a/Usermode/body.mk b/Usermode/body.mk
new file mode 100644 (file)
index 0000000..83a7b81
--- /dev/null
@@ -0,0 +1,14 @@
+
+OBJ := $(call fcn_src2obj,$(SRCS))
+ALL_OBJ := $(ALL_OBJ) $(OBJ)
+OBJ-$(DIR) := $(OBJ)
+BIN-$(DIR) := $(BIN)
+
+# Rules
+.PHONY: all-$(DIR) clean-$(DIR)
+all-$(DIR): $(BIN)
+clean-$(DIR): clean-%: 
+       $(eval BIN=$(BIN-$*/))
+       $(eval OBJ=$(OBJ-$*/))
+       $(RM) $(BIN) $(OBJ)
+
diff --git a/Usermode/footer.mk b/Usermode/footer.mk
new file mode 100644 (file)
index 0000000..d07e89d
--- /dev/null
@@ -0,0 +1,7 @@
+
+open-$(DIR): $(SRC-$(DIR))
+close-$(DIR): $(SRC-$(DIR))
+
+# Pop State
+DIR := $(DIR_$(x))
+x := $(x:%.x=%)
diff --git a/Usermode/header.mk b/Usermode/header.mk
new file mode 100644 (file)
index 0000000..6f3c1a7
--- /dev/null
@@ -0,0 +1,5 @@
+# Push State
+x := $(x).x
+DIR_$(x) := $(DIR)
+DIR := $(dir $(lastword $(filter-out %/header.mk,$(MAKEFILE_LIST))))
+PDIR := $(DIR_$(x))
diff --git a/Usermode/rules.mk b/Usermode/rules.mk
new file mode 100644 (file)
index 0000000..b31b60d
--- /dev/null
@@ -0,0 +1,122 @@
+#
+# Acess2 Global Makefile
+#
+
+# Config Options
+SOURCE_DIR = 
+OBJECT_DIR = obj-$(ARCH)
+OBJECT_SUFFIX =
+
+# Functions used later
+fcn_src2obj_int = \
+       $(patsubst %,%$(OBJECT_SUFFIX).o,$(filter %.c,$1)) \
+       $(patsubst %,%$(OBJECT_SUFFIX).o,$(filter %.cpp,$1)) \
+       $(patsubst %,%$(OBJECT_SUFFIX).o,$(filter %.cc,$1)) \
+       $(patsubst %,%$(OBJECT_SUFFIX).o,$(filter %.S,$1)) \
+       $(patsubst %,%$(OBJECT_SUFFIX).o,$(filter %.asm,$1))
+fcn_mkobj = $(addprefix $(DIR)$(OBJECT_DIR)/,$(patsubst $(SOURCE_DIR)%,%,$1))
+fcn_src2obj = $(call fcn_mkobj, $(call fcn_src2obj_int,$1))
+
+# Start of Voodoo code
+SUB_DIRS = $(wildcard */rules.mk)
+
+_REL_POS := $(dir $(lastword $(MAKEFILE_LIST)))
+BASE = $(abspath $(_REL_POS))/
+ifeq ($(_REL_POS),./)
+    # Root makefile
+    DEFAULT_RULES := $(dir $(SUB_DIRS))
+else
+    # Build part of the tree
+    DEFAULT_RULES := $(abspath $(pwd)/$(_REL_POS))
+endif
+
+include $(_REL_POS)../Makefile.cfg
+
+.PHONY: all clean
+
+all: $(BASE)obj_rules.mk $(addprefix all-,$(DEFAULT_RULES))
+clean: $(addprefix clean-,$(DEFAULT_RULES))
+
+# Sub-directory rules
+x = x
+include $(SUB_DIRS)
+
+
+# === Rules ===
+fcn_obj2src = $(subst $(OBJECT_DIR)/,$(SOURCE_DIR)/,$(patsubst %$(OBJECT_SUFFIX).o,%,$1))
+
+ifeq (x,)
+$(foreach file,$(filter %.cpp$(OBJECT_SUFFIX).o,$(ALL_OBJ)), $(eval $f: $(call fcn_obj2src,$f)))
+$(foreach file,$(filter %.cc$(OBJECT_SUFFIX).o,$(ALL_OBJ)), $(eval $f: $(call fcn_obj2src,$f)))
+$(foreach file,$(filter %.c$(OBJECT_SUFFIX).o,$(ALL_OBJ)), $(eval $f: $(call fcn_obj2src,$f)))
+$(foreach file,$(filter %.S$(OBJECT_SUFFIX).o,$(ALL_OBJ)), $(eval $f: $(call fcn_obj2src,$f))))
+$(foreach file,$(filter %.asm$(OBJECT_SUFFIX).o,$(ALL_OBJ)), $(eval $f: $(call fcn_obj2src,$f)))
+else
+.PHONY: $(BASE)obj_rules.mk
+$(BASE)obj_rules.mk:
+       @echo "$(foreach f,$(filter %.cpp$(OBJECT_SUFFIX).o,$(ALL_OBJ)),$f: $(call fcn_obj2src,$f)\n)" > $@
+       @echo "$(foreach f,$(filter %.cc$(OBJECT_SUFFIX).o,$(ALL_OBJ)),$f: $(call fcn_obj2src,$f)\n)" >> $@
+       @echo "$(foreach f,$(filter %.c$(OBJECT_SUFFIX).o,$(ALL_OBJ)),$f: $(call fcn_obj2src,$f)\n)" >> $@
+       @echo "$(foreach f,$(filter %.S$(OBJECT_SUFFIX).o,$(ALL_OBJ)),$f: $(call fcn_obj2src,$f)\n)" >> $@
+       @echo "$(foreach f,$(filter %.asm$(OBJECT_SUFFIX).o,$(ALL_OBJ)),$f: $(call fcn_obj2src,$f)\n)" >> $@
+include $(BASE)obj_rules.mk
+endif
+
+# --- Object Files ---
+# C++ (.cpp)
+%.cpp$(OBJECT_SUFFIX).o:
+       $(eval _dir=$(dir $(subst $(OBJECT_DIR)/,,$*)))
+       $(eval <=$(call fcn_obj2src,$@))
+       @echo [CXX] -o $<
+       @mkdir -p $(dir $@)
+       @$(CCPP) $(CXXFLAGS) $(CPPFLAGS) $(CXXFLAGS-$(_dir)) $(CPPFLAGS-$(_dir))-c $(_src) -o $@
+# C++ (.cc)
+%.cc$(OBJECT_SUFFIX).o:
+       $(eval _dir=$(dir $(subst $(OBJECT_DIR)/,,$*)))
+       $(eval _src=$(call fcn_obj2src,$@))
+       @echo [CXX] -o $<
+       @mkdir -p $(dir $@)
+       @$(CCPP) $(CXXFLAGS) $(CXXFLAGS-$(_dir)) $(CPPFLAGS-$(_dir)) -c $(_src) -o $@
+# C (.c)
+%.c$(OBJECT_SUFFIX).o:
+       $(eval _dir=$(dir $(subst $(OBJECT_DIR)/,,$*)))
+       $(eval _src=$(call fcn_obj2src,$@))
+       @echo [CC] -o $@
+       @mkdir -p $(dir $@)
+       @$(CC) $(CFLAGS) $(CPPFLAGS) $(CFLAGS-$(_dir)) $(CPPFLAGS-$(_dir)) -c $(_src) -o $@
+# Assembly (.S)
+%.S$(OBJECT_SUFFIX).o:
+       $(eval _dir=$(dir $(subst $(OBJECT_DIR)/,,$*)))
+       $(eval _src=$(call fcn_obj2src,$@))
+       @echo [AS] -o $@
+       @mkdir -p $(dir $@)
+       @$(AS) $(ASFLAGS) $(ASFLAGS-$(_dir)) -o $@ $(_src)
+       @$(AS) $(ASFLAGS) $(ASFLAGS-$(_dir)) -o [email protected] $(_src) -M
+# Assembly (.asm)
+%.asm$(OBJECT_SUFFIX).o:
+       $(eval _dir=$(dir $(subst $(OBJECT_DIR)/,,$*)))
+       $(eval _src=$(call fcn_obj2src,$@))
+       @echo [AS] -o $@
+       @mkdir -p $(dir $@)
+       @$(AS) $(ASFLAGS) $(ASFLAGS-$(_dir)) -o $@ $(_src)
+       @$(AS) $(ASFLAGS) $(ASFLAGS-$(_dir)) -o $@ $(_src) -MD [email protected]
+
+# --- Binaries ---
+# Static Library (.a)
+%.a:
+       $(eval _dir=$(subst $(OBJECT_DIR),,$(dir $<)))
+       @echo [AR] ru $@
+       @$(RM) $@
+       @$(AR) ru $@ $(OBJ-$(_dir))
+# Dynamic Library (.so)
+%.so:
+       $(eval _dir=$(subst $(OBJECT_DIR),,$(dir $<)))
+       @echo [LD] -shared -o $@
+       @$(LD) $(LDFLAGS) -shared -soname $(basename $@) -o $@ $(filter %.o,$^) $(LDFLAGS-$(_dir))
+# Executable (.bin)
+%.bin:
+       $(eval _dir=$(subst $(OBJECT_DIR),,$(dir $<)))
+       @echo [LD] -o $@
+       @$(ld) $(LDFLAGS) -o $@ $(OBJ-$(_dir)) $(LDFLAGS-$(_dir))
+       @$(CP) $@ $(@:%.bin=%)
+    

UCC git Repository :: git.ucc.asn.au