How to make gnatmake tool compile RTS with project? - ada

Is there a way to make gnatmake tool recompile the Ada's runtime library ("RTS") with the project I'm building file by file? I want to integrate my custom preprocessor that adds some features to ada source code and then compiles it with gcc. I'm passing --GCC=<preprocessor> flag to the gnatmake utility, it figures out dependencies automatically and runs my preprocessor for all of my source files. However I want custom preprocessing to be done on code in the RTS as well, is there any way to do it?

The -a flag tells gnatmake to recompile any RTS files that need to be recompiled.
After a little experiment here it seems that if you copy system.ads (and maybe gnat.ads, interfac.ads .. yes) from the compiler’s adainclude/ directory to your source tree (I think you’ll need to touch it whenever you update your preprocessor), gnatmake may be able do what you want.
$ cp /opt/gcc-4.9.0/lib/gcc/x86_64-apple-darwin13/4.9.0/adainclude/system.ads .
$ gnatmake -a int
gcc -c int.adb
gcc -gnatpg -c -I./ -I- /opt/gcc-4.9.0/lib/gcc/x86_64-apple-darwin13/4.9.0/adainclude/s-stalib.adb
gcc -gnatpg -c -I./ -I- /opt/gcc-4.9.0/lib/gcc/x86_64-apple-darwin13/4.9.0/adainclude/a-except.adb
gcc -gnatpg -c -I./ -I- /opt/gcc-4.9.0/lib/gcc/x86_64-apple-darwin13/4.9.0/adainclude/s-valint.adb
gcc -gnatpg -c system.ads
...
gcc -gnatpg -c -I./ -I- /opt/gcc-4.9.0/lib/gcc/x86_64-apple-darwin13/4.9.0/adainclude/s-conca4.adb
gnatbind -x int.ali
gnatlink int.ali
and, after I realised I hadn’t used -gnata,
$ touch int.adb
$ gnatmake -a -gnata int
gcc -c -gnata int.adb
gcc -gnatpg -c -I./ -gnata -I- /opt/gcc-4.9.0/lib/gcc/x86_64-apple-darwin13/4.9.0/adainclude/s-assert.adb
gnatbind -x int.ali
gnatlink int.ali
(I do not want to use -f here, because it’ll rebuild everything.)

Related

What is the meaning of -lNew in Makefile?

I am confused with the option -lNew in a Makefile.
What is the meaning of -lNEW ?
Do you know where can I get more information?
TARGET = Example
OBJS = main.o user.o
CXXLIBS = -Wall -lNew -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64
all: $(TARGET)
$(TARGET):$(OBJS)
$(CXX) -o $# $(OBJS) $(LIBS) $(CXXLIBS)
Supposing GCC is your build toolchain, -lNew tells to the linker to add the library called "libNew.so" or "libNew.a" to the list of files to link in the output binary.

what is the replacement for REGEXP_REPLACE(XXXXXX,' ', '') ; in sqlite? [duplicate]

