Skip to content

Commit a487011

Browse files
authored
refactored build system (#12)
added nix packaging, and autotools support (regular make still works)
1 parent a8c0961 commit a487011

File tree

8 files changed

+177
-10
lines changed

8 files changed

+177
-10
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ build
22
obj
33
lux
44

5+
# autotools
6+
autom4te.cache
7+
58
# Linux executables (files without extensions)
69
*
710
!*/

Makefile

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,18 @@
99
# override LDFLAGS += $(LLVM_LDFLAGS)
1010

1111
# # Detect platform and define commands
12-
include config.mk
12+
include config.default.mk
1313

1414
# Detect platform and define commands
1515
ifeq ($(OS),Windows_NT)
16-
SHELL := cmd.exe
16+
SHELL ?= cmd.exe
1717
MKDIR = if not exist "$(subst /,\,$1)" mkdir "$(subst /,\,$1)"
1818
RMDIR = if exist "$(subst /,\,$1)" rmdir /s /q "$(subst /,\,$1)"
1919
DEL = if exist "$(subst /,\,$1)" del /q "$(subst /,\,$1)"
2020
EXE = .exe
2121
PATHSEP = \\
2222
else
23-
SHELL := /bin/sh
23+
SHELL ?= /bin/sh
2424
MKDIR = mkdir -p $1
2525
RMDIR = rm -rf $1
2626
DEL = rm -f $1
@@ -30,7 +30,11 @@ endif
3030

3131
BIN := luma$(EXE)
3232

33-
.PHONY: all clean debug test llvm-test
33+
ifneq ($(wildcard config.mk),)
34+
include config.mk
35+
endif
36+
37+
.PHONY: all clean debug test check llvm-test
3438

3539
all: $(BIN)
3640

@@ -48,7 +52,10 @@ debug: all
4852
# Test targets
4953
test: $(BIN)
5054
@echo "Running basic tests..."
51-
./$(BIN) --help
55+
./$(BIN) --help || true # non-zero exit code expected
56+
57+
# Alias
58+
check: test
5259

5360
llvm-test: $(BIN)
5461
@echo "Testing LLVM IR generation..."

config.mk renamed to config.default.mk

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
# config.mk
1+
# config.default.mk
22

3-
CC = g++
4-
CFLAGS = -Wall -Wextra -std=c17 -Wno-unused-variable -O2 -x c # -x c tells g++ to treat files as C code
5-
LDFLAGS =
6-
INCLUDES = -Isrc
3+
CC ?= g++
4+
CFLAGS ?= -Wall -Wextra -std=c17 -Wno-unused-variable -O2 -x c # -x c tells g++ to treat files as C code
5+
LDFLAGS ?=
6+
INCLUDES ?= -Isrc
77

88
# LLVM configuration - request all necessary components
99
LLVM_CFLAGS := $(shell llvm-config --cflags)

config.mk.in

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
CC = @CXX@
2+
CFLAGS += @CXXFLAGS@
3+
LDFLAGS += @LDFLAGS@
4+
PREFIX = @prefix@
5+
6+
INSTALL ?= install
7+
DESTDIR ?= $(PREFIX)/bin
8+
9+
.PHONY: install
10+
11+
install: $(BIN)
12+
$(INSTALL) -d $(DESTDIR)
13+
$(INSTALL) -s -m 0755 $(BIN) $(DESTDIR)/$(BIN)
14+
@echo "Installed to $(DESTDIR)/$(BIN)"

configure.ac

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
AC_INIT([luma], [git], [https://github.com/TheDevConnor/Luma])
2+
AC_PREREQ([2.69])
3+
AC_CONFIG_SRCDIR([src/main.c]) # sanity check to make sure someone didn't pass a garbage --srcdir
4+
#AM_INIT_AUTOMAKE([foreign 1.16 dist-bzip2])
5+
6+
AC_PROG_CXX
7+
AC_LANG(C++)
8+
AC_SUBST(CXX)
9+
# connor, i have no idea why you're expecting CC to be a C++ compiler.
10+
# that's what CXX is for.
11+
12+
CXXFLAGS="$CXXFLAGS $CFLAGS $CPPFLAGS" # grab any env for flags
13+
LDFLAGS="$LDFLAGS"
14+
AC_SUBST(CXXFLAGS)
15+
AC_SUBST(LDFLAGS)
16+
17+
AC_PREFIX_DEFAULT(/usr/local)
18+
AC_SUBST(prefix)
19+
20+
AC_CONFIG_FILES([config.mk])
21+
AC_OUTPUT

default.nix

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
{ stdenv
2+
, pkg-config
3+
, llvmPackages
4+
, autoconf
5+
, doxygen
6+
, graphviz-nox
7+
}:
8+
9+
llvmPackages.stdenv.mkDerivation {
10+
pname = "luma";
11+
version = "0.0.0"; # TODO: versioning
12+
13+
src = ./.;
14+
15+
nativeBuildInputs = [
16+
pkg-config
17+
autoconf
18+
doxygen
19+
graphviz-nox
20+
];
21+
22+
outputs = [
23+
"out"
24+
"doc"
25+
];
26+
27+
preConfigure = ''
28+
autoconf
29+
'';
30+
31+
postInstall = ''
32+
doxygen Doxyfile
33+
mv docs/doxygen $doc
34+
'';
35+
36+
buildInputs = [
37+
llvmPackages.libllvm
38+
];
39+
40+
doCheck = true;
41+
}

flake.lock

Lines changed: 61 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
description = "Luma";
3+
4+
inputs = {
5+
nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
6+
flake-utils.url = "github:numtide/flake-utils";
7+
};
8+
9+
outputs = { self, nixpkgs, flake-utils }: flake-utils.lib.eachDefaultSystem (system:
10+
let
11+
pkgs = nixpkgs.legacyPackages.${system};
12+
in
13+
{
14+
packages = rec {
15+
default = luma;
16+
luma = pkgs.callPackage ./default.nix { };
17+
};
18+
}
19+
);
20+
}

0 commit comments

Comments
 (0)