├── auto ├── make_define ├── define ├── have ├── init ├── os │ ├── linux │ ├── darwin │ ├── nt │ └── conf ├── include ├── cc │ ├── version │ ├── name │ ├── gcc │ ├── clang │ ├── msvc │ └── conf ├── symbol ├── summary ├── install ├── configure ├── feature ├── options ├── check └── make ├── .gitignore ├── .github └── workflows │ └── ci.yml ├── test.sh ├── bootstrap.sh ├── README.org └── LICENSE /auto/make_define: -------------------------------------------------------------------------------- 1 | #### -*- mode:sh -*- vim:ft=sh 2 | #### 3 | ## No More than a C build system for clang, gcc and msvc. 4 | ## https://github.com/junjiemars/nore 5 | #### 6 | ## make_define 7 | #### 8 | 9 | op=${op:-"="} 10 | 11 | 12 | cat << END >> $NM_MAKEFILE 13 | 14 | $flag $op $value 15 | 16 | END 17 | -------------------------------------------------------------------------------- /auto/define: -------------------------------------------------------------------------------- 1 | #### -*- mode:sh -*- vim:ft=sh 2 | #### 3 | ## No More than a C build system for clang, gcc and msvc. 4 | ## https://github.com/junjiemars/nore 5 | #### 6 | ## define 7 | #### 8 | 9 | have="`symbol_value $have`" 10 | 11 | cat << END >> $NM_AUTO_H 12 | 13 | #ifndef $have 14 | #define $have $value 15 | #endif 16 | 17 | END 18 | -------------------------------------------------------------------------------- /auto/have: -------------------------------------------------------------------------------- 1 | #### -*- mode:sh -*- vim:ft=sh 2 | #### 3 | ## No More than a C build system for clang, gcc and msvc. 4 | ## https://github.com/junjiemars/nore 5 | #### 6 | ## have 7 | #### 8 | 9 | have=`echo $have | tr [:lower:] [:upper:]` 10 | 11 | have="`symbol_value $have`" 12 | 13 | cat << END >> $NM_AUTO_H 14 | 15 | #ifndef $have 16 | #define $have 1 17 | #endif 18 | 19 | END 20 | -------------------------------------------------------------------------------- /auto/init: -------------------------------------------------------------------------------- 1 | #### -*- mode:sh -*- vim:ft=sh 2 | #### 3 | ## No More than a C build system for clang, gcc and msvc. 4 | ## https://github.com/junjiemars/nore 5 | #### 6 | ## init 7 | #### 8 | 9 | 10 | NM_AUTO_H="$NM_OUT/nore.h" 11 | NM_AUTOTEST="$NM_OUT/autotest" 12 | NM_AUTO_ERR="$NM_OUT/auto.err" 13 | NM_MAKEFILE="$NM_OUT/Makefile" 14 | 15 | 16 | test -d $NM_OUT || mkdir -p $NM_OUT 17 | 18 | echo > $NM_AUTO_ERR 19 | 20 | # eof 21 | -------------------------------------------------------------------------------- /auto/os/linux: -------------------------------------------------------------------------------- 1 | #### -*- mode:sh -*- vim:ft=sh 2 | #------------------------------------------------ 3 | # target: os/linux for Linux OS 4 | # url: https://github.com/junjiemars/nore.git 5 | # author: Junjie Mars 6 | #------------------------------------------------ 7 | 8 | # lib 9 | nm_shared_opt="-shared" 10 | lib_ext=".so" 11 | 12 | have=$NM_SYSTEM . ${NORE_ROOT}/auto/have 13 | 14 | # os specifics for Linux 15 | 16 | 17 | # eof 18 | -------------------------------------------------------------------------------- /auto/os/darwin: -------------------------------------------------------------------------------- 1 | #### -*- mode:sh -*- vim:ft=sh 2 | #------------------------------------------------ 3 | # target: os/darwin for Darwin OS 4 | # url: https://github.com/junjiemars/nore.git 5 | # author: Junjie Mars 6 | #------------------------------------------------ 7 | 8 | # lib 9 | nm_shared_opt="-dynamiclib" 10 | lib_ext=".dylib" 11 | 12 | 13 | have=$NM_SYSTEM . ${NORE_ROOT}/auto/have 14 | 15 | # os specifics for Darwin 16 | 17 | 18 | # eof 19 | -------------------------------------------------------------------------------- /auto/include: -------------------------------------------------------------------------------- 1 | #### -*- mode:sh -*- vim:ft=sh 2 | #### 3 | ## No More than a C build system for clang, gcc and msvc. 4 | ## https://github.com/junjiemars/nore 5 | #### 6 | ## include 7 | #### 8 | 9 | 10 | nm_feature="$include" 11 | nm_feature_name="nm_have_`echo $include | tr . _`" 12 | nm_feature_run=value 13 | nm_feature_h="#include <$include>" 14 | nm_feature_flags= 15 | nm_feature_test= 16 | 17 | . ${NORE_ROOT}/auto/feature 18 | 19 | 20 | # eof 21 | -------------------------------------------------------------------------------- /auto/os/nt: -------------------------------------------------------------------------------- 1 | #### -*- mode:sh -*- vim:ft=sh 2 | #------------------------------------------------ 3 | # target: os/nt for WinNT OS 4 | # url: https://github.com/junjiemars/nore.git 5 | # author: Junjie Mars 6 | #------------------------------------------------ 7 | 8 | # lib 9 | nm_shared_opt="-LD" 10 | lib_ext=".dll" 11 | 12 | 13 | have=$NM_SYSTEM . ${NORE_ROOT}/auto/have 14 | 15 | nm_path_sep="\;" 16 | 17 | # os specifics for Windows 18 | 19 | 20 | 21 | # eof 22 | -------------------------------------------------------------------------------- /auto/os/conf: -------------------------------------------------------------------------------- 1 | #### -*- mode:sh -*- vim:ft=sh 2 | #------------------------------------------------ 3 | # target: os/conf for OS 4 | # url: https://github.com/junjiemars/nore.git 5 | # author: Junjie Mars 6 | #------------------------------------------------ 7 | 8 | # echo "checking for $NM_PLATFORM specific features" 9 | 10 | case "$NM_SYSTEM" in 11 | Linux) . ${NORE_ROOT}/auto/os/linux ;; 12 | Darwin) . ${NORE_ROOT}/auto/os/darwin ;; 13 | WinNT) . ${NORE_ROOT}/auto/os/nt ;; 14 | esac 15 | 16 | 17 | # eof 18 | -------------------------------------------------------------------------------- /auto/cc/version: -------------------------------------------------------------------------------- 1 | #### -*- mode:sh -*- vim:ft=sh 2 | #------------------------------------------------ 3 | # target: cc/version for compiler's version 4 | # url: https://github.com/junjiemars/nore.git 5 | # author: Junjie Mars 6 | #------------------------------------------------ 7 | 8 | version_n () { 9 | local v1="`echo $1 | cut -d'.' -f1 2>/dev/null`" 10 | local v2="`echo $1 | cut -d'.' -f2 2>/dev/null`" 11 | local v3="`echo $1 | cut -d'.' -f3 2>/dev/null`" 12 | local n=0 13 | if [ -n "$v1" ]; then 14 | n=$(( v1*10000 )) 15 | fi 16 | if [ -n "$v2" ]; then 17 | n=$(( n+v2*100 )) 18 | fi 19 | if [ -n "$3" ]; then 20 | v3=`echo $v3 | sed -e 's/^\([0-9]*\).*/\1/'` 21 | n=$(( n+v3 )) 22 | fi 23 | echo $n 24 | } 25 | 26 | # eof 27 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Xcode project files 2 | 21st_c.xcodeproj/xcuserdata 3 | 21st_c.xcodeproj/project.xcworkspace 4 | 5 | # Object files 6 | *.o 7 | *.ko 8 | *.obj 9 | *.elf 10 | 11 | # Precompiled Headers 12 | *.gch 13 | *.pch 14 | 15 | # Libraries 16 | *.lib 17 | *.a 18 | *.la 19 | *.lo 20 | 21 | # Shared objects (inc. Windows DLLs) 22 | *.dll 23 | *.so 24 | *.so.* 25 | *.dylib 26 | 27 | # Executables 28 | *.exe 29 | *.out 30 | *.app 31 | *.i*86 32 | *.x86_64 33 | *.hex 34 | erf 35 | *.dSYM/ 36 | *.i 37 | *.dylib 38 | *.pdb 39 | 40 | # objs directory 41 | objs/ 42 | 43 | # makefiles 44 | /Makefile 45 | objs/Makefile 46 | 47 | # editor swap files 48 | *.swp 49 | 50 | # vscode files 51 | .vscode/ 52 | /TAGS 53 | 54 | # org mode export 55 | *.html 56 | *.odt 57 | .~*# 58 | 59 | # nore 60 | build/ 61 | configure 62 | out/ 63 | src/ 64 | ci/ -------------------------------------------------------------------------------- /auto/symbol: -------------------------------------------------------------------------------- 1 | #### -*- mode:sh -*- vim:ft=sh 2 | #### 3 | ## No More than a C build system for clang, gcc and msvc. 4 | ## https://github.com/junjiemars/nore 5 | #### 6 | ## symbol 7 | #### 8 | 9 | symbol_table="\ 10 | WINNT:WINNT 11 | LINUX:LINUX 12 | DARWIN:DARWIN 13 | MSVC:MSVC 14 | GCC:GCC 15 | CLANG:CLANG 16 | CC_NAME:CC_NAME 17 | CC_VER:CC_VER 18 | NM_SYSTEM:NM_SYSTEM 19 | NM_RELEASE:NM_RELEASE 20 | NM_MACHINE:NM_MACHINE 21 | NM_PREFIX:NM_PREFIX 22 | NM_COMPILER:NM_COMPILER 23 | NM_CPU_CACHE_LINE:NM_CPU_CACHE_LINE 24 | NM_CPU_LITTLE_ENDIAN:NM_CPU_LITTLE_ENDIAN" 25 | 26 | 27 | load_symbol_table () { 28 | symbol_table="`cat $1`" 29 | } 30 | 31 | dump_symbol_table () { 32 | echo "$symbol_table" > "$1" 33 | } 34 | 35 | symbol_value () { 36 | local v=`echo "$symbol_table" | sed -n "s/$1:\(.*\)$/\1/p"` 37 | if [ -n "$v" ]; then 38 | echo "$v" 39 | else 40 | echo "$1" 41 | fi 42 | } 43 | 44 | 45 | # eof 46 | -------------------------------------------------------------------------------- /auto/summary: -------------------------------------------------------------------------------- 1 | #### -*- mode:sh -*- vim:ft=sh 2 | #### 3 | ## No More than a C build system for clang, gcc and msvc. 4 | ## https://github.com/junjiemars/nore 5 | #### 6 | ## summary 7 | #### 8 | 9 | 10 | yes_no_any_out () { 11 | local opt="$1" 12 | local any="$2" 13 | case "$opt" in 14 | YES|NO) echo "${opt}${any:+: $any}" ;; 15 | *) echo "$opt" ;; 16 | esac 17 | } 18 | 19 | 20 | echo "Configuration summary" 21 | 22 | cat << END 23 | platform: $NM_PLATFORM 24 | compiler: $NM_COMPILER 25 | symbol-table= $NM_SYMBOL_FILE 26 | prefix= $NM_PREFIX 27 | out= $NM_OUT 28 | src= $NM_SRC 29 | has= ${NM_HAS_STICKS} 30 | new= $NM_NEW 31 | error= `yes_no_any_out "$NM_ERROR" "$nm_error_opt"` 32 | warn= `yes_no_any_out "$NM_WARN" "$nm_warn_opt"` 33 | verbose= `yes_no_any_out "$NM_VERBOSE" "$nm_verbose_opt"` 34 | release= `yes_no_any_out "$NM_BUILD" "$nm_build_opt"` 35 | symbol= `yes_no_any_out "$NM_SYMBOL" "$nm_symbol_opt"` 36 | arch= `yes_no_any_out "$NM_ARCH" "$nm_arch_opt"` 37 | std= `yes_no_any_out "$NM_STD" "$nm_std_opt"` 38 | optimize= `yes_no_any_out "$NM_OPTIMIZE" "$nm_optimize_opt"` 39 | END 40 | 41 | # eof 42 | -------------------------------------------------------------------------------- /auto/install: -------------------------------------------------------------------------------- 1 | #### -*- mode:sh -*- vim:ft=sh 2 | #### 3 | ## No More than a C build system for clang, gcc and msvc. 4 | ## https://github.com/junjiemars/nore 5 | #### 6 | ## install 7 | #### 8 | 9 | 10 | NM_BIN_PATH="${NM_PREFIX}/${NM_BIN_PATH}" 11 | NM_ETC_PATH="${NM_PREFIX}/${NM_ETC_PATH}" 12 | NM_INC_PATH="${NM_PREFIX}/${NM_INC_PATH}" 13 | NM_LIB_PATH="${NM_PREFIX}/${NM_LIB_PATH}" 14 | NM_VAR_PATH="${NM_PREFIX}/${NM_VAR_PATH}" 15 | 16 | 17 | # append install target 18 | 19 | cat << END >> $NM_MAKEFILE 20 | 21 | install: all $NM_BIN_PATH $NM_ETC_PATH $NM_INC_PATH $NM_LIB_PATH 22 | \$(call cp-if, $NM_OUT/bin, $NM_BIN_PATH/) 23 | \$(call cp-if, $NM_OUT/etc, $NM_ETC_PATH/) 24 | \$(call cp-if, $NM_OUT/inc, $NM_INC_PATH/) 25 | \$(call cp-if, $NM_OUT/lib, $NM_LIB_PATH/) 26 | 27 | $NM_BIN_PATH $NM_ETC_PATH $NM_INC_PATH $NM_LIB_PATH: 28 | \$(call mkdir-if, $NM_BIN_PATH) 29 | \$(call mkdir-if, $NM_ETC_PATH) 30 | \$(call mkdir-if, $NM_INC_PATH) 31 | \$(call mkdir-if, $NM_LIB_PATH) 32 | \$(call mkdir-if, $NM_VAR_PATH) 33 | 34 | 35 | mkdir-if = \$(if \$(wildcard \$1),,mkdir -p \$1) 36 | cp-if = \$(foreach f,\$(wildcard \$1/*),\$(shell cp -r \$(f) \$2)) 37 | 38 | END 39 | 40 | 41 | # eof 42 | -------------------------------------------------------------------------------- /auto/cc/name: -------------------------------------------------------------------------------- 1 | #### -*- mode:sh -*- vim:ft=sh 2 | #------------------------------------------------ 3 | # target: cc/name for compiler's name 4 | # url: https://github.com/junjiemars/nore.git 5 | # author: Junjie Mars 6 | #------------------------------------------------ 7 | 8 | printf "checking for C compiler ... " 9 | 10 | nm_feature="C compiler" 11 | nm_feature_name= 12 | nm_feature_run=dumb 13 | nm_feature_h= 14 | nm_feature_flags= 15 | nm_feature_test= 16 | . ${NORE_ROOT}/auto/feature 17 | 18 | if [ ".no" = ".$nm_found" ]; then 19 | printf "${nm_found}\n" 20 | exit 1 21 | else 22 | printf "${nm_found}\n" 23 | fi 24 | 25 | 26 | nm_feature="C++ compiler" 27 | nm_feature_name="CXX" 28 | nm_feature_run=dumb 29 | nm_feature_h="#include " 30 | nm_feature_flags= 31 | nm_feature_value= 32 | nm_feature_test="std::cout << \"$CC\n\";" 33 | . ${NORE_ROOT}/auto/feature 34 | 35 | cc_or_cxx="C" 36 | if [ ".yes" = ".$nm_found" ]; then 37 | CXX=$nm_feature_value 38 | cc_or_cxx="C/C++" 39 | fi 40 | 41 | 42 | if `$CC -v 2>&1 | grep 'gcc version' >/dev/null 2>&1`; then 43 | CC_NAME=gcc 44 | echo " + using GNU ${cc_or_cxx} compiler" 45 | 46 | elif `$CC -v 2>&1 | grep '\(clang\|LLVM\) version' >/dev/null 2>&1`; then 47 | CC_NAME=clang 48 | echo " + using Clang ${cc_or_cxx} compiler" 49 | 50 | elif `$CC 2>&1 | grep 'Microsoft .* C\/C++' >/dev/null 2>&1`; then 51 | CC_NAME=msvc 52 | echo " + using Microsoft ${cc_or_cxx} compiler" 53 | 54 | else 55 | CC_NAME=unknown 56 | fi 57 | 58 | # eof 59 | -------------------------------------------------------------------------------- /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: Nore 2 | 3 | on: 4 | pull_request: 5 | branches: 6 | - edge 7 | push: 8 | branches: 9 | - edge 10 | 11 | jobs: 12 | 13 | Linux: 14 | runs-on: ubuntu-latest 15 | strategy: 16 | matrix: 17 | include: 18 | - CC: "gcc" 19 | - CC: "clang" 20 | steps: 21 | - uses: actions/checkout@v4 22 | with: 23 | fetch-depth: 1 # checkout history and tags 24 | - name: Install Dependencies 25 | run: | 26 | sudo apt-get update 27 | sudo apt-get install clang 28 | - name: Test Nore via CC=${{ matrix.CC }} 29 | env: 30 | _INSIDE_CI_: github 31 | run: | 32 | CC=${{ matrix.CC }} ./test.sh 33 | 34 | MacOS: 35 | runs-on: macos-latest 36 | strategy: 37 | matrix: 38 | include: 39 | - CC: "clang" 40 | - CC: "gcc" 41 | steps: 42 | - uses: actions/checkout@v4 43 | with: 44 | fetch-depth: 1 # checkout history and tags 45 | - name: Test Nore via CC=${{ matrix.CC }} 46 | env: 47 | _INSIDE_CI_: github 48 | run: | 49 | CC=${{ matrix.CC }} ./test.sh 50 | 51 | Windows: 52 | runs-on: windows-latest 53 | strategy: 54 | matrix: 55 | include: 56 | - CC: "cl" 57 | - CC: "gcc" 58 | defaults: 59 | run: 60 | shell: msys2 {0} 61 | steps: 62 | - uses: actions/checkout@v4 63 | with: 64 | fetch-depth: 1 # checkout history and tags 65 | - name: Install Dependencies 66 | uses: msys2/setup-msys2@v2 67 | with: 68 | update: true 69 | install: >- 70 | git 71 | make 72 | mingw-w64-x86_64-gcc 73 | - name: Test Nore via CC=${{ matrix.CC }} 74 | env: 75 | _INSIDE_CI_: github 76 | run: | 77 | CC=${{ matrix.CC }} ./test.sh 78 | 79 | 80 | # eof 81 | -------------------------------------------------------------------------------- /auto/configure: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | #------------------------------------------------ 3 | # target: configuration script of Nore 4 | # url: https://github.com/junjiemars/nore.git 5 | # author: Junjie Mars 6 | #------------------------------------------------ 7 | 8 | LC_ALL=C 9 | export LC_ALL 10 | 11 | NORE_ROOT="$(dirname `dirname $0`)" 12 | NORE_ROOT="${NORE_ROOT%/}" 13 | 14 | . ${NORE_ROOT}/auto/options 15 | . ${NORE_ROOT}/auto/init 16 | 17 | 18 | cat << END > $NM_AUTO_H 19 | /* ${NM_AUTO_H} 20 | * 21 | * ${gen_by_nore} 22 | * 23 | */ 24 | 25 | #ifndef NORE_H 26 | #define NORE_H 27 | 28 | #define NM_CONFIGURE "$NM_CONFIGURE" 29 | END 30 | 31 | 32 | . ${NORE_ROOT}/auto/symbol 33 | if [ -n "$NM_SYMBOL_FILE" ]; then 34 | if [ -f "$NM_SYMBOL_FILE" ]; then 35 | load_symbol_table "$NM_SYMBOL_FILE" 36 | else 37 | dump_symbol_table "$NM_SYMBOL_FILE" 38 | fi 39 | fi 40 | 41 | 42 | if [ -z "$NM_PLATFORM" ]; then 43 | echo "checking for OS" 44 | 45 | NM_SYSTEM=`uname -s 2>/dev/null` 46 | NM_RELEASE=`uname -r 2>/dev/null` 47 | NM_MACHINE=`uname -m 2>/dev/null` 48 | 49 | echo " + $NM_SYSTEM $NM_RELEASE $NM_MACHINE" 50 | 51 | case $NM_SYSTEM in 52 | MSYS_NT-*) 53 | NM_RELEASE=${NM_SYSTEM:8} 54 | NM_SYSTEM=WinNT 55 | ;; 56 | MINGW??_NT-*) 57 | NM_RELEASE=${NM_SYSTEM:11} 58 | NM_SYSTEM=WinNT 59 | ;; 60 | esac 61 | 62 | NM_PLATFORM="$NM_SYSTEM-$NM_RELEASE-$NM_MACHINE"; 63 | 64 | else 65 | echo "building for $NM_PLATFORM" 66 | NM_SYSTEM=$NM_PLATFORM 67 | fi 68 | 69 | 70 | . ${NORE_ROOT}/auto/cc/conf 71 | . ${NORE_ROOT}/auto/os/conf 72 | 73 | 74 | if [ -z "$NM_PREFIX" ]; then 75 | case "$NM_SYSTEM" in 76 | Linux) NM_PREFIX="/usr/local" ;; 77 | Darwin) NM_PREFIX="/opt/local" ;; 78 | WinNT|*) NM_PREFIX="dist" ;; 79 | esac 80 | fi 81 | have=NM_PREFIX value="${NM_PREFIX%/}" . ${NORE_ROOT}/auto/define 82 | 83 | 84 | . ${NORE_ROOT}/auto/make 85 | 86 | if [ -f "$NM_AUTO_H" ]; then 87 | cat << END >> $NM_AUTO_H 88 | #endif /* end of NORE_H */ 89 | END 90 | fi 91 | 92 | . ${NORE_ROOT}/auto/summary 93 | 94 | # eof 95 | -------------------------------------------------------------------------------- /auto/cc/gcc: -------------------------------------------------------------------------------- 1 | #### -*- mode:sh -*- vim:ft=sh 2 | #------------------------------------------------ 3 | # target: cc/gcc for gcc compiler 4 | # url: https://github.com/junjiemars/nore.git 5 | # author: Junjie Mars 6 | #------------------------------------------------ 7 | 8 | nm_gcc_ver=`$CC -v 2>&1 | grep 'gcc version' 2>&1 \ 9 | | sed -e 's/^.* version \(.*\)/\1/'` 10 | 11 | echo " + gcc version: $nm_gcc_ver" 12 | 13 | NM_COMPILER="gcc $nm_gcc_ver" 14 | have=NM_COMPILER value="\"$NM_COMPILER\"" . ${NORE_ROOT}/auto/define 15 | 16 | . ${NORE_ROOT}/auto/cc/version 17 | CC_VER=`version_n $(echo $nm_gcc_ver | cut -d' ' -f1)` 18 | have=GCC value=$CC_VER . ${NORE_ROOT}/auto/define 19 | 20 | 21 | # compiler 22 | [ "." = ".$CC" ] && CC="cc" 23 | 24 | # preprocessor 25 | [ "." = ".$CPP" ] && CPP="\$(CC)" 26 | 27 | # assembler 28 | [ "." = ".$AS" ] && AS="as" 29 | 30 | # linker 31 | [ "." = ".$LD" ] && LD="ld" 32 | 33 | # archiver 34 | [ "." = ".$AR" ] && AR="ar" 35 | 36 | 37 | # stage 38 | nm_stage_pre="-E" 39 | nm_stage_chk= 40 | nm_stage_asm="-S" 41 | nm_stage_c="-c" 42 | 43 | 44 | # error 45 | case "$NM_ERROR" in 46 | NO) nm_error_opt="" ;; 47 | YES) nm_error_opt="-Werror" ;; 48 | esac 49 | 50 | # warning 51 | case "$NM_WARN" in 52 | NO) nm_warn_opt="" ;; 53 | YES) nm_warn_opt="-Wall -Wextra" ;; 54 | *) nm_warn_opt="$NM_WARN" ;; 55 | esac 56 | 57 | # verbose 58 | case "$NM_VERBOSE" in 59 | NO) nm_verbose_opt="" ;; 60 | YES) nm_verbose_opt="-v" ;; 61 | esac 62 | 63 | # symbol 64 | case "$NM_SYMBOL" in 65 | NO) nm_symbol_opt="" ;; 66 | YES) nm_symbol_opt="-g3" ;; 67 | *) nm_symbol_opt="$NM_SYMBOL" ;; 68 | esac 69 | 70 | # arch 71 | case "$NM_ARCH" in 72 | NO) ;; 73 | YES) nm_arch_opt="-march=native" ;; 74 | *) nm_arch_opt="$NM_ARCH" ;; 75 | esac 76 | 77 | # std 78 | case "$NM_STD" in 79 | NO) nm_std_opt="" ;; 80 | YES) 81 | if [ "$CXX" = "$CC" ]; then 82 | nm_std_opt="" 83 | else 84 | nm_std_opt="-std=c11" 85 | fi 86 | ;; 87 | *) nm_std_opt="${NM_STD}" ;; 88 | esac 89 | 90 | # optimization 91 | case "$NM_OPTIMIZE" in 92 | NO) nm_optimize_opt="-O0" ;; 93 | YES) nm_optimize_opt="-O2" ;; 94 | *) nm_optimize_opt="$NM_OPTIMIZE" ;; 95 | esac 96 | 97 | # trigraphs 98 | nm_trigraphs_opt="-Wno-trigraphs" 99 | 100 | # openmp 101 | nm_openmp_opt="-fopenmp" 102 | 103 | # lib 104 | nm_lib_opt="-l" 105 | nm_libdir_opt="-L" 106 | nm_static_opt="-static" 107 | 108 | # link option 109 | LDFLAGS="${nm_libdir_opt}${NM_OUT}/lib${LDFLAGS:+ $LDFLAGS}" 110 | 111 | # eof 112 | -------------------------------------------------------------------------------- /auto/cc/clang: -------------------------------------------------------------------------------- 1 | #### -*- mode:sh -*- vim:ft=sh 2 | #------------------------------------------------ 3 | # target: cc/clang for clang compiler 4 | # url: https://github.com/junjiemars/nore.git 5 | # author: Junjie Mars 6 | #------------------------------------------------ 7 | 8 | nm_clang_ver=`$CC -v 2>&1 | grep '\(clang\|LLVM\) version' 2>&1 \ 9 | | sed -e 's/^.* version \(.*\)/\1/'` 10 | 11 | echo " + clang version: $nm_clang_ver" 12 | 13 | NM_COMPILER="clang $nm_clang_ver" 14 | have=NM_COMPILER value="\"$NM_COMPILER\"" . ${NORE_ROOT}/auto/define 15 | 16 | . ${NORE_ROOT}/auto/cc/version 17 | CC_VER=`version_n $(echo $nm_clang_ver | cut -d' ' -f1)` 18 | have=CLANG value=$CC_VER . ${NORE_ROOT}/auto/define 19 | 20 | 21 | # compiler 22 | [ "." = ".$CC" ] && CC="cc" 23 | 24 | # preprocess 25 | [ "." = ".$CPP" ] && CPP="\$(CC)" 26 | 27 | # assembler 28 | [ "." = ".$AS" ] && AS="as" 29 | 30 | # linker 31 | [ "." = ".$LD" ] && LD="ld" 32 | 33 | # archive 34 | [ "." = ".$AR" ] && AR="ar" 35 | 36 | 37 | # stage 38 | nm_stage_pre="-E" 39 | nm_stage_chk="-fsyntax-only" 40 | nm_stage_asm="-S" 41 | nm_stage_c="-c" 42 | 43 | 44 | # error 45 | case "$NM_ERROR" in 46 | NO) nm_error_opt="" ;; 47 | YES) nm_error_opt="-Werror" ;; 48 | esac 49 | 50 | # warnings (-Weverything) 51 | case "$NM_WARN" in 52 | NO) nm_warn_opt="" ;; 53 | YES) nm_warn_opt="-Wall -Wextra" ;; 54 | *) nm_warn_opt="$NM_WARN" ;; 55 | esac 56 | 57 | # verbose 58 | case "$NM_VERBOSE" in 59 | NO) nm_verbose_opt="" ;; 60 | YES) nm_verbose_opt="-v" ;; 61 | esac 62 | 63 | # symbol 64 | case "$NM_SYMBOL" in 65 | NO) nm_symbol_opt="" ;; 66 | YES) nm_symbol_opt="-g" ;; 67 | *) nm_symbol_opt="$NM_SYMBOL" ;; 68 | esac 69 | 70 | # arch 71 | case "$NM_ARCH" in 72 | NO) nm_arch_opt="" ;; 73 | YES) nm_arch_opt="-march=native" ;; 74 | *) nm_arch_opt="$NM_ARCH" ;; 75 | esac 76 | 77 | # std 78 | case "$NM_STD" in 79 | NO) nm_std_opt="" ;; 80 | YES) 81 | if [ "$CXX" = "$CC" ]; then 82 | nm_std_opt="" 83 | else 84 | nm_std_opt="-std=c11" 85 | fi 86 | ;; 87 | *) nm_std_opt="${NM_STD}" ;; 88 | esac 89 | 90 | # optimizations 91 | case "$NM_OPTIMIZE" in 92 | NO) nm_optimize_opt="-O0" ;; 93 | YES) nm_optimize_opt="-O2" ;; 94 | *) nm_optimize_opt="$NM_OPTIMIZE" ;; 95 | esac 96 | 97 | # trigraphs 98 | nm_trigraphs_opt="-Wno-trigraphs" 99 | 100 | # openmp 101 | nm_openmp_opt="-fopenmp" 102 | 103 | # lib 104 | nm_lib_opt="-l" 105 | nm_libdir_opt="-L" 106 | nm_static_opt="-static" 107 | 108 | # link option 109 | LDFLAGS="${nm_libdir_opt}${NM_OUT}/lib${LDFLAGS:+ $LDFLAGS}" 110 | 111 | # eof 112 | -------------------------------------------------------------------------------- /auto/feature: -------------------------------------------------------------------------------- 1 | #### -*- mode:sh -*- vim:ft=sh 2 | #### 3 | ## No More than a C build system for clang, gcc and msvc. 4 | ## https://github.com/junjiemars/nore 5 | #### 6 | ## feature 7 | #### 8 | 9 | 10 | if [ "dumb" != "$nm_feature_run" ]; then 11 | case $nm_feature_indent in 12 | yes|'') 13 | printf " + checking for $nm_feature ... " 14 | ;; 15 | no|*) 16 | printf "checking for $nm_feature ... " 17 | ;; 18 | esac 19 | fi 20 | 21 | 22 | if [ -n "$nm_feature_name" ]; then 23 | nm_have_feature=`echo $nm_feature_name \ 24 | | tr '[\-: =]' '_' | tr '[:lower:]' '[:upper:]'` 25 | fi 26 | 27 | 28 | autotest_c="$NM_AUTOTEST.c" 29 | if [ "$CXX" = "$CC" ]; then 30 | autotest_c="$NM_AUTOTEST.cc" 31 | fi 32 | 33 | cat << END > $autotest_c 34 | $nm_feature_h 35 | 36 | int main(void) 37 | { 38 | $nm_feature_test 39 | } 40 | 41 | END 42 | 43 | 44 | nm_test="$CC $nm_feature_flags ${bin_out}${NM_AUTOTEST} $autotest_c $nm_feature_tails" 45 | 46 | 47 | cat << END >> $NM_AUTO_ERR 48 | 49 | ---------------------------------------- 50 | checking for $nm_feature: "$nm_test" 51 | 52 | END 53 | 54 | 55 | `$nm_test >> "$NM_AUTO_ERR" 2>&1` 56 | 57 | nm_found=no 58 | 59 | if [ -x $NM_AUTOTEST ]; then 60 | 61 | case "$nm_feature_run" in 62 | yes) 63 | if `$NM_AUTOTEST >> "$NM_AUTO_ERR" 2>&1`; then 64 | nm_found=yes 65 | if [ -n "$nm_feature_name" ]; then 66 | have=$nm_have_feature . ${NORE_ROOT}/auto/have 67 | fi 68 | fi 69 | echo "$nm_found" 70 | ;; 71 | 72 | value) 73 | nm_feature_value=`$NM_AUTOTEST 2>> "$NM_AUTO_ERR"` 74 | if [ 0 -eq $? ]; then 75 | nm_found=yes 76 | have=$nm_have_feature value=$nm_feature_value \ 77 | . ${NORE_ROOT}/auto/define 78 | fi 79 | echo "$nm_found" 80 | ;; 81 | 82 | dumb) 83 | nm_feature_value=`$NM_AUTOTEST 2>> "$NM_AUTO_ERR"` 84 | if [ 0 -eq $? ]; then 85 | nm_found=yes 86 | fi 87 | ;; 88 | 89 | bug) 90 | if `$NM_AUTOTEST >> "$NM_AUTO_ERR" 2>&1`; then 91 | echo "$nm_found" 92 | else 93 | nm_found=yes 94 | echo "$nm_found" 95 | if [ -n "$nm_feature_name" ]; then 96 | have=$nm_have_feature . ${NORE_ROOT}/auto/have 97 | fi 98 | fi 99 | ;; 100 | 101 | *) 102 | nm_found=yes 103 | echo "$nm_found" 104 | 105 | if [ -n "$nm_feature_name" ]; then 106 | have=$nm_have_feature . ${NORE_ROOT}/auto/have 107 | fi 108 | ;; 109 | esac 110 | 111 | else 112 | if [ "dumb" != "$nm_feature_run" ]; then 113 | echo "$nm_found" 114 | fi 115 | 116 | echo "----------" >> $NM_AUTO_ERR 117 | cat $autotest_c >> $NM_AUTO_ERR 118 | echo "----------" >> $NM_AUTO_ERR 119 | echo $nm_test >> $NM_AUTO_ERR 120 | echo "----------" >> $NM_AUTO_ERR 121 | fi 122 | 123 | [ -f $NM_AUTOTEST ] && rm $NM_AUTOTEST 124 | [ -f $autotest_c ] && rm $autotest_c 125 | [ -f autotest.obj ] && rm autotest.obj 126 | -------------------------------------------------------------------------------- /auto/cc/msvc: -------------------------------------------------------------------------------- 1 | #### -*- mode:sh -*- vim:ft=sh 2 | #------------------------------------------------ 3 | # target: cc/msvc for msvc compiler 4 | # url: https://github.com/junjiemars/nore.git 5 | # author: Junjie Mars 6 | #------------------------------------------------ 7 | 8 | nm_msvc_ver=`$CC 2>&1 | grep 'Compiler Version' 2>&1 \ 9 | | sed -e 's/^.* Version \(.*\)/\1/'` 10 | 11 | echo " + msvc version: $nm_msvc_ver" 12 | 13 | NM_COMPILER="msvc $nm_msvc_ver" 14 | have=NM_COMPILER value="\"$NM_COMPILER\"" . ${NORE_ROOT}/auto/define 15 | 16 | . ${NORE_ROOT}/auto/cc/version 17 | CC_VER=`version_n $(echo $nm_msvc_ver | cut -d' ' -f1)` 18 | have=MSVC value=$CC_VER . ${NORE_ROOT}/auto/define 19 | 20 | 21 | # compiler 22 | [ "." = ".$CC" ] && CC="cl" 23 | 24 | # preprocess 25 | [ "." = ".$CPP" ] && CPP="\$(CC)" 26 | 27 | # assembler 28 | [ "." = ".$AS" ] && AS="ml" 29 | 30 | # linker 31 | [ "." = ".$LD" ] && LD="link" 32 | 33 | # archive 34 | [ "." = ".$AR" ] && AR="lib" 35 | 36 | 37 | # output options 38 | cpp_out=">" 39 | asm_out="-FAu -Fa" 40 | obj_out="-Fo" 41 | bin_out="-Fe" 42 | ar_out="-out:" 43 | 44 | # auto object output option 45 | auto_out=$obj_out 46 | 47 | # extensions 48 | cpp_ext=".c" 49 | asm_ext=".asm" 50 | obj_ext=".obj" 51 | bin_ext=".exe" 52 | ar_ext=".lib" 53 | 54 | # stage 55 | nm_stage_pre="-E" 56 | nm_stage_asm="-c" 57 | nm_stage_c="-c" 58 | 59 | 60 | # error 61 | case "$NM_ERROR" in 62 | NO) nm_error_opt="" ;; 63 | YES) nm_error_opt="-WX" ;; 64 | esac 65 | 66 | # warnings (-Wall) 67 | case "$NM_WARN" in 68 | NO) nm_warn_opt="" ;; 69 | YES) nm_warn_opt="-W4" ;; 70 | *) nm_warn_opt="$NM_WARN" ;; 71 | esac 72 | 73 | # verbose 74 | case "$NM_VERBOSE" in 75 | NO) 76 | CC="${CC:+$CC }-nologo" 77 | if [ "$CXX" = "$CC" ]; then 78 | CXX="${CXX:+$CXX }-nologo" 79 | fi 80 | AR="${AR:+$AR }-nologo" 81 | AS="${AS:+$AS }-nologo" 82 | ;; 83 | YES) ;; 84 | esac 85 | 86 | # release option 87 | # linker option @ tail: verfied checksum 88 | nm_release_opt="-release" 89 | 90 | # symbol 91 | case "$NM_SYMBOL" in 92 | NO) nm_symbol_opt="" ;; 93 | YES) nm_symbol_opt="-Z7" ;; 94 | *) nm_symbol_opt="$NM_SYMBOL" ;; 95 | esac 96 | 97 | # arch 98 | case "$NM_ARCH" in 99 | NO) nm_arch_opt="" ;; 100 | YES) nm_arch_opt="" ;; 101 | *) 102 | # -arch:xxx 103 | nm_arch_opt="$NM_ARCH" 104 | ;; 105 | esac 106 | 107 | # std 108 | case "$NM_STD" in 109 | NO) nm_std_opt="" ;; 110 | YES) 111 | #https://herbsutter.com/2012/05/03/reader-qa-what-about-vc-and-c99/ 112 | nm_std_opt="-std:c11" 113 | ;; 114 | *) 115 | # for c90: -Za 116 | # for c11 or later: -std:c11, -std:c17, -std:latest 117 | nm_std_opt="${NM_STD}" 118 | ;; 119 | esac 120 | 121 | # optimize 122 | # see also: https://docs.microsoft.com/en-us/cpp/build/reference/compiler-options-listed-by-category?view=vs-2017 123 | case "$NM_OPTIMIZE" in 124 | NO) nm_optimize_opt="-Od" ;; 125 | YES) nm_optimize_opt="-O2" ;; 126 | *) nm_optimize_opt="$NM_OPTIMIZE" ;; 127 | esac 128 | 129 | # model 130 | nm_model_opt="-EHsc" 131 | 132 | # unicode 133 | nm_utf_opt="-utf-8" 134 | 135 | # trigraphs 136 | nm_trigraphs_opt="-Zc:trigraphs" 137 | 138 | # openmp 139 | nm_openmp_opt="-openmp" 140 | 141 | # lib 142 | nm_libdir_opt="-libpath:" 143 | nm_lib_opt= 144 | nm_static_opt="-MT" 145 | 146 | # link option @ tail 147 | nm_link_opt="-link" 148 | 149 | LDFLAGS="${nm_link_opt} ${nm_libdir_opt}${NM_OUT}/lib${LDFLAGS:+ $LDFLAGS}" 150 | 151 | # eof 152 | -------------------------------------------------------------------------------- /auto/cc/conf: -------------------------------------------------------------------------------- 1 | #### -*- mode:sh -*- vim:ft=sh 2 | #------------------------------------------------ 3 | # target: cc/conf for C compiler 4 | # url: https://github.com/junjiemars/nore.git 5 | # author: Junjie Mars 6 | #------------------------------------------------ 7 | 8 | CC=${CC:-cc} 9 | CXX= 10 | 11 | # predefined to c compiler 12 | ASM="\$(CC)" 13 | LINK="\$(CC)" 14 | 15 | # c preprocessor 16 | CPP=${CPP} 17 | # extra flags to c preprocessor 18 | CPPFLAGS=${CPPFLAGS} 19 | 20 | # assembler 21 | AS=${AS} 22 | # extra flags to assembler 23 | ASFLAGS=${ASFLAGS} 24 | 25 | # archiver 26 | AR=${AR} 27 | # extra flags to archiver 28 | ARFLAGS=${ARFLAGS} 29 | 30 | # extra flags to c compiler 31 | CFLAGS=${CFLAGS} 32 | # extra flags to c++ compiler 33 | CXXFLAGS= 34 | 35 | INC=${INC} 36 | 37 | # extra flags to compiler for linker 38 | # such as -L 39 | LDFLAGS=${LDFLAGS} 40 | 41 | # extra flags to compiler for linker 42 | # such as -l 43 | LDLIBS=${LDLIBS} 44 | 45 | # extra flags to Lex 46 | LFLAGS=${LFLAGS} 47 | # extra flags to Yacc 48 | YFLAGS=${YFLAGS} 49 | 50 | # command line option 51 | nm_symbol_opt= 52 | nm_build_opt= 53 | nm_release_opt= 54 | nm_warn_opt= 55 | nm_error_opt= 56 | nm_optimize_opt= 57 | nm_std_opt= 58 | nm_arch_opt= 59 | nm_verbose_opt= 60 | 61 | # feature 62 | nm_model_opt= 63 | nm_utf_opt= 64 | nm_trigraphs_opt= 65 | nm_openmp_opt= 66 | 67 | # stage 68 | nm_stage_pre= 69 | nm_stage_chk= 70 | nm_stage_asm= 71 | nm_stage_c= 72 | 73 | # macro define 74 | nm_def_opt=-D 75 | nm_undef_opt=-U 76 | 77 | # include 78 | nm_inc_opt=-I 79 | 80 | # lib 81 | nm_shared_opt= 82 | nm_libdir_opt= 83 | nm_lib_opt= 84 | 85 | # link 86 | nm_link_opt= 87 | 88 | # path separator 89 | nm_path_sep=":" 90 | 91 | obj_out="-o" 92 | bin_out="-o" 93 | cpp_out="-o" 94 | asm_out="-o" 95 | ar_out="rcs " 96 | 97 | obj_ext=".o" 98 | bin_ext= 99 | cpp_ext=".i" 100 | asm_ext=".s" 101 | ar_ext=".a" 102 | 103 | 104 | . ${NORE_ROOT}/auto/cc/name 105 | 106 | 107 | case "$CC_NAME" in 108 | gcc) . ${NORE_ROOT}/auto/cc/gcc ;; 109 | clang) . ${NORE_ROOT}/auto/cc/clang ;; 110 | msvc) . ${NORE_ROOT}/auto/cc/msvc ;; 111 | esac 112 | 113 | 114 | # error option 115 | if [ -n "$nm_error_opt" ]; then 116 | CFLAGS=${CFLAGS:+$CFLAGS }${nm_error_opt} 117 | fi 118 | 119 | # warn option 120 | if [ -n "$nm_warn_opt" ]; then 121 | CFLAGS=${CFLAGS:+$CFLAGS }${nm_warn_opt} 122 | fi 123 | 124 | # verbose option 125 | if [ -n "$nm_verbose_opt" ]; then 126 | CFLAGS=${CFLAGS:+$CFLAGS }${nm_verbose_opt} 127 | fi 128 | 129 | # build option 130 | case "$NM_BUILD" in 131 | YES) 132 | nm_build_opt='-DNDEBUG=1' 133 | CPPFLAGS=${CPPFLAGS:+$CPPFLAGS }${nm_build_opt} 134 | ;; 135 | NO) nm_build_opt="" ;; 136 | esac 137 | 138 | # symbol option 139 | if [ -n "$nm_symbol_opt" ]; then 140 | CFLAGS=${CFLAGS:+$CFLAGS }${nm_symbol_opt} 141 | fi 142 | 143 | # arch option 144 | if [ -n "$nm_arch_opt" ]; then 145 | CFLAGS=${CFLAGS:+$CFLAGS }${nm_arch_opt} 146 | fi 147 | 148 | # std option 149 | if [ -n "$nm_std_opt" ]; then 150 | CFLAGS=${CFLAGS:+$CFLAGS }${nm_std_opt} 151 | fi 152 | 153 | # optimize option 154 | if [ -n "$nm_optimize_opt" ]; then 155 | CFLAGS=${CFLAGS:+$CFLAGS }${nm_optimize_opt} 156 | fi 157 | 158 | # model option 159 | if [ -n "$nm_model_opt" ]; then 160 | CFLAGS=${CFLAGS:+$CFLAGS }${nm_model_opt} 161 | fi 162 | 163 | # unicode option 164 | if [ -n "$nm_utf_opt" ]; then 165 | CFLAGS=${CFLAGS:+$CFLAGS }${nm_utf_opt} 166 | CPPFLAGS=${CPPFLAGS:+$CPPFLAGS }${nm_utf_opt} 167 | fi 168 | 169 | # cxx flags 170 | if [ "$CXX" = "$CC" ]; then 171 | CXXFLAGS=$CFLAGS 172 | fi 173 | 174 | # inc option 175 | INC="${nm_inc_opt}${NM_OUT} ${nm_inc_opt}${NM_OUT}/inc${INC:+ $INC}" 176 | 177 | 178 | # link option 179 | 180 | 181 | # eof 182 | -------------------------------------------------------------------------------- /auto/options: -------------------------------------------------------------------------------- 1 | #### -*- mode:sh -*- vim:ft=sh 2 | #### 3 | ## No More than a C build system for clang, gcc and msvc. 4 | ## https://github.com/junjiemars/nore 5 | #### 6 | ## options 7 | #### 8 | 9 | 10 | help=no 11 | gen_by_nore="generated by Nore (https://github.com/junjiemars/nore)" 12 | 13 | NM_SYMBOL_FILE= 14 | 15 | NM_PREFIX= 16 | 17 | NM_BIN_PATH= 18 | NM_LIB_PATH= 19 | NM_INC_PATH= 20 | NM_ETC_PATH= 21 | NM_VAR_PATH= 22 | 23 | NM_OUT=out 24 | NM_SRC=. 25 | 26 | NM_NEW=NO 27 | 28 | NM_ERROR=YES 29 | NM_WARN=YES 30 | NM_VERBOSE=NO 31 | NM_BUILD=NO 32 | NM_SYMBOL=YES 33 | NM_ARCH=NO 34 | NM_STD=YES 35 | NM_OPTIMIZE=NO 36 | 37 | NM_PLATFORM= 38 | NM_CPU_CACHE_LINE= 39 | NM_HAS_STICKS= 40 | 41 | 42 | legal_dir_reg='^[a-zA-Z_/][a-zA-Z_0-9/]*$' 43 | legal_opt_reg='[a-zA-Z_][a-zA-Z_0-9]*$' 44 | 45 | legal_dir () { 46 | echo "$@" | grep -q "${legal_dir_reg}" 47 | } 48 | 49 | panic_arg () { 50 | echo "! panic: invalid argument ${1}'${@:2}'" 51 | echo " ${1} should be '${legal_dir_reg}'" 52 | exit 1 53 | } 54 | 55 | legal_opt () { 56 | echo "$@" | grep -q "\-\-has-${legal_opt_reg}" 57 | } 58 | 59 | panic_has_opt () { 60 | echo "! panic: invalid option '$@'" 61 | echo " --has-* where * should be '${legal_opt_reg}'" 62 | exit 1 63 | } 64 | 65 | 66 | for option 67 | do 68 | opt="$opt `echo $option | sed -e \"s/\(--[^=]*=\)\(.* .*\)/\1'\2'/\"`" 69 | 70 | case "$option" in 71 | -*=*) value=`echo "$option" | sed -e 's/[-_a-zA-Z0-9]*=//'` ;; 72 | *) value="" ;; 73 | esac 74 | 75 | case "$option" in 76 | --help) help=yes ;; 77 | 78 | --symbol-table=*) legal_dir "$value" \ 79 | && NM_SYMBOL_FILE="${value%/}" || panic_arg "--symbol-table=" "$value" 80 | ;; 81 | --prefix=*) legal_dir "$value" \ 82 | && NM_PREFIX="${value%/}" || panic_arg "--prefix=" "$value" 83 | ;; 84 | --src-dir=*) legal_dir "$value" \ 85 | && NM_SRC="${value%/}" || panic_arg "--src-dir=" "$value" 86 | ;; 87 | --out-dir=*) legal_dir "$value" \ 88 | && NM_OUT="${value%/}" || panic_arg "--out-dir=" "$value" 89 | ;; 90 | 91 | --new) NM_NEW=YES ;; 92 | 93 | --with-error=*) NM_ERROR="$value" ;; 94 | --with-warn=*) NM_WARN="$value" ;; 95 | --with-verbose=*) NM_VERBOSE="$value" ;; 96 | --with-release=*) NM_BUILD="$value" ;; 97 | --with-symbol=*) NM_SYMBOL="$value" ;; 98 | --with-arch=*) NM_ARCH="$value" ;; 99 | --with-std=*) NM_STD="$value" ;; 100 | --with-optimize=*) NM_OPTIMIZE="$value" ;; 101 | 102 | --has-*) 103 | if `legal_opt "$option"`; then 104 | NM_HAS_STICKS=${NM_HAS_STICKS:+$NM_HAS_STICKS }`echo $option|sed -e "s/\ *--has-\(${legal_opt_reg}\)/\1/"|tr '[:upper:]' '[:lower:]'` 105 | else 106 | panic_has_opt "$option" 107 | fi 108 | ;; 109 | 110 | *) 111 | echo "! panic: unkown option '$option'" 112 | exit 1 113 | ;; 114 | esac 115 | done 116 | 117 | if [ $help = yes ]; then 118 | cat << END 119 | usage: configure [command] 120 | configure [options...] 121 | 122 | commands: 123 | clone clone Nore to current directory 124 | upgrade upgrade Nore 125 | where where Nore located 126 | trace trace Nore 127 | 128 | options: 129 | --help print this message 130 | --symbol-table=PATH dump or load symbol table 131 | --prefix=PATH installation prefix 132 | --src-dir=[.|src|*] set source directory 133 | --out-dir=[out|*] set build out directory 134 | --new generate Nore script templates 135 | --with-error=[YES|NO] treat warn as error 136 | --with-warn=[YES|NO|*] warn level option 137 | --with-verbose=[NO|YES] verbose output 138 | --with-release=[NO|YES] build for release 139 | --with-symbol=[YES|NO|*] generate debug symbols 140 | --with-arch=[NO|YES|*] arch option 141 | --with-std=[YES|NO|*] language standard option 142 | --with-optimize=[NO|YES|*] optimize level option 143 | --has-* has [*] to do 144 | 145 | END 146 | exit 1 147 | fi 148 | 149 | 150 | yes_no_opt () { 151 | local d="$1" 152 | shift 1 153 | local v="$@" 154 | local u="`echo $v | tr [:lower:] [:upper:]`" 155 | 156 | if [ -z "$v" ]; then 157 | echo "$d" 158 | elif [ "YES" = "$u" -o "NO" = "$u" ]; then 159 | echo "$u" 160 | else 161 | echo "$v" 162 | fi 163 | } 164 | 165 | 166 | NM_CONFIGURE="$opt" 167 | 168 | if [ . = "$NM_SRC" -a -d src ]; then 169 | NM_SRC=src 170 | fi 171 | 172 | if [ 0 -eq ${#NM_HAS_STICKS} ]; then 173 | NM_HAS_STICKS="." 174 | fi 175 | 176 | NM_ERROR="`yes_no_opt YES $NM_ERROR`" 177 | NM_WARN="`yes_no_opt YES $NM_WARN`" 178 | NM_VERBOSE="`yes_no_opt NO $NM_VERBOSE`" 179 | NM_BUILD="`yes_no_opt NO $NM_BUILD`" 180 | NM_SYMBOL="`yes_no_opt YES $NM_SYMBOL`" 181 | NM_ARCH="`yes_no_opt NO $NM_ARCH`" 182 | NM_STD="`yes_no_opt YES $NM_STD`" 183 | NM_OPTIMIZE="`yes_no_opt NO $NM_OPTIMIZE`" 184 | 185 | NM_BIN_PATH="${NM_BIN_PATH:-bin}" 186 | NM_LIB_PATH="${NM_LIB_PATH:-lib}" 187 | NM_ETC_PATH="${NM_ETC_PATH:-etc}" 188 | NM_INC_PATH="${NM_INC_PATH:-include}" 189 | NM_VAR_PATH="${NM_VAR_PATH:-var}" 190 | 191 | 192 | # eof 193 | -------------------------------------------------------------------------------- /auto/check: -------------------------------------------------------------------------------- 1 | ##### -*- mode:sh -*- vim:ft=sh 2 | #### 3 | ## No More than a C build system for clang, gcc and msvc. 4 | ## https://github.com/junjiemars/nore 5 | #### 6 | ## check 7 | #### 8 | 9 | 10 | # # #check header file existing 11 | # # #---------------------------------------- 12 | # echo "checking C header files ..." 13 | # include="complex.h" . ${NORE_ROOT}/auto/include 14 | # include="fenv.h" . ${NORE_ROOT}/auto/include 15 | # include="stdalign.h" . ${NORE_ROOT}/auto/include 16 | # include="stdatomic.h" . ${NORE_ROOT}/auto/include 17 | # include="stdnoreturn.h" . ${NORE_ROOT}/auto/include 18 | # include="threads.h" . ${NORE_ROOT}/auto/include 19 | 20 | 21 | # # #check machine features 22 | # # #---------------------------------------- 23 | # echo "checking Machine features ..." 24 | # nm_feature="endian" 25 | # nm_feature_name="nm_cpu_little_endian" 26 | # nm_feature_indent=yes 27 | # nm_feature_run=value 28 | # nm_feature_h="#include " 29 | # nm_feature_flags= 30 | # nm_feature_test=' 31 | # int i=0x11223344; 32 | # char *p=(char*)&i; 33 | # int le=(0x44 == *p); 34 | # printf("%d", le);' 35 | # . ${NORE_ROOT}/auto/feature 36 | 37 | 38 | # # #check machine features 39 | # # #---------------------------------------- 40 | # case "$NM_SYSTEM" in 41 | # Darwin) 42 | # nm_feature="cache line size" 43 | # nm_feature_name='nm_cpu_cache_line' 44 | # nm_feature_indent=yes 45 | # nm_feature_run=value 46 | # nm_feature_h='#include 47 | # #include' 48 | # nm_feature_flags= 49 | # nm_feature_value= 50 | # nm_feature_test=' 51 | # size_t line = 0; 52 | # size_t size = sizeof(line); 53 | # if (!sysctlbyname("hw.cachelinesize", &line, &size, 0, 0)) { 54 | # printf("%d\n", (int)line); 55 | # return 0; 56 | # } 57 | # return 1;' 58 | # . ${NORE_ROOT}/auto/feature 59 | # if [ "yes" = "$nm_found" ]; then 60 | # NM_CPU_CACHE_LINE=$nm_feature_value 61 | # fi 62 | # ;; 63 | # Linux) 64 | # nm_feature="cache line size" 65 | # nm_feature_name='nm_cpu_cache_line' 66 | # nm_feature_indent=yes 67 | # nm_feature_run=value 68 | # nm_feature_h='#include ' 69 | # nm_feature_flags= 70 | # nm_feature_value= 71 | # nm_feature_test=' 72 | # char f = "/sys/devices/system/cpu/cpu0/cache/index0/coherency_line_size"; 73 | # FILE * p = fopen(f, "r"); 74 | # if (p) { 75 | # int i = 0; 76 | # fscanf(p, "%d", &i); 77 | # fclose(p); 78 | # printf("%d\n", i); 79 | # return 0; 80 | # } 81 | # return 1;' 82 | # . ${NORE_ROOT}/auto/feature 83 | # if [ "yes" = "$nm_found" ]; then 84 | # NM_CPU_CACHE_LINE=$nm_feature_value 85 | # fi 86 | # ;; 87 | # WinNT) 88 | # nm_feature="cache line size" 89 | # nm_feature_name='nm_cpu_cache_line' 90 | # nm_feature_indent=yes 91 | # nm_feature_run=value 92 | # nm_feature_h='#include 93 | # #include 94 | # #include ' 95 | # nm_feature_flags= 96 | # nm_feature_value= 97 | # nm_feature_test=' 98 | # size_t line = 0; 99 | # DWORD size = 0; 100 | # SYSTEM_LOGICAL_PROCESSOR_INFORMATION *buf = 0; 101 | # GetLogicalProcessorInformation(0, &size); 102 | # if (!size) { 103 | # return 1; 104 | # } 105 | # buf = (SYSTEM_LOGICAL_PROCESSOR_INFORMATION*)malloc(size); 106 | # if (!buf) { 107 | # return 1; 108 | # } 109 | # if (GetLogicalProcessorInformation(&buf[0], &size)) { 110 | # for (DWORD i = 0;i != size/sizeof(SYSTEM_LOGICAL_PROCESSOR_INFORMATION);i++) { 111 | # if (buf[i].Relationship == RelationCache && 1 == buf[i].Cache.Level) { 112 | # line = buf[i].Cache.LineSize; 113 | # break; 114 | # } 115 | # } 116 | # } 117 | # free(buf); 118 | # if (line) { 119 | # printf("%d\n", (int)line); 120 | # return 0; 121 | # } 122 | # return 1;' 123 | # . ${NORE_ROOT}/auto/feature 124 | # if [ "yes" = "$nm_found" ]; then 125 | # NM_CPU_CACHE_LINE=$nm_feature_value 126 | # fi 127 | # ;; 128 | # *) 129 | # nm_found=no 130 | # ;; 131 | # esac 132 | # if [ "yes" = "$nm_found" ]; then 133 | # NM_CPU_CACHE_LINE=$nm_feature_value 134 | # else 135 | # case "$NM_MACHINE" in 136 | # x86_64|amd64|ia64) NM_CPU_CACHE_LINE=64 ;; 137 | # i386|i686|i86pc|*) NM_CPU_CACHE_LINE=32 ;; 138 | # esac 139 | # have=NM_CPU_CACHE_LINE value=$NM_CPU_CACHE_LINE . ${NORE_ROOT}/auto/define 140 | # fi # end of check cache line size 141 | 142 | 143 | # # #check compiler sanitize features 144 | # # #---------------------------------------- 145 | # echo "checking Compiler features ..." 146 | # case "$CC_NAME" in 147 | # msvc) 148 | # nm_feature="-fsanitize=address" 149 | # nm_feature_name= 150 | # nm_feature_indent=yes 151 | # nm_feature_run=no 152 | # nm_feature_h= 153 | # nm_feature_flags='-fsanitize=address' 154 | # nm_feature_test= 155 | # . ${NORE_ROOT}/auto/feature 156 | # if [ yes = $nm_found ]; then 157 | # flag=has_sanitize \ 158 | # op=":=" value="YES" \ 159 | # . ${NORE_ROOT}/auto/make_define 160 | # flag=has_sanitize_address \ 161 | # op=":=" value="YES" \ 162 | # . ${NORE_ROOT}/auto/make_define 163 | # flag=cflags_sanitize \ 164 | # op="+=" value=$nm_feature_flags \ 165 | # . ${NORE_ROOT}/auto/make_define 166 | # fi 167 | # ;; 168 | # *) 169 | # nm_feature="-fsanitize=address" 170 | # nm_feature_name= 171 | # nm_feature_indent=yes 172 | # nm_feature_run=no 173 | # nm_feature_h= 174 | # nm_feature_flags='-fsanitize=address' 175 | # nm_feature_test= 176 | # . ${NORE_ROOT}/auto/feature 177 | # if [ yes = $nm_found ]; then 178 | # flag=has_sanitize \ 179 | # op=":=" value="YES" \ 180 | # . ${NORE_ROOT}/auto/make_define 181 | # flag=has_sanitize_address \ 182 | # op=":=" value="YES" \ 183 | # . ${NORE_ROOT}/auto/make_define 184 | # flag=cflags_sanitize \ 185 | # op="+=" value=$nm_feature_flags \ 186 | # . ${NORE_ROOT}/auto/make_define 187 | # fi 188 | # ;; 189 | # esac 190 | 191 | 192 | # # #check compiler features 193 | # # #---------------------------------------- 194 | # nm_feature="restrict" 195 | # nm_feature_name="nm_have_restrict" 196 | # nm_feature_run=no 197 | # nm_feature_h= 198 | # nm_feature_flags= 199 | # nm_feature_test='int x = 0x11; int *restrict p = &x;' 200 | # . ${NORE_ROOT}/auto/feature 201 | # if [ "yes" != $nm_found ]; then 202 | # nm_feature="__restrict keyword" 203 | # nm_feature_name="nm_have___restrict" 204 | # nm_feature_run= 205 | # nm_feature_h= 206 | # nm_feature_flags= 207 | # nm_feature_test='int x = 0x11; int *__restrict p = &x;' 208 | # . ${NORE_ROOT}/auto/feature 209 | # fi 210 | 211 | 212 | 213 | # # #check OS features: mmap 214 | # # #---------------------------------------- 215 | # echo "checking OS features ..." 216 | # case $NM_SYSTEM in 217 | # Darwin|Linux) 218 | # nm_feature="mmap" 219 | # nm_feature_name="nm_have_mmap" 220 | # nm_feature_run=no 221 | # nm_feature_h='#include ' 222 | # nm_feature_flags= 223 | # nm_feature_test='mmap(0, 16, 1, 0, 3, 0);' 224 | # . ${NORE_ROOT}/auto/feature 225 | # ;; 226 | # WinNT) 227 | # ;; 228 | # *) 229 | # ;; 230 | # esac 231 | 232 | 233 | # # #check libraries 234 | # # #---------------------------------------- 235 | # echo "checking Libraries ..." 236 | # has_pkg_config=no 237 | # printf " + checking for pkg-config ... " 238 | # if [ 0 -eq $(pkg-config --version 2>&1 1>/dev/null;echo $?) ]; then 239 | # printf "yes\n" 240 | # has_pkg_config=yes 241 | # flag=has_pkg_config op=":=" value="$has_pkg_config" \ 242 | # . ${NORE_ROOT}/auto/make_define 243 | # else 244 | # printf "no\n" 245 | # fi 246 | 247 | 248 | # # #eof 249 | -------------------------------------------------------------------------------- /test.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | _ROOT_DIR_="`cd -- $(dirname -- $0) && pwd`" 4 | _CI_DIR_="${_ROOT_DIR_%/}/ci" 5 | _BRANCH_="${_BRANCH_:-edge}" 6 | _OS_NAME_="`uname -s 2>/dev/null`" 7 | _MSVC_ENV_= 8 | _TRACE_="${_TRACE_}" 9 | 10 | case "${_OS_NAME_}" in 11 | MSYS_NT-*|MINGW??_NT-*) _OS_NAME_="WinNT" ;; 12 | esac 13 | 14 | CC="${CC}" 15 | if [ -z "$CC" ]; then 16 | case "$_OS_NAME_" in 17 | Darwin) CC="clang" ;; 18 | Linux) CC="gcc" ;; 19 | WinNT) CC="cl" ;; 20 | esac 21 | fi 22 | 23 | 24 | env_ci_build () { 25 | if [ -d "$_CI_DIR_" ]; then 26 | rm -r "${_CI_DIR_}" 27 | fi 28 | mkdir -p "$_CI_DIR_" 29 | 30 | echo "------------" 31 | echo "CC=$CC" 32 | echo "_ROOT_DIR_=$_ROOT_DIR_" 33 | echo "_CI_DIR_=$_CI_DIR_" 34 | echo "------------" 35 | 36 | if [ ! -f "${_ROOT_DIR_%/}/bootstrap.sh" ]; then 37 | echo "!panic: ${_ROOT_DIR_%/}/bootstrap.sh no found" 38 | exit 1 39 | fi 40 | cd "${_CI_DIR_}" 41 | ${_ROOT_DIR_%/}/bootstrap.sh --branch=${_BRANCH_} 42 | 43 | if [ "WinNT" = "${_OS_NAME_}" -a "cl" = "${CC}" ]; then 44 | if [ ! -f "${HOME}/.nore/cc-env.sh" ]; then 45 | echo "!panic: ${HOME}/.nore/cc-env.sh no found" 46 | exit 1 47 | fi 48 | ${HOME}/.nore/cc-env.sh 1 49 | 50 | if [ ! -f "${HOME}/.nore/cc-env.bat" ]; then 51 | echo "!panic: ${HOME}/.nore/cc-env.bat no found" 52 | exit 1 53 | fi 54 | _MSVC_ENV_="${HOME}/.nore/cc-env.bat" 55 | fi 56 | } 57 | 58 | test_what () { 59 | echo "------------" 60 | echo "# $@ ..." 61 | echo "------------" 62 | } 63 | 64 | test_configure () { 65 | local msvc_bat="msvc.bat" 66 | cd "$_CI_DIR_" 67 | if [ -z "${_MSVC_ENV_}" ]; then 68 | ./configure ${_TRACE_} $@ 69 | else 70 | cat << END > "${msvc_bat}" 71 | @if not "%VSCMD_DEBUG%" GEQ "3" echo off 72 | REM generated by Nore (https://github.com/junjiemars/nore) 73 | call "%1" 74 | sh ./configure ${_TRACE_} $@ 75 | END 76 | if [ ! -f "${msvc_bat}" ]; then 77 | echo "!panic: generate msvc.bat failed" 78 | exit 1 79 | fi 80 | chmod u+x ${msvc_bat} 81 | ./${msvc_bat} "${_MSVC_ENV_}" 82 | fi 83 | } 84 | 85 | test_install_from_github () { 86 | local b="https://raw.githubusercontent.com/junjiemars/nore/master/bootstrap.sh" 87 | test_what "install from github.com" 88 | if [ -d "$_CI_DIR_" ]; then 89 | rm -r "${_CI_DIR_}" 90 | fi 91 | mkdir -p "$_CI_DIR_" && cd "$_CI_DIR_" 92 | 93 | curl $b -sSfL | sh -s -- --branch=$_BRANCH_ 94 | } 95 | 96 | test_make_print_database () { 97 | test_what "print the make's predefined database" 98 | make -C "$_CI_DIR_" -p 2>&1 || echo "------------" 99 | } 100 | 101 | test_make () { 102 | local msvc_bat="msvc.bat" 103 | cd "$_CI_DIR_" 104 | if [ -z "${_MSVC_ENV_}" ]; then 105 | make $@ 106 | else 107 | cat << END > "${msvc_bat}" 108 | @if not "%VSCMD_DEBUG%" GEQ "3" echo off 109 | REM generated by Nore (https://github.com/junjiemars/nore) 110 | call "%1" 111 | "%2" "%3" 112 | END 113 | if [ ! -f "${msvc_bat}" ]; then 114 | echo "!panic: generate msvc.bat failed" 115 | exit 1 116 | fi 117 | chmod u+x ${msvc_bat} 118 | ./${msvc_bat} "${_MSVC_ENV_}" "make $@" 119 | fi 120 | } 121 | 122 | test_nore_where_command () { 123 | test_what "./configure where" 124 | test_configure where 125 | } 126 | 127 | test_nore_new_option () { 128 | test_what "CC=$CC ./configure --new" 129 | test_configure --new 130 | test_make clean test 131 | } 132 | 133 | test_nore_symbol_option () { 134 | local c="`basename $_CI_DIR_`.c" 135 | 136 | test_what "CC=$CC ./configure --symbol-table=sym" 137 | test_configure --symbol-table=sym 138 | test_make clean test 139 | 140 | cat < "$c" 141 | #include 142 | #include 143 | 144 | int main(void) { 145 | #if __DARWIN__ 146 | printf("Hello, Darwin!\n"); 147 | #elif __LINUX__ 148 | printf("Hello, Linux!\n"); 149 | #elif __WINNT__ 150 | printf("Hello, WinNT!\n"); 151 | #else 152 | printf("!panic, unknown OS\n"); 153 | #endif 154 | return 0; 155 | } 156 | END 157 | 158 | case "$_OS_NAME_" in 159 | Darwin) 160 | sed "s/DARWIN:DARWIN/DARWIN:__DARWIN__/g" sym > sym1 2>/dev/null 161 | ;; 162 | Linux) 163 | sed "s/LINUX:LINUX/LINUX:__LINUX__/g" sym > sym1 2>/dev/null 164 | ;; 165 | WinNT) 166 | sed "s/WINNT:WINNT/WINNT:__WINNT__/g" sym > sym1 2>/dev/null 167 | ;; 168 | esac 169 | 170 | test_what "CC=$CC ./configure --symbol-table=sym1" 171 | test_configure --symbol-table=sym1 172 | test_make clean test 173 | } 174 | 175 | test_nore_optimize_option () { 176 | local c="`basename $_CI_DIR_`.c" 177 | local m="Makefile" 178 | 179 | cat < "$c" 180 | #include 181 | #include 182 | 183 | #if (MSVC) 184 | # pragma warning(disable : 4996) 185 | #endif 186 | 187 | int 188 | fibonacci(int n, int p, int acc) { 189 | if (0 == n) { 190 | return acc; 191 | } 192 | return fibonacci(n-1, acc, p+acc); 193 | } 194 | 195 | int main(int argc, char **argv) { 196 | if (argc < 2) { 197 | return 1; 198 | } 199 | int n; 200 | sscanf(argv[1], "%i", &n); 201 | int retval = fibonacci(n, 1, 0); 202 | printf("fibonacci(%i)=%i\n", n, retval); 203 | return 0; 204 | } 205 | END 206 | 207 | cat < "$m" 208 | include out/Makefile 209 | 210 | ci_root := ./ 211 | ci_binout := \$(bin_path)/ci\$(bin_ext) 212 | 213 | ci: \$(ci_binout) 214 | ci_test: ci 215 | \$(ci_binout) 5 216 | 217 | \$(ci_binout): \$(ci_root)/ci.c 218 | \$(CC) \$(CFLAGS) \$(INC) \$^ \$(bin_out)\$@ 219 | END 220 | 221 | test_what "CC=$CC ./configure --with-optimize=no" 222 | test_configure --with-optimize=no 223 | test_make clean test 224 | 225 | test_what "CC=$CC ./configure --with-optimize=yes" 226 | test_configure --with-optimize=yes 227 | test_make clean test 228 | } 229 | 230 | test_nore_std_option () { 231 | local c="`basename $_CI_DIR_`.c" 232 | local m="Makefile" 233 | 234 | cat < "$c" 235 | #include 236 | #include 237 | #include 238 | 239 | int main(void) { 240 | enum { N = 5 }; 241 | static_assert(N == 5, "N is not equal 5"); 242 | return 0; 243 | } 244 | END 245 | 246 | cat < "$m" 247 | include out/Makefile 248 | 249 | ci_root := ./ 250 | ci_binout := \$(bin_path)/ci\$(bin_ext) 251 | 252 | ci: \$(ci_binout) 253 | ci_test: ci 254 | \$(ci_binout) 255 | 256 | \$(ci_binout): \$(ci_root)/ci.c 257 | \$(CC) \$(CFLAGS) \$(INC) \$^ \$(bin_out)\$@ 258 | END 259 | 260 | test_what "CC=$CC ./configure --with-std=yes" 261 | test_configure "--with-std=yes" 262 | test_make clean test 263 | 264 | test_what "CC=$CC ./configure --with-std=-std=c11" 265 | case "$_OS_NAME_" in 266 | Darwin) test_configure "--with-std=-std=c11" ;; 267 | Linux) test_configure "--with-std=-std=c11" ;; 268 | WinNT|*) 269 | case "$CC" in 270 | cl) test_configure "--with-std=-std:c11" ;; 271 | gcc|*) test_configure "--with-std=-std=c11" ;; 272 | esac 273 | esac 274 | test_make clean test 275 | } 276 | 277 | test_nore_prefix_option () { 278 | local d="${_CI_DIR_}/xxx" 279 | test_what "CC=$CC ./configure --prefix=xxx" 280 | test_configure --new 281 | test_configure --prefix=xxx 282 | test_make clean test install 283 | if [ -d "$d" ]; then 284 | rm -r "$d" 285 | fi 286 | } 287 | 288 | test_nore_override_option () { 289 | test_what "CC=$CC ./configure --new" 290 | test_configure --new --with-optimize=yes --with-optimize=-Os 291 | test_make clean test 292 | } 293 | 294 | test_nore_auto_check () { 295 | local a="auto" 296 | sed -e 's/^#//g' "${_ROOT_DIR_}/auto/check" > "${a}" 297 | test_what "CC=$CC ./configure #auto" 298 | test_configure 299 | } 300 | 301 | # test 302 | if [ -n "$_INSIDE_CI_" ]; then 303 | test_install_from_github 304 | fi 305 | env_ci_build 306 | test_make_print_database 307 | test_nore_where_command 308 | test_nore_new_option 309 | test_nore_symbol_option 310 | test_nore_optimize_option 311 | test_nore_std_option 312 | test_nore_prefix_option 313 | test_nore_override_option 314 | test_nore_auto_check 315 | 316 | # clean CI directory 317 | [ -d "${_CI_DIR_}" ] && rm -r "${_CI_DIR_}" 318 | 319 | echo "#!completed" 320 | 321 | # eof 322 | -------------------------------------------------------------------------------- /auto/make: -------------------------------------------------------------------------------- 1 | #### -*- mode:sh -*- vim:ft=sh 2 | #### 3 | ## No More than a C build system for clang, gcc and msvc. 4 | ## https://github.com/junjiemars/nore 5 | #### 6 | ## make 7 | #### 8 | 9 | 10 | echo "creating $NM_MAKEFILE" 11 | 12 | mkdir -p $NM_OUT/bin \ 13 | $NM_OUT/etc \ 14 | $NM_OUT/inc \ 15 | $NM_OUT/lib \ 16 | $NM_OUT/tmp \ 17 | $NM_OUT/var 18 | 19 | asm_out="${auto_out:+${auto_out}${NM_OUT}/tmp/ }$asm_out" 20 | bin_out="${auto_out:+${auto_out}${NM_OUT}/tmp/ }$bin_out" 21 | 22 | 23 | cat << END > $NM_MAKEFILE 24 | # ${NM_MAKEFILE} (${NM_COMPILER}, ${NM_PLATFORM}) 25 | # 26 | # ${gen_by_nore} 27 | # 28 | # GNU make Manual: https://www.gnu.org/software/make/manual/make.html 29 | # 30 | 31 | CC = $CC 32 | ` 33 | if [ ".$CXX" = ".$CC" ]; then 34 | echo "CXX = \$CXX" 35 | fi 36 | ` 37 | 38 | CPP = $CPP 39 | AS = $AS 40 | AR = $AR 41 | LD = $LD 42 | 43 | # override make's predefined AS and LD 44 | ASM = $ASM 45 | LINK = $LINK 46 | 47 | 48 | CPPFLAGS = $CPPFLAGS 49 | ASFLAGS = $ASFLAGS 50 | LDFLAGS = $LDFLAGS 51 | LDLIBS = $LDLIBS 52 | ARFLAGS = $ARFLAGS 53 | LFLAGS = $LFLAGS 54 | YFLAGS = $YFLAGS 55 | 56 | CFLAGS = $CFLAGS 57 | ` 58 | if [ ".$CXX" = ".$CC" ]; then 59 | echo "CXXFLAGS = \$CFLAGS" 60 | fi 61 | ` 62 | 63 | INC = $INC 64 | 65 | nm_symbol_opt = $nm_symbol_opt 66 | nm_warn_opt = $nm_warn_opt 67 | nm_error_opt = $nm_error_opt 68 | nm_build_opt = $nm_build_opt 69 | nm_release_opt = $nm_release_opt 70 | nm_std_opt = $nm_std_opt 71 | nm_optimize_opt = $nm_optimize_opt 72 | nm_arch_opt = $nm_arch_opt 73 | nm_verbose_opt = $nm_verbose_opt 74 | 75 | 76 | # feature 77 | nm_model_opt = $nm_model_opt 78 | nm_utf_opt = $nm_utf_opt 79 | nm_trigraphs_opt = $nm_trigraphs_opt 80 | nm_openmp_opt = $nm_openmp_opt 81 | 82 | # stage 83 | nm_stage_pre = $nm_stage_pre 84 | nm_stage_chk = $nm_stage_chk 85 | nm_stage_asm = $nm_stage_asm 86 | nm_stage_c = $nm_stage_c 87 | 88 | # macro define 89 | nm_def_opt = $nm_def_opt 90 | nm_undef_opt = $nm_undef_opt 91 | 92 | # inc 93 | nm_inc_opt = $nm_inc_opt 94 | 95 | # lib 96 | nm_shared_opt = $nm_shared_opt 97 | nm_libdir_opt = $nm_libdir_opt 98 | nm_lib_opt = $nm_lib_opt 99 | 100 | # link 101 | nm_link_opt = $nm_link_opt 102 | 103 | # path separator 104 | nm_path_sep = $nm_path_sep 105 | 106 | # nore options 107 | NM_SYMBOL = $NM_SYMBOL 108 | NM_OPTIMIZE = $NM_OPTIMIZE 109 | NM_WARN = $NM_WARN 110 | NM_ERROR = $NM_ERROR 111 | NM_BUILD = $NM_BUILD 112 | NM_VERBOSE = $NM_VERBOSE 113 | NM_STD = $NM_STD 114 | NM_ARCH = $NM_ARCH 115 | 116 | # platform 117 | `symbol_value NM_SYSTEM` = $NM_SYSTEM 118 | `symbol_value NM_RELEASE` = $NM_RELEASE 119 | `symbol_value NM_MACHINE` = $NM_MACHINE 120 | 121 | # compiler 122 | `symbol_value CC_NAME` = $CC_NAME 123 | `symbol_value CC_VER` = $CC_VER 124 | 125 | # output option 126 | cpp_out = $cpp_out 127 | asm_out = $asm_out 128 | obj_out = $obj_out 129 | lib_out = $bin_out 130 | ar_out = $ar_out 131 | bin_out = $bin_out 132 | 133 | # output extension 134 | cpp_ext = $cpp_ext 135 | asm_ext = $asm_ext 136 | obj_ext = $obj_ext 137 | lib_ext = $lib_ext 138 | ar_ext = $ar_ext 139 | bin_ext = $bin_ext 140 | 141 | 142 | default: all 143 | 144 | clean_bin_dir: $NM_OUT/bin 145 | -\$(RM) -r $NM_OUT/bin/* 146 | clean_lib_dir: $NM_OUT/lib 147 | -\$(RM) -r $NM_OUT/lib/* 148 | clean_inc_dir: $NM_OUT/inc 149 | -\$(RM) -r $NM_OUT/inc/* 150 | clean_etc_dir: $NM_OUT/etc 151 | -\$(RM) -r $NM_OUT/etc/* 152 | clean_var_dir: $NM_OUT/var 153 | -\$(RM) -r $NM_OUT/var/* 154 | clean_tmp_dir: $NM_OUT/tmp 155 | -\$(RM) -r $NM_OUT/tmp/* 156 | 157 | clean: clean_bin_dir \\ 158 | clean_lib_dir \\ 159 | clean_inc_dir \\ 160 | clean_etc_dir \\ 161 | clean_var_dir \\ 162 | clean_tmp_dir 163 | 164 | 165 | END 166 | 167 | 168 | # make install targets 169 | . ${NORE_ROOT}/auto/install 170 | 171 | 172 | nm_sticks= 173 | nm_sticks_build= 174 | nm_sticks_test= 175 | nm_stick_src= 176 | nm_stick_norm= 177 | nm_stick_make= 178 | 179 | 180 | make_stick_path () { 181 | local src="$1" 182 | local stick="$2" 183 | if [ "." = "$stick" ]; then 184 | echo "$src" 185 | else 186 | echo "$src/$stick" 187 | fi 188 | } 189 | 190 | make_stick_norm () { 191 | local src="$1" 192 | local stick="$2" 193 | if [ "." = "$stick" ]; then 194 | if [ "." = "$src" ]; then 195 | echo "`basename \"$PWD\" | tr '[\t :=]' '_'`" 196 | else 197 | echo "`basename $src`" 198 | fi 199 | else 200 | echo "$stick" 201 | fi 202 | } 203 | 204 | echo_yes_or_no () { 205 | if [ 0 -eq $1 ]; then 206 | printf "yes\n" 207 | else 208 | printf "no\n" 209 | fi 210 | } 211 | 212 | echo_pretty_path () { 213 | echo "$@" | sed -e 's#^./\(.*\)#\1#' 214 | } 215 | 216 | 217 | # basic paths 218 | cat << END >> $NM_MAKEFILE 219 | 220 | #--------------------------------------- 221 | 222 | root = $NM_SRC 223 | out = $NM_OUT 224 | 225 | bin_path = $NM_OUT/bin 226 | etc_path = $NM_OUT/etc 227 | inc_path = $NM_OUT/inc 228 | lib_path = $NM_OUT/lib 229 | tmp_path = $NM_OUT/tmp 230 | var_path = $NM_OUT/var 231 | 232 | #--------------------------------------- 233 | END 234 | 235 | 236 | for stick in ${NM_HAS_STICKS}; do 237 | 238 | nm_stick_src="`make_stick_path $NM_SRC $stick`" 239 | nm_stick_norm="`make_stick_norm $nm_stick_src $stick`" 240 | nm_stick_norm_c= 241 | 242 | if [ ! -d "$nm_stick_src" ]; then 243 | if [ YES = $NM_NEW ]; then 244 | printf " + generating $nm_stick_src directory ... " 245 | mkdir -p "$nm_stick_src" 246 | echo_yes_or_no $? 247 | else 248 | echo " + checking for $nm_stick_src ... no" 249 | cat << END >> $NM_AUTO_ERR 250 | 251 | --------------------------------------- 252 | checking for $nm_stick_src ... no 253 | 254 | END 255 | continue 256 | fi 257 | fi # end of [ ! -d $nm_stick_src ] 258 | 259 | if [ "$CXX" != "$CC" ]; then 260 | nm_stick_norm_c="${nm_stick_norm}.c" 261 | else 262 | nm_stick_norm_c="${nm_stick_norm}.cc" 263 | fi 264 | 265 | if [ YES = $NM_NEW -a ! -f "$nm_stick_norm_c" ]; then 266 | printf " + generating `echo_pretty_path $nm_stick_src/$nm_stick_norm_c` file ... " 267 | 268 | cat < "$nm_stick_src/$nm_stick_norm_c" 269 | /* 270 | * ${gen_by_nore} 271 | * 272 | */ 273 | 274 | #include 275 | ` 276 | if [ "$CXX" != "$CC" ]; then 277 | echo "#include " 278 | else 279 | echo "#include " 280 | fi 281 | ` 282 | 283 | int 284 | main(void) 285 | { 286 | ` 287 | if [ "$CXX" != "$CC" ]; then 288 | echo " printf(\\"Hello, Nore!\\\\\n\\");" 289 | else 290 | echo " std::cout << \\"Hello, Nore!\\" << std::endl;" 291 | fi 292 | ` 293 | return 0; 294 | } 295 | END 296 | 297 | echo_yes_or_no $? 298 | fi # end of [ ! -f "$nm_stick_src/$nm_stick_norm_c" ] 299 | 300 | if [ -f "$nm_stick_src/version" ]; then 301 | echo " * checking for `echo_pretty_path $nm_stick_src/version` ... yes" 302 | have=`echo "$nm_stick_norm" | tr '[:lower:]' '[:upper:]'`_VERSION \ 303 | value=`cat "$nm_stick_src/version"` . ${NORE_ROOT}/auto/define 304 | 305 | elif [ YES = $NM_NEW ]; then 306 | printf " + generating `echo_pretty_path $nm_stick_src/version` file ... " 307 | cat << END > "$nm_stick_src/version" 308 | 0x030614 309 | 310 | END 311 | echo_yes_or_no $? 312 | fi # end of [ -f $nm_stick_src/version ] 313 | 314 | if [ -f "$nm_stick_src/auto" ]; then 315 | echo " * checking for `echo_pretty_path $nm_stick_src/auto` ... yes" 316 | . "$nm_stick_src/auto" 2>> $NM_AUTO_ERR 317 | 318 | elif [ YES = $NM_NEW ]; then 319 | printf " + generating `echo_pretty_path $nm_stick_src/auto` file ... " 320 | cat ${NORE_ROOT}/auto/check > "$nm_stick_src/auto" 321 | echo_yes_or_no $? 322 | else 323 | echo " * checking for `echo_pretty_path $nm_stick_src/auto` ... no" 324 | fi # end of [ -f $nm_stick_src/auto ] 325 | 326 | if [ -f "$nm_stick_src/Makefile" ]; then 327 | stick_makefile="$nm_stick_src/Makefile" 328 | echo " * checking for `echo_pretty_path $nm_stick_src/Makefile` ... yes" 329 | 330 | elif [ YES = $NM_NEW ]; then 331 | stick_makefile="$nm_stick_src/Makefile" 332 | if [ $nm_stick_src = . ]; then 333 | stick_makefile="$nm_stick_src/Makefile.NEW" 334 | else 335 | printf " + generating `echo_pretty_path $nm_stick_src/Makefile` ... " 336 | fi 337 | cat << END > "$stick_makefile" 338 | #--------------------------------------- 339 | 340 | ${nm_stick_norm}_root := $nm_stick_src 341 | 342 | ${nm_stick_norm}_binout := \$(bin_path)/${nm_stick_norm}\$(bin_ext) 343 | 344 | ${nm_stick_norm}: \$(${nm_stick_norm}_binout) 345 | ${nm_stick_norm}_test: ${nm_stick_norm} 346 | \$(${nm_stick_norm}_binout) 347 | 348 | \$(${nm_stick_norm}_binout): \$(${nm_stick_norm}_root)/${nm_stick_norm_c} 349 | \$(CC) \$(CFLAGS) \$(INC) \$^ \$(bin_out)\$@ 350 | 351 | END 352 | if [ $nm_stick_src != . ]; then 353 | echo_yes_or_no $? 354 | fi 355 | else 356 | 357 | echo " * checking for `echo_pretty_path $nm_stick_src/Makefile` ... no" 358 | cat << END >> $NM_AUTO_ERR 359 | 360 | ---------------------------------------- 361 | checking for ${nm_stick_src}/Makefile ... no 362 | 363 | END 364 | continue 365 | fi # end of [ -f $nm_stick_src/Makefile ] 366 | 367 | nm_sticks="$nm_stick $stick" 368 | nm_sticks_build="$nm_sticks_build $nm_stick_norm" 369 | nm_sticks_test="$nm_sticks_test ${nm_stick_norm}_test" 370 | 371 | if [ $nm_stick_src != . -a -n "$stick_makefile" ]; then 372 | cat << END >> $NM_MAKEFILE 373 | 374 | ${nm_stick_norm}_root := $nm_stick_src 375 | 376 | include $stick_makefile 377 | 378 | #--------------------------------------- 379 | END 380 | fi # end of [ -n $stick_makefile ] 381 | 382 | done # end of for loop sticks 383 | 384 | 385 | if [ 0 -lt ${#nm_sticks} ]; then 386 | 387 | cat << END >> $NM_MAKEFILE 388 | 389 | all: ${nm_sticks_build} 390 | test: ${nm_sticks_test} 391 | 392 | 393 | .PHONY: default all clean test task install \\ 394 | ${nm_sticks_build} ${nm_sticks_test} 395 | 396 | #--------------------------------------- 397 | 398 | #eof 399 | END 400 | 401 | fi 402 | 403 | 404 | # create root Makefile 405 | if [ ! -f Makefile ]; then 406 | printf " + generating Makefile file ... " 407 | cat << END > Makefile 408 | # Makefile 409 | # 410 | # ${gen_by_nore} 411 | # 412 | # check ${NM_MAKEFILE} for details 413 | 414 | include $NM_MAKEFILE 415 | 416 | END 417 | 418 | if [ -f "$nm_stick_src/Makefile.NEW" ]; then 419 | cat "$nm_stick_src/Makefile.NEW" >> Makefile 420 | rm "$nm_stick_src/Makefile.NEW" 421 | fi 422 | echo_yes_or_no $? 423 | 424 | fi # end of [ -f Makefile ] 425 | 426 | 427 | # eof 428 | -------------------------------------------------------------------------------- /bootstrap.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | #------------------------------------------------ 3 | # target: bootstrap script of Nore 4 | # url: https://github.com/junjiemars/nore.git 5 | # author: Junjie Mars 6 | #------------------------------------------------ 7 | 8 | HOME="${HOME}" 9 | PATH="/usr/bin:/usr/sbin:/bin:/sbin" 10 | unset -f command 2>/dev/null 11 | # check env 12 | # check commands 13 | set -e 14 | awk=$(command -v awk) 15 | chmod=$(command -v chmod) 16 | curl=$(command -v curl) 17 | cut=$(command -v cut) 18 | date=$(command -v date) 19 | dirname=$(command -v dirname) 20 | git=$(command -v git) 21 | grep=$(command -v grep) 22 | ls=$(command -v ls) 23 | mkdir=$(command -v mkdir) 24 | mv=$(command -v mv) 25 | printf=$(command -v printf) 26 | ps=$(command -v ps) 27 | pwd=$(command -v pwd) 28 | rm=$(command -v rm) 29 | sed=$(command -v sed) 30 | sort=$(command -v sort) 31 | tar=$(command -v tar) 32 | touch=$(command -v touch) 33 | tr=$(command -v tr) 34 | uname=$(command -v uname) 35 | # check shell 36 | PLATFORM=$($uname -s 2>/dev/null) 37 | on_windows_nt () { 38 | case $PLATFORM in 39 | MSYS_NT*|MINGW*) return 0 ;; 40 | *) return 1 ;; 41 | esac 42 | } 43 | on_darwin () { 44 | case $PLATFORM in 45 | Darwin) return 0 ;; 46 | *) return 1 ;; 47 | esac 48 | } 49 | on_linux () { 50 | case $PLATFORM in 51 | Linux) return 0 ;; 52 | *) return 1 ;; 53 | esac 54 | } 55 | set +e 56 | 57 | bootstrap_path () { 58 | local p="`$dirname $0`" 59 | local n="${PWD}/.nore" 60 | 61 | if [ -d "${p}" ]; then 62 | p="`( cd \"${p}\" && $pwd )`" 63 | if [ -z "$p" -o "/dev/fd" = "$p" ]; then 64 | echo "$n" 65 | elif [ ! -f "${p}/auto/configure" ]; then 66 | echo "${p}/.nore" 67 | else 68 | echo "$p" 69 | fi 70 | else 71 | echo "$n" 72 | fi 73 | } 74 | 75 | ROOT="${ROOT:-`bootstrap_path`}" 76 | NORE_WORK="$PWD" 77 | 78 | GITHUB_R="${GITHUB_R:-https://raw.githubusercontent.com/junjiemars}" 79 | GITHUB_H="${GITHUB_H:-https://github.com/junjiemars}" 80 | 81 | NORE_UPGRADE=no 82 | NORE_BRANCH=master 83 | 84 | for option 85 | do 86 | case "$option" in 87 | -*=*) value=`echo "$option" | $sed -e 's/[-_a-zA-Z0-9]*=//'` ;; 88 | *) value="" ;; 89 | esac 90 | 91 | case "$option" in 92 | --help) help=yes ;; 93 | --branch=*) NORE_BRANCH="$value" ;; 94 | --work=*) NORE_WORK="$value" ;; 95 | 96 | *) 97 | command="`echo $option | $tr '[:upper:]' '[:lower:]'`" 98 | ;; 99 | esac 100 | done 101 | 102 | case ".$command" in 103 | .u|.upgrade) 104 | NORE_UPGRADE=yes 105 | ;; 106 | esac 107 | 108 | check_nore () { 109 | local r="junjiemars/nore" 110 | if $($git -C "${ROOT}" remote -v 2>/dev/null | $grep -q "${r}"); then 111 | if [ "`check_nore_branch`" != "${NORE_BRANCH}" ] \ 112 | && [ "${ROOT}" != "${PWD}/.nore" ]; then 113 | ROOT="${PWD}/.nore" 114 | [ -d "${ROOT}" ] && $rm -rf "${ROOT}" 115 | return 1 116 | else 117 | # ignore unmatched branch 118 | return 0 119 | fi 120 | else 121 | return 1 122 | fi 123 | } 124 | 125 | check_nore_branch () { 126 | $git -C "${ROOT}" rev-parse --abbrev-ref HEAD 127 | } 128 | 129 | upgrade_nore () { 130 | local b="`check_nore_branch`" 131 | [ -n "${b}" ] || return 1 132 | 133 | $git -C "${ROOT}" reset --hard 1>/dev/null 2>&1 || return $? 134 | 135 | [ ${NORE_BRANCH} = ${b} ] || return $? 136 | $git -C "${ROOT}" pull --rebase origin ${b} 1>/dev/null 2>&1 137 | } 138 | 139 | clone_nore () { 140 | $git clone --depth=1 --branch=${NORE_BRANCH} ${GITHUB_H}/nore.git "${ROOT}" 1>/dev/null 2>&1 141 | } 142 | 143 | 144 | cat_configure () { 145 | local b="`check_nore_branch`" 146 | local conf="${NORE_WORK%/}/configure" 147 | local new_conf="${conf}.n" 148 | 149 | cat << END > "$new_conf" 150 | #!/bin/sh 151 | #------------------------------------------------ 152 | # target: configure 153 | # author: Junjie Mars 154 | # generated by Nore (${GITHUB_H}/nore) 155 | #------------------------------------------------ 156 | 157 | NORE_ROOT="${ROOT%/}" 158 | NORE_BRANCH="${b}" 159 | NORE_L_BOOT="\${NORE_ROOT}/bootstrap.sh" 160 | NORE_R_BOOT="${GITHUB_R}/nore/\${NORE_BRANCH}/bootstrap.sh" 161 | NORE_L_CONF="\${NORE_ROOT}/auto/configure" 162 | NORE_L_CONF_OPTS= 163 | NORE_L_CONF_TRACE="no" 164 | NORE_L_CONF_COMMAND= 165 | 166 | for option 167 | do 168 | case "\$option" in 169 | -*=*) 170 | NORE_L_CONF_OPTS="\${NORE_L_CONF_OPTS:+\$NORE_L_CONF_OPTS }\$option" 171 | ;; 172 | 173 | -*) 174 | NORE_L_CONF_OPTS="\${NORE_L_CONF_OPTS:+\$NORE_L_CONF_OPTS }\$option" 175 | ;; 176 | 177 | *) 178 | NORE_L_CONF_COMMAND="\$option" 179 | ;; 180 | esac 181 | done 182 | 183 | case "\`echo \${NORE_L_CONF_COMMAND} | $tr '[:upper:]' '[:lower:]'\`" in 184 | upgrade) 185 | if [ -f \${NORE_L_BOOT} ]; then 186 | \$NORE_L_BOOT --branch=\${NORE_BRANCH} upgrade 187 | else 188 | $curl -sqL \${NORE_R_BOOT} \\ 189 | | ROOT=\${NORE_ROOT} sh -s -- \\ 190 | --branch=\${NORE_BRANCH} upgrade 191 | fi 192 | exit \$? 193 | ;; 194 | 195 | clone) 196 | if [ -f \${NORE_L_BOOT} ]; then 197 | \$NORE_L_BOOT --branch=\${NORE_BRANCH} --work=\$PWD 198 | else 199 | $curl -sqL \${NORE_R_BOOT} \\ 200 | | ROOT=\${NORE_ROOT} sh -s -- \\ 201 | --branch=\${NORE_BRANCH} \\ 202 | --work=\$PWD 203 | fi 204 | exit \$? 205 | ;; 206 | 207 | where) 208 | echo "NORE_ROOT=\${NORE_ROOT}" 209 | echo "NORE_BRANCH=\${NORE_BRANCH}" 210 | echo "configure=@\$0" 211 | echo "make=@\$(command -v make)" 212 | $(if on_darwin; then 213 | echo " echo \"shell=@\$($ps -p\$\$ -ocommand|$sed -n '2p'|$cut -d ' ' -f1)\"" 214 | elif $(command -v readlink \&>/dev/null); then 215 | echo " echo \"shell=@\$(readlink /proc/\$\$/exe)\"" 216 | else 217 | echo " echo \"shell=@\$($ls -l /proc/\$\$/exe | $sed 's#.*->[ ]*\(.*\)#\1#g')\"" 218 | fi) 219 | $printf "cc-env.sh=@" 220 | if [ -f "\${HOME}/.nore/cc-env.sh" ]; then 221 | $printf "\${HOME}/.nore/cc-env.sh\n" 222 | else 223 | $printf "\n" 224 | fi 225 | $(if on_windows_nt; then 226 | echo " $printf \"cc-env.bat=@\"" 227 | echo " if [ -f \"\${HOME}/.nore/cc-env.bat\" ]; then" 228 | echo " $printf \"\${HOME}/.nore/cc-env.bat\n\"" 229 | echo " else" 230 | echo " $printf \"\\n\"" 231 | echo " fi" 232 | fi) 233 | $printf "cc-inc.lst=@" 234 | if [ -f "\${HOME}/.nore/cc-inc.lst" ]; then 235 | $printf "\${HOME}/.nore/cc-inc.lst\n" 236 | else 237 | $printf "\n" 238 | fi 239 | $printf ".exrc=@" 240 | if [ -f "\${HOME}/.exrc" ]; then 241 | $printf "\${HOME}/.exrc\n" 242 | else 243 | $printf "\n" 244 | fi 245 | $printf "init.vim=@" 246 | if [ -f "\${HOME}/.config/nvim/init.vim" ]; then 247 | $printf "\${HOME}/.config/nvim/init.vim" 248 | fi 249 | exit \$? 250 | ;; 251 | 252 | trace) 253 | NORE_L_CONF_TRACE="yes" 254 | ;; 255 | esac 256 | 257 | 258 | cd "\$(CDPATH= cd -- \$($dirname -- \$0) && echo \$PWD)" 259 | 260 | if [ -f \${NORE_L_CONF} ]; then 261 | case "\${NORE_L_CONF_TRACE}" in 262 | no) 263 | \$NORE_L_CONF "\$@" 264 | ;; 265 | yes) 266 | sh -x \$NORE_L_CONF \${NORE_L_CONF_OPTS} 267 | ;; 268 | esac 269 | else 270 | echo 271 | echo "!nore << no found, to fix >: configure clone" 272 | echo 273 | fi 274 | 275 | # eof 276 | 277 | END 278 | 279 | $chmod u+x "$new_conf" 280 | $mv "$new_conf" "$conf" 281 | } 282 | 283 | 284 | cat_cc_env () { 285 | local cc_env_sh="${1:-${HOME}/.nore/cc-env.sh}" 286 | local env_dir="`$dirname $cc_env_sh`" 287 | [ -d "$env_dir" ] || $mkdir -p "$env_dir" 288 | 289 | cat << END > "$cc_env_sh" 290 | #!/bin/sh 291 | #------------------------------------------------ 292 | # target: .cc-env.sh 293 | # author: Junjie Mars 294 | # generated by Nore (${GITHUB_H}/nore) 295 | #------------------------------------------------ 296 | 297 | CC_ENV_GEN="\$1" 298 | ` 299 | if on_windows_nt; then 300 | echo "CC_ENV_BAT=\\"\\\${HOME}/.nore/cc-env.bat\\"" 301 | fi 302 | ` 303 | CC_INC_LST="\${HOME}/.nore/cc-inc.lst" 304 | CC_INC_EXRC="\${HOME}/.nore/cc-inc.exrc" 305 | EXRC="\${HOME}/.exrc" 306 | 307 | 308 | delete_exrc_src () { 309 | local h="\$1" 310 | local e="\$2" 311 | local f="\$3" 312 | $(if on_darwin; then 313 | echo " local sed_opt_i=\"-i .pre\"" 314 | else 315 | echo " local sed_opt_i=\"-i.pre\"" 316 | fi) 317 | [ -f "\$f" ] || return 0 318 | $sed \$sed_opt_i "/\$h/,/\$e/d" "\$f" 319 | } 320 | ` 321 | if on_windows_nt; then 322 | echo "" 323 | echo "posix_path () { " 324 | echo " echo \\\$@ | $sed -e 's#\\\\\\\#\\\\\/#g'" 325 | echo "}" 326 | 327 | echo "" 328 | echo "find_vcvarsall () {" 329 | echo " local vswhere=\\"\\\$(posix_path \\\${PROGRAMFILES}) (x86)/Microsoft Visual Studio/Installer/vswhere.exe\\"" 330 | echo " local vcvarsall=" 331 | echo " if [ -f \\"\\\$vswhere\\" ]; then" 332 | echo " vcvarsall=\\"\\\$(\\"\\\$vswhere\\" -nologo -latest -property installationPath 2>/dev/null)\\"" 333 | echo " if [ -n \\"\\\$vcvarsall\\" ]; then" 334 | echo " vcvarsall=\\"\\\$(posix_path \\\$vcvarsall)/VC/Auxiliary/Build/vcvarsall.bat\\"" 335 | echo " if [ -f \\"\\\$vcvarsall\\" ]; then" 336 | echo " echo \\"\\\$vcvarsall\\"" 337 | echo " return 0" 338 | echo " fi" 339 | echo " fi" 340 | echo " fi" 341 | echo "" 342 | echo " vcvarsall=\\"\\\$(posix_path \\\${PROGRAMFILES}) (x86)/Microsoft Visual Studio\\"" 343 | echo " local ver=\\"\\\$($ls \\"\\\$vcvarsall\\" | $grep -E '[0-9]+' | $sort -gr | $sed 1q)\\"" 344 | echo " [ 0 -eq \\\$? ] && [ -n \\"\\\$ver\\" ] || return 1" 345 | echo "" 346 | echo " vcvarsall=\\"\\\${vcvarsall}/\\\$ver/BuildTools/VC/Auxiliary/Build/vcvarsall.bat\\"" 347 | echo " if [ -f \\"\\\$vcvarsall\\" ]; then" 348 | echo " echo \\"\\\$vcvarsall\\"" 349 | echo " return 0" 350 | echo " fi" 351 | echo " return 1" 352 | echo "}" 353 | 354 | echo "" 355 | echo "gen_cc_env_bat () {" 356 | echo " local vcvarsall=\\"\\\$(find_vcvarsall)\\"" 357 | echo " [ 0 -eq \\\$? ] || return 1" 358 | echo " local cc_env_bat=\\"\\\${CC_ENV_BAT}\\"" 359 | echo "" 360 | echo " cat << END > \\"\\\$cc_env_bat\\"" 361 | echo "@if not \\"%VSCMD_DEBUG%\\" GEQ \\"3\\" echo off" 362 | echo "REM generated by Nore (${GITHUB_H}/nore)" 363 | echo "REM" 364 | echo "" 365 | echo "set vcvarsall=\\"\\\${vcvarsall}\\"" 366 | echo "" 367 | echo "if \\"%1\\" == \\"\\" goto :\\\$(uname -m 2>/dev/null)" 368 | echo "if \\"%1\\" == \\"x86\\" goto :x86" 369 | echo "if \\"%1\\" == \\"x86_64\\" goto :x86_64" 370 | echo "" 371 | echo ":x86" 372 | echo "call %vcvarsall% x86" 373 | echo "set CC=cl" 374 | echo "set AS=ml" 375 | echo "goto :echo_inc" 376 | echo "" 377 | echo ":x86_64" 378 | echo "call %vcvarsall% x64" 379 | echo "set CC=cl" 380 | echo "set AS=ml64" 381 | echo "goto :echo_inc" 382 | echo "" 383 | echo ":echo_inc" 384 | echo "echo \\"%INCLUDE%\\" " 385 | echo "END" 386 | echo "" 387 | echo " test -f \\"\\\$cc_env_bat\\"" 388 | echo "}" 389 | fi 390 | ` 391 | 392 | gen_cc_inc_lst () { 393 | $(if on_windows_nt; then 394 | echo " [ -f \"\${CC_ENV_BAT}\" ] || return 1" 395 | echo " cat \"\${CC_ENV_BAT}\" | sed '\$d'" 396 | else 397 | echo " echo '' | cc -v -E 2>&1 >/dev/null - \\\\" 398 | echo " | $sed -n '/#include <...> search starts here:/,/End of search list./p' \\\\" 399 | echo " | $sed '1d;\$d' \\\\" 400 | echo " | $sed -e '/.*(framework directory).*/d' -e 's/^ *//' \\\\" 401 | echo " > \"\${CC_INC_LST}\"" 402 | fi) 403 | } 404 | 405 | src_cc_inc_exrc () { 406 | local cc_h="\\" nore cc inc" 407 | local cc_e="\\" eof cc inc" 408 | command -v vim >/dev/null 2>/dev/null || return 0 409 | [ -f "\${CC_INC_LST}" ] || return 1 410 | [ -f "\$EXRC" ] || $touch "\$EXRC" 411 | delete_exrc_src "\$cc_h" "\$cc_e" "\$EXRC" 412 | echo "\$cc_h" >> "\$EXRC" 413 | 414 | cat "\${CC_INC_LST}" | awk '{print "set path+=" \$0}' >> "\$EXRC" 415 | 416 | # while IFS= read -r inc; do 417 | # echo "abc_\$inc_abc 418 | # local ln=\$(echo "\$inc" | sed 's_ _\\\\\\\\\\\ _g'); 419 | # ` 420 | # if on_windows_nt; then 421 | # echo " ln=\\\$(echo \\\$ln | sed 's_\\(^[a-zA-Z]\\):_\\/\\1_g')" 422 | # fi 423 | # ` 424 | # echo "set path+=\${ln}" >> "\$CC_INC_EXRC" 425 | # done < "\${CC_INC_LST}" 426 | echo "\$cc_e" >> "\$EXRC" 427 | } 428 | 429 | gen_nvim_init () { 430 | local d="\${HOME}/.config/nvim" 431 | command -v nvim &>/dev/null || return 1 432 | [ -f "\$EXRC" ] || return 1 433 | [ ! -f "\${d}/init.vim" ] || return 1 434 | [ ! -d "\$d" ] || mkdir -p "\$d" 435 | ln -s "\$EXRC" "\${d}/init.vim" 436 | } 437 | 438 | gen_cc_tags () { 439 | [ -f "\${CC_INC_LST}" ] || return 1 440 | command -v ctags &>/dev/null || return 1 441 | ctags -a -oTAGS --langmap=c:.h.c --c-kinds=+px -R -L "\${CC_INC_LST}" 442 | } 443 | 444 | if test -n "\${CC_ENV_GEN}"; then 445 | $(if on_windows_nt; then 446 | echo " gen_cc_env_bat && gen_cc_inc_lst && src_cc_inc_exrc" 447 | else 448 | echo " gen_cc_inc_lst && src_cc_inc_exrc" 449 | echo " gen_nvim_init" 450 | echo " gen_cc_tags" 451 | fi) 452 | fi 453 | 454 | END 455 | if ! on_windows_nt; then 456 | $chmod u+x "$cc_env_sh" 457 | fi 458 | } 459 | 460 | echo_yes_or_no () { 461 | local c="$1" 462 | if [ 0 -eq $c ]; then 463 | $printf "yes\n" 464 | else 465 | $printf "no\n" 466 | fi 467 | return $c 468 | } 469 | 470 | echo_elapsed_seconds () { 471 | local begin=$1 472 | local end="$($date +%s)" 473 | $printf "\n... elpased %d seconds.\n" $(( ${end}-${begin} )) 474 | } 475 | 476 | exit_checking () { 477 | local c="$1" 478 | local b="$2" 479 | if [ 0 -ne $c ]; then 480 | echo_elapsed_seconds "$b" 481 | exit $c 482 | fi 483 | } 484 | 485 | download_gmake () { 486 | local env_dir="${1:-${HOME}/.nore}" 487 | local ver="4.2.90" 488 | local tgz="gnumake-${ver}-`$uname -m`.tar.gz" 489 | local url="${GITHUB_H}/make/releases/download/${ver}/${tgz}" 490 | local bin="${env_dir}/make.exe" 491 | local t=0 492 | 493 | [ -f "$env_dir" ] || $mkdir -p "$env_dir" 494 | [ -f "$bin" -a "GNU Make 4.2.90" = "`$bin -v &> /dev/null | $sed 1q`" ] && return 0 495 | 496 | $curl -fsL -o "${env_dir}/${tgz}" -C - "${url}" &> /dev/null 497 | t=$? 498 | if [ 33 -eq $t ]; then 499 | $curl -fsL -o "${env_dir}/${tgz}" "${url}" &> /dev/null 500 | elif [ 60 -eq $t -o 22 -eq $t ]; then 501 | [ -f "${env_dir}/${tgz}" ] && $rm "${env_dir}/${tgz}" 502 | $curl -fskL -o "${env_dir}" "${url}" &> /dev/null 503 | fi 504 | [ 0 -eq $t ] || return $t 505 | 506 | $tar xf "${env_dir}/${tgz}" -C "${env_dir}" --strip-components=1 &> /dev/null 507 | } 508 | 509 | 510 | BEGIN=`$date +%s` 511 | echo 512 | echo "configure Nore on $PLATFORM ..." 513 | echo 514 | 515 | $printf " + checking make ... " 516 | if make -v 2>&1 1>/dev/null; then 517 | echo_yes_or_no $? 518 | else 519 | echo_yes_or_no $? 520 | if `on_windows_nt`; then 521 | $printf " + downloading make ... " 522 | echo_yes_or_no `download_gmake "${HOME}/.nore"; echo $?` 523 | fi 524 | fi 525 | 526 | $printf " + checking nore ... " 527 | if check_nore; then 528 | echo_yes_or_no $? 529 | if [ "yes" = "$NORE_UPGRADE" ]; then 530 | $printf " + upgrading nore ... " 531 | echo_yes_or_no $(upgrade_nore; echo $?) 532 | exit_checking $? $BEGIN 533 | fi 534 | else 535 | echo_yes_or_no $? 536 | $printf " + cloning nore ... " 537 | echo_yes_or_no $(clone_nore; echo $?) 538 | exit_checking $? $BEGIN 539 | fi 540 | 541 | $printf " + generating configure ... " 542 | echo_yes_or_no $(cat_configure; echo $?) 543 | exit_checking $? $BEGIN 544 | 545 | $printf " + generating ~/.nore/cc-env.sh ... " 546 | echo_yes_or_no $(cat_cc_env "${HOME}/.nore/cc-env.sh"; echo $?) 547 | exit_checking $? $BEGIN 548 | 549 | echo_elapsed_seconds $BEGIN 550 | 551 | # eof 552 | -------------------------------------------------------------------------------- /README.org: -------------------------------------------------------------------------------- 1 | #+TITLE: Nore 2 | #+AUTHOR: Junjie Mars 3 | #+STARTUP: overview 4 | 5 | No More than a C build system for [[https://clang.llvm.org][clang]], [[https://gcc.gnu.org][gcc]] and [[https://www.visualstudio.com/vs/cplusplus/][msvc]]. 6 | 7 | @@html:clang, gcc and msvc@@ 8 | 9 | Let's start ... 10 | 11 | #+BEGIN_SRC sh 12 | # run bootstrap from github, it will generate a configure file in current directory 13 | $ curl https://raw.githubusercontent.com/junjiemars/nore/master/bootstrap.sh -sSfL | sh 14 | 15 | # generate a C application skeleton 16 | $ ./configure --new 17 | 18 | # build and test 19 | $ make test 20 | #+END_SRC 21 | 22 | done. 23 | 24 | 25 | - [[#story][Story]] 26 | - [[#recipe][Recipe]] 27 | - [[#editor][Editor]] 28 | - [[#troubleshoting][Troubleshoting]] 29 | 30 | * Story 31 | :PROPERTIES: 32 | :CUSTOM_ID: story 33 | :END: 34 | 35 | Why we need another C build system? 36 | 37 | Frequently, I want to know how things works in machine level, so I 38 | need to try something in C on popular platforms, but sadly, there are 39 | no handy weapons to do that. 40 | 41 | I known there are already aswsome tools exists, but the key question 42 | is how to easy build C code in varied OS by varied Compilers, among 43 | those things I just pick the most critical ones: *Make* and *Shell*. 44 | 45 | So the story begins ... 46 | - Keep things simple: classic workflow (configure, make and make 47 | install). 48 | - Write, Build, Test and Run on anywhere: Linux, Darwin, Windows. 49 | - Easy to try some new ideas but have no more unnecessaries. 50 | 51 | * Recipe 52 | :PROPERTIES: 53 | :CUSTOM_ID: recipe 54 | :END: 55 | 56 | This section describes how to use Nore in details. 57 | 58 | - [[#configuration][Configuration]] 59 | - [[#getting-started][Getting Started]] 60 | - [[#feature-testing][Feature Testing]] 61 | - [[#commands][Commands]] 62 | 63 | ** Configuration 64 | :PROPERTIES: 65 | :CUSTOM_ID: configuration 66 | :END: 67 | 68 | *** On Unix-like Platform 69 | :PROPERTIES: 70 | :CUSTOM_ID: on-unix-like-platform 71 | :END: 72 | 73 | There are no installation process just configure *sh* and *make* 74 | environment. 75 | 76 | The most simplest way to configure is go into your *C* application 77 | directory and run: 78 | 79 | #+BEGIN_SRC sh 80 | $ curl https://raw.githubusercontent.com/junjiemars/nore/master/bootstrap.sh -sSfL | sh 81 | 82 | configure Nore on Linux ... 83 | 84 | + checking make ... yes 85 | + checking nore ... yes 86 | + generating configure ... ok 87 | + generating ~/.nore/cc-env.sh ... ok 88 | 89 | ... elpased 0 seconds. 90 | #+END_SRC 91 | 92 | *** On Windows Platform 93 | :PROPERTIES: 94 | :CUSTOM_ID: on-windows-platform 95 | :END: 96 | 97 | Requirements on Windows: 98 | - Shell, because there are no *sh* by default, so we need to install 99 | one, [[https://git-scm.com/downloads][Git Bash]] easy to install and use. When installating /Git Bash/, 100 | select =unix compatible tools= option box. 101 | - MSVC environment, [[https://visualstudio.microsoft.com/downloads/#build-tools-for-visual-studio-2017][C/C++ Build Tools]] installer is enough, and select 102 | [[https://developer.microsoft.com/en-US/windows/downloads/windows-10-sdk][Windows SDK]]. 103 | 104 | In any =CMD= or =Git Bash=, run: 105 | #+BEGIN_SRC sh 106 | $ curl https://raw.githubusercontent.com/junjiemars/nore/master/bootstrap.sh -sSfL | sh 107 | 108 | configure Nore on MINGW64_NT-10.0 ... 109 | 110 | + checking make ... no 111 | + downloading make ... yes 112 | + checking nore ... yes 113 | + generating configure ... yes 114 | + generating ~/.nore/cc-env.sh ... yes 115 | 116 | ... elpased 9 seconds. 117 | 118 | # generate ~/.cc-env.bat for MSVC environment 119 | $ ~/.nore/cc-env.sh 120 | #+END_SRC 121 | 122 | Put =%USERPROFILE%\.nore= into your Windows' =%PATH%= let life more 123 | easier. 124 | 125 | /screenshots/: 126 | - [[https://github.com/junjiemars/images/blob/master/nore/bootstrap-on-windows.png][bootstrap on Windows]] 127 | - [[https://github.com/junjiemars/images/blob/master/nore/visual-studio-build-tools-2017.png][visual studio build tools 2017]] 128 | 129 | *** From Edge Branch 130 | :PROPERTIES: 131 | :CUSTOM_ID: from-edge-branch 132 | :END: 133 | 134 | If you want to try new features of Nore, try the =edge= branch. 135 | 136 | #+BEGIN_SRC sh 137 | $ curl https://raw.githubusercontent.com/junjiemars/nore/edge/bootstrap.sh -sSfL | sh -s -- --branch=edge 138 | #+END_SRC 139 | 140 | ** Getting Started 141 | :PROPERTIES: 142 | :CUSTOM_ID: getting-started 143 | :END: 144 | 145 | #+BEGIN_SRC sh 146 | $ ./configure --help 147 | #+END_SRC 148 | 149 | All Nore's options are orthographic. 150 | 151 | On Unix-like operating systems, there are no more things need to 152 | do. But on Windows, if using *MSVC* environment, we need host *MSVC* 153 | environment first. 154 | 155 | 156 | In /sh/: 157 | #+BEGIN_SRC sh 158 | # switch to cmd 159 | $ cmd 160 | 161 | REM host msvc environment 162 | > %userprofile%/.nore/cc-env.bat 163 | 164 | REM switch to sh 165 | > sh -i 166 | #+END_SRC 167 | 168 | Or in /cmd/: 169 | #+BEGIN_SRC bat 170 | REM host msvc environment 171 | > %userprofile%/.nore/cc-env.bat 172 | 173 | REM switch to sh 174 | > sh -i 175 | #+END_SRC 176 | 177 | /screenshots/: 178 | - [[https://github.com/junjiemars/images/blob/master/nore/host-msvc-env-on-windows.png][host msvc environment]] 179 | 180 | *** New a Skeleton 181 | :PROPERTIES: 182 | :CUSTOM_ID: new-a-skeleton 183 | :END: 184 | 185 | Using *--new* option to make a testable skeleton, you can easy to try 186 | some new idea from scratch. Don't warry, it is the same processing on 187 | Windows, Darwin and Linux. 188 | 189 | #+BEGIN_SRC sh 190 | # generate a new project's skeleton 191 | $ ./configure --new 192 | 193 | checking for OS 194 | + MSYS_NT-10.0 2.10.0(0.325/5/3) x86_64 195 | checking for C compiler ... yes 196 | + using Microsoft C/C++ compiler 197 | + msvc version: 19.16.27025.1 for x64 198 | checking for WinNT-10.0-x86_64 specific features 199 | 200 | creating out/Makefile 201 | + generating c.c file ... yes 202 | + generating version file ... yes 203 | + generating auto file ... yes 204 | + generating Makefile file ... yes 205 | 206 | Configuration summary 207 | platform: WinNT-10.0-x86_64 208 | compiler: msvc 19.16.27025.1 for x64 209 | symbol-table= 210 | prefix= dist 211 | out= out 212 | src= . 213 | has= . 214 | new= YES 215 | error= YES: -WX 216 | warn= YES: -W4 217 | verbose= NO 218 | debug= YES 219 | symbol= YES: -Z7 220 | arch= NO 221 | std= YES 222 | optimize= NO: -Od 223 | 224 | # after --new a skeleton, configure skeleton and make 225 | $ ./configure 226 | $ make clean test 227 | #+END_SRC 228 | 229 | /screenshots/: 230 | - [[https://github.com/junjiemars/images/blob/master/nore/new-skeleton-msvc.png][new skeleton msvc]] 231 | - [[https://github.com/junjiemars/images/blob/master/nore/new-skeleton-clang.png][new skeleton clang]] 232 | - [[https://github.com/junjiemars/images/blob/master/nore/new-skeleton-gcc.png][new skeleton gcc]] 233 | 234 | *** Configure existing one 235 | :PROPERTIES: 236 | :CUSTOM_ID: configure-existing-one 237 | :END: 238 | 239 | For existing C project 240 | 241 | #+BEGIN_SRC sh 242 | $ cd 243 | 244 | $ ./configure --src-dir= 245 | #+END_SRC 246 | 247 | *** Build and Test 248 | :PROPERTIES: 249 | :CUSTOM_ID: build-and-test 250 | :END: 251 | 252 | #+BEGIN_SRC sh 253 | $ ./configure 254 | 255 | $ make 256 | 257 | $ make test 258 | #+END_SRC 259 | 260 | Following the prompt of *configure* and *make*, change the /options/ 261 | of *configure* or modify /src/Makefile/. 262 | 263 | *** Multiple Targets 264 | :PROPERTIES: 265 | :CUSTOM_ID: multiple-targets 266 | :END: 267 | 268 | Suppose project /P/ has /A/, /B/ and /C/ three individual 269 | subprojects. And /A/, /B/ and /C/ has individual /Makefile/. The 270 | directory layout looks like: 271 | #+BEGIN_EXAMPLE 272 | P 273 | ├── src 274 | │ ├── A 275 | │ │ ├── Makefile 276 | │ │ └── ... 277 | │ ├── B 278 | │ │ ├── Makefile 279 | │ │ └── ... 280 | │ └── C 281 | │ ├── Makefile 282 | │ └── ... 283 | └── ... 284 | #+END_EXAMPLE 285 | 286 | You can make them all at once: 287 | #+BEGIN_SRC sh 288 | $ ./configure --has-A --has-B --has-C 289 | #+END_SRC 290 | 291 | *** Multiple Projects 292 | :PROPERTIES: 293 | :CUSTOM_ID: multiple-projects 294 | :END: 295 | 296 | All projects can share only one Nore clone. 297 | 298 | Suppose there are /A/, /B/ and /C/ projects, those projects sharing 299 | only one Nore clone. 300 | 301 | #+BEGIN_SRC sh 302 | # clone Nore in a directory, and annoted it as 303 | 304 | # in A project directory: 305 | $ cd 306 | $ /bootstrap.sh 307 | 308 | # in B project directory: 309 | $ cd 310 | $ /bootstrap.sh 311 | 312 | # in C project directory: 313 | $ cd 314 | $ /bootstrap.sh 315 | #+END_SRC 316 | 317 | *** Symbol Table 318 | :PROPERTIES: 319 | :CUSTOM_ID: symbol-table 320 | :END: 321 | 322 | Nore's builtin exportable symbols can be replaced via *--symbol-table* 323 | option, which let Nore easy port to existing C projects. 324 | 325 | For example: some tools annote /DARWIN/ symbol in C source code or 326 | make file as =__DARWIN__= , but the default in Nore is =DARWIN=, you 327 | can change that to =__DARWIN__=. 328 | 329 | #+BEGIN_SRC sh 330 | $ ./configure --symbol-table= 331 | 332 | # if does not existing, Nore will dump the symbol 333 | # table into it. Otherwise, Nore will import 334 | 335 | # change the then 336 | $ ./configure --symbol-table= --has- 337 | $ make clean test 338 | #+END_SRC 339 | 340 | ** Feature Testing 341 | :PROPERTIES: 342 | :CUSTOM_ID: feature-testing 343 | :END: 344 | 345 | Write a /sh/ script named /auto/ and put it into =--src-dir= 346 | directory. The errors of /auto/ will be recorded into the /auto.err/ 347 | file in your =--out-dir= directory. 348 | 349 | *** Header File Exists Testing 350 | :PROPERTIES: 351 | :CUSTOM_ID: header-file-exists-testing 352 | :END: 353 | 354 | #+BEGIN_SRC sh 355 | # check header file exiting 356 | #---------------------------------------- 357 | echo " + checking C99 header files ..." 358 | include="complex.h" . ${NORE_ROOT}/auto/include 359 | include="fenv.h" . ${NORE_ROOT}/auto/include 360 | include="inttypes.h" . ${NORE_ROOT}/auto/include 361 | include="stdint.h" . ${NORE_ROOT}/auto/include 362 | include="tgmath.h" . ${NORE_ROOT}/auto/include 363 | #+END_SRC 364 | 365 | *** Machine Feature Testing 366 | :PROPERTIES: 367 | :CUSTOM_ID: machine-feature-testing 368 | :END: 369 | 370 | #+BEGIN_SRC sh 371 | # check machine features 372 | #---------------------------------------- 373 | nm_feature="endian" 374 | nm_feature_name="nm_have_little_endian" 375 | nm_feature_run=value 376 | nm_feature_h="#include " 377 | nm_feature_flags= 378 | nm_feature_test='int i=0x11223344; 379 | char *p = (char *)&i; 380 | int le = (0x44 == *p); 381 | printf("%i", le);' 382 | . ${NORE_ROOT}/auto/feature 383 | #+END_SRC 384 | 385 | =nm_feature_run= should be =no=, =yes=, =value= and =dumb=. 386 | - =no= is the default. 387 | - =yes= will run the =nm_feature_test=. 388 | - =value= will run =nm_feature_test= and return =nm_feature_value=. 389 | - =dumb= will run =nm_feature_test= except output to screen. 390 | 391 | *** Compiler Switch Testing 392 | :PROPERTIES: 393 | :CUSTOM_ID: compiler-switch-testing 394 | :END: 395 | 396 | #+BEGIN_SRC sh 397 | # check compiler features 398 | #---------------------------------------- 399 | case "$CC_NAME" in 400 | clang) 401 | ;; 402 | gcc) 403 | nm_feature="$CC_NAME -Wl,-E|--export-dynamic" 404 | nm_feature_name= 405 | nm_feature_run=no 406 | nm_feature_h= 407 | nm_feature_flags='-Wl,-E' 408 | nm_feature_test= 409 | . ${NORE_ROOT}/auto/feature 410 | 411 | if [ yes = $nm_found ]; then 412 | flag=LDFLAGS op="+=" value=$nm_feature_flags \ 413 | . ${NORE_ROOT}/auto/make_define 414 | fi 415 | ;; 416 | msvc) 417 | ;; 418 | esac 419 | #+END_SRC 420 | 421 | *** OS Feature Testing 422 | :PROPERTIES: 423 | :CUSTOM_ID: os-feature-testing 424 | :END: 425 | 426 | #+BEGIN_SRC sh 427 | # check OS features 428 | # ---------------------------------------- 429 | case $NM_SYSTEM in 430 | Darwin|Linux) 431 | nm_feature="mmap fn" 432 | nm_feature_name="nm_have_mmap_fn" 433 | nm_feature_run=no 434 | nm_feature_h='#include ' 435 | nm_feature_flags= 436 | nm_feature_test='mmap(0, 16, 1, 0, 3, 0);' 437 | . ${NORE_ROOT}/auto/feature 438 | ;; 439 | WinNT) 440 | ;; 441 | *) 442 | ;; 443 | esac 444 | #+END_SRC 445 | 446 | *** ENV Feature Testing 447 | :PROPERTIES: 448 | :CUSTOM_ID: env-feature-testing 449 | :END: 450 | 451 | #+BEGIN_SRC sh 452 | # check ENV features 453 | # ---------------------------------------- 454 | case "$NM_SYSTEM" in 455 | Darwin) 456 | nm_feature="libuv" 457 | nm_feature_name="nm_have_libuv" 458 | nm_feature_indent=yes 459 | nm_feature_run=no 460 | nm_feature_h="#include " 461 | nm_feature_flags="`pkg-config --cflags --libs libuv`" 462 | nm_feature_test= 463 | . ${NORE_ROOT}/auto/feature 464 | ;; 465 | Linux) 466 | ;; 467 | WinNT) 468 | ;; 469 | *) 470 | ;; 471 | esac 472 | #+END_SRC 473 | 474 | ** Commands 475 | :PROPERTIES: 476 | :CUSTOM_ID: commands 477 | :END: 478 | 479 | *** where 480 | :PROPERTIES: 481 | :CUSTOM_ID: where 482 | :END: 483 | 484 | The *where* command used to review your current Nore's environment. 485 | After [[#configuration][configuration]], Nore should generate the =cc-env.sh= shell script 486 | file at your =$HOME/.nore= or =%UERPROFILE%/.nore= directory. Run 487 | =cc-env.sh= will generate some auxiliary files to help you setup your 488 | C programming environment. 489 | 490 | The =cc-env.sh= will generates the following files: 491 | - =cc-env.bat= file: only for /msvc/ on Windows 492 | - =cc-inc.lst= file: a list of C include path 493 | - =cc-inc.vimrc= file: =vimrc= file if =vim= already been instaslled 494 | 495 | 496 | On Unix-like platform, the output of *where* command looks like: 497 | #+BEGIN_SRC sh 498 | $ ~/.nore/cc-env.sh 499 | 500 | $ ./configure where 501 | NORE_ROOT=/opt/apps/c/.nore 502 | NORE_BRANCH=master 503 | configure=@./configure 504 | make=@/usr/bin/make 505 | shell=@/bin/sh 506 | cc-env.sh=@/home/ubuntu/cc-env.sh 507 | cc-inc.lst=@/home/ubuntu/cc-inc.lst 508 | cc-inc.vimrc=@/home/ubuntu/cc-inc.vimrc 509 | #+END_SRC 510 | 511 | On Windows platform, the output of *where* command looks like: 512 | #+BEGIN_SRC sh 513 | $ ~/.nore/cc-env.sh 514 | 515 | $ ./configure where 516 | NORE_ROOT=/c/opt/apps/nore 517 | NORE_BRANCH=edge 518 | configure=@./configure 519 | make=@/c/opt/open/gmake/4.2.90/make 520 | shell=@/usr/bin/sh 521 | cc-env.sh=@/c/Users/junjie/cc-env.sh 522 | cc-env.bat=@/c/Users/junjie/cc-env.bat 523 | cc-inc.lst=@/c/Users/junjie/cc-inc.lst 524 | cc-inc.vimrc=@/c/Users/junjie/cc-inc.vimrc 525 | #+END_SRC 526 | 527 | *** upgrade 528 | :PROPERTIES: 529 | :CUSTOM_ID: upgrade 530 | :END: 531 | 532 | Upgrade current Nore via *upgrade* command. 533 | 534 | #+BEGIN_SRC sh 535 | $ ./configure upgrade 536 | configure Nore on MSYS_NT-10.0 ... 537 | 538 | + checking make ... yes 539 | + checking nore ... yes 540 | + upgrading nore ... yes 541 | + generating configure ... yes 542 | + generating ~/.nore/cc-env.sh ... yes 543 | 544 | ... elpased 13 seconds. 545 | #+END_SRC 546 | 547 | *** clone 548 | :PROPERTIES: 549 | :CUSTOM_ID: clone 550 | :END: 551 | 552 | Clone the existing Nore into current directory. 553 | 554 | *** trace 555 | :PROPERTIES: 556 | :CUSTOM_ID: trace 557 | :END: 558 | 559 | Trace Nore processing. 560 | 561 | ** Examples 562 | :PROPERTIES: 563 | :CUSTOM_ID: examples 564 | :END: 565 | 566 | *** Make an executable 567 | *** Make a library 568 | *** All stages of compiling 569 | 570 | * Editor 571 | :PROPERTIES: 572 | :CUSTOM_ID: editor 573 | :END: 574 | 575 | This section introduces how Nore interactive with your favored 576 | Editors. 577 | 578 | ** Vim 579 | :PROPERTIES: 580 | :CUSTOM_ID: vim 581 | :END: 582 | 583 | On any platform, don't warry about C include path, Nore should 584 | generate a /shell script/ named =~/.nore/cc-env.sh= for you (for 585 | details see [[#where][where]] command). 586 | 587 | ** Emacs 588 | :PROPERTIES: 589 | :CUSTOM_ID: emacs 590 | :END: 591 | 592 | On any Unix-like platform: 593 | - @@html:@@M-x shell-command /configure 594 | --has-x@@html:@@ 595 | - @@html:@@M-x compile make -C clean 596 | test@@html:@@ 597 | 598 | 599 | On Window: 600 | - @@html:@@M-x shell-command cc-env.bat && sh 601 | /configure --has-x@@html:@@ or 602 | @@html:@@M-x compile cc-env.bat && sh 603 | /configure --has-x@@html:@@ 604 | - @@html:@@M-x compile cc-env.bat && make -C 605 | clean test@@html:@@ 606 | 607 | 608 | [[https://github.com/junjiemars/.emacs.d][Nore Emacs]] has awsome C programming experience, including C 609 | source code and makefile editing, syntax highlight, auto completion, 610 | interactive debugger(gdb, lldb, cdb), interactive shell, all those 611 | excellently smooth. 612 | 613 | ** Visual Stduio Code 614 | :PROPERTIES: 615 | :CUSTOM_ID: visual-studio-code 616 | :END: 617 | 618 | * Troubleshoting 619 | :PROPERTIES: 620 | :CUSTOM_ID: troubleshoting 621 | :END: 622 | 623 | Troubleshotting is more easier than other ones, because merely 624 | Makefile and shell script. And Nore provides a command for debugging 625 | purpose. 626 | 627 | #+BEGIN_SRC sh 628 | # review out/auto.err 629 | $ less out/auto.err 630 | 631 | # review out/Makefile 632 | $ less out/Makefile 633 | 634 | # trace Nore processing 635 | $ ./configure trace 636 | $ ./configure trace --without-error 637 | 638 | # make debugging options: --just-print --print-data-base --warn-undefined-variables --debug=b 639 | $ make --just-print 640 | #+END_SRC 641 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | --------------------------------------------------------------------------------