Documentation of CSL
libmakefile_data.h
Go to the documentation of this file.
1 // This file is part of MARTY.
2 //
3 // MARTY is free software: you can redistribute it and/or modify
4 // it under the terms of the GNU General Public License as published by
5 // the Free Software Foundation, either version 3 of the License, or
6 // (at your option) any later version.
7 //
8 // MARTY is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU General Public License for more details.
12 //
13 // You should have received a copy of the GNU General Public License
14 // along with MARTY. If not, see <https://www.gnu.org/licenses/>.
15 
23 #pragma once
24 
25 #include <iostream>
26 
27 void print_libmakefile_data(std::ostream &out, bool quad, bool clang) {
28  out << "# Part common to all libraries generated by CSL\n";
29  out << "\n";
30  if (clang) {
31  out << "CXX = clang++\n";
32  out << "MATH_OPTI = -ffast-math\n";
33  }
34  else {
35  out << "CXX = g++\n";
36 #if defined(__APPLE__) || defined(__MACH__)
37  out << "MATH_OPTI = -ffast-math\n";
38 #else
39  out << "MATH_OPTI = \\\n"
40  "\t\t-fno-math-errno\\\n"
41  "\t\t-ffinite-math-only\\\n"
42  "\t\t-fno-rounding-math\\\n"
43  "\t\t-fno-signaling-nans\\\n"
44  "\t\t-fcx-limited-range\\\n"
45  "\t\t-fexcess-precision=fast\\\n"
46  "\t\t-fno-signed-zeros\\\n"
47  "\t\t-fno-trapping-math\\\n"
48  "\t\t-fassociative-math\\\n"
49  "\t\t-freciprocal-math\n\n";
50 #endif
51  }
52  out << "DEFAULTFLAGS = -std=c++17 -Wall -Wextra -Wpedantic -Wno-deprecated-declarations -fPIC\n";
53  out << "OPTIFLAGS = -O2 $(MATH_OPTI)\n";
54  if (!quad) {
55  out << "CXXFLAGS = $(DEFAULTFLAGS) $(OPTIFLAGS)\n";
56  out << "LINKFLAGS = $(DEFAULTFLAGS)\n";
57  }
58  else {
59  out << "QUADFLAGS = -DQUAD=1 -DQUADSIZE=16\n";
60  out << "CXXFLAGS = $(DEFAULTFLAGS) $(OPTIFLAGS) $(QUADFLAGS)\n";
61  out << "LINKFLAGS = $(DEFAULTFLAGS) $(QUADFLAGS)\n";
62  }
63  out << "\n";
64  out << "SRCDIR = src\n";
65  out << "INCDIR = include\n";
66  out << "OBJDIR = obj\n";
67  out << "SCRIPTDIR = script\n";
68  out << "SOBJDIR = script/obj\n";
69  out << "BINDIR = bin\n";
70  out << "LIBDIR = lib\n";
71  out << "\n";
72  out << "SRC = $(wildcard $(SRCDIR)/*.cpp)\n";
73  out << "HEADERS = $(wildcard $(INCDIR)/*.h)\n";
74  out << "OBJ_INIT = $(SRC:$(SRCDIR)/%.cpp=$(OBJDIR)/%.o)\n";
75  out << "OBJ = $(filter-out $(OBJDIR)/$(NAME)_pylink.o, $(OBJ_INIT))\n";
76  out << "SCRIPTS = $(wildcard $(SCRIPTDIR)/*.cpp)\n";
77  out << "BINARIES = $(SCRIPTS:$(SCRIPTDIR)/%.cpp=%.x)\n";
78  out << "SOBJ = $(SCRIPTS:$(SCRIPTDIR)/%.cpp=$(SOBJDIR)/%.o)\n";
79  out << "\n";
80  out << "all: scripts lib\n";
81  out << "\n";
82  out << "scripts: $(BINARIES)\n";
83  out << "lib: $(NAMELIB).so $(NAMELIB).a\n";
84  out << "\n";
85  out << "$(OBJDIR)/%.o: $(SRCDIR)/%.cpp\n";
86  out << " $(CXX) $(CXXFLAGS) -c $< -o $@ $(INCPATH)\n";
87  out << "\n";
88  out << "$(SOBJDIR)/%.o: $(SCRIPTDIR)/%.cpp\n";
89  out << " $(CXX) $(CXXFLAGS) -c $< -o $@ $(INCPATH)\n";
90  out << "\n";
91  out << "%.x: $(SOBJDIR)/%.o $(OBJ)\n";
92  out << " $(CXX) $(LINKFLAGS) -o $(BINDIR)/$@ $< $(OBJ) $(INCPATH) $(LIBPATH) $(LIBS)\n";
93  out << "\n";
94  out << "$(NAMELIB).so: $(OBJ)\n";
95  out << " $(CXX) $(CXXFLAGS) -shared -o $(LIBDIR)/$@ $(OBJ) $(LIBPATH) $(LIBS)\n";
96  out << "$(NAMELIB).a: $(OBJ)\n";
97  out << " ar rcs $(LIBDIR)/$@ $(OBJ)\n";
98  out << "\n";
99  out << "clean:\n";
100  out << " rm $(OBJDIR)/*.o\n";
101  out << "Clean:\n";
102  out << " $(MAKE) clean\n";
103  out << " rm $(BINDIR)/*.x\n";
104 }