Static Nginx with Modsecurity - c

Trying to add Modsecurity v3.0.4 in to Nginx v1.19.9 but running in to some errors I do not understand. There are MANY errors similar to the ones I pasted below but did not include them all. My intention is to create a static Nginx binary and not use the dynamic Modsecurity module. Thanks for any help.
Dockerfile
FROM alpine:latest as build
#Define build argument for version
ARG NGNX_VERSION=1.19.8
ARG PCRE_VERSION=8.44
ARG OSSL_VERSION=1.1.1k
ARG ZLIB_VERSION=1.2.11
ARG GEO_DB_RELEASE=2021-04
ARG MODSEC_BRANCH=v3.0.4
ARG OWASP_BRANCH=v3.3/master
# Set working directory
WORKDIR /tmp
RUN echo "Installing Dependencies" && \
apk add --no-cache --virtual general-dependencies \
autoconf \
automake \
byacc \
build-base \
gnupg \
perl \
linux-headers \
pcre-dev \
wget \
geoip-dev \
curl-dev \
flex \
g++ \
gcc \
geoip-dev \
git \
libc-dev \
libmaxminddb-dev \
libstdc++ \
libtool \
libxml2-dev \
linux-headers \
lmdb-dev \
make \
openssl-dev \
pcre-dev \
yajl-dev \
zlib-dev
# Clone and compile modsecurity. Binary will be located in /usr/local/modsecurity
RUN echo "Installing ModSec Library" && \
git clone -b ${MODSEC_BRANCH} --depth 1 https://github.com/SpiderLabs/ModSecurity && \
git -C /tmp/ModSecurity submodule update --init --recursive && \
(cd "/tmp/ModSecurity" && \
./build.sh && \
./configure --with-lmdb && \
make -j 10 && \
make install \
)
# Retrieve required packages
RUN echo 'Cloning Modsec Nginx Connector, GeoIP, ModSec OWASP Rules, and download/extract nginx and GeoIP databases' && \
git clone -b master --depth 1 https://github.com/SpiderLabs/ModSecurity-nginx.git && \
git clone -b ${OWASP_BRANCH} --depth 1 https://github.com/coreruleset/coreruleset.git /usr/local/owasp-modsecurity-crs && \
wget -q https://www.openssl.org/source/openssl-$OSSL_VERSION.tar.gz && \
tar -xzf openssl-$OSSL_VERSION.tar.gz && \
wget -q https://ftp.pcre.org/pub/pcre/pcre-$PCRE_VERSION.tar.bz2 && \
tar -xjf pcre-$PCRE_VERSION.tar.bz2 && \
wget -q http://zlib.net/zlib-$ZLIB_VERSION.tar.gz && \
tar -xzf zlib-$ZLIB_VERSION.tar.gz && \
wget -q http://nginx.org/download/nginx-$NGNX_VERSION.tar.gz && \
tar -xzf nginx-$NGNX_VERSION.tar.gz
# Install Nginx with PCRE, OpenSSL, Geomod, Zlib
RUN set -x && \
cd /tmp/nginx-$NGNX_VERSION && \
./configure \
--with-compat \
--with-ld-opt="-static" \
--with-pcre=/tmp/pcre-${PCRE_VERSION} \
--with-zlib=/tmp/zlib-${ZLIB_VERSION} \
--with-openssl=/tmp/openssl-${OSSL_VERSION} \
--with-http_realip_module \
--with-http_v2_module \
--add-module=/tmp/ModSecurity-nginx \
--with-http_ssl_module && \
make -j 10 && \
make install && \
strip /usr/local/nginx/sbin/nginx && \
apk del general-dependencies
# Symlink access and error logs to /dev/stdout and /dev/stderr, in
# order to make use of Docker's logging mechanism
RUN ln -sf /dev/stdout /usr/local/nginx/logs/access.log && \
ln -sf /dev/stderr /usr/local/nginx/logs/error.log
RUN addgroup -S nginx && adduser -S -G nginx nginx
Failures occur during the Nginx make section. There are many similar to these.
/usr/include/c++/10.2.1/bits/basic_string.tcc:225: undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_S_copy_chars(char*, char const*, char const*)'
/usr/lib/gcc/x86_64-alpine-linux-musl/10.2.1/../../../../x86_64-alpine-linux-musl/bin/ld: /usr/include/c++/10.2.1/bits/basic_string.tcc:219: undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_create(unsigned long&, unsigned long)'
/usr/lib/gcc/x86_64-alpine-linux-musl/10.2.1/../../../../x86_64-alpine-linux-musl/bin/ld: /usr/include/c++/10.2.1/bits/basic_string.tcc:212: undefined reference to `std::__throw_logic_error(char const*)'
/usr/lib/gcc/x86_64-alpine-linux-musl/10.2.1/../../../../x86_64-alpine-linux-musl/bin/ld: /usr/local/modsecurity/lib/libmodsecurity.a(lt5-libmodsecurity_la-rule.o): in function `_GLOBAL__sub_I_rule.cc':
/usr/include/c++/10.2.1/iostream:74: undefined reference to `std::ios_base::Init::Init()'
/usr/lib/gcc/x86_64-alpine-linux-musl/10.2.1/../../../../x86_64-alpine-linux-musl/bin/ld: /usr/local/modsecurity/lib/libmodsecurity.a(lt5-libmodsecurity_la-rule.o): in function `__static_initialization_and_destruction_0':
/usr/include/c++/10.2.1/iostream:74: undefined reference to `std::ios_base::Init::~Init()'
/usr/lib/gcc/x86_64-alpine-linux-musl/10.2.1/../../../../x86_64-alpine-linux-musl/bin/ld: /usr/local/modsecurity/lib/libmodsecurity.a(lt5-libmodsecurity_la-rule.o): in function `__static_initialization_and_destruction_0':
/tmp/ModSecurity/src/variables/rule.cc:23: undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()'
collect2: error: ld returned 1 exit status
make[1]: *** [objs/Makefile:267: objs/nginx] Error 1

OWASP ModSecurity Core Rule Set project here.
I've never attempted a static compile, but I suggest you ask the question on the modsecurity mailinglist or on the specific modsecurity developer mailinglist.
https://sourceforge.net/p/mod-security/mailman/

Related

Multiple extra-cflags of a makefile

