changeset 54:aa0095c4c2b0

fix cmake linker options
author anatofuz
date Thu, 06 Jun 2019 19:16:22 +0900
parents 435bfab09924
children 4f5d1aa8b594
files src/CMakeLists.txt src/makefile-armgccbc
diffstat 2 files changed, 61 insertions(+), 36 deletions(-) [+]
line wrap: on
line diff
--- a/src/CMakeLists.txt	Mon Jun 03 19:39:11 2019 +0900
+++ b/src/CMakeLists.txt	Thu Jun 06 19:16:22 2019 +0900
@@ -1,6 +1,29 @@
 cmake_minimum_required(VERSION 3.8)
 project(xv6cbc C ASM)
 
+# https://github.com/llvm-mirror/libcxx/blob/master/cmake/Modules/HandleCompilerRT.cmake
+function(find_compiler_rt_library dest)
+  #if (NOT DEFINED LIBC_COMPILE_FLAGS)
+  #  message(FATAL_ERROR "LIBC_COMPILE_FLAGS must be defined when using this function")
+  #endif()
+  set(dest "" PARENT_SCOPE)
+  set(CLANG_COMMAND ${CMAKE_C_COMPILER} 
+      "--print-libgcc-file-name")
+  if (CMAKE_C_COMPILER_ID MATCHES Clang AND CMAKE_C_COMPILER_TARGET)
+    list(APPEND CLANG_COMMAND "--target=${CMAKE_C_COMPILER_TARGET}")
+  endif()
+  #get_property(LIBC_C_FLAGS CACHE CMAKE_C_FLAGS PROPERTY VALUE)
+  string(REPLACE " " ";" LIBC_C_FLAGS "${LIBC_C_FLAGS}")
+  list(APPEND CLANG_COMMAND ${LIBC_C_FLAGS})
+  execute_process(
+      COMMAND ${CLANG_COMMAND}
+      RESULT_VARIABLE HAD_ERROR
+      OUTPUT_VARIABLE LIBRARY_FILE
+  )
+  string(STRIP "${LIBRARY_FILE}" LIBRARY_FILE)
+  set(${dest} "${LIBRARY_FILE}" PARENT_SCOPE)
+endfunction()
+
 set(USE_CUDA,0)
 # -DUSE_CUDA
 #  add_definitions("-Wall -g -O")
@@ -11,15 +34,16 @@
              -Wno-macro-redefined -Wno-gnu-designator -Wno-sometimes-uninitialized -Wno-tautological-compare 
              -I/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/usr/include
              -Wno-nullability-completeness -Wno-expansion-to-defined")
-    set(CMAKE_EXE_LINKER_FLAGS "-L. -arch armv7 -T  kernel.ld -o  kernel.elf ")
+    set(CMAKE_EXE_LINKER_FLAGS "-L. -arch armv7 -T  kernel-cmake.ld -o  kernel.elf ")
 else (APPLE)
     set(CMAKE_C_COMPILER /mnt/dalmore-home/one/src/armgcc/cross/bin/arm-none-eabi-gcc)
     set(CMAKE_ASM_COMPILER /mnt/dalmore-home/one/src/armgcc/cross/bin/arm-none-eabi-gcc)
+    set(CMAKE_EXE_LINK_EXECUTABLE "/mnt/dalmore-home/one/src/armgcc/cross/bin/arm-none-eabi-ld")
     add_definitions("-B/mnt/dalmore-home/one/src/armgcc/cross/bin/arm-none-eabi-  
              -DCBCXV6=1 -fno-pic -static -fno-builtin -fno-strict-aliasing -Wall -I. -g -O0")
-    set(CMAKE_EXE_LINKER_FLAGS "-L.  -T  kernel.ld  -o  kernel.elf -nostdlib ")
-
-
+    find_compiler_rt_library("LIBRARY_FILE")
+    set(CMAKE_EXE_LINKER_FLAGS "-L.  -T  kernel-cmake.ld  ${LIBRARY_FILE} -o kernel.elf  -b binary -nostdlib ")
+    
 endif (APPLE)
 
 # -DCMAKE_BUILD_TYPE=Debug
@@ -86,8 +110,7 @@
   SOURCES
 	lib/string.c arm.c asm.S bio.c buddy.c console.cbc exec.c file.cbc fs.c log.c main.c memide.c pipe.cbc proc.cbc spinlock.cbc
 	start.c swtch.S syscall.cbc sysfile.cbc sysproc.c trap_asm.S trap.c vm.c device/picirq.c device/timer.c device/uart.c
-         entry.S 
+     lib/string.c    entry.S 
 )
 
 
