Revision 0d9153dc34ee2dcf0821e3f21e825fc5bb8895b4 authored by Santiago Zanella-Beguelin on 11 December 2019, 17:46:08 UTC, committed by Santiago Zanella-Beguelin on 12 December 2019, 10:33:01 UTC
1 parent 7405f78
Raw File
Makefile.basic
# A basic Makefile that KreMLin copies in the output directory; this is not
# guaranteed to work and will only work well for very simple projects. This
# Makefile uses:
# - the custom C files passed to your krml invocation
# - the custom C flags passed to your krml invocation
# - the -o option passed to your krml invocation

include Makefile.include

ifeq (,$(KREMLIN_HOME))
  $(error please define KREMLIN_HOME to point to the root of your KReMLin git checkout)
endif

CFLAGS 	+= -I. -I $(KREMLIN_HOME)/include -I $(KREMLIN_HOME)/kremlib/dist/minimal
CFLAGS 	+= -Wall -Wextra -Werror -std=c11 -Wno-unused-variable \
  -Wno-unknown-warning-option -Wno-unused-but-set-variable \
  -Wno-unused-parameter -Wno-infinite-recursion \
  -g -fwrapv -D_BSD_SOURCE -D_DEFAULT_SOURCE
ifeq ($(OS),Windows_NT)
CFLAGS 	+= -D__USE_MINGW_ANSI_STDIO
else
CFLAGS 	+= -fPIC
endif
CFLAGS 	+= $(USER_CFLAGS)

SOURCES += $(ALL_C_FILES) $(USER_C_FILES)
OBJS 	+= $(patsubst %.c,%.o,$(SOURCES))

all: $(USER_TARGET)

$(USER_TARGET): $(OBJS)

AR ?= ar

%.a:
	$(AR) cr $@ $^

%.exe:
	$(CC) $(CFLAGS) -o $@ $^ $(KREMLIN_HOME)/kremlib/dist/generic/libkremlib.a

%.so:
	$(CC) $(CFLAGS) -shared -o $@ $^

%.d: %.c
	@set -e; rm -f $@; \
	  $(CC) -MM $(CFLAGS) $< > $@.$$$$; \
	  sed 's,\($(notdir $*)\)\.o[ :]*,$(dir $@)\1.o $@ : ,g' < $@.$$$$ > $@; \
	  rm -f $@.$$$$

include $(patsubst %.c,%.d,$(SOURCES))

clean:
	rm -rf *.o *.d $(USER_TARGET)
back to top