I installed REGEX support with
apt-get install sqlite3 sqlite3-pcre
now I can use REGEX in my queries on the bash console like
DB="somedb.db"
REGEX_EXTENSION="SELECT load_extension('/usr/lib/sqlite3/pcre.so');"
sqlite3 $DB "$REGEX_EXTENSION select * from sometable where name REGEXP '^[a-z]+$'"
But how can I update a string with an sqlite query using regex?
Sqlite by default does not provide regex_replace function. You need to load it as an extension. Here is how i managed to do it.
Download this C code for the extension (icu_replace)
Compile it using
gcc --shared -fPIC -I sqlite-autoconf-3071100 icu_replace.c -o icu_replace.so
And in sqlite3 runn following command post above mentioned command has run and create a file icu_replace.so
SELECT load_extension(' path to icu_replace.so', 'sqlite3_extension_init') from dual;
After this you will be able to use such a function as :-
select regex_replace('\bThe\b',x,'M') from dual;
The following builds latest sqlite with dynamic library support, and compiles ICU extension and regex_replace extension. It also assumes debian-based linux distributive:
sudo apt build-dep sqlite3 # fetches dependencies to compile sqlite3
mkdir sqlite-compilation
cd sqlite-compilation
wget -O sqlite.tar.gz https://www.sqlite.org/src/tarball/sqlite.tar.gz?r=release
tar xzf sqlite.tar.gz
mkdir build
cd build
../sqlite/configure
make OPTS='-DSQLITE_ENABLE_LOAD_EXTENSION'
./sqlite3 -cmd 'pragma compile_options;' <<< .exit
cd -
# https://sqlite.org/src/dir?name=ext/icu
cd sqlite/ext/icu
sed -i 's/int sqlite3_icu_init(/int sqlite3_extension_init(/' icu.c
sed -i 's/int sqlite3IcuInit(/int sqlite3_extension_init(/' sqliteicu.h
gcc -g -O2 -shared icu.c -fPIC -I ../../../build `pkg-config --libs icu-i18n` -o libSqlite3Icu.so
cp libSqlite3Icu.so ../../../build/
cd -
# https://github.com/gwenn/sqlite-regex-replace-ext
cd sqlite/ext
wget -O sqlite-regex-replace-ext-master.zip https://github.com/gwenn/sqlite-regex-replace-ext/archive/master.zip
unzip sqlite-regex-replace-ext-master.zip
cd sqlite-regex-replace-ext-master
gcc -g -O2 -shared icu_replace.c -fPIC -I ../../../build -o libSqlite3IcuReplace.so
cp libSqlite3IcuReplace.so ../../../build/
cd -
cd ../../
In result you will have:
build/sqlite3 # sqlite3 binary
build/libSqlite3Icu.so # unicode support
build/libSqlite3IcuReplace # regex_replace function
Test:
cd build
sqlite3 <<< "
.load ./libSqlite3Icu
.load ./libSqlite3IcuReplace
select regex_replace('^a', 'aab', 'b');
.exit
" # should output: bab
cd -
For me the above answers didn't work because of some missing parameters in the gcc command.
This works for me:
git clone https://github.com/gwenn/sqlite-regex-replace-ext.git
cd sqlite-regex-replace-ext-master/
./icu_replace.sh
Now you should be able to load the extension using: SELECT LOAD_EXTENSION('path-to-icu_replace.so');

what is wrong with my makefile code?

