Skip to content
This repository was archived by the owner on Jan 31, 2025. It is now read-only.

Commit 21c24ec

Browse files
author
John D. Verne
committed
Preparation for adding a POSIX Makefile to the project
1 parent 3ce83bc commit 21c24ec

1 file changed

Lines changed: 289 additions & 0 deletions

File tree

Makefile.GNU

Lines changed: 289 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,289 @@
1+
# Makefile for nqc
2+
#
3+
# This Source Code Form is subject to the terms of the Mozilla Public
4+
# License, v. 2.0. If a copy of the MPL was not distributed with this
5+
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
6+
#
7+
# The Initial Developer of this code is David Baum.
8+
# Portions created by David Baum are Copyright (C) 1999 David Baum.
9+
# All Rights Reserved.
10+
#
11+
# Portions created by John Hansen are Copyright (C) 2005 John Hansen.
12+
# All Rights Reserved.
13+
#
14+
# original author:
15+
# Dave Baum <dbaum@enteract.com>
16+
#
17+
# other contributors:
18+
# Rodd Zurcher <rbz@enteract.com>
19+
# Patrick Nadeau <pnadeau@wave.home.com>
20+
# Jonathan W. Miner <jminer@fcmail.com>
21+
#
22+
#
23+
.SUFFIXES: .cpp .c
24+
25+
#
26+
# Pick your C++ compiler.
27+
#
28+
CXX ?= ${CXX}
29+
# CXX ?= g++
30+
31+
#
32+
# Pick your YACC processor
33+
#
34+
YACC ?= bison -y
35+
# YACC ?= yacc
36+
37+
#
38+
# Define the FLEX processor
39+
# NOTE: lex will not work
40+
#
41+
FLEX ?= flex -Cfe
42+
43+
#
44+
# Link in any necessary C++ libraries
45+
#
46+
LIBS ?= -lstdc++
47+
48+
# installation information
49+
PREFIX ?= /usr/local
50+
BINDIR ?= ${PREFIX}/bin
51+
MANDIR ?= ${PREFIX}/man/man1
52+
MANEXT ?= 1
53+
54+
# other commands
55+
CP ?= cp -f
56+
MKDIR ?= mkdir
57+
MV ?= mv -f
58+
RM ?= rm -f
59+
DOXYGEN ?= doxygen
60+
61+
# Common local include directories
62+
INCLUDE_DIRS = platform rcxlib nqc compiler
63+
INCLUDES = $(addprefix -I, $(INCLUDE_DIRS))
64+
65+
# Common compiler flags
66+
CFLAGS += $(INCLUDES) -Wall
67+
68+
# Default to NO USB tower support. USB support can be enabled
69+
# via the platform specific settings, below.
70+
USBOBJ = RCX_USBTowerPipe_none
71+
72+
# Set this to define the serial port for serial IR towers.
73+
# If unset, "/dev/ttyS0" will be the default port.
74+
#DEFAULT_SERIAL_NAME = "/dev/ttyS0"
75+
76+
#
77+
# Platform specific settings
78+
#
79+
OSTYPE := $(strip $(shell uname -s))
80+
81+
ifneq (,$(strip $(findstring $(OSTYPE), Darwin)))
82+
# Mac OS X
83+
LIBS += -framework IOKit -framework CoreFoundation
84+
USBOBJ = RCX_USBTowerPipe_osx
85+
CXX = c++
86+
CFLAGS += -O3 -std=c++11 -Wno-deprecated-register
87+
else
88+
ifneq (,$(strip $(findstring $(OSTYPE), Linux)))
89+
# Linux
90+
# uncomment this next line if you have the USB tower library installed
91+
#USBOBJ = RCX_USBTowerPipe_linux
92+
DEFAULT_SERIAL_NAME = "/dev/ttyS0"
93+
CFLAGS += -I/usr/local/include/LegoUSB -Wno-deprecated
94+
else
95+
ifneq (,$(findstring $(OSTYPE), SunOS))
96+
# Solaris
97+
CFLAGS += -DSOLARIS
98+
else
99+
ifneq (,$(strip $(findstring $(OSTYPE), FreeBSD)))
100+
# FreeBSD
101+
USBOBJ = RCX_USBTowerPipe_fbsd
102+
DEFAULT_SERIAL_NAME = "/dev/cuad0"
103+
CFLAGS += -Wno-deprecated
104+
else
105+
ifneq (,$(strip $(findstring $(OSTYPE), OpenBSD)))
106+
# OpenBSD i386
107+
DEFAULT_SERIAL_NAME = "/dev/cua00"
108+
CFLAGS += -O2 -std=gnu++98 -pipe
109+
else
110+
# default Unix build without USB support
111+
CFLAGS += -O2
112+
endif
113+
endif
114+
endif
115+
endif
116+
endif
117+
118+
#
119+
# If the serial port is explicitly set, use it.
120+
#
121+
ifneq ($(strip $(DEFAULT_SERIAL_NAME)),)
122+
CFLAGS += -DDEFAULT_SERIAL_NAME='$(DEFAULT_SERIAL_NAME)'
123+
endif
124+
125+
#
126+
# Debug builds for most Clang/GCC environments.
127+
# This implies -DDEBUG_TIMEOUT
128+
#
129+
#CFLAGS += -DDEBUG -DPDEBUG -g -O0
130+
131+
#
132+
# Object files
133+
#
134+
OBJ = $(NQCOBJ) $(COBJ) $(RCXOBJ) $(POBJ)
135+
136+
RCXOBJS = RCX_Cmd RCX_Disasm RCX_Image RCX_Link RCX_Log \
137+
RCX_Target RCX_Pipe RCX_PipeTransport RCX_Transport \
138+
RCX_SpyboticsLinker RCX_SerialPipe \
139+
$(USBOBJ)
140+
RCXOBJ = $(addprefix rcxlib/, $(addsuffix .o, $(RCXOBJS)))
141+
142+
POBJS = PStream PSerial_unix PHashTable PListS PDebug
143+
POBJ = $(addprefix platform/, $(addsuffix .o, $(POBJS)))
144+
145+
COBJS = AsmStmt AssignStmt BlockStmt Bytecode Conditional \
146+
CondParser DoStmt Expansion Fragment IfStmt JumpStmt \
147+
lexer Macro parse PreProc Program RepeatStmt \
148+
AssignMathStmt Stmt Symbol TaskStmt WhileStmt Error \
149+
AutoFree parse_util Expr GosubStmt Scope InlineStmt \
150+
CallStmt CaseStmt SwitchStmt MonitorStmt AcquireStmt \
151+
DeclareStmt ScopeStmt ForStmt CatchStmt LabelStmt \
152+
GotoStmt Compiler Buffer Mapping FunctionDef ExprStmt \
153+
AtomExpr IncDecExpr BinaryExpr UnaryExpr ValueExpr \
154+
TypeExpr ModExpr EventSrcExpr SensorExpr ArrayExpr \
155+
TaskIdExpr RelExpr LogicalExpr NegateExpr IndirectExpr \
156+
NodeExpr ShiftExpr TernaryExpr VarAllocator VarTranslator \
157+
Resource AddrOfExpr DerefExpr GosubParamStmt
158+
COBJ = $(addprefix compiler/, $(addsuffix .o, $(COBJS)))
159+
160+
NQCOBJS = nqc SRecord DirList CmdLine
161+
NQCOBJ = $(addprefix nqc/, $(addsuffix .o, $(NQCOBJS)))
162+
163+
# We need a 'bin' directory because the names of the binaries clash
164+
# with existing directory names.
165+
all : bin nqh nub bin/nqc
166+
167+
# Create the bin directory in the Makefile because it is not part
168+
# of the original distribution. This prevents the need to tell the user
169+
# to do it.
170+
bin:
171+
$(MKDIR) bin
172+
173+
bin/nqc: compiler/parse.cpp $(OBJ)
174+
$(CXX) -o $@ $(OBJ) $(LIBS)
175+
176+
bin/mkdata: mkdata/mkdata.cpp nqc/SRecord.cpp
177+
$(CXX) -o $@ $(INCLUDES) $^
178+
179+
#
180+
# clean up stuff
181+
#
182+
clean: clean-parser clean-lexer clean-obj clean-nqh clean-nub
183+
184+
clean-obj:
185+
-$(RM) bin/*
186+
-$(RM) */*.o
187+
188+
clean-parser:
189+
-$(RM) compiler/parse.cpp compiler/parse.tab.h
190+
191+
clean-lexer:
192+
-$(RM) compiler/lexer.cpp
193+
194+
clean-nqh:
195+
-$(RM) compiler/rcx1_nqh.h compiler/rcx2_nqh.h
196+
197+
clean-nub:
198+
-$(RM) rcxlib/rcxnub.h
199+
200+
#
201+
# create the parser files (parse.cpp and parse.tab.h)
202+
#
203+
compiler/parse.cpp: compiler/parse.y
204+
cd compiler ; \
205+
$(YACC) -d parse.y ; \
206+
$(MV) y.tab.c parse.cpp ; \
207+
$(MV) y.tab.h parse.tab.h
208+
209+
#
210+
# create the lexer file (lexer.cpp)
211+
#
212+
compiler/lexer.cpp: compiler/lex.l
213+
cd compiler ; \
214+
$(FLEX) lex.l
215+
216+
#
217+
# NQH files
218+
#
219+
nqh: compiler/rcx1_nqh.h compiler/rcx2_nqh.h
220+
221+
compiler/rcx1_nqh.h: compiler/rcx1.nqh bin/mkdata
222+
bin/mkdata $< $@ rcx1_nqh
223+
224+
compiler/rcx2_nqh.h: compiler/rcx2.nqh bin/mkdata
225+
bin/mkdata $< $@ rcx2_nqh
226+
227+
#
228+
# rcxnub.h
229+
#
230+
nub: rcxlib/rcxnub.h
231+
232+
rcxlib/rcxnub.h: rcxlib/fastdl.srec bin/mkdata
233+
bin/mkdata -s $< $@ rcxnub
234+
235+
#
236+
# general rule for compiling
237+
#
238+
.cpp.o:
239+
$(CXX) -c $(CFLAGS) $< -o $*.o
240+
241+
#
242+
# Use these targets to use the default parser/lexer files. This is handy if
243+
# your system does not have a suitable flex and/or yacc tool.
244+
#
245+
default-parser:
246+
$(CP) default/parse.cpp default/parse.tab.h nqc
247+
248+
default-lexer:
249+
$(CP) default/lexer.cpp nqc
250+
251+
#
252+
# This is used to create a default parser, lexer, and nqh files for later use.
253+
# You shouldn't need to do this as part of a port.
254+
#
255+
DEF_FILES = compiler/parse.cpp compiler/lexer.cpp compiler/rcx1_nqh.h compiler/rcx2_nqh.h
256+
default-snapshot: default $(DEF_FILES)
257+
$(CP) $(DEF_FILES) compiler/parse.tab.h default
258+
259+
default:
260+
$(MKDIR) default
261+
262+
#
263+
# Generate API docs. Not part of a port.
264+
#
265+
docs:
266+
@$(DOXYGEN) Doxyfile
267+
268+
#
269+
# Installation of binary and man page
270+
#
271+
install: all
272+
test -d $(BINDIR) || mkdir -p $(BINDIR)
273+
cp -r bin/* $(BINDIR)
274+
test -d $(MANDIR) || mkdir -p $(MANDIR)
275+
cp nqc-man-2.1r1-0.man $(MANDIR)/nqc.$(MANEXT)
276+
277+
#
278+
# Print some info about the environment
279+
#
280+
info:
281+
@echo "Building for: $(OSTYPE)"
282+
@echo CXX=$(CXX)
283+
@echo CFLAGS=$(CFLAGS)
284+
@echo YACC=$(YACC)
285+
@echo FLEX=$(FLEX)
286+
@echo LIBS=$(LIBS)
287+
@echo OBJ=$(OBJ)
288+
@echo USBOBJ=$(USBOBJ)
289+
@echo PREFIX=$(PREFIX)

0 commit comments

Comments
 (0)