view src/usr/CMakeLists.txt @ 111:239bd73abac6

add gen context.h at generate_context.pl
author anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
date Thu, 28 Nov 2019 12:17:05 +0900
parents 0956648d24e5
children 124c59d99fc9
line wrap: on
line source

cmake_minimum_required(VERSION 3.8)
set(CMAKE_C_COMPILER "/usr/bin/cc")
project(usr C ASM)

if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
  set(CMAKE_SYSROOT "${CBC_XV6_SYSROOT}")
  set(CMAKE_OSX_SYSROOT "${CBC_XV6_SYSROOT}")
  include_directories("${CMAKE_OSX_SYSROOT}")
  include_directories(SYSTEM "${CMAKE_OSX_SYSROOT}/usr/include")
  include_directories(SYSTEM "${CMAKE_OSX_SYSROOT}/usr/include/arm-linux-gnueabihf")
  set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
  set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
  set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
  set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
endif()


set(CMAKE_C_FLAGS_DEBUG "-O0")
add_definitions(${PMAKE_ARGS})
set(CMAKE_C_COMPILER "${CBC_COM}")
set(CMAKE_ASM_COMPILER "${CBC_COM}")

#include_directories("..")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ")
set(CMAKE_C_LINK_EXECUTABLE "${KERNEL_LINK_EXECUTABLE}")
set(CMAKE_EXE_LINKER_FLAGS  "${CMAKE_EXE_LINKER_FLAGS} ${GCC_LIB} -nostdlib")


macro( GearsCommand )
    include_directories(${CMAKE_SOURCE_DIR})
    include_directories(${CMAKE_SOURCE_DIR}/usr)
    include_directories(${CMAKE_BINARY_DIR}/usr/c)
  
    set( _OPTIONS_ARGS )
    set( _ONE_VALUE_ARGS TARGET )
    set( _MULTI_VALUE_ARGS SOURCES )
    cmake_parse_arguments( _Gears "${_OPTIONS_ARGS}" "${_ONE_VALUE_ARGS}" "${_MULTI_VALUE_ARGS}" ${ARGN} )

    set (_Gears_CBC_SOURCES)
    set (_Gears_CSOURCES)
    foreach(i ${_Gears_SOURCES})
        if (${i} MATCHES "\\.cbc")
            string(REGEX REPLACE "(.*).cbc" "c/\\1.c" j ${i})
            add_custom_command (
                OUTPUT    ${j}
                DEPENDS   ${i}
                COMMAND  "perl" "${CMAKE_SOURCE_DIR}/gearsTools/generate_stub.pl" "-o" ${j} ${i}
            )
            list(APPEND _Gears_CBC_SOURCES ${j})
        elseif (${i} MATCHES "\\.cu")
            string(REGEX REPLACE "(.*).cu" "c/\\1.ptx" j ${i})
            add_custom_command (
                OUTPUT    ${j}
                DEPENDS   ${i}
                COMMAND  nvcc ${NVCCFLAG} -c -ptx -o ${j} ${i}
            )
            list(APPEND _Gears_CBC_SOURCES ${j})
        else()
            set(j ${i})
            file(COPY "${CMAKE_SOURCE_DIR}/context.h" DESTINATION "${CMAKE_BINARY_DIR}/usr/${_Gears_TARGET}.dir")
            list(APPEND _Gears_CSOURCES ${j})
        endif()
    endforeach(i)

    add_custom_command (
          OUTPUT    ${_Gears_TARGET}.dir/c/${_Gears_TARGET}-context.c
          DEPENDS   ${_Gears_CBC_SOURCES}
          COMMAND  "cd" "${_Gears_TARGET}.dir" ";" "perl" "${CMAKE_SOURCE_DIR}/gearsTools/generate_context.pl" "-o" ${_Gears_TARGET} "-w" ${CMAKE_SOURCE_DIR}/usr/${_Gears_CSOURCES}
    )
    add_executable(${_Gears_TARGET} ${_Gears_CBC_SOURCES} ${_Gears_CSOURCES} ${_Gears_TARGET}.dir/c/${_Gears_TARGET}-context.c )
    target_link_libraries(${_Gears_TARGET} ulib)
endmacro()

add_library(ulib STATIC  ulib.c usys.S printf.c umalloc.c)
#add_library(syslib string.c)

# set(USR_COMMANDS cat echo grep init kill ln ls mkdir rm sh stressfs usertests wc zombie hello)
set(USR_COMMANDS cat echo grep init kill ln ls mkdir rm sh hello)

foreach(cmd ${USR_COMMANDS}) 
    GearsCommand (TARGET _${cmd} SOURCES ${cmd}.c) 
endforeach(cmd)

set(_USR_COMMANDS)
foreach (i ${USR_COMMANDS})
  list(APPEND _USR_COMMANDS "_${i}")
endforeach(i)


file(COPY "${CMAKE_SOURCE_DIR}/usr/UNIX" DESTINATION "${CMAKE_BINARY_DIR}/usr")

add_custom_target(fs.img ALL
  COMMAND ${CMAKE_BINARY_DIR}/tools/mkfs fs.img ${_USR_COMMANDS} UNIX \; cp fs.img ${CMAKE_BINARY_DIR}
  DEPENDS ${_USR_COMMANDS} mkfs
)