so there is this library am trying to use ffmpeg.js and am customizing the Makefile. I have done everything that I wanted to do but on building, I got the error ERROR: opus not found using pkg-config. Now I have two problems:
--extra-cflags="-s USE_ZLIB=1 -I../lame/dist/include -I../libvpx/dist/include" this configuration was initially --extra-cflags="-s USE_ZLIB=1 -I../lame/dist/include" but I wanted to include two folders, so is the merging correct or that's where I went wrong.
The complete Makefile is as below (there are alot of changes from the original one from the repository), is there anything I did wrong?
PRE_JS = build/pre.js
POST_JS_SYNC = build/post-sync.js
COMMON_FILTERS = aresample scale crop overlay hstack vstack
COMMON_DEMUXERS = matroska ogg mov mp3 wav image2 concat
COMMON_DECODERS = vp8 vp9 h264 vorbis opus mp3 aac pcm_s16le mjpeg png
COMMON_BSFS = vp9_superframe
MUXERS = mp4 mp3 webm ogg null
ENCODERS = libx264 libmp3lame aac libvpx_vp8 libopus
FFMPEG_BC = build/ffmpeg/ffmpeg.bc
FFMPEG_PC_PATH = ../x264/dist/lib/pkgconfig
SHARED_DEPS = \
build/lame/dist/lib/libmp3lame.so \
build/x264/dist/lib/libx264.so \
build/opus/dist/lib/libopus.so \
build/libvpx/dist/lib/libvpx.so
all: ffmpeg.js
clean: clean-js \
clean-opus clean-libvpx clean-lame \
clean-x264 clean-ffmpeg
clean-js:
rm -f ffmpeg*.js
clean-opus:
cd build/opus && git clean -xdf
clean-libvpx:
cd build/libvpx && git clean -xdf
clean-lame:
cd build/lame && git clean -xdf
clean-x264:
cd build/x264 && git clean -xdf
clean-ffmpeg:
cd build/ffmpeg-mp4 && git clean -xdf
build/opus/configure:
cd build/opus && ./autogen.sh
build/opus/dist/lib/libopus.so: build/opus/configure
cd build/opus && \
emconfigure ./configure \
CFLAGS=-O3 \
--prefix="$$(pwd)/dist" \
--disable-static \
--disable-doc \
--disable-extra-programs \
--disable-asm \
--disable-rtcd \
--disable-intrinsics \
--disable-hardening \
--disable-stack-protector \
&& \
emmake make -j && \
emmake make install
build/libvpx/dist/lib/libvpx.so:
cd build/libvpx && \
git reset --hard && \
patch -p1 < ../libvpx-fix-ld.patch && \
emconfigure ./configure \
--prefix="$$(pwd)/dist" \
--target=generic-gnu \
--disable-dependency-tracking \
--disable-multithread \
--disable-runtime-cpu-detect \
--enable-shared \
--disable-static \
\
--disable-examples \
--disable-docs \
--disable-unit-tests \
--disable-webm-io \
--disable-libyuv \
--disable-vp8-decoder \
--disable-vp9 \
&& \
emmake make -j && \
emmake make install
build/lame/dist/lib/libmp3lame.so:
cd build/lame/lame && \
git reset --hard && \
patch -p2 < ../../lame-fix-ld.patch && \
emconfigure ./configure \
CFLAGS="-DNDEBUG -O3" \
--prefix="$$(pwd)/../dist" \
--host=x86-none-linux \
--disable-static \
\
--disable-gtktest \
--disable-analyzer-hooks \
--disable-decoder \
--disable-frontend \
&& \
emmake make -j && \
emmake make install
build/x264/dist/lib/libx264.so:
cd build/x264 && \
emconfigure ./configure \
--prefix="$$(pwd)/dist" \
--extra-cflags="-Wno-unknown-warning-option" \
--host=x86-none-linux \
--disable-cli \
--enable-shared \
--disable-opencl \
--disable-thread \
--disable-interlaced \
--bit-depth=8 \
--chroma-format=420 \
--disable-asm \
\
--disable-avs \
--disable-swscale \
--disable-lavf \
--disable-ffms \
--disable-gpac \
--disable-lsmash \
&& \
emmake make -j && \
emmake make install
FFMPEG_COMMON_ARGS = \
--cc=emcc \
--ranlib=emranlib \
--enable-cross-compile \
--target-os=none \
--arch=x86 \
--disable-runtime-cpudetect \
--disable-asm \
--disable-fast-unaligned \
--disable-pthreads \
--disable-w32threads \
--disable-os2threads \
--disable-debug \
--disable-stripping \
--disable-safe-bitstream-reader \
\
--disable-all \
--enable-ffmpeg \
--enable-avcodec \
--enable-avformat \
--enable-avfilter \
--enable-swresample \
--enable-swscale \
--disable-network \
--disable-d3d11va \
--disable-dxva2 \
--disable-vaapi \
--disable-vdpau \
$(addprefix --enable-bsf=,$(COMMON_BSFS)) \
$(addprefix --enable-decoder=,$(COMMON_DECODERS)) \
$(addprefix --enable-demuxer=,$(COMMON_DEMUXERS)) \
--enable-protocol=file \
$(addprefix --enable-filter=,$(COMMON_FILTERS)) \
--disable-bzlib \
--disable-iconv \
--disable-libxcb \
--disable-lzma \
--disable-sdl2 \
--disable-securetransport \
--disable-xlib \
--enable-zlib
build/ffmpeg/ffmpeg.bc: $(SHARED_DEPS)
cd build/ffmpeg-mp4 && \
EM_PKG_CONFIG_PATH=$(FFMPEG_PC_PATH) emconfigure ./configure \
$(FFMPEG_COMMON_ARGS) \
$(addprefix --enable-encoder=,$(ENCODERS)) \
$(addprefix --enable-muxer=,$(MUXERS)) \
--enable-gpl \
--enable-libmp3lame \
--enable-libx264 \
--enable-libopus \
--enable-libvpx \
--extra-cflags="-s USE_ZLIB=1 -I../lame/dist/include -I../libvpx/dist/include" \
--extra-ldflags="-L../lame/dist/lib -L../libvpx/dist/lib" \
&& \
emmake make -j && \
cp ffmpeg ffmpeg.bc
EMCC_COMMON_ARGS = \
-O3 \
--closure 1 \
--memory-init-file 0 \
-s WASM=0 \
-s WASM_ASYNC_COMPILATION=0 \
-s ASSERTIONS=0 \
-s EXIT_RUNTIME=1 \
-s NODEJS_CATCH_EXIT=0 \
-s NODEJS_CATCH_REJECTION=0 \
-s TOTAL_MEMORY=67108864 \
-lnodefs.js -lworkerfs.js \
--pre-js $(PRE_JS) \
-o $#
ffmpeg.js: $(FFMPEG_BC) $(PRE_JS) $(POST_JS_SYNC)
emcc $(FFMPEG_BC) $(SHARED_DEPS) \
--post-js $(POST_JS_SYNC) \
$(EMCC_COMMON_ARGS) -O2
What I was trying to achieve was combine some of the webm encoders and muxers into the mp4 module so I use only that one module for all webm and mp4 format types.
Also one thing to know about me, the whole Makefile and C and building it is totally new territory for me, I just did what I thought was right, thanks in advance.
It's good you have solid goals. Without those, the problem is much harder.
What you need to do is understand the commands you would run, without make or Makefiles, to achieve those goals, and the files that are created along the way. With this, you then encode those commands in the format
file_to_be_created:source_file_1 source_file_2 source_file_3
<tab>command to be executed
<tab>second command to be executed
The tabs are an unfortunate side-effect of a bad choice in make's history.
With this, you can modify the Makefile. If you have one source that is built from other sources, make two "make" rules using the pattern above, and make will correctly determine the build order and run the commands needed. If make determines a crated file is newer than its sources, it will skip building the created file.
As you can see, while make is not very complicated, it does little to help you know the commands you must run. Maybe you know them already; but, if you don't I'd take your personal knowledge and what you can read out of the Makefile and combine them to see if you can fashion the make file rules you need.
Initially, I'd do this by creating new rules and new files, because if you break a rule you need, odds are you won't find out until much later. Once you get something building, you can review if you should roll you rules into some of the existing ones or not.
Good luck!

ELF section not being linked

