Skip to content

Instantly share code, notes, and snippets.

@bacongobbler
Created February 12, 2018 00:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bacongobbler/92d2cab46e236623967dc9a61d7cb0a8 to your computer and use it in GitHub Desktop.
Save bacongobbler/92d2cab46e236623967dc9a61d7cb0a8 to your computer and use it in GitHub Desktop.
CC=gcc
CFLAGS=-lm
ODIR=obj
BINDIR=bin
HOST_OS := $(shell uname -s 2>/dev/null | tr "[:upper:]" "[:lower:]")
TARGET_OS ?= $(HOST_OS)
HOST_ARCH := $(shell uname -m)
TARGET_ARCH ?= $(HOST_ARCH)
ifeq ($(TARGET_ARCH),x86_64)
TARGET_ARCH = amd64
endif
all: $(BINDIR)/helloworld-$(TARGET_OS)-$(TARGET_ARCH)
$(ODIR)/%.o: %.c
mkdir -p $(ODIR)
$(CC) -c -o $@ $^ $(CFLAGS)
$(BINDIR)/%-$(TARGET_OS)-$(TARGET_ARCH): $(ODIR)/%.o
mkdir -p $(BINDIR)
$(CC) -o $@ $^ $(CFLAGS)
clean:
rm -rf $(ODIR) $(BINDIR)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment