Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I use different c compiler/linker options on a per-file basis using rebar?

I've got rebar set up to build an erlang module which uses two different c files.

I set c compilation options in my rebar.config using (for example):

{port_env, [{"DRV_CFLAGS", "$DRV_CFLAGS -Wall -Wextra"}]}.

Is it possible to set different options for each c source file? I'd like different compiler and linker flags for each.

If not, what's the most common alternative/workaround? I guess that creating a Makefile and moving the c compilation to there would work, it just seems a shame to have to do when rebar takes care of the rest so nicely.

like image 259
Dave Challis Avatar asked Jan 29 '26 00:01

Dave Challis


1 Answers

Crazy idea: You can use pre_hooks and post_hooks to execute shell scripts. Maybe you could run your own shell script to compile the file with your desired compiler and flags, after rebar already has done it's job.

For an example of preprocessing, check out Steve Vinoskis NIF implementation of the SHA-2 standard. See his rebar.config and c_src/config.sh

like image 178
knutin Avatar answered Jan 30 '26 21:01

knutin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!