I'm running into some trouble with the GNU linker.
In short, I have one object which has a .yksir_ykpack ELF section, which is being linked with an object which has a .yksir_yktrace ELF section. The desired outcome is a binary with both of these sections.
Here's the object with the .yksir_ykpack section:
readelf --section-headers /home/vext01/research/yk/target/debug/deps/libykpack-2a9122d94a2f837e.rlib 2>/dev/null
...
File: /home/vext01/research/yk/target/debug/deps/libykpack-2a9122d94a2f837e.rlib(ykpack-2a9122d94a2f837e.4kxe4998mamwcrkf.rcgu.o)
There are 6 section headers, starting at offset 0xc25f8:
Section Headers:
[Nr] Name Type Address Offset
Size EntSize Flags Link Info Align
[ 0] NULL 0000000000000000 00000000
0000000000000000 0000000000000000 0 0 0
[ 1] .strtab STRTAB 0000000000000000 000c2580
0000000000000074 0000000000000000 0 0 1
[ 2] .text PROGBITS 0000000000000000 00000040
0000000000000000 0000000000000000 AX 0 0 4
[ 3] .yksir_ykpack PROGBITS 0000000000000000 00000040
00000000000c24f5 0000000000000000 0 0 16
[ 4] .note.GNU-stack PROGBITS 0000000000000000 000c2535
0000000000000000 0000000000000000 0 0 1
[ 5] .symtab SYMTAB 0000000000000000 000c2538
0000000000000048 0000000000000018 1 2 8
...
Note that this object is a Rust rlib, but it's ELF compatible.
Note also that there other "sub-files" in the rlib. I've elided them.
The other object being linked (containing .yksir_yktrace) is a regular .o file.
And since my section names will be unrecogised by the default linker script, I've used section directives (in inline asm). For example, for .yksir_ykpack:
.section .yksir_ykpack, "", #progbits
Now here's our linker command line (sorry it's long -- it is hard to make a minimal example in my setup):
cc \
-Wl,--as-needed \
-Wl,-z,noexecstack \
-m64 \
-L \
/home/vext01/research/ykrustc/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/x86_64-unknown-linux-gnu/lib \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.10c166lfq64r2e3y.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.10qcnu2sbqobows0.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.115niq53kx6tizom.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.120g6826u8fiklab.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.14rek8asgh23tnza.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.154hfu34te2ge40t.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.177trhwt854ryxrc.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.18scvl9vj2f5b06v.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.18vw9lln0d5b3qrw.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.1b3h401yq8qa8ur5.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.1b77e65v6f58yuv6.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.1bx0tifep7a0rrg2.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.1f45w8utte9cb7vq.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.1gu52jpfp6kyy8ga.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.1gxs1zbjd9l1x29m.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.1jidej0kgblhzsyd.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.1kxugzjco2szwc38.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.1lgrutz0tyx7absl.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.1ozmuob6f299nm7.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.1q2fa8g6b78o6dlx.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.1rlyknl6qs9nwcax.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.1xi7nbo1lotv9jbw.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.241a14yvztsg3uho.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.263wkarma1f4il5c.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.26z1aszmxuxamrl6.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.2853vbh8zenhwv7w.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.28bq65c862o6lbw3.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.2928kri5ycvnjicw.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.293in29h8y2p3l2b.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.2bhdn9m34dljrb32.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.2c3zsda0wuw2rgnr.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.2c7gsrv4f7hrohm9.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.2crlph00pparx8rl.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.2d9e1vcwdgfeqahl.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.2dshiej7wzf5qhqc.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.2f8ravnggrepx4x9.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.2h6d7quzn2azwinl.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.2i9tj89psdv0p93c.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.2ibi7q757d8gjivn.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.2o8kwjdjgy2ybl41.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.2oiqp6v3amvs5ntu.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.2q1okbobeouigo3x.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.2qfanjg39058djk4.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.2r2b4hs5fzkuh2xg.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.2r63byzwj3tomouq.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.2solqp985j0ij1iv.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.2tukccybgj9vycj9.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.2ufh1wltjgi0ncw8.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.2v16mhbnkzo2h1j1.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.2vpbdcbcpuaozllz.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.2w6ewmxetdc306hu.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.2wmzmwzopnst0oks.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.2x6tg5n30lb0h4dm.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.2y1u4ztvloojzu1e.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.32ako2nv80o7xnx9.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.336kexx0suto8yk0.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.34a312torkwd02am.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.38eqcg27n3vxgdmg.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.3c45tbmi2ikdru55.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.3csuiad3mvn7wgqc.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.3d1afrosx210ksv8.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.3fm3cboeuara00yc.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.3gq2u8x551t2ef0u.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.3itxhruj3tgegtyr.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.3k1x60obvhk78c0f.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.3k2mv967ff5wbde9.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.3keaisjesqpgzid7.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.3knbirxkrhjnqc0j.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.3lka49k5uun01x61.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.3m1g3a2t7sziz3k8.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.3mbasooz3zq9lq2j.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.3nfs7qwaz8pe36zr.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.3nnnuv59023znw62.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.3ptew4t1q7mvc8z2.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.3qdehdp4kxtbq0tj.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.3r7sp7knkxz5a9u2.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.3rnnuvaazxtmknct.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.3rw5uarkaib7yafm.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.3vsqsa5e8ys24frq.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.3wddp6f4tv68zbr3.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.3yyfhdodvs54rvbs.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.3zj0neynl1tg27y0.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.3zx5ut953nbpjm4h.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.42g1k7sztcmhf5ak.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.46bo2vabr45h9mqv.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.46dmw1z0esu1hxri.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.479eiwn05j7vuk1p.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.47g9z8o12t0bz84h.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.49o7bkfhu7tpp5ra.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.4ab0cs1z37jlq52s.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.4do73rnjg7fn2sou.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.4f6peemwtbhuiqw4.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.4h2ljwnazsotxzgx.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.4j1d9zei95ciav3u.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.4l4m07sfgf7zynqq.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.4lhkgbdz114036lo.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.4lufiuj41yjsxxxy.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.4njp70315f2wj26b.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.4nxht76y2opj1mic.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.4q23mole4mu9mt24.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.4qd7hpf2syf2o2pp.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.4wiu8i53hl4c96yo.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.5143dlty43nxmbim.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.57dfjw10traxw3ae.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.5ckz2fx2s5apni0f.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.5dy4mq6l10uhilba.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.5eapic3g6plq22h8.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.5eba7m25m1l02h9m.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.5gudrx0yblx2aj77.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.5krt6jfk0979emg.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.62xy9gq4fuhf36h.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.7nla6xrkcjgwurc.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.8jk62bksvzymbp5.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.ggonqqon6gxi2af.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.gjhkwkf95up18pw.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.hxqc3dcbdk1faag.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.j2yhsf7842yw3sb.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.jey67dcpnxuoywx.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.jhvojsq8gkuti7k.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.jybymzk00d3e5t7.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.kqmbtygjxlnx47m.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.ndroblzkpdcjzo1.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.o3bxbvma8t5xkne.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.r1w6eadga16ihy4.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.s6ldoaew31npivj.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.tmt3fv8lu8oua6k.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.v51zeo4f699m0ti.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.w55t39wk5qjg2bc.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.xp7r6sx9ppyf9t0.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.y8lfemb87vtfeob.rcgu.o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.zwjbkly56hl6j7y.rcgu.o \
-o \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8 \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.3qhbgyy4j5mr4hcm.rcgu.o \
-pie \
-Wl,-zrelro \
-Wl,-znow \
-nodefaultlibs \
-L \
/home/vext01/research/yk/target/debug/deps \
-L \
/home/vext01/research/yk/target/debug/build/hwtracer-928324455c3b5b0d/out \
-L \
/home/vext01/.cargo/git/checkouts/hwtracer-07feaf5fa95de145/fdce391/c_deps/inst/lib \
-L \
/home/vext01/research/yk/target/debug/build/hwtracer-928324455c3b5b0d/out \
-L \
/home/vext01/research/ykrustc/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/x86_64-unknown-linux-gnu/lib \
-Wl,-Bstatic \
/home/vext01/research/yk/target/debug/deps/libmemmap-5f23cb5259f61858.rlib \
/home/vext01/research/yk/target/debug/deps/libgimli-d46f6b1d6250e62c.rlib \
/home/vext01/research/yk/target/debug/deps/libindexmap-a7445e071182095b.rlib \
/home/vext01/research/yk/target/debug/deps/libarrayvec-4d4c4abac05eec7a.rlib \
/home/vext01/research/yk/target/debug/deps/libnodrop-3da1b04b3cad85a5.rlib \
/home/vext01/research/yk/target/debug/deps/libstable_deref_trait-7630eaff18b8ab57.rlib \
/home/vext01/research/yk/target/debug/deps/libelf-97ced5ab8064f12b.rlib \
/home/vext01/research/yk/target/debug/deps/libbyteorder-a1ca60651d3abac3.rlib \
/home/vext01/research/yk/target/debug/deps/libphdrs-b9f0bd244ef345ca.rlib \
/home/vext01/research/yk/target/debug/deps/libobject-78dffdc0007e71b6.rlib \
/home/vext01/research/yk/target/debug/deps/libparity_wasm-6e118c1ea26bb0ca.rlib \
/home/vext01/research/yk/target/debug/deps/libflate2-a0dbcb32ab5b92bb.rlib \
/home/vext01/research/yk/target/debug/deps/libminiz_oxide-feee87a1e827d34e.rlib \
/home/vext01/research/yk/target/debug/deps/libadler32-df5c7e6116a31c83.rlib \
/home/vext01/research/yk/target/debug/deps/libcrc32fast-e74dc8ce28b7f377.rlib \
/home/vext01/research/yk/target/debug/deps/libgoblin-31c3e1931784d72b.rlib \
/home/vext01/research/yk/target/debug/deps/liblog-6bd6a1a9417c9b44.rlib \
/home/vext01/research/yk/target/debug/deps/libplain-815d5b934f3c458c.rlib \
/home/vext01/research/yk/target/debug/deps/libscroll-57c304c9c9aa4f19.rlib \
/home/vext01/research/yk/target/debug/deps/libuuid-d9fa09a0ac505087.rlib \
/home/vext01/research/yk/target/debug/deps/libtarget_lexicon-bd6c9c95040de744.rlib \
/home/vext01/research/yk/target/debug/deps/libfailure-883b6313101c519f.rlib \
/home/vext01/research/yk/target/debug/deps/libhwtracer-4a7fcfc6cdb25d08.rlib \
/home/vext01/research/yk/target/debug/deps/libtempfile-f73c3fca6b62eb80.rlib \
/home/vext01/research/yk/target/debug/deps/librand-df0ca11adb03b8e3.rlib \
/home/vext01/research/yk/target/debug/deps/librand_chacha-276a59e9166a9193.rlib \
/home/vext01/research/yk/target/debug/deps/libc2_chacha-170e0ce215266f6e.rlib \
/home/vext01/research/yk/target/debug/deps/libppv_lite86-8dd4ff65271756be.rlib \
/home/vext01/research/yk/target/debug/deps/librand_core-4c118f0513457ff6.rlib \
/home/vext01/research/yk/target/debug/deps/libgetrandom-a724117bf2304247.rlib \
/home/vext01/research/yk/target/debug/deps/libremove_dir_all-635dd99a7c406912.rlib \
/home/vext01/research/yk/target/debug/deps/libcfg_if-6454a07998dfdf77.rlib \
/home/vext01/research/yk/target/debug/deps/libtime-de6100a3b17d5591.rlib \
/home/vext01/research/yk/target/debug/deps/liblibc-7376e8de49ab6c4d.rlib \
/home/vext01/research/yk/target/debug/deps/libykpack-2a9122d94a2f837e.rlib \
/home/vext01/research/yk/target/debug/deps/librmp_serde-337cde3a4d7cf067.rlib \
/home/vext01/research/yk/target/debug/deps/libserde-af0b54eec19c1f21.rlib \
/home/vext01/research/yk/target/debug/deps/librmp-3e2e145986c5b5a2.rlib \
/home/vext01/research/yk/target/debug/deps/libnum_traits-e132ced7a5978735.rlib \
/home/vext01/research/yk/target/debug/deps/libbyteorder-06c02cccfe57c005.rlib \
/home/vext01/research/yk/target/debug/deps/libfallible_iterator-72f65c2f6c00d6f7.rlib \
/home/vext01/research/yk/target/debug/deps/liblazy_static-40baa21fb02fe58c.rlib \
/home/vext01/research/ykrustc/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/x86_64-unknown-linux-gnu/lib/libtest-fa7c5db992c603ae.rlib \
/home/vext01/research/ykrustc/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/x86_64-unknown-linux-gnu/lib/libterm-677b7a33a112844b.rlib \
/home/vext01/research/ykrustc/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/x86_64-unknown-linux-gnu/lib/libgetopts-3823ca10bcc34fef.rlib \
/home/vext01/research/ykrustc/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/x86_64-unknown-linux-gnu/lib/libunicode_width-b085949ade5be118.rlib \
/home/vext01/research/ykrustc/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_std_workspace_std-937f89c7b4331592.rlib \
-Wl,--start-group \
/home/vext01/research/ykrustc/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd-d5a0f5d9c2ecbc13.rlib \
/home/vext01/research/ykrustc/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/x86_64-unknown-linux-gnu/lib/libpanic_unwind-6214af4642f83019.rlib \
/home/vext01/research/ykrustc/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/x86_64-unknown-linux-gnu/lib/libhashbrown-d853b38ef82d1b80.rlib \
/home/vext01/research/ykrustc/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_std_workspace_alloc-b5c8492ce140f2f4.rlib \
/home/vext01/research/ykrustc/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/x86_64-unknown-linux-gnu/lib/libbacktrace-4f884e18d6db8201.rlib \
/home/vext01/research/ykrustc/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/x86_64-unknown-linux-gnu/lib/libbacktrace_sys-55bf2675880f6c0f.rlib \
/home/vext01/research/ykrustc/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_demangle-e80dead6761c88af.rlib \
/home/vext01/research/ykrustc/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/x86_64-unknown-linux-gnu/lib/libunwind-a0079eacbe814aa8.rlib \
/home/vext01/research/ykrustc/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcfg_if-eaebc19628616584.rlib \
/home/vext01/research/ykrustc/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/x86_64-unknown-linux-gnu/lib/liblibc-041597c76bfe99c8.rlib \
/home/vext01/research/ykrustc/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/x86_64-unknown-linux-gnu/lib/liballoc-4f9776276b6dc54c.rlib \
/home/vext01/research/ykrustc/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_std_workspace_core-f0c8c9c0de0535e4.rlib \
/home/vext01/research/ykrustc/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcore-cf28f55e983f3931.rlib \
-Wl,--end-group \
/home/vext01/research/ykrustc/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcompiler_builtins-f4dd3b487c184fe0.rlib \
-Wl,-Bdynamic \
-lipt \
-lutil \
-lutil \
-ldl \
-lrt \
-lpthread \
-lgcc_s \
-lc \
-lm \
-lrt \
-lpthread \
-lutil \
-lutil \
-Wl,--no-gc-sections \
/home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8.2qajgdgxxha7pskm.rcgu.o
This suceeds, but when we inspect the resulting binary, .yksir_ykpack is missing:
$ readelf --section-headers /home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8 2>/dev/null | grep 'yksir_ykpack'
$
The .yksir_yktrace section is in the binary though:
$ readelf --section-headers /home/vext01/research/yk/target/debug/deps/yktrace-191ae338a3a7cbe8 2>/dev/null | grep 'yksir_yktrace'
...
[31] .yksir_yktrace PROGBITS 0000000000000000 009ba0e0
0000000000078ed3 0000000000000000 0 0 16
Does anyone know why this is? Where did .yksir_ykpack go?
I've tried removing -Wl,--as-needed and moving up -Wl,--no-gc-sections. No joy.
Thank you!
I've figured it out.
The crucial detail here is that Rust .rlib files are static libraries. Unlike .o object files, when linking a static library (usually a .a file), the linker uses a resolution step to pull in only as yet undefined symbols and nothing else.
This can be seen using this minimal example:
all: main_a main_o main_a_whole dump
# Generate text files to use as the contents of the sections.
my_section1.raw:
echo "mydata1" > $#
my_section2.raw:
echo "mydata2" > $#
# Generate object files for the sections.
my_section1.o: my_section1.raw
objcopy --input-target binary \
--output-target=elf64-x86-64 \
--binary-architecture i386:x86-64 \
--rename-section .data=.my_section1 \
my_section1.raw $#
my_section2.o: my_section2.raw
objcopy --input-target binary \
--output-target=elf64-x86-64 \
--binary-architecture i386:x86-64 \
--rename-section .data=.my_section2 \
my_section2.raw $#
# And for section1 only, we will make a static lib.
my_section1.a: my_section1.o
ar rcs $# my_section1.o
# A "main" stub to link our objects to.
main.c:
echo "void main(void) {}" > main.c
# Now make some binaries using varying linkage configurations.
# main_o is made from the object files.
main_o: main.o my_section1.a my_section2.o
${CC} -o $# my_section1.o my_section2.o main.o
# main_a uses the static lib for section1 and the object file for section2.
main_a: main.o my_section1.a my_section2.o
${CC} -o $# my_section1.a my_section2.o main.o
# main_a_whole is the same as main_a, but uses --whole-archive when linking section1.
main_a_whole: main.o my_section1.a my_section2.o
${CC} -o $# -Wl,--whole-archive my_section1.a -Wl,--no-whole-archive my_section2.o main.o
# Print the sections of interest from the resulting binaries.
dump:
#echo "\n>>> main_o sections"
objdump -h main_o | grep my_section
#echo "\n>>> main_a sections"
objdump -h main_a | grep my_section
#echo "\n>>> main_a_whole sections"
objdump -h main_a_whole | grep my_section
clean:
rm -f *.o *.a main_a main_o main_a_whole *.raw main.c
When run, we get:
>>> main_o sections
objdump -h main_o | grep my_section
23 .my_section1 00000008 0000000000004028 0000000000004028 00003028 2**0
24 .my_section2 00000008 0000000000004030 0000000000004030 00003030 2**0
>>> main_a sections
objdump -h main_a | grep my_section
23 .my_section2 00000008 0000000000004028 0000000000004028 00003028 2**0
>>> main_a_whole sections
objdump -h main_a_whole | grep my_section
23 .my_section1 00000008 0000000000004028 0000000000004028 00003028 2**0
24 .my_section2 00000008 0000000000004030 0000000000004030 00003030 2**0
Note the use of --whole-archive to force the whole static lib to be loaded. This may be undesirable, as you may wish to fully link only one section, which cannot be done directly AFAICS. In such as case you can extract the section using ar or objcopy and link that instead.