I have a makefile that I needed to change around, and use it to install the program. I can;t figure out why I am getting this error:
v245-2% make install
install -m 555 audit /export/home/student/scort323/bin
sh: install: not found
*** Error code 1
make: Fatal error: Command failed for target `install'
Below is my code, can somebody please give me some advice. I am not good at makefiles so trying to find this error is hard for me until I get a better understanding:
# Make file for audit
# Location to install binary. Default is /usr/local/bin. You may
# prefer to install it in /usr/bin or /sbin
BINDIR = /export/home/student/scort323/bin
#BINDIR=/usr/bin
#BINDIR=/usr/sbin
# Location to install man page. Default is /usr/local/man. You may
# prefer to install it in /usr/man
MANDIR = /export/home/student/scort323/bin
#MANDIR = /usr/man
# Compiler to use
CC = gcc
# Linker to use
LD = gcc
# Preprocessor options
CPPFLAGS = -DGETOPTLONG
# Compile and link options
# On a.out systems you might want to add -N when linking
# RPM_OPT_FLAGS can be set by rpm tool
# ...For production code
CFLAGS = -Wall -O3 $(RPM_OPT_FLAGS)
LDFLAGS = -s
# ...For debug
#CFLAGS = -Wall -g
#LDFLAGS = -g
audit: audit.o
$(LD) $(LDFLAGS) -o audit audit.o
audit.o: audit.c
$(CC) $(CPPFLAGS) $(CFLAGS) -c audit.c
install: audit
install -m 555 audit $(BINDIR)
#/audit
install -m 444 audit.1 $(MANDIR)
#/man1/audit.1
clean:
$(RM) audit audit.o core *~ results
# check in
ci: clean
-ci -l *
dist: clean
cd .. ; tar --exclude RCS -czvf audit-0.2.tar.gz audit-0.2
There is no problem with the makefile. Check if you have install utility
$~ install --help
If you dont have then you can get it from GNU coreutils. If you have install somewhere then export its path in PATH variable
export PATH=$PATH:/path/to/install-utilit

GNU makefile detect header changes

I have a directory with dozens of source and header files. Is there a better or cleaner way than the following %.o target for make to detect changes to header files? When the object is compiled, g++ is invoked with both the .cc and .h files which doesn't seem right, it should find the .h file automatically.
%.o: %.cc %.h
g++ -c $^
OBJECTS=headless-driver.o config.o simplefm2.o emulator.o basis-util.o objective.o weighted-objectives.o motifs.o util.o
learnfun : $(OBJECTS) learnfun.o
g++ $^ -o $#
%.o: %.cc %.h
g++ -c $^
You are specifying $^ which expands to all dependencies. If you just want the first dependency on the Gcc command line, use $< instead.

Makefile errors when I change a directory name

I have a Makefile that compiles, but I want to change the name of one of the directories from "release" to "objects". This is the original Makefile -
# This makefile compiles ....
INCLUDE = -I/usr/include/X11 -I/usr/local/include -I/usr/local/include/FL/images -I/usr/include/freetype2
CC=g++
CFLAGS=-w -D LINUX -O3 -fpermissive
OBJDIR=release # HERE IS THE DIRECTORY I WANT TO CHANGE
SRCDIR=src
LDFLAGS= -L/usr/X11R6/lib$(LIBSELECT) -lpthread -lfltk -lXext -lXft -lfontconfig -lXinerama -lpthread -ldl -lm -lX11
SOURCES_RAW= robot_driver_agent.cpp robot_driver_position.cpp robot_driver_priorityqueue.cpp main.cpp robot_driver_tree.cpp robot_driver_stack.cpp robot_driver_grid.cpp robot_driver_path.cpp grid_analyzer.cpp tcpserver.cpp tcpclient.cpp servercontrol.cpp clientcontrol.cpp robot.cpp udpserver.cpp udpclient.cpp owncontrol.cpp guiwindow.cpp rs232.cpp
TARGET:= go
TARGETD:= go_d
OBJECTS:=$(SOURCES_RAW:.cpp=.o)
OBJECTS:=$(patsubst %.o, $(OBJDIR)/%.o, $(OBJECTS))
SOURCES:=$(SOURCES_RAW)
SOURCES:=$(patsubst %.cpp, $(SRCDIR)/%.cpp, $(SOURCES))
all: $(TARGET)
$(TARGET): $(OBJECTS)
$(CC) -w -D LINUX $(INCLUDE) $^ -o $# $(LDFLAGS)
release/%.o: src/%.cpp
test -d $(OBJDIR) || mkdir $(OBJDIR)
$(CC) -g -c $< $(CFLAGS) -o $#
debug: $(TARGETD)
$(TARGETD): $(OBJECTS)
$(CC) -w -D LINUX $(INCLUDE) $^ -o $# $(LDFLAGS)
%.o: $(SRCDIR)/%.cpp
$(CC) -c -g $< $(CFLAGS)-o $#
.PHONY : clean
clean:
rm -f $(OBJDIR)/*.o
rm -f $(TARGET) $(TARGETD)
All I do is change the OBJDIR symbol to "objects" so it would just be -
OBJDIR=objects
But when I do that, I get the error -
make: *** No rule to make target `objects/robot_driver_agent.o', needed by `go'.
What am I missing? Is "objects" a word reserved for something in make so I can't use it for directories? Is it something in the make file that I need to change? Honestly, I don't know that much about makefiles so any help at all would be great. Thanks.
You have a rule:
release/%.o: src/%.cpp
...
So that when OBJDIR=release and Make wants to build release/robot_driver_agent.o, it knows just what to do. Then you try OBJDIR=objects, it wants to build objects/robot_driver_agent.o, and it doesn't know how because there's no rule that fits. Try changing the rule to:
$(OBJDIR)/%.o: src/%.cpp
...

Resources