Skip to content
南山竹 edited this page Aug 26, 2017 · 9 revisions

Nore

No More than a C build system for clang, gcc and msvc.

Configuration

There are no installation process just setup bash and make environment.

The most simplest way to configure is into your C application directory and run

bash <(curl https://raw.githubusercontent.com/junjiemars/nore/master/bootstrap.sh)

then done.

On Windows, because there are no bash by default, so We need install Git Bash first, and select 'unix compatible tools' when installing. Run bash in any CMD or MSYS, then

bash <(curl https://raw.githubusercontent.com/junjiemars/nore/master/bootstrap.sh)

In this process, the bootstrap.sh will configuration bash environment and install GNU Make if there hadn't installed yet.

Getting start

There are an example at https://github.com/junjiemars/nore-hi,

$ git clone --depth=1 https://github.com/junjiemars/nore-hi.git

The nore-hi directory look like this:

.
├── LICENSE
├── Makefile
├── README.md
└── hi
    ├── Makefile
    ├── hi.c
    └── version

After configuration, it's look like:

.
├── LICENSE
├── Makefile (generated by Nore)
├── README.md
├── configure (generated by Nore)
└── hi
    ├── Makefile
    ├── hi.c
    └── version

Now, a story of classic workflow begins:

  • compose a Makefile, here we use hi/Makefile;
  • ./configure --has-hi --prefix=/tmp, after configured, the structure of working directory looks like:
.
├── LICENSE
├── Makefile
├── README.md
├── configure
├── hi
│   ├── Makefile
│   ├── hi.c
│   └── version
└── out (generated by Nore)
    ├── Makefile (generated by Nore base on your hi/Makefile)
    ├── autoconf.err
    ├── bin
    ├── conf
    ├── inc
    ├── lib
    ├── log
    ├── nore.h (generated by Nore)
    ├── pid
    └── tmp
  • make
  • make install

The out/Makefile be generated by Nore base on hi/Makefile

# hi/Makefile

hi_binout := $(bin_path)hi$(bin_ext)

# note: hi target has same name with the directory
hi: $(hi_binout)
hi_test: hi
	$(hi_binout)

$(hi_binout): $(src_path)hi.c 
	$(CC) $(CFLAGS) $(INC) $^ $(bin_out)$@

All elements of hi/Makefile can be found in out/makefile:

# out/Makefile (clang, MacOS)

CC = cc
CPP = $(CC)
CAS = $(CC)
AS = $(CC)
AR = ar
LINK = $(CC)

CPPFLAGS = 
CFLAGS =  -std=c99 -g -Wall -Wextra -Wpointer-arith -Wconditional-uninitialized -Wunused-variable -Wunused-parameter -Wno-error=unused-command-line-argument -Werror
ASFLAGS = 
LDLIBS = 
LDFLAGS = 
ARFLAGS = 
LFLAGS = 
YFLAGS = 

LDFLAGS = -Lout/lib

INC = -Iout -Iout/inc

nm_symbol_opt = -g
nm_optimize_opt = -O2
nm_warn_opt = -Wall -Wextra -Wpointer-arith -Wconditional-uninitialized -Wunused-variable -Wunused-parameter -Wno-error=unused-command-line-argument
nm_error_opt = -Werror
nm_debug_opt = 
nm_std_opt = -std=c99
nm_cpu_opt = 
nm_verbose_opt = -v

nm_pic_opt = 
nm_shared_opt = -dynamiclib

nm_stage_pre = -E
nm_stage_chk = -fsyntax-only
nm_stage_asm = -S
nm_stage_c = -c

# path separator
nm_p = :

src_root = ./

# nore options
NM_SYMBOL = YES
NM_OPTIMIZE = NO
NM_WARN = YES
NM_ERROR = YES
NM_DEBUG = YES
NM_VERBOSE = NO
NM_STD = YES
NM_CPU = NO

# platform
NM_SYSTEM = Darwin
NM_RELEASE = 16.7.0
NM_MACHINE = x86_64
CC_NAME = clang

# output option
cpp_out = -o 
asm_out = -o 
obj_out = -o 
lib_out = -o 
ar_out = rcs 
bin_out = -o 

# output extension
cpp_ext = .i
asm_ext = .s
obj_ext = .o
lib_ext = .dylib
ar_ext = .a
bin_ext = 


default: build

clean:
	$(RM) -r out/bin/*
	$(RM) -r out/lib/*
	$(RM) -r out/inc/*
	$(RM) -r out/log/*
	$(RM) -r out/pid/*
	$(RM) -r out/tmp/*
	$(RM) -r out/conf/*



.PHONY: hi hi_test

build: hi

test: hi_test


#---------------------------------------

hi_binout := out/bin/hi$(bin_ext)

hi: $(hi_binout)
hi_test: hi
	$(hi_binout)

$(hi_binout): ./hi/hi.c 
	$(CC) $(CFLAGS) $(INC) $^ $(bin_out)$@


#---------------------------------------


install: build /opt/run/bin /opt/run/lib /opt/run/conf /opt/run/inc
	$(call cp-if, out/bin, /opt/run/bin/)
	$(call cp-if, out/lib, /opt/run/lib/)
	$(call cp-if, out/conf, /opt/run/conf/)
	$(call cp-if, out/inc, /opt/run/inc/)


/opt/run/bin /opt/run/lib /opt/run/conf /opt/run/inc:
	$(call mkdir-if, /opt/run/bin)
	$(call mkdir-if, /opt/run/lib)
	$(call mkdir-if, /opt/run/conf)
	$(call mkdir-if, /opt/run/inc)
	$(call mkdir-if, /opt/run/log)


mkdir-if = $(if $(wildcard $1),,mkdir -p $1)
cp-if = $(foreach f,$(wildcard $1/*),$(shell cp -r $(f) $2))
Clone this wiki locally