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})
|
86
|
46 file(COPY "${CMAKE_SOURCE_DIR}/origin-context.h" DESTINATION "${CMAKE_BINARY_DIR}/usr/${_Gears_TARGET}.dir")
|
|
47 file(RENAME "${CMAKE_BINARY_DIR}/usr/${_Gears_TARGET}.dir/origin-context.h" "${CMAKE_BINARY_DIR}/usr/${_Gears_TARGET}.dir/context.h")
|
58
|
48 list(APPEND _Gears_CSOURCES ${j})
|
|
49 endif()
|
|
50 endforeach(i)
|
|
51
|
|
52 add_custom_command (
|
71
|
53 OUTPUT ${_Gears_TARGET}.dir/c/${_Gears_TARGET}-context.c
|
58
|
54 DEPENDS ${_Gears_CBC_SOURCES}
|
71
|
55 COMMAND "cd" "${_Gears_TARGET}.dir" ";" "perl" "${CMAKE_SOURCE_DIR}/gearsTools/generate_context.pl" "-o" ${_Gears_TARGET} ${CMAKE_SOURCE_DIR}/usr/${_Gears_CSOURCES}
|
58
|
56 )
|
71
|
57 add_executable(${_Gears_TARGET} ${_Gears_CBC_SOURCES} ${_Gears_CSOURCES} ${_Gears_TARGET}.dir/c/${_Gears_TARGET}-context.c )
|
58
|
58 target_link_libraries(${_Gears_TARGET} ulib)
|
|
59 endmacro()
|
|
60
|
59
|
61 add_library(ulib STATIC ulib.c usys.S printf.c umalloc.c)
|
61
|
62 #add_library(syslib string.c)
|
58
|
63
|
75
|
64 # set(USR_COMMANDS cat echo grep init kill ln ls mkdir rm sh stressfs usertests wc zombie hello)
|
|
65 set(USR_COMMANDS cat echo grep init kill ln ls mkdir rm sh hello)
|
58
|
66
|
59
|
67 foreach(cmd ${USR_COMMANDS})
|
|
68 GearsCommand (TARGET _${cmd} SOURCES ${cmd}.c)
|
|
69 endforeach(cmd)
|
58
|
70
|
63
|
71 set(_USR_COMMANDS)
|
|
72 foreach (i ${USR_COMMANDS})
|
|
73 list(APPEND _USR_COMMANDS "_${i}")
|
|
74 endforeach(i)
|
|
75
|
72
|
76
|
|
77 file(COPY "${CMAKE_SOURCE_DIR}/usr/UNIX" DESTINATION "${CMAKE_BINARY_DIR}/usr")
|
|
78
|
63
|
79 add_custom_target(fs.img ALL
|
72
|
80 COMMAND ${CMAKE_BINARY_DIR}/tools/mkfs fs.img ${_USR_COMMANDS} UNIX \; cp fs.img ${CMAKE_BINARY_DIR}
|
64
|
81 DEPENDS ${_USR_COMMANDS} mkfs
|
58
|
82 )
|