-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
154 lines (109 loc) · 6.09 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
###############################################################################
# Parutil
# Multi-platform library of parallelized utility functions.
###############################################################################
# Authored by Samuel Grossman
# Department of Electrical Engineering, Stanford University
# Copyright (c) 2016-2017
###############################################################################
# Makefile
# Build script for GNU-compatible Linux operating systems.
###############################################################################
# --------- PROJECT PROPERTIES ------------------------------------------------
PROJECT_NAME = parutil
PLATFORM_NAME = linux
SOURCE_DIR = source
INCLUDE_DIR = include/$(PROJECT_NAME)
ASSEMBLY_SOURCE_DIR = $(OUTPUT_DIR)/asm/source
ASSEMBLY_INCLUDE_DIR = $(OUTPUT_DIR)/asm/include
OUTPUT_BASE_DIR = output
OUTPUT_DOCS_DIR = $(OUTPUT_BASE_DIR)/docs
OUTPUT_DIR = $(OUTPUT_BASE_DIR)/$(PLATFORM_NAME)
OUTPUT_FILE = lib$(PROJECT_NAME).a
INTERMEDIATE_DIR = $(OUTPUT_DIR)/build
C_SOURCE_SUFFIX = .c
CXX_SOURCE_SUFFIX = .cpp
MASM_SOURCE_SUFFIX = .asm
MASM_HEADER_SUFFIX = .inc
ASSEMBLY_SOURCE_SUFFIX = .s
ASSEMBLY_HEADER_SUFFIX = .S
# --------- TOOL SELECTION AND CONFIGURATION ----------------------------------
CC = gcc
CXX = g++
AS = as
AR = ar
CCFLAGS = -O3 -Wall -fPIC -std=c11 -masm=intel -march=core-avx-i -mno-vzeroupper -I$(INCLUDE_DIR) -D_GNU_SOURCE -DPARUTIL_LINUX
CXXFLAGS = -O3 -Wall -fPIC -std=c++0x -masm=intel -march=core-avx-i -mno-vzeroupper -I$(INCLUDE_DIR) -DPARUTIL_LINUX
ASFLAGS = --64 -mmnemonic=intel -msyntax=intel -mnaked-reg -I$(ASSEMBLY_INCLUDE_DIR) --defsym PARUTIL_LINUX=1
ARFLAGS =
# --------- FILE ENUMERATION --------------------------------------------------
OBJECT_FILE_SUFFIX = .o
DEP_FILE_SUFFIX = .d
C_SOURCE_FILES = $(filter-out $(wildcard $(SOURCE_DIR)/*-*$(C_SOURCE_SUFFIX)), $(wildcard $(SOURCE_DIR)/*$(C_SOURCE_SUFFIX))) $(wildcard $(SOURCE_DIR)/*-$(PLATFORM_NAME)$(C_SOURCE_SUFFIX))
CXX_SOURCE_FILES = $(filter-out $(wildcard $(SOURCE_DIR)/*-*$(CXX_SOURCE_SUFFIX)), $(wildcard $(SOURCE_DIR)/*$(CXX_SOURCE_SUFFIX))) $(wildcard $(SOURCE_DIR)/*-$(PLATFORM_NAME)$(CXX_SOURCE_SUFFIX))
ALL_SOURCE_FILES = $(C_SOURCE_FILES) $(CXX_SOURCE_FILES)
MASM_SOURCE_FILES = $(wildcard $(SOURCE_DIR)/*$(MASM_SOURCE_SUFFIX))
MASM_HEADER_FILES = $(wildcard $(INCLUDE_DIR)/*$(MASM_HEADER_SUFFIX))
ASSEMBLY_SOURCE_FILES = $(patsubst $(SOURCE_DIR)/%$(MASM_SOURCE_SUFFIX), $(ASSEMBLY_SOURCE_DIR)/%$(ASSEMBLY_SOURCE_SUFFIX), $(MASM_SOURCE_FILES))
ASSEMBLY_HEADER_FILES = $(patsubst $(INCLUDE_DIR)/%$(MASM_HEADER_SUFFIX), $(ASSEMBLY_INCLUDE_DIR)/%$(ASSEMBLY_HEADER_SUFFIX), $(MASM_HEADER_FILES))
OBJECT_FILES_FROM_SOURCE = $(patsubst $(SOURCE_DIR)/%, $(INTERMEDIATE_DIR)/%$(OBJECT_FILE_SUFFIX), $(ALL_SOURCE_FILES))
OBJECT_FILES_FROM_ASSEMBLY = $(patsubst $(ASSEMBLY_SOURCE_DIR)/%, $(INTERMEDIATE_DIR)/%$(OBJECT_FILE_SUFFIX), $(ASSEMBLY_SOURCE_FILES))
DEP_FILES_FROM_SOURCE = $(patsubst $(SOURCE_DIR)/%, $(INTERMEDIATE_DIR)/%$(DEP_FILE_SUFFIX), $(ALL_SOURCE_FILES))
# --------- TOP-LEVEL RULE CONFIGURATION --------------------------------------
.PHONY: parutil docs clean help
.SECONDARY: $(ASSEMBLY_SOURCE_FILES) $(ASSEMBLY_HEADER_FILES)
# --------- TARGET DEFINITIONS ------------------------------------------------
parutil: $(OUTPUT_DIR)/$(OUTPUT_FILE)
docs: | $(OUTPUT_DOCS_DIR)
@doxygen
help:
@echo ''
@echo 'Usage: make [target]'
@echo ''
@echo 'Targets:'
@echo ' parutil'
@echo ' Default target.'
@echo ' Builds Parutil as a static library.'
@echo ' docs'
@echo ' Builds HTML and LaTeX documentation using Doxygen.'
@echo ' clean'
@echo ' Removes all output files, including binary and documentation.'
@echo ' help'
@echo ' Shows this information.'
@echo ''
# --------- BUILDING AND CLEANING RULES ---------------------------------------
$(OUTPUT_DIR)/$(OUTPUT_FILE): $(OBJECT_FILES_FROM_SOURCE) $(OBJECT_FILES_FROM_ASSEMBLY)
@echo ' AR $@'
@$(AR) $(ARFLAGS) rcs $@ $^
@echo 'Build completed: $(PROJECT_NAME).'
clean:
@echo ' RM $(OUTPUT_BASE_DIR)'
@rm -rf $(OUTPUT_BASE_DIR)
@echo 'Clean completed: $(PROJECT_NAME).'
# --------- COMPILING AND ASSEMBLING RULES ------------------------------------
$(INTERMEDIATE_DIR):
@mkdir -p $(INTERMEDIATE_DIR)
$(OUTPUT_DOCS_DIR):
@mkdir -p $(OUTPUT_DOCS_DIR)
$(INTERMEDIATE_DIR)/%$(ASSEMBLY_SOURCE_SUFFIX)$(OBJECT_FILE_SUFFIX): $(ASSEMBLY_SOURCE_DIR)/%$(ASSEMBLY_SOURCE_SUFFIX) $(ASSEMBLY_HEADER_FILES) | $(INTERMEDIATE_DIR)
@echo ' AS $@'
@$(AS) $(ASFLAGS) $< -o $@
$(INTERMEDIATE_DIR)/%$(C_SOURCE_SUFFIX)$(OBJECT_FILE_SUFFIX): $(SOURCE_DIR)/%$(C_SOURCE_SUFFIX) | $(INTERMEDIATE_DIR)
@echo ' CC $@'
@$(CC) $(CCFLAGS) -MD -MP -c -o $@ -Wa,-adhlms=$(patsubst %$(OBJECT_FILE_SUFFIX),%$(ASSEMBLY_SOURCE_SUFFIX),$@) $<
$(INTERMEDIATE_DIR)/%$(CXX_SOURCE_SUFFIX)$(OBJECT_FILE_SUFFIX): $(SOURCE_DIR)/%$(CXX_SOURCE_SUFFIX) | $(INTERMEDIATE_DIR)
@echo ' CXX $@'
@$(CXX) $(CXXFLAGS) -MD -MP -c -o $@ -Wa,-adhlms=$(patsubst %$(OBJECT_FILE_SUFFIX),%$(ASSEMBLY_SOURCE_SUFFIX),$@) $<
-include $(DEP_FILES_FROM_SOURCE)
# --------- ASSEMBLY SOURCE FILE TRANSFORMATION RULES -------------------------
$(ASSEMBLY_SOURCE_DIR):
@mkdir -p $(ASSEMBLY_SOURCE_DIR)
$(ASSEMBLY_INCLUDE_DIR):
@mkdir -p $(ASSEMBLY_INCLUDE_DIR)
$(ASSEMBLY_SOURCE_DIR)/%$(ASSEMBLY_SOURCE_SUFFIX): $(SOURCE_DIR)/%$(MASM_SOURCE_SUFFIX) | $(ASSEMBLY_SOURCE_DIR)
@echo ' X-AS $@'
@cat $< | $(X-AS) > $@
$(ASSEMBLY_INCLUDE_DIR)/%$(ASSEMBLY_HEADER_SUFFIX): $(INCLUDE_DIR)/%$(MASM_HEADER_SUFFIX) | $(ASSEMBLY_INCLUDE_DIR)
@echo ' X-AS $@'
@cat $< | $(X-AS) > $@
-include buildhelpers/x-$(AS).mk