58
|
1 cmake_minimum_required(VERSION 3.8)
|
59
|
2 set(CMAKE_C_COMPILER "/usr/bin/cc")
|
58
|
3 project(usr C ASM)
|
|
4
|
|
5
|
|
6 set(CMAKE_C_FLAGS_DEBUG "-O0")
|
|
7 add_definitions(${PMAKE_ARGS})
|
|
8 set(CMAKE_C_COMPILER "${CBC_COM}")
|
|
9
|
69
|
10 #include_directories("..")
|
63
|
11 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ")
|
|
12 set(CMAKE_C_LINK_EXECUTABLE "${KERNEL_LINK_EXECUTABLE}")
|
62
|
13 set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${GCC_LIB} -nostdlib")
|
58
|
14
|
|
15 macro( GearsCommand )
|
69
|
16 include_directories(${CMAKE_SOURCE_DIR})
|
|
17 include_directories(${CMAKE_SOURCE_DIR}/usr)
|
|
18 include_directories(${CMAKE_BINARY_DIR}/usr/c)
|
|
19
|
58
|
20 set( _OPTIONS_ARGS )
|
|
21 set( _ONE_VALUE_ARGS TARGET )
|
|
22 set( _MULTI_VALUE_ARGS SOURCES )
|
|
23 cmake_parse_arguments( _Gears "${_OPTIONS_ARGS}" "${_ONE_VALUE_ARGS}" "${_MULTI_VALUE_ARGS}" ${ARGN} )
|
|
24
|
|
25 set (_Gears_CBC_SOURCES)
|
|
26 set (_Gears_CSOURCES)
|
|
27 foreach(i ${_Gears_SOURCES})
|
|
28 if (${i} MATCHES "\\.cbc")
|
|
29 string(REGEX REPLACE "(.*).cbc" "c/\\1.c" j ${i})
|
|
30 add_custom_command (
|
|
31 OUTPUT ${j}
|
|
32 DEPENDS ${i}
|
69
|
33 COMMAND "perl" "${CMAKE_SOURCE_DIR}/gearsTools/generate_stub.pl" "-o" ${j} ${i}
|
58
|
34 )
|
|
35 list(APPEND _Gears_CBC_SOURCES ${j})
|
|
36 elseif (${i} MATCHES "\\.cu")
|
|
37 string(REGEX REPLACE "(.*).cu" "c/\\1.ptx" j ${i})
|
|
38 add_custom_command (
|
|
39 OUTPUT ${j}
|
|
40 DEPENDS ${i}
|
|
41 COMMAND nvcc ${NVCCFLAG} -c -ptx -o ${j} ${i}
|
|
42 )
|
|
43 list(APPEND _Gears_CBC_SOURCES ${j})
|
|
44 else()
|
|
45 set(j ${i})
|
71
|
46 file(COPY "${CMAKE_SOURCE_DIR}/context.h" DESTINATION "${CMAKE_BINARY_DIR}/usr/${_Gears_TARGET}.dir")
|
58
|
47 list(APPEND _Gears_CSOURCES ${j})
|
|
48 endif()
|
|
49 endforeach(i)
|
|
50
|
|
51 add_custom_command (
|
71
|
52 OUTPUT ${_Gears_TARGET}.dir/c/${_Gears_TARGET}-context.c
|
58
|
53 DEPENDS ${_Gears_CBC_SOURCES}
|
71
|
54 COMMAND "cd" "${_Gears_TARGET}.dir" ";" "perl" "${CMAKE_SOURCE_DIR}/gearsTools/generate_context.pl" "-o" ${_Gears_TARGET} ${CMAKE_SOURCE_DIR}/usr/${_Gears_CSOURCES}
|
58
|
55 )
|
71
|
56 add_executable(${_Gears_TARGET} ${_Gears_CBC_SOURCES} ${_Gears_CSOURCES} ${_Gears_TARGET}.dir/c/${_Gears_TARGET}-context.c )
|
58
|
57 target_link_libraries(${_Gears_TARGET} ulib)
|
|
58 endmacro()
|
|
59
|
59
|
60 add_library(ulib STATIC ulib.c usys.S printf.c umalloc.c)
|
61
|
61 #add_library(syslib string.c)
|
58
|
62
|
62
|
63 set(USR_COMMANDS cat echo grep init kill ln ls mkdir rm sh stressfs usertests wc zombie hello)
|
58
|
64
|
59
|
65 foreach(cmd ${USR_COMMANDS})
|
|
66 GearsCommand (TARGET _${cmd} SOURCES ${cmd}.c)
|
|
67 endforeach(cmd)
|
58
|
68
|
63
|
69 set(_USR_COMMANDS)
|
|
70 foreach (i ${USR_COMMANDS})
|
|
71 list(APPEND _USR_COMMANDS "_${i}")
|
|
72 endforeach(i)
|
|
73
|
72
|
74
|
|
75 file(COPY "${CMAKE_SOURCE_DIR}/usr/UNIX" DESTINATION "${CMAKE_BINARY_DIR}/usr")
|
|
76
|
63
|
77 add_custom_target(fs.img ALL
|
72
|
78 COMMAND ${CMAKE_BINARY_DIR}/tools/mkfs fs.img ${_USR_COMMANDS} UNIX \; cp fs.img ${CMAKE_BINARY_DIR}
|
64
|
79 DEPENDS ${_USR_COMMANDS} mkfs
|
58
|
80 )
|