|
1 | 1 | # Makefile |
2 | 2 |
|
| 3 | +# This is the default target: |
3 | 4 | .DEFAULT_GOAL := all |
4 | | - |
5 | 5 | .PHONY: all |
6 | 6 | all: build-library build-executable |
7 | 7 |
|
| 8 | +# ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
| 9 | + |
| 10 | +# The user can override these to use custom locations for Julia and/or GCC: |
8 | 11 | JULIA ?= julia |
9 | 12 | GCC ?= gcc |
10 | 13 |
|
| 14 | +# We automatically compute DLEXT: |
11 | 15 | DLEXT := $(shell $(JULIA) --startup-file=no -e 'import Libdl; print(Libdl.dlext)') |
12 | 16 |
|
| 17 | +# Define TARGET in one place, so that we don't need to keep retyping it. |
13 | 18 | TARGET="MyLibCompiled" |
14 | 19 |
|
| 20 | +# ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
| 21 | + |
| 22 | +# build-library and build-executable are just for convenience: |
| 23 | + |
| 24 | +.PHONY: build-library |
| 25 | +build-library: $(TARGET)/lib/libmylib.$(DLEXT) |
| 26 | + |
| 27 | +.PHONY: build-executable |
| 28 | +build-executable: my_application.out |
| 29 | + |
| 30 | +# ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
| 31 | + |
| 32 | +.PHONY: clean |
| 33 | +clean: |
| 34 | + $(RM) *.o |
| 35 | + $(RM) *.out |
| 36 | + $(RM) *.$(DLEXT) |
| 37 | + $(RM) -rf $(TARGET) |
| 38 | + |
| 39 | +# ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
| 40 | + |
| 41 | +# Library: |
| 42 | + |
15 | 43 | MYLIB_INCLUDES = $(TARGET)/include/julia_init.h $(TARGET)/include/mylib.h |
16 | 44 | MYLIB_PATH := $(TARGET)/lib/libmylib.$(DLEXT) |
17 | 45 |
|
| 46 | +# We split this up into multiple lines, just so that we don't end up with a single really long line. |
18 | 47 | DEPS_build_library := src/MyLib.jl |
19 | 48 | DEPS_build_library += build/build.jl |
20 | 49 | DEPS_build_library += build/generate_precompile.jl build/additional_precompile.jl |
21 | 50 | DEPS_build_library += build/mylib.h |
22 | 51 | DEPS_build_library += build/Project.toml build/Manifest.toml |
23 | 52 |
|
24 | | -.PHONY: build-library |
25 | | -build-library: MyLibCompiled/lib/libmylib.dylib |
26 | | - |
27 | | -MyLibCompiled/lib/libmylib.dylib: $(DEPS_build_library) |
| 53 | +$(TARGET)/lib/libmylib.$(DLEXT): $(DEPS_build_library) |
28 | 54 | $(JULIA) --startup-file=no --project=. -e 'import Pkg; Pkg.instantiate(); Pkg.precompile()' |
29 | 55 | $(JULIA) --startup-file=no --project=build -e 'import Pkg; Pkg.instantiate(); Pkg.precompile()' |
30 | 56 | $(JULIA) --startup-file=no --project=build -e 'include("build/build.jl")' |
31 | 57 |
|
32 | 58 | INCLUDE_DIR = $(TARGET)/include |
33 | 59 |
|
34 | | -.PHONY: build-executable |
35 | | -build-executable: my_application.out |
| 60 | +# ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
| 61 | + |
| 62 | +# Application (my_application.out): |
36 | 63 |
|
37 | | -my_application.out: MyLibCompiled/lib/libmylib.dylib |
| 64 | +my_application.out: $(TARGET)/lib/libmylib.$(DLEXT) |
38 | 65 | $(GCC) my_application.c -o my_application.out -I$(INCLUDE_DIR) -L$(TARGET)/lib -ljulia -lmylib |
39 | 66 |
|
40 | | -.PHONY: clean |
41 | | -clean: |
42 | | - $(RM) *~ *.o *.$(DLEXT) |
43 | | - $(RM) -Rf $(TARGET) |
| 67 | +# ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
0 commit comments