Initial commit
This commit is contained in:
commit
19b21f65d5
|
@ -0,0 +1,37 @@
|
||||||
|
include common.mk
|
||||||
|
|
||||||
|
all: server
|
||||||
|
|
||||||
|
server: $(BUILD_DIR)/server/main.o
|
||||||
|
$(COMPILE_EXE)
|
||||||
|
|
||||||
|
run: server
|
||||||
|
./$< $(RUN_ARGS)
|
||||||
|
|
||||||
|
$(BUILD_DIR)/%.o: $(BUILD_DIR)/%.c.deps.mk
|
||||||
|
$(MAKE) -f $(BUILD_DIR)/$*.c.deps.mk $(MFLAGS) $(MAKEOVERRIDES) $@ $(BUILD_DIR)/$*.c.deps.mk
|
||||||
|
|
||||||
|
$(BUILD_DIR)/%.c.deps.mk: $(SRC_DIR)/%.c
|
||||||
|
$(ENSURE_DIR)
|
||||||
|
echo include common.mk > $@
|
||||||
|
@printf '%s: ' "$@" >> $@
|
||||||
|
@# SIC: not `read -r`
|
||||||
|
@$(CPP) $(CPPFLAGS) -M $(SRC_DIR)/$*.c | { read target deps; echo "$$deps" ;} >> $@
|
||||||
|
@echo ' rm $@' >> $@
|
||||||
|
@echo ' $$(MAKE) -f Makefile $$(MFLAGS) $$(MAKEOVERRIDES) $@' >> $@
|
||||||
|
@printf '%s/%s' "$(BUILD_DIR)" "$(dir $*)" >> $@
|
||||||
|
$(CPP) $(CPPFLAGS) -M $(SRC_DIR)/$*.c >> $@
|
||||||
|
echo ' $(CC) -c $$< $$(CPPFLAGS) $$(CFLAGS) $$(INCPATH) -o $$@' >> $@
|
||||||
|
|
||||||
|
ifneq ($(BUILD_DIR),)
|
||||||
|
# Avoid `rm /`
|
||||||
|
clean:
|
||||||
|
-rm main $(BUILD_DIR)/*.o $(BUILD_DIR)/*.deps.mk
|
||||||
|
endif
|
||||||
|
|
||||||
|
.PHONY: $(shell find $(BUILD_DIR) -name '*.deps.mk')
|
||||||
|
.PHONY: all run clean
|
||||||
|
|
||||||
|
.PRECIOUS: $(BUILD_DIR)/%.deps.mk $(shell find $(BUILD_DIR) -name '*.deps.mk')
|
||||||
|
.SECONDARY:
|
||||||
|
.SUFFIXES:
|
|
@ -0,0 +1,37 @@
|
||||||
|
DEPS =
|
||||||
|
SRC_DIR = src
|
||||||
|
BUILD_DIR = build
|
||||||
|
|
||||||
|
ifdef ARCH
|
||||||
|
CROSS_COMPILE ?= $(ARCH)-linux-gnu-
|
||||||
|
endif
|
||||||
|
ifdef CROSS_COMPILE
|
||||||
|
# FIXME we need something between `=` and `?=` that does not respect builtins, but respects MAKEOVERRIDES
|
||||||
|
CC = $(CROSS_COMPILE)gcc
|
||||||
|
CPP = $(CROSS_COMPILE)cpp
|
||||||
|
CXX = $(CROSS_COMPILE)g++
|
||||||
|
AR = $(CROSS_COMPILE)ar
|
||||||
|
AS = $(CROSS_COMPILE)as
|
||||||
|
endif
|
||||||
|
LD ?= $(CROSS_COMPILE)ld
|
||||||
|
NM ?= $(CROSS_COMPILE)nm
|
||||||
|
OBJCOPY ?= $(CROSS_COMPILE)objcopy
|
||||||
|
OBJDUMP ?= $(CROSS_COMPILE)objdump
|
||||||
|
STRIP ?= $(CROSS_COMPILE)strip
|
||||||
|
PKGCONFIG ?= $(CROSS_COMPILE)pkg-config
|
||||||
|
|
||||||
|
CFLAGS = -Wall -Wextra
|
||||||
|
ifdef DEBUG
|
||||||
|
CFLAGS += -Og -gdwarf-2
|
||||||
|
CPPFLAGS += -D DEBUG
|
||||||
|
else
|
||||||
|
CFLAGS += -O2
|
||||||
|
endif
|
||||||
|
ifneq ($(strip $(DEPS)),)
|
||||||
|
CPPFLAGS += $(shell $(PKGCONFIG) --cflags $(DEPS))
|
||||||
|
LDLIBS += $(shell $(PKGCONFIG) --libs $(DEPS))
|
||||||
|
endif
|
||||||
|
INCPATH += -iquote $(SRC_DIR)
|
||||||
|
ENSURE_DIR = mkdir -p $(shell dirname "$@")
|
||||||
|
COMPILE_EXE = $(CC) $(LDFLAGS) $^ $(LOADLIBES) $(LDLIBS) -o $@
|
||||||
|
COMPILE_DLL = $(CC) -shared $(LDFLAGS) $^ $(LOADLIBES) $(LDLIBS) -o $@
|
|
@ -0,0 +1,12 @@
|
||||||
|
#include "main.h"
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
int
|
||||||
|
main(int argc, char **argv)
|
||||||
|
{
|
||||||
|
(void) argc;
|
||||||
|
(void) argv;
|
||||||
|
printf("Hello, server!\n");
|
||||||
|
return 0;
|
||||||
|
}
|
|
@ -0,0 +1,6 @@
|
||||||
|
#ifndef SERVER_MAIN_H_
|
||||||
|
#define SERVER_MAIN_H_
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* end of include guard: SERVER_MAIN_H_ */
|
Loading…
Reference in New Issue