-
--- a/src/makefile-armgccbc	Mon Jun 03 19:39:11 2019 +0900
+++ b/src/makefile-armgccbc	Thu Jun 06 19:16:22 2019 +0900
@@ -31,42 +31,44 @@
 # link the libgcc.a for __aeabi_idiv. ARM has no native support for div
 LIBS = $(LIBGCC)
 
+CMAKEDIR =  CMakeFiles/kernel.dir
+
 OBJS = \
-	lib/string.o \
+	$(CMAKEDIR)/lib/string.c.o \
+	$(CMAKEDIR)/c/kernel-context.c.o\
+	$(CMAKEDIR)/arm.c.o\
+	$(CMAKEDIR)/asm.S.o\
+	$(CMAKEDIR)/bio.c.o\
+	$(CMAKEDIR)/buddy.c.o\
+	$(CMAKEDIR)/c/console.c.o\
+	$(CMAKEDIR)/exec.c.o\
+	$(CMAKEDIR)/c/file.c.o\
+	$(CMAKEDIR)/fs.c.o\
+	$(CMAKEDIR)/log.c.o\
+	$(CMAKEDIR)/main.c.o\
+	$(CMAKEDIR)/memide.c.o\
+	$(CMAKEDIR)/c/pipe.c.o\
+	$(CMAKEDIR)/c/proc.c.o\
+	$(CMAKEDIR)/c/spinlock.c.o\
+	$(CMAKEDIR)/start.c.o\
+	$(CMAKEDIR)/swtch.S.o\
+	$(CMAKEDIR)/c/syscall.c.o\
+	$(CMAKEDIR)/c/sysfile.c.o\
+	$(CMAKEDIR)/sysproc.c.o\
+	$(CMAKEDIR)/trap_asm.c.o\
+	$(CMAKEDIR)/trap.c.o\
+	$(CMAKEDIR)/vm.c.o \
 	\
-	arm.o\
-	asm.o\
-	bio.o\
-	buddy.o\
-	console.o\
-	exec.o\
-	file.o\
-	fs.o\
-	log.o\
-	main.o\
-	memide.o\
-	pipe.o\
-	proc.o\
-	spinlock.o\
-	start.o\
-	swtch.o\
-	syscall.o\
-	sysfile.o\
-	sysproc.o\
-	trap_asm.o\
-	trap.o\
-	vm.o \
-	\
-	device/picirq.o \
-	device/timer.o \
-	device/uart.o
+	$(CMAKEDIR)/device/picirq.c.o \
+	$(CMAKEDIR)/device/timer.c.o \
+	$(CMAKEDIR)/device/uart.c.o
 
-KERN_OBJS = $(OBJS) entry.o
-kernel.elf: $(addprefix build/,$(KERN_OBJS)) kernel.ld build/initcode build/fs.img
+KERN_OBJS = $(OBJS) entry.S.o
+kernel.elf: $(KERN_OBJS) kernel.ld build/initcode build/fs.img
 	cp -f build/initcode initcode
 	cp -f build/fs.img fs.img
 	$(call LINK_BIN, kernel.ld, kernel.elf, \
-		$(addprefix build/,$(KERN_OBJS)), \
+		$(KERN_OBJS), \
 		initcode fs.img)
 	$(OBJDUMP) -S kernel.elf > kernel.asm
 	$(OBJDUMP) -t kernel.elf | sed '1,/SYMBOL TABLE/d; s/ .* / /; /^$$/d' > kernel.sym