How can I give the sourcefilepaths to gcc?

How can I give my sourcepaths to gcc?
I have my .c files in source and test directory.
How can I give gcc the path to it? Im compiling with amakefile` and always get the message
"no such file or directory test.c"
My directory structure:
make-directory|
|
|--source
|
|--Header
|
|--test
|
|--out
|
as asked:
# makefile to generate UNIT-tests
# define any directories containing header files other than /usr/include
# TODO
HEADERS = :../CUnit/headers \
CUnit/sources/Automated \
CUnit/sources/Basic \
CUnit/sources/Console \
CUnit/sources/Curses \
CUnit/sources/Framework \
CUnit/sources/Test \
CUnit/sources/Win \
CUnit/sources/wxWidget \
stub \
../source \
test
SOURCES = CUnit/headers \
CUnit/sources/Automated \
CUnit/sources/Basic \
CUnit/sources/Console \
CUnit/sources/Curses \
CUnit/sources/Framework \
CUnit/sources/Test \
CUnit/sources/Win \
CUnit/sources/wxWidget \
stub \
source \
test
# define any libraries to link into executable:
# if I want to link in libraries (libx.so or libx.a) I use the -llibname
# option, something like (this will link in libmylib.so and libm.so:
LIBS =
# TODO define the C source files
TST_SRCS = min.c max.c
SRCS = CUnit.c Automated.c Basic.c Console.c CUCurses.c CUError.c Cunit_intl.c \
MyMem.c TestDB.c TestRun.c Util.c wxWidget.c \
$(TST_SRCS)
# define the C object files
#
# This uses Suffix Replacement within a macro:
# $(name:string1=string2)
# For each word in 'name' replace 'string1' with 'string2'
#OBJ = $(SRCS:%.c=%.o)
OBJ = $(TST_SRCS:%.c=%.o)
#OBJ=$(join ($(SOURCES)), $(notdir $(SRCS:%.c=%.o)))
# define the C compiler to use
CC = gcc
# define any compile-time flags
CFLAGS = -O0 -g -Wall -fmessage-length=0 -fprofile-arcs -ftest-coverage
#TODO Linkerflags
LFLAGS = --coverage
VPATH=source
# define the executable file,
TARGET = CUnit
all:
$(CC) -I $(HEADERS) $(CFLAGS) $(OBJ) -o $(TARGET) $(LFLAGS)
You can make use of vpath or VPATH in makefile to point to the directory containing the source files.
See the online gnu make manual here.

adding new file to C project using Makefile

I am trynig to add new file to source code of an open-source software called snort in order to extend it. This project is based on Makefile and I use the netbeans IDE. I want to add my file named my_new_file.h & my_new_file.c to this project. I investigated the Makefile and added the name of my files to the end of lists of source files and object files wherever I saw; that you can see simply by searching my_new_file in this page(ctrl+F). After this the project is built fine; but when I want to run the software I see the error stating that the definition of new function I defined in my_new_file not found.
/libsf_sip_preproc.so: undefined symbol: my_new_func
All of this package is going to be compiled and linked into some shared object files. I see the object file of my sources are generated but I think they didn't link correctly into the makefile. The mekefile I use is auto-generated by mixing makefile.in & makefile.am using the configure script. I attached the whole main makefile bellow. If somebody knows how can I edit this makefile to compile and link my sources to the main project I will be so thankful.
This Is the make.am file:
## $Id
AUTOMAKE_OPTIONS=foreign no-dependencies
INCLUDES = -I../include -I${srcdir}/../libs -I$(srcdir)/includes
libdir = ${exec_prefix}/lib/snort_dynamicpreprocessor
lib_LTLIBRARIES = libsf_sip_preproc.la
libsf_sip_preproc_la_LDFLAGS = -shared -export-dynamic -module #XCCFLAGS#
if SO_WITH_STATIC_LIB
libsf_sip_preproc_la_LIBADD = ../libsf_dynamic_preproc.la
else
nodist_libsf_sip_preproc_la_SOURCES = \
../include/sf_dynamic_preproc_lib.c \
../include/sf_ip.c \
../include/sfPolicyUserData.c
endif
libsf_sip_preproc_la_SOURCES = \
spp_sip.c \
spp_sip.h \
sip_config.c \
sip_config.h \
sip_parser.c \
sip_parser.h \
sip_dialog.c \
sip_dialog.h \
sip_roptions.c \
sip_roptions.h \
sip_utils.c \
sip_utils.h \
sip_debug.h \
my_new_file.c \
my_new_file.h
EXTRA_DIST = \
sf_sip.dsp
all-local: $(LTLIBRARIES)
$(MAKE) DESTDIR=`pwd`/../build install-libLTLIBRARIES
and this is the main Maikefile generated using makefile.am and makefile.in by configure script:
# Makefile.in generated by automake 1.11.1 from Makefile.am.
# src/dynamic-preprocessors/sip/Makefile. Generated from Makefile.in by configure.
pkgdatadir = $(datadir)/snort
pkgincludedir = $(includedir)/snort
pkglibdir = $(libdir)/snort
pkglibexecdir = $(libexecdir)/snort
am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd
install_sh_DATA = $(install_sh) -c -m 644
install_sh_PROGRAM = $(install_sh) -c
install_sh_SCRIPT = $(install_sh) -c
INSTALL_HEADER = $(INSTALL_DATA)
transform = $(program_transform_name)
NORMAL_INSTALL = :
PRE_INSTALL = :
POST_INSTALL = :
NORMAL_UNINSTALL = :
PRE_UNINSTALL = :
POST_UNINSTALL = :
build_triplet = i686-pc-linux-gnu
host_triplet = i686-pc-linux-gnu
subdir = src/dynamic-preprocessors/sip
DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
am__aclocal_m4_deps = $(top_srcdir)/m4/libprelude.m4 \
$(top_srcdir)/configure.in
am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
$(ACLOCAL_M4)
mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs
CONFIG_HEADER = $(top_builddir)/config.h
CONFIG_CLEAN_FILES =
CONFIG_CLEAN_VPATH_FILES =
am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`;
am__vpath_adj = case $$p in \
$(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \
*) f=$$p;; \
esac;
am__strip_dir = f=`echo $$p | sed -e 's|^.*/||'`;
am__install_max = 40
am__nobase_strip_setup = \
srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*|]/\\\\&/g'`
am__nobase_strip = \
for p in $$list; do echo "$$p"; done | sed -e "s|$$srcdirstrip/||"
am__nobase_list = $(am__nobase_strip_setup); \
for p in $$list; do echo "$$p $$p"; done | \
sed "s| $$srcdirstrip/| |;"' / .*\//!s/ .*/ ./; s,\( .*\)/[^/]*$$,\1,' | \
$(AWK) 'BEGIN { files["."] = "" } { files[$$2] = files[$$2] " " $$1; \
if (++n[$$2] == $(am__install_max)) \
{ print $$2, files[$$2]; n[$$2] = 0; files[$$2] = "" } } \
END { for (dir in files) print dir, files[dir] }'
am__base_list = \
sed '$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;s/\n/ /g' | \
sed '$$!N;$$!N;$$!N;$$!N;s/\n/ /g'
am__installdirs = "$(DESTDIR)$(libdir)"
LTLIBRARIES = $(lib_LTLIBRARIES)
libsf_sip_preproc_la_DEPENDENCIES = \
../libsf_dynamic_preproc.la
am_libsf_sip_preproc_la_OBJECTS = spp_sip.lo sip_config.lo \
sip_parser.lo sip_dialog.lo sip_roptions.lo sip_utils.lo \
my_new_file.lo
#nodist_libsf_sip_preproc_la_OBJECTS = \
# sf_dynamic_preproc_lib.lo sf_ip.lo \
# sfPolicyUserData.lo
libsf_sip_preproc_la_OBJECTS = $(am_libsf_sip_preproc_la_OBJECTS) \
$(nodist_libsf_sip_preproc_la_OBJECTS)
libsf_sip_preproc_la_LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) \
$(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
$(libsf_sip_preproc_la_LDFLAGS) $(LDFLAGS) -o $#
DEFAULT_INCLUDES = -I. -I$(top_builddir)
depcomp =
am__depfiles_maybe =
COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
$(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
LTCOMPILE = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \
--mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \
$(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
CCLD = $(CC)
LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \
--mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) \
$(LDFLAGS) -o $#
SOURCES = $(libsf_sip_preproc_la_SOURCES) \
$(nodist_libsf_sip_preproc_la_SOURCES)
DIST_SOURCES = $(libsf_sip_preproc_la_SOURCES)
ETAGS = etags
CTAGS = ctags
DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
ACLOCAL = ${SHELL} /usr/local/src/snort-2.9.2.2/missing --run aclocal-1.11
AMTAR = ${SHELL} /usr/local/src/snort-2.9.2.2/missing --run tar
AR = ar
AUTOCONF = ${SHELL} /usr/local/src/snort-2.9.2.2/missing --run autoconf
AUTOHEADER = ${SHELL} /usr/local/src/snort-2.9.2.2/missing --run autoheader
AUTOMAKE = ${SHELL} /usr/local/src/snort-2.9.2.2/missing --run automake-1.11
AWK = mawk
CC = /usr/bin/gcc
CCDEPMODE = depmode=gcc3
CCONFIGFLAGS = -DSF_VISIBILITY -fvisibility=hidden
CFLAGS = -g3 -gdwarf-2 -DSF_VISIBILITY -fvisibility=hidden -fno-strict-aliasing -Wall
CONFIGFLAGS = -DSF_WCHAR -DSUP_IP6 -DTARGET_BASED -DPERF_PROFILING -DSNORT_RELOAD -DNORMALIZER -DACTIVE_RESPONSE
CPP = /usr/bin/gcc -E
CPPFLAGS = -I/usr/local/include -DDYNAMIC_PLUGIN -I/usr/local/include -DZLIB -DGRE -DMPLS -DPREPROCESSOR_AND_DECODER_RULE_EVENTS -DPPM_MGR -DENABLE_PAF -DENABLE_REACT -DENABLE_RESPOND -DENABLE_RESPONSE3 -DSF_WCHAR -DSUP_IP6 -DTARGET_BASED -DPERF_PROFILING -DSNORT_RELOAD -DNORMALIZER -DACTIVE_RESPONSE
CYGPATH_W = echo
DEFS = -DHAVE_CONFIG_H
DEPDIR = .deps
DLLTOOL = false
DSYMUTIL =
DUMPBIN =
ECHO_C =
ECHO_N = -n
ECHO_T =
EGREP = /bin/grep -E
EXEEXT =
FGREP = /bin/grep -F
GREP = /bin/grep
ICONFIGFLAGS =
INCLUDES = -I../include -I${srcdir}/../libs -I$(srcdir)/includes
INSTALL = /usr/bin/install -c
INSTALL_DATA = ${INSTALL} -m 644
INSTALL_PROGRAM = ${INSTALL}
INSTALL_SCRIPT = ${INSTALL}
INSTALL_STRIP_PROGRAM = $(install_sh) -c -s
LD = /usr/bin/ld
LDFLAGS = -L/usr/local/lib -lpcre -L/usr/local/lib -ldnet
LEX = flex
LIBOBJS =
LIBPRELUDE_CFLAGS =
LIBPRELUDE_CONFIG =
LIBPRELUDE_CONFIG_PREFIX =
LIBPRELUDE_LDFLAGS =
LIBPRELUDE_LIBS =
LIBPRELUDE_PREFIX =
LIBPRELUDE_PTHREAD_CFLAGS =
LIBS = -lz -ldaq_static -ldnet -lpcre -lpcap -lnsl -lm -lm -ldl -L/usr/local/lib -ldaq_static_modules -lsfbpf -lpcap -lsfbpf -lpcap -lz -lpthread -lpthread -lpthread
LIBTOOL = $(SHELL) $(top_builddir)/libtool
LIPO =
LN_S = ln -s
LTLIBOBJS =
MAINT = #
MAKEINFO = ${SHELL} /usr/local/src/snort-2.9.2.2/missing --run makeinfo
MANIFEST_TOOL = :
MKDIR_P = /bin/mkdir -p
NM = /usr/bin/nm -B
NMEDIT =
OBJDUMP = objdump
OBJEXT = o
OTOOL =
OTOOL64 =
PACKAGE = snort
PACKAGE_BUGREPORT =
PACKAGE_NAME =
PACKAGE_STRING =
PACKAGE_TARNAME =
PACKAGE_URL =
PACKAGE_VERSION =
PATH_SEPARATOR = :
PKG_CONFIG =
PKG_CONFIG_LIBDIR =
PKG_CONFIG_PATH = NONE/lib/pkgconfig:
RANLIB = ranlib
RAZORBACK_CFLAGS =
RAZORBACK_LIBS =
SED = /bin/sed
SET_MAKE =
SHELL = /bin/bash
SIGNAL_SNORT_DUMP_STATS =
SIGNAL_SNORT_READ_ATTR_TBL =
SIGNAL_SNORT_RELOAD =
SIGNAL_SNORT_ROTATE_STATS =
STRIP = strip
VERSION = 2.9.2.2
XCCFLAGS =
YACC = bison -y
abs_builddir = /usr/local/src/snort-2.9.2.2/src/dynamic-preprocessors/sip
abs_srcdir = /usr/local/src/snort-2.9.2.2/src/dynamic-preprocessors/sip
abs_top_builddir = /usr/local/src/snort-2.9.2.2
abs_top_srcdir = /usr/local/src/snort-2.9.2.2
ac_ct_AR = ar
ac_ct_CC = /usr/bin/gcc
ac_ct_DUMPBIN =
am__include = include
am__leading_dot = .
am__quote =
am__tar = ${AMTAR} chof - "$$tardir"
am__untar = ${AMTAR} xf -
bindir = ${exec_prefix}/bin
build = i686-pc-linux-gnu
build_alias =
build_cpu = i686
build_os = linux-gnu
build_vendor = pc
builddir = .
datadir = ${datarootdir}
datarootdir = ${prefix}/share
docdir = ${datarootdir}/doc/${PACKAGE}
dvidir = ${docdir}
exec_prefix = ${prefix}
extra_incl = -I/usr/include/pcap
host = i686-pc-linux-gnu
host_alias =
host_cpu = i686
host_os = linux-gnu
host_vendor = pc
htmldir = ${docdir}
includedir = ${prefix}/include
infodir = ${datarootdir}/info
install_sh = ${SHELL} /usr/local/src/snort-2.9.2.2/install-sh
libdir = ${exec_prefix}/lib/snort_dynamicpreprocessor
libexecdir = ${exec_prefix}/libexec
localedir = ${datarootdir}/locale
localstatedir = ${prefix}/var
mandir = ${datarootdir}/man
mkdir_p = /bin/mkdir -p
oldincludedir = /usr/include
pdfdir = ${docdir}
prefix = /usr/local
program_transform_name = s,x,x,
psdir = ${docdir}
sbindir = ${exec_prefix}/sbin
sharedstatedir = ${prefix}/com
srcdir = .
sysconfdir = ${prefix}/etc
target_alias =
top_build_prefix = ../../../
top_builddir = ../../..
top_srcdir = ../../..
AUTOMAKE_OPTIONS = foreign no-dependencies
lib_LTLIBRARIES = libsf_sip_preproc.la
libsf_sip_preproc_la_LDFLAGS = -shared -export-dynamic -module
libsf_sip_preproc_la_LIBADD = ../libsf_dynamic_preproc.la
#nodist_libsf_sip_preproc_la_SOURCES = \
#../include/sf_dynamic_preproc_lib.c \
#../include/sf_ip.c \
#../include/sfPolicyUserData.c
libsf_sip_preproc_la_SOURCES = \
spp_sip.c \
spp_sip.h \
sip_config.c \
sip_config.h \
sip_parser.c \
sip_parser.h \
sip_dialog.c \
sip_dialog.h \
sip_roptions.c \
sip_roptions.h \
sip_utils.c \
sip_utils.h \
sip_debug.h \
my_new_file.c \
my_new_file.h
EXTRA_DIST = \
sf_sip.dsp
all: all-am
.SUFFIXES:
.SUFFIXES: .c .lo .o .obj
$(srcdir)/Makefile.in: # $(srcdir)/Makefile.am $(am__configure_deps)
#for dep in $?; do \
case '$(am__configure_deps)' in \
*$$dep*) \
( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \
&& { if test -f $#; then exit 0; else break; fi; }; \
exit 1;; \
esac; \
done; \
echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign src/dynamic-preprocessors/sip/Makefile'; \
$(am__cd) $(top_srcdir) && \
$(AUTOMAKE) --foreign src/dynamic-preprocessors/sip/Makefile
.PRECIOUS: Makefile
Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
#case '$?' in \
*config.status*) \
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \
*) \
echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$# $(am__depfiles_maybe)'; \
cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$# $(am__depfiles_maybe);; \
esac;
$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES)
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
$(top_srcdir)/configure: # $(am__configure_deps)
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
$(ACLOCAL_M4): # $(am__aclocal_m4_deps)
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
$(am__aclocal_m4_deps):
install-libLTLIBRARIES: $(lib_LTLIBRARIES)
#$(NORMAL_INSTALL)
test -z "$(libdir)" || $(MKDIR_P) "$(DESTDIR)$(libdir)"
#list='$(lib_LTLIBRARIES)'; test -n "$(libdir)" || list=; \
list2=; for p in $$list; do \
if test -f $$p; then \
list2="$$list2 $$p"; \
else :; fi; \
done; \
test -z "$$list2" || { \
echo " $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL) $(INSTALL_STRIP_FLAG) $$list2 '$(DESTDIR)$(libdir)'"; \
$(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL) $(INSTALL_STRIP_FLAG) $$list2 "$(DESTDIR)$(libdir)"; \
}
uninstall-libLTLIBRARIES:
#$(NORMAL_UNINSTALL)
#list='$(lib_LTLIBRARIES)'; test -n "$(libdir)" || list=; \
for p in $$list; do \
$(am__strip_dir) \
echo " $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=uninstall rm -f '$(DESTDIR)$(libdir)/$$f'"; \
$(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=uninstall rm -f "$(DESTDIR)$(libdir)/$$f"; \
done
clean-libLTLIBRARIES:
-test -z "$(lib_LTLIBRARIES)" || rm -f $(lib_LTLIBRARIES)
#list='$(lib_LTLIBRARIES)'; for p in $$list; do \
dir="`echo $$p | sed -e 's|/[^/]*$$||'`"; \
test "$$dir" != "$$p" || dir=.; \
echo "rm -f \"$${dir}/so_locations\""; \
rm -f "$${dir}/so_locations"; \
done
libsf_sip_preproc.la: $(libsf_sip_preproc_la_OBJECTS) $(libsf_sip_preproc_la_DEPENDENCIES)
$(libsf_sip_preproc_la_LINK) -rpath $(libdir) $(libsf_sip_preproc_la_OBJECTS) $(libsf_sip_preproc_la_LIBADD) $(LIBS)
mostlyclean-compile:
-rm -f *.$(OBJEXT)
distclean-compile:
-rm -f *.tab.c
.c.o:
$(COMPILE) -c $<
.c.obj:
$(COMPILE) -c `$(CYGPATH_W) '$<'`
.c.lo:
$(LTCOMPILE) -c -o $# $<
sf_dynamic_preproc_lib.lo: ../include/sf_dynamic_preproc_lib.c
$(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o sf_dynamic_preproc_lib.lo `test -f '../include/sf_dynamic_preproc_lib.c' || echo '$(srcdir)/'`../include/sf_dynamic_preproc_lib.c
sf_ip.lo: ../include/sf_ip.c
$(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o sf_ip.lo `test -f '../include/sf_ip.c' || echo '$(srcdir)/'`../include/sf_ip.c
sfPolicyUserData.lo: ../include/sfPolicyUserData.c
$(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o sfPolicyUserData.lo `test -f '../include/sfPolicyUserData.c' || echo '$(srcdir)/'`../include/sfPolicyUserData.c
mostlyclean-libtool:
-rm -f *.lo
clean-libtool:
-rm -rf .libs _libs
ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES)
list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
unique=`for i in $$list; do \
if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
done | \
$(AWK) '{ files[$$0] = 1; nonempty = 1; } \
END { if (nonempty) { for (i in files) print i; }; }'`; \
mkid -fID $$unique
tags: TAGS
TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \
$(TAGS_FILES) $(LISP)
set x; \
here=`pwd`; \
list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
unique=`for i in $$list; do \
if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
done | \
$(AWK) '{ files[$$0] = 1; nonempty = 1; } \
END { if (nonempty) { for (i in files) print i; }; }'`; \
shift; \
if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \
test -n "$$unique" || unique=$$empty_fix; \
if test $$# -gt 0; then \
$(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
"$$#" $$unique; \
else \
$(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
$$unique; \
fi; \
fi
ctags: CTAGS
CTAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \
$(TAGS_FILES) $(LISP)
list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
unique=`for i in $$list; do \
if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
done | \
$(AWK) '{ files[$$0] = 1; nonempty = 1; } \
END { if (nonempty) { for (i in files) print i; }; }'`; \
test -z "$(CTAGS_ARGS)$$unique" \
|| $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \
$$unique
GTAGS:
here=`$(am__cd) $(top_builddir) && pwd` \
&& $(am__cd) $(top_srcdir) \
&& gtags -i $(GTAGS_ARGS) "$$here"
distclean-tags:
-rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags
distdir: $(DISTFILES)
#srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
list='$(DISTFILES)'; \
dist_files=`for file in $$list; do echo $$file; done | \
sed -e "s|^$$srcdirstrip/||;t" \
-e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \
case $$dist_files in \
*/*) $(MKDIR_P) `echo "$$dist_files" | \
sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \
sort -u` ;; \
esac; \
for file in $$dist_files; do \
if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \
if test -d $$d/$$file; then \
dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \
if test -d "$(distdir)/$$file"; then \
find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \
fi; \
if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \
cp -fpR $(srcdir)/$$file "$(distdir)$$dir" || exit 1; \
find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \
fi; \
cp -fpR $$d/$$file "$(distdir)$$dir" || exit 1; \
else \
test -f "$(distdir)/$$file" \
|| cp -p $$d/$$file "$(distdir)/$$file" \
|| exit 1; \
fi; \
done
check-am: all-am
check: check-am
all-am: Makefile $(LTLIBRARIES) all-local
installdirs:
for dir in "$(DESTDIR)$(libdir)"; do \
test -z "$$dir" || $(MKDIR_P) "$$dir"; \
done
install: install-am
install-exec: install-exec-am
install-data: install-data-am
uninstall: uninstall-am
install-am: all-am
#$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
installcheck: installcheck-am
install-strip:
$(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
`test -z '$(STRIP)' || \
echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install
mostlyclean-generic:
clean-generic:
distclean-generic:
-test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES)
-test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES)
#echo "This command is intended for maintainers to use"
#echo "it deletes files that may require special tools to rebuild."
clean: clean-am
clean-am: clean-generic clean-libLTLIBRARIES clean-libtool \
mostlyclean-am
distclean: distclean-am
-rm -f Makefile
distclean-am: clean-am distclean-compile distclean-generic \
distclean-tags
dvi: dvi-am
dvi-am:
html: html-am
html-am:
info: info-am
info-am:
install-data-am:
install-dvi: install-dvi-am
install-dvi-am:
install-exec-am: install-libLTLIBRARIES
install-html: install-html-am
install-html-am:
install-info: install-info-am
install-info-am:
install-man:
install-pdf: install-pdf-am
install-pdf-am:
install-ps: install-ps-am
install-ps-am:
installcheck-am:
maintainer-clean: maintainer-clean-am
-rm -f Makefile
maintainer-clean-am: distclean-am maintainer-clean-generic
mostlyclean: mostlyclean-am
mostlyclean-am: mostlyclean-compile mostlyclean-generic \
mostlyclean-libtool
pdf: pdf-am
pdf-am:
ps: ps-am
ps-am:
uninstall-am: uninstall-libLTLIBRARIES
.MAKE: install-am install-strip
.PHONY: CTAGS GTAGS all all-am all-local check check-am clean \
clean-generic clean-libLTLIBRARIES clean-libtool ctags \
distclean distclean-compile distclean-generic \
distclean-libtool distclean-tags distdir dvi dvi-am html \
html-am info info-am install install-am install-data \
install-data-am install-dvi install-dvi-am install-exec \
install-exec-am install-html install-html-am install-info \
install-info-am install-libLTLIBRARIES install-man install-pdf \
install-pdf-am install-ps install-ps-am install-strip \
installcheck installcheck-am installdirs maintainer-clean \
maintainer-clean-generic mostlyclean mostlyclean-compile \
mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \
tags uninstall uninstall-am uninstall-libLTLIBRARIES
all-local: $(LTLIBRARIES)
$(MAKE) DESTDIR=`pwd`/../build install-libLTLIBRARIES
# Tell versions [3.59,3.63) of GNU make to not export all variables.
# Otherwise a system limit (for SysV at least) may be exceeded.
.NOEXPORT:

Is this a good way to be root in a makefile?

Is this a good way to be root in a makefile?
SHELL = /bin/sh
INSTDIR = /usr/bin/
OBJS = main.o file.o gen.o stat.o
program1: $(OBJS)
gcc -o program1 $(OBJS)
main.o: main.c file.h gen.h stat.h
gcc -c main.c
file.o: file.c file.h
gcc -c file.c
gen.o: gen.c gen.h
gcc -c gen.c
stat.o: stat.c stat.h
gcc -c stat.c
clean:
rm -f $(OBJS) program1
install:
#if [ -f program1 ]; then \
if [ $$(id -u) -eq 0 ]; then \
cp program1 $(INSTDIR) && \
echo "Installed in $(INSTDIR)" ; \
else \
(sudo cp program1 $(INSTDIR) 2> /dev/null && \
echo "Installed in $(INSTDIR)") || \
(echo 'No sudo on this machine, trying su.' \
&& su -c "cp program1 $(INSTDIR)" && \
echo "Installed in $(INSTDIR)") ; \
fi ; \
else \
echo "There was no program to install, run make." ; \
fi
uninstall:
#if [ -f $(INSTDIR)program1 ]; then \
if [ $$(id -u) -eq 0 ]; then \
rm $(INSTDIR)program1 && \
echo "Uninstalled in $(INSTDIR)" ; \
else \
(sudo rm $(INSTDIR)program1 2> /dev/null && \
echo "Uninstalled in $(INSTDIR)") || \
(echo 'No sudo on this machine, trying su.' \
&& su -c "rm $(INSTDIR)program1" && \
echo "Uninstalled in $(INSTDIR)") ; \
fi ; \
else \
echo "There was no program to remove." ; \
fi
NO!
First, generally users do sudo make install. Second, you didn't think about cases when the program is installed into a custom directory, which doesn't always need root privileges. Packaging tools use this feature, for example, and they don't have root privileges.

Resources