diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..ba7e14f --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "libraries/lwcell"] + path = libraries/lwcell + url = https://github.com/MaJerle/lwcell diff --git a/libraries/lwcell b/libraries/lwcell new file mode 160000 index 0000000..422e7ab --- /dev/null +++ b/libraries/lwcell @@ -0,0 +1 @@ +Subproject commit 422e7ab289ab2d8cc37f93d92ee1dbaabaaf37c2 diff --git a/makefile b/makefile new file mode 100644 index 0000000..6ee432c --- /dev/null +++ b/makefile @@ -0,0 +1,70 @@ +CC = gcc +CFLAGS = -Wall -Wextra -std=c11 +LIBRARIES= -L ./libraries/lwcell/build -l lwcell.so -lm +INCLUDES = -I ./source -I ./libraries/lwcell/include + +# define variable for our dependencies' Makefiles. +# we use find to grab only the top level Makefiles and also some convenient ignores. +DEPENDENCIES = $(shell find ./deps -maxdepth 2 -name Makefile -printf '%h\n' | grep -v 'unittest' | grep -v '^.$$') + +SOURCES = $(shell find ./source -name '*.c') + +SRC = source +OBJ = objects +BIN = bin +TARGET = root + +PREFIX ?= /usr/local + +# Debug +ifeq ($(DEBUG), 1) + CFLAGS += -DDEBUG=1 -ggdb +endif + +# Release +ifeq ($(RELEASE), 1) + CFLAGS += -O2 +endif + +# Shared +ifeq ($(SHARED), 1) + SOURCES=$(shell find ./$(SRC)/libraries -name '*.c') + TARGET=my_lib +endif + +OBJECTS = $(addprefix $(OBJ)/,$(SOURCES:%.c=%.o)) + +.PHONY: all +all: dependencies source + +.PHONY: dependencies +dependencies: + git -C ./libraries/lwcell pull + +.PHONY: source +source: $(OBJECTS) + @mkdir -p $(BIN) +ifeq ($(SHARED), 1) + $(CC) -shared -fPIC -o $(BIN)/$(TARGET).so $^ $(LIBRARIES) + ar -rcs $(BIN)/$(TARGET).a $^ +else + $(CC) $(CFLAGS) $(LIBRARIES) $^ -o $(BIN)/$(TARGET) +endif + # $(CC) -o $(TARGET) $(OBJECTS) $(CFLAGS) + +$(OBJ)/%.o: %.c + @mkdir -p $(dir $@) + $(CC) -c -o $@ $< $(CFLAGS) $(INCLUDES) + +.PHONY: clean +clean: + @rm -rf $(OBJ)/* 2> /dev/null + @rm -f $(BIN)/* 2> /dev/null + +# .PHONY: install +# install: +# install $(TARGET) $(PREFIX)/bin + +# .PHONY: uninstall +# uninstall: +# @rm -f $(PREFIX)/bin/$(TARGET) 2> /dev/null diff --git a/source/main.c b/source/main.c new file mode 100644 index 0000000..4917a92 --- /dev/null +++ b/source/main.c @@ -0,0 +1,6 @@ +#include + +int main() { + printf("Hello World!\n"); + return 0; +} diff --git a/source/test b/source/test new file mode 100755 index 0000000..034fec9 Binary files /dev/null and b/source/test differ