Menu

Home

Brad Lanam

An example using mkconfig to build a very simple program.

Makefile

# Example Makefile
#
# OBJ_EXT and EXE_EXT are used for portability to windows.
#

MKC_DIR = ../..
OBJ_EXT = .o
EXE_EXT =
MKC_REQLIB = hello.reqlibs

# executable
hello$(EXE_EXT):                $(MKC_REQLIB) hello$(OBJ_EXT)
        @. ./hello.env;$(_MKCONFIG_SHELL) \
                $(MKC_DIR)/mkc.sh -link -exec -r $(MKC_REQLIB) \
                -o hello$(EXE_EXT) hello$(OBJ_EXT)

# object files
hello$(OBJ_EXT):        config.h
        @. ./hello.env;$(_MKCONFIG_SHELL) $(MKC_DIR)/mkc.sh -compile \
                -o hello$(OBJ_EXT) hello.c

# required libraries
# for this example, there are none.
$(MKC_REQLIB):  config.h
        @$(_MKCONFIG_SHELL) $(MKC_DIR)/mkc.sh -reqlib \
                -o $(MKC_REQLIB) config.h

# config.h file created by mkconfig
config.h:       hello.env hello.mkc
        . ./hello.env; \
                CC=$(CC) $(_MKCONFIG_SHELL) $(MKC_DIR)/mkconfig.sh hello.mkc

# environment variables created by mkconfig
hello.env:      env.mkc
        CC=$(CC) $(_MKCONFIG_SHELL) $(MKC_DIR)/mkconfig.sh env.mkc

.PHONY: clean
clean:
        @-rm -f mkc_* mkconfig.cache mkconfig.log \
                hello.env config.h $(MKC_REQLIB) \
                hello$(EXE_EXT) hello$(OBJ_EXT) \
                *~

hello.c

#include "config.h"

#include <stdio.h>
#include <stdlib.h>
#ifdef _hdr_string
# include <string.h>
#endif

int main (int argc, char *argv[])
{
  printf ("hello world\n");
}

env.mkc

# configuration to set up the build environment

loadunit env-main
loadunit env-systype
loadunit env-cc
loadunit env-extension

output  hello.env

# starting with version 2.4 only standard_system is needed
standard_system
# starting with version 2.4 only standard_cc is needed
standard_cc
libs
extension obj
extension exe

hello.mkc

# configuration for hello.c

loadunit c-main
output config.h

standard

hdr string.h